Fix i/o handling for Python integration