Post Reply 
Python: How do I save a graphic?
09-09-2023, 09:29 AM
Post: #15
RE: Python: How do I save a graphic?
(01-05-2023 08:44 PM)Guenter Schink Wrote:  Consider you deal with a graphic G1 in Python and wish to save it as "pic.png" using the variable "b", a simple two liner would do:
hpprime.eval('AFiles(" '+b+' "):=G1')

It's important to use the single and double quotes as shown.

There is another solution, and it seems even better to me because MicroPython on HP Prime supports %-formatting of strings, which can be used here.
hpprime.eval('AFiles("%s"):=G0' %b)

It works Smile And as you can see, there is no use of string concatenation.

You can also create a string containing several placeholders marked with '%', and then specify all the variables you want to substitute into those places one by one:
s='My text - label %s: %d' %(a,b) 

and it prints:
My text - label number: 12345

Here '%s' is used to embed strings, '%d' for integers and '%f' for floating-point values.

Piotr Kowalewski
Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: Python: How do I save a graphic? - komame - 09-09-2023 09:29 AM

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