Post Reply 
How to run Python (new Prime) ?
04-19-2021, 02:40 PM
Post: #1
How to run Python (new Prime) ?
Hello,
How can I run Python on a G2 ?
There is no Python app on my calculator (unboxed a week ago).
Should I install something ? Is there a documentation on this subject ?

thank you.

---
HP 48GX, Prime G2, 50G, 28S, 15c CE. SwissMicros DM42, DM15L
A long time ago : 11C, 15C, 28C.
Find all posts by this user
Quote this message in a reply
04-19-2021, 02:42 PM
Post: #2
RE: How to run Python (new Prime) ?
It is only Beta at this time. Look at the Beta threads.
Find all posts by this user
Quote this message in a reply
04-19-2021, 02:50 PM (This post was last modified: 04-19-2021 02:54 PM by OlidaBel.)
Post: #3
RE: How to run Python (new Prime) ?
(04-19-2021 02:42 PM)KeithB Wrote:  It is only Beta at this time. Look at the Beta threads.

I understood Running Python is not a new feature...
I see many posts on the web with Python examples, but none of them explain how they get Python module/app. I don't think only the new Beta can run Python.

---
HP 48GX, Prime G2, 50G, 28S, 15c CE. SwissMicros DM42, DM15L
A long time ago : 11C, 15C, 28C.
Find all posts by this user
Quote this message in a reply
04-19-2021, 02:56 PM (This post was last modified: 04-19-2021 02:59 PM by toml_12953.)
Post: #4
RE: How to run Python (new Prime) ?
(04-19-2021 02:50 PM)OlidaBel Wrote:  
(04-19-2021 02:42 PM)KeithB Wrote:  It is only Beta at this time. Look at the Beta threads.

I understood Running Python is not a new feature...
I see many posts on the web with Python examples, but none of them explain how they get Python module/app. I don't think only the new Beta can run Python.

You can also use Python syntax in a CAS program in the shipping version of the OS. Perhaps that's what those programs you see are doing.
Code:
#cas
def pyhat():
  t0 = ticks # Save the current clock count for timing program
  # Clear screen
  rect_p(0,0,319,239,rgb(0,0,0))
  # Start program proper
  p=160; q=120
  xp=144; xr=1.5*3.1415927
  yp=56; yr=1; zp=64
  xf=xr/xp; yf=yp/yr; zf=xr/zp
  for zi in range(-q,q+1):
    if zi>=-zp and zi<=zp:
      zt=zi*xp/zp; zz=zi
      xl=int(.5+sqrt(xp*xp-zt*zt))
      # Draw one cross-section of figure
      for xi in range(-xl,xl+1):
        xt=sqrt(xi*xi+zt*zt)*xf; xx=xi
        yy=(sin(xt)+.4*sin(3*xt))*yf
        x1=xx+zz+p
        y1=yy-zz+q
        pixon_p(x1,230-y1,rgb(0,255,0))
        if y1!=0:
          Line_p(x1,230-y1+1,x1,230) # Erase points below current point
  t = ticks-t0
  # Wait for key and print elapsed time
  wait
  print(approx(t/1000)+" seconds")
#end

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
04-19-2021, 03:11 PM
Post: #5
RE: How to run Python (new Prime) ?
(04-19-2021 02:56 PM)toml_12953 Wrote:  You can also use Python syntax in a CAS program in the shipping version of the OS. Perhaps that's what those programs you see are doing.
Code:
#cas
def pyhat():
  t0 = ticks # Save the current clock count for timing program
  # Clear screen
  rect_p(0,0,319,239,rgb(0,0,0))
  # Start program proper
  p=160; q=120
  xp=144; xr=1.5*3.1415927
  yp=56; yr=1; zp=64
  xf=xr/xp; yf=yp/yr; zf=xr/zp
  for zi in range(-q,q+1):
    if zi>=-zp and zi<=zp:
      zt=zi*xp/zp; zz=zi
      xl=int(.5+sqrt(xp*xp-zt*zt))
      # Draw one cross-section of figure
      for xi in range(-xl,xl+1):
        xt=sqrt(xi*xi+zt*zt)*xf; xx=xi
        yy=(sin(xt)+.4*sin(3*xt))*yf
        x1=xx+zz+p
        y1=yy-zz+q
        pixon_p(x1,230-y1,rgb(0,255,0))
        if y1!=0:
          Line_p(x1,230-y1+1,x1,230) # Erase points below current point
  t = ticks-t0
  # Wait for key and print elapsed time
  wait
  print(approx(t/1000)+" seconds")
#end

exactly. now it's ok. It was a hidden feature.
It's also case sensitive, "DEF" is not accepted, I must write "def", etc.
I'd rather try on a real keyboard !
at least, it works, Thank you.

---
HP 48GX, Prime G2, 50G, 28S, 15c CE. SwissMicros DM42, DM15L
A long time ago : 11C, 15C, 28C.
Find all posts by this user
Quote this message in a reply
05-11-2021, 06:59 PM
Post: #6
RE: How to run Python (new Prime) ?
If you are trying this code in cas,
first create and save the code exactly as is, in a program.
Delete any template code (EXPORT, BEGIN, END) lines.

Run the function, by calling <name of program>:<name of function>()

For example, if code is saved as test01,
in cas screen, type test01:pyhat()

Fast way: open the emulator,
copy/paste the code into a new program,
then use the connectivy kit, to transfer the program
to the physical Prime.
Find all posts by this user
Quote this message in a reply
Post Reply 




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