How does python work?
|
09-06-2021, 04:37 PM
Post: #1
|
|||
|
|||
How does python work?
I recently upgraded my Prime to the latest firmware and I'm trying to understand how to write python functions/scripts. I didn't seem to find much a solution while perusing older threads.
Let's say my script looks like this: PHP Code: def func1(a, b): I know this is a contrived example, but I just want to know how to make it work. The question is, how do I call func3 ? |
|||
09-06-2021, 04:53 PM
Post: #2
|
|||
|
|||
RE: How does python work?
This will work
Code: def func1(a, b): return a + b def func2(a, b): return a - b def func3(a, b, c): if c == 0: return func1(a, b) else: return func2(a, b) d=func3(4,2,0) |
|||
09-06-2021, 05:01 PM
Post: #3
|
|||
|
|||
RE: How does python work?
(09-06-2021 04:53 PM)Dougggg Wrote: This will work Maybe, I didn't explain properly. I am not looking to run the code from the python app. I am looking to run the code from the place where you do regular calculations. For example, if I was using python-syntax under XCas, I would do the following: PHP Code: #cas I'm looking to do the same but with python, not XCas. |
|||
09-06-2021, 08:15 PM
(This post was last modified: 09-06-2021 08:16 PM by roadrunner.)
Post: #4
|
|||
|
|||
RE: How does python work? | |||
09-07-2021, 07:45 AM
Post: #5
|
|||
|
|||
RE: How does python work?
(09-06-2021 08:15 PM)roadrunner Wrote: Just paste your program exactly as written into a prime program file: Yes, but this doesn't run the program as a python code. It runs it as an XCAS program. It just so happens that XCAS can accept some python syntax. What I am asking how to run python code, not XCAS with python-like syntax. |
|||
09-07-2021, 12:06 PM
Post: #6
|
|||
|
|||
RE: How does python work?
Maybe the PYTHON command is what you are looking for?
Code: #PYTHON test |
|||
09-07-2021, 09:24 PM
Post: #7
|
|||
|
|||
RE: How does python work?
(09-07-2021 12:06 PM)roadrunner Wrote: Maybe the PYTHON command is what you are looking for? Thanks for this. But how do you display the result in the calculations window like regular functions so that they can be used. At the moment, the result only shows in the terminal. |
|||
09-07-2021, 10:05 PM
Post: #8
|
|||
|
|||
RE: How does python work?
I think you would have to save it as a variable, then do what ever you want with the variable like in the following example:
PHP Code: #PYTHON test You can also save it as a home variable with hpprime.eval instead of cas.caseval. -road |
|||
09-08-2021, 10:48 AM
Post: #9
|
|||
|
|||
RE: How does python work?
(09-07-2021 10:05 PM)roadrunner Wrote: I think you would have to save it as a variable, then do what ever you want with the variable like in the following example: Thanks for this. This seems more complicated than I hoped for. Is there some resource I can use to learn things like this? |
|||
09-08-2021, 11:08 AM
Post: #10
|
|||
|
|||
RE: How does python work?
I don't know of any resources. There may be a better way to do what you want but that's the best I could come up with. Everything I know about Python on the prime was learned by trial and error (mostly error), and by reading posts in this forum.
-road |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)