Confused with module and .py files
Roel Schroeven
rschroev_nospam_ml at fastmail.fm
Wed Oct 5 04:52:17 EDT 2005
Iyer, Prasad C wrote:
> Actually I am bit confused between the modules and .py file
> How do I differentiate between the 2.
>
> For example
> I have a file import1.py, import2.py file
> Which has few functions and classes
> And if I have a class with same name "BaseClass" in both the file
>
> How would I use it if I declare it as given below in my 3rd class
>
> from import1.py import *
> from import2.py import *
Name conflicts like that are a good reason not to use from ... import *,
but instead:
import import1
import import2
bc1 = import1.BaseClass()
bc2 = import2.BaseClass()
(Note: don't include the extension .py in the import statements)
Namespaces are great for preventing name conflicts; don't circumtvent
them by blindly importing everything into the same namespace. As the Zen
of Python says: "Namespaces are one honking great idea -- let's do more
of those!"
--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton
Roel Schroeven
More information about the Python-list
mailing list