[Tutor] How to check the word size of the platform(OS)?

2014-08-02 Thread Varuna Seneviratna
What is the way to check the word size of the platform(OS), and also int
size and character size, are they the same. I searched on line But couldn't
get an answer
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to check the word size of the platform(OS)?

2014-08-02 Thread Alan Gauld

On 02/08/14 14:02, Varuna Seneviratna wrote:

What is the way to check the word size of the platform(OS), and also int
size and character size, are they the same. I searched on line But
couldn't get an answer



You need to give us more context.

Word size usually depends on CPU architecture.
It could be anything from 8 bit to 128 bit (and possibly more).

int size and char size depend on the compiler/interpreter.
For example in the TinyC compiler both int and char are 8 bits.
But several C++ compilers have settings/pragmas so you can
change the sizes within the limits of the target CPU.

If you are talking about Python (and this is, after all, a
Python list!) then int size is effectively unlimited.
char size depends on the Unicode encoding you choose. It
can be anything from 8 bits to 32 bits

What exactly do you need to know? How do you plan on using it?

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to check the word size of the platform(OS)?

2014-08-02 Thread Steven D'Aprano
On Sat, Aug 02, 2014 at 06:32:31PM +0530, Varuna Seneviratna wrote:
> What is the way to check the word size of the platform(OS), and also int
> size and character size, are they the same. I searched on line But couldn't
> get an answer

You can get some platform details from the platform module:

https://docs.python.org/2/library/platform.html

but why do you need these details? Python is a high-level 
object-oriented language, not a low-level language like C, and native 
machine types aren't very often relevant. For example, Python ints are 
not the same as native ints, they are "Big Num" objects of unlimited 
size:

py> sys.getsizeof(23)  # returns number of bytes used
12
py> sys.getsizeof(2**3)
4014


Just about the only things I can think of where I might want to know 
these sorts of low-level platform details can be handled by the struct 
module:

https://docs.python.org/2/library/struct.html

If you explain what you want to do in more detail, perhaps we can help 
with a better answer.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor