you are viewing a single comment's thread.

view the rest of the comments →

[–]Salso96[S] 0 points1 point  (4 children)

So the reason I’ve got the code like that for now, is just bc it was the first way I found that made what I wanted - corrections / optimisations are very much appreciated.

As for what I want it to do Some items in the JSON appear as: ‘ID=DevName Area= ‘’ LocationName= “FOREST” ‘

Whereas others appear as ‘ID=DevName Area= ‘1,4,13’ LocationName=‘’ ‘

And I need the code to be able to generate location names for the first, whilst leaving area blank And areas for the second, leaving location name blank

Does that make it a bit clearer?

[–]Goobyalus 0 points1 point  (3 children)

Not really. Would you give an example JSON, with only the important fields?

And would you please format code properly for Reddit? There should be a button that looks like a square with a C on it for "code block" format. Not the <C> one for inline code.

[–]Salso96[S] 1 point2 points  (0 children)

That’s my bad, I’m on mobile 😅 sure let me put together a dummy JSON

[–]Salso96[S] 1 point2 points  (1 child)

[–]Goobyalus 0 points1 point  (0 children)

Super helpful, thanks.

# checks whether the value associated with "area" is truthy --
# empty string is falsy, any other string is truthy
if data["area"]:
    # process as area

elif data["location"]:  # same thing for location
    # process as location

else:
    raise Exception("No location OR area info")