On Nov 26, 5:35 pm, Steve Shepherd <sargs...@gmail.com> wrote:
> IF someone could help with some examples of answers would be great.
>
> 1. Where should we put common functions that will be called by different
> parts.
> For example I am wanting to use a Soundex function to add as a computed
> field.
> Where should I put it so I can call it and then how should I call it.

Those common functions can go in your modules directory.
Use local_import to have access to them in your code as explained in
http://web2py.com/book/default/chapter/04#Third-Party-Modules


> Here is the Soundex code:
>
> def soundex(name, len=4):
>     """ soundex module conforming to Knuth's algorithm
> implementation 2000-12-24 by Gregory Jorgensen        public domain
> """
>
>     # digits holds the soundex values for the alphabet
>     digits = '01230120022455012623010202'
>     sndx = ''
>     fc = ''
>
>     # translate alpha chars in name to soundex digits
>     for c in name.upper():
>         if c.isalpha():
>             if not fc: fc = c   # remember first letter
>             d = digits[ord(c)-ord('A')]
>             # duplicate consecutive soundex digits are skipped
>             if not sndx or (d != sndx[-1]):
>                 sndx += d
>
>     # replace first digit with first alpha character
>     sndx = fc + sndx[1:]
>
>     # remove all 0s from the soundex code
>     sndx = sndx.replace('0','')
>
>     # return soundex code padded to len characters
>     return (sndx + (len * '0'))[:len]
>
> 2. How do I trace through code. line by line and then inspect values in
> variables or objects
>
> Steve Shepherd
> Newbie

Reply via email to