[Tutor] Re: Is there a "better" way to do this?
missive at hotmail.com
Wed Dec 22 23:50:58 CET 2004
# I think the word you are looking for is
self.OK = False
self.lowValue = 1
self.highValue = 6
Please choose from the following options.
1) - Normal Unit test with static data.
2) - Normal Unit test with missing data.
3) - Integration test with current DTG.
4) - Integration test with missing data.
5) - Clean directory
6) - Exit
self.choice = raw_input("Choice(1-6) ")
# I would probably do this more like ...
self.options = ['Normal Unit test with static data',
'Normal Unit test with missing data',
# ... etc
for i, option in self.options:
print '%s) - %s', (i+1, option)
# it makes the code marginally more complex now
# but think about what will happen when you go to
# rearrange the options or add new ones ...
# also, think about what you are going to "do" with
# the choice made ... you might make the options
# list a list of tuples and handle it all in one place ...
self.options = [('Normal Unit test with static data',
('Normal Unit test with missing data',
# ... etc
# Or if you want "object oriented" practice... how about
# an "Option" class with "description" and "method"
# attributes? Just a thought ...
Express yourself instantly with MSN Messenger! Download today it's FREE!
More information about the Tutor