468,133 Members | 1,236 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,133 developers. It's quick & easy.

include a python class in another python script.

I have a class that is defined in a file called MyClass.py

How do I use that class in another python script..
import MyClass ? (Does it need to be in a specific location?)

Aug 15 '06 #1
2 2673
KraftDiner wrote:
I have a class that is defined in a file called MyClass.py

How do I use that class in another python script..
import MyClass ? (Does it need to be in a specific location?)
Same directory as the script that's importing it, or in the PYTHONPATH.

import sys
print sys.path

Aug 15 '06 #2

KraftDiner wrote:
I have a class that is defined in a file called MyClass.py

How do I use that class in another python script..
import MyClass ? (Does it need to be in a specific location?)
MyClass.py has to be on your "python path". Your python path is a list
of directories python will search (in order) when you do an import
statement. By default, your current working directory is the first
place Python will search. You can also customize your python path.
Check out this part of the docs for more info:

http://docs.python.org/inst/search-p...ml#search-path

Aug 15 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

43 posts views Thread by steve | last post: by
3 posts views Thread by Tubby Tudor | last post: by
11 posts views Thread by dmbkiwi | last post: by
10 posts views Thread by Andrew Dalke | last post: by
68 posts views Thread by Lad | last post: by
8 posts views Thread by Paul Cochrane | last post: by
11 posts views Thread by cybervigilante | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.