それモジュールで
慣習に従わないことによる弊害というものは理解しにくいものかな。
てか、やるならもう少しうまいやり方があるだろう。
typealias.py
Str = str List = list Dict = dict Tuple = tuple Set = set Object = object Type = type Int = int Long = long Float = float Complex = complex Bool = bool Unicode = unicode File = file
% python Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from typealias import * >>> Str <type 'str'> >>> Dict <type 'dict'> >>>
あとまぁ、typealias.py はこんなのでもいいかもしれない。
import __builtin__ def _init(): types = [] context = globals() for name in dir(__builtin__): obj = getattr(__builtin__, name) if type(obj) is type and name.islower(): capitalized = name.capitalize() context[capitalized] = obj types.append(capitalized) global __all__ __all__ = types _init()