3

我是 Python 新手,正在尝试我的第一个应用程序。为什么我会收到属性消息:

回溯(最近一次调用最后):文件“C:\Users\myname\documents\visual studio 2010\Projects\PythonApplication 1\PythonApplication1\RunSikuliOnVM.py”,第 97 行,在 logging.config.dictConfig(LOG_DICT_CONFIG_OnVM) AttributeError: ' module' 对象没有属性 'config' 按任意键继续。. .

到目前为止,这是我的代码的一部分:

import os
import sys
import subprocess
import fnmatch
import datetime
import logging
import logging.handlers
import logging.config

"""===Global Variables==="""

LOGFILE = r"V:/RunTests.log"
LOGDETAILS= r"V:/SikuliScriptDetails.log"
FAILEDTESTS = r"V:/FailedTests.txt"

"""Logging configuration"""
#   Dictionary configuration for logging within RunSikuliOnVM.py
LOG_DICT_CONFIG_OnVM = {
    'version': 1,              
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
        'format': '%(levelname)-8s %(asctime)s %(module)s %(process)d %(thread)d %(message)s',
        'datefmt': '%a, %d %b %Y %H:%M:%S'

    },
    'standard': {
        'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
        'datefmt': '%a, %d %b %Y %H:%M:%S'

    },
    'simple': {
        'format': '%(asctime)s %(levelname)-8s %(message)s',
        'datefmt': '%a, %d %b %Y %H:%M:%S'
    }
},
'handlers': {
    'console': {
        'level':'DEBUG',    
        'class':'logging.StreamHandler',
        'formatter': 'simple'
    },
    'RunTests_Handler': {
        'class': 'logging.handlers.TimedRotatingFileHandler',
        'level': 'DEBUG',
        'formatter': 'simple',
        'filename': LOGFILE,
        'when':'D',
        'interval': 7, 
        'backupCount':1, 
        'encoding': None, 
        'delay': False, 
        'utc': False,
    },
    'SikuliScriptDetails_Handler': {
        'class': 'logging.handlers.TimedRotatingFileHandler',
        'level': 'DEBUG',
        'formatter': 'verbose',
        'filename':LOGDETAILS,
        'when':'D',
        'interval': 7, 
        'backupCount':2, 
        'encoding': None, 
        'delay': False, 
        'utc': False,
    },
    'FailedTests_Handler': {
        'class': 'logging.handlers.TimedRotatingFileHandler',
        'level': 'DEBUG',
        'formatter': 'standard',
        'filename':FAILEDTESTS,
        'when':'D',
        'interval': 7, 
        'backupCount':2, 
        'encoding': None, 
        'delay': False, 
        'utc': False,
    }
},
'loggers': {
    'RunTests_Logger': {                  
        'handlers': ['RunTests_Handler'],        
        'level': 'DEBUG',  
        'propagate': False  
    },
    'SikuliScriptDetails_Logger': { 
        'handlers': ['SikuliScriptDetails_Handler'],
        'level': 'DEBUG',  
        'propagate': False 
    },
    'FailedTests_Logger': {
        'handlers': ['FailedTests_Handler'],
        'level': 'DEBUG',
        'propagate': False
    }
}
}

logging.config.dictConfig(LOG_DICT_CONFIG_OnVM)

logfilelogger = logging.getLogger('RunTests_Logger')
logdetailslogger = logging.getLogger('SikuliScriptDetails_Logger')
failedtestslogger = logging.getLogger('FailedTests_Logger')

PS:有些缩进是关闭的...

4

1 回答 1

2

我也是新手。我有同样的问题。我删除了目录中的 crud(build 和 dist 文件夹等),然后全部重建。答对了!我怀疑,正如 Alain 所建议的那样,PyCharm 缓存了一些不受欢迎的东西。

于 2013-12-14T13:22:47.777 回答