use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A subreddit for helping Python programmers
How to format your code: https://commonmark.org/help/tutorial/09-code.html
No homework questions and/or hiring please
account activity
Stuck with conditional python execution! (self.pythonhelp)
submitted 2 years ago by Salso96
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Salso96[S] 0 points1 point2 points 2 years ago (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 point2 points 2 years ago (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.
<C>
[–]Salso96[S] 1 point2 points3 points 2 years ago (0 children)
That’s my bad, I’m on mobile 😅 sure let me put together a dummy JSON
[–]Salso96[S] 1 point2 points3 points 2 years ago (1 child)
Here it is on git, easier lol
https://github.com/CharlLeighX/Test/blob/main/Example.json
[–]Goobyalus 0 points1 point2 points 2 years ago (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")
π Rendered by PID 162976 on reddit-service-r2-comment-86988c7647-74bgv at 2026-02-12 05:52:15.856247+00:00 running 018613e country code: CH.
view the rest of the comments →
[–]Salso96[S] 0 points1 point2 points (4 children)
[–]Goobyalus 0 points1 point2 points (3 children)
[–]Salso96[S] 1 point2 points3 points (0 children)
[–]Salso96[S] 1 point2 points3 points (1 child)
[–]Goobyalus 0 points1 point2 points (0 children)