首页 \ 问答 \ 使用super与类方法(Using super with a class method)

使用super与类方法(Using super with a class method)

我想自己学习Python中的super()函数。

我虽然掌握了它,直到我来了这个例子(2.6),发现自己陷入困境。

http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html#super-with-classmethod-example

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "test.py", line 9, in do_something
    do_something = classmethod(do_something)
TypeError: unbound method do_something() must be called with B instance as first argument (got nothing instead)
>>>

当我在这个例子之前阅读这行时,不是我预期的:

如果我们使用类方法,我们没有一个实例调用super。 幸运的是,我们的超级作品甚至有一个类型作为第二个参数。 ---该类型可以直接传递给super,如下所示。

这是Python告诉我的是不可能的,因为do_something()应该被调用一个B的实例。

提前致谢


I'm trying to learn the super() function in Python.

I thought I had a grasp of it until I came over this example (2.6) and found myself stuck.

http://www.cafepy.com/article/python_attributes_and_methods/python_attributes_and_methods.html#super-with-classmethod-example

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "test.py", line 9, in do_something
    do_something = classmethod(do_something)
TypeError: unbound method do_something() must be called with B instance as first argument (got nothing instead)
>>>

It wasn't what I expected when I read this line right before the example:

If we're using a class method, we don't have an instance to call super with. Fortunately for us, super works even with a type as the second argument. --- The type can be passed directly to super as shown below.

Which is exactly what Python tells me is not possible by saying that do_something() should be called with an instance of B.


原文:https://stackoverflow.com/questions/1817183
更新时间:2023-07-29 08:07

最满意答案

这解决了我的问题https://stackoverflow.com/a/33405651/2322026

请求通过Fiddler代理,Fiddler未公开。


This solved my problem https://stackoverflow.com/a/33405651/2322026

Requests were being proxied through Fiddler and Fiddler wasn't open.

相关问答

更多
  • 我只是使用通配符glob来包含所有程序集: 工作就像一个魅力。 I did it by simply using a wildcard glob to include all the assemblies: Worked l ...
  • 这解决了我的问题https://stackoverflow.com/a/33405651/2322026 请求通过Fiddler代理,Fiddler未公开。 This solved my problem https://stackoverflow.com/a/33405651/2322026 Requests were being proxied through Fiddler and Fiddler wasn't open.
  • ASP.Net 5 / Core可以根据环境变量或您希望的其他标准在启动期间使用选择/组合不同的appsettings.json文件。 但是你不能将不同的文件“合并”到物理文件中(没有任何外部任务/工具)。 这是一种“好”还是“坏”的方式 - 完全取决于你的情况。 为了在不同的文件中存储dev / prod的连接字符串(和其他秘密),这绝对是一个不好的想法,因为你将生产秘密存储在源代码中。 相反,使用AddEnvironmentVariables并使用生产一个“内部”生产服务器覆盖dev param值。 A ...
  • 在您可以预期已发布的应用程序在没有任何依赖项的情况下运行之前,您应该测试是否可以使用dnx web在本地启动应用程序。 这样做会告诉你同样的错误,这是由Pawel说的:你在较低版本的项目上使用不同版本的DNX。 您应该使用dnvm选择beta 6 DNX运行时,然后您可以发布beta 6应用程序包。 但更好的解决方案是升级到RC1-update1,因为这是目前唯一受支持的版本,包括之前存在的许多错误修复。 beta 6和beta 7实际上都非常古老,并且有很多你想要避免的问题。 Before you can ...
  • 检查这种情况: 根据上一个答案和Microsoft部署指南,Powershell脚本“prebuild.ps1”: https ://msdn.microsoft.com/en-us/Library/vs/alm/Build/azure/deploy-aspnet5 香草MSBuild构建。 没有开关或特殊设置。 Powershell脚本运行“dnu发布”。 这将创建整个Web应用程序结构的目录。 “Windows文件复制”任务将#4中创建的目录结构部署到测试环境中的所有目标计算机。 Check this ...
  • 您似乎没有在Azure中设置端点。 请看这里: https ://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-classic-portal-use-docker/转到:添加Docker通信端点你需要把你的端口放进去吧。 然后它应该工作。 希望 :) It seems that you haven't setup your Endpoint in Azure. Please have a look here: ...
  • 因此,您似乎在每台机器上运行.net核心SDK的不同版本。 对你正在尝试做的事情有个大警告。 你是否试图在Linux上使用Jetbrains的Project Rider? 这只适用于project.json(截至本文发稿时),所以要谨慎。 现在有两种方法可以做到这一点。 如果你想要最新的Linux并且不关心使用Rider,那么你可以到这里: https : //github.com/dotnet/core/blob/master/release-notes/download-archive.md和下载Lin ...
  • 您是否尝试过Microsoft ASP.NET Web API 2.2客户端库? 只需添加对您的project.json文件的引用,如下所示: "dependencies": { "Microsoft.AspNet.WebApi.Client": "5.2.3" } 在包恢复之后,您可以像下面这样调用您的Web Api: using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://yourapid ...
  • 现在,dnx仅在Ubuntu 14.04上运行。 抱歉... Right now, dnx only runs on Ubuntu 14.04. Sorry...
  • Azure CLI将很快更新,但您可以直接使用kuduscript npm包来使用最新kuduscript 。 安装它使用: npm install -g kuduscript 然后,您可以使用类似的东西生成ASP.NET Core脚本(根据需要替换名称): kuduscript -y --aspNetCore src\AspNetCoreVS\project.json -s AspNetCoreVS.sln 或者,如果您没有解决方案文件,则可以跳过生成稍微不同的脚本的文件。 请注意,在一般情况下,Ku ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。