On Tue, Jan 6, 2009 at 04:38, bob gailer <[email protected]> wrote:
> I also suggest splitting convertValue into two functions, one that takes
> strings and one that takes numbers. A lot easier to read and maintain.
>
> FWIW you could dispense with reverse in convertValue by testing the type of
> value for int or str.

Thanks for feedback and suggestions. Below is the function split in 2.

def convertToString(value, dateformat):
    print value
    if type(value) == int:
        return str(value)
    else:
        try:
            return strftime(dateformat, value)
        except TypeError:
            return value

def convertFromString(value, dateformat):
    try:
        return int(float(value))
    except ValueError:
        try:
            return strptime(value, dateformat)
        except:
            return value

Greets
Sander
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to