summaryrefslogtreecommitdiff
path: root/examples/quickstart/write_file.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/quickstart/write_file.py')
-rw-r--r--examples/quickstart/write_file.py14
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()