473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

newbe questions

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()
Jul 18 '05 #1
2 1261
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
Jul 18 '05 #2
[..]
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

--
Daniel
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Yaro | last post by:
Hello DB2/NT 8.1.3 Sorry for stupid questions. I am newbe in DB2. 1. How can I read *.sql script (with table and function definitions) into a database? Tool, command... 2. In Project Center...
17
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not...
1
by: Snaggy | last post by:
1. Why arent't default parameters accepted? Why do I have to use polymorphism everywhere? This makes my code redundant. Example: public string showStuff (string whatToShow, int limit = 0){...} ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.