can python do this?

Thomas Weholt thomas at cintra.no
Tue Jun 13 04:35:56 EDT 2000


On Tue, 13 Jun 2000 17:44:52 +1000, "Jason" <it at onestopent.com.au>
wrote:

>hi thomas
>thanks for your help again...
>here's the error message i get when i run your script in IDLE
>the listing is the first in the txt file
>can you help pls....
>does this script make the output file a tab file..i can't see any tab in the
>script at all...can you let me know pls...
>
>thanks
>jason
>
>FORM: ['Popular Recording']
>CMTYPESWITCH: ['Popular']
>RELOCORIGINAL: ['8F2C014FEFE7A61DCA2568D600267EBD']
>CMCOUNTRY_ORIGIN: ['']
>CMGENRE_CODE: ['']
>CPTITLE: ['LIQUID']
>CPARTIST: ['RECOIL']
>CPOARTISTS: ['']
>CMCATNUMBER: ['CDSTUMM173']
>CMAPN: ['5016025611737']
>CMARIAPRICECODE: ['C1145']
>CMARIAMEDIACODE: ['21']
>CMARIADISTRIBUTORCODE: ['MDS']
>CMARIAPACKAGECODE: ['']
>DMRELEASE: ['19/06/2000']
>cMDateFormat: ['19/06/2000 12']
>DMDELETE: ['']
>cMDeleteStatus: ['No']
>CMLISTPTRACKS: ['']
>CMLISTPARTISTS: ['']
>RELOCMEDIA: ['0FE68A46C3E72687CA2568D6002C9FAD']
>CURMPRICE: ['21.71']
>CMTYPE: ['Compact Disc']
>CMRECORDCOMPANY: ['MUSHROOM DISTRIBUTION SERVICES']
>CMPACKAGE: ['']
>CMARIADISTRIBUTORHOUSECODE: ['BFM']
>cDistributorHouse: ['BFM']
>CMLOCALE: ['Y']
>$UpdatedBy: ['CN=PPT/OU=AEROS/O=JUKEBOX']
>$Revisions: ['05/05/2000 06']
>Traceback (innermost last):
>  File "C:\PROGRA~1\PYTHON\TOOLS\IDLE\ScriptBinding.py", line 131, in
>run_module_event
>    execfile(filename, mod.__dict__)
>  File "C:\WINDOWS\Desktop\aeros1.py", line 6, in ?
>    print pair[0] +": "+ `string.split(string.strip(pair[1]),",")`
>IndexError: list index out of range
>
>

Look at the error-message. IndeError: list index out of range. It`s
referring to the line above, 
print pair[0] +": "+ `string.split(string.strip(pair[1]),",")`

The variable pair have to parts, accessible by using an index, like
pair[0] would get you the first item in pair, pair[1] the second etc.
In the line that gives you the error you try to access and print an
item that doesn`t exists. That`s why it says "IndexError". Before
trying to access the pair variable you should check to see that it
actually has some contents, like so:

if len(pair) == 2:
	print pair[0] +": "+ `string.split(string.strip(pair[1]),",")`

Then it will only try to access and print if the pair-variable has to
items in it.

Hope that helps.

Thomas




More information about the Python-list mailing list