type object of an instance without instantiation? 
Author Message
 type object of an instance without instantiation?

I have the following code (well, in summary):

class BigClass:
        def __init__(self):
                ...does some horrifyingly {*filter*} operation...

def some_generic_fn(object):
        if hasattr(object, '__class__') and object.__class__ == BigClass:
                ...do some BigClass-specific thing...

Is there a way to create a type object for the instance of a BigClass object
without actually creating an instance of one?



Wed, 24 Apr 2002 03:00:00 GMT  
 type object of an instance without instantiation?

Quote:
claudius writes:
> I have the following code (well, in summary):

> class BigClass:
>  def __init__(self):
>   ...does some horrifyingly {*filter*} operation...

> def some_generic_fn(object):
>  if hasattr(object, '__class__') and object.__class__ ==
>  BigClass:
>   ...do some BigClass-specific thing...

> Is there a way to create a type object for the instance of a
> BigClass object without actually creating an instance of one?

The type object of an instance (any instance) is the one and
only InstanceType object. The type of object of a class (any
class) is the one and only ClassType object.

I think you mean the BigClass class object. This exists as
soon as the "class" statement is executed. When you create
an instance of BigClass, you are "calling" the BigClass class
object.

BTW, while doing lots of stuff in the constructor is often a
valuable technique in other languages, it is much less so in
Python. It makes things like pickling a lot harder (unless you
provide default args and alternate ways to get the work done).
That doesn't mean it's *always* bad, just that it reduces your
flexibility.

- Gordon



Wed, 24 Apr 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. type(type) is an object, not an instance

2. Runtime object type determination/ runtime generic instantiation

3. adding instance methods after instantiation

4. Inheritance And Instantiation Of Instance Variables

5. Pathname translations to types without type specification.

6. Class objects , instance objects

7. instantiation from an instantiation

8. Instantiation of generic controlled type?

9. Object as Instance Variable of an Object

10. Instantiation of 2nd object appends 1st?

11. instances of classes and instances of instances

 

 
Powered by phpBB® Forum Software