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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:59:23+00:00 2026-05-27T07:59:23+00:00

class ClassA: pass mytype = type(ClassA) Using mytype , how do you create an

  • 0
class ClassA: pass
mytype = type(ClassA)

Using mytype, how do you create an instance of ClassA?

Note that I’m NOT looking for this as my answer 🙂

instance = ClassA()

I know that in this example, that’s all you need to do but suppose that you have this type (mytype), you don’t know anything about it, and you need to create an instance of it.

I tried just calling mytype() and it returns an error stating that type() takes 1 or 3 arguments. I imagine these arguments may be related to any arguments you’d want to pass into the init method of the object being created.

Note: I’ve seen a number of questions asked about how to create an object given a string representing its fully qualified name. Note that here, I already have a type so it’s a bit different? I think?

I had hoped that I could do the equivalent of the following .NET code:

class A {}

class Program
{
    static void Main(string[] args)
    {
        Type type = typeof(A);

        // Given the type, I can create a new instance
        object new_instance = Activator.CreateInstance(type);
    }
}

I had assumed that in Python, type(ClassA) gave something back that I could later use to create an instance of ClassA. Looks like I misunderstood type in Python.

  • 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-27T07:59:24+00:00Added an answer on May 27, 2026 at 7:59 am

    If you use a new style class it, this will work:

    class ClassA(object):
        pass
    
    o = ClassA()
    mytype = type(o)
    new_object = mytype()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is this: class MyType(type): def __init__(cls, name, bases, attrs): print 'created', cls class
Suppose code like this: class Base: def start(self): pass def stop(self) pass class A(Base):
How do I grab the Type of the inherited class and pass it into
How to pass a class and a method name as strings and invoke that
I'm using a library that manipulates a binary search tree. In this library is
Let's say that I have this: public abstract class myClass<T> : Ob<T> where T
I am wondering if it's better to pass an instance of a whole class
I want to define a class, ClassA , that can be passed as a
Consider this class: class foo(object): pass The default string representation looks something like this:
I have two classes, ClassA that will instantiate ClassB and pass off a method

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.