diff --git a/files.html b/files.html index 65266d5..4f0071f 100644 --- a/files.html +++ b/files.html @@ -499,6 +499,18 @@ C you@localhost:~/diveintopython3/examples$ cat out.log B +
+

Did you get this error? +

+you@localhost:~/diveintopython3/examples$ python3 stdout.py
+  File "stdout.py", line 15
+    with open('out.log', mode='w', encoding='utf-8') as a_file, RedirectStdoutTo(a_file):
+                                                              ^
+SyntaxError: invalid syntax
+

If so, you’re probably using Python 3.0. You should really upgrade to Python 3.1. +

Python 3.0 supported the with statement, but each statement can only use one context manager. Python 3.1 allows you to chain multiple context managers in a single with statement. +

+

Let’s take the last part first.

print('A')