newbe questions

D

Daniel Schüle

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()
 
D

Diez B. Roggisch

Hi,
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):

your __init__ method lacks a second underscore. BTW: Why do you use inner
classes at all? The make sense in e.g. java, because they can overcome some
limitations in java itself. The only thing I ever used them in c++ was to
create a sort of namespace, which is also not neccessary because of
modules. What are your reasons for using them?

Regards,

Diez
 
D

Daniel Schüle

[..]
your __init__ method lacks a second underscore. BTW: Why do you use inner
classes at all? The make sense in e.g. java, because they can overcome some
limitations in java itself. The only thing I ever used them in c++ was to
create a sort of namespace, which is also not neccessary because of
modules. What are your reasons for using them?

thank you for your quick answear

i dont really need them, i was just playing with python
and possibilities of this language

in C++ i use them to emphasis the logical relationsship of some classes to
each other
for example
class list{/**/class node {/**/} };
class tree{/**/class node {/**/} };
or for the iterator implementation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,460
Latest member
eibafima

Latest Threads

Top