我已經辛苦打字轉讓土地:變換分配與dict
definition = ['basename', 'dirname', 'supports_unicode_filenames']
condition = ['isabs', 'isdir', 'isfile', 'islink', 'ismount']
.
.
.
打算改造他們與dict避免重複打字:
{'definition': ['basename', 'dirname', 'supports_unicode_filenames'],
'condition': ['isabs', 'isdir', 'isfile', 'islink', 'ismount'] ...}
我想,把它們封裝在課堂上。
class OsPath:
definition = ['basename', 'dirname', 'supports_unicode_filenames']
condition = ['isabs', 'isdir', 'isfile', 'islink', 'ismount']
工作控制檯
In [125]: dt = dict(vars(OsPath))
In [127]: {i:dt[i] for i in dt if not i.startswith('__')}
Out[127]:
{'condition': ['isabs', 'isdir', 'isfile', 'islink', 'ismount'],
'definition': ['basename', 'dirname', 'supports_unicode_filenames']}
如何做到這一點的捷徑嗎?
就像你剛剛表明...你究竟問? –
'd = {'definition':defintion,'condition':condition}',不要陰影'字典' – schwobaseggl
我現在正在編輯 –