On Sep 1, 2011, at 09:48, Amogh M S wrote:

> Hey guys... 
> I think we have a problem with my _init_ method and the constructor
> When I create a class and its _init_ method and try to create an object of it 
> outside the class,
> Say, something like
> 
> class S:
>    def _init_(self, name=None):
>        self.name = name
> s = S("MyName")

Two things: Derive your class from object, and the constructor function should 
be '__init__', that is, with *two* underscores before and after it. Are you 
reading a book or tutorial which does use a badly chosen font which doesn't 
distinguish two consecutive underscores well?

class S(object):
    def __init__(self, name=None):
        self.name = name

s = S("MyName")
print s.name

Greetings,


-- 
"If you don't know, the thing to do is not to get scared, but to learn." - Ayn 
Rand      



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to