Python Student Question

Something's not working with my input exercises. I'm long past school - just learning for my interest.
The code is below and the results follow. The error has the carat under the second quotation mark in line 8.
I can't figure out what it's complaining about. Thoughts??

from sys import argv

script, filename = argv

txt = open(filename)

print "Heres your file %r:"  % filename

print "Type the filename again:"
file_again = raw_input("> ")

txt_again = open(file_again)


C:\Users\admin\PycharmProjects\MessinRound1>python abc.t
  File "", line 8
    print "Heres your file %r:"  % filename
SyntaxError: invalid syntax
amigan_99Network EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I can't reproduce the error with my Linux Python installation. At first I thought that, Python being sensitive to white space, that having two spaces before the % was somehow causing a problem. But it didn't cause a problem for me.

That leads me to think that you may have some weird extra character in your file which didn't survive the cut-and-paste when you posted it here.

So the first thing to try is to cut what you posted and put that in a file and try to run it.
It may be the case that you are running the Python 2 script using the Python 3 interpreter. I tried it with Python 3.4.3 where the error is more detailed:
  File "", line 7
    print "Heres your file %r:"  % filename
SyntaxError: Missing parentheses in call to 'print'

Open in new window

amigan_99Network EngineerAuthor Commented:
Thanks. I'll try to run it tomorrow with paren.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

As you use Windows, I suggest to install the latest Python 3 -- it installs also Python Launcher for Windows (the c:\Windows\py.exe and pyw.exe). Remove any Python directory from your PATH. Install the latest Python 2 also.

Then put #!python2 as the first line of your script. This way you will be able to launch it via typing its name to the command line (without explicit invoking the Python interpreter). The #! line will be used by the Python launcher to detect and use the newest installed Python 2 interpreter. The #!python3 says to use the installed Python 3 interpreter. Using that line, you can write both Python 2 and Python 3 scripts and launch them a unified way. If you need to launch it explicitly, use py (instead of python; py.exe is in PATH, because c:\Windows is always in PATH). The py.exe is the one that checks the #! line and launches the correct interpreter.

See for more details.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amigan_99Network EngineerAuthor Commented:
I simplified the code to ...

print "How now brown cow"

  File "", line 3
    print "How now brown cow"
SyntaxError: invalid syntax

print ("How now brown cow")

How now brown cow

If I run the simple script in pycharm IDE either way is fine.

I looked at the output window and pycharm and say that it was running:

C:\Anaconda\python.exe C:/Users/admin/PycharmProjects/MessinRound1/

So the python installed with Anaconda is good and as pepr suggested it's version related.

amigan_99Network EngineerAuthor Commented:
Thanks much!
You are welcome ;)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.