Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Use namedtuples in SndRcvList() #2746

Closed
guedou opened this issue Aug 3, 2020 · 1 comment
Closed

[Proposal] Use namedtuples in SndRcvList() #2746

guedou opened this issue Aug 3, 2020 · 1 comment

Comments

@guedou
Copy link
Member

guedou commented Aug 3, 2020

While teaching Scapy, I realized that it is difficult to understand which indices to use to iterate a response of type SndRcvList().

For example, to display the first answer, a user must do:

>>> r, u = sr(IP(dst="8.8.8.8") / ICMP())
>>> r[0][1]

Beginners might do the following, which is more complex to understand:

>>> r = sr(IP(dst="8.8.8.8") / ICMP())
>>> r[0][0][1]

Using a namedtuple instead of a tuple in SndRcvList(), it is possible to simplify the access to the answer with .answer while maintaining [1] for backward compatibility:

>>> r, u = sr(IP(dst="8.8.8.8") / ICMP()
>>> r[0].answer == r[0][1]

Do you think that this feature is interesting?

@guedou guedou self-assigned this Aug 3, 2020
@gpotter2
Copy link
Member

gpotter2 commented Aug 8, 2020

This sounds super reasonable, LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants