I'm building an object that has an attribute whose value is randomly generated at instantiation. The attribute will be assigned a new value (also randomly) from time to time, so I'm defining a method to do so. Is it bad form to initialize the attribute by calling that method from within __init__
? It would be easy enough to avoid—I'd just have to duplicate a small amount of code—but it seems more elegant to call the method. Here's an example:
import random
class Robot(object):
def __init__(self):
self.setDirection()
def setDirection(self):
self.direction = random.random() * 360