Why is function level import considered bad practice?
Deadlocking on the import lock might be introduced by an innocent code that uses a library with function level imports.
In general globals should be written at a global level.
Re:The Zen of Python by Example
by dustingetz on Friday February 11, 2011 @11:20AM
(#2206844)
#3: `users` is not defined. `sqlalchemy` names are not defined. The file should be opened for writing in the json example.
#5 It is simpler to allow the animal to know its kind:
or just: #6 `elem.xpath('./a/@href')` is simpler than Also `elem.iterlinks()` could be used http://codespeak.net/lxml/lxmlhtml.html#working-with-linksThere is no `lxml.CSSSelector` (python-lxml 2.2.6-1). Use `elem.cssselect`
#7 You don't need to add `ifmain` stub in every module:
# 8 & 9: The first variant of `make_counter()` won't work without `nonlocal i` -- it leads to `UnboundLocalError` otherwise.Despite the fact that it works on my machine on all available Python implementations such code should be avoided:
# 10 & 11: Use stdlib's version: It is a matter of preference but it makes testing more predictable.#13 `__builtins__` is not defined on jython: