I am a python beginner and I want to wrap my code in a class. However when I run the code I am getting an AttributeError: 'Generating_objects' object has no attribute 'pick_type'. Please tell me where is wrong ?
import random
from random import choice
class Generating_objects(object):
"""This class would be used to generate objects of different types e.g
integers, string, lists and so on"""
def __init__(self):
pass
def generateRandomInt(self):
self.num = random.randint(-100000, 1000000000)
return self.num
def pick_type(self):
lists = ["Int","String","Float","bool"]
choices = choice(lists)
if choices == "Int":
print generateRandomInt()
else:
print "BOO"
genR = Generating_objects()
genR.pick_type()
editbutton, copy paste your code there again, select the code, then click the{ }button on the toolbar. ;)passbreaks initialising even the parentobjectclass, so your class has no attributes at all