Re: converting an int to a string

2007-06-08 Thread John Machin
On Jun 9, 1:40 am, Sean Farrow <[EMAIL PROTECTED]> 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.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: converting an int to a string

2007-06-08 Thread Paul McGuire
On Jun 8, 10:40 am, Sean Farrow <[EMAIL PROTECTED]> 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)
> 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?
> sean.

The divmod builtin function is your friend here.

def parseTime(time):
seconds = float(time)
minutes,seconds = divmod(seconds,60)
return "%02d:%06.3f" % (minutes,seconds) # just guessing

divmod divides the first argument by the second, and returns the tuple
(quotient,remainder).

-- Paul

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: converting an int to a string

2007-06-08 Thread Diez B. Roggisch
Sean Farrow schrieb:
> 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)
> 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 do you mean by "don't seem to be working"

Usually, they do:

Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Welcome to rlcompleter2 0.96
for nice experiences hit  multiple times
 >>> str(120)
'120'
 >>>

Any change you overdefined str with something weird?

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


converting an int to a string

2007-06-08 Thread Sean Farrow
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)
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?
sean.
-- 
http://mail.python.org/mailman/listinfo/python-list