def readfile(file): edges = [] # to contain tuples of all edges with open(file) as f: for line in f: I'm trying to pass in a text file called file, then read it, but it doesn't work. Even if I cast file to a string it doesn't work. Python says
with open(file) as f: IOError: [Errno 22] invalid mode ('r') or filename: "<type 'file'>" How do I open a file, passed to open as a variable?
readfile? seems you are not passing value forfileargument.fileobject to your function, andopenexpects a string name. So there is an inconsistency here.