From: Navkirat Singh on
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
From: Navkirat Singh on

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.


From: Ralf Schoenian on
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
From: 夏震 on


> 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.


From: Navkirat Singh on

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