Im tring to write a piece of code to work out the indentation level of a code snippet from a text file. I know i need to use regular expressions but i dont know that much about regualr expressions in Python. What i really need is some ideas on how to work out indentation levels. Anyone got any ideas?


heres what i have so far: (not sure how this is gonna turn out)

class parser:
	def __init__(self):
	def load(self, file): = open(file, 'r').read()
		print + '\n\n\n'
	def clean(self):
		parts = token.split(
		for part in parts:
			if part[:3] == '<py':
				part = re.split('\n', part[4:-3])
				for bit in part:
					bit = re.sub('\t|\s\s', '', bit)
					if bit == '': pass
					else: self.indent(bit)
	def indent(self, indent):
		if indent[-1] == ':': print indent
		elif indent[-1] == ',': print indent
		elif indent[-1] == '/': print indent
		else: print indent