导入时__init__参数错误

时间:2017-01-26 21:13:08

标签: python python-3.x

我在Windows 7计算机上运行Python 3.5 64位版本。

我有一个Python类,其构造函数需要两个参数,self和另一个类的实例:

class Level3_CoilsSet(Recordset):
    def __init__(self, connection):
        super().__init__(connection)
        self.DefaultTableName = 'coils'
        self._keyFields.append('coils_key')
        self._defaultedFields.append('coils_key')

这是Recordset构造函数的顶部(唯一遗漏的是变量的初始化):

from adodb_pyodbc import Connection
from adodb_pyodbc import Field

class Recordset:
    def __init__(self, connection: Connection = None):
        self.Conn = connection
        self.DefaultTableName = None
        self.WhereClause = None
        self.OrderClause = None

Connection类的构造函数没什么特别的:

class Connection:
    def __init__(self):
        self.pyConnection = None
        self.AutoCommit = True

ConnectionRecordset类位于site-packages中的文件夹中,还有一个空的__init__.py文件。 当我运行它时,我收到以下错误:

C:\Python35\python.exe "C:/Customers/Nucor Crawfordsville/Scripts/64 bit/Testing/cpsa_simulator.py"
Traceback (most recent call last):
  File "C:/Customers/Nucor Crawfordsville/Scripts/64 bit/Testing/cpsa_simulator.py", line 8, in <module>
    from Level3_CoilsSet import Level3_CoilsSet
  File "C:\Customers\Nucor Crawfordsville\Scripts\64 bit\Testing\Level3_CoilsSet.py", line 3, in <module>
    class Level3_CoilsSet(Recordset):
TypeError: module.__init__() takes at most 2 arguments (3 given)

这里发生了什么?为什么在导入期间调用__init__()方法?给出了三个论点? PyCharm中给出的回调列表并没有指向任何有用的东西。我有相同的代码在不同的目录结构中成功运行,adodb_pyodbc文件夹中的三个文件与我的主文件位于同一文件夹中,但现在我将它们移动到site-packages下的文件夹中,它失败了。

0 个答案:

没有答案
相关问题