zoukankan      html  css  js  c++  java
  • python3输出指定log信息

    问题背景:

    win10

    python xxx.py > c:test.txt

    上面这句只能把信息输出到test.txt,但是控制台看不到信息

    #######################################################################

    要想在控制台和test.txt同时得到信息,如下操作:

    官网源码:

    import logging
    logging.basicConfig(filename='log_examp.log',level=logging.DEBUG)#level=logging.DEBUG定义日志级别

    logging.debug('This message should go to the log file')#输出级别level=logging.DEBUG
    logging.info('So should this')#输出级别level=logging.INFO
    logging.warning('And this, too')#输出级别level=logging.WARNING

    实战项目部分代码:

     1 def a(self):
     2         #with open("info.csv","r") as csvfile:
     3         with open("产品库模板(PLT导入)20161205_01.csv","r") as csvfile:
     4             #读取csv文件,返回的是迭代类型
     5             self.read = csv.reader(csvfile)
     6             for self.i in self.read:
     7                 if self.i[8] =="" or self.i[8]=="9" or self.i[8]=='项目编号':
     8                     continue
     9                 else :
    10                     try:
    11                         self.b(self.i)
    12                     except Exception as e:
    13                         print(e)
    14             self.logging.info(e)
    15 
    16                     finally:
    17                         print(self.i[8])
    18           self.logging.info(self.i[8])
  • 相关阅读:
    LeetCode 50. Pow(x, n)
    java方法的多态性理解
    向量的相似性度量
    LeetCode 43. Multiply Strings
    java中的字符编码方式
    LeetCode 67. Add Binary
    LeetCode 2. Add Two Numbers
    LeetCode 13. Roman to Integer
    linux-系统启动过程,执行的配置文件
    linux-后台运行程序-nohup
  • 原文地址:https://www.cnblogs.com/imtester/p/6146926.html
Copyright © 2011-2022 走看看