ODBC module and strange date reference <...>

D

dananrg

Been using the ODBC module for Python 2.1 (Win32) and had another
question. When I return data from date columns, it's in a strange
object form, e.g. <something or other> (don't have the output in front
of me>.

What's an easy way to convert date objects into a human-readable
string? I'm using this module to extract data from an Oracle database,
then converting it to a flat-file for import into an old flat-file
database on a mainframe. I need to be able to change the date object
into something the mainframe database will recognize.

Incidentally, I have just ordered:

* Learning Python
* Python Cookbook
* Python Pocket Reference

Are there any other books y'all would recommend as essential Python
references and/or books for becoming fluent in Python?

Thanks again.
 
F

Frank Millman

Been using the ODBC module for Python 2.1 (Win32) and had another
question. When I return data from date columns, it's in a strange
object form, e.g. <something or other> (don't have the output in front
of me>.

What's an easy way to convert date objects into a human-readable
string? I'm using this module to extract data from an Oracle database,
then converting it to a flat-file for import into an old flat-file
database on a mainframe. I need to be able to change the date object
into something the mainframe database will recognize.

odbc returns something called a DbiDate object.

You can convert this into a datetime object like this -

import datetime
dat = datetime.datetime.fromtimestamp(int(dbidate_object))

Now you can use any of the datetime attributes or methods to convert it
to human-readable form, such as dat.year, dat.month, str(dat), etc

I use odbc with MS Sql Server. I have never used Oracle, so I can't be
sure that it works the same way. Try it and see what happens.

HTH

Frank Millman
 
D

dananrg

Sorry for the double-thanks Frank.

I'm using Python 2.1 for Win32 and import datetime fails.

Does the datetime module come standard with later releases of Python?
If so, which release? If not, will datetime with with Python 2.1, if it
will, where can I get it? I'm still such a newbie with Python that I'm
not even sure where in the directory structure modules go. My Python
reference books from Amazon.com are in the mail.

Thanks again for your help.
 
D

Diez B. Roggisch

Sorry for the double-thanks Frank.

I'm using Python 2.1 for Win32 and import datetime fails.

Does the datetime module come standard with later releases of Python?
If so, which release? If not, will datetime with with Python 2.1, if it
will, where can I get it? I'm still such a newbie with Python that I'm
not even sure where in the directory structure modules go. My Python
reference books from Amazon.com are in the mail.

I think datetime became available around 2.3. And it's a binary module, so
chances are slim that you can backport it.

However, what Frank suggested should work with module time. too:

import time
dat = time.localtime(int(dbidate_object))

Diez
 
F

Frank Millman

Diez said:
I think datetime became available around 2.3. And it's a binary module, so
chances are slim that you can backport it.

However, what Frank suggested should work with module time. too:

import time
dat = time.localtime(int(dbidate_object))

Diez

Yes, this works fine on my setup.

You can then use time.strftime() to format it into human-readable
output.

Frank
 
M

Magnus Lycka

Incidentally, I have just ordered:

* Learning Python
* Python Cookbook
* Python Pocket Reference

Are there any other books y'all would recommend as essential Python
references and/or books for becoming fluent in Python?

Both Beazley's "Python Essential Reference" and Martelli's
"Python in a Nutshell" are good reference books. I think
Beazley's book has just been released in its 3rd edition,
and I understand that Alex is working on the 2nd edition
of the Nutshell book.

They are both good, so if you don't want to wait, I think
you should get Beazley's book, which should be more up to
date than the 1st ed of the Nutshell book.

I think Chris Fehily's "Python: Visual Quickstart Quide"
was good too. The 2nd ed is due in April. It might be a
bit redundant if you have Learning Python though.

I guess the same goes for Magnus Lie Hetlands new book.

If you are working with Python on Windows and want to use
COM or other Windows features, you might want to get "Python
Programming on Win32" by Hammond and Robinson. It's six
years old, so it's not 100% up to date, but I think it's
the only book that covers Windows programming with Python
in detail.

There are also good books concerning other spcific topics
such as text processing, networking, GUI development etc,
but don't get all the books at once. :)
 
M

Magnus Lycka

Been using the ODBC module for Python 2.1

It might well become a problem that you are stuck with
a five year old Python version. Python 2.1 is no longer
a supported Python version. Support for 2.2 will probably
end soon.

Are you using an old version of ESRI software, or are
they shipping a product with an ancient version of
Python?

You can't really expect that third party product will
support Python 2.1 any longer. A lot of new software
take advantage of the new features in Python that came
in later versions. Current Python versions are also a
bit faster.

If I were you, I'd check with ESRI support if you can't
use a newer version of Python. I think it's possible.

Concerning mxODBC, you might want to have a second look
at it. I don't know your business context of course, but
if I understand correctly, it can be used for free for
inhouse use, and if that doesn't apply to your situation,
a licence might well be worth its price. If this is
something you will distribute to customers, I suspect
you can make a deal with eGenix and get a better price
than the normal site license. (It's a while since I
looked at their pricing, so I don't know if I'm making
sense...)

Anyway, I think the best option would be to get a newer
Python installed if that's reasonable, but I realize
that might cause some extra work if your code is to
run on a lot of machines...
 
S

Scott David Daniels

Magnus said:
.... Concerning mxODBC, you might want to have a second look
at it. ... a licence might well be worth its price.
Yup, it _is_ a great deal. I worked with mxODBC in a former
job at DevelopNET, and (A) the license cost was _low_, and (B)
it saved me enough time in the first month to cover what we
spent on the license for the two years we used it (then the
company died).

--Scott David Daniels
(e-mail address removed)
 
S

Steve Holden

Scott said:
Yup, it _is_ a great deal. I worked with mxODBC in a former
job at DevelopNET, and (A) the license cost was _low_, and (B)
it saved me enough time in the first month to cover what we
spent on the license for the two years we used it (then the
company died).

Be aware, though, that the license requires a payment for commercial use
even if it's only in-house, I believe.

regards
Steee
 
?

=?ISO-8859-1?Q?Gerhard_H=E4ring?=

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Magnus said:
Been using the ODBC module for Python 2.1


It might well become a problem that you are stuck with
a five year old Python version. Python 2.1 is no longer
a supported Python version. Support for 2.2 will probably
end soon. [...]

At this point you shouldn't expect anything but the Python 2.4 series to
be actually supported.

By supported I mean that a new minor release will happen if a
significant bug is found.

- -- Gerhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFECItwdIO4ozGCH14RApVHAJ4ieo901ys5ygcKedSNaNCSpPjbqgCfZKSV
uRakdde/S8erdk1RnMJIiI0=
=YgSZ
-----END PGP SIGNATURE-----
 
D

dananrg

Magnus said:
Are you using an old version of ESRI software, or are
they shipping a product with an ancient version of Python?

We're using the latest and greatest ArcGIS Desktop product, which is at
release 9.1. Evidently they chose to use Python 2.1 to ensure a "silent
install" when ArcGIS Desktop gets installed.

I've been told the beta for ArcGIS Desktop 9.2 ships with Python 2.4,
so it's safe to say the official release of 9.2 this summer will ship
with Python 2.4 as well. At least that's my hope.
You can't really expect that third party product will
support Python 2.1 any longer. A lot of new software
take advantage of the new features in Python that came
in later versions. Current Python versions are also a
bit faster.

I'm all for using for the latest version of Python. I'm just now
learning about Python classes, and it seems like there were some
significant changes at 2.2.
If I were you, I'd check with ESRI support if you can't
use a newer version of Python. I think it's possible.

I think it is as well and am looking into it.

Thanks again for your help Magnus.

Dana
 
A

Andrew MacIntyre

I think it is as well and am looking into it.

It's possible if they choose to build the necessary binary modules
(DLLs).
On Windows, Python extension modules are linked to the Python interpreter
core DLL, which is version specific (python??.dll, eg python21.dll). As
ESRI were including Python 2.1, I doubt that they went to the trouble of
building multiple versions, especially considering that the MSVC runtime
(as of VC7.0) changes. The standard installers for Python 2.1, 2.2 &
2.3 were all built with VC6, while Python 2.4 is built with VC7.1.
 
M

Magnus Lycka

I'm all for using for the latest version of Python. I'm just now
learning about Python classes, and it seems like there were some
significant changes at 2.2.

I don't remember exactly what appeared when, but nothing you
learn with 2.1 will stop working in 2.2 (I think--at least
nothing broke for me, and I haven't heard of any problems
in this regard).

On Windows, you might have problems crossing the 2.2 -> 2.3
gap if you use non-ASCII characters in the source code. That's
the only upgrade problem I ever had from 1.4.2 to 2.4.2...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top