2018年6月28日

用sys模块创建一个进度条

摘要: import sys import time def view_bar(num, total): rate = num / total rate_num = int(rate * 100) r = "\r%s>%d%%" % ("=" * num, rate_num,) # \r:回到当前行的第一个位置 sys.stdout.write(r) #这里不能... 阅读全文

posted @ 2018-06-28 22:01 你是不夜星空 阅读(89) 评论(0) 推荐(0) 编辑

模块中的特殊变量

摘要: print(__file__) #获取当前pyc的相对路径 print(__doc__) #获取注释 import os os.path.abspath() #获取某个文件的绝对路径 os.path.dirname() #获取某个文件的上级目录 sys.path.append(os.path.dirname()) #添加目录名 import xxx print(xxx.__package... 阅读全文

posted @ 2018-06-28 20:38 你是不夜星空 阅读(72) 评论(0) 推荐(0) 编辑

多模块的结合---getattr

摘要: 举例如下: 阅读全文

posted @ 2018-06-28 19:52 你是不夜星空 阅读(142) 评论(0) 推荐(0) 编辑

日志的一般用法 log

摘要: import logging # logging.warning("warning: error") # logging.critical("112233455") # logging.basicConfig(filename="sample_logging",level=logging.debug("111")) #在debug级别之上的信息才被记录 # logging.basicCon... 阅读全文

posted @ 2018-06-28 18:53 你是不夜星空 阅读(631) 评论(0) 推荐(0) 编辑

2018年6月25日

装饰器的嵌套

摘要: user_info = {}def check_login(func): def inner(*args, **kwargs): if user_info.get("in_login", None): ret = func(*args, **kwargs) return ret else: prin 阅读全文

posted @ 2018-06-25 14:46 你是不夜星空 阅读(132) 评论(0) 推荐(0) 编辑

2018年6月20日

装饰器——test

摘要: LOGIN_USER = {"is_login": False} def outer(func): def inner(*args, **kwargs): if LOGIN_USER['is_login']: r = func() return r else: print("请登陆... 阅读全文

posted @ 2018-06-20 18:47 你是不夜星空 阅读(91) 评论(0) 推荐(0) 编辑

2018年6月17日

产生6位的随机码

摘要: import randomli=[]for i in range(6): r=random.randrange(0,6) if r==3 or r==5: num=random.randrange(1,10) li.append(str(num)) else: temp = random.randr 阅读全文

posted @ 2018-06-17 20:10 你是不夜星空 阅读(176) 评论(0) 推荐(0) 编辑

2018年6月14日

用户输入注册的小程序

摘要: def login(username, password): f = open("sample2", "r") for line in f: line_list = line.split(":") if line_list[0] == username and line_list[1] == password: retu... 阅读全文

posted @ 2018-06-14 19:21 你是不夜星空 阅读(189) 评论(0) 推荐(0) 编辑

2018年6月7日

进度条的小程序

摘要: import sys, time for i in range(50): sys.stdout.write("...") sys.stdout.flush time.sleep(0.3) 阅读全文

posted @ 2018-06-07 20:31 你是不夜星空 阅读(128) 评论(0) 推荐(0) 编辑

文件的相关操作---读写与修改

摘要: '''f=open("sample",'r',encoding="utf-8") #打开文件,替代使用utf-8,默认只读,若要写,中间加 w;若在中加a,则追加,a=append; ''' '''data=f.read() print(data) ''' '''for i in range(3): #打印某几行 print(f.readline()) ''' ''' fo 阅读全文

posted @ 2018-06-07 20:30 你是不夜星空 阅读(139) 评论(0) 推荐(0) 编辑

导航