[Tutor] Re: Help with AppendText Syntax

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sun Dec 21 23:06:47 EST 2003



On Sun, 21 Dec 2003, Lee Harr wrote:

> >I tried the following but still no luck.
> >
> >self.tester.AppendText("Code returned is:" field1)
> >
> >The error is still invalid syntax. I think I am missing something to
> >prefix "field1" but do not know what.
>
> Ah. Ok, I guess you can only do that with string literals ...


Yes, strings literals get put together if they're adjacent.  The official
Python tutorial talks about this near the middle of:

http://python.org/doc/current/tut/node5.html#SECTION005120000000000000000

It's cute, but I have to admit I don't use this feature too much.  *grin*


For regular string concatenation, we can use '+' or string formatting.
By the way, if we find outselves gluing a lot of strings together, it's
good to use a specialized string joiner like the join() method of strings:

    http://python.org/doc/current/lib/string-methods.html#l2h-188

but for small string joining, addition or formatting works out fine.



> So, probably what you want is ...
>
> self.tester.AppendText("Code returned is: %s" % field1)

Yes, this should be syntactically correct.


Good luck!




More information about the Tutor mailing list