[Tutor] Conventions for code snippets for debugging and testing?
Kent Johnson
kent37 at tds.net
Thu Apr 10 23:46:14 CEST 2008
Eric Walstad wrote:
> I'd do something like this:
>
> from settings import DEBUG
>
> def my_user_list()
> # assumes long_list is already populated (db, file, etc)
> if DEBUG:
> return long_list[:5]
> else:
> return long_list
>
> def process(user):
> # do the work on the user here
> pass
>
> def main():
> # ...
> [process(user) for user in my_user_list()]
>
> The idea is to encapsulate the retrieval of the user list and let that
> encapsulation hide the DEBUG logic. It could be done with a function,
> like above, or with a MyUserList class.
I would encapsulate the retrieval but not the DEBUG. My preference would
be to have a separate main() in a test module that trims the user list.
Then the DEBUG setting is not needed at all.
Kent
More information about the Tutor
mailing list