472,993 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Redo: Problem with dynamic creation of classes.

Sorry, I had a small description problem. It's corrected below.

I have a base class B and a derived class D which inherits from B. I also
have a D2 class which inherits from D. D is used as a base class for most
of my generated classes. I have a "special" class which inherits from D2
because I need to override a couple of its methods. Anything based on D
will inherit Encode and Decode from B.

class D(b.B):
def __init__(self, data, timestamp = None):
b.B.__init__(self, data)
self.timestamp = timestamp

class D2( D ):
def __init__(self, data, timestamp = None):
DS.__init__(self, data, timestamp)
def Decode(self):
pass
def Encode(self):
pass

The generated classes come from this loop:

for m in mdefs:
mdef = mdefs[m]
name = mdef['name'] + fbase
if mdef.has_key('baseclass'):
base_class_seq = mdef['baseclass']
else:
base_class_seq = DEFAULT_BASE_CLASS
nclass = new.classobj( name, base_class_seq, globals() )

base_class_seq is either going to be (D,) or (D2,)

After I get through the class generation, I want to say
globals()['IFRAMED2'].Decode = dynDecode
globals()['IFRAMED2'].Encode = dynEncode
for the one class that inherited from D2. If I do that, I find that *all*
classes that call Encode or Decode are all calling dyn{En,De}code (which
is exactly what I *don't* want).

So I looked at the id values after class generation.

print 'IFRAMED2.Encode = ', IFRAMED2.Encode, id(IFRAMED2.Encode)
print 'SNRMD.Encode = ', SNRMD.Encode, id(SNRMD.Encode)
print 'IFRAMED2 = ', IFRAMED2, id(IFRAMED2)
print 'SNRMD = ', SNRMD, id(SNRMD)
IFRAMED2.Decode = dynDecode
IFRAMED2.Encode = dynEncode
print 'IFRAMED2.Encode = ', IFRAMED2.Encode, id(IFRAMED2.Encode)
print 'SNRMD.Encode = ', SNRMD.Encode, id(SNRMD.Encode)

Here's the output:

IFRAMED2.Encode = <unbound method IFRAMED2.Encode1100623660
SNRMD.Encode = <unbound method SNRMD.Encode1100623660
IFRAMED2 = d.IFRAMED2 1076299644
SNRMD = d.SNRMD 1103202364
IFRAMED2.Encode = <unbound method IFRAMED2.dynEncode1100623660
SNRMD.Encode = <unbound method SNRMD.dynEncode1100623660

So it looks like the IFRAMED2 class which inherits from D2 is starting out
with the same id value for Encode as SNRMD which inherits from D, even
though D2 defines its own Encode method.

Is it me of is it the interpreter doing something wrong?

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
--
http://mail.python.org/mailman/listinfo/python-list
Aug 23 '07 #1
1 1257
On Thu, 23 Aug 2007 16:55:21 -0400, Steven W. Orr wrote:
So it looks like the IFRAMED2 class which inherits from D2 is starting out
with the same id value for Encode as SNRMD which inherits from D, even
though D2 defines its own Encode method.

Is it me of is it the interpreter doing something wrong?
Hard to tell without seeing where `IFRAMED2` is bound and without knowing
what you actually want to do. Can you provide a self contained example
that people here can actually try!?

Ciao,
Marc 'BlackJack' Rintsch
Aug 23 '07 #2

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

Similar topics

9
by: Zunbeltz Izaola | last post by:
Hi to all! I wonder if it possible (i'm sure python can do :-) ) to define classes on runtime. My problem (schematically) is the folowwin. The User can choise betwenn 3 property of an object....
54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
3
by: babylon | last post by:
any facilities in csharp that can help me implmenting undo/redo in my application? thx
4
by: thanigai | last post by:
How to implement undo/redo technique in C#? The undo/redo are not only for text changes, it also support previous action like creation of an object.
3
by: Teis Draiby | last post by:
I'm looking for some information (books, articles, tutorials) on how to implement a multiple undo/redo framework. I'm a beginner in this so I prefer information specifically targeting C# with code...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
2
by: Bernard Dhooghe | last post by:
The (limited to propagatable since version 9) log records are described in the API reference manual. What is meant by: normal/undo/redo/compensation records, what are the possible subtypes for...
19
by: adriancico | last post by:
Hi I am working on a python app, an outliner(a window with a TreeCtrl on the left to select a document, and a RichTextBox at the right to edit the current doc). I am familiarized with OOP...
0
by: Steven W. Orr | last post by:
I have a base class B and a derived class D which inherits from B. I also have a D2 class which inherits from D. D is used as a base class for most of my generated classes. I have a "special" class...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.