Is it safe to use the expression "from copy copy copy" in Python?

Python has a complex namespace and modules, so I'm not sure about that. Usually the python module and something that is imported from it have different names or only the module is imported, and the content is used with the full name:

 import copy # will use copy.copy from time import localtime # "localtime" has different name from "time". 

But what if the module has the same name as what I import from it? For instance:

 from copy import copy copy( "something" ) 

It is safe? Maybe these are some complex consequences that I do not see?

+4
source share
1 answer

From PEP8 ( http://www.python.org/dev/peps/pep-0008/#imports ):

When importing a class from a module containing a class, this is usually normal:

 from myclass import MyClass from foo.bar.yourclass import YourClass 

If this spelling causes local name conflicts, write them down

 import myclass import foo.bar.yourclass 

and use "myclass.MyClass" and "foo.bar.yourclass.YourClass".

+4
source

All Articles