pythonprintingpprint

How to print without new line using pprint


How to pprint.pformat string as like print. I am using pprint because I need to use indent

test = 'google\\nfirefox'
import pprint
pprint.pformat(test)

output is "'enable\\\\nshow'"

expected result is like

print (test)
google\nfirefox

Solution

  • try:

    test = 'google\\nfirefox'
    import pprint
    string = pprint.pformat(test) # google\\nfirefox
    print (eval(string)) # google\nfirefox
    

    output:

    google\nfirefox
    

    The eval() method parses the expression passed to this method and runs python expression (code) within the program.