Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Markov Analysis Help (http://www.velocityreviews.com/forums/t615341-re-markov-analysis-help.html)

bearophileHUGS@lycos.com 05-17-2008 12:01 PM

Re: Markov Analysis Help
 
dave, few general comments to your code:
- Instead of using a comment that explains the meaning of a function,
add such things into docstrings.
- Your names can be improved, instead of f you can use file_name or
something like that, instead of convert_file you can use a name that
denotes that the conversion is already done, etc.
- You can use xrange instead of range and you can indent less, like 4
spaces.
- This line may be slow, you may want to find simpler ways to do the
same thing:
rkey = random.choice(analyze.keys())
- I suggest you to add doctests to all your functions.

Bye,
bearophile

Terry Reedy 05-17-2008 04:13 PM

Re: Markov Analysis Help
 

"dave" <squareswallower@1ya2hoo3.net> wrote in message
news:g0mvc2$sic$1@news.xmission.com...
| bear,
| thanks for the suggestions. I use IDLE to write the code and when it's
| working I paste it over into a new window.

Or you can just save code you want to keep to a new name.

| To add doctests would I need to use a certain
| filename for the tests to be run on?

You can run a doctest on a file from within the file (as well as from
without).

if __name__ == '__main__': <run doctest>

I presume the manual gives the details.

| Can you have doctests on random functions?

???

tjr




bearophileHUGS@lycos.com 05-17-2008 08:05 PM

Re: Markov Analysis Help
 
dave:
>Can you have doctests on random functions?


Yes, you can add doctests to methods, functions, classes, module
docstrings, and in external text files.

Bye,
bearophile


All times are GMT. The time now is 08:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.