I try to concatenate txt files, and almost all goes well but
the out file has a space between each letter
like l o r e m i p s u m
here's my code
import glob
all = open("all.txt","a");
for f in glob.glob("*.txt"):
print f
t = open(f, "r")
all.write(t.read())
t.close()
all.close()
I'm working on windows 7, python 2.7
EDIT
Maybe there's better way to concatenate files?
EDIT2
I got decoding issues now:
Traceback (most recent call last):
File "P:\bwiki\BWiki\MobileNotes\export\999.py", line 9, in <module>
all.write( t.read())
File "C:\Python27\lib\codecs.py", line 671, in read
return self.reader.read(size)
File "C:\Python27\lib\codecs.py", line 477, in read
newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf3 in position 18: invalid
continuation byte
import codecs
import glob
all =codecs.open("all.txt", "a", encoding="utf-8")
for f in glob.glob("*.txt"):
print f
t = codecs.open(f, "r", encoding="utf-8")
all.write( t.read())