string literal vs string variable

Piet van Oostrum piet at
Sat Aug 22 22:43:13 CEST 2009

>>>>> Kee Nethery <kee at> (KN) wrote:

>KN> On Aug 22, 2009, at 3:32 AM, Stefan Behnel wrote:

>>> You can use both, but I suspect parsing from StringIO to be slower  than
>>> parsing from the string directly. That's the case for lxml, at least.
>>> Note that fromstring() behaves the same as XML(), but it reads  better
>>> when
>>> parsing from a string variable. XML() reads better when parsing from a
>>> literal string.

>KN> I'm not sure I know the difference between a string variable and a  literal
>KN> string. Is the difference as simple as:

>KN> somestring = u'<stuff>hello world</stuff>'
>KN> fromstring(somestring)  <-- string variable
>KN> vs
>KN> XML(u'<stuff>hello world</stuff>')  <-- literal string


Stefan probably means `looks better for the human reader' when he says
`reads better'. XML and fromstring are just different names for the same
Piet van Oostrum <piet at>
URL: [PGP 8DAE142BE17999C4]
Private email: piet at

More information about the Python-list mailing list