Daniel Power
Daniel Power

Reputation: 645

SyntaxError when running with Python 2

I have a Python script called "controlled_biomass_exp.py" that generates some data and plots it. Its over 100 lines long so I don't want to dump it all here.

I can run it from Ipython in the terminal once and it works fine. If I repeat the command to run the script again with:

In [3]: run controlled_biomass_exp.py

I get:

File "< ipython-input-3-3ec3d096e779>", line 1

run controlled_biomass_exp.py

                     ^

SyntaxError: invalid syntax

(The carrot is pointing at the last letter of the filename, "p".)

I get the same problem if I run any other python script after running this one. If I quit Ipython in the terminal and restart it the problem "re-sets". I can run other scripts fine, until I run the broken one once. I haven't encountered a problem like this before. Any help directing me where to look for solutions much appreciated.

Upvotes: 0

Views: 1124

Answers (1)

cel
cel

Reputation: 31349

It appears that your script controlled_biomass_exp.py overwrites run in your current namespace.

This toy example will produce a similar problem:

# file: test.py
run = "hello world!"
print(run)

Calling run in IPython is just a shortcut for %run which is a built-in magic function. Once you overwrite run (e.g. as shown in my toy example) you cannot use the shortcut anymore.

However, %run controlled_biomass_exp.py should still work for you.

Upvotes: 3

Related Questions