[英]What's the best way convert object to list in python?
So I receive parameter from json string, and convert it to Json object. 所以我从json字符串接收参数,并将其转换为Json对象。
In this object, I have a field named DepartmentIds
. 在此对象中,我有一个名为DepartmentIds
的字段。
This DepartmentIds
may an int
or a list
of int
. 这DepartmentIds
可以在int
或list
的int
。
So I do a type check to see if DepartmentIds
is instance of int
. 因此,我进行类型检查以查看DepartmentIds
是否为int
实例。
if isinstance(DepartmentIds,int) :
DepartmentIds = [DepartmentIds]
Any syntactic sugar exists? 是否存在语法糖?
DepartmentIds = [DepartmentIds] if isinstance(DepartmentIds,int) else DepartmentIds
没有更好的..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.