Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试验证一个包含字符串化整数作为键的字典。这些整数是任意数字 ID,不受我的控制。
我如何在模式中声明它?
也许有一种方法可以声明一个我可以用作包罗万象的默认模式?
谢谢。
http://marshmallow.readthedocs.org/en/latest/index.html
我喜欢的方式是使用地图而不是if statement:
if statement
for key, value in dictionary.items(): dictionary[ { "True": str(key), "False": <build a random key> }.get(str(isinstance(key, int))) ] = value
注意:仅适用于 Python3+