Code Snippets

Chris Angelico rosuav at gmail.com
Wed Nov 1 16:23:33 EDT 2017


On Thu, Nov 2, 2017 at 7:17 AM, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
> Wolfgang Maier <wolfgang.maier at 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.

If you're using the name "os" for something else, you need to be aware
of that anyway. Leaking names of core modules shouldn't normally be a
problem.

ChrisA



More information about the Python-list mailing list