草庐IT

gtk_init_check

全部标签

python - 为什么 Fraction 使用 __new__ 而不是 __init__?

我正在尝试创建一个新的不可变类型,类似于内置的Fraction但不是派生自它。分数类iscreatedlikethis:#We'reimmutable,souse__new__not__init__def__new__(cls,numerator=0,denominator=None):...self=super(Fraction,cls).__new__(cls)self._numerator=...self._denominator=...returnself但是我看不出这和有什么不同def__init__(self,numerator=0,denominator=None):..

python - python2.7如何安装gtk?

我使用的是Debian6.04和Python2.7我编译了Python2.7,(./configure,make,makeinstall)在控制台中:>python2.7Python2.7.3(default,Jul282012,16:54:06)[GCC4.4.5]onlinux2Type"help","copyright","credits"or"license"formoreinformation.>>>importgtkTraceback(mostrecentcalllast):File"",line1,inImportError:Nomodulenamedgtk如何在Pyth

python - Django get_models 与模型/__init.py__

我在django中使用get_model和get_models时遇到问题我在models下有几个模型/models/blog.pymodels/tags.pymodels/users.pymodels/comments.pymodels/category.py还有一个models/__init.py__frommyapp.models.blogimport*frommyapp.models.tagsimport*frommyapp.models.usersimport*frommyapp.models.commentsimport*frommyapp.models.categoryim

python - 抽象类的错误 "__init__ method from base class is not called"

我有classA(object):def__init__(self):raiseNotImplementedError("A")classB(A):def__init__(self):....和pylint说__init__methodfrombaseclass'A'isnotcalled很明显,我不想做super(B,self).__init__()那我该怎么办?(我尝试了abc并得到了Undefinedvariable'abstractmethod'来自pylint,因此这也不是一个选项)。 最佳答案 忽略pylint。它只是一

python - 在 `super()` 内使用 `__init_subclass__` 找不到父类的类方法

这个问题在这里已经有了答案:Whydoesaclassmethod'ssuperneedasecondargument?(1个回答)3年前关闭。我尝试从__init_subclass__中访问父级的类方法但是这似乎不起作用。假设以下示例代码:classFoo:def__init_subclass__(cls):print('init',cls,cls.__mro__)super(cls).foo()@classmethoddeffoo(cls):print('foo')classBar(Foo):pass产生以下异常:AttributeError:'super'objecthasnoa

python - 编译错误。属性错误 : 'module' object has no attribute 'init'

这是我的小程序,importpygamepygame.init()这是我的编译命令。pythonmyprogram.py编译错误,File"game.py",line1,inimportpygameFile"/home/ubuntu/Documents/pygame.py",line2,inpygame.init()AttributeError:'module'objecthasnoattribute'init'Ihavepygameinstalledinmyubuntu,Itisinstalledin/usr/lib/python2.6/dist-packages/pygame我从I

python - 几个模块的 Pytest init 设置

假设我有下一个测试结构:test/module1/test1.pymodule2/test2.pymodule3/test3.py我如何设置某些方法在所有这些测试之前只调用一次? 最佳答案 您可以使用自动装置:#contentoftest/conftest.pyimportpytest@pytest.fixture(scope="session",autouse=True)defexecute_before_any_test():#yoursetupcodegoeshere,executedaheadoffirsttest参见pyt

python 3.5 类型提示 : can i check if function arguments match type hints?

python3.5是否提供允许测试给定的函数是否参数是否符合函数声明中给出的类型提示?如果我有这个函数:deff(name:List[str]):pass有没有python方法可以检查是否name=['a','b']name=[0,1]name=[]name=None...符合类型提示?我知道“运行时不会发生类型检查”,但我仍然可以检查在python中手动验证这些参数的有效性?或者如果python本身不提供该功能:我会使用什么工具需要用吗? 最佳答案 Python本身不提供此类函数,您可以阅读更多相关信息here:我为此写了一个装饰

python - __init__ 类(不是实例 __init__)

这是我试图解决的一个非常简单的例子:classTest(object):some_dict={Test:True}问题是我无法在Test仍在定义时引用它通常,我会这样做:classTest(object):some_dict={}def__init__(self):ifself.__class__.some_dict=={}:self.__class__.some_dict={Test:True}但我从未创建此类的实例。它实际上只是一个容纳一组相关函数和数据的容器(我有几个这样的类,我传递了对它们的引用,所以Test有必要成为它自己的类)所以我的问题是,我如何在定义Test时引用它,或

python - 如何使用 GTK3 和 PyGObject 绘制 GdkPixbuf

我有一个小型应用程序,它使用DrawingArea使用PyGObject和GTK3绘制简单的map。我使用加载一个Pixbuffromgi.repositoryimportGtk,GdkPixbufpixbuf=GdkPixbuf.Pixbuf.new_from_file_at_size("logo.png",25,25)然后尝试在DrawingArea的绘图事件信号中绘制它defdraw(self,widget,context):window=widget.get_window()ctx=window.cairo_create()ctx.set_source_pixbuf(pixbu