os.chmod() question ?

Ben Hutchings do-not-spam-ben.hutchings at businesswebsoftware.com
Thu Apr 3 19:04:39 CEST 2003


In article <bd993a2f.0304022308.19f36fec at posting.google.com>,
Anand B Pillai wrote:
> Hi pythonfolks,
>  
>     What numerical argument does os.chmod() accept on windoze .
> For a unix box, I used to give the following for files:
> 
> chmod - 777 => All rwx permissions enabled (-rwxrwxrwx)
> chmod - 644 => RW for owner, r for group/world (-rw-r--r--)
> 
> I attempted os.chmod() command on Windoze on similar lines
> on a read-only file.
<snip> 
>     Apparently, os.chmod() works differently from original chmod() command.
> On a unix box, the results were totally different.
> 
> Do I need to pass an octal integer as the second argument ?

The Python interpreter can't interpret literals in different bases
according to which function you call, so you must put a '0' at the
beginning of octal numbers.

Anyway, Windows file permissions work in a totally different way
from Unix permissions.  The only simple flag is the R (read-only)
attribute.  In NT/2000/XP all other permissions are controlled by
an ACL.  In toy Windows everything else is always permitted.

Under Windows, I think os.chmod() ignores everything except the
owner-writable flag (0200) and sets the R attribute to the inverse
of that.  Cygwin will show permissions as either 0777 or 0555
depending on the state of the R attribute.

So 777 decimal = 01411 octal which means the R attribute is set
and the permissions read as 0555, and 644 decimal = 01204 octal
which means the R bit is cleared and the permissions read as 
0777.  All clear?




More information about the Python-list mailing list