【发布时间】:2018-07-30 21:33:21
【问题描述】:
我正在尝试编写 Python 脚本来解析 Excel 数据并生成自定义输出。
我被卡住的部分是输出将“.0”添加到电子表格中包含数字的任何字段的末尾。我正在做的字符串连接是将这些数值视为浮点整数。
对于任何数值,我如何确保输出是常规整数而不是浮点整数?
到目前为止,这是我的脚本:
import xlrd
book = xlrd.open_workbook('/Users/doctorwho/test.xls')
sheet = book.sheet_by_index(0)
myList = []
for i in range(sheet.nrows):
myList.append(sheet.row_values(i))
outFile = open('/Users/doctorwho/update.txt', 'wb')
for i in myList:
outFile.write("Test data 1" + str(i[1]) + "Test data 2" + str(i[2])
【问题讨论】:
标签: python parsing floating-point integer string-concatenation