0

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.

5
  • I'm not familiar with iPython but does your script contain a run function? One that overrides the original. Commented Nov 18, 2014 at 12:18
  • Hi Rik. The script doesn't contain any run functions. Commented Nov 18, 2014 at 13:16
  • Hi Daniel, in that case, maybe you could post the code so we can check for problems there. Commented Nov 18, 2014 at 13:19
  • Have you tried to use python instead of run ? open terminal and enter python controlled_biomass_exp.py. Of course you have to be in directory where this file located Commented Nov 18, 2014 at 13:33
  • Thanks Rik, micgeronimo. I can see now you were both pointing me in the right direction. Commented Nov 21, 2014 at 8:55

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks cel. This was exactly the problem. I knew it would be something daft. I had a loop of "runs" with a variable "run". Once I changed the name of this, everything is awesome!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.