python - What turns following to __builtin__? -
i have next snippet , output
with metaclass:
def some(*args): homecoming type(args) __metaclass__ = class foo: = 'khkjh' print foo.__module__ output: __builtin__
without metaclass:
class foo: = 'khkjh' print foo.__module__ output: __main__
so,
what __builtin__?
why or how metaclass affecting it?
__builtin__ module provides built-in functions, exceptions, etc.
you're getting returned __module__ because metaclass you're providing turning foo tuple type:
>>> def (*args): ... homecoming type(args) # returns <type 'tuple'> ... >>> class hmm(object): ... __metaclass__ = ... >>> class foo(object): ... pass ... >>> print hmm <type 'tuple'> >>> print foo <class '__main__.foo'> >>> print tuple <type 'tuple'> >>> print tuple.__module__ __builtin__ as can see hmm type tuple. tuple type provided __builtin__ module, hence output you're seeing.
python metaclass built-in
No comments:
Post a Comment