mardi 4 avril 2017

How can I convert if else code into json (or other) format?

Consider this (arbitrary example, python syntax) code:

number = 42
name = 'arthur'

if number != 42:
    if name == 'arthur':
        number = 42
else
    if name == 'zaphod':
        number = 0

I want to convert it somehow into some kind of format so it can be kept as a file.
My initial thought is using json, but this is not a concrete requirement.

My thought is that the above code would translate into something like:

{'number':
    {'42':
        ['name': {'zaphod':0}],
     'other': 
         ['name':{'arthur':42}]
    }
}

Basically saying that at the end of process, the if-else rationale could be read from a file and by navigating the json the proper result would be found (if it exists).

I'm looking to see if there is any known way to do this or some documentation on an easy way to go.

Thanks

Aucun commentaire:

Enregistrer un commentaire