Apr-27-2020, 02:43 PM
so how do we this with pprint.pprint()? as it gives more formated with proper indent and dictionary display with proper well readable format all its sub dictionary too.
python display with '\\' when prints with key-value in dictionary
|
Apr-27-2020, 02:43 PM
so how do we this with pprint.pprint()? as it gives more formated with proper indent and dictionary display with proper well readable format all its sub dictionary too.
Use yaml if that extra
\ is annoying as it should not be for any Python developers,maybe showing the raw dictionary for end-users it could be ![]() my_dict = { "name": "\python", "brand": "\Ford", "model": "Mustang", "year": 1964 } >>> import yaml >>> >>> print(yaml.dump(my_dict)) {brand: \Ford, model: Mustang, name: \python, year: 1964} >>> print(yaml.dump(my_dict, width=5)) {brand: \Ford, model: Mustang, name: \python, year: 1964} >>> print(yaml.dump(my_dict, default_flow_style=False)) brand: \Ford model: Mustang name: \python year: 1964
May-30-2020, 05:56 PM
Excellent.!!!!
will definitely use this yaml format, and let me try to explore on this too. Just a curiosity with this possible to print list values in the format of [item1, item2] with comma separated instead of the yaml format of -item1 in each line. Thanks a lot, by the way the above solution is an excellent choice too. Regards, Maiya |
|