How to call a function from another file in Python

0 votes

Hi Guys,

I have one function in a python file. I want to use this function in a different python file. How can I call a function from another file in python?

Jun 24, 2020 in Python by akhtar
• 38,210 points

1 answer to this question.

0 votes


You can use the import keyword to call your function. I have attached one example below. You can go through it.

Say you have one python file like this.

$ notepad
  def fun(x,y):
    z= x+y
    return (z)

Now you can call this function into a different python file like this.

from basic import fun

I hope this will give you some ideas.

answered Jun 24, 2020 by MD
• 95,300 points

Related Questions In Python

0 votes
1 answer

How to create and read from a temporary file in Python?

Hi, there is a very simple solution ...READ MORE

answered Jan 29, 2019 in Python by Nymeria
• 3,520 points
0 votes
0 answers
0 votes
2 answers
0 votes
1 answer

I want to download a file from the website by web scraping. Can anyone explain how to do this in jupyter lab (python) with an example?

Hey, Web scraping is a technique to automatically ...READ MORE

answered Apr 7, 2020 in Python by Gitika
• 65,950 points
0 votes
3 answers

Python Selenium best tutorials for beginners

Hope this will help you...Python Tutorial READ MORE

answered Feb 11, 2019 in Python by aldrinjohn
• 140 points
0 votes
1 answer

How to transfer multiple lines in a file using python?

Hi@akhtar, I don't know it will help you ...READ MORE

answered Mar 31, 2020 in Python by MD
• 95,300 points
0 votes
1 answer

How to crop face from a photo using cv2 in python?

Hi@akhtar, You can do this task using cv2 ...READ MORE

answered Apr 9, 2020 in Python by MD
• 95,300 points