Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python cubes.errors.ConfigurationError:config应该是ConfigParser实例,但为<;类型';实例'&燃气轮机;_Python_Python 2.7_Python 3.x_Types_Instance - Fatal编程技术网

Python cubes.errors.ConfigurationError:config应该是ConfigParser实例,但为<;类型';实例'&燃气轮机;

Python cubes.errors.ConfigurationError:config应该是ConfigParser实例,但为<;类型';实例'&燃气轮机;,python,python-2.7,python-3.x,types,instance,Python,Python 2.7,Python 3.x,Types,Instance,我正在尝试使用,创建工作区时需要使用ConfigParser实例。我尝试了以下方法: from cubes import Workspace import ConfigParser configg = ConfigParser.ConfigParser() print configg print type(configg) configg.read('slicer.ini') workspace = Workspace(config=configg) 输出结果如下: <ConfigPa

我正在尝试使用,创建工作区时需要使用
ConfigParser
实例。我尝试了以下方法:

from cubes import Workspace
import ConfigParser

configg = ConfigParser.ConfigParser()
print configg
print type(configg)
configg.read('slicer.ini')
workspace = Workspace(config=configg)
输出结果如下:

<ConfigParser.ConfigParser instance at 0x0387F148>
Traceback (most recent call last):
<type 'instance'>
  File "C:/Users/saiki/PycharmProjects/bcubes2/b_cubes.py", line 8, in <module>
    workspace = Workspace(config=configg)
  File "build\bdist.win32\egg\cubes\workspace.py", line 83, in __init__
cubes.errors.ConfigurationError: config should be a ConfigParser instance, but is <type 'instance'>

回溯(最近一次呼叫最后一次):
文件“C:/Users/saiki/PycharmProjects/bcubes2/b_cubes.py”,第8行,在
工作空间=工作空间(配置=配置)
文件“build\bdist.win32\egg\cubes\workspace.py”,第83行,在__
cubes.errors.ConfigurationError:config应该是ConfigParser实例,但不是
如何解决此问题?

更改:

import ConfigParser
致:

并举例说明:

configg = ConfigParser().
cubes
库使用一个兼容模块使其与Python 2和3一起工作。它做了以下工作:

if py3k:
    # ...
    from configparser import ConfigParser
    # ...
else:
    from ConfigParser import SafeConfigParser as ConfigParser
    # ...
因此,如果您使用的是Python2two,则需要一个
SafeConfigParser
实例。 更简单:只需使用
cubes.compat.ConfigParser


更好:切换到Python 3.:)

尝试
workspace=workspace(config='slicer.ini')
。它给出了错误:config应该是一个ConfigParser实例,但没有问题。不是从多维数据集导入配置解析器do
。而是从多维数据集导入配置解析器
和以后的
configg=ConfigParser()
。非常感谢你,迈克:)如果你发布它,我想接受它作为答案
if py3k:
    # ...
    from configparser import ConfigParser
    # ...
else:
    from ConfigParser import SafeConfigParser as ConfigParser
    # ...