I am working on a Python Project and want to call multiple functions from other python files, but I'm having trouble. Can someone please help me?
Asked
Active
Viewed 49 times
-3
-
Please read [ask] – klutt Sep 19 '19 at 13:21
-
You import them. What exactly are you having trouble with? – chepner Sep 19 '19 at 13:21
-
I want to call a function from another python file. For example: I want to call a function inside of Application.py from Main.py. – ScotthomasPrime Sep 19 '19 at 13:29
-
please do a little search on how to create your own python module , and come back with your code if things not going well – James Li Sep 19 '19 at 13:32
-
you can start from here [how-to-write-a-python-module-package](https://stackoverflow.com/questions/15746675/how-to-write-a-python-module-package) – James Li Sep 19 '19 at 13:33
-
Well, I just created my account and i'm new to Stack Overflow – ScotthomasPrime Sep 19 '19 at 13:34
-
Possible duplicate of [How to write a Python module/package?](https://stackoverflow.com/questions/15746675/how-to-write-a-python-module-package) – chakeda Sep 19 '19 at 15:34
1 Answers
0
Each of your Python file can act as a module, that you can import.
for example for numpy you just type 'import numpy' and then you'll be able to use numpy.sin() function.
by default you can only append modules located in sys.path. So What you can do is:
import sys
if not (<folder_with_your_function> in sys.path):
sys.path.append( <folder_with_your_function> )
import <your_function>

Adrien Mau
- 181
- 5
-
-
You're welcome.. It's not the best way to do it but it will work. if you want to be cleaner, take a look at 'init.py' files. – Adrien Mau Sep 19 '19 at 13:55