im trying to access a class method from a user input. An example would be that i want to get access the method “drive_to(destination)” from the instance “fast_bycicle” of the class “Bicycle”. I want to let the user decide which bike to use so my idea kinda looks like this
class Bycicle():
def __init__(self, color, position)
self.color = color
self.position = position
def drive_to(self, destination)
self.position = destination
fast_bycicle = ("red","home")
x = input("Please select a bike: ")
x = "fast_bycicle"
y = input("Please select a destination: ")
y = "Hamburg"
x.drive_to(y)
which falls short. On the other hand side id(x) returns the id of the object.
I thought about creating a list and saving the bikes names/ids to a list and access them like that but i will run into the same problem that i cant access the instance by using a string. (I might be wrong on this)
Duke Newton is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.