2018年5月20日

main

摘要: if __name__ == '__main__':#判断这个Python文件是导入的,还是直接在运行这个Python文件 这句话一般是做调试的时候用的。 如果是直接运行这个Python文件的时候,这个一点用都没有 阅读全文

posted @ 2018-05-20 14:51 公子兔 阅读(162) 评论(0) 推荐(0) 编辑

class私有

摘要: import redisclass My(object): def __init__(self): self.__host='118.24.3.40'#self变量前面加__,出了类就不能用了 self.__port=6379 self.__password='HK139bc&*' self.r=r 阅读全文

posted @ 2018-05-20 14:50 公子兔 阅读(153) 评论(0) 推荐(0) 编辑

根据签名规则,加密URL

摘要: from urllib import parseurl='http://www.baidu.com?query=python基础教程'url_str=parse.quote_plus(url)#URL编码baidu_url='http%3A%2F%2Fwww.baidu.com%3Fquery%3D 阅读全文

posted @ 2018-05-20 14:48 公子兔 阅读(197) 评论(0) 推荐(0) 编辑

class连接数据库

摘要: import pymysqlclass MyDb(object): def __init__(self,host,user,passwd,db,port=3306,charset='utf8'): try: self.coon=pymysql.connect( host=host,user=user 阅读全文

posted @ 2018-05-20 14:46 公子兔 阅读(578) 评论(0) 推荐(0) 编辑

类方法@classmethod、属性方法@property、静态方法 @staticmethod

摘要: class Baby(): # def __init__(self,name):#构造函数不是必须得 # print('self的内存地址',id(self)) # self.name=name # #self代表的就是实例化之后的对象 # self.money=5000 # self.sex='女 阅读全文

posted @ 2018-05-20 14:44 公子兔 阅读(247) 评论(0) 推荐(0) 编辑

class继承

摘要: class Lz(object): def __init__(self): self.money=1000000000000 self.house='大别野' def sing(self): print('唱歌') def dance(self): print('跳广场舞') def lm(self 阅读全文

posted @ 2018-05-20 14:41 公子兔 阅读(179) 评论(0) 推荐(0) 编辑

导航