python doesn't like my numbers

P

paul k

hi,

is there any way to convince python not to take my (phone)numbers
starting with zero as octals?
File "<stdin>", line 1
int(088)
^
SyntaxError: invalid token

thanks
Paul
 
P

Peter Kleiweg

paul k schreef:
hi,

is there any way to convince python not to take my (phone)numbers
starting with zero as octals?

File "<stdin>", line 1
int(088)
^
SyntaxError: invalid token


What is the integer value of a phone number?
 
R

Reid Nichol

paul said:
hi,

is there any way to convince python not to take my (phone)numbers
starting with zero as octals?

File "<stdin>", line 1
int(088)
^
SyntaxError: invalid token

thanks
Paul

int("088")
 
A

Alan Kennedy

[paul k]
is there any way to convince python not to take my (phone)numbers
starting with zero as octals?

File "<stdin>", line 1
int(088)
^
SyntaxError: invalid token

Answer 1: Use strings: that's really what telephone numbers should be

Answer 2: Use valid octal digits in your phone numbers. The digit '8'
cannot appear in base 8 numbers, only the digits 0-7.
Traceback (innermost last):
(no code object) at line 0
File "<console>", line 1
int(088)
^
SyntaxError: invalid syntax
 
L

Leif K-Brooks

paul said:
is there any way to convince python not to take my (phone)numbers
starting with zero as octals?

File "<stdin>", line 1
int(088)
^
SyntaxError: invalid token

Why do they have to start with zeros in your source code?

The fact that you're passing the number through int() makes me guess
that you're actually talking about input of some kind which you'll pass
through int(). If that's the case, they will be strings, and the problem
will go away:
88
 
P

paul k

Alan said:
Answer 1: Use strings: that's really what telephone numbers should be
Yea, should have done this in the first place...
Answer 2: Use valid octal digits in your phone numbers. The digit '8'
cannot appear in base 8 numbers, only the digits 0-7.
I can't change reality (yet) ;)

thanks for all your comments
Paul
 
A

Andrea Griffini

Why do they have to start with zeros in your source code?

My guess is that his program was simply using "input()"

Im rather new to python and I've to say that I found quite
surprising that the "input" function does also evaluate
(so entering "1+1" i get the number 2 and not the string
"1+1") and that I've to use "raw_input" to get what the
user typed in.

Andrea
 

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

Members online

Forum statistics

Threads
474,204
Messages
2,571,063
Members
47,670
Latest member
micheljon

Latest Threads

Top