Post Reply 
HP Prime Python runs consecutive programs
09-24-2023, 03:50 PM (This post was last modified: 09-24-2023 03:51 PM by toml_12953.)
Post: #3
RE: HP Prime Python runs consecutive programs
(09-23-2023 05:57 PM)Guenter Schink Wrote:  
(09-22-2023 07:42 PM)Pellidon Wrote:  I have two scripts. When the first one is done, the second imports and runs. This does not occur on my Casio, Numworks or either TI calculators with Python. When the second one is done, it does not import back to the first file. Very strange.
Unfortunately the Prime doesn't allow for selected imports or runs. One work around is to enclose all programs in "def xx():" you do this on the Numworks too usually, don't you?

Consider you have 2 programs "main" and "another"

Then "main" may have as content:
Code:
def foobar():
    print("this is from main")

and "another" may have as content:
Code:
def foobar():
    print("this is from another")
Then upon starting Python you'll see both modules imported but not executed.

Entering "main.foobar()" will then show: "this is from main"
consequently
"another.foobar()" will then show: "this is from another"

That's a bit cumbersome, hopefully someone does a thorough repair on the Python implementation.

I'll elaborate a bit on this at the HHUC at Orlando.
HTH Günter

After an import, NumWorks will automatically run a program that is not included in a function.

If you import the program below, Numworks will automatically run the code and print 7. If you remove the # and indent the print statement, then nothing will run automatically when this code is imported.

Code:
def addit(x,y):
  return x+y

#def main():
print(addit(5,2))

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HP Prime Python runs consecutive programs - toml_12953 - 09-24-2023 03:50 PM



User(s) browsing this thread: 2 Guest(s)