[Tutor] Deleting specified files using a python program...help with code?]
srilyk at gmail.com
Tue Jul 1 11:21:01 CEST 2008
On Tue, Jul 1, 2008 at 3:47 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:
> But I find the in technique more flexible.
> If you go with the default approach the test becomes:
> if confirmation in 'yY' or not confirmation:
> # go ahead and delete them
That's slightly different, but basically the same (I think) how I
often run input:
if confirmation in ('yes', 'ye', 'y', 'Y', 'YES', 'si', 'ja', 'absolutely'):
Mostly it's my tongue in cheek brand of humor coming out in my
programming... Perhaps I go a little overboard, but I doubt, even if
you had that many options, that you would find much of an increase in
execution time. I'm sure in most cases, 'input [y/n]:' and 'in ('y',
'Y')' would be fine, though.
Testing your example, Alan, you have it defaulted to "delete",
correct? That's where the "not confirmation" part comes in? I just
tried it in a simple function:
def confirm(iput): #I wasn't sure if input was "reserved"
if iput in 'yY' or not iput:
print "Not confirmed"
That's something I didn't expect at first, mainly because I'm not used
to setting up that sort of input (but it makes sense to do it that
More information about the Tutor