converting an int to a string
John Machin
sjmachin at lexicon.net
Fri Jun 8 17:53:37 EDT 2007
On Jun 9, 1:40 am, Sean Farrow <sean.far... at seanfarrow.co.uk> wrote:
> Hi:
> I have the folling code:
> def parseTime(self, time):
> minutes =int(float(time)/60)
> seconds =int(float(time)-minutes*60)
> minutes =str(minutes)
> seconds =str(minutes)
seconds = str(minutes) ???
Is that the actual code that you executed?
What does "don't seem to be working" mean? The seconds output is
always the same as the minutes output?
Try again, with
seconds = str(seconds)
followed by
print "debugging", repr(time), repr(minutes), repr(seconds)
If it still seems not to be working, come back with a copy/paste of
the actual code that you executed, plus a copy/paste of the output
> the statements that convert the minutes and seconds variables
> str(minutes) and str(seconds) don't seem to be working.
> Any idea why?
> is there any other way of doing this and perhaps using the $d
> interpolation operator?
What is the $d interpolation operator? Do you mean the %d string
formatting operator? If so, the answer depends on what you want to do
with the output ... e.g.
"%d:%02d" % (int_minutes, int_seconds)
might be what you want.
More information about the Python-list
mailing list