def __exit__(self, type, value, traceback):
    if self.file is not sys.stdin:
        self.file.close()

def __getattr__(self, name):
    return getattr(self.file, name)
Python use lxml with fileinput