我正在编写一个小脚本,可以将我的Facebook联系人的电子邮件地址导入到GMail/Android。我的输入文件包含Unicode字符,例如:Jasmin L\u00f3pez。生成的CSV输出文件如下所示:
任何想法吗?我很新手,每次使用编码时,它都不能按照我希望的工作 =(
非常感谢你的帮助!
正如您所看到的,我在编码方面遇到了问题。我正在创建Google联系人CSV文件,但需要正确显示名称。我使用此函数来编写CSV:André Zzz,,,,,,,,,,,,,,,,,,,,,,,,,,fbcontacts ::: * My Contacts,* Home,zzz@yahoo.com
Andréia Ggg,,,,,,,,,,,,,,,,,,,,,,,,,,fbcontacts ::: * My Contacts,* Home,ggg@hotmail.com
Andrés Bbb,,,,,,,,,,,,,,,,,,,,,,,,,,fbcontacts ::: * My Contacts,* Home,bbb@gmail.com
def writecsv(self):
if self.outfile is not '':
#fh = open(self.outfile, 'wb')
#fh = codecs.open(self.outfile, "wb", "utf-8")
fh = codecs.open(self.outfile, 'wb', encoding="latin-1")
else:
fh = sys.stdout
csvhdlr = csv.writer(fh, quotechar='"', quoting=csv.QUOTE_MINIMAL)
csvhdlr.writerow("Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Group Membership,E-mail 1 - Type,E-mail 1 - Value".split(','))
for contact in self.clist:
#csvhdlr.writerow(dict((vname, vtype, vnotes, vstereotype, vauthor, valias, vgenfile.encode('utf-8')) for vname, vtype, vnotes, vstereotype, vauthor, valias, vgenfile in row.iteritems()))
row = contact.fullname + ',,,,,,,,,,,,,,,,,,,,,,,,,,fbcontacts ::: * My Contacts,* Home,' + contact.email
csvhdlr.writerow(row.split(','))
任何想法吗?我很新手,每次使用编码时,它都不能按照我希望的工作 =(
非常感谢你的帮助!