mirror of
https://github.com/python/cpython.git
synced 2026-01-24 16:18:45 +00:00
#6211: elaborate a bit on ways to call the function.
This commit is contained in:
parent
9be5998760
commit
4c324b9801
1 changed files with 14 additions and 5 deletions
|
|
@ -312,14 +312,23 @@ defined to allow. For example::
|
|||
def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
|
||||
while True:
|
||||
ok = raw_input(prompt)
|
||||
if ok in ('y', 'ye', 'yes'): return True
|
||||
if ok in ('n', 'no', 'nop', 'nope'): return False
|
||||
if ok in ('y', 'ye', 'yes'):
|
||||
return True
|
||||
if ok in ('n', 'no', 'nop', 'nope'):
|
||||
return False
|
||||
retries = retries - 1
|
||||
if retries < 0: raise IOError('refusenik user')
|
||||
if retries < 0:
|
||||
raise IOError('refusenik user')
|
||||
print complaint
|
||||
|
||||
This function can be called either like this: ``ask_ok('Do you really want to
|
||||
quit?')`` or like this: ``ask_ok('OK to overwrite the file?', 2)``.
|
||||
This function can be called in several ways:
|
||||
|
||||
* giving only the mandatory argument:
|
||||
``ask_ok('Do you really want to quit?')``
|
||||
* giving one of the optional arguments:
|
||||
``ask_ok('OK to overwrite the file?', 2)``
|
||||
* or even giving all arguments:
|
||||
``ask_ok('OK to overwrite the file?', 2, 'Come on, only yes or no!')``
|
||||
|
||||
This example also introduces the :keyword:`in` keyword. This tests whether or
|
||||
not a sequence contains a certain value.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue