A more straightforward solution wanted

Alex alex at somewhere.round.here
Fri Sep 24 21:47:04 EDT 1999


If record_list is a list, it will be affected by the operations on
return_list.  This may not be what you want.  You should probably make a
copy of the list, with return_list=record_list[:].  The symbol "=" is
used for assignment to variables.  Use "==" to test for equality.  Also,
you have to end if, elif, and else lines with a ":".

There are some things that seem to be included in every branch of some
if statements.  Some other long sequences of instructions seem to occur
in several branches.  You can factor these out.

Also, you might end up with more readable code if you make your record a
collection of classes.  Even if it doesn't make the code intrinsically
simpler, but it would make it much easier to follow.  It would allow you
to refer to members of record_list with comprehensible names like 

record_list.country_section

instead of record_list[31].  You could also consider using a more
readable representation of the data.  The expression "scott_suffix=='a'"
does not mean much to me.

Here is some refactored code which might do what I think you wanted your
code to do.  It is untested, though.

def vryburg(record_list):
  return_list=record_list[:]
  return_list[2]='Vryburg'
  return_list[30]=216501
  country_section=return_list[31]
  scott_number=return_list[6]
  scott_suffix=return_list[7]
  if country_section==0:
    return_list[38]='regular issues'
    return_list=valid_scott_number_range(return_list,1,5)
  if country_section==501:
    return_list[38]='Vryburg Occupation Issues'
    return_list=valid_scott_number_range(return_list,1,4)
  if country_section in [0,501]:
    return_list[91]='Cape of Good Hope'
    return_list[92]='Vryburg: Boer Occupation'
    return_list=valid_scott_prefix(return_list,'N',
                                   'Issued in Vryburg Under Boer Occupation')
    if return_list[26] in ['sp-','sp+']:
      print 'Invalid Scott Number'
    else:
      if scott_number<5:
        if scott_number<4:return_list[44]=' '
        return_list[51]=' '
        return_list[50]='SACC'
        return_list[45]=return_list[52]=scott_number
        if scott_suffix==' ':
          if scott_number==3:return_list[46]='Type B'
          else: return_list[46]='Type A'
          return_list[53]=' '
        elif scott_suffix=='a':
          if scott_number==2:return_list[53]='c'
          else: return_list[53]='b'
          return_list[46]=[None,'Type B','l for 1',
                           'Type B/Italic Z','Type B'][scott_number]
        elif scott_number==2 and scott_suffix=='b':
          return_list[53]='b';return_list[46]="Type B1"
        else:
          if scott_number==2:return_list[53]='b'
          else: return_list[53]='a'
          if scott_number!=3:
            return_list[46]=[None,'Type A/Italic Z','Type A/Italic Z',
                             None,'Type A/Italic Z'][scott_number]
      elif scott_number==5 and country_section==501:
        return_list[5]  = "Vryburg: British Occupation"
        return_list[92] = "Vryburg: British Reoccupation"
        return_list[45] = 1
        return_list[46] = " "
        return_list[52] = 2
        return_list[53] = "a" 
  else:
    return_list[38] = "Miscellaneous: Other"
    return_list[31] = 999
    return_list[28] = "Sec"
  return return_list

Alex.




More information about the Python-list mailing list