草庐IT

propertie

全部标签

python - 如何在python中获取property的setter方法的属性

请考虑下面的代码classDataMember():def__init__(self,**args):self.default={"required":False,"type":"string","length":-1}self.default.update(args)def__call__(self,func):#HereIwanttosettheattributetomethodsetattr(func,"__dbattr__",self.default)defvalidate(obj,value):#someothercodefunc(obj,value)returnvalida

python - salt 栈 : Properties (computed values) for data from SLS files?

我们在salt管理的minions上运行多个Python虚拟环境。系统的名称是按此架构构建的:project_customer_stage例子:supercms_favoritcustomer_p支柱数据:systems:-customer:favoritcustomerproject:supercmsstage:p-customer:favoritcustomerproject:supercmsstage:q对于每个virtualenv,我们都有一个linux用户。到目前为止,我们像这样计算像“home”这样的值:{%forsysteminpillar.systems%}{%sets

python - 为什么 properties 是 Python 中的类属性?

我正在阅读FluentPython第19章>正确查看属性,我对以下单词感到困惑:Propertiesarealwaysclassattributes,buttheyactuallymanageattributeaccessintheinstancesoftheclass.示例代码是:classLineItem:def__init__(self,description,weight,price):self.description=descriptionself.weight=weight#self.price=pricedefsubtotal(self):returnself.weigh

Python 类设计 : explicit keyword arguments vs. **kwargs 与 @property

是否有一个普遍接受的最佳实践来创建一个类,其实例将具有许多(不可默认的)变量?例如,通过显式参数:classCircle(object):def__init__(self,x,y,radius):self.x=xself.y=yself.radius=radius使用**kwargs:classCircle(object):def__init__(self,**kwargs):if'x'inkwargs:self.x=kwargs['x']if'y'inkwargs:self.y=kwargs['y']if'radius'inkwargs:self.radius=kwargs['rad

python - 在@property 之后装饰类方法

我想使用装饰器包装除__init__之外的各种对象的每个方法。classMyObject(object):defmethod(self):print"methodcalledon%s"%str(self)@propertydefresult(self):return"Somederivedproperty"defmy_decorator(func):def_wrapped(*args,**kwargs):print"Callingdecoratedfunction%s"%funcreturnfunc(*args,**kwargs)return_wrappedclassWrappedOb

python - 谷歌应用引擎 : how can I programmatically access the properties of my Model class?

我有一个模型类:classPerson(db.Model):first_name=db.StringProperty(required=True)last_name=db.StringProperty(required=True)我在p中有一个此类的实例,字符串s包含值'first_name'。我想做类似的事情:printp[s]和p[s]=new_value两者都会导致TypeError。有人知道我怎样才能实现我想要的吗? 最佳答案 如果模型类足够智能,它应该能够识别执行此操作的标准Python方法。尝试:getattr(p,s)

Python 类变量或@property

我正在编写一个python类来存储数据,然后另一个类将创建该类的一个实例来打印不同的变量。一些类变量需要大量格式化,这可能需要多行代码才能使其处于“最终状态”。仅使用这种结构从类外部访问变量是否是一种不好的做法?classData():def__init__(self):self.data="data"还是使用@property方法访问变量更好?classData:@propertydefdata(self):return"data" 最佳答案 小心,如果你这样做:classData:@propertydefdata(self):r

python - celery 的困难 : function object has no property 'delay'

我最近一直在忙于软件开发,并取得了一些成功,使celery屈服于我的意志。我已经成功地使用它发送电子邮件,并且刚刚尝试使用几乎完全相同的代码(在重新启动所有进程等之后)通过Twilio发送短信。但是我不断遇到以下问题:File"/Users/Rob/Dropbox/Python/secTrial/views.py",line115,insend_smssend_sms.delay(recipients,form.text.data)AttributeError:'function'objecthasnoattribute'delay'我的代码如下:@celery.taskdefsend

python - Flask-Login 引发 TypeError : 'bool' object is not callable when trying to override is_active property

我想修改Flask-Login中的is_active,这样用户就不会一直处于事件状态。默认值始终返回True,但我将其更改为返回banned列的值。根据文档,is_active应该是一个属性。但是,内部Flask-Login代码引发:TypeError:'bool'objectisnotcallable尝试使用is_active时。如何正确使用is_active来停用某些用户?classUser(UserMixin,db.Model):id=db.Column(db.Integer,primary_key=True)banned=db.Column(db.Boolean,default

python - @property 在这种情况下的用处

给定以下类:classBasicRNNCell(RNNCell):"""ThemostbasicRNNcell."""def__init__(self,num_units,input_size=None):self._num_units=num_unitsself._input_size=num_unitsifinput_sizeisNoneelseinput_size@propertydefinput_size(self):returnself._input_size@propertydefoutput_size(self):returnself._num_units@propert