I've defined a main function in my class as well as a method to return the properties of the object using the method def __str__(self):. Being that I'm calling __repr__ inside of the class, is this the proper way of invoking this function? Also, is there a better alternative to having to use a long chain of if, elif, and else's?
Code:
def main(self):
"""Create usability of the account. Accessing the account
should enable the user to check the account balance, make
a deposit, and make a withdrawal."""
main_menu = {1: 'Balance', 2: 'Deposit', 3: 'Withdraw', 4: 'Exit'}
using_account = True
while using_account:
print '\nAvailable Choices:'
print '\n'.join('%d.) %s' % (i, choice) for i, choice in
main_menu.iteritems())
my_choice = int(raw_input('Enter a choice: '))
if my_choice == 1:
self.current_balance()
elif my_choice == 2:
self.deposit_funds()
elif my_choice == 3:
self.withdraw_funds()
elif my_choice == 4:
print self.__repr__()
using_account = False
else:
print 'Invalid choice, try again!'
repr(self)instead.