How can I detect 64 bit versions of Python?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I detect 64 bit versions of Python?

Vernon D. Cole
This is a reworded re-post of a question which I just placed to the IronPython list.  I repeat it here, because I hope to get a general answer which will work on CPython, too, since the database driver I support works on both implementations.  [Note: this applies to Windows only, *nix users can stop reading now. (Lucky dogs.)]

I am testing adodbapi using my new laptop which I have set up as an everything in 64-bit test bed. 

My default test database is an .mdb (so-called ACCESS database) file.  Microsoft has decided that the JET engine, which has historically been used to read and write that format is to be deprecated, so there is no 64 bit version of it.  It is replaced by the Access Database Engine 2010 redistributable. Of course, the new software requires a different connection string, one containing "Provider=Microsoft.ACE.OLEDB.12.0;".

So, how can I tell which "width" of Python I am running, so I know which connection string to use?
--
Vernon


_______________________________________________
DB-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/db-sig
Reply | Threaded
Open this post in threaded view
|

Re: How can I detect 64 bit versions of Python?

Daniele Varrazzo-2
On Mon, Feb 13, 2012 at 10:19 PM, Vernon Cole <[hidden email]> wrote:

> So, how can I tell which "width" of Python I am running, so I know which
> connection string to use?

I use sys.maxint, which is 2^63-1 on 64 bit and 2^31-1 on 32 bit. It's
not available on py3, but sys.maxsize is available on both, and it's
probably equivalent.

-- Daniele
_______________________________________________
DB-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/db-sig
Reply | Threaded
Open this post in threaded view
|

Re: How can I detect 64 bit versions of Python?

M.-A. Lemburg
In reply to this post by Vernon D. Cole
Vernon Cole wrote:

> This is a reworded re-post of a question which I just placed to the
> IronPython list.  I repeat it here, because I hope to get a general answer
> which will work on CPython, too, since the database driver I support works
> on both implementations.  [Note: this applies to Windows only, *nix users
> can stop reading now. (Lucky dogs.)]
>
> I am testing adodbapi using my new laptop which I have set up as an
> everything in 64-bit test bed.
>
> My default test database is an .mdb (so-called ACCESS database) file.
> Microsoft has decided that the JET engine, which has historically been used
> to read and write that format is to be deprecated, so there is no 64 bit
> version of it.  It is replaced by the Access Database Engine 2010
> redistributable.<http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13255>Of
> course, the new software requires a different connection string, one
> containing "Provider=Microsoft.ACE.OLEDB.12.0;".
>
> So, how can I tell which "width" of Python I am running, so I know which
> connection string to use?

The safest bet is to have a look at sys.maxsize. If it's > 2**31,
you have a 64-bit Python version, otherwise a 32-bit one.

sys.maxsize is only available in Python 2.6 and later. If you
support older versions, using the struct module can help: check
the size of a pointer to find out which bit size the Python
interpreter is using.

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 13 2012)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
_______________________________________________
DB-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/db-sig
Reply | Threaded
Open this post in threaded view
|

Re: How can I detect 64 bit versions of Python?

M.-A. Lemburg
In reply to this post by Daniele Varrazzo-2
Daniele Varrazzo wrote:
> On Mon, Feb 13, 2012 at 10:19 PM, Vernon Cole <[hidden email]> wrote:
>
>> So, how can I tell which "width" of Python I am running, so I know which
>> connection string to use?
>
> I use sys.maxint, which is 2^63-1 on 64 bit and 2^31-1 on 32 bit. It's
> not available on py3, but sys.maxsize is available on both, and it's
> probably equivalent.

Better use sys.maxsize :-)

sys.maxint is 2**31-1 on Windows x64, since MS chose not to change the
size of longs on Win64.

--
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Feb 14 2012)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/
_______________________________________________
DB-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/db-sig