“int”对象不是Callab

2024-06-28 19:55:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个简单的python脚本来处理一个表。我使用数组来存储单元格值。 代码如下:

table =[]
hlen = input("Please enter the amount of columns \n")
vlen = input("Please enter the amount of rows \n")
curcol = 1
currow = 1
totcell = hlen*vlen
while (totcell >= curcol * currow):
   str = input("Please input "+ str(curcol) +"," + str(currow))
   table.append(str)
   if (curcol >= hlen):
       currow =+ 1

//Process Table

这个程序运行得很好,要求1,1的第一个单元格。一切正常,直到重新加载时代码停止。这里是Python错误输出

^{pr2}$

谢谢你的帮助。在


Tags: ofthe代码脚本inputtableamountenter
3条回答

您使用变量名对内置的str进行跟踪:

str = input("Please input "+ str(curcol) +"," + str(currow))

第二次,使用str(currow)你试图调用str,现在是int

把它命名为除此之外的任何东西!

另外,您使用的是python2,因此最好使用raw_input,而不是{}

您正在使用str作为从输入返回的int的变量名。当您使用str(curcol)和str(currow)时,Python指的是它,而不是Python字符串函数。在

  m = input("Please input "+ str(curcol) +"," + str(currow))
  please use different name of variable not use 'str' because it is python default function for type  casting

  table =[]
  hlen = input("Please enter the amount of columns \n")
  vlen = input("Please enter the amount of rows \n")
  curcol = 1
  currow = 1
  totcell = hlen*vlen
  while (totcell >= curcol * currow):
       m = input("Please input "+ str(curcol) +"," + str(currow))
  table.append(m)
  if (curcol >= hlen):
    currow += 1



   Please enter the amount of columns 
   5
  Please enter the amount of rows 
   1
  Please input 1,11
  Please input 1,11
  Please input 1,1
  >>> ================================ RESTART ================================
  >>> 
  >>>Please enter the amount of columns 
  >>>1
  Please enter the amount of rows 
  1
 Please input 1,12


 see this program and run it .

相关问题 更多 >