Python &引用;属性错误:';模块';对象没有属性“;排列

Python &引用;属性错误:';模块';对象没有属性“;排列,python,class-method,Python,Class Method,这应该是一个垒球问题 我有一个名为Table的自定义类,其方法包括getTableName class table(object): def __init__(self, tableName, aliasName = 'none'): """Create assign a name""" self.tableName = tableName if aliasName == 'none': self.aliasName

这应该是一个垒球问题

我有一个名为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
在一个单独的脚本中,我创建了一个表数组

import table
tables = []
然后我附加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'"
def附录表(新表):
#匹配表的检查列表
#如果第一批表只是附加到表中
如果len(表)==0:
tables.append(newTable)
返回
发现=错误
对于表中的可旋转项:
打印“新表格类型”#新表格类型
打印类型(新表格)#
打印“可旋转类型”#可旋转类型
打印类型(可旋转)#
a=newTable.getTableName()#好的
b=oTable.getTableName()#崩溃“AttributeError:'module'对象没有属性“getTableName”

为什么Python不能识别该类?

如果类
是在文件
table.py
中定义的,则需要

from table import table
或者使用
table.table
作为类的名称。此外,按照惯例,用户定义的类名应该以大写字母开头,这样代码看起来就像

class Table(object):


我认为这与模块名称冲突。这个模块/包叫什么?尝试使用其他局部变量。示例:
对于表中的t:
from table import Table
table.Table