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


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

Re: intX.__str__() ??

Started byMitya Sirenef <msirenef@lightbird.net>
First post2013-02-24 13:09 -0500
Last post2013-02-24 13:44 -0500
Articles 3 — 2 participants

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: intX.__str__() ?? Mitya Sirenef <msirenef@lightbird.net> - 2013-02-24 13:09 -0500
    Re: intX.__str__() ?? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-24 18:23 +0000
      Re: intX.__str__() ?? Mitya Sirenef <msirenef@lightbird.net> - 2013-02-24 13:44 -0500

#39766 — Re: intX.__str__() ??

FromMitya Sirenef <msirenef@lightbird.net>
Date2013-02-24 13:09 -0500
SubjectRe: intX.__str__() ??
Message-ID<mailman.2421.1361729399.2939.python-list@python.org>
On 02/24/2013 12:29 PM, Michael Torrie wrote:
>
 > I think he's maintaining existing code. It's unfortunate that his first
 > exposure to python is code written by someone else in such a poor style,
 > and in a way that definitely isn't pythonic. No wonder he's struggling
 > to like python! Though I'm sure since his recent experience has been
 > exclusively in C# that he probably uses hungarian notation as a matter
 > of course. A hard habit to break! Is this a good time to introduce him
 > to duck typing? Probably not.
 >
 > Another way to explain the double underscore methods is that they are
 > how things like operator overloading is performed. Want to make a class
 > that you can use the [index] notation on instances? Define the
 > __get_attr__() method. And to define a class that you can then use

small correction: it should be __getattr__()


-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Admiration for a quality or an art can be so strong that it deters us from
striving to possess it.  Friedrich Nietzsche

[toc] | [next] | [standalone]


#39768

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-02-24 18:23 +0000
Message-ID<512a5a95$0$29998$c3e8da3$5496439d@news.astraweb.com>
In reply to#39766
On Sun, 24 Feb 2013 13:09:56 -0500, Mitya Sirenef wrote:

> On 02/24/2013 12:29 PM, Michael Torrie wrote:

>  > Another way to explain the double underscore methods is that they are
>  > how things like operator overloading is performed. Want to make a
>  > class that you can use the [index] notation on instances? Define the
>  > __get_attr__() method. And to define a class that you can then use
> 
> small correction: it should be __getattr__()


Correct correction: it should be __getitem__ to override instance[item] 
access. __getattr__ is for overriding instance.attribute.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#39770

FromMitya Sirenef <msirenef@lightbird.net>
Date2013-02-24 13:44 -0500
Message-ID<mailman.2423.1361731464.2939.python-list@python.org>
In reply to#39768
On 02/24/2013 01:23 PM, Steven D'Aprano wrote:
> On Sun, 24 Feb 2013 13:09:56  -0500, Mitya Sirenef wrote:
 >
 >> On 02/24/2013 12:29 PM, Michael Torrie wrote:
 >
 >> > Another way to explain the double underscore methods is that they are
 >> > how things like operator overloading is performed. Want to make a
 >> > class that you can use the [index] notation on instances? Define the
 >> > __get_attr__() method. And to define a class that you can then use
 >>
 >> small correction: it should be __getattr__()
 >
 >
 > Correct correction: it should be __getitem__ to override instance[item]
 > access. __getattr__ is for overriding instance.attribute.
 >
 >


Oh, yes.. I guess it pays to read more than a single sentence
when making corrections! -m


-- 
Lark's Tongue Guide to Python: http://lightbird.net/larks/

Each religion, by the help of more or less myth, which it takes more or
less seriously, proposes some method of fortifying the human soul and
enabling it to make its peace with its destiny.  George Santayana

[toc] | [prev] | [standalone]


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


csiph-web