How to resolve module name conflicts during python program writing?

If you have two modules with the same name, you can only import one of them - by default, Python will always choose the leftmost one in the module search path sys.path item. This isn't a problem if your preferred module is in the same directory as the top-level script; since the top-level script's home directory is always the first item in the module search path, its contents are always automatically located first. However, for cross-directory imports, the linear nature of the module search path means that files with the same name will conflict.

To fix this conflict, either avoid files with the same name. If you need to access two files with the same name at the same time, then put the two source files into subdirectories respectively, so that the package import directory name will make the module reference unique. As long as the surrounding package directory names are unique, you can access either, or both, modules of the same name. Note that this problem can also occur if you accidentally use a name for your module that happens to be the same name as a standard library module you need to use. This is because local modules in the program's home directory (or another directory earlier in the module path) will hide and replace standard library modules. To fix this override, either avoid using the same name as another module you need, or put the module into a package directory and use Python 3. is an optional feature). Under the package relative import model, normal import will skip the package directory, so you can get the standard library version, but if necessary, special dot-starting import statements can still select the local version of the module with the same name.