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,202
  • 2
  • 32
  • 42
khris
  • 4,501
  • 18
  • 60
  • 93

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
  • 24,746
  • 8
  • 73
  • 76
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]"