newbe questions

Daniel Schüle for_usenet2000 at yahoo.de
Sat Nov 1 18:15:22 CET 2003


Hi all

i am new to python but not to programming in general
i tryed the code below i would write in C++
in particular the nested classes and creation of
objects in constr

my questions are
why are the variables x_ and y_ not set properly?
constr of base_inner never runs?!
but the initialisation of z_ trough foo() seems to work!!!


is the (let's call it) class-namespace resolution
trough self the right way to do it? (for types as well as for variables)
see self.y_ = self.base_inner()
        ^^              ^^
 variable             type

i think x_ doesnt need self.base_inner() for the construction
because on its place the definition of class base_inner
is visible for it


thanks for your time

ps: is there any tutorials how to learn python coming from C++ background
especially what are the pitfalls .. etc


*******************************************************
import os

os.system("cls")

def foo():
 return 1

class base:
 def __init__(self):
  print "base"
  self.y_ = self.base_inner()
 def show(self):
  print self.x_.value_
  print self.y_.value_
  print self.z_
 class base_inner:
  def __init_(self):
   print "base::x"
   self.value = "ok"
  value_ = "not ok"
 x_ = base_inner()
 y_ = None
 z_ = foo()

class derived(base):
 def __init__(self):
  print "derived"

b = base()
#d = derived()

b.show()
#d.show()






More information about the Python-list mailing list