Reputation: 11
Hello: I have a text file where the double- and single-quote characters cannot be matched and replaced (Python 3.5.2). Below is a sample word copied and pasted.
>>> line_copied_pasted = 'gilingan.”'
>>> line_copied_pasted.replace('"','')
'gilingan.”'
When the string is manually entered, matching succeeds:
>>> line_manually_entered = 'gilingan."'
>>> line_manually_entered
'gilingan."'
>>> line_manually_entered.replace('"','')
'gilingan.'
The file is UTF-16 encoded, I think. Any help to fix the problem? Thanks.
Upvotes: 0
Views: 32
Reputation: 5070
In copied text ”
(right double quotation mark) and "
(quotation mark) are different characters. You could check their codes here.
Upvotes: 1
Reputation: 6781
You seem to have it figured out. Since it both ”
and "
are different, it does not make sense to try replacing first while comparing with the latter.
Just do :
line_copied_pasted.replace('”','')
Upvotes: 1