tuple probleme with openpyxl python

huangapple go评论65阅读模式
英文:

tuple probleme with openpyxl python

问题

我需要使用openpyxl为Excel文件中的表格创建一个循环,使用以下代码:

book_stock = load_workbook(r'\\file.xlsx')
sheet_stock = book_stock.active

for row in range(2, sheet_stock.max_row+1):
    sheet_stock.cell(row=row, column=4).number_format = 'dd/mm/yyyy'

但我遇到了这个错误:

for one_row in range(2, wb_sheet.max_row+1): TypeError: 'tuple' object is not callable

英文:

i need to create a loop for the table from excel file with openpyxl with the bellow code :

book_stock = load_workbook(r'\\file.xlsx')
    sheet_stock = book_stock.active

for row in range(2, sheet_stock.max_row+1):
        sheet_stock.cell(row=row, column=4).number_format = 'dd/mm/yyyy'

but i had this errer

for one_row in range(2, wb_sheet.max_row+1):
TypeError: 'tuple' object is not callable

答案1

得分: 0

错误信息的含义是:

在代码的第2行到wb_sheet.max_row+1行的范围内,出现了一个TypeError(类型错误):'tuple'对象不可调用。

这个错误表明,一个被定义为元组的对象被调用了,而在这种情况下,该对象是"range"。

"range"是一个内置函数,完全可以以你在代码中所使用的方式被调用。

你得到这个错误的事实强烈暗示了你之前已经覆盖了内置的"range",并且在你的代码中将它用作了一个元组。

只需将你在其他地方定义为元组的变量"range"重命名为不是内置名称的东西。

英文:

Digesting the error:

   for one_row in range(2, wb_sheet.max_row+1) TypeError: 'tuple' object is not callable

The error is showing that an object defined as a tuple is being called, in this case the object is "range".

Range is a Built-in Function, which is perfectly capable of being called in the way you have here.

The fact that you are getting this error strongly suggests that you have overwritten the builtin "range" and used it as a tuple previously in your code.

Simply rename the variable "range" which you have defined elsewhere as a tuple to something not reserved for the name of a builtin.

huangapple
  • 本文由 发表于 2023年2月14日 00:26:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438612.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定