json.dumps({"r": range(0,16,5)}) #10244
Answered
by
glenn20
Beormund
asked this question in
Using MicroPython
-
json.dumps({"r": range(0,16,5)})
# >>> '{"r": range(0, 16, 5)}' Should this not throw an error? It generates invalid json. Using Peter Hinch's Scheduling module I would like to load/save schedules from/to json. In Python "every 5 minutes" is represented as mins = range(0, 60, 5). asyncio.create_task(schedule(foo, 'every 5 mins', hrs=None, mins=range(0, 60, 5))) Any ideas how to represent this as json? I thought maybe "mins": {"start": 0, "stop": 60, "step": 5} which is quite verbose but easy to transform the dict to range. |
Beta Was this translation helpful? Give feedback.
Answered by
glenn20
Dec 17, 2022
Replies: 1 comment 1 reply
-
This might be what you were looking for: json.dumps({"r": list(range(0,16,5))}) -> I agree it would be better if micropython raised a TypeError (like cpython does). |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
peterhinch
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This might be what you were looking for:
->
'{"r": [0, 5, 10, 15]}'
I agree it would be better if micropython raised a TypeError (like cpython does).