I have a pycharm project with one python file called main.py
on my desktop i have a folder called ‘Python’ inside it looks like this:
JavaScript
x
7
1
- Desktop
2
- framework.py
3
- Python
4
- Python Projects
5
- Project File
6
- main.py
7
In my main file i want to import a function from the framework file. for example if my framework file looks like this:
JavaScript
1
3
1
def print_hi():
2
print("hi")
3
how would i import the function into my main file?
Advertisement
Answer
in the python structure for import, you should use system layout I mean:
JavaScript
1
9
1
parent/
2
__init__.py
3
one/
4
__init__.py
5
two/
6
__init__.py
7
three/
8
__init__.py
9
so first of all use init file the simply use import