I've made a few text files that are formatted in the following way:
['number', 'number', 'number']
number
number
number
However, some of my files only contain this:
['number', 'number', 'number']
When I run my current code (seen below) and it encounters files like these, it gives me this error:
Traceback (most recent call last):
File "product_1digcon1.py", line 879, in <module>
punch_it()
File "product_1digcon1.py", line 875, in punch_it
last()
File "product_1digcon1.py", line 742, in last
finale()
File "product_1digcon1.py", line 775, in finale
for value, line in zip(values, fh):
TypeError: zip argument #1 must support iteration
I'm trying to modify my code such that, if zip argument #1 does not support iteration, the code should move on to the next file. This is what I've written so far.
def StDev():
for root, dirs, files in os.walk('/Users/Bashe/Desktop/12/'):
file = os.path.join(root, "Graph_StDev.txt")
file_name_out = os.path.join(root,"StDev.txt")
test = []
if os.path.exists(os.path.join(root,"Graph_StDev.txt")):
with open(file) as th, open(file_name_out,"w") as fh_out:
first_line = th.readline()
values = eval(first_line)
test.append(values)
test1 = str(test)
try:
float(test1)
if True:
for value, line in zip(values, th):
first_column = line.strip()
fh_out.write("%s\n" % (first_column))
except ValueError:
pass
Any Help would be appreciated.