[Tutor] redundant function ( or,
I need advice about cleaning up my code )
Morgan Meader
morgan at insightmill.com
Wed Oct 13 21:40:15 CEST 2004
Hello all,
I am very new to python. I have the basics down somewhat but really want
to save myself maintainence problems down the road. Please permit me to
ask for guidance.
This is one function example of the 4000 lines or so that I have so far.
It(the program) is working as expected but it is ugly... well... just
look below at this example. Anyway... some pointers( not refs ;-) ) as
to how some of you experts would handle this kind of duplicate code in a
function.
FYI... I don't quite understand OOP yet but I'm reading furiously. And
unfortunately I come from the Shell scripting world so any advice re:
unlearning bad habits would be welcome.
[code]
def addChannelFeatures(job,step,impData,coup):
layerNames = []
layerTypes = []
layerPols = []
for i in xrange(len(job.matrix.info['gROWname'])):
if job.matrix.info['gROWtype'][i] == 'power_ground' or \
job.matrix.info['gROWtype'][i] == 'mixed' or \
job.matrix.info['gROWtype'][i] == 'signal':
layerNames.append(job.matrix.info['gROWname'][i])
layerTypes.append(job.matrix.info['gROWlayer_type'][i])
layerPols.append(job.matrix.info['gROWpolarity'][i])
layers.sort()
# add the channels
step.clearAll()
for imp in impData:
# positive planes
for i in imp['ranges']:
if layerTypes[i] != 'signal':
if layerPols == 'positive':
step.affect(layerNames[i])
if imp['impedence_type'] == 'stripline':
channelSize = 1000*(imp['width'] + 2*imp['spacing'])
addSChannel(imp,channelSize,coup,pol='negative')
elif imp['impedence_type'] == 'broadside':
channelSize = 1000*(imp['width'] + 2*imp['spacing'])
addBChannel(imp,channelSize,coup,pol='negative')
elif imp['impedence_type'] == 'differential':
channelSize = 1000*(2*imp['width'] + 3*imp['spacing'])
addDChannel(imp,channelSize,coup,pol='negative')
step.clearAll()
if DEBUG:
step.PAUSE('are stripline the channels looking good?')
# negative planes
for i in imp['ranges']:
if layerTypes[i] != 'signal':
if layerPols == 'negative':
step.affect(layerNames[i])
if imp['impedence_type'] == 'stripline':
channelSize = 1000*(imp['width'] + 2*imp['spacing'])
addSChannel(imp,channelSize,coup,pol='positive')
elif imp['impedence_type'] == 'broadside':
channelSize = 1000*(imp['width'] + 2*imp['spacing'])
addBChannel(imp,channelSize,coup,pol='positive')
elif imp['impedence_type'] == 'differential':
channelSize = 1000*(2*imp['width'] + 3*imp['spacing'])
addDChannel(imp,channelSize,coup,pol='positive')
step.clearAll()
if DEBUG:
step.PAUSE('are stripline the channels looking good?')
pass
[/code]
Thank you for any help,
Morgan
More information about the Tutor
mailing list