Question

I am using the Anaconda command prompt, with Python - in Windows 8. I have a py file containing containing a number of "Helper Functions".

How do I import this file in to the command prompt I am using so future operation will recognize the function calls and execute them appropriately?

Était-ce utile?

La solution

If by command prompt, you mean that the python interactive shell and you want to import the module every time you start the interactive shell, you can use the .pystartup file to import the relevant modules so that they are always available when you start the interpreter.

On Linux, you can edit the file /home/username/.pystartup to add:

import mod1
import mod2

Have an environment variable which points to the ~/.pystartup file

$ export PYTHONSTARTUP=~/.pystartup

And then use the python interactive shell use the modules loaded in ~/.pystartup

$ python 
>> mod1.something

On Windows, you can do the same by adding the environment variable PYTHONSTARTUP with value some_windows_path (I keep mine in C:\python27\pystartup.py) via Computer->Advanced Settings->Environment variables.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top