1

I ran my script from Python environment launched in bash:

>>> import myscript

I then modified my script a little and save it. Then run again

>>> import myscript

But it doesn't run the updated script.

How can I tell Python to run the updated one? Thanks!

1

2 Answers 2

4

Simply reload it like this

reload(myscript)

Quoting from the docs,

Reload a previously imported module. The argument must be a module object, so it must have been successfully imported before. This is useful if you have edited the module source file using an external editor and want to try out the new version without leaving the Python interpreter.

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

4 Comments

so the syntax for import is import myscript not import(myscript), while for reload is reload(myscript) not reload myscript?
@Tim reload is actually a function, so you need to use it like that only, whereas import is a keyword in the language.
Thanks. Is import not a function? What is it? (don't say it is a keyword. the name of a build in function is a keyword too)
@Tim Keyword is different from a builtin function. The line which has import will be normally called as import statement. You cannot use that as a variable.
2

reload builtin is what you actually need: https://docs.python.org/2/library/functions.html#reload

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.