I have a text file and need to make all the text into an array where each item is a letter i.e. the cow needs to be split in to ["t","h","e"," ","c","o","w"]. how could i do this as simply as possible?
So you need to duplicate the line? Why are you writing to the same file you just read from?
You could always do this...
message = list(open("Catext.txt").read())
f = open('Catext.txt', 'wb')
# write the original
f.write(''.join(message))
# write the duplicate
f.write(''.join(message))
f.close()
with some stuff in between
You can't read and write from the same file at the same time.
That makes more sense. Still, why not just do an infile and an outfile with a similar name? It's generally not a good idea to wipe the original file. Windows/linux don't delete the original file when you unpack a zip/tar.
1
u/billsil Jan 26 '15
So you need to duplicate the line? Why are you writing to the same file you just read from?
You could always do this...
with some stuff in between
You can't read and write from the same file at the same time.