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

How to find the parent of an old-style class?

I'm stuck using a library based on old style classes, and need to find
a class's parent at runtime.

With new style classes you can use .__base__ to inspect a parent, but
I can't remember how this was done in days of yore, before object.
I've tried googling, but apparently my search term Fu is weak. :-(

Can anyone help me out here? There must be something simple.

-Jasper
Jun 27 '08 #1
2 1930
On Apr 24, 7:16*am, Jasper <jas...@peak.orgwrote:
I'm stuck using a library based on old style classes, and need to find
a class's parent at runtime.

With new style classes you can use .__base__ to inspect a parent, but
I can't remember how this was done in days of yore, before object.
I've tried googling, but apparently my search term Fu is weak. :-(

Can anyone help me out here? *There must be something simple.
It's very odd that you need to know a class's parent. I'm interested
in hearing why you need this. In all my years, I've never had to do
this.

Regardless, I believe you are looking for __bases__.

Jun 27 '08 #2
On Apr 24, 10:02 am, Jonathan Gardner <jgard...@jonathangardner.net>
wrote:
On Apr 24, 7:16 am, Jasper <jas...@peak.orgwrote:
I'm stuck using a library based on old style classes, and need to find
a class's parent at runtime.
With new style classes you can use .__base__ to inspect a parent, but
I can't remember how this was done in days of yore, before object.
I've tried googling, but apparently my search term Fu is weak. :-(
Can anyone help me out here? There must be something simple.

It's very odd that you need to know a class's parent. I'm interested
in hearing why you need this. In all my years, I've never had to do
this.

Regardless, I believe you are looking for __bases__.
*smack* That's what I get for programming too late into the morning;
can't believe I missed that. Thanks for sorting me out!

-Jasper
PS I'm using a hierarchy of (never instantiated) classes as resource
types in an economic sim, e.g. Resource, Luxury( Resource ),
Gold( Luxury ). Prices are dicts of {resource:amount}, where resource
can be something concrete like Gold, or a general group like Luxury
(which could be paid with Gold, but also Ivory, etc). Payments are in
dicts of {concrete-resource:amount}, and to verify correct payment I
iterate through them, matching concrete resources (via their parent)
to general price requirements like Luxury or Resource. I could avoid
referencing __bases__ by instead iterating through price and checking
issubclass(), but the logic is more complex.

And yes, I know this is a bit of an unorthodox use of classes. ;-)
Jun 27 '08 #3

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

Similar topics

9
by: Bernd.Moos | last post by:
Given the following XML document: <text> <p> <w>Ronaldo</w> <w>scoredw> <w>the</w> <w>1</w> <c>:</c> <w>1</w>
25
by: Steve Jorgensen | last post by:
Yup, Steve's full of tips, but hey, it makes him feel important, right? Ok, here goes. I've been trying to improve encapsulation by putting code in the same object as the stuff it affects, so I...
1
by: Roy | last post by:
How is it done? BTW, I'm reposting this here, as the datagrid newsgroup appears functionally comatose... I have a nested datagrid setup. When one updates the child grid using edit, it also...
5
by: Steve Richter | last post by:
In my user control I want to read the ViewState dictionary of the Parent control. But this sensible idea is not permitted by the compiler: Compiler Error Message: CS1540: Cannot access...
2
by: Thelma Lubkin | last post by:
My ColorSet building form/subform now works beautifully, thanks to the help that I've gotten from people in this group. The working form displays the parent ColorSet record with the child records...
8
by: Henrik Stidsen | last post by:
I am trying to access a table in an iframe via javascript. It sounds easy - but it won´t work... The iframe is added to the document via someContainerElement.innerHTML = "<iframe...>", it has...
4
by: brookdb | last post by:
I have three forms we'll call, "Mainform A", "Mainform B" and "Mainform C" in which there is a subform, "Subform" and inside my subform I have another subform, "Sub-Subform". It is paramount to my...
5
by: gnewsgroup | last post by:
In my user control, I would like to find a Label control in the parent page (the page that uses my user control). I need to update that Label.Text when something happens in the user control. I...
5
by: YaoBao | last post by:
Is any ColdFusion script I can put on my webpage that will create a search bar so people can type keywords to match it on the current page in my website? It will be exactly like the finder search bar...
7
by: dweeti | last post by:
Hi, I am trying to display the child element in the DOM, while hiding the parent using JS and CSS, however I cannot find a way to do this. So for example: <body> <div id="Parent"> <div...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.