Avoid base 8 automatic conversion

时间:2015-05-24 21:36:10

标签: python

I have a parameter which start with 0, something like 0100. All I want is to "stringify" it and have

mystring = '0100'

with the leading 0 in the string, but Python is interpreting it automatically to base 8 and I get:

mystring = '64'

How can I avoid this and get exactly

mystring = '0100' 

2 个答案:

答案 0 :(得分:0)

Myint = class int(mystr, base)

正常使用10。

答案 1 :(得分:-1)

Please initialize your variable as a string '0100' if you require a preceding zero, not an octal number.