Python Forum

Full Version: How i can use categories with folder?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I want to know how can I import a subfolder?

I have tried with:
from test.test2 import file

but this isn't works.

Best regards
You don't import folders, you import packages and modules.

Are your trying to do this?
Output:
test |_test2 |_file
If so, the "test", "test2" and "file" folders need to contain a file named "__init__.py". This file can be empty. It's presence tells Python that this directory is part of a package.

if test2 is a Python file, and file is an object in the test2.py file, you only need an __init__.py file in the test folder.
Output:
test |_ __init__.py, test2.py
First read what the Python tutorial has to say about modules and packages