Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: intX.__str__() ??

Reply
Thread Tools

Re: intX.__str__() ??

 
 
Mitya Sirenef
Guest
Posts: n/a
 
      02-24-2013
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

 
Reply With Quote
 
 
 
 
Steven D'Aprano
Guest
Posts: n/a
 
      02-24-2013
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
 
Reply With Quote
 
 
 
 
Mitya Sirenef
Guest
Posts: n/a
 
      02-24-2013
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments