草庐IT

init_printing

全部标签

python - 在 __init__.py 中找不到引用 'xxx'

我在PyCharm中有一个项目,组织如下:--Sources|--__init__.py|--Calculators|--__init__.py|--Filters.py|--Controllers|--__init__.py|--FiltersController.py|--Viewers|--__init__.py|--DataVisualization.py|--Models|--__init__.py|--Data我所有的__init__.py,除了Sources正上方的那个都是空白文件。我收到了很多这样的警告:Cannotfindreference'xxx'in__init_

python - 如何在 __init__ 中使用 await 设置类属性

如何在构造函数或类体中使用await定义类?例如我想要的:importasyncio#somecodeclassFoo(object):asyncdef__init__(self,settings):self.settings=settingsself.pool=awaitcreate_pool(dsn)foo=Foo(settings)#itraises:#TypeError:__init__()shouldreturnNone,not'coroutine'或带有类主体属性的示例:classFoo(object):self.pool=awaitcreate_pool(dsn)#Sur

python - Lisp 的 read-eval-print 循环与 Python 的有何不同?

我遇到了以下statementbyRichardStallman:'WhenyoustartaLispsystem,itentersaread-eval-printloop.Mostotherlanguageshavenothingcomparabletoread,nothingcomparabletoeval,andnothingcomparabletoprint.Whatgapingdeficiencies!'现在,我很少用Lisp进行编程,但我已经用Python编写了大量代码,最近还用Erlang编写了一些代码。我的印象是这些语言也提供read-eval-print循环,但Sta

python - 防止在 __init__ 之外创建新属性

我希望能够创建一个类(在Python中),该类一旦用__init__初始化,不接受新属性,但接受对现有属性的修改。我可以看到有几种hack-ish方法可以做到这一点,例如使用__setattr__方法,例如def__setattr__(self,attribute,value):ifnotattributeinself.__dict__:print"Cannotset%s"%attributeelse:self.__dict__[attribute]=value然后直接在__init__内编辑__dict__,但我想知道是否有“正确”的方法来做到这一点? 最

python - 编写一个 __init__ 函数用于 django 模型

我正在尝试为我的一个模型编写一个__init__函数,以便我可以通过以下方式创建一个对象:p=User('name','email')当我编写模型时,我有:def__init__(self,name,email,house_id,password):models.Model.__init__(self)self.name=nameself.email=email这行得通,我可以将对象保存到数据库中,但是当我执行User.objects.all()时,除非我取出我的__init__,否则它不会拉出任何东西函数。有什么想法吗? 最佳答案

Python 属性错误 : 'module' object has no attribute 'SSL_ST_INIT'

我的一个Python脚本失败了:Traceback(mostrecentcalllast):File"./inspect_sheet.py",line21,inmain()File"./inspect_sheet.py",line12,inmainworkbook_name=workbook_name,File"./google_sheets.py",line56,in__init__self.login()File"./google_sheets.py",line46,inloginself.client=gspread.authorize(credentials)File"/usr

python - 如何从子类调用基类的 __init__ 方法?

这个问题在这里已经有了答案:HowtoinvokethesuperconstructorinPython?(7个回答)关闭6年前。如果我有一个python类:classBaseClass(object):#codeandtheinitfunctionofthebaseclass然后我定义一个子类如:classChildClass(BaseClass):#hereIwanttocalltheinitfunctionofthebaseclass如果基类的init函数接受一些我将它们作为子类的init函数的参数的参数,我如何将这些参数传递给基类?我写的代码是:classCar(object)

python - 如何使用 Sphinx 的 autodoc 来记录类的 __init__(self) 方法?

默认情况下,Sphinx不会为__init__(self)生成文档。我尝试了以下方法:..automodule::mymodule:members:和..autoclass::MyClass:members:在conf.py中,设置以下内容仅将__init__(self)文档字符串附加到类文档字符串(theSphinxautodocdocumentation似乎同意这是预期的行为,但没有提及我要解决的问题):autoclass_content='both' 最佳答案 这里有三种选择:为确保始终记录__init__(),您可以使用au

python - 如何在 Python 中从 __init__ 返回一个值?

我有一个带有__init__函数的类。创建对象时如何从该函数返回整数值?我写了一个程序,其中__init__进行命令行解析,我需要设置一些值。可以将其设置在全局变量中并在其他成员函数中使用吗?如果是这样怎么做?到目前为止,我在类外声明了一个变量。并将其设置为一个功能不会反射(reflect)在其他功能中?? 最佳答案 你为什么要这样做?如果你想在调用类时返回一些其他对象,那么使用__new__()方法:classMyClass(object):def__init__(self):print"nevercalledinthiscase

python - 为什么 Python 2.7 中的 print 括号是自愿的?

在Python2.7中,以下两个都将执行相同的操作print("Hello,World!")#Prints"Hello,World!"print"Hello,World!"#Prints"Hello,World!"但以下不会print("Hello,","World!")#Printsthetuple:("Hello,","World!")print"Hello,","World!"#Printsthewords"Hello,World!"在Python3.x中,print上的括号是强制性的,本质上使它成为一个函数,但在2.7中,两者都会产生不同的结果。关于Python2.7中的pri