我现在使用python2.7.6,并使用XslxWriter模块将一些数据写入excel文件。我有一些unicode数据存储在一个列表中。当我试图根据文档使用说明将数据保存到文件中时,我遇到了一些麻烦。指令发现这里
指令说,当您想要使用与unicode字符串和python 2一起使用的模块时,必须在字符串的第一个输入u!我尝试使用简单的字符串,比如.The,محسن结果很好。
但是,当我尝试这样做时,我的数据在列表中,解释器试图将它识别为具有新名称(如ufoo )的变量。当空间断开时,解释器将u识别为一个未知变量(也试图连接到这个问题),我有点困惑。有没有办法解决这个模棱两可的问题?
谢谢你的帮助。
发布于 2015-12-15 08:54:40
我使用函数解码。
tip = 'Haz clic aquí para acceder al fichero remoto.'
tip = tip.decode('utf-8')在python 2中使用解码的一个例子
import xlsxwriter
# Create a new workbook and add a worksheet
workbook = xlsxwriter.Workbook('hyperlink.xlsx')
worksheet = workbook.add_worksheet('Hyperlinks')
# Format the first column
worksheet.set_column('A:A', 30)
# Add the standard url link format.
url_format = workbook.add_format({
'font_color': 'blue',
'underline': 1
})
# Add a sample alternative link format.
red_format = workbook.add_format({
'font_color': 'red',
'bold': 1,
'underline': 1,
'font_size': 12,
})
# Add an alternate description string to the URL.
string = 'Grabación'
string = string.decode('utf-8')
# Add a "tool tip" to the URL.
tip = 'Haz clic aquí para acceder al fichero remoto.'
tip = tip.decode('utf-8')
# Write some hyperlinks
worksheet.write_url('A15', 'external://ordenador-remoto/Directorio/fichero.wav', red_format, string, tip)
workbook.close() https://stackoverflow.com/questions/22648775
复制相似问题