Python Patterns

Author: Jeroen Ruigrok van der Werven <asmodai@in-nomine.org>
Version: $Id$

Architecture

Bitsize

Assuming that a byte is 8 bits, the code below will print the bitsize of the void pointer, which on many, if not all, platforms is the upper reach of the architecture.

On an ILP32 platform, such as the IA32 architecture, it produces the following:

>>> import ctypes
>>> ctypes.sizeof(ctypes.c_void_p) * 8
32
>>> import platform
>>> platform.architecture()
('32bit', 'ELF')

Unicode character encoding

A quick test to see whether your Python is UCS2 or UCS4 enabled is through:

>>> import sys
>>> print sys.maxunicode > 65536 and 'UCS4' or 'UCS2'

C Equivalents

__FILE__

inspect.currentframe().f_code.co_filename
>>> import inspect
>>> inspect.currentframe().f_code.co_filename
'<stdin>'

__LINE__

sys.exc_info()[2].tb_frame.f_back.f_lineno

Java Equivalents