2012-03-18 77 views
-2

所以,我剛開始使用它的python twitter api挖掘twitter數據。 ,並且即將繪製鳴叫stucture 但我收到此錯誤unicode格式錯誤

f.write('strict digraph {\n%s\n}' % (';\n'.join(dot),)) 
    UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 108: 
    ordinal not in range(128) 

這是代碼..

def draw_tweet_graph(g): 
OUT = "graph.dot" 
try: 
    nx.drawing.write_dot(g, OUT) 
except ImportError, e: 

    dot = ['"%s" -> "%s" [tweet_id=%s]' % (n1, n2, g[n1][n2]['tweet_id']) \ 
     for n1, n2 in g.edges()] 
    f = open(OUT, 'w') 
    f.write('strict digraph {\n%s\n}' % (';\n'.join(dot),)) 
    f.close() 

回答

0

你想codecs.open()爲您的文件。

+0

你能再詳細一點嗎? – Fraz 2012-03-18 00:09:33

+0

看看你有'open()'的地方嗎? – 2012-03-18 00:11:13

+0

仍然是一樣的錯誤:( – Fraz 2012-03-18 00:13:26