Python Forum
configuration formats / languages
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
configuration formats / languages
#21
Well, convert the set into list, before jsonify it. Or use jsonpickle. You can store whatever Python object you want and will be readable.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#22
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.
Reply
#23
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]: set
So, it works. I can see at out[8] that 'crew members' holds a set.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#24
Quote:you cannot put comments in JSON
ive 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:
Reply
#25
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  different programming languages/words in text editors alok 7 3,433 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 1,737 Mar-26-2020, 05:36 PM
Last Post: buran
  Suggestions for a machine learning model for invoice processing multiple languages? animeshsarraf 1 2,091 May-26-2019, 04:43 AM
Last Post: heiner55
  Interaction between different programming languages Krookroo 3 3,863 Sep-23-2017, 08:50 PM
Last Post: Krookroo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020