Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Markov Analysis Help

Reply
Thread Tools

Re: Markov Analysis Help

 
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      05-17-2008
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
 
Reply With Quote
 
 
 
 
Terry Reedy
Guest
Posts: n/a
 
      05-17-2008

"dave" <(E-Mail Removed)> wrote in message
news:g0mvc2$sic$(E-Mail Removed)...
| 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



 
Reply With Quote
 
 
 
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      05-17-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
markov chains Sigma2 Digital Photography 0 11-30-2007 02:30 PM
[SOLUTION] Markov Chain (#74) semmons99@gmail.com Ruby 0 04-09-2006 01:19 PM
Re: Markov process representation kpp9c Python 8 03-16-2006 08:17 AM
markov query kpp9c Python 5 03-15-2006 01:12 AM
Markov chain with extras? temp@mclift.fsnet.co.uk Python 7 05-19-2005 06:23 PM



Advertisments