__builtin_과 __builtin_의 차이점은 무엇입니까?
오늘 코딩을 하다가 뭔가를 발견했습니다.새 인터프리터 세션(IDLE)을 열고 다음 항목에 정의된 내용을 확인하는 경우dir
함수는 다음과 같습니다.
$ python
>>> dir()
['__builtins__', '__doc__', '__name__', '__package__']
>>> dir(__builtins__)
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '_', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']
>>> import __builtin__
['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BufferError', 'BytesWarning', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'NameError', 'None', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'ReferenceError', 'RuntimeError', 'RuntimeWarning', 'StandardError', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'ZeroDivisionError', '_', '__debug__', '__doc__', '__import__', '__name__', '__package__', 'abs', 'all', 'any', 'apply', 'basestring', 'bin', 'bool', 'buffer', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'cmp', 'coerce', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'intern', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'raw_input', 'reduce', 'reload', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'unichr', 'unicode', 'vars', 'xrange', 'zip']
>>> dir(__builtin__) == dir(__builtins__) # They seem to have the same things
True
마지막 줄을 주의하십시오.
그래서, 제 질문은:
다른 사람의 가명이 있습니까?
파이썬 사람들은 그 중 하나를 없앨 계획입니까?
내 프로그램에 무엇을 사용해야 합니까?
파이썬 3는 어떻습니까?
모든 정보는 가치가 있습니다!
중요:
Ubuntu에서 Python 2.7.2+를 사용하고 있습니다.
파이썬 문서에서 직접: http://docs.python.org/reference/executionmodel.html
기본적으로 다음 위치에 있을 때
__main__
모듈,__builtins__
내장 모듈임__builtin__
(참고: no 's'; 다른 모듈에 있는 경우__builtins__
의 사전에 대한 별칭입니다.__builtin__
모듈 자체.
__builtins__
사용자가 만든 사전으로 설정하여 약한 형식의 제한된 실행을 만들 수 있습니다.Cython 구현 세부 정보:사용자가 만지면 안 됩니다.
__builtins__
이것은 엄격하게 구현 세부사항입니다.기본 제공 네임스페이스의 값을 재정의하려는 사용자는import
그__builtin__
(no 's') 모듈을 구성하고 해당 속성을 적절히 수정합니다.모듈의 네임스페이스는 모듈을 처음 가져올 때 자동으로 만들어집니다.
Python3에서 모듈은__builtin__
로 이름이 변경되었습니다.builtins
이런 혼란을 피하기 위해.
사용해야 합니다.__builtin__
당신의 프로그램에서 (필요한 드문 경우에), 왜냐하면__builtins__
는 CPython의 구현 세부사항입니다.다음과 같을 수 있습니다.__builtin__
또는 로__builtin__.__dict__
문맥에 따라설명서에 나와 있듯이 다음과 같습니다.
대부분의 모듈에는 다음과 같은 이름이 있습니다.
__builtins__
('s' 참고)는 글로벌의 일부로 제공됩니다.의 가치__builtins__
일반적으로 이 모듈 또는 이 모듈의 값입니다.__dict__
기여하다.구현 세부 정보이므로 Python의 대체 구현에서는 사용할 수 없습니다.
파이썬 3에서,__builtin__
로 이름이 변경되었습니다.builtins
,그리고.__builtins__
동일하게 유지됩니다(따라서 사용자는builtins
Python 3)에서 확인할 수 있습니다.
귀도는 단결하기를 원했습니다.__builtin__
그리고.__builtins__
여기에서 볼 수 있듯이 ("갖기")__builtins__
그리고.__builtin__
둘 다 분명히 나쁜 생각입니다.") 하지만 분명히 아무 것도 나오지 않았습니다.
분명히 사용하는 것은__builtins__
성능을 위한 것입니다. 직접 액세스할 수 있습니다.__builtin__.__dict__
비주요 모듈에서 사용할 경우, 한 수준의 간접성이 제거됩니다.
__builtin__
는 기본 제공 기능 및 유형을 포함하는 모듈입니다.라는 이름이__builtins__
구현 세부 정보와 동일한 내용을 포함하여 사용할 수 있습니다. 말해,중 , 다시말서해, 약당그중한사다면야용해하를만신이나것들,한다,import __builtin__
그런 다음 사용합니다.__builtin__
설명서를 참조하십시오.
load cython을 실행합니다. cpython load cypton을 실행합니다.__builtin__
로 변환합니다.
__builtin__
~하듯이__builtins__
그__builtins__
과 모듈을 는 안 .__builtin__
파이썬 의 혼란을 .물론 이름이 너무 비슷해서 여기까지 온 새로운 파이썬 프로그래머들 사이에 약간의 혼란을 초래하는 경향이 있습니다. 그__builtins__
모듈은 기본 제공 네임스페이스의 기본 제공 이름 집합으로 구성됩니다.전부는 아니더라도 대부분의 이 이름들은__builtin__
모듈은 기본 제공 함수, 예외 및 기타 속성의 모듈입니다.에서, 준파실서에행썬이표,__builtins__
에는 의모이포있습다니함어되름의 되어 있습니다.__builtin__
, 이 모델은 Python의 을 했습니다.__builtins__
주요 내용은 다음과 같습니다.__builtin__
샌드박스 환경을 만들기 위해 제외되었습니다.
그러나 보안 결함과 이를 복구하는 데 따르는 어려움으로 인해 Python(2.3 기준)에서는 제한된 실행이 더 이상 지원되지 않습니다.
언급URL : https://stackoverflow.com/questions/11181519/whats-the-difference-between-builtin-and-builtins
'sourcecode' 카테고리의 다른 글
TesseractNotFound 오류를 해결하려면 어떻게 해야 합니까? (0) | 2023.05.13 |
---|---|
NSLocalizedString을 사용하는 모범 사례 (0) | 2023.05.13 |
GitHub: 공공 저장소의 포크를 비공개로 만드는 방법은 무엇입니까? (0) | 2023.05.13 |
PostgreSQL에서 업데이트 + 가입하는 방법은 무엇입니까? (0) | 2023.05.13 |
VBA(Excel)에서 = Empty()와 Is Empty()의 차이점은 무엇입니까? (0) | 2023.05.13 |