Skip to content
Advertisement

Why do I need to introduce the arguments when importing the functions of one file

I have a program (file1.py) with functions and I want to test these functions from the file test1.py. When I import the first function I don’t know why the terminal tells me that I need to introduce the arguments that are required when I run file1.py. Is beyond my understanding why this happens because as far as I know from test1.py I am taking the first function and not the complete file1.py.

file1.py (until the first function)

JavaScript

And my test1.py

JavaScript

The output:

JavaScript

Advertisement

Answer

You have to structure file1.py as follows if you don’t want to run the “main” part every time you import this file from some other Python file:

JavaScript

For a better explanation, see.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement