Oct-11-2022, 03:05 PM
Agree with ndc85430. You should try to write a python module in a way that other modules can import the useful parts.
Let's say your add.py program adds the command line arguments, which must be numbers, and prints the result. You could write as:
add.py
file test.py
Let's say your add.py program adds the command line arguments, which must be numbers, and prints the result. You could write as:
add.py
import sys def Add(*numbers): """Add a list of numbers, Retrurn total.""" return sum(numbers) if __name__ == "__main__": print(sys.argv[1:]) print(Add(*map(float, sys.argv[1:])))You can run this as a program, but you can also import it and use the function.
file test.py
import add print(add.Add(1, 2, 3, 4))