모듈 ¶
모듈란? ¶
- 램 C
- 램(, ... ) 데를
- 모듈 변 는 ( = 브러리)
모듈 ? ¶
- 를 .
- 모 모듈 리 .
- 른 모듈 문 독립 능.
모듈만들(..) ¶
~cpp c = 2 def add(a, b): return a+b def mul(a, b): return a*b
mymath.py 는 ..
~cpp >>> import mymath >>> dir(mymath) ['__builtins__', '__doc__', '__file__', '__name__', 'add', 'c', 'mul'] >>> mymath <module 'mymath' from 'C:\Python22\mymath.py'> >>> >>> mymath.c 2 >>> mymath.add <function add at 0x00A927E0> >>> mymath.add(3,4) 7 >>> mymath.mul(4,6) 24
¶
- = 는
- 변 = ddd.sss 명 는 변.
- 무변 = ktf 명 변.
, ¶
globals(), locals()
~cpp a = 1 b = 2 def f(): localx = 10 localy = 20 print '변:', globals() print '변:', locals() f() print '모듈 변:', globals() print '모듈 변:', locals()
~cpp 변 a,b 변 localx,localy 는.. a,b,f()
모듈 보 ¶
는...
~cpp >>> import string >>> dir(string) ['_StringTypes', '__builtins__', '__doc__', '__file__', '__name__', '_float', '_idmap', '_idmapL', '_int', '_long', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'atof', 'atof_error', 'atoi', 'atoi_error', 'atol', 'atol_error', 'capitalize', 'capwords', 'center', 'count', 'digits', 'expandtabs', 'find', 'hexdigits', 'index', 'index_error', 'join', 'joinfields', 'letters', 'ljust', 'lower', 'lowercase', 'lstrip', 'maketrans', 'octdigits', 'printable', 'punctuation', 'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 'split', 'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 'whitespace', 'zfill']
모듈 ¶
~cpp 무..보..!! import string string.__dict__
는들 ¶
- 모듈, , 등..
- 부 능..
~cpp >>> string.b Traceback (most recent call last): File "<pyshell#17>", line 1, in ? string.b AttributeError: 'module' object has no attribute 'b' >>> string.b=2 >>> string.b 2