문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top