python open找不到文件的原因_python – logger找不到文件
我输入此输入命令时收到此错误:
$python3.4 cron_e2e.py -f test_web_events -E ctg-clickstream testbrad
错误:
$python3.4 cron_e2e.py -f test_web_events -E ctg-clickstream testbrad
Traceback (most recent call last):
File "cron_e2e.py", line 421, in
sys.exit(main(sys.argv))
File "cron_e2e.py", line 368, in main
log.addHandler(logging.FileHandler(logfile))
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/logging/__init__.py", line 1006, in __init__
StreamHandler.__init__(self, self._open())
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/logging/__init__.py", line 1030, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/bli1/Development/QE/chun-qe-trinity-functional/qe/tests/qe/logs/testbrad_8_21_2015_cron.log'
错误发生在这一行:
log.addHandler(logging.FileHandler(logfile))
不太确定我的代码在哪里不为我创建日志文件
码:
def main(argv):
"Test"
exit_code = 0
global me; me = os.path.basename(argv[0]) # name of this program
global mydir; mydir = os.path.dirname(os.path.abspath(__file__))
parser = argparse.ArgumentParser(description=main.__doc__)
parser.add_argument("-f", "--functional_test", metavar="FUNCTEST",
dest="functest", help="Type of functional test")
parser.add_argument("-p","--phase", action="append",
metavar="POST|HDFS|HIVE|ALL", dest="phase",
help="phase of test to run")
parser.add_argument("-t", "--testfile", metavar="TESTFILE",
dest="testfile", default=os.path.join(mydir, "resources/cron.json"),
help="file with test commands")
parser.add_argument("-E","--Event", metavar="EVENTNAME",
dest="event_names", action="append",
help="[repeatable] topic to which to post")
parser.add_argument("runtag",
metavar="RUNTAG",
help="run tag for this run")
args = parser.parse_args(args=argv[1:]) # will exit on parse error
log = logging.getLogger(me)
log.setLevel(logging.INFO)
dt = datetime.datetime.utcnow()
logfile = "qe/logs/" + (args.runtag + "_{}_{}_{}".format(dt.month, dt.day, dt.year) + "_cron.log")
pdb.set_trace()
if isinstance(logfile, str):
if os.path.exists(logfile):
os.remove(logfile)
# logging.FileHandler() returns FileHandler class, the file is opened and used as the stream for logging
log.addHandler(logging.FileHandler(logfile))
console = logging.StreamHandler(sys.stderr); console.setLevel(logging.WARNING); log.addHandler(console)
解决方法:
问题是您定义要转到的日志文件的目录 – “qe / logs /” – 不存在.
默认情况下,FileHandler的模式为“a”,这意味着如果日志文件存在,它将打开它并在最后开始追加它,否则它将创建该文件.
但是FileHandler只会创建日志文件,如果它不存在,它就不会创建目录,如果该目录不存在,如果该目录不存在,它会抛出一个类似你的错误.
您需要手动或以编程方式自己创建目录.如果要以编程方式创建目录,可以使用 – os.makedirs() – 这将 –
create all intermediate-level directories needed to contain the leaf directory.
示例 –
import os, os.path
if not os.path.exists("qe/logs/"):
os.makedirs("qe/logs/")
标签:python,python-3-x,logging
来源: https://codeday.me/bug/20190727/1557884.html
python open找不到文件的原因_python – logger找不到文件相关推荐
- python xlrd读取文件报错_python利用xlrd读取excel文件始终报错原因
1.代码按照网上百度的格式进行书写如下: 但运行后,始终报错如下: 百度了xlrd网页: 分明支持xls和xlsx两种格式的文件,但运行始终报错. 最后找到原因是因为我所读取的文件虽然是以.xls命名 ...
- python读取压缩文件的大小_python查看zip包中文件及大小的方法
python查看zip包中文件及大小的方法 本文实例讲述了python查看zip包中文件及大小的方法.分享给大家供大家参考.具体实现方法如下: #!/usr/bin/env python import ...
- python文件同时读写_python 同时读取多个文件的例子
Python中打开文本使用的是with语句,比如打开一个文件并读取每一行 with open(filename) as fp: for line in fp: # do something 为了同时读 ...
- python数据写入csv会丢失0字头_python csv模块生成CSV文件,0字头数字缺失,汉字乱码...
python CSV模块 写入CSV文件时,0开头的数字会丢失 # _*_ coding:utf-8 _*_ #win7+python2.7.x import csv csvfile = file(' ...
- python安装找不到.log的文件_python – logger找不到文件
我输入此输入命令时收到此错误: $python3.4 cron_e2e.py -f test_web_events -E ctg-clickstream testbrad 错误: $python3.4 ...
- python文件输入符_python基础入门详解(文件输入/输出 内建类型 字典操作使用方法)...
一.变量和表达式 >>> 1 + 1 2 >>> print 'hello world' hello world >>> x = 1 >&g ...
- python循环控制语句将数值转化成字符串_python基础入门详解(文件输入/输出内建类型字典操作使用方法)...
f=open("foo.txt") line=f.readline() while line: print line, line=f.readline() #读取一行,包括换行符' ...
- python的requests库发送携带上传文件的接口_python requests 库请求带有文件参数的接口实例...
python requests 库请求带有文件参数的接口实例 有些接口参数是一个文件格式,比如fiddler 抓包参数如下显示 这个接口的 form-data fiddler 显示的和不带文件参数的接 ...
- python selenium 文件上传_Python+Selenium学习--上传文件
场景 文件上传操作也比较常见功能之一,上传功能操作webdriver 并没有提供对应的方法,关键上传文件的思路. 上传过程一般要打开一个系统的window 窗口,从窗口选择本地文件添加.所以,一般会卡 ...
最新文章
- 科普|什么是负载均衡(Load balancing)
- mkdir()提示No such file or directory错误的解决方法
- 并发数据结构-1.1.2 阻塞技术
- C语言fwrite函数了解
- 【软件测试】《软件测试技术基础》知识点整理
- pyppeteer-比 selenium 更高效的爬虫利器
- 信息论基础——消息,信息,信号区别 信息的度量
- 卷皮网aso优化数据分析报告
- 如何找到电脑自带的浏览器
- 使用python创建数组的方法
- 今天不忙,咱们来说说域名是什么意思?
- Access Key / Secret key 密钥安全原理架构
- App推广应该避免的十大误区
- PC-Lint的使用方法
- O32 对接 交易所报盘软件_沈阳企业“新”社保报盘软件(下载地址)!
- Rust中的channel
- 爬取百思不得姐的段子
- 前端架构 101(六):整洁(Clean Architecture)架构是归宿
- 叮,一份详细的LIN收发器选型指南请查收
- 2018年又传喜报!热烈祝贺王家林大师大数据经典著作《Spark SQL大数据实例开发教程》 畅销书籍 出版上市!
热门文章
- Bailian2943 小白鼠排队【排序】
- 分布式设计 —— 容错与主备
- C Tricks(十六)—— 复制字符串
- 机器学习基础(四)——持久化分类器
- lc滤波电路电感电容值选择_模拟电路中,电感的这些知识点你都清楚吗?
- 2018年python工作好找吗-2018年最新数据:python、大数据、人工智能从业者薪资表...
- python能做什么-python能用来做什么?这3大主要用途你一定要知道!(实用)
- python和c 的区别-Python和c语言的主要区别在哪
- python爬虫-Python爬虫学习之(一)| 从零开始
- python和java的区别-python与java区别