Kaydet (Commit) d6ac380d authored tarafından Guido van Rossum's avatar Guido van Rossum

fix bug in example (should close file at all times)

üst 6b686e94
......@@ -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}
......@@ -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}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment