My Python library triggon
has just surpassed 500 installs on PyPI!
↓ Here’s an article that covers the basic usage:
Switch Values and Logic—No Ifs, Just a Python Library
In this post, I’d like to share one of the 3 5 new features planned for the next update.
triggon
allows you to switch values or behavior automatically when a trigger point is activated based on labels.
With the upcoming update, you'll be able to pass conditional expressions to control when those triggers are activated, giving you more control and flexibility.
Example (Planned)
(Excerpt from the README)
tg = Triggon("A", True)
def example(num: int):
# If the condition "num == 0" is True, the trigger will activate
tg.set_trigger("A", cond="num == 0")
flag = tg.alter_literal("A", False)
print(flag)
example(10) # Output: False
example(0) # Output: True
By setting a condition in the keyword argument cond
, the trigger will only activate when the condition evaluates to True
.
Note: Control structures like if x == 5:
are not supported—only simple comparison expressions are allowed."
Internally, it uses ast
along with eval()
, but it’s designed with safety in mind—any non-comparison expressions will raise an error.
↓ You can find the other two features in the README, along with sample code
README
The next update (v0.1.0b3) is scheduled for next week,
but the source code is already available on GitHub—feel free to check it out if you're interested!
🔗 GitHub -> tsuruko/triggon
🔗 X -> @tool_tsuruko12
Top comments (0)