summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-07-07 23:01:27 (GMT)
committerGuido van Rossum <guido@python.org>1995-07-07 23:01:27 (GMT)
commitd6ac380d394771a8c72e42a8c1443b2151718d62 (patch)
tree3d49698f1f40ba7a374e33f39d5eeb48c2161868 /Doc
parent6b686e94a1b752efaa471266047d6fdc2d12a5d9 (diff)
downloadcpython-d6ac380d394771a8c72e42a8c1443b2151718d62.zip
cpython-d6ac380d394771a8c72e42a8c1443b2151718d62.tar.gz
cpython-d6ac380d394771a8c72e42a8c1443b2151718d62.tar.bz2
fix bug in example (should close file at all times)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/lib/libimp.tex23
-rw-r--r--Doc/libimp.tex23
2 files changed, 26 insertions, 20 deletions
diff --git a/Doc/lib/libimp.tex b/Doc/lib/libimp.tex
index 2e72602..4456814 100644
--- a/Doc/lib/libimp.tex
+++ b/Doc/lib/libimp.tex
@@ -158,14 +158,17 @@ def __import__(name, globals=None, locals=None, fromlist=None):
fp, pathname, (suffix, mode, type) = imp.find_module(name)
# See what we got.
- # Note that fp will be closed automatically when we return.
- if type == imp.C_EXTENSION:
- return imp.load_dynamic(name, pathname)
- if type == imp.PY_SOURCE:
- return imp.load_source(name, pathname, fp)
- if type == imp.PY_COMPILED:
- return imp.load_compiled(name, pathname, fp)
-
- # Shouldn't get here at all.
- raise ImportError, '%s: unknown module type (%d)' % (name, type)
+ try:
+ if type == imp.C_EXTENSION:
+ return imp.load_dynamic(name, pathname)
+ if type == imp.PY_SOURCE:
+ return imp.load_source(name, pathname, fp)
+ if type == imp.PY_COMPILED:
+ return imp.load_compiled(name, pathname, fp)
+
+ # Shouldn't get here at all.
+ raise ImportError, '%s: unknown module type (%d)' % (name, type)
+ finally:
+ # Since we may exit via an exception, close fp explicitly.
+ fp.close()
\end{verbatim}
diff --git a/Doc/libimp.tex b/Doc/libimp.tex
index 2e72602..4456814 100644
--- a/Doc/libimp.tex
+++ b/Doc/libimp.tex
@@ -158,14 +158,17 @@ def __import__(name, globals=None, locals=None, fromlist=None):
fp, pathname, (suffix, mode, type) = imp.find_module(name)
# See what we got.
- # Note that fp will be closed automatically when we return.
- if type == imp.C_EXTENSION:
- return imp.load_dynamic(name, pathname)
- if type == imp.PY_SOURCE:
- return imp.load_source(name, pathname, fp)
- if type == imp.PY_COMPILED:
- return imp.load_compiled(name, pathname, fp)
-
- # Shouldn't get here at all.
- raise ImportError, '%s: unknown module type (%d)' % (name, type)
+ try:
+ if type == imp.C_EXTENSION:
+ return imp.load_dynamic(name, pathname)
+ if type == imp.PY_SOURCE:
+ return imp.load_source(name, pathname, fp)
+ if type == imp.PY_COMPILED:
+ return imp.load_compiled(name, pathname, fp)
+
+ # Shouldn't get here at all.
+ raise ImportError, '%s: unknown module type (%d)' % (name, type)
+ finally:
+ # Since we may exit via an exception, close fp explicitly.
+ fp.close()
\end{verbatim}