python 2.7.2 command line argument problem
|
Hi i'm new to programming in python. While following the online tutorials from the book: 'learn python the hard way', i kept coming across the same problem. When i try to use command line arguments and run the script, i get an 'invalid syntax' error at the string that's printed out. Here's some code that just won't run. Any ideas why it won't? Any help would be appreciated. #!/usr/local/bin/env python import sys def main(): host = sys.argv[1] print "connecting to " + host + "..." if __name__ == '__main__': main() The error i get is: File "ex15.py", line 17 print "connecting to " + host + "..." ^ SyntaxError: invalid syntax I keep getting this type of error WHENEVER i try to use command line arguments in python 2.7.2 And, yes, i do pass command line arguments I run the script like this: C:\python\python ex15.py argument Any ideas? Thanks. |
Re: python 2.7.2 command line argument problem
Link |
by
on 2012-03-09 19:31:20
|
works fine for me. make sure that you have things properly indented. python is strict with white-space. |
Re: python 2.7.2 command line argument problem
|
Yesterday i thought, 'Maybe Gendou will answer it'. Immediately after i thought: 'Yeah right' O..k :) (kind of blown away) Thank you for answering. I'll check the indentation. checked the indentation: Wasn't it. But i got an idea. I've installed python 3 and 2.7 It seems python 3 just runs by default somehow when i run a script using 'python ex13.py' I have to run: 'C:/python27/python ex13.py argument1 argument2 argument3' for it to work properly. Thanks again, i'd just about given up. (currently torn between c and python) |