kieran
December 23, 2018, 9:48pm
1
In the app, I print the output, like below.
How can I redirect this from the output log into the screen?
#only print the closing brackets if we have aggregations
if len(counts) >0 or len(sums) >0:
print(" )\")
# PRINT THE FINAL SELECT
if len(sums) and len(counts) == 0:
print(" .select(" + extracted_features + ")")
elif len(sums) ==0 and len(counts) > 0:
print(" .select(" + extracted_features + "," + extracted_counts + ")")
elif len(sums) > 0 and len(counts) == 0:
print(" .select(" + extracted_features + "," + extracted_sums + ")")
elif len(sums) > 0 and len(counts) > 0:
print(" .select(" + extracted_features + "," + extracted_sums + "," + extracted_counts + ")")
print("df_agg.createOrReplaceTempView(\"temporarytable\")")
Not 100% sure I understand the question, but to add text to a label you update its text property like this :
labelname.text += "whatever you want to print"
If you want to print to both the debug window and the label, then I suggest creating a function :
def myprint(txt):
print(txt)
self.mylabel.text += txt
As I say though, I’m not 100% sure I understood your question properly.
kieran
December 23, 2018, 10:03pm
3
Ah, I am sorry if i wasn’t able to explain properly.
In the below, I effecitvely want the output panel to print in the label that I’ve added under the form - but I’m not sure how
Assuming there is a label under the “submit” button then I think what I wrote was 90% correct.
I’d drop a TextArea control on your form, then instead of your print statements that write to the output window, replace them with this :
self.textarea_1.text += "your text \n"
or do it in the function I suggested above if you want both.
Did I understand correctly, and does that help?
1 Like
kieran
December 23, 2018, 10:59pm
5
Thanks - that works well.
However, since making the change, I now get “<anvil.TextBox object>)” printed in the output, rather than the value from the text box. Any ideas?
here is an example;/
self.output_text.text +=" df1 = spark_session.table(" + new_from.replace(' ', '').strip() + ")\n"
Perhaps you have print self.text_area1
instead of print self.text_area1.text
?
kieran
December 24, 2018, 1:58pm
7
The issue is, that the below statement:
from_statement = str(self.from_)
Returns
<anvil.TextBox object>
How do I take the value in the field?
self.from_
is the object.
self.from_.text
is the text contained in the object.
str(self.from_)
is the string representing the object, not its text, not its name. It’s some text defined in its __str__()
or __repr__()
designed to give you a description of the object, not of its text or any other property.
1 Like