Oct-16-2017, 03:43 AM
Well, convert the set into list, before jsonify it. Or use jsonpickle. You can store whatever Python object you want and will be readable.
configuration formats / languages
|
Oct-16-2017, 03:43 AM
Well, convert the set into list, before jsonify it. Or use jsonpickle. You can store whatever Python object you want and will be readable.
Oct-16-2017, 08:14 AM
but how does one code a set in JSON so that after it is loaded it is a set?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
I have never used this module. But I knew about it. I have just tried it.
import jsonpickle members = set(['Dallas - Captain', 'Kane - Executive Officer', 'Ellen Ripley - Warrant Officer', 'Ash - Science Officer', 'Lambert - Navigator', 'Parker - Chief Engineer', 'Brett - Engineering Technician']) doomed = {'name': 'USCSS Nostromo', 'crew number': 7, 'crew members': members} type(doomed['crew members']) Out[4]: set serialized = jsonpickle.encode(doomed) serialized Out[6]: '{"crew members": {"py/set": ["Lambert - Navigator", "Ash - Science Officer", "Ellen Ripley - Warrant Officer", "Kane - Executive Officer", "Parker - Chief Engineer", "Brett - Engineering Technician", "Dallas - Captain"]}, "crew number": 7, "name": "USCSS Nostromo"}' data = jsonpickle.decode(serialized) data Out[8]: {'crew members': {'Ash - Science Officer', 'Brett - Engineering Technician', 'Dallas - Captain', 'Ellen Ripley - Warrant Officer', 'Kane - Executive Officer', 'Lambert - Navigator', 'Parker - Chief Engineer'}, 'crew number': 7, 'name': 'USCSS Nostromo'} type(data['crew members']) Out[9]: setSo, it works. I can see at out[8] that 'crew members' holds a set. Quote:you cannot put comments in JSONive never really needed to comment in JSON, but i guess you could always make a sibling entry in the form of "//": "comment",and then just ignore it in your program
Recommended Tutorials:
Oct-17-2017, 02:08 AM
i comment config files a lot. i often see config file comments, sometimes big multiline ones. i don't know if sibling entries would be very easy to read big ones.
there might be the option to have some code that reads in a bunch of lines, throws away lines where the first non-whitespace is # and processes those lines as JSON.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American. |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Python vs low level languages, (say C++) | astral_travel | 1 | 1,380 |
Apr-07-2024, 01:22 AM Last Post: PyDan |
|
different programming languages/words in text editors | alok | 7 | 5,232 |
Jul-05-2021, 03:46 PM Last Post: alok |
|
Stanza: A Python NLP Library for Many Human Languages, by the Stanford NLP Group | buran | 0 | 2,407 |
Mar-26-2020, 05:36 PM Last Post: buran |
|
Suggestions for a machine learning model for invoice processing multiple languages? | animeshsarraf | 1 | 2,828 |
May-26-2019, 04:43 AM Last Post: heiner55 |
|
Interaction between different programming languages | Krookroo | 3 | 4,849 |
Sep-23-2017, 08:50 PM Last Post: Krookroo |