Parsing Data, Storing into an array, Infinite Backslashes

supercomputer at gmail.com supercomputer at gmail.com
Mon Jul 11 16:47:22 EDT 2005


I am using this function to parse data I have stored in an array.

This is what the array looks like:

[['Memory', '0', 'Summary', '0'], ['Memory', '0', 'Speed',
'PC3200U-30330'], ['Memory', '0', 'Type', 'DDR SDRAM'], ['Memory', '0',
'Size', '512'], ['Memory', '0', 'Slot', 'DIMM0/J11'], ['Memory', '0',
'ConfigurationType', '2'], ['Memory', '1', 'Summary', '0'], ['Memory',
'1', 'Speed', 'PC3200U-30330'], ['Memory', '1', 'Type', 'DDR SDRAM'],
['Memory', '1', 'Size', '512'], ['Memory', '1', 'Slot', 'DIMM1/J12'],
['Memory', '1', 'ConfigurationType', '2'], ['Memory', '2', 'Summary',
'0'], ['Memory', '2', 'Speed', 'PC3200U-30330'], ['Memory', '2',
'Type', 'DDR SDRAM'], ['Memory', '2', 'Size', '512'], ['Memory', '2',
'Slot', 'DIMM2/J13'], ['Memory', '2', 'ConfigurationType', '2'],
['Memory', '3', 'Summary', '0'], ['Memory', '3', 'Speed',
'PC3200U-30330'], ['Memory', '3', 'Type', 'DDR SDRAM'], ['Memory', '3',
'Size', '512'], ['Memory', '3', 'Slot', 'DIMM3/J14'], ['Memory', '3',
'ConfigurationType', '2']]

This is the code to parse the array:

count=0
place=0
query=[]
while 1:
        try:
                i=fetch.next()
        except StopIteration:
                break
        if i[1] != count:
                ++count
                query.append(count)
        qval=`query[count]`
        query[count]=qval+i[2]+"="+i[3]+", "

print qval,"\n"

When it runs I get an output similar to this.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'Type=DDR
SDRAM,
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'Size=512,
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'Slot=DIMM2/J13,
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'ConfigurationType=2,
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\'Summary=0,
\\\\\\\\\\\\\\\'Speed=PC3200U-30330, \\\\\\\'Type=DDR SDRAM,
\\\'Size=512, \'Slot=DIMM3/J14, '

When it's supposed to print just the plain text with the numbers etc.

I have changed these lines:

        qval=`query[count]`
        query[count]=qval+i[2]+"="+i[3]+", "

To this:

        query[count]=query[count]+i[2]+"="+i[3]+", "

I get this error:

 Traceback (most recent call last):  File "infnode.py", line 60, in ?
  query[count]=query[count]+i[2]+"="+i[3]+", "TypeError: unsupported
operand type(s) for +: 'int' and 'str'

So I try and fix it by doing this:

        query[count]=`query[count]`+i[2]+"="+i[3]+", "

Can someone please point me in the right direction I am sure that the
`query[count]` is causing the backslashes.

Thanks in advance.




More information about the Python-list mailing list