0

I am new to Python,
I tried to execute file with code:

import sys
def main():
    print sys.argv[1]

main()

For this run: hello.py from command line, but got

C:\Python34>hello.py
File "C:\Python34\hello.py", line 4
print sys.argv[1]
        ^
SyntaxError: invalid syntax

Could someone help me with this issue?

cadrian
  • 7,332
  • 2
  • 33
  • 42
khris
  • 4,809
  • 21
  • 64
  • 94

3 Answers3

5

In Python 3.x print is no longer a statement, it is a function print(), and as suggested in PEP8, you should ident your code with 4 space per level.

import sys
def main():
    print(sys.argv[1])

main()
jabaldonedo
  • 25,822
  • 8
  • 77
  • 77
3

Python 3.4 requires brackets parentheses around prints. E.g. print(sys.argv[1])

milmulho
  • 46
  • 2
-1

Try to insert a tab before "print sys.argv[1]"