coding convention conversion

D-Man dsh8290 at rit.edu
Fri Dec 22 16:55:27 EST 2000


This shouldn't be too hard with a python script and some regexes with
some more string processing in between (or maybe multiple pass).

Everything you want to change is bounded by "def" on one side and "("
on the other.  Then replace the capitals with _ followed by the lower
case version.

A quick (partial) solution:

re = re.compile( "def ([a-z]+)([A-Z])([a-z]*)\(" )

for line in source.readlines() :
	match = re.match( line )
	if ( match ) :
		res = "def " + re.group( 0 ) + "_" + \
			string.lower( re.group( 1 ) + re.group( 2 ) + "("


This isn't complete and won't have the arguments in the result (nor
preserve indentation before the "def").

I think the re.sub() function will do more of what you want it to.


HTH,
-D


On Fri, Dec 22, 2000 at 12:20:15PM -0800, Issac Trotts wrote:
> Does anyone know of a utility to change between the coding conventions 
> of
> 
> def fooBarBaz(): pass
> 
> and 
> 
> def foo_bar_baz(): pass
> 
> It is a pain to do this by hand.
> 
> Thanks,
> Issac




More information about the Python-list mailing list