Tuesday, January 24, 2012

Re: django docs __unicode__ return u'%s %s

rOn Tue, 24 Jan 2012 15:04:32 -0800 (PST), Krondaj
<c.d.smith9@gmail.com> wrote:


> return u'%s %s' % (self.first_name, self.last_name)
>
>what does the u'%s %s' % mean... I cannot find any exaplanation of
>this in the docs?
>
As mentioned, this is standard Python (pre 3.x) string interpolation
(formatting).

u"any string"
defines "any string" to be unicode rather than 7-bit ASCII; in Python
3.x, all strings are unicode and one needs to specify if plain bytes are
needed.

"some string with %placeholders" % (some, tuple, of, values)
replaces the placeholders with a textual representation of the values
provided. The %s placeholder is most common as it handles any object
that has a method to produce a string representation ( __str__(self) )
-- which is pretty much anything. One can use others -- similar to the C
runtime library printf() format strings.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment