This should be a softball question.
I have a custom class called Table with methods including 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
In a separate script I created an array of tables
import table
tables = []
Then I append the tables array.
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'"
Why does Python not recognize the class?
for t in tables: