[Tutor] more problems, my final questions

Kyle Babich Kyle Babich" <kb@kb5.org
Wed, 10 Jul 2002 16:39:29 +0000


Yes, I've read that tutorial before.  It was nice, but the one that
taught me the most by far was:
http://blacksun.box.sk/tutorials/python.htm

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?

I tried in IDLE and I can do similar things like:

>>> slptm = 10
>>> import time
>>> time.sleep( slptm * 1 )

So what went wrong and how would I fix this?

Thank you again,
Kyle

On Wed, 10 Jul 2002 10:37:59 -0400, "Lloyd Kvam"
<pythontutor@venix.com> said:
> I assume cont() is your old hour2 function.
> 
> In custom use cont( sleeptime).  This passes the sleeptime variable to
> cont.  You need to change the definition of cont to something like:
> 
> def cont( sleeptime):
> 
> Now I used the same name sleeptime within both custom and cont.  This
> isn't
> necessary, but can avoid confusion.  Also note that sleeptime is
> originally
> set to be a StringType variable as returned by raw_input.  You will
> need to
> convert this to a number before doing any arithmatic with it.
>      sleeptime = int(sleeptime)
> will do the trick so long as sleeptime is truly an integer.
> 
> You would probably be well served spending some time going through Alan
> Gauld's
> web site:
> http://www.freenetpages.co.uk/hp/alan.gauld/
> Learning to program
> 
> Kyle Babich wrote:
> 
> > It works! :)
> > 
> > The only bug I have left is when trying to execute cont() I need the
> > sleeptime variable from custom().  How do I import it?
> > 
> > On Tue, 9 Jul 2002 22:35:49 -0400, "Timothy M. Brauch"
> > <tbrauch@mindless.com> said:
> > 
> >>----- Original Message -----
> >>From: "Kyle Babich" <kb@kb5.org>
> >>To: "tutor" <tutor@python.org>
> >>Sent: Tuesday, July 09, 2002 10:08 PM
> >>Subject: [Tutor] more problems, my final questions
> >>
> >>
> >>
> >>>New problems has arisin.  I was wondering if there was way to replace:
> >>>if begin in "Yy":
> >>>        print "why is the sky blue?"
> >>>
> >>>With something like:
> >>>if begin == "Y" "y":
> >>>        print "why isn't the sky green or purple?"
> >>>
> >>You should be able to use either:
> >>if begin in ['Y', 'y']:
> >>        do something
> >>        ...
> >>or
> >>if begin == 'Y' or begin == 'y':
> >>        do something
> >>        ...
> >>
> >>I am not sure which one is preferred...
> >>
> >>>(only unlike the code above I need something that works of course)
> >>>
> >>>I'm asking because I recently added:
> >>>else begin in "CustomcustomCUSTOM":
> >>>
> >>In this case, I think it would be better to use the list:
> >>if begin in ['Custom', 'custom', 'CUSTOM']:
> >>        ...
> >>
> >>
> >>>But I had also changed the Yy and Nn to be YyYesyesYES and NnNonoNO,
> >>>however the o in No and the o and custom are conflicting and I'm trying
> >>>to find a way to fix this.  Any ideas?
> >>>
> >>Although, a solution I just thought of that might make things even
> >>easier...
> >>import string
> >>...
> >>begin = string.lower(begin)
> >>if begin in ['y', 'yes']:
> >>        ...
> >>
> >>The third line converts begin to all lowercase (you could just as
> >>arbitrarily use string.upper()) thus making the possible choices fewer.
> >>
> >>Although, all of this is fly-by-the-seat-of-my-pants-untested code.  It
> >>looks correct as I type it into my email...
> >>
> >>
> >>>Also, my final questions regaurding this program:
> >>>Could some one point me to an example or show me how to
> >>>countdown/countup time.sleep?
> >>>And the same goes for delaying/suspending and prematurly ending
> >>>time.sleep.
> >>>
> >>Someone else will have to handle this.  I will admit I only listen to
> >>this
> >>list with one ear, that is, only when I have free time, which seems to
> >>be
> >>almost never.
> >>
> >>
> >>>If anyone sees any problems-waiting-to-happen in my program (attached)
> >>>please tell me.
> >>>
> >>Again, someone else...
> >>
> >>
> >>>Thank you, this list has been so helpful.
> >>>--
> >>>Kyle
> >>>
> >> - Tim
> >>
> >>
> >>
> >>
> >>
> >>
> > 
> > --
> > Kyle
> > 
> > 
> > _______________________________________________
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> > 
> > 
> 
> 
> -- 
> Lloyd Kvam
> Venix Corp.
> 1 Court Street, Suite 378
> Lebanon, NH 03766-1358
> 
> voice: 
> 603-443-6155
> fax: 
> 801-459-9582
> 
> 
> 
> 
> 

--
Kyle