Question: In this code with pyshark

```
import pyshark
cap = pyshark.FileCapture(filename)
i = 0
for idx, packet in enumerate(cap):
    i += 1
print i
print len(cap._packets)

```

`i` and `len(cap._packets)` give two different results. Why is that?

Answer: 
Don't know if it works in Python 2.7, but in Python 3.4 `len(cap)` returns 0.
The FileCapture object is a generator, so what worked for me is `len([packet for packet in cap])`
Just adding another way using callback function. Also little bit faster approach.

```
length = 0 
def count_callback(pkt):
    global length
    length = length + 1

cap.apply_on_packets(count_callback)

print(length)

```