Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio
01-17-2022, 08:59 PM
Post: #3
 Guenter Schink Senior Member Posts: 485 Joined: Dec 2013
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
 « Next Oldest | Next Newest »

 Messages In This Thread Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio - Guenter Schink - 12-20-2021, 10:17 PM RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works - tcab - 12-29-2021, 07:51 AM RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works - Guenter Schink - 01-17-2022 08:59 PM RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022 - Guenter Schink - 01-23-2022, 11:16 PM RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022 - jfelten - 01-24-2022, 06:34 PM RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works Correction 17.Jan 2022 - Guenter Schink - 01-24-2022, 10:44 PM RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio - jfelten - 01-25-2022, 02:46 AM RE: Python: TEXTOUT_P, CHOOSE, INPUT here is how it works 22.jan addded a TextOut functio - Guenter Schink - 01-25-2022, 09:44 PM

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