python中“p=property”的含义

2024-05-16 23:53: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())

Tags: the代码selfnone声明langdefproperty
1条回答
网友
1楼 · 发布于 2024-05-16 23:53:08

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

相关问题 更多 >