Skip to content

Instantly share code, notes, and snippets.

@triplefox
Created October 17, 2014 04:53
Show Gist options
  • Save triplefox/e0457dbeea4073b26e6d to your computer and use it in GitHub Desktop.
Save triplefox/e0457dbeea4073b26e6d to your computer and use it in GitHub Desktop.
example of staticmethod
import random
class Mech(object):
def __str__(self):
return "Name: %s\n\tweight: %s\n\tslots: %s\n\tmax heat: %s" % (self.name, self.max_weight, self.slots, self.max_heat)
@staticmethod
def generator():
obj = Mech()
obj.name = 'Random Mech '+str(random.randint(0,9999))
obj.weight = random.randint(1,10)
obj.slots = random.randint(1,5)
obj.hps = -(round(random.randint(0,3) + random.random(),2))
obj.max_weight = 10
obj.max_heat = 10
return obj
for n in range(0, 10):
print(Mech.generator())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment