英文:
Using pyodata, how do I list all available properties of a queried Entity?
问题
我想要动态列出使用PyOData包从odata实体中获取所有可用属性的方法。
以下是我想要做的事情:
service = pyodata.Client(SERVICE_URL, session)
positions = service.entity_sets.TRLPositionSet.get_entities().select('Prop1,Prop2').execute()
for p in positions:
# 如何实现下面的get_properties函数?
properties = get_properties(p)
for prop in properties:
print(prop.name, getattr(p, prop.name))
我该如何实现get_properties(p)
函数以使其返回一个列表['Prop1', 'Prop2']
?
英文:
I want to dynamically list all available properties from an odata Entity using PyOData package.
Here is what I'd like to do:
service = pyodata.Client(SERVICE_URL, session)
positions = service.entity_sets.TRLPositionSet.get_entities().select('Prop1,Prop2').execute()
for p in positions:
# how to implement get_properties below?
properties = get_properties(p)
for prop in properties:
print(prop.name, getattr(p, prop.name)
How would I implement the get_properties(p)
function to make it return a list ['Prop1', 'Prop2']
?
答案1
得分: 1
翻译结果如下:
看看这里:
https://github.com/SAP/python-pyodata/issues/53#issuecomment-533261246
for es in client.schema.entity_sets:
print(es.name)
properties = es.entity_type.properties()
for prop in es.entity_type.key_properties:
print(f' K {prop.name}({prop.type.name})')
properties.remove(prop)
for prop in properties:
print(f' + {prop.name}({prop.type.name})')
for prop in es.entity_type.nav_properties:
print(f' + {prop.name}({prop.to_role.entity_type_name})')
在我的情况下,我必须使用`es._entity_type`
请注意,我已经将代码中的 "proprties" 更正为 "properties",并将 "key_proprties" 更正为 "key_properties",以及 "nav_proprties" 更正为 "nav_properties",以匹配正确的Python语法。
英文:
Take a look here:
https://github.com/SAP/python-pyodata/issues/53#issuecomment-533261246
for es in client.schema.entity_sets:
print(es.name)
proprties = es.entity_type.proprties()
for prop in es.entity_type.key_proprties:
print(f' K {prop.name}({prop.typ.name})')
proprties.remove(prop)
for prop in proprties:
print(f' + {prop.name}({prop.typ.name})')
for prop in es.entity_type.nav_proprties:
print(f' + {prop.name}({prop.to_role.entity_type_name})')
In my case I had to use es._entity_type
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论