python-module

module

a module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable name.

when you run a Python module with

1
python fibo.py <arguments>

the code in the module will be executed, just as if you imported it, but with the name set to “main“. That means that by adding this code at the end of your module:

1
2
3
if __name__ == '__main__':
import sys
fib(int(sys.argv[1]))

you can make the file usable as a script as well as an imiportable module, because the code that parses the command line only runs if the module is executed as the “main” file.

python scripts vs. module

an answer to python exception message like ‘attempted relative module non-package’.

HERE IS THE ANSWER