""" Felix Muzny DS 2000 Lecture 18 November 12, 2024 Experiments with classes! """ # I just care this file exists FILENAME = "ds2000_staff.csv" class Cat: def __init__(self, name, color): """ Initialize a new cat :param name: string name of the cat :param color: string color of the cat """ self.cat_name = name self.cat_color = color def purr(self): """ Make a satisfying cat sound :return: none """ print("purrrrrrrrr") def is_orange(self): """ evaluates whether or not this cat is orange :return: True if the cat is orange, False otherwise """ # access the cat_color attribute # return True or False return self.cat_color == "orange" def main(): print("lec 18 - experiments") # making some cats # ignore the self parameter # say the name of the class to call the constructor garfield = Cat("garfield", "orange") garfield.purr() print(garfield.is_orange()) print() goose = Cat("goose", "grey") goose.purr() print(goose.is_orange()) print() # seeing what class a file object is with open(FILENAME, "r") as file: # what type is the thing in the file variable? # TextIOWrapper # specific instance of TextIOWrapper (talking to "ds2000_staff.csv) print(type(file)) # attributes: # - name of the file/location on the computer # - position in the file # methods: # .readline() # .readlines() # .close() main()