def _test(): ''' 此处展示如何使用本类 ''' printfgx('%s._test() start' % __file__) hi=HostInfo() # 执行run()来获取当前主机的一些信息,存到一个dict中 hi.run() # 以较为易读的方式输出这个dict hi.put_all() # 将这个dict的内容存入db中,以下两个方法目前对python3支持不是太好 hi.update_to_db() # 从db中读取存入的dict,并以易读的方式输出到终端 hi.check_from_db() printfgx('%s._test() stop ' % __file__)
'a' : 'aa' , 'c' : '123' , 'b' : 324.8 , 123 : 323 , 'daaaaaaaaaaa' : ["172.16.40.109","172.16.40.177"] , 423.4 : 3223873 , 'e' : {'eth0':"172.16.40.109",'eth0:0':"172.16.40.177"} , } #echo_dict(MAP_TEST, 423.4) #echo_dict(memory_stat()) hi=HostInfo() hi.get_xx="" hi.run() hi.put_all() printfgx() #echo_dict(hi.get_mem(),'MemTotal') #echo_dict( hi.get_diskinfo()) printfgx() hi.update_to_db() printfgx() hi.check_from_db() #### NameError("global name 'long' is not defined",) #### TypeError("Type str doesn't support the buffer API",) #### except Exception, x: ^ SyntaxError: invalid syntax #### 'dict_keys' object has no attribute 'sort'