我已经用Google搜索了这个错误,并且不明白它是什么。我正在尝试用类进行一个简单的游戏,我所拥有的敌人类不允许我调用攻击方法。
这是错误发生的行:
Your health: 100
Attack or Heal attack
Hit for 3 damage.
97
Traceback (most recent call last):
File "E:\Computing\player.py", line 119, in <module>
enemy.attack()
TypeError: 'int' object is not callable
这是方法:
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Module Module1
Sub Main()
Dim reader As New CSVReader()
Dim ds As DataSet = reader.ReadCSVFile("filename", True)
End Sub
End Module
Public Class CSVReader
Public Function ReadCSVFile(ByVal fullPath As String, ByVal headerRow As Boolean) As DataSet
Dim path As String = fullPath.Substring(0, fullPath.LastIndexOf("\") + 1)
Dim filename As String = fullPath.Substring(fullPath.LastIndexOf("\") + 1)
Dim ds As DataSet = New DataSet()
Dim header As String
If headerRow Then
header = "Yes"
Else
header = "No"
End If
Try
If File.Exists(fullPath) Then
Dim ConStr As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}" + ";Extended Properties=""Text;HDR={1};FMT=Delimited\""", path, header)
Dim SQL As String = String.Format("SELECT * FROM {0}", filename)
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(SQL, ConStr)
adapter.Fill(ds, "TextFile")
ds.Tables(0).TableName = "Table1"
End If
For Each col As DataColumn In ds.Tables("Table1").Columns
col.ColumnName = col.ColumnName.Replace(" ", "_")
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Return ds
End Function
End Class
如果您需要有关该代码的更多信息,请询问。我不确定我打算给你什么信息,因为我不明白这个错误。
控制台出错:
CstName = Me![CustName]
答案 0 :(得分:6)
在某些时候,您为int
分配了enemy.attack
值,然后尝试将enemy.attack()
作为函数调用。
查找xyz.attack = {something}
之类的行并仔细检查{something}
是什么。
高级调试技术 - 使enemy.attack
成为只读属性,返回无操作函数,即
class enemy:
@property
def attack(self, player):
def null_fn():
pass
return null_fn
...现在运行代码会抛出AttributeError
指向您尝试为attack
分配值的行; - )