Re: [Tutor] __new__ over __init__

2010-09-02 Thread Payal
On Wed, Sep 01, 2010 at 09:14:50AM +0100, Alan Gauld wrote: > It is an abbreviation for class. The first parameter to new() must be a > refernce to the class. > It is similar to self in an instance method, where the first parameter > is a reference > to the instance. Thanks a lot. With warm re

Re: [Tutor] __new__ over __init__

2010-09-02 Thread Peter Otten
Alan Gauld wrote: > "Payal" wrote >> b. What does type(_) mean? > > The _ refers to the last evaluated result, in this case the tuple > (1,2). > Its a shorthand trick, I think it only works in the interpreter, I > don't like > it and never use it, but many do. (FWIW Perl has a similar shortcut >

Re: [Tutor] __new__ over __init__

2010-09-01 Thread Alan Gauld
"Payal" wrote >>> class A(tuple): ... def __new__(cls, a, b): ... return tuple.__new__(cls, (a, b)) a. I have seen this cls before, what does it mean? It is an abbreviation for class. The first parameter to new() must be a refernce to the class. It is similar to self in an

Re: [Tutor] __new__ over __init__

2010-09-01 Thread Payal
On Tue, Aug 31, 2010 at 08:27:10AM +0200, Peter Otten wrote: > Subclasses of immutable types, e. g. tuple: That was one great example, thanks. Some doubts, a. I have seen this cls before, what does it mean? b. What does type(_) mean? Thanks a lot in advance. With warm regards, -Payal -- > >>

Re: [Tutor] __new__ over __init__

2010-08-30 Thread Peter Otten
Payal wrote: > Can someone please give a very simple example of using __new__ wherein > __init__ cannot be used? Subclasses of immutable types, e. g. tuple: >>> class A(tuple): ... def __init__(self, a, b): ... pass ... >>> a = A(1,2) Traceback (most recent call last): File "",

[Tutor] __new__ over __init__

2010-08-30 Thread Payal
Hi all, Can someone please give a very simple example of using __new__ wherein __init__ cannot be used? With warm regards, -Payal -- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman