Is there a possibility to execute a Python script while being in interactive mode

后端 未结 6 1258
再見小時候
再見小時候 2020-12-23 09:10

Normally you can execute a Python script for example: python myscript.py, but if you are in the interactive mode, how is it possible to execute a Python script

6条回答
  •  借酒劲吻你
    2020-12-23 10:01

    import file without the .py extension will do it, however __name__ will not be "__main__" so if the script does any checks to see if it's being run interactively you'll need to bypass them.

    Alternately, if you're wanting to have a look at the environment after the script runs try python -i script.py

    EDIT: To load it again

    file = reload(file)

提交回复
热议问题