JokerMartini JokerMartini - 1 year ago 129
Python Question

Python Class Duplication

Is it bad practice to use the same names for classes inside tools that both get executed into the same python environment, simultaneously?

I've created two python widgets as seen in the image below. Each of the widgets contain QTreeViews that use their own custom SortModel.

enter image description here

I was wondering if it's bad practice to name both of the SortModel and MainWindow classes the same between the two files?

Because i later load both files into the same tool as Tabs. I'm starting to get some weird bugs in the program and I have a feeling this may be causing it.

enter image description here

Answer Source

Considering you have to import both classes into the same module namespace, using the same name for distinct classes is more of a bad idea than a bad practice.

The current module will use only one of the classes for all cases where you need one of both; weird results.

However, you can distinguish one from the other at the import level by using the import as feature:

from camera_publish import SortModel as CameraSortModel
from cache_publish import SortModel as CacheSortModel
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download