파이썬 globals()

1 개요[편집]

Python globals()
파이썬 globals()
  • 글로벌 심볼 테이블을 딕셔너리 형태로 돌려줌
Python 2
Python 2.4.3 (#1, Feb 22 2012, 16:05:45) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> globals()
{'__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main__', '__doc__': None}
Python 3
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> globals()
{'__builtins__': <module 'builtins' (built-in)>, '__name__': '__main__', '__doc__': None, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': None, '__package__': None}

2 예시[편집]

# a.py
foo = 'bar'
print(globals())
$ python3 a.py
{'__builtins__': <module '__builtin__' (built-in)>, '__file__': 'a.py', '__package__': None, '__name__': '__main__', 'foo': 'bar', '__doc__': None}
→기본 글로벌 심볼 이외에 별도 추가한 'foo': 'bar' 값이 있는 것을 확인할 수 있다.

3 같이 보기[편집]

4 참고[편집]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}