2017-02-01 5 views
-1

引用符( `」`)と、通常の引用符( `" `)交換する方法:我々は、私はこの()特殊なタイプを持って気付いた場合は私はこのようなテキストファイル内のいくつかの大規模なコンテンツ持っ

1. name="user1” age="21” 
2. name="user2” age="25” 
.... 

を。

:ここでは、各単語の最後に引用

の私は、通常の引用符("

コードとその引用符()を交換したいです210

import codecs f = codecs.open('myfile.txt',encoding='utf-8') for line in f: print "str text : ",line a = repr(line) print "repr text : ",a x = a.replace(u'\u201d', '"') print "new text : ",x 

出力:

str text : 1. name="user1” age="21” 

repr text : u'1. name="user1\u201d age="21\u201d\n' 
new text : u'1. name="user1\u201d age="21\u201d\n' 

が、その動作していません。私はここで何が欠けているのですか?

アップデート:私はちょうどこれを試してみました

import codecs 
f = codecs.open('one.txt') 
for line in f: 
    print "str text : ",line 
    y= line.replace("\xe2\x80\x9d", '"') 
    print "ynew text : ",y 

、それが今取り組んでいます。

はまだ私がいないがchar が含まれていのreprラインの、あるx = a.replace(u'\u201d', '"')

答えて

2

aで間違っていたかを知りたいが、文字列が含まれている\u201,d

a = repr(line)からa = lineに変更すると問題が解決されます。

+0

ありがとうございます! –

関連する問題