[Tutor] How convert an int to a string
Dave Angel
davea at davea.name
Sun Jun 23 00:57:59 CEST 2013
On 06/22/2013 05:01 PM, Jim Byrnes wrote:
> I need to convert a series of digits like 060713 to a string so I can
> make it look like a date 06-07-13.
>
Where is this series of digits coming from? Is it in the source code,
or in a file, or coming from the user, or what? If it's in source code,
add quotes around it, and it'll be a string. The whole octal nonsense
is a non-starter, because it won't handle a date like September 18.
Octal numbers only have digits zero through seven.
If the digits are coming from a file, then they're already a string.
Don't waste the time converting to decimal and/or octal, just use them.
If they come from somewhere else, then tell us. And while you're at it,
tell us the Python version so we have a chance at matching the advice to
what you're running.
> >>> a = 060713
That assignment will try to make it octal. If there are digits bigger
than 7, it'll fail.
--
DaveA
More information about the Tutor
mailing list