这应该是一个垒球问题。在
我有一个名为Table的自定义类,其方法包括getTableName
class table(object):
def __init__(self, tableName, aliasName = 'none'):
"""Create assign a name"""
self.tableName = tableName
if aliasName == 'none':
self.aliasName = tableName
else:
self.aliasName = aliasName
self.columns = []
self.relatedTables = []
def getTableName (self):
return self.tableName
在一个单独的脚本中,我创建了一个表数组
^{pr2}$然后追加tables数组。在
def appendTables(newTable):
#check list of tables for match
#if first batch of tables just append to tables
if len(tables) == 0:
tables.append(newTable)
return
found = False
for oTable in tables:
print "type newTable" #type newTable
print type(newTable) #<class 'table.table'>
print "type oTable" #type oTable
print type (oTable) #<type 'module'>
a = newTable.getTableName() #OK
b = oTable.getTableName() #CRASH "AttributeError: 'module' object has no attribute 'getTableName'"
为什么Python不能识别这个类?在
如果类
table
在文件table.py
中定义,则需要或者使用
^{pr2}$table.table
作为类名。另外,根据惯例,用户定义的类名应该以大写字母开头,这样您的代码看起来像以及
以及
相关问题 更多 >
编程相关推荐