diff options
author | Oleg Pudeyev <oleg@bsdpower.com> | 2014-06-03 22:47:57 -0400 |
---|---|---|
committer | Oleg Pudeyev <oleg@bsdpower.com> | 2014-06-24 21:56:46 -0400 |
commit | 178aeb9c8f7e4cb314407d106916dce1a70b7d6f (patch) | |
tree | 01ccc06b31309ea3dee89931b7759c6d51ec8876 /examples | |
parent | a4c19413f5bd27259edf851842dd96e3ca9f685c (diff) | |
download | pycurl-178aeb9c8f7e4cb314407d106916dce1a70b7d6f.tar.gz |
Quickstart - writing to a file
Diffstat (limited to 'examples')
-rw-r--r-- | examples/quickstart/write_file.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/examples/quickstart/write_file.py b/examples/quickstart/write_file.py new file mode 100644 index 0000000..f4f9ee9 --- /dev/null +++ b/examples/quickstart/write_file.py @@ -0,0 +1,14 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# vi:ts=4:et + +import pycurl + +# As long as the file is opened in binary mode, both Python 2 and Python 3 +# can write response body to it without decoding. +with open('out.html', 'wb') as f: + c = pycurl.Curl() + c.setopt(c.URL, 'http://pycurl.sourceforge.net/') + c.setopt(c.WRITEDATA, f) + c.perform() + c.close() |