Import a script in IDLE
To import a script from IDLE, you can do:
>>> import os
>>> os.chdir('C:\\Users\\You\\Some\\Arbitrary\\Path')
>>> import scriptname
Keep in mind that you will need to call constructors with scriptname.
prepended, like scriptname.myClass(...)
If you change something in the script, you will need to reload it like this:
>>> import imp
>>> imp.reload(scriptname)
(There is a simpler way if you just want to play around with types from one script, and if the script only contains function and class definitions (no running code). Then you can simply open the script in IDLE and go to Run>Run Module
. When you use this method, it is not necessary to put scriptname.
before constructors.)
In idle you could append a path containing your scriptname.py file.
>>> import pprint
>>> import sys
>>> print pprint.pprint(sys.path)
# you could just move your scriptname.py to a directory in the sys.path list
>>> sys.path.append(r"C:\Users\You\")
>>> import scriptname
You could also customize the PYTHONPATH environment variable in windows to include other directories like "C:\Users\You\lib"