python - APT command line interface-like yes/no input? -


The APT ( advanced package device ) command line interface is any short path to achieving Python In?

I mean, when the package manager indicates a yes / no question after which [yes / no] , accepts the script YES / Y / yes / Y or enter (as indicated by the original letter as yes ).

Only the official documents come in I input and raw_input ...

I know it is not difficult to simulate But, writing again is painful: |

As you have said, the easiest way is to use raw_input () To do. There is no underlying way to do this. From:

  import sys def query_yes_no (question, default = "yes"): "" "via raw_input () ask a question / yes and answer back." The question "is a string that is presented to the user. If the user" hit "(default) by default," no "or none (which means the answer is needed for the user)" yes "return value" yes "True", "yes": true, "yes": true, "no": wrong, "n" is true for "right" or "no" : False} if not the default: prompt = "[y / n]" elif default == "yes": Prompt = "[y / n]" elif default == "no": Prompt = " [Y / N] "else: Increase ValueError (" Invalid default response: '% s' "% default) while correct: sys.stdout.write (question + sign) likes = raw_input (). Choose the default [default] option in the default () if the default is none and the preferred == '': valid: Answer with "yes" or "no" "(or 'y' or 'n'). \ N" )  
P> Usage example:

  & gt; & Gt; & Gt; Query_yes_no ("Cabbage is boring with cauliflower?") Cabbage is boiled in comparison to cabbage? [Y / N] Oh please respond with 'yes' or 'no' (or 'y' or 'n'). Cabbage is boiled in comparison to cauliflower? [Y / N] [Enter]> & Gt; & Gt; True & gt; & Gt; & Gt; Query_yes_no ("Cabbage is boring from cauliflower?", No one) Cabbage is boiled with cauliflower? [Or / n] [Enter] Please reply with 'yes' or 'no' (or 'y' or 'n'). Cabbage is boiled in comparison to cauliflower? [Y / n] y & gt; & Gt; & Gt; True  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -