如何獲得一個包含班級所有功能但不按字母順序排列的列表? 因爲實際上我有一個: 按書寫順序列出班級的所有功能
[ foo.__dict__.get(a) for a in dir(foo) if isinstance(foo.__dict__.get(a), types.FunctionType) ]
,並返回我一個名單,但重新排序... 我也試着與裝飾:
def decorator():
listing = []
def wrapped (func):
listing.append(func)
return func
wrapped.listing = listing
return wrapped
這很好,但我需要在我班的每個功能上添加一個裝飾器...可能是你有一些技巧?
'字典不保存順序。所以如果你想按照外觀順序,你可能需要使用正則表達式進行解析。 – tuxuday