On Wed, Jun 12, 2013 at 3:02 PM, Khalid Al-Ghamdi <emailkg...@gmail.com>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) return something else.
Try making whatever you want to return an instance variable (or function).

Refer this thread
http://stackoverflow.com/questions/2491819/python-init-how-to-return-a-value


>
>    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 "<pyshell#58>", line 1, in <module>
>    9.     khalid=k(3)
>    10. TypeError: __init__() should return None, not 'int'
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Vishwajeet Singh
+91-9657702154 | dextrou...@gmail.com | http://bootstraptoday.com
Twitter: http://twitter.com/vishwajeets | LinkedIn:
http://www.linkedin.com/in/singhvishwajeet
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to