使用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.
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
最满意答案
这解决了我的问题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.
相关问答
更多-
如何从MSBuild引用`dnu restore`生成的包?(How to reference packages generated by `dnu restore` from MSBuild?)[2023-10-04]
我只是使用通配符glob来包含所有程序集: -
这解决了我的问题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 ...
-
dnu发布 - 输出(dnu publish - output)[2022-12-28]
在您可以预期已发布的应用程序在没有任何依赖项的情况下运行之前,您应该测试是否可以使用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 ...