iggy
iggy

Reputation: 31

Input parameter for python

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.

Upvotes: 0

Views: 106

Answers (2)

Matthew Iselin
Matthew Iselin

Reputation: 10670

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

Upvotes: 1

skyking
skyking

Reputation: 14360

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' )

Upvotes: 1

Related Questions