Re: weird problem with os.chmod

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

  1. 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?

    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 wrote:
    > 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?


    Try this:

    http://docs.python.org/lib/built-in-funcs.html#l2h-39

    Regards,
    Martin
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=, Nov 12, 2005
    #2
    1. Advertising

  3. James Colannino

    Mike Meyer Guest

    James Colannino <> writes:
    > 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?


    Strange that int doesn't recognize the leading 0. But you can use the
    second argument to int:

    >>> int("0600", 16)

    1536
    >>>


    <mike
    --
    Mike Meyer <> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
    Mike Meyer, Nov 12, 2005
    #3
  4. James Colannino

    Peter Hansen Guest

    Mike Meyer wrote:
    > Strange that int doesn't recognize the leading 0. But you can use the
    > second argument to int:
    >
    >>>>int("0600", 16)

    >
    > 1536


    You can use it another way too:

    >>> int('0600', 0)

    384
    >>> int('0x180', 0)

    384
    >>> 0600

    384

    -Peter
    Peter Hansen, Nov 12, 2005
    #4
  5. Mike Meyer wrote:

    > Strange that int doesn't recognize the leading 0. But you can use the
    > second argument to int:
    >
    > >>> int("0600", 16)

    > 1536
    > >>>


    int is designed for humans, not C programmers. humans tend to view
    e.g. "08" as a valid decimal number (*), not a ValueError.

    to get programmer behaviour, pass in 0 as the base:

    >>> int("10", 0)

    10
    >>> int("010", 0)

    8
    >>> int("0x10", 0)

    16

    </F>

    *) unless you're living in sweden, in which case "08" is quite often used
    as an insult.
    Fredrik Lundh, Nov 12, 2005
    #5
  6. On Sat, 12 Nov 2005 12:53:17 +0100, "Fredrik Lundh" <> wrote:
    [...]
    >int is designed for humans, not C programmers. humans tend to view
    >e.g. "08" as a valid decimal number (*), not a ValueError.

    [...]
    ></F>
    >
    >*) unless you're living in sweden, in which case "08" is quite often used
    >as an insult.


    I am always curious about languages, and considering my name, I think I'd
    like to know this definition ;-) Is it telephone-exchange-related?
    Or a police code for something? Can you say, delicately?
    (jag stavar daligt, men det gar bra pa Svenska om det ar omogligt at oversatta ;-)

    Regards,
    Bengt Richter
    Bengt Richter, Nov 12, 2005
    #6
  7. Bengt Richter wrote:

    > >*) unless you're living in sweden, in which case "08" is quite often used
    > >as an insult.

    >
    > I am always curious about languages, and considering my name, I think I'd
    > like to know this definition ;-) Is it telephone-exchange-related?


    it's the area code for Stockholm. I think you can figure the rest out
    yourself ;-)

    > ... det gar bra pa Svenska om det ar omogligt at oversatta ;-)


    här finns lite mer bakgrund:

    http://susning.nu/Noll%E5tta
    http://susning.nu/Stockholmare

    </F>
    Fredrik Lundh, Nov 12, 2005
    #7
    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,051
    Steve Grazzini
    Jul 25, 2003
  2. Brad Cooper

    Chmod from Runtime.Exec

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

    weird problem with os.chmod

    James Colannino, Nov 12, 2005, in forum: Python
    Replies:
    1
    Views:
    354
    Mardy
    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