python - Importing modules from nested folder -


this question has answer here:

i have folder structure

main_folder | |--done |  | |  |--test1 |  |--__init__.py | |---check.py 

__init__.py:

class tries(object):     def __init__(self):         print "test" 

check.py:

from done.test1 import tries tries() 

error:

--------------------------------------------------------------------------- importerror                               traceback (most recent call last) <ipython-input-8-10953298e1df> in <module>() ----> 1 done.test1 import tries  importerror: no module named done.test1  

i not able import modules nested folder. there way this.

edit:

after salva's answer changed structure

. ├── check.py |--__init__.py(no content) └── done     ├── __init__.py(no content)     └── test1         └── __init__.py <-- files contains tries class 

same error thrown also.

you need file __init__.py in each directory want considered package need in both directories:

. ├── check.py └── done     ├── __init__.py     └── test1         └── __init__.py <-- files contains tries class 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -