Python: Multiple Files
|
05-22-2021, 07:33 AM
Post: #6
|
|||
|
|||
RE: Python: Multiple Files
I've gotten around this by not including `while True`, `if __main__:` and similar in my Prime Python scripts. I think of them not as programs that you run, but as functions that you load into memory.
For example, if I have a script called names.py: Code:
I intentionally don't call the `get_name()` function inside the script. Instead, the function will be imported from my script when I switch to the Numeric view (`> import names`), and I'll call the function from the Numeric REPL using the script's namespace: `names.get_name()`. This is similar to the Numworks sample scripts. They do let you choose which script to import instead of importing all of them, but you still enter the main function in the script ("simulation(), mandelbrot(), etc.") into the REPL to make it do something. However, having to enter the complete namespace and function name using the calculator keypad is cumbersome. Two approaches to this could be:
-DrBarnack |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Python: Multiple Files - Eddie W. Shore - 05-09-2021, 09:38 PM
RE: Python: Multiple Files - Dougggg - 05-09-2021, 10:39 PM
RE: Python: Multiple Files - Dougggg - 05-09-2021, 10:53 PM
RE: Python: Multiple Files - toml_12953 - 05-10-2021, 02:13 AM
RE: Python: Multiple Files - Dirk.nl - 05-10-2021, 09:59 AM
RE: Python: Multiple Files - drbarnack - 05-22-2021 07:33 AM
|
User(s) browsing this thread: