FAQ
Hi guys,

I am new to python and would like to import certain classes in sub-directories of the working directory. I was wondering how will I be able to achieve this?

Regards,
Nav

Search Discussions

  • Navkirat Singh at Aug 6, 2010 at 5:41 am

    On 06-Aug-2010, at 10:44 AM, Navkirat Singh wrote:

    Hi guys,

    I am new to python and would like to import certain classes in sub-directories of the working directory. I was wondering how will I be able to achieve this?

    Regards,
    Nav

    Thanks. I got it. I just put an empty __init__.py file in the subdirectories and it worked.
  • Ralf Schoenian at Aug 6, 2010 at 6:05 am

    Navkirat Singh wrote:
    Hi guys,

    I am new to python and would like to import certain classes in sub-directories of the working directory. I was wondering how will I be able to achieve this?

    Regards,
    Nav
    Hi,

    put an empty file with the name __init__.py in your subdirectory. I call
    it sub1 here. Assuming your filename is importme.py and your classname
    is Test you can do the following imports:

    from sub1.importme import Test
    import sub1.importme

    You can find further explainations in the official tutorial
    http://docs.python.org/tutorial/modules.html

    Regards,
    Ralf
  • 夏震 at Aug 6, 2010 at 7:43 am

    Hi guys,

    I am new to python and would like to import certain classes in sub-directories of the
    working directory. I was wondering how will I be able to achieve this?

    Regards,
    Nav
    --
    http://mail.python.org/mailman/listinfo/python-list
    >

    Please try "touch __init__.py" in sub-directories.
  • Navkirat Singh at Aug 6, 2010 at 1:15 pm
    On 06-Aug-2010, at 1:13 PM, ?? wrote:
    Hi guys,

    I am new to python and would like to import certain classes in sub-directories of the
    working directory. I was wondering how will I be able to achieve this?

    Regards,
    Nav
    --
    http://mail.python.org/mailman/listinfo/python-list
    Please try "touch __init__.py" in sub-directories.


    --
    http://mail.python.org/mailman/listinfo/python-list
    Thanks, that worked : )

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 6, '10 at 5:14a
activeAug 6, '10 at 1:15p
posts5
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase