+ 3
Code to restart script within the Shell.
I want to be able to restart my script within the python shell. The current code I'm using gives me the error that "os" is not defined. Any suggestions?
7 Réponses
+ 1
I couldn't get the recommended code to work so I decided on using.
def start():
print("example")
start()
start()
+ 10
import os
+ 3
if your python version is 3, use importlib.reload(yourModuleName) .
+ 1
It didn't work. Module name is the name of my file right?(test.py). If so the code didn't work, gave me this error:
File "C:\Users\Student\Desktop\Test.py", line 188,in <module>
importlib.reload(test.py)
NameError: name 'importlib' is not defined.
Apologies if I fail to understand some things, I'm quite new to this.
Should I be using the directory path in the module?
+ 1
Just import 'importlib' module first because it is a module like your code, right? Then You can use reload function.
Like this:
from importlib import reload
then, reload(test)
+ 1
The error has changed to
NameError: name 'test' is not defined.
What does it mean :/
0
You must import your code aka module first. reload function just ..well.. reload specific module without restarting interpreter.