weird problem with os.chmod

Discussion in 'Python' started by James Colannino, Nov 12, 2005.

  1. 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
    James Colannino, Nov 12, 2005
    #1
    1. Advertising

  2. James Colannino

    Mardy Guest

    On Fri, 11 Nov 2005 16:49:23 -0800, James Colannino wrote:
    > 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.


    --
    Saluti,
    Mardy
    http://interlingua.altervista.org
    Mardy, Nov 12, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Lubavin
    Replies:
    1
    Views:
    3,047
    Steve Grazzini
    Jul 25, 2003
  2. Brad Cooper

    Chmod from Runtime.Exec

    Brad Cooper, May 13, 2004, in forum: Java
    Replies:
    3
    Views:
    10,070
    Brad Cooper
    May 13, 2004
  3. Bob K.
    Replies:
    9
    Views:
    1,553
    PeterMcC
    Jul 5, 2004
  4. James Colannino

    Re: weird problem with os.chmod

    James Colannino, Nov 12, 2005, in forum: Python
    Replies:
    6
    Views:
    375
    Fredrik Lundh
    Nov 12, 2005
  5. James Colannino

    Re: weird problem with os.chmod

    James Colannino, Nov 12, 2005, in forum: Python
    Replies:
    2
    Views:
    335
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
    Nov 12, 2005
Loading...

Share This Page