引用这个函数时无法打开 headers.json 文件 IOError: [Errno 2] No such file or directory: 'headers.json'

1 hahastudio Oct 6, 2015 这是当然啊,你指望 python 从哪个文件夹找文件啊= = 放到另外一个文件夹,鬼知道是哪个文件夹= = |
2 commoccoom OP @hahastudio 新建文件夹 /Get_HTML headers.json get_html.py __init__.py test.py 结构是这样的,运行 test.py 文件,调用 web_spider 函数,但是无法读取 headers.json 文件 |
3 commoccoom OP |
4 csslayer Oct 6, 2015 使用相对路径时是相对你执行脚本时的工作目录,和代码存放的位置没有关系。 |
5 Kisesy Oct 6, 2015 你只要记住: python 执行的哪个文件,就得跟哪个在一块 |
6 codeforlife Oct 6, 2015 f = open('./Get_HTML/headers.json') |
7 wizardforcel Oct 6, 2015 via Android headers.json 等价于 ./headers.json |