I'm trying to check that a user of this code runs this program from command line using only one command line parameter (the name of the file). When I run this code like this (I'm on windows)
C:\>python program.py
Usage: program.py <file.txt>
C:\>
Right. But when I run this program using a file I want to manipulate, I get nothing printed:
C:\>python program.py file.txt
C:\>
Where's the problem, my code is here
#!/Python26/
# -*- coding: utf-8 -*-
import sys
def main(argv):
if len(argv) < 2:
sys.stderr.write("Usage: %s <file.txt>" % (argv[0],))
return 1
if __name__ == "__main__":
sys.exit(main(sys.argv))
f = open(sys.argv[1])
lines = f.readlines()
f.close()
for line in lines:
line = line.strip()
etc...