def is_writable(path):
    """Return True if the given path can be written (if it exists) or created
    (if it doesn't exist)
    """
    if os.path.exists(path):
        return os.access(path, os.W_OK)
    else:
        return os.access(os.path.dirname(path), os.W_OK)
Return True if the given path can be written (if it exists) or created
    (if it doesn't exist)
    
stackoverflow/venv/lib/python3.6/site-packages/scrapy/utils/python.py