import a user created python file as module

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

    import a user created python file as module

    Hi,
    I have the following directory structure in my project.
    Base:
    file1.py
    file2.py
    Directory1:
    file1-dir1.py

    I am able to import file1 into file2.py
    What I need to do is, import file1 in the file file1-dir1.py.
    I did not create the entire dir structure as package. Adding
    __init__.py file in both Base: as well as Directory1: is not helpful. I
    am unable to import file1 in the file1-dir1.py. It is not able to find
    the path of the file1.py.

    How and what should I do to import file1.py into file1-dir1.py ? Please
    give me some references to the tutorial topic which I can study as
    well.

    Thanks,
    Senthil

  • Amit Khemka

    #2
    Re: import a user created python file as module

    On 30 Jul 2006 23:07:07 -0700, Phoe6 <orsenthil@gmai l.comwrote:
    Hi,
    I have the following directory structure in my project.
    Base:
    file1.py
    file2.py
    Directory1:
    file1-dir1.py
    >
    I am able to import file1 into file2.py
    What I need to do is, import file1 in the file file1-dir1.py.
    I did not create the entire dir structure as package. Adding
    __init__.py file in both Base: as well as Directory1: is not helpful. I
    am unable to import file1 in the file1-dir1.py. It is not able to find
    the path of the file1.py.
    >
    How and what should I do to import file1.py into file1-dir1.py ? Please
    give me some references to the tutorial topic which I can study as
    well.
    Modify the path where python searches for modules, for example in
    file1-dir1.py add:

    import sys
    sys.path.append ("/path/to/Base")
    import file1


    cheers,
    amit.
    --
    ----
    Amit Khemka -- onyomo.com
    Home Page: www.cse.iitd.ernet.in/~csd00377
    Endless the world's turn, endless the sun's Spinning, Endless the quest;
    I turn again, back to my own beginning, And here, find rest.

    Comment

    • Rob Wolfe

      #3
      Re: import a user created python file as module


      How and what should I do to import file1.py into file1-dir1.py ? Please
      give me some references to the tutorial topic which I can study as
      well.
      And some reference:



      Regards,
      Rob

      Comment

      Working...