Possible bug in setting Windows file permissions? (os.chmod() not working properly?)

Gus Tabares gus.tabares at verizon.net
Tue Jun 17 01:51:54 CEST 2003


OK I lied. It's 666:)


Sorry,
Gus

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Gus Tabares
Sent: Monday, June 16, 2003 7:50 PM
To: Matthew Shomphe
Cc: python-list at python.org
Subject: RE: Possible bug in setting Windows file permissions?
(os.chmod() not working properly?)


Matt,

	The second parameter to os.chmod() is typical UNIX-style permissions (i.e,
777 is r/w/x). I would suggest firing up google and searching for UNIX
permissions (or something of the sort). I'm pretty positive that
os.chmod(file, 777) will make <file> R/W.


HTH,
Gus

-----Original Message-----
From: Matthew Shomphe [mailto:Matthews at heyanita.com]
Sent: Monday, June 16, 2003 7:44 PM
To: Gus Tabares
Cc: python-list at python.org
Subject: RE: Possible bug in setting Windows file permissions?
(os.chmod() not working properly?)


Gus,

Thanks for the information.  I thought this was the case as well.  However,
in the book (below), it says:

----------------------------------------------------
chmod(path, mode)

Changes the mode of path.  mode has the same values as described for the
open() function.  UNIX and Windows.
----------------------------------------------------

Beazley could full well be wrong (sorry, David! ;).  In the on-line
documentation (http://www.python.org/doc/current/lib/os-file-dir.html) it
says:

------------------------------------------------------------------------
chmod(path, mode)
Change the mode of path to the numeric mode. Availability: Unix, Windows.
------------------------------------------------------------------------

However, I don't see a description of the values for "mode".  I could only
deduce the numeric value required to get read/write permissions by checking
the permissions of a file that I knew to be both readable & writable:

=========================
from stat import *
print os.stat('myReadAndWriteFile.txt')[ST_MODE]
=========================

I can use the numeric value I grabbed from the above output to set
permissions.  However, setting permissions using these raw numeric values
strikes me as A Bad Thing(TM).  It doesn't make the code portable.  And who
knows what Redmond will do in the future?

Let me make my inquiry clearer (I hope):
(1) What are the values expected for the second argument to os.chmod()?
(2) Are these values platform independant?
(3) Is it documented anywhere?

Thanks for your help!

M@

PS.  I'm using python2.3b1



-----Original Message-----
From: Gus Tabares [mailto:gus.tabares at verizon.net]
Sent: Monday, June 16, 2003 4:30 PM
To: Matthew Shomphe; python-list at python.org
Subject: RE: Possible bug in setting Windows file permissions?
(os.chmod() not working properly?)


Matt,

	I do believe os.O_RDWR is specifically for the open() function. Check out
the bottom of this page:
http://www.python.org/doc/current/lib/os-fd-ops.html



HTH,
Gus

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Matt Shomphe
Sent: Monday, June 16, 2003 7:18 PM
To: python-list at python.org
Subject: Possible bug in setting Windows file permissions? (os.chmod()
not working properly?)


I noticed an error when trying to change the file permissions for a
file on a Windows (2K) machine.  I'm using David Beazley's excellent
"Python Essential Reference, 2nd. Ed." as a reference.  According to
the book (p. 186 for those following along at home), it should be used
thusly:

import os
os.chmod('myReadOnlyFile.txt', os.O_RDWR)


Where for os.O_RDWR, you could have any of the modes specified on p.
184.  In other words, all the same bitwise-or modes for opening a
file.  What happens with the above code is: nothing at all.  However,
the following code *will* work to change a file to be accessible:

import os
os.chmod('myReadOnlyFile.txt', 33206)

So, either I am using the os.chmod() function incorrectly, or there is
something wrong elsewhere.

Any hints on what's to be done?

M@
--
http://mail.python.org/mailman/listinfo/python-list



-- 
http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list