摘要: 断言: 阅读全文
posted @ 2018-03-18 17:26 梦中琴歌 阅读(135) 评论(0) 推荐(0) 编辑
摘要: #coding=utf-8 names = ['a','b'] try: names[3] # except IndexError as e: # print '123214',e # except (KeyError,IndexError) as e: # print 'asdasd',e # except Exception as e: #捕获所有异常,不建议... 阅读全文
posted @ 2018-03-17 23:51 梦中琴歌 阅读(98) 评论(0) 推荐(0) 编辑
摘要: #coding=utf-8 class Dog(object): def __init__(self,name): self.name = name def eat(self): print '1234' def talk(self): print '678678' d = Dog('xiaobai') #choice = raw_i... 阅读全文
posted @ 2018-03-17 02:31 梦中琴歌 阅读(93) 评论(0) 推荐(0) 编辑
摘要: #coding=utf-8 class Dog(object): ''' 类的描述 ''' def __init__(self,name): self.name = name self.__food = None @staticmethod #实际上跟类没什么关系,单纯的函数,但是必须通过类名来调用 d... 阅读全文
posted @ 2018-03-17 01:56 梦中琴歌 阅读(158) 评论(0) 推荐(0) 编辑
摘要: 深度优先与广度优先 阅读全文
posted @ 2018-03-16 00:08 梦中琴歌 阅读(157) 评论(0) 推荐(0) 编辑
摘要: #coding=utf-8 """ 实例的变量又叫类的静态属性 类的方法又叫类的动态属性 类变量与实例变量的区别 x不用实例化就可以调用 所有实例都可以调用x """ class role(): x = "1234" def __init__(self,name): self.name = name print role.x print role("zq").... 阅读全文
posted @ 2018-03-15 01:14 梦中琴歌 阅读(140) 评论(0) 推荐(0) 编辑
摘要: class 类 对一类拥有相同属性的对象的抽象、蓝图、原型,在类中定义了这些对象都具备的属性、共同方法 object对象 一个对象就是一个类的实例化模型,一个类必须经过实例化后才能在程序中调用,一个类可以实例化多个对象 类的三大特性: 1、封装 在类中对数据赋值。内部调用对外部用户是透明的、里面包含 阅读全文
posted @ 2018-03-15 00:32 梦中琴歌 阅读(570) 评论(0) 推荐(0) 编辑
摘要: #coding=utf-8 import ConfigParser #配置文件模块 import hashlib #用于加密的模块 m = hashlib.md5() m.update(b'hello') print m.hexdigest() m.update(b'i am oung ') print m.hexdigest() m1 = hashlib.sha1() m1.up... 阅读全文
posted @ 2018-03-14 00:24 梦中琴歌 阅读(104) 评论(0) 推荐(0) 编辑
摘要: #coding=utf-8 import sys ## sys.argv #从命令行获取参数 import shutil #文件、文件夹、压缩包、处理模块 f1 = open("test.txt") f2 = open("test2.txt","wb") #shutil.copyfileobj(f1,f2) shutil.copyfile("test.txt","test2.txt") shut... 阅读全文
posted @ 2018-03-13 23:51 梦中琴歌 阅读(112) 评论(0) 推荐(0) 编辑
摘要: #coding=utf-8 import os os.getcwd() #获取目录 os.chdir(r'C:\user') #切换目录 os.curdir() #获取当前目录 os.pardir() #获取当前目录的父目录 os.makedirs(r'C:\a\b\v\d') #创建目录 os.removedirs(r'C:\a\b\v\d') #目录为空则删除 os.mkdir() #单次... 阅读全文
posted @ 2018-03-13 23:50 梦中琴歌 阅读(73) 评论(0) 推荐(0) 编辑