Python: OSError: [Errno 2] No such file or directory: ''

后端 未结 3 1687
鱼传尺愫
鱼传尺愫 2020-12-05 03:08

I have a 100 lines, 3 years old python scraper that now bug. Starting lines are:

import urllib, re, os, sys, time    # line 1: import modules
os.chdir(os.pat         


        
3条回答
  •  难免孤独
    2020-12-05 03:51

    Have you noticed that you don't get the error if you run

    python ./script.py
    

    instead of

    python script.py
    

    This is because sys.argv[0] will read ./script.py in the former case, which gives os.path.dirname something to work with. When you don't specify a path, sys.argv[0] reads simply script.py, and os.path.dirname cannot determine a path.

提交回复
热议问题