Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8201919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:58:55+00:00 2026-06-07T06:58:55+00:00

I have the following two classes : class DbQuery: def __init__(self,query): self.query = query

  • 0

I have the following two classes :

class DbQuery:
    def __init__(self,query):
        self.query = query

class DbResultSet:
    def __init__(self,query):
        self.result = []

And these classes are used for SQL queries and results, attributes are used to simulate enum-like functionality. A query looks as follows :

q_forum_heirarchy =\
    type(   "RtDbQuery",
            DbQuery( """SELECT level, id, parent_id, name 
                        FROM forum_heirarchy_node
                        WHERE forum_id = :f_id 
                        AND level != 0
                        ORDER BY level ASC;"""), 
            LEVEL=0, ID=1, PARENT_ID=2, NAME=3 )

Is there some way for me to copy the attributes from DbQuery into DbResultset ? I don’t want to have to embed the query in the resultset because then I would have to write db_resultset.query.LEVEL instead of db_resultset.LEVEL to get to the enum ordinals.

I see a __get_attribute__ method but I suppose this is indexed by attribute_name.

edit:

The code is invalid python, it doesn’t change the gist of what I was asking. I discovered psycopg2(database library) can do namedtuples() (python objects with the performance characters of enums), so I can’t be bothered to update it 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:58:59+00:00Added an answer on June 7, 2026 at 6:58 am

    I think that you should use __getattr__ method. This method is used by lookup mechanism when no class attributes are found.

    class DbQuery(object):
      def __init__(self,query):
            self.query = query
    
    class DbResultSet(object):
      def __init__(self, dbquery):
            self.result = []
            self.dbquery = dbquery
      def __getattr__(self, name):
            return getattr(self.dbquery,name)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say, I have the following two classes: class A(object): def __init__(self, i): self.i
I have the following two classes: public class Address { public string AddressLine1 {
I have the following two classes, one inherits from the other Class A{ void
I have two entity classes annotated in the following way @Entity class A {
Suppose we have following two classes: class Temp{ public: char a; char b; };
I have the following two classes: public class User { public Integer userId; //
Say i have the following two classes: public class User { public int ID
I m not very versed in Hibernate and have following query: Consider two classes:
I have the following two classes: class Key<T1, T2> {} class Pair<F, S> {}
Assume I have the following two classes: public class User : Entity { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.