Python类属性 - 复位 [英] Python Class attributes - resetting

查看:109
本文介绍了Python类属性 - 复位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么在Python中重置类属性的最佳方式。

Whats the best way to reset class attributes in Python.

我有伟驰有大约20类属性的一类,在我的init我有

I have a class whichs has about 20 class attributes, in my init I have

class MyClass:
    def __init__(self)
       self.time=0
       self.pos=0
       self.vel=0
       self.acc=0
       self.rot=0
       self.dyn=0

这些都需要在我的程序的每个迭代复位,什么是该做的,而不是设置为零如上图

These need to be reset on each iteration of my program, what is the neatest way of doing this rather than setting to zero as shown above

感谢

推荐答案

我宁愿不重置它们在的init 方法,而是定义了一个重置方法对于这一点,并调用重置的init 和以后每迭代之前。

I'd rather not reset them in the init method but define a reset method for this, and call reset from init and before every subsequent iteration.

这篇关于Python类属性 - 复位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆