摘要: #pickling import pickle,json # d = dict(name='傻狗1',age=300,score=100) # d1 = pickle.dumps(d)#pickle.dumps()方法把任意对象序列化成一个bytes,然后,就可以把这个bytes写入文件 # print(d1)#b'\x80\x03}q\x00(X\x04\x00\x00\x00nameq\x0... 阅读全文
posted @ 2019-05-20 15:55 周大侠小课堂 阅读(194) 评论(0) 推荐(0)
摘要: class Point(object): # def get_score(self): # return self.score # def set_score(self,value): # if not isinstance(value,(int)): # raise ValueError('score must be ... 阅读全文
posted @ 2019-05-20 08:47 周大侠小课堂 阅读(203) 评论(0) 推荐(0)
摘要: class Point(object): __slots__ = ('name','point') p1 = Point() p1.name = 100 print(p1.name)#100 #p1.score = 200#由于'score'没有被放到__slots__中,所以不能绑定score属性,试图绑定score将得到AttributeError的错误 #使用__slots__要... 阅读全文
posted @ 2019-05-20 08:46 周大侠小课堂 阅读(176) 评论(0) 推荐(0)
摘要: import types print(type('abc') == str)#True print(type(123) == int)#True def f1(): pass print(type(f1) == types.FunctionType)#True print(type(abs) == types.BuiltinFunctionType)#True print(type(l... 阅读全文
posted @ 2019-05-20 08:45 周大侠小课堂 阅读(784) 评论(0) 推荐(0)
摘要: class Point(object): def __init__(self,name,score): self.__name = name self.__score = score def print_data(self): print('name:%s score:%s' % (self.__name,self.__score... 阅读全文
posted @ 2019-05-20 08:43 周大侠小课堂 阅读(506) 评论(0) 推荐(0)