This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2015年01月13日 12:18 by luisgf, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg233928 - (view) | Author: Luis G.F (luisgf) | Date: 2015年01月13日 12:18 | |
Python 3.4 interpreter fail to parse a integer that has zero padding, whereas python 2.7 works properly. Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> int(001) 1 >>> Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> int(001) File "<stdin>", line 1 int(001) ^ SyntaxError: invalid token >>> |
|||
| msg233929 - (view) | Author: Geoffrey Spear (geoffreyspear) * | Date: 2015年01月13日 12:22 | |
This is not a bug, it's a deliberate change. Python 2.x doesn't "work correctly"; what you have there is an octal literal, not a 0-padded base-10 integer. Try 008 or 011 and be surprised that python 2 is "broken" and you'll see why this syntax was removed. |
|||
| msg233930 - (view) | Author: Luis G.F (luisgf) | Date: 2015年01月13日 12:45 | |
Thanks for the response, but in my case, 001 is not an octal literal, is a base-10 zero padded comming from the parsing of a ip string like 111.000.222.333 , where numbers are all integers in base-10.
The solution for parsing that seams to cast 000 as string and then using int('000', base=10).
|
|||
| msg233961 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2015年01月13日 19:33 | |
> is a base-10 zero padded comming from the parsing of a ip string
If you're parsing an ip string, how do you end up with a 000 *literal*? The SyntaxError only applies to literals in Python code; it doesn't affect conversion from strings to integers. So you don't need the "base=10" keyword: the following works in both Python 2 and Python 3.
>>> int("000")
0
>>> int("0019")
19
|
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:11 | admin | set | github: 67419 |
| 2015年01月13日 19:33:04 | mark.dickinson | set | nosy:
+ mark.dickinson messages: + msg233961 |
| 2015年01月13日 13:13:37 | r.david.murray | set | status: open -> closed stage: resolved |
| 2015年01月13日 12:45:18 | luisgf | set | resolution: not a bug messages: + msg233930 |
| 2015年01月13日 12:22:18 | geoffreyspear | set | nosy:
+ geoffreyspear messages: + msg233929 |
| 2015年01月13日 12:18:29 | luisgf | create | |