Connecting Tech Pros Worldwide Forums | Help | Site Map

weird problem with os.chmod

James Colannino
Guest
 
Posts: n/a
#1: Nov 12 '05
Ok, so now I have a very interesting problem, this time related to
os.chmod. I have the following in a text file: 0600. My script reads
that number as a string and converts it to an integer for use with
chmod. However, when I do this, instead of the rw------ permissions
that I expect, I get ---x-wx--T. I tried placing 0600 directly in the
command (chmod(filename, 0600)), and that worked as expected (I got
rw------). So then I entered the command print 0600, and saw that the
actual number being output was 384 (why would it output 384?!) I put
384 in place of 0600 (chmod(filename, 384)), and again I got what I
wanted (rw------). So, I guess the number 0600 is actually being
converted to 384. However, this leaves me with the question: how
exactly do I go about getting the number 0600 from my file and turning
it into something I can use? int(string) gives me 600, not 384 (which
results in the funky permissions.) If I could figure out how Python was
converting 0600 to 384, I could try to emulate that behavior in my
script. Any input would be greatly appreciated.

James

--
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"A well regulated militia being necessary to the security of a free
state, THE RIGHT of the people to keep and bear arms SHALL NOT BE
INFRINGED." --United States Constitution, Second Ammendment


Mardy
Guest
 
Posts: n/a
#2: Nov 22 '05

re: weird problem with os.chmod


On Fri, 11 Nov 2005 16:49:23 -0800, James Colannino wrote:[color=blue]
> Ok, so now I have a very interesting problem, this time related to
> os.chmod. I have the following in a text file: 0600. My script reads
> that number as a string and converts it to an integer for use with
> chmod. However, when I do this, instead of the rw------ permissions[/color]

0600 is the octal representation of 384. "man chmod" should help you.
Just use
perm = int(string, 8)
instead of
perm = int(string)
when converting to int the string you read from the file.


--
Saluti,
Mardy
http://interlingua.altervista.org

Closed Thread