mirror of
https://github.com/python/cpython.git
synced 2024-12-02 22:35:26 +08:00
fix bug in example (should close file at all times)
This commit is contained in:
parent
6b686e94a1
commit
d6ac380d39
@ -158,7 +158,7 @@ def __import__(name, globals=None, locals=None, fromlist=None):
|
|||||||
fp, pathname, (suffix, mode, type) = imp.find_module(name)
|
fp, pathname, (suffix, mode, type) = imp.find_module(name)
|
||||||
|
|
||||||
# See what we got.
|
# See what we got.
|
||||||
# Note that fp will be closed automatically when we return.
|
try:
|
||||||
if type == imp.C_EXTENSION:
|
if type == imp.C_EXTENSION:
|
||||||
return imp.load_dynamic(name, pathname)
|
return imp.load_dynamic(name, pathname)
|
||||||
if type == imp.PY_SOURCE:
|
if type == imp.PY_SOURCE:
|
||||||
@ -168,4 +168,7 @@ def __import__(name, globals=None, locals=None, fromlist=None):
|
|||||||
|
|
||||||
# Shouldn't get here at all.
|
# Shouldn't get here at all.
|
||||||
raise ImportError, '%s: unknown module type (%d)' % (name, type)
|
raise ImportError, '%s: unknown module type (%d)' % (name, type)
|
||||||
|
finally:
|
||||||
|
# Since we may exit via an exception, close fp explicitly.
|
||||||
|
fp.close()
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
@ -158,7 +158,7 @@ def __import__(name, globals=None, locals=None, fromlist=None):
|
|||||||
fp, pathname, (suffix, mode, type) = imp.find_module(name)
|
fp, pathname, (suffix, mode, type) = imp.find_module(name)
|
||||||
|
|
||||||
# See what we got.
|
# See what we got.
|
||||||
# Note that fp will be closed automatically when we return.
|
try:
|
||||||
if type == imp.C_EXTENSION:
|
if type == imp.C_EXTENSION:
|
||||||
return imp.load_dynamic(name, pathname)
|
return imp.load_dynamic(name, pathname)
|
||||||
if type == imp.PY_SOURCE:
|
if type == imp.PY_SOURCE:
|
||||||
@ -168,4 +168,7 @@ def __import__(name, globals=None, locals=None, fromlist=None):
|
|||||||
|
|
||||||
# Shouldn't get here at all.
|
# Shouldn't get here at all.
|
||||||
raise ImportError, '%s: unknown module type (%d)' % (name, type)
|
raise ImportError, '%s: unknown module type (%d)' % (name, type)
|
||||||
|
finally:
|
||||||
|
# Since we may exit via an exception, close fp explicitly.
|
||||||
|
fp.close()
|
||||||
\end{verbatim}
|
\end{verbatim}
|
||||||
|
Loading…
Reference in New Issue
Block a user