How can I use functions that I have created before, in different python files and projects? for example functions that I have created in project A I want to use in project B.
Asked
Active
Viewed 56 times
-1
-
5Does this answer your question? [How to import other Python files?](https://stackoverflow.com/questions/2349991/how-to-import-other-python-files) – KDD2020 Jun 02 '20 at 17:00
-
see this sample: https://repl.it/@willianvieira/BasicModuleImport – Willian Vieira Jun 02 '20 at 17:10
2 Answers
0
A.py contains
def myFunction():
print("Hello World")
you can call this function in your B.py by simply importing it
B.py contains
import A
A.myFunction()

desertnaut
- 57,590
- 26
- 140
- 166
0
You need to import like any other library you import in your python file. For example if you have a python script A.py and you are writing another python script B.py and you want to use some methods of A then you just need to import like this:
from A import *
Will import all the methods of A.
you can import a specific method only like this:
from A import method1
Thanks hope it helps

sdpshaw
- 46
- 7