ODBC module and strange date reference <...>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dananrg@yahoo.com

    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.

  • Frank Millman

    #2
    Re: ODBC module and strange date reference &lt;...&gt;


    dananrg@yahoo.c om wrote:[color=blue]
    > 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.
    >[/color]

    odbc returns something called a DbiDate object.

    You can convert this into a datetime object like this -

    import datetime
    dat = datetime.dateti me.fromtimestam p(int(dbidate_o bject))

    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

    Comment

    • dananrg@yahoo.com

      #3
      Re: ODBC module and strange date reference &lt;...&gt;

      Thanks Frank. Much appreciated. I will give it a go.

      Comment

      • dananrg@yahoo.com

        #4
        Re: ODBC module and strange date reference &lt;...&gt;

        Thanks Frank. Much appreciated. I will give it a go.

        Comment

        • dananrg@yahoo.com

          #5
          Re: ODBC module and strange date reference &lt;...&gt;

          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.

          Comment

          • Diez B. Roggisch

            #6
            Re: ODBC module and strange date reference &lt;...&gt;

            dananrg@yahoo.c om wrote:
            [color=blue]
            > 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.[/color]

            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_obj ect))

            Diez

            Comment

            • Frank Millman

              #7
              Re: ODBC module and strange date reference &lt;...&gt;


              Diez B. Roggisch wrote:[color=blue]
              > dananrg@yahoo.c om wrote:
              >[color=green]
              > > 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.[/color]
              >
              > 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_obj ect))
              >
              > Diez[/color]

              Yes, this works fine on my setup.

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

              Frank

              Comment

              • Magnus Lycka

                #8
                Re: ODBC module and strange date reference &lt;...&gt;

                dananrg@yahoo.c om wrote:[color=blue]
                > 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?[/color]

                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. :)

                Comment

                • Magnus Lycka

                  #9
                  Re: ODBC module and strange date reference &lt;...&gt;

                  dananrg@yahoo.c om wrote:[color=blue]
                  > Been using the ODBC module for Python 2.1[/color]

                  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...

                  Comment

                  • Scott David Daniels

                    #10
                    Re: ODBC module and strange date reference &lt;...&gt;

                    Magnus Lycka wrote:[color=blue]
                    > .... Concerning mxODBC, you might want to have a second look
                    > at it. ... a licence might well be worth its price.[/color]
                    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
                    scott.daniels@a cm.org

                    Comment

                    • Steve Holden

                      #11
                      Re: ODBC module and strange date reference &lt;...&gt;

                      Scott David Daniels wrote:[color=blue]
                      > Magnus Lycka wrote:
                      >[color=green]
                      >>.... Concerning mxODBC, you might want to have a second look
                      >>at it. ... a licence might well be worth its price.[/color]
                      >
                      > 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).
                      >[/color]

                      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.blogs pot.com

                      Comment

                      • Gerhard Häring

                        #12
                        Re: ODBC module and strange date reference &lt;...&gt;

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

                        Magnus Lycka wrote:[color=blue]
                        > dananrg@yahoo.c om wrote:
                        >[color=green]
                        >>Been using the ODBC module for Python 2.1[/color]
                        >
                        >
                        > 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. [...][/color]

                        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

                        iD8DBQFECItwdIO 4ozGCH14RApVHAJ 4ieo901ys5ygcKe dSNaNCSpPjbqgCf ZKSV
                        uRakdde/S8erdk1RnMJIiI0 =
                        =YgSZ
                        -----END PGP SIGNATURE-----

                        Comment

                        • dananrg@yahoo.com

                          #13
                          Re: ODBC module and strange date reference &lt;...&gt;

                          Magnus Lycka wrote:[color=blue]
                          > Are you using an old version of ESRI software, or are
                          > they shipping a product with an ancient version of Python?[/color]

                          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.
                          [color=blue]
                          > 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.[/color]

                          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.
                          [color=blue]
                          > 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.[/color]

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

                          Thanks again for your help Magnus.

                          Dana

                          Comment

                          • Andrew MacIntyre

                            #14
                            Re: ODBC module and strange date reference &lt;...&gt;

                            dananrg@yahoo.c om wrote:
                            [color=blue][color=green]
                            >> 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.[/color]
                            >
                            > I think it is as well and am looking into it.[/color]

                            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: andymac@bullsey e.apana.org.au (pref) | Snail: PO Box 370
                            andymac@pcug.or g.au (alt) | Belconnen ACT 2616
                            Web: http://www.andymac.org/ | Australia

                            Comment

                            • Magnus Lycka

                              #15
                              Re: ODBC module and strange date reference &lt;...&gt;

                              dananrg@yahoo.c om wrote:[color=blue]
                              > 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.[/color]

                              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...

                              Comment

                              Working...