Post Reply 
Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio
01-17-2022, 08:59 PM
Post: #3
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works
Passing strings as such from the Python environment to the HOME environment is straightforward:

Prerequisite: from hppprime import *

Example:
Code:
00 from hppprime import *
01 eval(' AVars("Text"):="This is my text" ')
works flawlessly

but consider this where I try to pass the string as a variable

Code:
00 from hppprime import *
01 text= "This is my text"
02 eval(' AVars("Text"):=' + text )

This doesn't work! Why? The reason is that the content of the variable text isn't enclosed in quotes (or double quotes). Thus it is interpreted as a variable name by the HOME environment ==> Syntax Error

Solution: enclose the variable name text with double quotes. here is how it works:

Code:
00 from hppprime import *
01 text= "This is my text"
02 eval(' AVars("Text"):=' + ' " '+ text + ' " ' )

The spaces between the quotes and double quote are here only to show the two different kinds of quotes. Practically you'd omit them as they actually add blanks to the string.

In order to make life easier it is suitable to define a function for this

Code:
00 from hppprime import *

def string(text):
        return '"' + text + '"'    # remember ' " ' is how those quotings look with blanks

01 text= "This is my text"
02 eval(' AVars("Text"):=' + string(text) )

This function is specifically useful for the <TEXTOUT_P> function in the HOME environment as this function is much more powerful than the <textout> function in the Python environment. The next release of my Mandelbrot Explorer will demonstrate some use of it.

I hope:

a) This is understandable
b) of use for someone

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


Messages In This Thread
RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works - Guenter Schink - 01-17-2022 08:59 PM



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