LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-23-2011, 03:10 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Python: how to determine if running in 32 or 64bit mode?


I know I've done this before, but my googling is failing, so I'll ask here.

How can I programmatically determine if my python script is being run with a 32 or 64 bit interpreter? Better yet, is there a one-liner I can run that will print out the word size of the current python session?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 06-23-2011, 03:28 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,225

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
sys.maxint?
 
1 members found this post helpful.
Old 06-23-2011, 03:54 PM   #3
audriusk
Member
 
Registered: Mar 2011
Location: Klaipėda, Lithuania
Distribution: Slackware
Posts: 360

Rep: Reputation: 199Reputation: 199
Code:
import platform
print platform.architecture()[0]
Be sure to read the docstring for details:
Code:
$ pydoc platform.architecture
 
2 members found this post helpful.
Old 06-23-2011, 05:56 PM   #4
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Thanks to both of you. I think I have my answer now.

I appears that platform.architecture() may only return the architecture of the python on which it is being run as opposed to the 64 or 32-bittedness of the actual instance. Under OSX, you can run in 32bit mode by prefacing the command with a given architecture. For example:

Code:
$ arch -x86_64 /usr/bin/python2.6 -c "import sys;print '%x' % sys.maxint"
7fffffffffffffff

$ arch -i386 /usr/bin/python2.6 -c "import sys;print '%x' % sys.maxint"
7fffffff

$ arch -x86_64 /usr/bin/python2.6 -c "import platform; print platform.architecture()"
('64bit', '')

$ arch -i386 /usr/bin/python2.6 -c "import platform; print platform.architecture()"
('64bit', '')
so platform.architecture may not be as reliable, but it seems like a good way to check if a given python is 32 or 64bit capable.
 
Old 06-23-2011, 06:40 PM   #5
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Just to elaborate on what you now have - how about the following :
Code:
arch -x86_64 /usr/bin/python2.6 -c "import math,sys;print '%dbit' % (round(math.log(sys.maxint,2)+1))"
arch -i386 /usr/bin/python2.6 -c "import math,sys;print '%dbit' % (round(math.log(sys.maxint,2)+1))"
To report the actual bittedness of the running version of python rather than a long hex number.
 
1 members found this post helpful.
Old 06-23-2011, 06:51 PM   #6
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Ahh, very cool, bgeddy. Thanks for that addition.
 
Old 06-24-2011, 08:34 AM   #7
audriusk
Member
 
Registered: Mar 2011
Location: Klaipėda, Lithuania
Distribution: Slackware
Posts: 360

Rep: Reputation: 199Reputation: 199
Quote:
Originally Posted by BrianK View Post
I appears that platform.architecture() may only return the architecture of the python on which it is being run as opposed to the 64 or 32-bittedness of the actual instance.
Yes, just checked the docs and it's noted there: http://docs.python.org/library/platf...m.architecture
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to determine if Gnome is in screen saver mode trymore Linux - Newbie 8 02-15-2010 03:52 PM
Python: can you determine the type of shell the user is using (tcsh, bash, etc)? BrianK Programming 1 01-20-2010 09:43 PM
Determine if memory is operating in dual channel mode vascov Linux - Hardware 1 06-26-2009 02:31 AM
LFS compiled in 64bit mode? ParticleHunter Linux From Scratch 4 06-03-2004 01:33 PM
gcc on Opteron: 64bit-mode slower than 32bit-mode!!!? duckie Linux - General 2 05-20-2004 10:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration