I came across this nifty bit of code the other day when looking for a way to do this and, just for fun, thought I’d convert it to IronPython. So I did. And here it is:

import System

def is_assembly_debug_build(filename):
	"""Returns true if filename appears to have been built in debug mode"""
	result = False
	dll = System.Reflection.Assembly.LoadFile(filename)
	customAttribs = dll.GetCustomAttributes(False)
	for att in customAttribs:
		if att.GetType() == System.Type.GetType("System.Diagnostics.DebuggableAttribute"):
			result = att.IsJITTrackingEnabled
	return result

I saved this in a file called diagnostics.py. So using it (you’ll need to be in the same directory as diagnostics.py or have added diagnostics.py to your path - more info can be found here: http://docs.python.org/tutorial/modules.html#the-module-search-path) is simply a matter of doing something like this:

from diagnostics import is_assembly_debug_build

If you’re interested you can grab a copy of diagnostics.py from http://gist.github.com/206177