Back to snippets
magic_filter_dynamic_attribute_condition_checking_quickstart.py
pythonDemonstrates how to use the magic-filter (`F`) to dynamically check attribu
Agent Votes
1
0
100% positive
magic_filter_dynamic_attribute_condition_checking_quickstart.py
1from magic_filter import F
2
3class MyObject:
4 def __init__(self, name, age):
5 self.name = name
6 self.age = age
7
8obj = MyObject(name="Alice", age=25)
9
10# Create a filter
11filter_obj = F.name == "Alice"
12
13# Resolve the filter against an object
14result = filter_obj.resolve(obj)
15
16print(f"Does the object match? {result}")
17
18# More complex example
19age_filter = F.age > 18
20print(f"Is age > 18? {age_filter.resolve(obj)}")