小编Jag*_*kół的帖子

super()失败并出现错误:当父不从对象继承时,TypeError"参数1必须是type,而不是classobj"

我得到一些我无法弄清楚的错误.任何线索我的示例代码有什么问题?

class B:
    def meth(self, arg):
        print arg

class C(B):
    def meth(self, arg):
        super(C, self).meth(arg)

print C().meth(1)
Run Code Online (Sandbox Code Playgroud)

我从"超级"内置方法的帮助下得到了示例测试代码."C"级是

这是错误:

Traceback (most recent call last):
  File "./test.py", line 10, in ?
    print C().meth(1)
  File "./test.py", line 8, in meth
    super(C, self).meth(arg)
TypeError: super() argument 1 must be type, not classobj
Run Code Online (Sandbox Code Playgroud)

仅供参考,这是来自python本身的帮助(超级):

Help on class super in module __builtin__:

class super(object)
 |  super(type) -> unbound super object
 |  super(type, obj) -> bound super object; requires isinstance(obj, type)
 |  super(type, type2) -> bound …
Run Code Online (Sandbox Code Playgroud)

python inheritance object parent super

186
推荐指数
4
解决办法
11万
查看次数

如何在python中获得任何大小的空数组?

我基本上想在C中使用python等效的py:

int a[x];
Run Code Online (Sandbox Code Playgroud)

但是在python中我声明了一个数组:

a = []
Run Code Online (Sandbox Code Playgroud)

问题是我想为随机插槽分配如下值:

a[4] = 1
Run Code Online (Sandbox Code Playgroud)

但我无法用python做到这一点,因为数组是空的.

python arrays dynamic-arrays

102
推荐指数
5
解决办法
40万
查看次数

Compiling Python to a static lib and using pythoncore.lib

I'm trying to build Python 2.7 as a static single .lib file.

I've already made the following changes to the Python source code:

  1. Change to "Release" mode.
  2. Change all DLL projects to Static library (.lib) and set runtime library to /MT
  3. Add preprocessor definition Py_NO_ENABLE_SHARED to python and pythoncore

I've managed to compile the pythoncore project to pythoncore.lib (about 11mb size), but when trying to compile the python project I get the following linking errors:

error LNK2019: unresolved external symbol …

python static compilation static-libraries python-2.7

9
推荐指数
0
解决办法
1115
查看次数

Python工具Visual Studio 2017 RC

有人知道是否可以在Visual Studio 2017 RC中打开旧的(VS2015)Python解决方案和项目?VS 2017无法加载我的项目,只是说它不兼容.我在修改Visual Studio选项中寻找一些Python工具,但在那里找不到任何关于它的东西.

python visual-studio-2017

6
推荐指数
1
解决办法
5215
查看次数

如何在 docker 中增加超时时间?

我的 docker 机器有问题。我需要增加超时时间,但我不知道在哪里。我增加了php.ini文件中的超时,但不起作用。

我需要帮助,谢谢!

PD:我的操作系统是 Ubuntu。

php docker docker-compose docker-machine

2
推荐指数
1
解决办法
5137
查看次数