python-3.xdictionarypprintenviron

ValueError: dictionary update sequence element #0 has length 1; 2 is required, at the output of pprint in Python


I get the error:

ValueError: dictionary update sequence element #0 has length 1; 2 is required

at the output of this line:

pprint.pprint(dict(os.environ['MOTECOM']), width= 1)

I'm using Python 3.6.2 on docker container.


Solution

  • You get this error when messing around with dict and str. Using literal_eval should help:

    >>> pprint.pprint(literal_eval(os.environ['MOTECOM']), width= 1)
    'MOTECOM value'