[Tutor] Engarde program was: i++
scott
slewin at rogers.com
Wed Jun 6 20:17:49 CEST 2007
Danny Yoo wrote:
> In the context of the new Master_stats class, it makes more sense for
> mfile_read() to return a Master_stats object now rather than a two-tuple
> list.
I was able to change the [year, month] to just master and it worked
fine. I was also able to do master = mfile_read() and it worked fine as
well.
> To make the code a little safer, explicitely close the file here.
Oh, I forgot to add in the close; I intended to have one put in. I also
noticed I forgot to put a close in for the char_sheet as well, so I
added one in. I assume that it is good programming practise to close
all open files when they are not needed anymore?
> Ok, looking at create_char() since it's one of the larger functions.
> The value of 's' in create_char() is mixed: at one point, it's an
> integer, at other instances, a string. There's a possible flow of
> control that doesn't make sense to me...
I wrote the is_yes as follows and it seems to work fine.
###################################################
def is_yes(question):
i = 0
while i == 0:
s = raw_input(question)
if s == 'y' or s == 'yes':
return True
elif s == 'n' or s == 'no':
return False
else:
print '\nplease select y, n, yes, or no\n'
###################################################
I was also able to shrink the code down to:
###################################################
if not is_yes('Is ' + name + ' a sufficient character name?'):
if is_yes('Is ' + alt_name + ' a sufficient character name?'):
name = alt_name
else:
return
###################################################
You will probably notice a new unused class. I am starting to do the
main part of the program and the first thing I need to do is read a very
large text file generated from a web form. What I was thinking about
doing was creating a function that reads the text form and then place
all the values into variables "glued" together in a class. I can then
pass that class back and use the variables when I need them.
--
Your friend,
Scott
Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: engarde.py
Type: text/x-python
Size: 12173 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20070606/443b9086/attachment-0001.py
More information about the Tutor
mailing list