Python Forum
python display with '\\' when prints with key-value in dictionary
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python display with '\\' when prints with key-value in dictionary
#11
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.
Reply
#12
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 Undecided
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
Reply
#13
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python prints none in function output chairmanme0wme0w 3 500 Jul-07-2021, 05:18 PM
Last Post: deanhystad
Information Unable to display joystick's value from Python onto display box MelfoyGray 2 779 Nov-11-2020, 02:23 AM
Last Post: MelfoyGray
  Try/Exept prints only ones tester_V 11 1,330 Nov-03-2020, 02:38 AM
Last Post: tester_V
  How To Display this Python Code in Web browser? pradhan 1 1,862 Jul-14-2019, 06:59 PM
Last Post: snippsat
  Escape sequences display in python Uchikago 1 1,094 Jun-27-2019, 03:25 PM
Last Post: Gribouillis
  Convert List of Dictionary to dictionary of dictionary list in python kk230689 2 1,729 Apr-27-2019, 03:13 AM
Last Post: perfringo
  How to display <IPython.core.display.HTML object>? pythopen 2 32,499 Oct-17-2018, 06:22 PM
Last Post: pythopen
  What for a file that prints nothing sylas 1 1,176 Sep-12-2018, 01:18 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020