课堂笔记随记10-pycharm使用技巧v0_第1页
课堂笔记随记10-pycharm使用技巧v0_第2页
课堂笔记随记10-pycharm使用技巧v0_第3页
课堂笔记随记10-pycharm使用技巧v0_第4页
课堂笔记随记10-pycharm使用技巧v0_第5页
已阅读5页,还剩1页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、思路分解:1- 获取文件中每一行的信息:学生 id 课程 id 签到时间2- 按照要求去统计3- 输出step over-单步运行每一行为一步def func():pr(1)pr(2)pr(3)pr(4)#1- 获取文件中每一行的信息:学生 id 课程 id 签到时间fileDir = rG:0005_1.txtdef putInfoToDict(fileName):resDict = #1- 打开文件with open(fileName) as fo:#2-所有行lines = fo.read().splitlines()#返回是 list#3- 对每一行进去提取数据-遍历for line

2、in lines:# info = #临时的字典line =line.replace(t,).replace(,).replace(),).replace(,)#切割 ,temp = line.split(,)checkTime = temp0lessonId =(temp1)userId =(temp2)#2- 按照要求去统计info = lessonid:lessonId, checkime:checkTime# infolessonid = lessonId# infocheckime = checkTimeif userId in resDict:#如果学生 id 在里面resDict

3、userId.append(info)else:#新增键值对import loggingLOG_FORMAT = %(asctime)s - %(levelname)s - %(message)sDATE_FORMAT = %m/%d/%Y %H:%M:%S %plog_file = G:/basic20200315.loglogging.basicConfig(filename=log_file,level=logging.DEBUG,formOG_FORMAT,datefmt=DATE_FORMAT)# logging.basicConfig(filename=log_file, leve

4、l=logging.DEBUG)logging.debug(this is a debugmsg!)(this is a infomsg!)logging.warning(this is a warn msg!)logging.error(this is a error msg!)logging.critical(this is a criticag!)时间级别重要数据异常信息等resDictuserId = info# func()return resDictres = putInfoToDict(fileDir)# pr(res)#完美打印import pprppr

5、.ppr(res)#json# import json# pr(json.dumps(res,indent=1)import loggingfrom logging.handlers import RoingFileHandlerimport datetime# pr(datetime.datetime.now().strftime(%Y_%m_%d_%H_%M_%S)STYLE = fore:# 前景色black: 30,# 黑色red: 31,# 红色green: 32,# 绿色yellow: 33,# 黄色blue: 34,# 蓝色purple: 35,# 紫红色cyan: 36,# 青

6、蓝色white: 37,# 白色,back :# 背景black: 40, # 黑色red: 41, # 红色green: 42, # 绿色yellow: 43, # 黄色blue: 44, # 蓝色purple: 45, # 紫红色cyan: 46, # 青蓝色white: 47, # 白色,mode :# 显示模式mormal: 0,# 终端默认设置 bold: 1,#显示 underline : 4,# 使用下划线blink: 5,# 闪烁invert: 7,# 反白显示hide: 8,# 不可见,default :end : 0,def UseStyle(string, mode =

7、, fore = , back = ):mode = %s % STYLEmodemode if STYLEmode.get(mode) elsefore = %s % STYLEforefore if STYLEfore.get(fore) elseback = %s % STYLEbackback if STYLEback.get(back) elsestyle = ;.join(s for s in mode, fore, back if s)style = 033%sm % style if style else end= 033%sm % STYLEdefaultend if sty

8、le else return %s%s%s % (style, string, end)debug:最细微的信息到 debug 中,这个级别就是用来 debug 的,看程序在哪一次迭发生了错误,比如每次循环都输出一些东西用 debug 级别info:级别用于 routines,也就是输出 start finish 状态改变等信息warn:输出一些相对重要,但是不是程序 bug 的信息,比如输入了错误的,或者连接较慢error:输出程序 bug,打印异常信息critical:用于处理一些非常糟糕的事情,比如内存溢出、磁盘已满,这个一般较少使用class Logger:def init (self

9、,inLevel=DEBUG,inName= name ):self.logger = logging.getLogger(inName)self.logger.setLevel(inLevel)self.formatter = logging.Formatter(%(asctime)s - %(name)s- %(levelname)s - %(message)s)def addHand(self,source):self.logger.addHandler(source)def debug(self, msg):self.logger.debug(msg)def info(self, ms

10、g):(msg)def warning(self, msg):self.logger.warning(msg)def error(self, msg):self.logger.error(msg)#def critical(self, msg):self.logger.criticag)class FileLogger(Logger):#log 文件输出类def init (self, logName):Logger. init (self, inLevel=DEBUG, inName= name )self.loggerName = logNameself.r

11、Handler =RoingFileHandler(_.log.format(self.loggerName,datetime.datetime.now().strftime(%Y_%m_%d_%H_%M_%S),maxBytes = 1*1024,backupCount =3,encoding=utf-8)self.rHandler.setFormatter(self.formatter)self.addHand(self.rHandler)class ConsoleLogger(Logger):#控制台输出日志类def init (self):Logger. init (self, inL

12、evel=DEBUG, inName= name )self.console = logging.StreamHandler()self.console.setFormatter(self.formatter)self.addHand(self.console)def debug(self, msg):self.logger.debug(UseStyle(msg, fore = black)#黑色def info(self, msg):(UseStyle(msg, fore = blue)#蓝色def warning(self, msg):self.logger.warning(UseStyle(msg, fore = yellow)#黄色def error(self, msg):self.logger.error(UseStyle(msg, fore = red)#红色def cr

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论