By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,263 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,263 IT Pros & Developers. It's quick & easy.

ODBC module and strange date reference <...>

P: n/a
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.

Mar 2 '06 #1
Share this Question
Share on Google+
14 Replies


P: n/a

da*****@yahoo.com wrote:
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

Mar 2 '06 #2

P: n/a
Thanks Frank. Much appreciated. I will give it a go.

Mar 2 '06 #3

P: n/a
Thanks Frank. Much appreciated. I will give it a go.

Mar 2 '06 #4

P: n/a
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.

Mar 2 '06 #5

P: n/a
da*****@yahoo.com wrote:
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
Mar 2 '06 #6

P: n/a

Diez B. Roggisch wrote:
da*****@yahoo.com wrote:
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


Yes, this works fine on my setup.

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

Frank

Mar 2 '06 #7

P: n/a
da*****@yahoo.com wrote:
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. :)
Mar 3 '06 #8

P: n/a
da*****@yahoo.com wrote:
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...
Mar 3 '06 #9

P: n/a
Magnus Lycka wrote:
.... 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
sc***********@acm.org
Mar 3 '06 #10

P: n/a
Scott David Daniels wrote:
Magnus Lycka wrote:
.... 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).


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

regards
Steee
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

Mar 3 '06 #11

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Magnus Lycka wrote:
da*****@yahoo.com wrote:
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

iD8DBQFECItwdIO4ozGCH14RApVHAJ4ieo901ys5ygcKedSNaN CSpPjbqgCfZKSV
uRakdde/S8erdk1RnMJIiI0=
=YgSZ
-----END PGP SIGNATURE-----
Mar 3 '06 #12

P: n/a
Magnus Lycka wrote:
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

Mar 7 '06 #13

P: n/a
da*****@yahoo.com wrote:
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.


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.

-------------------------------------------------------------------------
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: an*****@bullseye.apana.org.au (pref) | Snail: PO Box 370
an*****@pcug.org.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia
Mar 8 '06 #14

P: n/a
da*****@yahoo.com wrote:
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...
Mar 8 '06 #15

This discussion thread is closed

Replies have been disabled for this discussion.