weird problem with os.chmod

J

James Colannino

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
 
M

Mardy

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

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top