views:

189

answers:

2

Hi,

I'm a beginner in python and I'm trying to use a octal number in my script, but when I try it, it returns me that error:

>>> a = 010
SyntaxError: invalid token (<pyshell#0>, line 1)
>>> 01
SyntaxError: invalid token (<pyshell#1>, line 1)

There's something wrong with my code? I'm using Python3 (and reading a python 2.2 book)

+13  A: 

Try 0o10, may be because of python 3, or pyshell itself.

PEP says,

octal literals must now be specified with a leading "0o" or "0O" instead of "0";

http://www.python.org/dev/peps/pep-3127/

S.Mark
I wish every language required this for octal numbers; how stupid was using a lead 0. Now if we can just get support for 0sNNN (for sexagesimal) and put base-64 numbers into our code.
Software Monkey
Think of the possibilities for magic constants... no longer being constrained to `0xdeadbeef`, etc. :o
Andrew Keeton
Thank S.Mark, using the "Oo" works just fine.
Rafael
+1  A: 

What is the version of Python? At least Python 2.6 process such statements correctly:

a=010
print a
8

Vladimir Aks