Hi,I was wondering how to read and write strings in python. I have this code where I'm creating a path, but its a string, and now I want to write to this string. But keep getting this error message AttributeError: 'str' object has no attribute 'write'
I was thinking about using StringIO(), but I'm not sure how it's used.
create a path1
create a newfile
for each filename in path1: # only look at the filenames of all the txtfiles in path1
create fullpath1 + filename #create fullpath
create newfile + filenames from path1 #create fullpath
open fullpath1
for each line in fullpath1:
get some information from fullpath1
write it to newfile
path1 is just the path to a lot of txt files, and in these txt files I want to get some information and create new txt files, but with the same filenames as the other txt files. For example, if we look at the first file in fullpath1 named tree1 then I want to go in to that file and extract some of the columns and write it to a newfile also called tree1. The same for tree2, tree3... and so on... So that I in the end have the same file names (tree1, tree2, tree3...) only containing the extracted columns from fullpath1.