Static parameter count

Tertius Cronje Tertius.Cronje at postoffice.co.za
Thu Mar 17 10:14:00 CET 2005


Hi all,
This does not feel Pythonic. Is there a better way to do the same?

Many TIA
T

		
 	  # L = [1,2,3,4,5,6, etc....]
	  # L can contain 'n' elements
        # fmt is made up to each particular specification
        
        if len(L) == 0:
            return ''
        elif len(L) == 1:
            return struct.pack(fmt,L[0] )
        elif len(L) == 2:
            return struct.pack(fmt,L[0] , L[1])
        elif len(L) == 3:
            return struct.pack(fmt,L[0] , L[1], L[2])
        elif len(L) == 4:
            return struct.pack(fmt,L[0] , L[1], L[2], L[3])
        elif len(L) == 5:
            return struct.pack(fmt,L[0] , L[1], L[2], L[3], L[4])
        elif len(L) == 6:
            return struct.pack(fmt,L[0] , L[1], L[2], L[3], L[4], L[5])

	# etc... etc... etc ...



More information about the Python-list mailing list