450 Pound Library Program

Magnus Lycka lycka at carmen.se
Wed Feb 8 07:49:12 EST 2006


just a few style notes...

>     def checkOutBook(self, readerName):
>         "'Remove book from the front of the list, block if no books are
> available'"

I don't understand what "' is supposed to imply. If you
meant to use triple quoting, you need to use ''' or """.
Then the string can contain line breaks. (Perhaps you have
a really stupid email client/news client/editor/whatever that
replaces ''' with "'? Please loose that or use """.)

Also, please use lines that are short enough not to wrap
around. Line wrapping makes the code very ugly. Do like this:

     def checkOutBook(self, readerName):
         """Remove book from the front of the list, block if no
            books are available."""

[...]
>         for line in theBookFile.readlines():

In modern Python you simply write:
         for line in theBookFile:

>             L = line.split (",")  # a comma-delimited list
>             author = L[0]
>             bookName =  L[1]

Why bother with L? The follwing is as clear I think, and solves
the problem of commas in the title. Also, don't put a space between
the callable and the parenthesis please. See the Python style guide,
PEP 008.

             author, bookName = line.split(",", 2)

[...]
>     totalBooks = input("How many books would you like in the
> Library?[1-" + str(len(stacks)) + "]")

Again, don't make the lines so long. You don't have to do that.
You can break lines freely inside (), {} and [], and adjacent
string literals are automatically concatenated.

     totalBooks = input("How many books would you like in "
                        "the Library?[1-%d]" % len(stacks))



More information about the Python-list mailing list