Skip to content

Instantly share code, notes, and snippets.

@zhangzhhz
Last active June 4, 2020 06:23
Show Gist options
  • Save zhangzhhz/a5443eacb448fd1624c75492d325dbdc to your computer and use it in GitHub Desktop.
Save zhangzhhz/a5443eacb448fd1624c75492d325dbdc to your computer and use it in GitHub Desktop.
Python: load a script in Python shell

Python: load a script in Python shell

This is usually for some quick testing.

  1. python -i myscript.py

    Then you can reference functions and variables in the script directly.

  2. While you are already in a Python shell:

    2.1. import myscript

    Then you can reference functions and variables in the script by prefixing with myscript..

    2.2.

    • python2:

      execfile('myscript.py')

    • python3:

      exec(open('myscript.py').read())

    Then you can reference functions and variables in the script directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment