Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read/Write files in Python

I need to make a file readable and writable in python. Currently the file is read-only. I am running on a Windows machine. I run the following code:


os.chmod(projectPath, stat.S_IWRITE | stat.S_IREAD)

on a file that needs to be read/write. But when I try to execute the file that needs to be read write, I get the following:


ISDEV : fatal error -2200: Could not overwrite file C:\WINDOWS\Temp\STixInstaller\STixInstallShield.ism

So obviously, it is not making the file read/write. I then check the file permissions and it is still read-only.

Any ideas why this fails or if there is an easier way to do this I am missing?

like image 719
user489041 Avatar asked Apr 25 '11 15:04

user489041


1 Answers

I think you only need the stat.S_IWRITE mode. I just ran a test with this code

def main():
    path = "C:\\temp\\log.txt"
    os.chmod(path, stat.S_IWRITE)

And it set a file that was read only to not read only, where as when I ran it with S_IREAD instead, it set it back to read only

like image 195
keepitreall89 Avatar answered Oct 24 '22 20:10

keepitreall89