Constructor of object

2007-03-14 Thread inline
Hello!
I want to assign self to object of parent class in constructor, like

def my_func():
...
return ParentClass()

class MyClass (ParentClass):
def __init__(self):
self = my_func()

but it not work, because "object not initialized". What i can do?

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


Re: Constructor of object

2007-03-14 Thread inline
On Mar 14, 9:05 pm, Thinker <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> inline wrote:
> > Hello! I want to assign self to object of parent class in
> > constructor, like
>
> > def my_func(): ... return ParentClass()
>
> > class MyClass (ParentClass): def __init__(self): self = my_func()
>
> > but it not work, because "object not initialized". What i can do?
>
> Do you want to call constructor of super-class to initialize the object?
> If it is true, you have following options.
>
> In old style class:
> class MyClass(ParentClass):
> def __init__(self):
> ParentClass.__init__(self)
>
> In new style class:
> class MyClass(ParentClass):
> def __init__(self):
> super(MyClass).__init__(self)
>
> Or
> class MyClass(ParentClass):
> def __init__(self):
> super(MyClass, self).__init__()
>
> - --
> Thinker Li - [EMAIL PROTECTED] [EMAIL 
> PROTECTED]://heaven.branda.to/~thinker/GinGin_CGI.py
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.6 (FreeBSD)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
>
> iD8DBQFF+Dls1LDUVnWfY8gRAvDaAKDVmX8LmuWUdJ4eVil7l//rjCQZLQCg8dO8
> Y77CL1ikmtdl6S3HD04GWiA=
> =mvSe
> -END PGP SIGNATURE-

I know it, but i don't want call constructor of parent class - I use
PyGTK and want to load window from glade file and assign it to object,
parented gtk.Window:

#!/usr/bin/env python

import gtk
import gtk.glade

class HelloWindow (gtk.Window):
def __init__(self):
xml = gtk.glade.XML("hello.glade")
xml.signal_autoconnect(self)
self = xml.get_widget("window")

window = HelloWindow()
window.connect("delete_event", gtk.main_quit)
window.show_all()
gtk.main()

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


Re: Constructor of object

2007-03-14 Thread inline
On Mar 14, 9:05 pm, Thinker <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> inline wrote:
> > Hello! I want to assign self to object of parent class in
> > constructor, like
>
> > def my_func(): ... return ParentClass()
>
> > class MyClass (ParentClass): def __init__(self): self = my_func()
>
> > but it not work, because "object not initialized". What i can do?
>
> Do you want to call constructor of super-class to initialize the object?
> If it is true, you have following options.
>
> In old style class:
> class MyClass(ParentClass):
> def __init__(self):
> ParentClass.__init__(self)
>
> In new style class:
> class MyClass(ParentClass):
> def __init__(self):
> super(MyClass).__init__(self)
>
> Or
> class MyClass(ParentClass):
> def __init__(self):
> super(MyClass, self).__init__()
>
> - --
> Thinker Li - [EMAIL PROTECTED] [EMAIL 
> PROTECTED]://heaven.branda.to/~thinker/GinGin_CGI.py
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.6 (FreeBSD)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
>
> iD8DBQFF+Dls1LDUVnWfY8gRAvDaAKDVmX8LmuWUdJ4eVil7l//rjCQZLQCg8dO8
> Y77CL1ikmtdl6S3HD04GWiA=
> =mvSe
> -END PGP SIGNATURE-

I know it, but i don't want call constructor of parent class - I use
PyGTK and want to load window from glade file and assign it to object,
parented gtk.Window:

#!/usr/bin/env python

import gtk
import gtk.glade

class HelloWindow (gtk.Window):
def __init__(self):
xml = gtk.glade.XML("hello.glade")
xml.signal_autoconnect(self)
self = xml.get_widget("window")

window = HelloWindow()
window.connect("delete_event", gtk.main_quit)
window.show_all()
gtk.main()

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


Re: Constructor of object

2007-03-15 Thread inline
Thanks. But can I change returned by xml.get_widget() object type from
gtk.Window to HelloWindow?

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