处理python中的特殊字符

时间:2017-04-26 11:38:42

标签: python character

我有这个字符串:

self.assertEquals(ex.user_message,
                              '''Equalum agent has returned the following error:\nDirectory "{}" doesnt exist.'''
                              .format(agent_stream['directory']))

我希望将其更改为:

self.assertEquals(ex.user_message,
                                  '''Equalum agent has returned the following error:\nDirectory "{}" doesn't exist.'''
                                  .format(agent_stream['directory']))

我怎么能写而不是在python中没有?

埃雷兹

1 个答案:

答案 0 :(得分:1)

例如,您可以使用\'来转义单引号,例如“doesn \'t”。 http://python-reference.readthedocs.io/en/latest/docs/str/escapes.html