I have following snippet and output
with metaclass:
def some(*args):
return type(args)
__metaclass__ = some
class Foo:
a = 'khkjh'
print Foo.__module__
Output: __builtin__
without metaclass:
class Foo:
a = 'khkjh'
print Foo.__module__
Output: __main__
So,
What is __builtin__
?
why or how metaclass is affecting it?
__builtin__
is the module that provides all built-in functions, exceptions, etc.
You're getting this returned from __module__
because the metaclass you're providing is essentially turning Foo
into the tuple
type:
>>> def some (*args):
... return type(args) # This returns <type 'tuple'>
...
>>> class Hmm(object):
... __metaclass__ = some
...
>>> class Foo(object):
... pass
...
>>> print Hmm
<type 'tuple'>
>>> print Foo
<class '__main__.Foo'>
>>> print tuple
<type 'tuple'>
>>> print tuple.__module__
__builtin__
As you can see Hmm
is now the type tuple
. The tuple
type is provided by the __builtin__
module, hence the output you're seeing.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.