Did you do something like the following? - >>> open = (1,2,3)
-
>>> for item in lst:
-
... g = open(item,'w')
-
... g.close()
-
...
-
Traceback (most recent call last):
-
File "<interactive input>", line 2, in ?
-
TypeError: 'tuple' object is not callable
-
>>>
Thanks for the quick reply :)
Ok: The raw data are files that each contain several observations of each of a certain set of items. What I want is a separate file for each item that contains all the observations from all the raw data files.
I create a list of the items that I want separate files of, and using glob I create a list of the file names in the raw data folder. Using the code below I get the the 'tuple' error message first for line 9 and when I try to run it again I get the same error message for line 7.
(Being a 'newbie' i am currently writing the script in textwrangler and pasting it into the python interpretor in terminal on my mac to run the script. I have heard about #!/usr/local/bin/python but do not know how to go about implementing that)
-
itemlist = ['1','4']
-
import glob
-
datafiles = glob.glob('raw/*.txt')
-
for n in itemlist:
-
itemfile = 'trans/no.txt'
-
itemfile = itemfile.replace('no', n)
-
g = open ( itemfile, 'w' )
-
for x in datafiles:
-
f = open ( x, 'r' )
-
for line in f:
-
data = line.split(';')
-
if data[0] == n:
-
trans = ';'.join(data) + '\n'
-
g.write(trans)
-
pass