gpt4 book ai didi

python - xlsxwriter 需要一个缩进 block

转载 作者:太空宇宙 更新时间:2023-11-03 17:41:51 25 4
gpt4 key购买 nike

花了一些时间编译后libxlsxwriter作为 osx 的 dylib 但没有成功,我决定使用 Python 模块切换到 NSTask XlsxWriter 。但另一个问题又出现了:缩进!我想通过数组实现迭代,并以编程方式将每个值放入行和列中。然而,我正在努力处理文档中的这个示例:

import xlsxwriter. 

# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook('Expenses01.xlsx')
worksheet = workbook.add_worksheet()

# Some data we want to write to the worksheet.
expenses = (
['Rent', 1000],
['Gas', 100],
['Food', 300],
['Gym', 50],
)

# Start from the first cell. Rows and columns are zero indexed.
row = 0
col = 0

# Iterate over the data and write it out row by row.
for item, cost in (expenses):
worksheet.write(row, col, item) #LINE 21 <---
worksheet.write(row, col + 1, cost)
row += 1
# Write a total using a formula.
worksheet.write(row, 0, 'Total')
worksheet.write(row, 1, '=SUM(B1:B4)')

workbook.close()

输出

File "test.py", line 21
worksheet.write(row, col, item)
^
IndentationError: expected an indented block

最佳答案

XlsxWriter 不希望 block 缩进,但 Python 会缩进。

您需要缩进代码,如原始 example that the code above was taken from 所示。 .

关于python - xlsxwriter 需要一个缩进 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30440180/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com