Metaprogramming question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Menard

    #1

    Metaprogramming question

    I have a need to create class instance without invokking the class' __init__
    method.

    Were I using old-style classes, I'd use new.instance() function. However, I
    am using new-style classes and new.instance() complain "TypeError:
    instance() argument 1 must be classobj, not type" ...

    So my question is, how to replicate new.instance() functionality with new
    classes?

    Steve Menard
    Author and Maintainer of http://jpype.sourceforge.net


  • MonkeeSage

    #2
    Re: Metaprogramming question

    Steve Menard wrote:
    So my question is, how to replicate new.instance() functionality with new
    classes?
    class A(object):
    def __init__(self):
    print "Class A"
    A()
    A.__new__(A) # <- this one

    Regards,
    Jordan

    Comment

    • Georg Brandl

      #3
      Re: Metaprogramming question

      Steve Menard wrote:
      I have a need to create class instance without invokking the class' __init__
      method.
      >
      Were I using old-style classes, I'd use new.instance() function. However, I
      am using new-style classes and new.instance() complain "TypeError:
      instance() argument 1 must be classobj, not type" ...
      >
      So my question is, how to replicate new.instance() functionality with new
      classes?
      Use object.__new__.

      Georg

      Comment

      Working...