Python, separate file handling - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Python, separate file handling (/thread-16724.html) Pages: 1 2 |
Python, separate file handling - Dirk.nl - 04-23-2021 11:20 AM 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. RE: Python, separate file handling - Guenter Schink - 04-23-2021 07:43 PM (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 RE: Python, separate file handling - jonmoore - 04-24-2021 09:46 AM 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. RE: Python, separate file handling - Dirk.nl - 04-24-2021 10:47 AM 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. RE: Python, separate file handling - jonmoore - 04-24-2021 11:14 AM (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. RE: Python, separate file handling - Dirk.nl - 04-24-2021 12:51 PM 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! RE: Python, separate file handling - Guenter Schink - 04-24-2021 05:14 PM (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 RE: Python, separate file handling - jonmoore - 04-24-2021 06:52 PM (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. RE: Python, separate file handling - Guenter Schink - 04-24-2021 10:34 PM (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 RE: Python, separate file handling - jonmoore - 04-25-2021 05:55 AM 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. RE: Python, separate file handling - StephenG1CMZ - 04-25-2021 07:17 AM 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. RE: Python, separate file handling - jonmoore - 04-25-2021 10:25 AM (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/ RE: Python, separate file handling - Stevetuc - 04-25-2021 10:30 AM (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/reference/index.html Micropython aims to implement a subset of Python 3.4 RE: Python, separate file handling - StephenG1CMZ - 04-25-2021 12:51 PM Now the screenshot makes sense. Thanks. RE: Python, separate file handling - Dirk.nl - 04-25-2021 01:04 PM 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 !) RE: Python, separate file handling - cyrille de brébisson - 04-26-2021 09:25 AM 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 RE: Python, separate file handling - jonmoore - 04-26-2021 09:42 AM 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!). RE: Python, separate file handling - Dirk.nl - 04-26-2021 10:13 AM 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 RE: Python, separate file handling - jonmoore - 04-26-2021 11:45 AM (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. RE: Python, separate file handling - Dirk.nl - 04-26-2021 12:11 PM 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 |