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