string.translate() with unicode data in python

后端 未结 5 482
情书的邮戳
情书的邮戳 2020-12-03 05:05

I have 3 API\'s that return json data to 3 dictionary variables. I am taking some of the values from the dictionary to process them. I read the specific values that I want t

5条回答
  •  隐瞒了意图╮
    2020-12-03 05:27

    I noticed that string.translate is deprecated. Since you are removing punctuation, not actually translating characters, you can use the re.sub function.

        >>> import re
    
        >>> s1="this.is a.string, with; (punctuation)."
        >>> s1
        'this.is a.string, with; (punctuation).'
        >>> re.sub("[\.\t\,\:;\(\)\.]", "", s1, 0, 0)
        'thisis astring with punctuation'
        >>>
    

提交回复
热议问题