相关疑难解决方法(0)

使用__init __()方法理解Python super()

我正在努力了解它的用法super().从它的外观来看,可以创建两个子类,就好了.

我很想知道以下2个孩子班级之间的实际差异.

class Base(object):
    def __init__(self):
        print "Base created"

class ChildA(Base):
    def __init__(self):
        Base.__init__(self)

class ChildB(Base):
    def __init__(self):
        super(ChildB, self).__init__()

ChildA() 
ChildB()
Run Code Online (Sandbox Code Playgroud)

python oop inheritance class super

2366
推荐指数
7
解决办法
158万
查看次数

"mro()"有什么作用?

django.utils.functional.py:

for t in type(res).mro():  # <----- this
    if t in self.__dispatch:
        return self.__dispatch[t][funcname](res, *args, **kw)
Run Code Online (Sandbox Code Playgroud)

我不明白mro().它是做什么的,"mro"是什么意思?

python method-resolution-order

118
推荐指数
3
解决办法
5万
查看次数

单个django ModelForm中的多个模型?

是否有可能ModelForm在django中包含多个模型?我正在尝试创建个人资料编辑表单.所以我需要包含User模型 UserProfile模型中的一些字段.目前我正在使用这样的2个表单

class UserEditForm(ModelForm):

    class Meta:
        model = User
        fields = ("first_name", "last_name")

class UserProfileForm(ModelForm):

    class Meta:
        model = UserProfile
        fields = ("middle_name", "home_phone", "work_phone", "cell_phone")
Run Code Online (Sandbox Code Playgroud)

有没有办法将这些整合到一个表单中,或者我只需要创建一个表单并处理数据库加载并保存自己?

python django django-forms

89
推荐指数
3
解决办法
6万
查看次数

Python多重继承,调用第二个基类方法,如果两个基类都持有相同的方法

class A:
    def amethod(self): print("Base1")


class B():
    def amethod(self): print("Base3")

class Derived(A,B):
    pass

instance = Derived()
instance.amethod() 
#Now i want to call B method amethod().. please let me know the way.**
Run Code Online (Sandbox Code Playgroud)

Python多重继承,调用第二个基类方法,如果两个基类都持有相同的方法

python class

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