0

I'm reading a pcap file using the rdpcap function:

s = rdpcap(pcap)

I'd like to know how to reverse s: it should be a list, but I tried with:

rev_s = s.reverse()

and it doesn't work: it gives me the SyntaxError: invalid syntax error.

Can anyone help me, please?

Piotr Kula
  • 9,597
  • 8
  • 59
  • 85
auino
  • 1,644
  • 5
  • 23
  • 43
  • It gives me ``. I found a syntax error, but now, it gives me this error: Traceback (most recent call last): File "myscript.py", line 100, in myfunction for pkt in s.reverse(): TypeError: 'NoneType' object is not iterable I know that `s` is not `None`. – auino May 23 '12 at 08:56
  • `s = None` hence the TypeError you're getting. If `s` was a string you could use `.reverse()` or `[::-1]` to step it backwards. I'd recommend loading up a file that contains data, then doing a `dir(var_name)` on it to see what functions it supports. – Christian Witts May 23 '12 at 09:08
  • As what you're trying to achieve works just fine (cf. my answer below), you have other mistakes in your code. If you do not mange to resolve them by yourself, you can show more code in your question. – Dr. Jan-Philip Gehrcke May 23 '12 at 09:14

1 Answers1

1

For me, this works:

>>> a = rdpcap("test.pcap")
>>> b = a.reverse()
>>> c = a[::-1]

(you can also use the slice notation to create a reversed copy of the list)

Dr. Jan-Philip Gehrcke
  • 33,287
  • 14
  • 85
  • 130