In a bash shell, I can use 'bash ' or 'source ' to invoke a script by hand. Can I do the similar thing in the Python IDLE's interactive shell? I know I can go to File >> Open Module, then run it in a separate window, but that's troublesome.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
If what you meant is executing in the Python IDLE's interactive shell instead of command prompt or command line, then I usually use this approach:
python -m idlelib.idle -r "C:/dir1/dir2/Your script.py"
It works well with me. Tested on my Windows 10, python 3.7.3.
Please ensure that you have added your desired python version on your environment variables.
You can just run a Python script from the commandline:
One method I have found is
execfile
. It has the signatureexecfile(<filename>,<globals>,<locals>)
and runs the file in the same thread as the current IDLE Session. This method is Python 2 specificThe method the OP is asking for (in a different thread/window) would be to use
subprocess
to run in a different thread/window.These essentially do what nneonneo's answer does, but using
subprocess
to execute it in a different thread.