weird problem with os.chmod

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Sat Nov 12 11:37:59 EST 2005


Gary Herron wrote:
> James Colannino wrote:
> 
>> James Colannino wrote:
>>
>>  
>>
>>> So then I entered the command print 0600, and saw that the actual
>>> number being output was 384 (why would it output 384?!)
>>>
>>>
>>>   
>>
>>
>> Ok, so further research revealed that 0600 is actually the octal
>> representation for 384 (which makes sense.)  So then, I guess my
>> question would have to be, is there a way for me to make Python aware
>> that the 0600 I'm passing to int() is octal and not decimal so that I
>> will get 384 instead of 600?
>>  
>>
> int('0600',8) will do, but why would you want to do that?
> 
> Any of
> x = 0600
> x = 384
> x = 0x180
> x = int('0600',8)
> will bind x to the same value (110000000 in binary if you care).
> 
> But once you've got the valued defined, through whatever human readable
> representation you want, the command
> chmod(filename, x)
> can be issued without further thought.

He reads the string ('0600' in this case, but I guess it can be any
permission) from a file. So he doesn't have the numerical value to begin
with.

BTW, I guess it's safer to do int(permission, 8) than int(permission,
0), since the first digit isn't guaranteed to be zero: it is used for
set user ID, set group ID and the sticky bit.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven



More information about the Python-list mailing list