Restriction 1: Safe importing of main module
- Problem:
Running the script below would fail with a RuntimeError
The error should be like this
- Solution:
In the python document above, it states:
Make sure that the main module can be safely imported by a new Python interpreter without causing unintended side effects (such a starting a new process).That means we need to put the all the commands inside a if __name__ == '__main__': block. That will prevent calling a new process (could be unintended) when import that module.
The code should be look like this
No comments:
Post a Comment