Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

how to transform the txt(saving my dictionary) to dictionary that can be used in Python?(about 10) #71

Closed
StudyMLCN opened this issue Nov 1, 2018 · 1 comment

Comments

@StudyMLCN
Copy link

my data's format is :
{
“a”:[1, 2, ...... , 1024],
"b":[1, 2, ...... , 1024],
"c":[1, 2, ...... , 1024]
}

I want to save it as a dictionary in Python and use it to do experiment.What should i do??

@SalomonSmeke
Copy link

SalomonSmeke commented May 2, 2019

This is very similar to:

#62

If you're fine with getting one array at a time:

def json_iter_parse_map(_buffer):
    """Iterate a JSON byte buffer in the form of:

    dict(str: list(any)) -> yield: str, list(any)
    """
    key = "__!NO-KEY-YET!__"
    for prefix, event, value in ijson.parse(_buffer):
        if prefix == "" and event == "map_key":
            key = value
            builder = ObjectBuilder()

        elif prefix.startswith(key):
            builder.event(event, value)
            if prefix == key and event == "end_array":
                yield key, builder.value

should work for you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants