Type of user defined class objects - Python

I am not very experienced with classes or OOP, and I'm confused with some of the results I'm getting.

I am trying to use type() on a class I have created.

    class TestClass:

    my_class = TestClass()
    print type(my_class)

The above code returns

    <type: 'instance'>

Based on my understanding my_class should be initialized as a TestClass object.. right? Why isn't the output TestClass. Also, if possible, what would I need to change to get this result?


From the documentation:

Classes and instances come in two flavors: old-style (or classic) and new-style.

Up to Python 2.1, old-style classes were the only flavour available to the user. The concept of (old-style) class is unrelated to the concept of type: if x is an instance of an old-style class, then x.__class__ designates the class of x, but type(x) is always <type 'instance'>. This reflects the fact that all old-style instances, independently of their class, are implemented with a single built-in type, called instance.

By not inheriting from object, you create an old-style class, so type(my_class) behaves like it does.

Inherit from object and your problems will go away:

class TestClass(object):

In Python 3, all classes are new-style classes, which is nice.

If you want TestClass to be an object, you have to specify it like so

class TestClass(object):

Need Your Help

Trouble Creating Directories with mkdir

ruby mkdir

New to Ruby, probably something silly

How redis-store stores room data in redis?

node.js redis socket.io

When a client joins a room, all corresponding data (i.e rooms, sockets in rooms and other) goes to Redis.