[Tutor] now = ctime()[11:20]

Richard D. Moores rdmoores at gmail.com
Sat Jul 17 13:25:50 CEST 2010


On Sat, Jul 17, 2010 at 00:08, Luke Paireepinart <rabidpoobear at gmail.com> wrote:
> If you are asking how to get a variable to call a function each time it's accessed... Well that's kind of a weird request. I know you can create properties in a class that act like variables but you can do whatever you want behind the scenes, like calling the now() function on each access. A much more clear way to do this would be to create a function that calls the now function and just call your function whenever you want the value.

That's essentially Alan's suggestion, right? I've adopted it. See the
current state of the script I'm working on at
<http://tutoree7.pastebin.com/5XYaaNfp>. (I'll be posting a separate
question about it.)

 >Is there a specific reason why you would prefer to solve this
without having to type 2 extra characters ()

Actually, at age 73 I have trouble remembering the [11:20] part.

>and in turn make your code more readable and logical? The problem with the approach you hint at is that then the function call is implicit. What if someone else wanted to use your variable in a tight loop? They don't probably expect or want your variable to automatically update itself.

Point taken, and instead I'm going with Alan's function. But also,
this script is only for my own use, and the calling of ctime()[11:20]
is just so I can see where the script is bogging down. Turns out the
problem is that the writing of the long string of digits gets close to
exhausting my laptop's memory. But that's for another thread.

> Also are you aware of the timeit module for dete

I used to use it to time snippets at the command line. I've never used
it in a script. I'll check it out again. Usually if I time something
within a script I do it by using t0 = time() and t1 = time() and
printing the difference.

> Perhaps I misunderstood your intent.

I don't think so.

Thanks, Luke.

Dick


More information about the Tutor mailing list