Last active
January 4, 2016 10:59
-
-
Save huyx/8612381 to your computer and use it in GitHub Desktop.
文件和目录是否可写
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import tempfile | |
def dir_writeable(dir): | |
try: | |
(fd, name) = tempfile.mkstemp(dir=dir) | |
os.close(fd) | |
os.unlink(name) | |
except IOError: | |
return False | |
return True | |
def file_writeable(filename): | |
return os.access(filename, os.W_OK) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment