Bottom Page

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
Quote
#22
but how does one code a set in JSON so that after it is loaded it is a set?
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote
#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
Quote
#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
Quote
#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.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Stanza: A Python NLP Library for Many Human Languages, by the Stanford NLP Group buran 0 77 Mar-26-2020, 05:36 PM
Last Post: buran
  Suggestions for a machine learning model for invoice processing multiple languages? animeshsarraf 1 389 May-26-2019, 04:43 AM
Last Post: heiner55
  Interaction between different programming languages Krookroo 3 1,444 Sep-23-2017, 08:50 PM
Last Post: Krookroo

Forum Jump:


Users browsing this thread: 1 Guest(s)