Question

I'm using python2.7, and have written a few functions for analyzing protein structure files, which I have saved as pdbtools.py One function, for example, is getprot() which lets me pull protein structures from a database.

After I open and edit the file and save it from python, I can then use all of the function definitions. However, when I start a new python session, it forgets all of my functions that I have written, so I have to %edit pdbtools.pdb, save it, and then I can run everything.

What's going on here? How do I use the functions that I have written?

Was it helpful?

Solution

If I understand right, you want open the interpreter and call the functions from that py script. To doing so in python 2.7 you should do two thing, go in the directory where the .py file reside and save and empty text file named:

__init__.py 

this tell the interpreter the files in that directory are good to import then use

import pdbtools 

as the first thing you do opening a new interpreter, this import that file and all the function inside it, making them ready to use from the interpreter prompt

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top