Process escape sequences in a string in Python

前端 未结 6 1374
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 03:56

Sometimes when I get input from a file or the user, I get a string with escape sequences in it. I would like to process the escape sequences in the same way that Python proc

6条回答
  •  生来不讨喜
    2020-11-22 04:57

    Below code should work for \n is required to be displayed on the string.

    import string
    
    our_str = 'The String is \\n, \\n and \\n!'
    new_str = string.replace(our_str, '/\\n', '/\n', 1)
    print(new_str)
    

提交回复
热议问题