在某些代码中,我找到了以下语句:
p = property
我的问题是该声明的意图是什么?
(我发布的代码摘自一个较大的软件包(http://asymptote.sourceforge.net/),p = propery
背后的总体思路是什么?)
在某些情况下,带有以下语句的完整文件:
#!/usr/bin/env python3
import gettext
p = property
class xasyString:
def __init__(self, lang=None):
s = self
if lang is None:
_ = lambda x: x
else:
lng = gettext.translation('base', localedir='GUI/locale', languages=[lang])
lng.install()
_ = lng.gettext
s.rotate = _('Rotate')
s.scale = _('Scale')
s.translate = _('Translate')
s.fileOpenFailed = _('File Opening Failed.')
s.fileOpenFailedText = _('File could not be opened.')
s.asyfyComplete = _('Ready.')
我可以找到的关于p
的唯一进一步参考是:
class asyLabel(asyObj):
"""A python wrapper for an asy label"""
...
def updateCode(self, asy2psmap=identity()):
"""Generate the code describing the label"""
newLoc = asy2psmap.inverted() * self.location
locStr = xu.tuple2StrWOspaces(newLoc)
self.asyCode = 'Label("{0}",{1},p={2}{4},align={3})'.format(self.text, locStr, self.pen.getCode(), self.align,
self.getFontSizeText())
答案 0 :(得分:2)
p = property
只是使p
再次引用了property
类型,以便以后可以写
@p
def foo(...):
...
代替
@property
def foo(...):
...
property
是一种类型,所以p
只是同一类型的另一个名称。
>>> type(property)
<type 'type'>
>>> p = property
>>> type(p)
<type 'type'>
>>> p is property
True