include a python class in another python script.

Discussion in 'Python' started by KraftDiner, Aug 15, 2006.

  1. KraftDiner

    KraftDiner Guest

    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?)
     
    KraftDiner, Aug 15, 2006
    #1
    1. Advertisements

  2. KraftDiner

    sjdevnull Guest

    Same directory as the script that's importing it, or in the PYTHONPATH.

    import sys
    print sys.path
     
    sjdevnull, Aug 15, 2006
    #2
    1. Advertisements

  3. KraftDiner

    danielx Guest

    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-path.html#search-path
     
    danielx, Aug 16, 2006
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.