Thanks, Eric. v1.1 runs to completion on my utils.py test case.  I'm 
finding that a good work flow involves commenting out all the functions in 
the output and fixing them up one at a time.  Here's what pytogo did for me 
on my base36encode function and what I had to do manually:

*python:*
def base36encode(number):
    """
    Encode an integer as Base 36.
    >>> base36decode('1BIGNUMBER')
    134038991273283
    """
    if not isinstance(number, int):
        raise TypeError('number must be an integer')
    if number < 0:
        raise ValueError('number must be positive')


    alphabet = '0123456789abcdefghijklmnopqrstuvwxyz'


    base36 = ''
    while number:
        number, i = divmod(number, 36)
        base36 = alphabet[i] + base36


    return base36.upper() or alphabet[0]


*pytogo:*
func base36encode(number) {
    `
    Encode an integer as Base 36.
    >>> base36decode('1BIGNUMBER')
    134038991273283
    `
    if !isinstance(number, int) {
        raise TypeError("number must be an integer")
    }
    if number < 0 {
        raise ValueError("number must be positive")


    }
    alphabet := "0123456789abcdefghijklmnopqrstuvwxyz"


    base36 = ""
    while number {
        number, i = divmod(number, 36)
        base36 = alphabet[i] + base36


    }
    return strings.ToUpper(base36) || alphabet[0]
}

*final go code:*
Getting it to compile and run required:

   1. Removing the isinstance test on number. It's not needed in Go.
   2. Deciding what to do about the number > 0 test. I made it return an 
   error.
   3. Choosing types for the arguments and returns.
   4. Declaring i outside the encoding loop.
   5. Testing number explicitly against 0.
   6. Converting alphabet[i] to string
   7. Discarding the final OR against alphabet[0]
   8. Writing a divmod function

I'm not sure which, if any, of the above are feasible to automate. Which is 
not to say that pytogo isn't useful.  It provides a good rough draft and 
that's quite a lot.  I'll certainly keep using it.

My only immediate suggestion would be to consider yanking function doc 
strings from the body and outputting them as comments above the func line.

// divmod returns quotient and remainder from numerator and denominator.
func divmod(num, denom int64) (q, r int64) {
   q, r = num/denom, num%denom
   return
}

// base36encode encodes an integer as Base 36.
func base36encode(number int64) (err error, base36 string) {
   if number < 0 {
       err = errors.New("number must be positive")
   }
   alphabet := "0123456789abcdefghijklmnopqrstuvwxyz"

   var i int64
   for number > 0 {
       number, i = divmod(number, 36)
       base36 = string(alphabet[i]) + base36
   }
   base36 = strings.ToUpper(base36)
   return
}




-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to