-1

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.

2 Answers2

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