import twitter
import unicodedata
import string
def get_tweets(user):
resultado=[]
temp=[]
api=twitter.Api()#
statuses=api.GetUserTimeline(user)
for tweet in statuses:
var = unicodedata.normalize('NFKD', tweet.text).encode('utf-8', 'replace')
print var# Horóscopo when i dont append it
resultado.append(var)
print resultado# Horo\xcc\x81scopo, mie\xcc\x81rcoles i get these when i append them
get_tweets('HoroscopoDeHoy')
2 に答える
0
問題はprintコマンドにあると思います。Printは、リストに対して文字列変換を実行し、標準出力に書き込む前に「面白い」文字をエスケープします。各アイテムを同じ行に表示したい場合は、次のことをお勧めします。
for item in resultado:
print item,
これにより、リストの文字列変換がバイパスされます。
出典: http ://docs.python.org/reference/simple_stmts.html#the-print-statement http://docs.python.org/reference/expressions.html#string-conversions
于 2012-07-06T07:51:02.170 に答える
0
ユニコードをリストに入れたいと思います:
var = unicodedata.normalize('NFKD', tweet.text)
resultado.append( var )
temp.append(var.encode('utf-8', 'ignore'))
于 2012-07-04T19:37:49.450 に答える