Re: string literal vs string variable

2009-08-22 Thread Jan Kaliszewski

22-08-2009 o 19:46:51 Kee Nethery  wrote:

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


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


Yes, simply:

s = 'hello world'
#^
#it is a *string literal*

s  # <- it is a *string object*
   #(or rather a name referring to it :-))

(In Python we have rather 'names' than 'variables', though -- as
a mental leap -- they are commonly referred to as 'variables',
regarding other languages' terminology).

Cheers,
*j

--
Jan Kaliszewski (zuo) 
--
http://mail.python.org/mailman/listinfo/python-list


Re: string literal vs string variable

2009-08-22 Thread Piet van Oostrum
> Kee Nethery  (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'hello world'
>KN> fromstring(somestring)  <-- string variable
>KN> vs
>KN> XML(u'hello world')  <-- literal string

Yes.

Stefan probably means `looks better for the human reader' when he says
`reads better'. XML and fromstring are just different names for the same
function. 
-- 
Piet van Oostrum 
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


string literal vs string variable

2009-08-22 Thread Kee Nethery


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.


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


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

Kee


--
http://mail.python.org/mailman/listinfo/python-list