python getattr函数的妙用

import platform

class Test:
def test(self):
func = getattr(self,'windows')
func()

@staticmethod
def windows():
from plugins.collect_windows_info import Win32Info
return Win32Info().collect() #在调用self对象时,本类调用用Win32Info().collect()
@staticmethod
def linux():
return 'OK2'





if __name__ == '__main__':
ob = Test()
ob.test()
print(ob.windows())
原文地址:https://www.cnblogs.com/cheyunhua/p/12092094.html