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 7501193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:27:17+00:00 2026-05-29T20:27:17+00:00

I am working with an ORM that accepts classes as input and I need

  • 0

I am working with an ORM that accepts classes as input and I need to be able to feed it some dynamically generated classes. Currently, I am doing something like this contrived example:

def make_cls(_param):
   def Cls(object):
       param = _param
   return Cls

A, B = map(make_cls, ['A', 'B'])

print A().foo
print B().foo

While this works fine, it feels off by a bit: for example, both classes print as <class '__main__.Cls'> on the repl. While the name issue is not a big deal (I think I could work around it by setting __name__), I wonder if there are other things I am not aware of.
So my question is: is there a better way to create classes dynamically or is my example mostly fine already?

  • 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-05-29T20:27:18+00:00Added an answer on May 29, 2026 at 8:27 pm

    What is class? It is just an instance of type. For example:

    >>> A = type('A', (object,), {'s': 'i am a member', 'double_s': lambda self: self.s * 2})
    >>> a = A()
    >>> a
    <__main__.A object at 0x01229F50>
    >>> a.s
    'i am a member'
    >>> a.double_s()
    'i am a memberi am a member'
    

    From the doc:

    type(name, bases, dict)

    Return a new type object. This is essentially a dynamic form of the class statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Django/Python, but pseudo-code is definitely acceptable here. Working with some models that
I'm working on a project that uses ADO.NET entity framework as the ORM framework
I'm currently working with an online application that requires multiple screens/steps in order to
I have a project that I'm currently working on but it currently only supports
I am pretty new to ColdFusion ORM and I have some questions that I
What are your thoughts on this? I'm working on integrating some new data that's
I'm working on an app that currently has a lot of ManyToMany relationships (and
I come from a Codeigniter MVC background that we've been working with for some
I'm working on a backend for an open source Python ORM. The library includes
I've been working with Zend Framework (using Doctrine as the ORM) for quite a

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.