Re: [Tutor] Using __init__ to return a value

2013-06-12 Thread Steven D'Aprano
On 12/06/13 19:32, Khalid Al-Ghamdi wrote: Hi, Why doesn't this work? And is there way to have an object immediately return a value or object once it is instantiated with using a method call? It does return a value. It returns the object that was just instantiated. Supposed you could do what

Re: [Tutor] Using __init__ to return a value

2013-06-12 Thread Peter Otten
Khalid Al-Ghamdi wrote: >1. >>> class k: >2. def __init__(self,n): >3. return n*n >4. >5. >6. >>> khalid=k(3) >7. Traceback (most recent call last): >8. File "", line 1, in >9. khalid=k(3) >10. TypeError: __init__() should retu

Re: [Tutor] Using __init__ to return a value

2013-06-12 Thread vishwajeet singh
On Wed, Jun 12, 2013 at 3:02 PM, Khalid Al-Ghamdi wrote: > Hi, > > Why doesn't this work? And is there way to have an > object immediately return a value or object once it is instantiated with > using a method call? > __init__ returns the newly created object. You cannot (or at least shouldn't) r

[Tutor] Using __init__ to return a value

2013-06-12 Thread Khalid Al-Ghamdi
Hi, Why doesn't this work? And is there way to have an object immediately return a value or object once it is instantiated with using a method call? 1. >>> class k: 2. def __init__(self,n): 3. return n*n 4. 5. 6. >>> khalid=k(3) 7. Traceback (most rec