由于为int发送了无值,因此我在进行节俭调用时遇到问题。
所以在代码中我打算检查声明的类型。我打算写下面的内容(因为我们有太多的对象不想为每个字段编写代码)
def(thrift_obj):
for field in thrift_obj.__dict__:
#Here I want to check the declared type of the field (not the type of value of the field)
# if the type is int and value is None then assign it as zero
我尝试使用type(getattr(thrift_obj, field))
类型函数,它给出了字段内部值的类型。(考虑一个结构带有i32类型的字段i,它带有None类型,如果我检查它的类型回复我NoneType。)
我想检查该字段的声明类型。
答案 0 :(得分:0)
也许?
$data = array(
'name' => 'John Doe',
'address' => array(
'city' => 'Somewhere far beyond'
),
'foo' => array(
'bar' => array(
'baz' => array(
'xyz' => 'hij'
)
)
)
);
$structure = array(
'address' => array(
'city' => array(
'regex' => '[a-Z]'
)
),
'foo' => array(
'bar' => array(
'baz' => array(
'xyz' => array(
'regex' => '[0-9]+'
)
)
)
)
);