I'm quite new to Python and I'm running into a very basic problem. I've written a function with multiple 2 for loops and 1 if statement. This function when run separately it shows all values that I expects. However when put into a def function it returns only the first value. I know it has something to do with indention and using yield instead of return in the function. However trying to resolve it with both options still gives one result back. Below the sample of the code:
def generate_body(objectFr, properties):
objFrame = objectFr
data = properties
for obj in objFrame.Object_Naam:
properties = data.loc[data['Objects'] == obj, 'attribuut_naam'].dropna()
# minOccur = data.loc[data['Objects'] == obj, 'minOccurs'].dropna()
for prop in properties:
last = properties.iloc[-1]
first = properties.iloc[0]
jsonbody = []
# bodystring = ''.join(jsonbody)
if prop == first:
jsonbody.append('"' + obj + '",' + ' "type": "object,"' + ' "properties": {' + str(prop) + '"' + ': { "type": "string" }' )
elif prop == last:
jsonbody.append('"' + str(prop) + '"' + ': { "type": "string" }' )
else:
jsonbody.append('"' + str(prop) + '"' + ': { "type": "string" },' )
return ''.join(jsonbody)
Can someone please help me out?
Regards, Sef
Aucun commentaire:
Enregistrer un commentaire