在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Python  網(wǎng)絡(luò)安全/ Flask 源碼為什么使用property有些代碼不用裝飾器方式, 有些又用了?

Flask 源碼為什么使用property有些代碼不用裝飾器方式, 有些又用了?

最近看到flask的某段源碼, 看到一個(gè)類(lèi)定義里面, 有些屬性使用了裝飾器形式的property寫(xiě)法, 有些卻用了property實(shí)例化的寫(xiě)法, 這是有什么用途呢?實(shí)在看不懂為什么?

    def _get_static_url_path(self):
        if self._static_url_path is not None:
            return self._static_url_path

        if self.static_folder is not None:
            return '/' + os.path.basename(self.static_folder)

    def _set_static_url_path(self, value):
        self._static_url_path = value

    static_url_path = property(
        _get_static_url_path, _set_static_url_path,
        doc='The URL prefix that the static route will be registered for.'
    )
    del _get_static_url_path, _set_static_url_path

    @property
    def has_static_folder(self):
        """This is ``True`` if the package bound object's container has a
        folder for static files.

        .. versionadded:: 0.5
        """
        return self.static_folder is not None
回答
編輯回答
挽歌

殊途同歸~ 確切的說(shuō):這倆達(dá)到的效果是相同的。

容我猜測(cè)一下,我猜這是個(gè)人風(fēng)格的問(wèn)題(不過(guò),每個(gè)人隨著時(shí)間的推移,風(fēng)格也會(huì)變的)。不信你看~

還有一種情況,就是 當(dāng)你只需要對(duì)某個(gè)值獲取的時(shí)候進(jìn)行處理的時(shí)候,注解的方式是比較簡(jiǎn)便快捷的~

clipboard.png

2017年6月28日 20:57