Quote:
Originally Posted by mohtech
It seems to be waiting for something....stdin I assume. Is there any way of doing this through fileinput or should I use the myfile=open("datasheet.txt",'r')....?
|
What was on the command line? Filenames or nothing? My guess is the latter.
Where I think you might be lead astray a bit is that fileinput.input() returns an
instance of class FileInput, not necessarily data.
Your "if" clause will always return TRUE, regardless of whether there's data there or not.
If your cmdline was bare, FileInput.input() did exactly what it said it would do; waited on stdin. Try feeding your as-is test program a filename or two on the cmdline. See if it runs. It probably will (unless I'm completely off-base).
I'm not quite sure what to tell you about your design, I don't use FileInput very much at all (old schooler). I don't particularly like this class design -- there's no indicator that anything is READY for input, only if you have ALREADY read something. *grumble, mumble, kick desk*
At the scratch-the-surface level, I think I'd replace that leading "if" statement, then just iterate over sys.argv[1:] until I find a readable file. If I find one, then I execute your following "for" clause. I have no idea what FileInput.input() does when it encounters list tuples like these: ['valid.filename', 'not_a_valid_filename', 'another_valid_filename'] ... I just don't use this class myself. Also, if you don't ever want to read stdin, you've got to somehow pre-filter out '-' tokens. Yick.
Of course, while I'm iterating over those args, there's nothing stopping me from calling
open(sys.argv[i]) myself, which is exactly what I'd do. Sometimes trying to use a "convenience" class isn't very convenient :-)