<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Sander Sweers wrote:
<blockquote
cite="mid:b65fbb130901061030x6378ab4j8f0ba4f2c096b1bf@mail.gmail.com"
type="cite">
<pre wrap="">On Tue, Jan 6, 2009 at 04:38, bob gailer <a class="moz-txt-link-rfc2396E" href="mailto:bgailer@gmail.com"><bgailer@gmail.com></a> wrote:
</pre>
<blockquote type="cite">
<pre wrap="">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.
</pre>
</blockquote>
<pre wrap=""><!---->
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
</pre>
</blockquote>
<br>
Yes - that is what we had in mind. FWIW you can simplify slightly:<br>
<pre wrap="">def convertToString(value, dateformat):
print value
if type(value) == int:
return str(value)
try:
return strftime(dateformat, value)
except TypeError:
return value
</pre>
<br>
<br>
<pre class="moz-signature" cols="72">--
Bob Gailer
Chapel Hill NC
919-636-4239</pre>
</body>
</html>