导入模块时出现Python 2.7语法错误

2024-10-04 09:31:11 发布

您现在位置:Python中文网/ 问答频道 /正文

首先感谢您阅读这个问题

我正在尝试将模块导入新脚本

我正在使用以下命令:

import mosaic.qdfTrajIO as qdf 

这将返回以下语法错误:

runfile('C:/Users/reneb/projects/mosaic/mosaic/utilities/mosaicLogging.py',
wdir='C:/Users/reneb/projects/mosaic/mosaic/utilities')


File "C:/Users/reneb/projects/mosaic/mosaic/utilities/mosaicLogging.py", line 50
class mosaicLogging(object, metaclass=metaSingleton):
                                     ^

SyntaxError:无效语法

这是第42行到第59行的代码:

class MessageFormatter(logging.Formatter):
def format(self, record):
    try:
        record.msg = record.msg.strip()
    except:
        pass
    return super(MessageFormatter, self).format(record)

class mosaicLogging(object, metaclass=metaSingleton): #this is where the error takes place

"""A custom logging class that uses the Python logging facility. Logs are automatically saved to a metaMDIO instance,
    and to a file log when DeveloperMode is active.
"""

_loggers = {}

log=logging.getLogger()
log.setLevel(logging.DEBUG)

Tags: pylogobjectloggingrecordusersclassmetaclass