TypeError:调用元类库模块时出错

时间:2016-03-17 13:59:33

标签: python inheritance import module

我收到以下错误:

Traceback (most recent call last):
  File "/Users/user/repos/prodigy/Sweeper/envsweeper/lib/python2.7/site-packages/nose/loader.py", line 414, in loadTestsFromName
    addr.filename, addr.module)
  File "/Users/user/repos/dr/Sweeper/envsweeper/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/Users/user/repos/prodigy/Sweeper/envsweeper/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/Users/user/repos/dr/Sweeper/test.py", line 5, in <module>
    from SomethingSubclass import SomethingSubclass
      File "/Users/user/repos/dr/Something/SomethingSubclass.py", line 18, in <module>
    class SomethingSubclass(SomethingBaseclass):

TypeError: Error when calling the metaclass bases
    module.__init__() takes at most 2 arguments (3 given)

这是Base类中的代码:

import os
import sys
import inspect
from settings import picklePass, masterMap
from decimal import Decimal
CURRENTDIR = os.path.dirname(
    os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(CURRENTDIR)
sys.path.insert(0, parentdir)
from libs.pickler.pickler import Pickler
import logging


class BaseClass(object):

    def __init__(self, address, fee, msg_body):
        self.address = address
        self.fee = (fee)
        self.msg_body = msg_body

这是SubClass中引发错误的代码,文件名:SubClass.py

import os
import sys
import inspect
import Sweeper
CURRENTDIR = os.path.dirname(
    os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(CURRENTDIR)
sys.path.insert(0, parentdir)
from libs.deterministic import electrum_privkey
from libs.transaction import sign, mksend
import logging
sys.path.insert(0, CURRENTDIR)


class SubClass(BaseClass):
    def __init__(self, address, fee, msg_body):
        BaseClass.__init__(self, address, fee, msg_body)

这就是实例化子类的方式:

....           
module = __import__('SubClass')
class_ = getattr(module, 'SubClass')

任何可能出错的线索?

1 个答案:

答案 0 :(得分:1)

from module'name import class'name

不要使用

import class'name 

如果您的模块和类具有相同的名称。 它会混淆不同的名字。