[Tutor] Conventions for code snippets for debugging and testing?
Eric Walstad
eric at ericwalstad.com
Thu Apr 10 23:21:05 CEST 2008
Hi Robert
On Thu, Apr 10, 2008 at 1:34 PM, Robert Kirkpatrick <robertk at bcgsc.ca> wrote:
> Hi All,
>
> Just wondering if there are any basic conventions for including code
> snippets that are for testing / debugging only?
>
> For example, you could set a boolean variable called DEBUG, then have
> snippets of code like:
>
> if DEBUG:
> do stuff
> else:
> do otherstuff
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.
More information about the Tutor
mailing list