0

I made this small program :

program

I wanna know how to automatically call it, so that when I open the .py it shows up immediatly. Please understand that I am a beginner in Python.

DYZ
  • 55,249
  • 10
  • 64
  • 93
  • You mean when you automatically call it, it produces output, right? Your wording are confusing. what do you mean by `it shows up immediatly. ` – Sheldore Sep 16 '18 at 16:37
  • Please post the code as text. – Agile_Eagle Sep 16 '18 at 16:38
  • Possible duplicate of [What does it mean to "call" a function in Python?](https://stackoverflow.com/questions/19130958/what-does-it-mean-to-call-a-function-in-python) – Agile_Eagle Sep 16 '18 at 16:40

3 Answers3

0

You can call it like this:

# Add this lines at the end of your code

table_par_7()
Agile_Eagle
  • 1,710
  • 3
  • 13
  • 32
0

If you mean:- (1) When you will run the .py file, how to call it. Then the answer is, you will have to write the name of function and press ENTER to execute it. (2) When you will open the .py file from any folder, is it possible to print final result. The the answer is a big NO. This is because using def in any program is just a keyword to create function. It do not have any property by which it will execute by its own. It must be called by the system which is known as system call.

Kasturi
  • 21
  • 5
0

The right way to do this is to add the following statement in the end of the file:

if __name__ == "__main__":
    table_par_7()

Explanation

This will ensure that if you open the file directly (and thus makes it the main file), the function will run, but if another python file imports this file (thus this file isn't the main one), it wont run.