By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,660 Members | 1,102 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,660 IT Pros & Developers. It's quick & easy.

Metaprogramming question

P: n/a
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
Oct 6 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Oct 6 '06 #2

P: n/a
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
Oct 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.