include a python class in another python script.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • KraftDiner

    #1

    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?)

  • sjdevnull@yahoo.com

    #2
    Re: include a python class in another python script.

    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

    Comment

    • danielx

      #3
      Re: include a python class in another python script.


      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:



      Comment

      Working...