473,471 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ODBC module and strange date reference <...>

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
14 1754

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
Thanks Frank. Much appreciated. I will give it a go.

Mar 2 '06 #3
Thanks Frank. Much appreciated. I will give it a go.

Mar 2 '06 #4
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
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

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
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
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
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
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
-----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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gerry | last post by:
Help needed with this: I have had a guestbook-page in Europe and will now have to move it to a US based-server. This makes the time-function showing time 6 hours wrong. The time should be GMT...
1
by: Fons Dijkstra | last post by:
Hello, I'm using the mx.ODBC.Windows package in order to read/write a MSAccess database. Everything works fine apart from the DATE format handling. I'm using the default "datetimeformat" (i.e....
0
by: Nico den Boer | last post by:
Hi all, I'm working with: MySql: Database server: mysql-4.1.7-essential-win ODBC driver: MyODBC-3.51.10-x86-win-32bit Administrator: mysql-administrator-1.0.14-win Query browser:...
3
by: Johnny M | last post by:
using Access 2003 Pardon the subject line, but I don't have a better word for this strange behavior (or behavior I don't understand!!!) I have a class module named DepreciationFactor. One of...
9
by: newtophp2000 | last post by:
I need to add the ability for the users to select a date on one of our web pages. The examples I was given by some users were in JavaScript. Is there a free date picker that I can use? I saw one...
5
by: dananrg | last post by:
I was messing around with the native ODBC module (I am using Python in a Win32 environment), e.g: import dbi, odbc ....and it seems to meet my needs. I'd rather use a module that comes...
16
by: network-admin | last post by:
We have Problems with Access query on Oracle 10g Database with ODBC Connection. The Query_1 is such as select * from xtable where ycolumn <"S" Result = ODBC Faild...
1
by: Nilam2477 | last post by:
I have application developed in VC/COM/DCOM At some point of time i got the following error message and application closed. Faulting application <application name>, version <version number>,...
3
by: Jeff | last post by:
hi asp.net 2.0 i've used connectionstrings like this one for my webproject: connectionString="Server=Pdc1;Database=Testing;Integrated Security=false;User ID=tester;Pwd=hardtoguesspwd;" /> ...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.