The __getitem__()
and keys()
methods will suffice:
>>> class D:
def keys(self):
return ['a', 'b']
def __getitem__(self, key):
return key.upper()
>>> def f(**kwds):
print kwds
>>> f(**D())
{'a': 'A', 'b': 'B'}
More Related Contents:
- Does Python have “private” variables in classes?
- How do I call a parent class’s method from a child class in Python?
- Instance variables vs. class variables in Python
- Python: Bind an Unbound Method?
- Why do we use __init__ in Python classes?
- Explaining the ‘self’ variable to a beginner [duplicate]
- Python decorators in classes
- Why does a class’ body get executed at definition time?
- How do I exchange keys with values in a dictionary? [duplicate]
- Getting an instance name inside class __init__() [duplicate]
- What is the difference between __init__ and __call__?
- How do I detect if the mouse is hovering over a button? PyGame button class is not displaying the text or changing colour on hover
- correct way to define class variables in Python [duplicate]
- What are data classes and how are they different from common classes?
- How do I implement __getattribute__ without an infinite recursion error?
- What is the purpose of the `self` parameter for methods?
- How to properly overload the __add__ method?
- What is the purpose of python’s inner classes?
- putting current class as return type annotation [duplicate]
- How to create multiple class objects with a loop in python?
- overriding bool() for custom class [duplicate]
- Python Class __div__ issue
- How do I access instance variables in Python?
- How to force/ensure class attributes are a specific type?
- Class (static) variables and methods
- using import inside class
- NameError: global name is not defined
- Accessing attribute from parent class inside child class
- What is the difference between super() with arguments and without arguments?
- member variable string gets treated as Tuple in Python