473,378 Members | 1,119 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,378 software developers and data experts.

Re: why am I not allowed to redefine a class ?

Stef Mientki wrote:
hello,

although this is not a real problem for me,
it was caused by a copying, instead of moving, a piece of code.
But I don't understand at all why the code below gives the error.
class derived_class, is defined twice,
the error is cuase by the second instance creation "test2="
for me even weirder, if I create test2 in another module, everything
works perfect ???
Any explanation would be welcome.
A different version of what Arnaud D. said:
==== start of code ===
class base_class ( object ) :
def __init__ ( self ) :
pass

class derived_class ( base_class ) :
def __init__ ( self ) :
base_class.__init__ ( self )

class final_class_1 ( derived_class ) :
In this line, 'derived_class' is evaluated when the class is defined
def __init__ ( self ) :
derived_class.__init__ ( self )
In this line, 'devired_class' is evaluated when the class is
instantiated and __init__ is called.
test1 = final_class_1 ()
Here, the object corresponding to 'derived_class in f_c_1.__init__is the
same as when f_c_1 was created.
class derived_class ( base_class ) :
def __init__ ( self ) :
base_class.__init__ ( self )

test2 = final_class_1 ()
Here, object corresponding to 'derived_class in f_c_1.__init__is no
longer the same as when f_c_1 was created.

==== end of code =====

==== error meassage =====
Traceback (most recent call last):
File "D:\Data_Python_25\PyLab_Works\module1.py", line 19, in <module>
test2 = final_class_1 ()
File "D:\Data_Python_25\PyLab_Works\module1.py", line 11, in __init__
derived_class.__init__ ( self )
TypeError: unbound method __init__() must be called with derived_class
This refers to the second 'derived_class', and f_c_1 ia *not* a subclass
of *that* class object.
instance as first argument (got final_class_1 instance instead)
tjr

Nov 9 '08 #1
0 955

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

Similar topics

2
by: BillD | last post by:
I'm trying to derive a schema from a base schema. I want to redefine a "group" from the base schema in my derived schema in order to add more options to the "choice" aggregate (see schema1.xsd...
1
by: Cat | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I'm getting a validation error when I try to restrict the content of nested groups with xs:redefine whereas the same restriction on xs:element's...
6
by: eselk | last post by:
If I have: class A { public: class some_base_class **Obj; }; And I would like to redefine "Obj" in a class derived from class A, something like this maybe:
3
by: junlia | last post by:
We are using ACORD xml schema standard, and we need to add to it, so we choose to redefine ACORD xml schema. One of the problems that I ran into is how to add some values to an emumerated list. ...
2
by: ERingmae | last post by:
Hi, The environment is .NET 2.0, the language is C# and the problem is reading XSD file with xs:redefine section correctly to a XMLDataDocument.DataSet. What I am trying to do: I am trying...
10
by: Amber | last post by:
For example if anywhere defined MyChar as typedef char MyChar; Now I want to redefine MyChar as wchar_t, how can I do this?
2
by: jeff123 | last post by:
Hi all, Recently I started using C#, I have a question: Can we redefine a class legally in C# ? For example: private void button1_Click(object sender, EventArgs e) {...
1
by: Stef Mientki | last post by:
hello, although this is not a real problem for me, it was caused by a copying, instead of moving, a piece of code. But I don't understand at all why the code below gives the error. class...
0
by: Stef Mientki | last post by:
thanks guys. cheers, Stef Terry Reedy wrote:
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.