派生类参数如何在Python中工作? [英] How does derived class arguments work in Python?
本文介绍了派生类参数如何在Python中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难理解Python中的一件事,我已经使用Python进行了很长时间的编码,但是今天有些事情令我震惊,我一直难以理解
I am having difficulty understanding one thing in Python.I have been coding in Python from a very long time but there's is something that just struck me today which i struggle to understand
所以情况就这样
我有一个混音和一个视图
I have a mixin and a view
class Mixin:
def get_session(self,request,*args,**kwargs):
print(self) #should be the instance passed
print(request) #should be the request object passed but it's also an instance
class View:
def get(self,request,*args,**kwargs):
self.get_session(self,request,*args,*kwargs)
pass
为什么请求参数是类视图的实例,应该是请求.请帮助我阐明这些概念.
Why is the request argument the instance of the Class View, It should be request.Please help me clarify these concepts.
推荐答案
您正在显式传递self
作为get_session
的第一个参数.这意味着它进入了request
参数.
You're passing self
explicitly as the first argument of get_session
. That means it goes into the request
parameter.
self.get_session(self,request,*args,*kwargs)
^ ^ ^^^^^^^^^^
(self) (request) (the rest)
我想你的意思是:
self.get_session(request, *args, **kwargs)
这篇关于派生类参数如何在Python中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文