Skip to content

Instantly share code, notes, and snippets.

@markqiu
Created December 18, 2016 11:38
Show Gist options
  • Save markqiu/59af9f88e3e1da5fe927f32fab5bbff6 to your computer and use it in GitHub Desktop.
Save markqiu/59af9f88e3e1da5fe927f32fab5bbff6 to your computer and use it in GitHub Desktop.
# somewhere to store output
err = StringIO.StringIO()
# save a reference to real stderr so we can restore later
oldstderr = sys.stderr
# set stderr to our StringIO instance
sys.stderr = err
tp = pd.read_csv(f_in, sep=',', chunksize=1000, encoding='utf-8',quotechar='"', error_bad_lines=False)
for chunk in tp:
chunk
# restore stderr
sys.stderr = oldstderr
# print(or use) the stored value from previous print
print err.len + 'lines skipped.'
print err.getvalue()
err.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment