0

I am new to Python.Below is part of my python script

if( len(sys.argv) < 2 ):
    print "Please provide the SDK version!"
    print "Usage: python parse.py <sdk_version>"
    sys.exit(2)

sdk_version = sys.argv[1]
timestamp = int( time.time() )
created_on = datetime.datetime.fromtimestamp(timestamp).strftime( '%a %b %d %H:%M:%S %Z %Y' )

The input command I am giving is "python parse.py 8". But it is giving below error:

File "parse.py", line 10 print "Please provide the SDK version!" ^ SyntaxError: invalid syntax

What should be correct input.

3
  • 1
    Indentation matters in python and you should not mix tab and spaces.That is you have not provided any indentation at all Commented Aug 7, 2015 at 11:51
  • 1
    Which version of Python is python using? (the REPL usually shows this in startup) Commented Aug 7, 2015 at 11:55
  • Yes it is start up. Python 3.4 i am using. I want to know that what input parameter do i need to pass. When i comment the argument check then script runs well Commented Aug 7, 2015 at 11:58

2 Answers 2

1

SyntaxError means that there is a syntax error: In python3 there no longer is a print statement, instead there is a print function (that need to be called).

You should use print function instead of trying to use the print statement (note the parentheses around the text to be printed):

if( len(sys.argv) < 2 ):
    print("Please provide the SDK version!")
    print("Usage: python parse.py <sdk_version>")
    sys.exit(2)

sdk_version = sys.argv[1]
timestamp = int( time.time() )
created_on = datetime.datetime.fromtimestamp(timestamp).strftime( '%a %b %d %H:%M:%S %Z %Y' )
Sign up to request clarification or add additional context in comments.

Comments

1

Python 3 requires parentheses for print: print("Hello!")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.