LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-27-2012, 04:45 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
python: inheritance not working as expected. Problem with my code?


I'm writing a layer that goes on top of a 3rd party module. My class inherits from a class in the 3rd party module. That moule [eventually] inherits from dict. The layout looks like:

Code:
class 3rdPartyParent(dict):
 ...

class 3rdPartyObject(3rdPartyParent):
...

class MyClass(3rdPartyObject):
    ...
    @property
    def frames(self):
        if not self.__frames:
            self.__updateFrames()
        return self.__frames
    ...
However, when I try to use my defined "frames" property (by my_instance = MyClass(); my_instance.frames), I'm getting a result from the 3rdPartyParent's __getattr__ (which happens to raise an error that the requested attribute doesn't exist). Not quite sure why that would be. I expect that it would execute my code, but it doesn't. Any ideas?

Last edited by BrianK; 02-27-2012 at 04:47 PM.
 
Old 03-04-2012, 12:21 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Is it frames that isn't found, or is it __frames or __updateFrames?
Kevin Barry
 
Old 03-05-2012, 07:53 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Oops... forgot to update this thread.

It was "frames" that wasn't found - the property, not "__frames" the variable. The problem had something to do with a coding error that wasn't caught by the interpreter. Unfortunately, I can't say exactly what it was, but I was in the middle of a rather large edit when this started coming up. After checking over the property time & time again, I pushed through to finish the edit, checked again & it was working as expected.
 
Old 03-06-2012, 09:21 AM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,219

Rep: Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309Reputation: 5309
Does it work without the property decorator? Python's property inheritance is one of the things that works funny.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
inheritance in python vbx_wx Programming 9 01-23-2011 07:57 AM
Python: finding substring code not working :( PiNPOiNT Programming 1 08-31-2009 08:34 PM
Python inheritance and scope dakensta Programming 2 07-31-2005 06:16 AM
python inheritance towlie Programming 3 09-23-2004 12:13 AM
OOP / Python inheritance question usernamenumber Programming 1 12-02-2003 10:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration