Why can’t I make multiple assignments under an if statement in python? Is there some syntax I am missing?
I want to do this:
files = ["file1", "file2", "file3"]
print "\nThe following files are available: \n"
i = 0
for file in files:
i = i + 1
print i, file
choice = int(raw_input("\Enter a file number: "))
if choice ==1:
file = np.genfromtxt(files[0], usecols = (1,2,3), dtype = (float), delimiter = '\t')
time = np.genfromtxt(files[0], usecols = (0), dtype = (str), delimiter = '\t')
print time
Time is defined outside of my if statement, so it doesn’t change as choice changes…what the heck?
Both variables file and time must be defined at an higher block level than your if statement.
Be careful with “time”, as it is the name of a python module. You should use a variation of this name (time_ for example).