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.path.dirname(sys.argv)) # line 2: all works in script's folder > relative address
# (rest of my script here!)
Traceback (most recent call last):
File "script.py", line 2, in <module>
OSError: [Errno 2] No such file or directory: ''
Have you noticed that you don't get the error if you run
This is because
sys.argv 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 reads simply
os.path.dirname cannot determine a path.