[Tutor] How to enable pausing my stop_watch.py ? (original) (raw)
Dick Moores rdm at rcblue.com
Sat Jul 10 02:36:13 CEST 2004
- Previous message: [Tutor] How to enable pausing my stop_watch.py ?
- Next message: [Tutor] Config Files and Thankx (Reading Numerical Data)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Alan Gauld wrote at 14:19 7/9/2004:
> > hseconds = (hours and 3600*int(hours)) or 0 # shorter but more > >obscure > > > >Works like this: > >Only evaluate 3600*hours if hours NOT "" > >If result is False(ie hours was "") then evaluate > >second part of OR - ie 0 > > I'm very glad to know about these uses of "and" and "or", but why is your > way better? Is fewer lines better? Is it faster? More Pythonesque? (I'm > not defending my code; I'd just like to know.)
It's not better, just an alternative way of doing it. Indeed as the comment says its more obscure and so could be regarded as worse! However it is also very slightly faster. If you are a C (or Perl or Java/Javascript) you might be familiar with the tertiary ?: operator, if so the and/or pair will present a familiar shortcut and for those programmers the obscurity is not a problem. I prefer it simply because it is shorter and doesn't clutter up my main program with if/elses that are tangential to the main purpose of the program. But tastes differ and I would never claim the and/or option was better. Indeed part of the zen of Python is that explicit is better than implicit...
Yes, I vaguely remember the ?: operator from learning some C years ago.
Thanks very much. I'm glad explicit is better than implicit, ATBE or almost..
Dick Moores
- Previous message: [Tutor] How to enable pausing my stop_watch.py ?
- Next message: [Tutor] Config Files and Thankx (Reading Numerical Data)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]