Advanced Prompts
Reason this release was yanked:
Library now has slightly different usage and entirely different syntax.
Project description
aprompt
aprompt (short for advanced prompt) is a library to create input prompts in the console easily. Most use cases are for forms and setups.
Installation
pip install aprompt
Quickstart
import aprompt as ap
@ap.prompt()
def prompt(age: int):
"""
How old are you?
"""
if age < 18:
return ap.Err("You are too young!")
else:
print("Thanks for joining our community!")
age = prompt()
This is a basic example on how to request the user's age. The function takes one positional argument, which - in this case - requires type annotation. By default, everything is interpreted as a string. Here however we need an integer.
Example
import json
from pathlib import Path
import aprompt
manifest = {}
@aprompt.prompt()
def prompt(_):
"""
Enter your name
"""
manifest["author"] = prompt()
@aprompt.option("1.0", "1.1", "1.2", default = 1)
def prompt(_):
"""
What version do you want to use?
"""
manifest["version"] = prompt()
@aprompt.yesno()
def prompt(use_icon: bool):
"""
Do you want to include an icon?
"""
if use_icon:
@aprompt.prompt()
def prompt(path: Path):
"""
Enter the path to the file
"""
if not path.is_file():
return aprompt.Err(f"{path} is not a file")
manifest["icon"] = prompt()
else:
manifest["icon"] = None
prompt()
@aprompt.confirm()
def prompt(_):
"""
Your manifest will be generated. Hit Enter
to continue or quit with Ctrl + C or Ctrl + Z.
"""
with open("manifest.json", "w") as f:
json.dump(manifest, f)
print("File has been generated")
prompt()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aprompt-0.1.1.tar.gz
(4.0 kB
view hashes)