Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6238 > unrolled thread

Re: Newbie string questions

Started byChris Guidry <chris@theguidrys.us>
First post2011-05-25 06:13 -0700
Last post2011-05-25 09:21 -0400
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Re: Newbie string questions Chris Guidry <chris@theguidrys.us> - 2011-05-25 06:13 -0700
    Re: Newbie string questions Matty Sarro <msarro@gmail.com> - 2011-05-25 09:21 -0400

#6238 — Re: Newbie string questions

FromChris Guidry <chris@theguidrys.us>
Date2011-05-25 06:13 -0700
SubjectRe: Newbie string questions
Message-ID<997e06dd-55dc-4b45-9ff2-97f24dd49908@glegroupsg2000goo.googlegroups.com>
On Wednesday, May 25, 2011 9:06:02 AM UTC-4, Matty Sarro wrote:
> can't seem to find some of the items in the documentation. Right now
> what is stumping me... what exactly does %r do? I can't find it in the
> documentation anywhere.

Matty, %r in a format string is very much like %s.  %s calls str(your_object) in order to produce the resulting string.  %r calls repr(your_object).  Generally, you'd want to use %s for strings that will surface to a user, while %r is great for debugging and logging.

Also, if you haven't come across repr(), you should be able to find that in the docs; it's also considered good practice to overload repr() in your own classes in order to provide a useful representation for your objects.

[toc] | [next] | [standalone]


#6240

FromMatty Sarro <msarro@gmail.com>
Date2011-05-25 09:21 -0400
Message-ID<mailman.2074.1306329690.9059.python-list@python.org>
In reply to#6238
Thanks guys! I appreciate it. I was wondering why %r was always
showing things enclosed in single-quotes.

On Wed, May 25, 2011 at 9:13 AM, Chris Guidry <chris@theguidrys.us> wrote:
> On Wednesday, May 25, 2011 9:06:02 AM UTC-4, Matty Sarro wrote:
>> can't seem to find some of the items in the documentation. Right now
>> what is stumping me... what exactly does %r do? I can't find it in the
>> documentation anywhere.
>
> Matty, %r in a format string is very much like %s.  %s calls str(your_object) in order to produce the resulting string.  %r calls repr(your_object).  Generally, you'd want to use %s for strings that will surface to a user, while %r is great for debugging and logging.
>
> Also, if you haven't come across repr(), you should be able to find that in the docs; it's also considered good practice to overload repr() in your own classes in order to provide a useful representation for your objects.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web