passing lists
Steve Holden
steve at holdenweb.com
Thu Mar 3 10:06:52 EST 2005
Earl Eiland wrote:
> This message contains the responses to two previous messages:
>
[...]
>
>
> In response to Steve H., the traceback is
> Traceback (most recent call last):
> File "../Devel_2.py", line 125, in ?
> Inbound_Results = Parser.Sort(Inb_sequence,
> "Inbound-dump-"+Run_ID+"-Dropped
> .dmp", "Inbound-dump-"+Run_ID+"-Created.dmp")
> File
> "/home/earl/ResearchProjects/IntrusionResistance/NewPhasee2/Parser.py",
> l
> ine 291, in Sort
> if Raw_packet_queue[ctr][1] == Passed_IP: Last_Passed, Last_Dropped,
> Raw_pac
> ket_queue = Match(Created, Passed, Raw_packet_queue, Raw, False,
> Last_Passed, La
> st_Dropped, First_Created, ctr)
> File
> "/home/earl/ResearchProjects/IntrusionResistance/NewPhasee2/Parser.py",
> l
> ine 132, in Match
> Last_Passed = Raw_packet_queue[0][0][1]
> TypeError: unsubscriptable object
>
> On Wed, 2005-03-02 at 15:34, Steve Holden wrote:
>
>>Earl Eiland wrote:
>>
>>>def Match(..., Raw_packet_queue, ...):
>>> ...
>>> print 'in Match, Raw_Packet_queue is', Raw_packet_queue # this returns
>>>'Reader object at 0xaaa'
>>> ...
>>> return [Last_Passed, Last_Dropped, Raw_packet_queue] # this causes
>>>'unsubscriptable object'error message
>>>
>>>#*************************************************
>>>def Main(...):
>>> Raw_packet_queue = []
>>> ...
>>> Raw_packet_queue = enqueue(..., Raw_packet_queue, ...) # this works
>>> ...
>>> if Raw_packet_queue[ctr][1] == Passed_IP: Last_Passed, Last_Dropped,
>>
>> ^^^^^^^^
>> oops!
>>
>>>Raw_packet_queue = Match(..., Raw_packet_queue, ...) # the problem
>>>starts here
>>> ...
>>>
>>
>>Rule one: ALWAYS include the actual traceback, rather than providing
>>your interporetation of what it means (though you are then free to do
>>that, too).
>>
>>What makes you think it's the Match() call that's causing the problem?
>>
>>I'd be willing to bet money it's the double-subscripting of
>>Raw_packet_queue - if item [ctr] on the Raw_packet_queue isn't a list or
>>a dict then subscripting it by [1] will give you the error message that
>>you quote.
>>
>>But if you had included the traceback you would have made it unnecessary
>>for me to use my psychic powers :-)
>>
>>regards
>> Steve
>>
[...]
>>>>On Wed, 02 Mar 2005 14:05:18 -0700, Earl Eiland <eee at nmt.edu> wrote:
>>>>
>>>>
>>>>>I have a program in which I'm passing a list to functions. When I
>>>>>reference an element in a function to which it is passed, I get the
>>>>>error message "unsubscriptable object". When printing the list contents
>>>>>in that same function, I get "xxx is <Reader object at 0xyyyy>". How do
>>>>>I pass a list?
>>>>>
>>>>>Earl Eiland
>>>>>
Earl:
It seems you code isn't optimized for debugging :-)
Why all the use of lists? I suspect (though I don;t mean to demean your
programming skill) that you might be better to define object classes to
represent things like the elements of your Raw_packet_queue. Then,
rather than having to refer to
Raw_packet_queue[0][0][1]
you would be able to use something a little more helpful like
Raw_packet_queue[0].pkt_hdr.something
which would make the code more readable and also more writable!
Anyhow, the problem appears to be somewhere other than you originally
suggested, since the code you originally posted didn't IIRC, contain any
reference to Raw_packet_queue[0][0][1], while the traceback specifically
points to such a reference as the cause of the problem.
If Kent Johnson is wrong about the cause of the problem then please get
back to the list. And think about refactoring the code to avoid all
those lists and tuples - they don't appear to be the appropriate
structures for optimum readability!
regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/
More information about the Python-list
mailing list