473,386 Members | 1,886 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.

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

thanks guys.

cheers,
Stef

Terry Reedy wrote:
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

--
http://mail.python.org/mailman/listinfo/python-list
Nov 9 '08 #1
0 880

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. ...
1
by: Raed Sawalha | last post by:
i have the following scenario I've created MFC Application using Visual Studio 2003, then change the project settings to use Managed Extensions as follows: 1. Configuration...
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: Terry Reedy | last post by:
Stef Mientki wrote: A different version of what Arnaud D. said: In this line, 'derived_class' is evaluated when the class is defined In this line, 'devired_class' is evaluated when the...
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: 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?
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,...

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.