# Re: weird problem with os.chmod

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

1. ### James ColanninoGuest

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

2. ### =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=Guest

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

3. ### Mike MeyerGuest

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/

Mike Meyer, Nov 12, 2005
4. ### Peter HansenGuest

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
5. ### Fredrik LundhGuest

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
6. ### Bengt RichterGuest

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
7. ### Fredrik LundhGuest

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