[Tutor] more problems, my final questions

Jeff Shannon jeff@ccvcorp.com
Wed, 10 Jul 2002 10:28:03 -0700


Kyle Babich wrote:

> Anyway, I came up with a work around where I write sleeptime to a
> temporary file and extract it later.  I have narrowed my last problem
> down to this:
>
> logret = open( "custom.dat", "r" )
> slptm = logret.read()
> logret.close()
>
> time.sleep( slptm * 60 )
>
> Why can't I do that?

When you read something from a file, you get a string object.  Strings don't
allow arithmetic -- you need to convert the string into an integer first.

time.sleep( int(slptim) * 60 )

In your experimentations in IDLE, you were already using an integer, so you
didn't have this problem.

Btw, when something doesn't work like this, it's usually best if you can copy &
paste the exception (including the entire traceback).  That makes it easier for
us to figure out where it's failing, and why...    :)

Jeff Shannon
Technician/Programmer
Credit International