开发者

How to remove curly quotes?

开发者 https://www.devze.com 2023-01-10 09:39 出处:网络
I开发者_高级运维n my utf-8 encoded file, there are curly quotes (“”). How do I replace them all with normal quotes (\")?

I开发者_高级运维n my utf-8 encoded file, there are curly quotes (“”).

How do I replace them all with normal quotes (")?

cell_info.replace('“','"')
cell_info.replace('”','"')

did not work. No error message.

Thank you. :)


str.replace() doesn't replace the original string, it just returns a new one.

Do:

cell_info = cell_info.replace('“','"').replace('”','"')


other way that work with my code is this:

cell_info = cell_info.replace(u'\u201c', '"').replace(u'\u201d', '"')

this because i already have this # -*- coding: utf-8 -*- at the top of my script


cell_info = cell_info.replace('“','"').replace('”','"')

The replace method return a new string with the replacement done. It doesn't act directly on the string.

0

精彩评论

暂无评论...
验证码 换一张
取 消