[Tutor] TimeTracker

Gregor Lingl glingl@aon.at
Tue, 06 Aug 2002 22:51:08 +0200


Kyle Babich schrieb:

>For those of you who remember TimeTracker, I've begun rewriting my
>first and only program for v0.1.0.
>
>I'm getting this error:
>Traceback (most recent call last):
>  File "C:\WINDOWS\Desktop\TimeTracker\TimeTracker_0_1_0.py", line 65,
>  in ?
>    sleep( tosleep )
>  File "C:\WINDOWS\Desktop\TimeTracker\TimeTracker_0_1_0.py", line 22,
>  in sleep
>    int (sleeptime)
>ValueError: int() literal too large:
>111111111111111111111111111111111111111111111111111111111111
>  
>
Remark 1: Functioncalls like int(sleeptime) as well as int(a) compute 
some value, but then
do not assign them ro same variable or use them further in some 
expression. Instead those
values ar thrown away.

This means the don't make sense and have to be replaced by something like

tosleep =  int(tosleep)

Remark 1: The special error in your program occurs because
- apparantly a has the value "1"
- in line 19 int("1") is called, constructs 1 and leaves it somewhwew in 
memory
- in line 20, sleeptime becomes 60'*"1" which
equals "111111111111111111111111111111111111111111111111111111111111"
as the errormessage reports.
now the equally senseless call 
int("111111111111111111111111111111111111111111111111111111111111")
fails because this literal connot be converted to an integer (as it is 
larger than 2**31-1)
 
had you written

a = int(a)
sleeptime = a * 60

the intended conversion sleeptime = int(sleeptime) was not necessary at all,
as sleeptime is already an int

Tip: think about the difference of statements and expressions
And about the fact, that a script is a sequence of statements.
(... and about the use of function-calls as statements for their 
side-effects to
be performed ...  - I think, not so simple, this ...)

Gregor


>The problem seems to be where I am declaring the input an integer and
>then putting the integer into the function, but once again I'm not sure
>how to change this and make it work.
>
>Here is the complete program:
>
>#####################################################
>
>#! C:\Python22\python
>
>import time, sys
>
>def sleep(a):
>    currtime = time.strftime( "%I:%M:%S%p %Z" )
>    print "Current time:  %(currtime)s" % vars()
>
>    begin = raw_input( "Begin tracking?  [Y/N]:  " )
>
>    if begin.lower() in "y yes".split():
>        logcurrtime = open( "log.dat", "aa" )
>        logcurrtime.write( " [Current Time:  %(currtime)s]" % vars() )
>        logcurrtime.close()
>
>        int (a)
>        sleeptime = a * 60
>        int (sleeptime)
>        
>        logsleeptime = open( "log.dat", "aa" )
>        logsleeptime.write( " [Sleep Time:  %(sleeptime)s Mins.]" %
>        vars() )
>        logsleeptime.close()
>        
>        time.sleep( sleeptime )
>        print "Set Time Complete"
>
>        comptime = time.strftime( "%I:%M:%S%p %Z" )
>
>        logcomptime = open( "log.dat", "aa" )
>        logcomptime.write( " [Time Completed:  %(comptime)s]" % vars()
>        )
>        logcomptime.close()
>        
>        print "Completed at %(comptime)s." % vars()
>        print "This window will close in 60 seconds."
>
>        time.sleep(60)
>        sys.exit()
>        
>    if begin.lower in "n no".split():
>        print "FAILED"
>        print "This window will close in 60 seconds."
>        
>        time.sleep( 60 )
>        sys.exit()
>
>name = raw_input( "Please type your name:  " )
>
>logname = open( "log.dat", "aa" )
>logname.write( "[Name:  %(name)s]" % vars() )
>logname.close()
>
>if name.lower() in "kyle jason chelsea john cheryl".split():
>    while 1:
>        print
>        tosleep = raw_input( "Enter time to sleep in minutes:  " )
>        
>        confirm = raw_input( "Confirm %(tosleep)s minutes [Y/N]:  " %
>        vars() )
>        
>        if confirm.lower() in "y yes".split():
>            int( tosleep )
>            sleep( tosleep )
>
>else:
>    print "FAILED"
>    print "This window will close in 60 seconds."
>    
>    time.sleep( 60 )
>    sys.exit()
>
>##########################################################
>
>Thank you,
>--
>Kyle
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>