A collection of utility functions that I found myself writing over and over again across different projects. Instead of duplicating code, I've extracted these into a reusable module.
This repository contains commonly-used helper functions for:
- Interactive user prompts with yes/no questions
- Human-readable list joining
Add this repository as a Git submodule in your project:
git submodule add https://github.com/trldp/trldp-utils.git trldp_utilsNo pypi package is available yet.
Once added as a submodule, you can import the utilities directly:
import trldp_utilsAsk the user a yes/no question and get a boolean response:
import trldp_utils
if trldp_utils.ask_yes_no("Do you want to continue?"):
print("User said yes!")
else:
print("User said no!")Join a list of strings into a natural, human-readable format:
import trldp_utils
print(trldp_utils.hjoin(['apple', 'banana'])) #Output: 'apple and banana'
print(trldp_utils.hjoin(['apple', 'banana', 'cherry'])) #Output: 'apple, banana and cherry'
print(trldp_utils.hjoin(['a', 'b', 'c', 'd'], max_items=2)) #Output: 'a, b and 2 others'See docs/api.md for the full API documentation.
This small project is open-source and welcomes all contributions. Please use GitHub pull requests to propose any changes and the GitHub issues page to report any issue.
All code in this repository is licensed under GPL-3+, see here for more information.