gpt4 book ai didi

Python-@property 与 func()

转载 作者:太空宇宙 更新时间:2023-11-04 07:01:50 24 4
gpt4 key购买 nike

<分区>

使用 someclass.func 代替 someclass.func() 一直是我的梦想。我阅读了有关 @decorators 的内容。现在我问:

哪种方式更好?

方式一

class Main(object):

def __init__(self):

self.func()

def func(self):

print 'hi'

或者...

方式二

class Main(object):

def __init__(self):

self.func

@property
def func(self):

print 'hi'

编辑

代码如下: http://randomgalaxy.com/stackoverflow/python-property-vs-func/term.py

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com