Cannot run python script [duplicate]

2019-09-19 20:18发布

问题:

This question already has an answer here:

  • Syntax error on print with Python 3 [duplicate] 3 answers

I am trying to run this python script:

https://gist.githubusercontent.com/nk9/b150542ef72abc7974cb/raw/4a1e249976c6c330116fc068fb7001e3443c5b8d/largestFiles.py

but for some reason it contains a bunch of illegal characters and gives this error:

C:\tools\inspect>python largestFiles.py
  File "largestFiles.py", line 28
    print "Finding objects larger than {}kB\u2026".format(args.filesExceeding)
                                            ^
SyntaxError: invalid syntax

If I remove those illegal characters I still get:

C:\tools\inspect>python largestFiles.py
  File "largestFiles.py", line 28
    print "Finding objects larger than {}".format(args.filesExceeding)
                                         ^
SyntaxError: invalid syntax

Any ideas?

I am running it on windows 8 using python 3.4

回答1:

As print is function in python 3 you need to put your string in parenthesis. https://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function

>>> print ("Finding objects larger than kB\u2026")
Finding objects larger than kB…