Create a new type in python

You would want something like this, a class. In the source code all of the object types you see in Python are in class form.

>>> class myName:
...     def __init__(self, name):
...         self.name = name
...     def __str__(self):
...         return self.name
...

>>> b = myName('John')
>>> type(b)
<class '__main__.myName'>
>>> print(b)
John

The reason the output is slightly different to what you expected is because the name of the class is myName so that is what is returned by type(). Also we get the __main__. before the class name because it is local to the current module.


You might have a look at Metaclasses: http://eli.thegreenplace.net/2011/08/14/python-metaclasses-by-example/

However, what exactly do you want to achieve?