• Home
  • Raw
  • Download

Lines Matching +full:bare +full:- +full:os

2   Idioms and Anti-Idioms in Python
25 ---------------------
44 a bad idea. For one, this loses an important property Python otherwise has ---
56 os import *`` is present. The :mod:`os` module has a function called
61 take what you need --- ``from module import name1, name2``, or keep them in the
62 module and access on a per-need basis --- ``import module;print module.name``.
79 -------------------------------------------------------
83 dangerous for the same reasons ``from import *`` is dangerous --- it might step
112 -------------------------------
144 -------
173 .. index:: bare except, except; bare
177 should not normally be caught by user code), using a bare ``except:`` is almost
181 possible for third-party code to raise exceptions that do not inherit from
183 use a bare ``except:`` and manually re-raise the exceptions you don't want
194 The following is a very popular anti-idiom ::
197 if not os.path.exists(file):
203 :func:`os.path.exists` is made and the time :func:`open` is called. In that
206 machine on existent and non-existent files makes it seem bugless, the test
225 However, even this version of :func:`get_status` makes too many assumptions ---
235 your code as you can --- the ones you do use will usually be inside calls which
236 should always succeed, or a catch-all in a main function.
247 But the last version still has a serious problem --- due to implementation
270 A useful module very few people know about is :mod:`os.path`. It always has the
279 return os.path.join(dir, file)
281 More useful functions in :mod:`os.path`: :func:`basename`, :func:`dirname` and
284 There are also many useful built-in functions people seem not to be aware of
298 :func:`long` all accept string arguments and will reject ill-formed strings