Do you use the get/set pattern (in Python)?

后端 未结 8 1985
长情又很酷
长情又很酷 2020-12-12 13:25

Using get/set seems to be a common practice in Java (for various reasons), but I hardly see Python code that uses this.

Why do you use or avoid get/set methods in Py

8条回答
  •  情深已故
    2020-12-12 14:15

    I had come here for that answer(unfortunately i couldn't) . But i found a work around else where . This below code could be alternative for get .
    class get_var_lis: def __init__(self): pass def __call__(self): return [2,3,4] def __iter__(self): return iter([2,3,4]) some_other_var = get_var_lis
    This is just a workaround . By using the above concept u could easily build get/set methodology in py too.

提交回复
热议问题