# the code that depicts issuse posted on StackOverflow # http://stackoverflow.com/questions/23599457/how-to-parse-an-email-in-python-without-closing-the-file from email.parser import BytesParser, Parser from io import StringIO, TextIOWrapper f = open('mail.eml', 'r') #change to 'rb' for BytesParser def parsefromfile(f, headersonly=None): info_msg = "Type of f is now: {}, the id is: {}." f.seek(0) msg = Parser().parse(f,headersonly) #BytesParser make the code fail on the next f.seek print(msg) print(msg.get('date', None)) f.seek(0) print(f.read()) parsefromfile(f)