#File: mymath.py
mypi = 3.14
def add(a, b):
return a + b
def area(r):
return mypi * r * r
import mymath
print dir(mymath) # mymath에 정의된 이름들 확인하기
print mymath.mypi # mymath 안에 정의된 mypi를 사용한다
print mymath.area(5) # mymath 안에 정의된 area를 사용한다
['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'add', 'area', 'mypi'] 3.14 78.5
x = 10
print globals()
print locals()
# module01.py
# -*- coding:utf-8 -*-
a = 1
b = 2
def f():
localx = 10
localy = 20
print '함수 내에서 전역 변수:', globals()
print
print '함수 내에서 지역 변수:', locals()
f()
print
print '모듈 수준에서의 전역 변수:', globals()
print
print '모듈 수준에서의 지역 변수:', locals()
#module02.py
a = 1
b = 2
gns = globals()
print gns
print
gns['c'] = 3
print gns
import string
print dir(string)
['Formatter', 'Template', '_TemplateMetaclass', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_float', '_idmap', '_idmapL', '_int', '_long', '_multimap', '_re', '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', 'rsplit', 'rstrip', 'split', 'splitfields', 'strip', 'swapcase', 'translate', 'upper', 'uppercase', 'whitespace', 'zfill']
print string.__dict__ # 출력은 너무 길어서 생략
print string.__dict__.keys() # 이름 키:속성 사전에서 키만 뽑아낼 수 있다. 이것은 dir(string)과 동일
['ascii_lowercase', 'upper', '_re', 'letters', 'atol_error', 'lstrip', 'uppercase', 'ascii_letters', 'find', 'atof', 'replace', 'capwords', 'index_error', 'expandtabs', 'Template', 'strip', 'ascii_uppercase', 'octdigits', 'index', 'ljust', 'whitespace', '_int', 'rindex', '_float', 'punctuation', '__package__', 'printable', 'splitfields', 'split', 'rstrip', 'translate', '__doc__', '_multimap', 'count', 'joinfields', 'rjust', '__builtins__', '__file__', 'lower', 'swapcase', 'atof_error', 'atoi', 'hexdigits', 'Formatter', 'atol', '__name__', 'rsplit', '_idmapL', 'digits', 'lowercase', 'join', 'center', '_long', 'rfind', 'atoi_error', 'maketrans', 'capitalize', '_TemplateMetaclass', 'zfill', '_idmap']
import string
for name in dir(string):
if name not in string.__dict__.keys():
print name
import string
string.a = 1
print string.a
1
class C: # 클래스도 독립적인 이름 공간
a = 2 # 클래스 이름 공간 내에 변수 선언
pass # 클래스 정의
c = C() # 클래스 인스턴스 객체 생성
c.a = 1 # 클래스에서 생성된 인스턴스 객체도 별도의 이름 공간
print c.a
print c.__class__.a
print C.a
1 2 2
x = 10 # 현재 모듈 내부에 정의되는 이름
def f():
a = 1
b = 2 # 현재 모듈에 정의되는 함수 f 내에 이름 a,b를 정의하고있다. 함수도 독립적인 이름 공간
f.c = 1
print f.c
print
print f.a
1
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-6-1110995cdbd5> in <module>() 6 print f.c 7 print ----> 8 print f.a AttributeError: 'function' object has no attribute 'a'
import sys
print sys.path
['', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python27.zip', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/plat-darwin', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/plat-mac', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/plat-mac/lib-scriptpackages', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-tk', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-old', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-dynload', '/Users/yhhan/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages', '/Users/yhhan/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/PIL', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages', '/Users/yhhan/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/extensions', '~/mypythonlib']
import sys
sys.path.append('~/mypythonlib')
print sys.path
['', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python27.zip', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/plat-darwin', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/plat-mac', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/plat-mac/lib-scriptpackages', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-tk', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-old', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-dynload', '/Users/yhhan/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages', '/Users/yhhan/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/PIL', '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/site-packages', '/Users/yhhan/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/extensions', '~/mypythonlib']
import mymath
print mymath.area(5)
78.5
from mymath import area, mypi
print area(5)
78.5
from mymath import *
print area(5)
78.5
import string as chstr
print chstr
print
print chstr.punctuation
<module 'string' from '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/string.pyc'> !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
from string import replace as substitute
print substitute
print substitute('ham chicken spam', 'chicken', 'egg')
<function replace at 0x1006a01b8> ham egg spam
from string import replace as substitute, upper as up
print up
print up('abc')
<function upper at 0x10286b668> ABC
def str_test(s):
import string
t = string.split(s)
return t
from Tkinter import (Tk, Frame, Button, Entry, Canvas, Text, LEFT, DISABLED, NORMAL, RIDGE, END)
mypi = 3.14
def add(a, b):
return a + b
def area(r):
return mypi * r * r
print area(4.0)
50.24
import mymath02
50.24
modulename = 're'
re = __import__(modulename)
print re
<module 're' from '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/re.pyc'>
string = "My first string"
import string
print string
<module 'string' from '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/string.pyc'>
import string
string = "My first string" #여기서 string이란 이름은 문자열을 참조하게 된다.
print string
My first string
import string
string.a = 1
string = "My first string"
print string
import string
print string.a # 여기서 string 모듈이 기존에 이미 등록되었던 것임을 알 수 있다.
My first string 1
#file : teststring1.py
import string # string 모듈을 import 함
print 'test string1'
string.a = 1 # import한 string 모듈에 a 변수 등록
print "---"
import teststring2 # 서로 다른 모듈인 teststring2를 import 함
print "---"
print 'test string1 done'
test string1 --- test string2 1 test string2 done --- test string1 done
#file : teststring2.py
import string # 동일한 string 모듈을 import 함
print 'test string2'
print string.a # 다른 모듈에서 등록한 a 변수 사용 가능
print 'test string2 done'
test string2 1 test string2 done
import mymath
mymath.mypi = 6.2 # 값 수정(원래 모듈 파일에 정의된 값은 3.14)
import mymath # 다시 import
print mymath.mypi # 3.14가 아니라 6.2 -> 즉 이미 적재되어 있는 모듈 그냥 이용
6.2
print mymath.mypi
reload(mymath)
print mymath.mypi
6.2 3.14
#FILE : prname.py
print __name__
__main__
import prname
print prname.__name__
prname prname
import string
print string.__name__
import re
print re.__name__
import mimetools
print mimetools.__name__
import os
print os.__name__
string re mimetools os
#file: name_attr_test.py
def test():
print "Python is becoming popular."
if __name__ == "__main__":
test()
Python is becoming popular.
import name_attr_test
import calendar
print getattr(calendar, 'prmonth') # 문자열 이름을 이용한 모듈 내 속성(변수나 함수) 참조
print calendar.prmonth # 직접 calendar.prmonth를 참조하는 것과 같다
<bound method TextCalendar.prmonth of <calendar.TextCalendar object at 0x103c37190>> <bound method TextCalendar.prmonth of <calendar.TextCalendar object at 0x103c37190>>
calendar.prmonth(2014, 10)
October 2014 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
getattr(calendar, 'prmonth')(2014, 10) #같은 출력결과
October 2014 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
f = getattr(calendar, 'prmonth')
f(2014, 10) #같은 출력결과
October 2014 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
import calendar
setattr(calendar, 'spam', 10)
print calendar.spam
print hasattr(calendar, 'spam')
print delattr(calendar, 'spam')
print calendar.spam
10 True None
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-12-bd10029fff92> in <module>() 6 7 print delattr(calendar, 'spam') ----> 8 print calendar.spam AttributeError: 'module' object has no attribute 'spam'
print dir(calendar)
print
print calendar.__dict__
['Calendar', 'EPOCH', 'FRIDAY', 'February', 'HTMLCalendar', 'IllegalMonthError', 'IllegalWeekdayError', 'January', 'LocaleHTMLCalendar', 'LocaleTextCalendar', 'MONDAY', 'SATURDAY', 'SUNDAY', 'THURSDAY', 'TUESDAY', 'TextCalendar', 'TimeEncoding', 'WEDNESDAY', '_EPOCH_ORD', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_colwidth', '_locale', '_localized_day', '_localized_month', '_spacing', 'c', 'calendar', 'datetime', 'day_abbr', 'day_name', 'error', 'firstweekday', 'format', 'formatstring', 'isleap', 'leapdays', 'main', 'mdays', 'month', 'month_abbr', 'month_name', 'monthcalendar', 'monthrange', 'prcal', 'prmonth', 'prweek', 'setfirstweekday', 'sys', 'timegm', 'week', 'weekday', 'weekheader'] {'MONDAY': 0, 'weekheader': <bound method TextCalendar.formatweekheader of <calendar.TextCalendar object at 0x105635190>>, 'FRIDAY': 4, 'formatstring': <function formatstring at 0x1056360c8>, 'datetime': <module 'datetime' from '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-dynload/datetime.so'>, 'timegm': <function timegm at 0x105636140>, 'mdays': [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], 'calendar': <bound method TextCalendar.formatyear of <calendar.TextCalendar object at 0x105635190>>, '__package__': None, 'SATURDAY': 5, '_localized_day': <class calendar._localized_day at 0x1056308d8>, '_localized_month': <class calendar._localized_month at 0x105630870>, 'leapdays': <function leapdays at 0x105626a28>, 'monthcalendar': <bound method TextCalendar.monthdayscalendar of <calendar.TextCalendar object at 0x105635190>>, '__all__': ['IllegalMonthError', 'IllegalWeekdayError', 'setfirstweekday', 'firstweekday', 'isleap', 'leapdays', 'weekday', 'monthrange', 'monthcalendar', 'prmonth', 'month', 'prcal', 'calendar', 'timegm', 'month_name', 'month_abbr', 'day_name', 'day_abbr'], 'c': <calendar.TextCalendar object at 0x105635190>, 'TUESDAY': 1, 'format': <function format at 0x105636050>, 'SUNDAY': 6, 'THURSDAY': 3, 'IllegalMonthError': <class 'calendar.IllegalMonthError'>, 'LocaleTextCalendar': <class 'calendar.LocaleTextCalendar'>, 'month_name': <calendar._localized_month instance at 0x105633368>, 'day_abbr': <calendar._localized_day instance at 0x105633320>, '_colwidth': 20, '_EPOCH_ORD': 719163, 'main': <function main at 0x1056361b8>, '__doc__': 'Calendar printing functions\n\nNote when comparing these calendars to the ones printed by cal(1): By\ndefault, these calendars have Monday as the first day of the week, and\nSunday as the last (the European convention). Use setfirstweekday() to\nset the first day of the week (0=Monday, 6=Sunday).', 'weekday': <function weekday at 0x105626aa0>, 'week': <bound method TextCalendar.formatweek of <calendar.TextCalendar object at 0x105635190>>, 'February': 2, 'monthrange': <function monthrange at 0x105626b18>, 'LocaleHTMLCalendar': <class 'calendar.LocaleHTMLCalendar'>, 'prmonth': <bound method TextCalendar.prmonth of <calendar.TextCalendar object at 0x105635190>>, '__builtins__': {'bytearray': <type 'bytearray'>, 'IndexError': <type 'exceptions.IndexError'>, 'all': <built-in function all>, 'help': Type help() for interactive help, or help(object) for help about object., 'vars': <built-in function vars>, 'SyntaxError': <type 'exceptions.SyntaxError'>, '__IPYTHON__active': 'Deprecated, check for __IPYTHON__', 'unicode': <type 'unicode'>, 'UnicodeDecodeError': <type 'exceptions.UnicodeDecodeError'>, 'memoryview': <type 'memoryview'>, 'isinstance': <built-in function isinstance>, 'copyright': Copyright (c) 2001-2013 Python Software Foundation. All Rights Reserved. Copyright (c) 2000 BeOpen.com. All Rights Reserved. Copyright (c) 1995-2001 Corporation for National Research Initiatives. All Rights Reserved. Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. All Rights Reserved., 'NameError': <type 'exceptions.NameError'>, 'BytesWarning': <type 'exceptions.BytesWarning'>, 'dict': <type 'dict'>, 'input': <function <lambda> at 0x10dd0c7d0>, 'oct': <built-in function oct>, 'bin': <built-in function bin>, 'SystemExit': <type 'exceptions.SystemExit'>, 'StandardError': <type 'exceptions.StandardError'>, 'format': <built-in function format>, 'repr': <built-in function repr>, 'sorted': <built-in function sorted>, 'False': False, 'RuntimeWarning': <type 'exceptions.RuntimeWarning'>, 'list': <type 'list'>, 'iter': <built-in function iter>, 'reload': <built-in function reload>, 'Warning': <type 'exceptions.Warning'>, '__package__': None, 'round': <built-in function round>, 'dir': <built-in function dir>, 'cmp': <built-in function cmp>, 'set': <type 'set'>, 'bytes': <type 'str'>, 'reduce': <built-in function reduce>, 'intern': <built-in function intern>, 'issubclass': <built-in function issubclass>, 'Ellipsis': Ellipsis, 'EOFError': <type 'exceptions.EOFError'>, 'locals': <built-in function locals>, 'BufferError': <type 'exceptions.BufferError'>, 'slice': <type 'slice'>, 'FloatingPointError': <type 'exceptions.FloatingPointError'>, 'sum': <built-in function sum>, 'getattr': <built-in function getattr>, 'abs': <built-in function abs>, 'print': <built-in function print>, 'True': True, 'FutureWarning': <type 'exceptions.FutureWarning'>, 'ImportWarning': <type 'exceptions.ImportWarning'>, 'None': None, 'hash': <built-in function hash>, 'ReferenceError': <type 'exceptions.ReferenceError'>, 'len': <built-in function len>, 'credits': Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands for supporting Python development. See www.python.org for more information., 'frozenset': <type 'frozenset'>, '__name__': '__builtin__', 'ord': <built-in function ord>, 'super': <type 'super'>, 'TypeError': <type 'exceptions.TypeError'>, 'license': Type license() to see the full license text, 'KeyboardInterrupt': <type 'exceptions.KeyboardInterrupt'>, 'UserWarning': <type 'exceptions.UserWarning'>, 'filter': <built-in function filter>, 'range': <built-in function range>, 'staticmethod': <type 'staticmethod'>, 'SystemError': <type 'exceptions.SystemError'>, 'BaseException': <type 'exceptions.BaseException'>, 'pow': <built-in function pow>, 'RuntimeError': <type 'exceptions.RuntimeError'>, 'float': <type 'float'>, 'MemoryError': <type 'exceptions.MemoryError'>, 'StopIteration': <type 'exceptions.StopIteration'>, 'globals': <built-in function globals>, 'divmod': <built-in function divmod>, 'enumerate': <type 'enumerate'>, 'apply': <built-in function apply>, 'LookupError': <type 'exceptions.LookupError'>, 'open': <built-in function open>, 'basestring': <type 'basestring'>, 'UnicodeError': <type 'exceptions.UnicodeError'>, 'zip': <built-in function zip>, 'hex': <built-in function hex>, 'long': <type 'long'>, 'next': <built-in function next>, 'ImportError': <type 'exceptions.ImportError'>, 'chr': <built-in function chr>, 'xrange': <type 'xrange'>, 'type': <type 'type'>, '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", 'Exception': <type 'exceptions.Exception'>, '__IPYTHON__': True, 'tuple': <type 'tuple'>, 'UnicodeTranslateError': <type 'exceptions.UnicodeTranslateError'>, 'reversed': <type 'reversed'>, 'UnicodeEncodeError': <type 'exceptions.UnicodeEncodeError'>, 'IOError': <type 'exceptions.IOError'>, 'hasattr': <built-in function hasattr>, 'delattr': <built-in function delattr>, 'setattr': <built-in function setattr>, 'raw_input': <function <lambda> at 0x10dd0c848>, 'SyntaxWarning': <type 'exceptions.SyntaxWarning'>, 'compile': <built-in function compile>, 'ArithmeticError': <type 'exceptions.ArithmeticError'>, 'str': <type 'str'>, 'property': <type 'property'>, 'dreload': <function reload at 0x105842f50>, 'GeneratorExit': <type 'exceptions.GeneratorExit'>, 'int': <type 'int'>, '__import__': <built-in function __import__>, 'KeyError': <type 'exceptions.KeyError'>, 'coerce': <built-in function coerce>, 'PendingDeprecationWarning': <type 'exceptions.PendingDeprecationWarning'>, 'file': <type 'file'>, 'EnvironmentError': <type 'exceptions.EnvironmentError'>, 'unichr': <built-in function unichr>, 'id': <built-in function id>, 'OSError': <type 'exceptions.OSError'>, 'DeprecationWarning': <type 'exceptions.DeprecationWarning'>, 'min': <built-in function min>, 'UnicodeWarning': <type 'exceptions.UnicodeWarning'>, 'execfile': <built-in function execfile>, 'any': <built-in function any>, 'complex': <type 'complex'>, 'bool': <type 'bool'>, 'get_ipython': <bound method ZMQInteractiveShell.get_ipython of <IPython.kernel.zmq.zmqshell.ZMQInteractiveShell object at 0x105841890>>, 'ValueError': <type 'exceptions.ValueError'>, 'NotImplemented': NotImplemented, 'map': <built-in function map>, 'buffer': <type 'buffer'>, 'max': <built-in function max>, 'object': <type 'object'>, 'TabError': <type 'exceptions.TabError'>, 'callable': <built-in function callable>, 'ZeroDivisionError': <type 'exceptions.ZeroDivisionError'>, 'eval': <built-in function eval>, '__debug__': True, 'IndentationError': <type 'exceptions.IndentationError'>, 'AssertionError': <type 'exceptions.AssertionError'>, 'classmethod': <type 'classmethod'>, 'UnboundLocalError': <type 'exceptions.UnboundLocalError'>, 'NotImplementedError': <type 'exceptions.NotImplementedError'>, 'AttributeError': <type 'exceptions.AttributeError'>, 'OverflowError': <type 'exceptions.OverflowError'>}, 'January': 1, '__file__': '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/calendar.pyc', 'WEDNESDAY': 2, 'sys': <module 'sys' (built-in)>, 'EPOCH': 1970, '_spacing': 6, 'prweek': <bound method TextCalendar.prweek of <calendar.TextCalendar object at 0x105635190>>, '__name__': 'calendar', 'month': <bound method TextCalendar.formatmonth of <calendar.TextCalendar object at 0x105635190>>, 'firstweekday': <bound method TextCalendar.getfirstweekday of <calendar.TextCalendar object at 0x105635190>>, 'setfirstweekday': <function setfirstweekday at 0x105634758>, 'TimeEncoding': <class calendar.TimeEncoding at 0x105630940>, '_locale': <module 'locale' from '/Applications/Canopy.app/appdata/canopy-1.4.1.1975.macosx-x86_64/Canopy.app/Contents/lib/python2.7/locale.pyc'>, 'prcal': <bound method TextCalendar.pryear of <calendar.TextCalendar object at 0x105635190>>, 'isleap': <function isleap at 0x105626488>, 'TextCalendar': <class 'calendar.TextCalendar'>, 'day_name': <calendar._localized_day instance at 0x1056332d8>, 'month_abbr': <calendar._localized_month instance at 0x1056333b0>, 'IllegalWeekdayError': <class 'calendar.IllegalWeekdayError'>, 'error': <type 'exceptions.ValueError'>, 'HTMLCalendar': <class 'calendar.HTMLCalendar'>, 'Calendar': <class 'calendar.Calendar'>}
for attr, val in calendar.__dict__.items():
print 'name = %-20s, type = %s' % (attr, type(val))
name = MONDAY , type = <type 'int'> name = weekheader , type = <type 'instancemethod'> name = FRIDAY , type = <type 'int'> name = formatstring , type = <type 'function'> name = datetime , type = <type 'module'> name = timegm , type = <type 'function'> name = mdays , type = <type 'list'> name = calendar , type = <type 'instancemethod'> name = __package__ , type = <type 'NoneType'> name = SATURDAY , type = <type 'int'> name = _localized_day , type = <type 'classobj'> name = _localized_month , type = <type 'classobj'> name = leapdays , type = <type 'function'> name = monthcalendar , type = <type 'instancemethod'> name = __all__ , type = <type 'list'> name = c , type = <class 'calendar.TextCalendar'> name = TUESDAY , type = <type 'int'> name = format , type = <type 'function'> name = SUNDAY , type = <type 'int'> name = THURSDAY , type = <type 'int'> name = IllegalMonthError , type = <type 'type'> name = LocaleTextCalendar , type = <type 'type'> name = month_name , type = <type 'instance'> name = day_abbr , type = <type 'instance'> name = _colwidth , type = <type 'int'> name = _EPOCH_ORD , type = <type 'int'> name = main , type = <type 'function'> name = __doc__ , type = <type 'str'> name = weekday , type = <type 'function'> name = week , type = <type 'instancemethod'> name = February , type = <type 'int'> name = monthrange , type = <type 'function'> name = LocaleHTMLCalendar , type = <type 'type'> name = prmonth , type = <type 'instancemethod'> name = __builtins__ , type = <type 'dict'> name = January , type = <type 'int'> name = __file__ , type = <type 'str'> name = WEDNESDAY , type = <type 'int'> name = sys , type = <type 'module'> name = EPOCH , type = <type 'int'> name = _spacing , type = <type 'int'> name = prweek , type = <type 'instancemethod'> name = __name__ , type = <type 'str'> name = month , type = <type 'instancemethod'> name = firstweekday , type = <type 'instancemethod'> name = setfirstweekday , type = <type 'function'> name = TimeEncoding , type = <type 'classobj'> name = _locale , type = <type 'module'> name = prcal , type = <type 'instancemethod'> name = isleap , type = <type 'function'> name = TextCalendar , type = <type 'type'> name = day_name , type = <type 'instance'> name = month_abbr , type = <type 'instance'> name = IllegalWeekdayError , type = <type 'type'> name = error , type = <type 'type'> name = HTMLCalendar , type = <type 'type'> name = Calendar , type = <type 'type'>
import Speech
def train():
print "Train"
pass
def loadModel():
print "LoadModel"
pass
def saveModel():
print "SaveModel"
pass
import Speech.Recognition.HMM
Speech.Recognition.HMM.train()
Train
from Speech.Recognition import HMM
HMM.train()
Train
from Speech.Recognition.HMM import train
train()
Train
from Speech.Recognition.HMM import *
train()
loadModel()
saveModel()
Train LoadModel SaveModel
__all__ = ['HMM', 'NN', 'DTW']
from Speech.Recognition import *
print HMM
print NN
print DTW
HMM.train()
<module 'Speech.Recognition.HMM' from 'Speech/Recognition/HMM.py'> <module 'Speech.Recognition.NN' from 'Speech/Recognition/NN.pyc'> <module 'Speech.Recognition.DTW' from 'Speech/Recognition/DTW.pyc'> Train
__all__ = ['Synthesis']
from Speech import *
print Synthesis
<module 'Speech.Synthesis' from 'Speech/Synthesis/__init__.pyc'>
print Recognition.HMM
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-9-6f332fa1fc57> in <module>() ----> 1 print Recognition.HMM NameError: name 'Recognition' is not defined
def warping():
print "warping"
pass
def train():
print "Train"
pass
def loadModel():
print "LoadModel"
pass
def saveModel():
print "SaveModel"
pass
import DTW
DTW.warping()
def train():
print "Train"
pass
def loadModel():
print "LoadModel"
pass
def saveModel():
print "SaveModel"
pass
import DTW
DTW.warping()
import Adaptation.ML
Adaptation.ML.test()
def train():
print "Train"
pass
def loadModel():
print "LoadModel"
pass
def saveModel():
print "SaveModel"
pass
import DTW
DTW.warping()
from Adaptation import ML
ML.test()
def train():
print "Train"
pass
def loadModel():
print "LoadModel"
pass
def saveModel():
print "SaveModel"
pass
import DTW
DTW.warping()
from Adaptation.ML import *
test()