用allowlist或blocklist装饰命令行界面并简化复杂的用户输入。
monoprompt的Python项目详细描述
单挑
用allowlist或blocklist装饰命令行界面并简化复杂的用户输入。在
安装
pip install monoprompt
使用
1。导入
^{pr2}$2。询问用户的输入。
# basic usageask("What is your name? ")# removes extra charactersask("What is your age? ",chars="3")# allows empty inputask("Where do you live? ",once=True)
3。请求输入并与允许值进行比较。
# basic usagerequest("Choose a number? ",("1","2","0"))# allows only to choose between Apple, Banana, and Cherry, and never Durianrequest("Select? ",("Apple","Banana","Cherry"),blocklist=("Durian"))# allows empty inputrequest("Select? ",("Apple","Banana","Cherry",""),blocklist=("Durian"))
4。用任何字符装饰线条。
# fills the whole console line with the specified characterdecorate("#")# limits only to 50 characters in lengthdecorate("#",chars=50)# fills the whole console line with the specified word, up to the max limitdecorate("hello")# fills the whole console line with the specified word, up to a hundred charactersdecorate("hello",100)
^{str 1}5美元。将消息打印到控制台。
# basic usagemessage(string)# centers message in consolemessage(string,centered=True)# centers message in a 50-character lengthmessage(string,chars=50,centered=True)# padds a string to the leading and trailing ends of the messagemessage(string,padding="#",centered=True)# fills the leading and trailing white spaces with the specified charactermessage(string,chars=0,fill="-",centered=True)
6。打印已排序的列表。
# basic usagecatalog(("Apple","Banana","Cherries"))# orselection=("Apple","Banana","Cherries")catalog(selection)
7。获取列表的索引。
# basic usageindices=keys(("Apple","Banana","Cherries"))# extend listindices=keys(("Apple","Banana","Cherries"),extend=["x"])
- 项目
标签: