erocarrera / pefile

pefile is a Python module to read and work with PE (Portable Executable) files
MIT License
1.88k stars 521 forks source link

Add support for `with` statement (context handler) #232

Open htgoebel opened 6 years ago

htgoebel commented 6 years ago

Please add __enter__ and __exit__, to be able to write e.g.

with pefile.PE(exenm, fast_load=True) as pe:
    overlay_before = pe.get_overlay()

This may also be used to simplify the internal code.

cicconej commented 6 years ago

@htgoebel - One thing you could consider is:

from contextlib import closing

with closing(pefile.PE(exenm, fast_load=True)) as pe:
    overlay_before = pe.get_overlay()