Python, separate file handling
|
04-23-2021, 11:20 AM
Post: #1
|
|||
|
|||
Python, separate file handling
Hello,
When I first started discovering Python I thought that every file <more, files, new> could contain a separate program which could be started separately after selecting it, however this is to divide the total program into, clear, blocks. I have also discovered that the files are handled in the order indicated by <more, files> from the top to down. Are my “discoveries” correct? How can I change the order of the individual files so that the entire program is handled in (my) correct order? Does this mean that a copy of the Python app must be made for every program? Actually, I prefer HPPL over Python, also because of the fantastic <input> command. For me, the Python app is nice to learn more about Python. Cyrille, thanks for the new update. — Dirk Hartland |
|||
04-23-2021, 07:43 PM
Post: #2
|
|||
|
|||
RE: Python, separate file handling
(04-23-2021 11:20 AM)Dirk.nl Wrote: Hello, Being new to this Python stuff, I'm puzzled by this myself. What works however is what Tim described in Beta Notes, a snipped from there. For example: Code: #PYTHON name ppl(5) will print "35" This way your Python program exists in the PPL environment and can be called by its assigned name (ppl in this case). Günter |
|||
04-24-2021, 09:46 AM
Post: #3
|
|||
|
|||
RE: Python, separate file handling
File handling is via Python's 'import' mechanism. Each Python file is effectively treated in the same manner as external python libraries. The TI Inspire functions in the same way, as do Casio calculators.
Round trips via PPL appear to be less performant than using the numerical and symbolic views of the Python app itself. The numerical view is the Python terminal and the symbolic view is the Python text editor. |
|||
04-24-2021, 10:47 AM
Post: #4
|
|||
|
|||
RE: Python, separate file handling
Günter and Jonmoore,
Thank you for your response! It's about the more menu (betanotes.zip); “This allows you to “cut” a program in various chunks” I have tested this in the Python app, only with Python and not in combination with HPPL. Symb (editor); I have made three “new files” with three different programs. First “test1”, then “test2”, then “test3” In the pop-up screen at more -> files you will see these new files in the order from top to bottom; test3, test2, test1. Num (terminal); the program is loaded and started and running; first (chunk) test3 immediately followed by (chunk) test2 and (chunk) test1. So this is the order of the total program. My questions remain: 1 Can I change the order? 2 How does this dividing actually work? I thought this was made to make my program (in this case only a Python program) a bit more manageable. For instance; chunk1 initialization (declaration variables, etc), chunk2 definitions (functions, etc) and chunk3 the main program (calculations, etc). Or is this not the intention? Then why this possibility? Probably my thoughts are in the wrong direction. Thanks. — Dirk Hartland |
|||
04-24-2021, 11:14 AM
Post: #5
|
|||
|
|||
RE: Python, separate file handling
(04-24-2021 10:47 AM)Dirk.nl Wrote: Or is this not the intention? Then why this possibility? I don't believe things are functioning in an optimal manner right now. As the Python functionality improves over time, you should be able to have 10's even 100's of .py files within the Python apps content folder and call them up at will. Some will be standalone programs whilst others could be bespoke function libraries that use the 'import from xxxx ****' Python function library workflow. |
|||
04-24-2021, 12:51 PM
(This post was last modified: 04-24-2021 12:52 PM by Dirk.nl.)
Post: #6
|
|||
|
|||
RE: Python, separate file handling
Hi Jonmoore,
Thanks for your reply! What I have written before; I use HPPL to make (for myself) handy programs for my hobby (electronics). I use C++ for Arduino which is also fun to learn (structures, classes, etc) and I am reasonably adept at that at my level. For now I can use the Python app to learn Python, at a leisurely pace. BTW, I am a retired consultant (at a fairly old age) for offshore control systems; crane control and crane information systems, ballast control and ballast simulation systems, tensioners and abandonment and recovery winches (constant tension control), etc. I have a lot of experience with programming Siemens PLC systems in SCL (like Pascal). This info is not important (pff, why I write this) Thanks! — Dirk Hartland |
|||
04-24-2021, 05:14 PM
Post: #7
|
|||
|
|||
RE: Python, separate file handling
(04-24-2021 09:46 AM)jonmoore Wrote: Round trips via PPL appear to be less performant than using the numerical and symbolic views of the Python app itself. The numerical view is the Python terminal and the symbolic view is the Python text editor. I don't think that there is a discernible adverse effect on performance when invoking a Python script through PPL. The Python code seems to be directly processed by the Python interpreter. After all, the only PPL portion is just that call of the interpreter with the Python code. "PYTHON(name, param) Günter |
|||
04-24-2021, 06:52 PM
Post: #8
|
|||
|
|||
RE: Python, separate file handling
(04-24-2021 05:14 PM)Guenter Schink Wrote: I don't think that there is a discernible adverse effect on performance when invoking a Python script through PPL. The Python code seems to be directly processed by the Python interpreter. After all, the only PPL portion is just that call of the interpreter with the Python code. "PYTHON(name, param) I could of course be wrong, but plan to do some robust tests once the text editor in the Connection Kit functions properly. |
|||
04-24-2021, 10:34 PM
(This post was last modified: 04-24-2021 10:35 PM by Guenter Schink.)
Post: #9
|
|||
|
|||
RE: Python, separate file handling
(04-24-2021 11:14 AM)jonmoore Wrote: I don't believe things are functioning in an optimal manner right now. As the Python functionality improves over time, you should be able to have 10's even 100's of .py files within the Python apps content folder and call them up at will. Some will be standalone programs whilst others could be bespoke function libraries that use the 'import from xxxx ****' Python function library workflow. As I'm digging in more and more, I'm definitely missing a coherent description of the intended architecture. So far it seems to me that: The PPL environment is the place to create and store your Python executives. Whereas the files within the Python app are the place to define your independent modules. Example: Have a system wide module with a function to raise a number to a power of itself in the Python app: File name "test2.py" Code: def expself(x): Create a short PPL program that actually provides a python program and uses the module test2.py Code: #PYTHON name Editing is done with a lot of copy and paste. Unfortunately the G2 as well as the virtual calculator always reboot when chnaging from <HOME> to the Python app. It's not a big deal because almost nothing is lost. But annoying still. And the statement of Tim in the python.odt Quote:If you create a python file in your program (using the more/Files/New program function), you can call this script by doing PYTHON(“_name”, parameters) where name is the name of your python file. The “_” here serves as the marker for the system to know how to interpret the input.doesn't work for me. Günter |
|||
04-25-2021, 05:55 AM
(This post was last modified: 04-25-2021 05:55 AM by jonmoore.)
Post: #10
|
|||
|
|||
RE: Python, separate file handling
I think this is where great clarity will be needed in the final documentation
A further complication is that Python function names can also be used in the CAS as these are built into XCAS to provide compatibility for those more fluent with Python. They're not truly Python as they're not passed to the Python interpreter. At a fundamental level, the Python virtual machine is provided for education markets and in that scenario, it would be unacceptable for the primary workflow to be a hybrid PPL/Python workflow. In education environments, Python is considered as a first programming language. Incidentally, the intended use case is documented on the calculator if you enter the help card with the rollover state over the Python App. Apologies for the final line of text being cut off but you should still be able to get the gist. |
|||
04-25-2021, 07:17 AM
(This post was last modified: 04-25-2021 07:19 AM by StephenG1CMZ.)
Post: #11
|
|||
|
|||
RE: Python, separate file handling
I'd just like to point out for the benefit of those new to Python that there are a plethora of of version numbers in use.
For example, the screenshot references 3.4 but the latest download listed on micropython.Org is 1.15. Similarly, the Casio-specific version number is 3.4 but it is based on micropython 1.9.4. Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz |
|||
04-25-2021, 10:25 AM
Post: #12
|
|||
|
|||
RE: Python, separate file handling
(04-25-2021 07:17 AM)StephenG1CMZ Wrote: I'd just like to point out for the benefit of those new to Python that there are a plethora of of version numbers in use. As far as I know, the 3.4 relates to the version of Python that has the closest relationship to the version of MicroPython on the calculator. If somebody is learning Python for the first time using only the calculator, the Python 3.4 documentation is actually of more use than the MicroPython documentation, as this is primarily used to detail the commands that relate to programming a 'pyboard'. If you go to the page detailed below it explains what's more than likely happening in reality when using MicroPython on a calculator. The important detail of relevance here is that MicroPython is running as an emulation layer. With a 'pyboard', you're programming the board directly with MicroPython commands. https://micropython.org/unicorn/ |
|||
04-25-2021, 10:30 AM
Post: #13
|
|||
|
|||
RE: Python, separate file handling
(04-25-2021 07:17 AM)StephenG1CMZ Wrote: I'd just like to point out for the benefit of those new to Python that there are a plethora of of version numbers in use. According to:https://docs.micropython.org/en/latest/r...index.html Micropython aims to implement a subset of Python 3.4 |
|||
04-25-2021, 12:51 PM
Post: #14
|
|||
|
|||
RE: Python, separate file handling
Now the screenshot makes sense. Thanks.
Stephen Lewkowicz (G1CMZ) https://my.numworks.com/python/steveg1cmz |
|||
04-25-2021, 01:04 PM
Post: #15
|
|||
|
|||
RE: Python, separate file handling
Thanks for all your answers !
For the time being, I will continue (slowly) to discover the Python app. I leave the division of the program into chunks for a while. I'm waiting to see if something more will be documented about this, or maybe Cyrille can indicate something about this (no hurry !) — Dirk Hartland |
|||
04-26-2021, 09:25 AM
Post: #16
|
|||
|
|||
RE: Python, separate file handling
Hello,
The python app is designed for someone that is using python in a class room and needs to do a python exercise. It is also useful if you want a python console. Python integration with PPL is to allow you to use python in your normal programs. With all the normal program caveats: - standalone programs should be more "library" types. Stuff that you use from the command line - app programs are for larger/more complex programs and/or games In this context it will be best if you use: - CAS for symbolic math stuff... - Python when you need speed (games, stuff like that) - PPL for simple programs, system stuff and basically all the rest. AVOID switches from one "domain" to the other as much as possible, at best it will be slow, at worse it will cause crashes. Cyrille Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP. |
|||
04-26-2021, 09:42 AM
Post: #17
|
|||
|
|||
RE: Python, separate file handling
Thanks for the clarification Cyrille. I guessed things were much as you describe, but it's good to hear it from the 'horse's mouth' (a strange metaphor that one!).
|
|||
04-26-2021, 10:13 AM
Post: #18
|
|||
|
|||
RE: Python, separate file handling
Cyrille thanks for your answer !!
I got confused about the <New Program> selection in <More>. To me a new program is a really new program, you can select the newly created programs, indicated by a check mark. Then I thought; if I go to Num only this indicated program will be imported and run. Turns out everything is imported and run ! If I want to learn Python step by step with small programs, I will have to delete the previous one each time or copy the Python app a lot. How are they going to do this in the classroom anytime soon (with small programs), without having to deal with HPPL? Regards, Dirk — Dirk Hartland |
|||
04-26-2021, 11:45 AM
Post: #19
|
|||
|
|||
RE: Python, separate file handling
(04-26-2021 10:13 AM)Dirk.nl Wrote: Cyrille thanks for your answer !! As I suggested in another thread, you should double click on the Python App in the Connection Kit. It isn't fully functional right now, (it doesnt' update the calculator), but the framework is visible. It provides a lot of control and basic syntax highlighting in the text editor tab. This appears to be engineered with classroom use as a primary driver. It should also provide program/script management in a more user friendly fashion than attempting the same workflow on the calculator iteself. |
|||
04-26-2021, 12:11 PM
Post: #20
|
|||
|
|||
RE: Python, separate file handling
Hi Jonmoore,
Thank you, I did read your post. Will investigate this. Actually, I also find it easy to sit on the sofa and play with my calculator instead of a PC on my lap (smile !). Regards, Dirk — Dirk Hartland |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)