Need help in refactoring my python script

n179911 n179911 at gmail.com
Sat Aug 8 18:47:38 CEST 2009


I have a python script which process a file line by line, if the line
matches a regex, it calls a function to handle it.

My question is is there a better write to refactor my script. The
script works, but as it is, i need to keep indent to the right of the
editor as I add more and more regex for my file.

Thank you for any idea.
Now my code end up like this:

for line in fi.readlines():

	result= reg1.match(line)

	if result:
		handleReg1(result)

	else:
		result = reg2.match(line)

		if result:
			handleReg2(result)
		else:
			result = reg3.match(line)

			if result:
				handleReg3(result)
			else:
				result = reg4.match(line)

				if result:
					handleReg4(result)
				else:
					result = reg5.match(line)

					if result:
                                               handleReg5(result)



More information about the Python-list mailing list