python中“ p = property”的含义

时间:2019-08-05 12:04:08

标签: python

在某些代码中,我找到了以下语句:

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())

1 个答案:

答案 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