On Thu, Nov 2, 2017 at 8:02 AM, Ben Bacarisse <ben.use...@bsb.me.uk> wrote: > r...@zedat.fu-berlin.de (Stefan Ram) writes: > >> Wolfgang Maier <wolfgang.ma...@biologie.uni-freiburg.de> writes: >>>If you're worried bout having things on separate lines, you could write: >>>import os; os.getcwd() >>>,etc., which is actually saving a few characters :) >> >> Yes, but there still is the risk of the identifier »os« >> already being used in the sorrounding code. While >> >> __import__( "os" ).getcwd() >> >> does not seem to "leak" names into the enclosing scope. > > Also it's an expression which may be important in your "quick and dirty" > scripts.
If your quick-and-dirties are needing these kinds of imports all the time, the best solution might be to slap something into site.py that "pre-imports" those into the builtins. Then you can just use os.getcwd() without worrying about the import, and without calling a dunder. ChrisA -- https://mail.python.org/mailman/listinfo/python-list