相关疑难解决方法(0)

Python扩展 - 使用super()Python 3与Python 2

本来我想问这个问题,但后来我发现之前已经想过......

谷歌搜索我发现这个扩展configparser的例子.以下适用于Python 3:

$ python3
Python 3.2.3rc2 (default, Mar 21 2012, 06:59:51) 
[GCC 4.6.3] on linux2
>>> from configparser import  SafeConfigParser
>>> class AmritaConfigParser(SafeConfigParser):
...     def __init_(self):
...         super().__init__()
... 
>>> cfg = AmritaConfigParser()
Run Code Online (Sandbox Code Playgroud)

但不是Python 2:

>>> class AmritaConfigParser(SafeConfigParser):
...       def __init__(self):
...           super(SafeConfigParser).init()
... 
>>> cfg = AmritaConfigParser()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __init__
TypeError: must be type, not classob
Run Code Online (Sandbox Code Playgroud)

然后我读了一下Python New Class和Old Class样式(例如 …

python inheritance configparser

90
推荐指数
4
解决办法
13万
查看次数

标签 统计

configparser ×1

inheritance ×1

python ×1