Post Reply 
Python: How do I save a graphic?
10-06-2021, 10:50 PM (This post was last modified: 10-06-2021 10:51 PM by Guenter Schink.)
Post: #1
Python: How do I save a graphic?
In my App Mandelbrot Explorer I tried to save a picture in graphic G1 by:

name="tst.jpg"
hpprime.eval("MandelExpl.AFiles(name):=G1")

this line is executed without any error, but there is no graphic stored. When I terminate the App, I still can save this picture from the command line by AFiles(name):=G1. And then it shows up in the connectivity kit as a file at the right place.

Does someone have a clue?

Günter
Find all posts by this user
Quote this message in a reply
10-06-2021, 11:01 PM
Post: #2
RE: Python: How do I save a graphic?
(10-06-2021 10:50 PM)Guenter Schink Wrote:  In my App Mandelbrot Explorer I tried to save a picture in graphic G1 by:

name="tst.jpg"
hpprime.eval("MandelExpl.AFiles(name):=G1")

this line is executed without any error, but there is no graphic stored. When I terminate the App, I still can save this picture from the command line by AFiles(name):=G1. And then it shows up in the connectivity kit as a file at the right place.

Does someone have a clue?

Günter

Have you tried:

name="tst.jpg"
hpprime.eval("MandelExpl.AFiles(" & name & "):=G1")

or

hpprime.eval("MandelExpl.AFiles(tst.jpg):=G1")

?

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
10-07-2021, 04:21 PM
Post: #3
RE: Python: How do I save a graphic?
If you are trying to put tst.jpg into G1, should it be:

hpprime.eval("G1:=MandelExpl.AFiles(name)")

?

-road
Find all posts by this user
Quote this message in a reply
10-07-2021, 09:19 PM
Post: #4
RE: Python: How do I save a graphic?
Thanks for your inputs, but that didn't help

Anyway a little bit of progress.

When I end the Mandelbrot Explorer, and I am in "Python Numeric View" and I enter

Code:
from hppprime import *
eval('AFiles("test.png"):=G1')

then G1 is successfully stored in test.png. But when I exchange quotes and double quotes a Syntax Error is raised. So far so good, that's an easy one.

Next try:
Code:
from hppprime import *
aa="test.png"
eval('AFiles(aa):=G1')

Results in Syntax Error

Next try:
Code:
from hppprime import *
aa="test.png"
xx=eval('AFiles(aa):=G1')

No Error, but also no file: test.png
type(xx) gives <class 'str'>, but print(xx) gives Error:Syntax Error of course as you can't print a class. I think.

Next try: Function in the Mandelbrot Explorer

Code:
def save():
    eval('AFiles("test3.png"):=G1')
    line(0,0,240,320,0,0) #to show the function was executed

Tataa test3.png is there

Next try:
Code:
def save():
    aa="test3.png"
    eval('AFiles(aa):=G1')          #prefacing with xx=  doesn't change anything
    line(0,0,240,320,0,0) #to show the function was executed
No error, but also no file,
Hmm ....

Conclusion so far: providing a file name directly works but submitting a file name as a variable does not.

any suggestions?
Günter
Find all posts by this user
Quote this message in a reply
10-07-2021, 10:25 PM
Post: #5
RE: Python: How do I save a graphic?
(10-07-2021 09:19 PM)Guenter Schink Wrote:  Thanks for your inputs, but that didn't help

Anyway a little bit of progress.

When I end the Mandelbrot Explorer, and I am in "Python Numeric View" and I enter

Code:
from hppprime import *
eval('AFiles("test.png"):=G1')

then G1 is successfully stored in test.png. But when I exchange quotes and double quotes a Syntax Error is raised. So far so good, that's an easy one.

Next try:
Code:
from hppprime import *
aa="test.png"
eval('AFiles(aa):=G1')

Results in Syntax Error

Next try:
Code:
from hppprime import *
aa="test.png"
xx=eval('AFiles(aa):=G1')

No Error, but also no file: test.png
type(xx) gives <class 'str'>, but print(xx) gives Error:Syntax Error of course as you can't print a class. I think.

Next try: Function in the Mandelbrot Explorer

Code:
def save():
    eval('AFiles("test3.png"):=G1')
    line(0,0,240,320,0,0) #to show the function was executed

Tataa test3.png is there

Next try:
Code:
def save():
    aa="test3.png"
    eval('AFiles(aa):=G1')          #prefacing with xx=  doesn't change anything
    line(0,0,240,320,0,0) #to show the function was executed
No error, but also no file,
Hmm ....

Conclusion so far: providing a file name directly works but submitting a file name as a variable does not.

any suggestions?
Günter

Did you try eval('AFiles(' + aa + '):=G1')

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
10-08-2021, 01:18 PM
Post: #6
RE: Python: How do I save a graphic?
... to the last proposal using the string concatenation, one might probably have to add double quotes in the leading and trailing strings to quote the content of variable aa ...
Find all posts by this user
Quote this message in a reply
10-08-2021, 07:07 PM
Post: #7
RE: Python: How do I save a graphic?
Thank you Tom and Martin,

but that didn't work either. Whether with single quotes or double quotes in various combinations. I don't understand, how string concatenation is supposed to help at all?

I guess the problem is not in Python itself but in the implementation of the hpprime module, specifically "eval()". I.e. I wasn't able to have TEXTOUT deliver something through hpprime.eval().

Günter
Find all posts by this user
Quote this message in a reply
Post Reply 




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