【问题标题】:'int' Object not Callable'int' 对象不可调用
【发布时间】:2014-03-17 16:20:55
【问题描述】:

我正在制作一个简单的 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。一切都很好,直到重新加载时代码停止。 Heres pythons错误输出

Traceback (most recent call last):
  File "./Evacuation.py", line 13, in <module>
    str = input("Please input "+ str(curcol) +"," + str(currow))
TypeError: 'int' object is not callable

感谢您的帮助。

【问题讨论】:

  • 不要将你的变量命名为str(或input),你的问题就解决了......
  • currow =+ 1currow += 1?
  • 使用pylint。它会解决这样的常见问题。
  • 感谢大家的帮助,你可能已经猜到了,我对 python 比较陌生 :)。

标签: python int callable


【解决方案1】:

你正在用你的变量名隐藏内置的str

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

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

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

另外,您使用的是 Python 2,因此最好使用 raw_input 而不是 input

【讨论】:

    【解决方案2】:
      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 .
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 2015-01-29
        • 1970-01-01
        • 2022-11-28
        • 2015-12-19
        • 2017-09-19
        • 2012-04-03
        相关资源
        最近更新 更多