I try to pass command line argument to python script under win7, but the length of sys.argv always equals to one. Is that means it fails to recognize the argument? Here is the code and command line:
import sys
def Cat(filename):
f = open(filename, 'r')
for line in f:
print(line)
def main():
if len(sys.argv) > 1:
Cat(sys.argv[1])
else:
print(input('enter argument: '))
if __name__ == '__main__':
main()
Here is my command line:
F:\Google's_python_class\part1>Cat.py small.txt
But the result is
enter argument:
SOLVED:
There are two solutions:
c:\...\python\python.exe Cat.py small.txt