I have a module defined with a class and a few functions. I am trying to import this module in my main script that also has a class defined with the same name. The main functions constructs a json with a 'Header' and a 'Body' and calls a function that returns it's 'Header' and a 'Body' as a json.
Main:
import myModule
class Header:
def __init__(self, ID: str, DateTime: str, DSTFlag: str, IPAddr: str):
self.ID = ID
self.DateTime=DateTime
self.DSTFlag=DSTFlag
self.IPAddr=IPAddr
myModule.py:
class Header:
def __init__(self, Id=None, DateTime=None, DSTFlag=None):
self.Id = Id
self.DateTime = DateTime
self.DSTFlag = DSTFlag
Can I still import myModule into my main script without class name clash? Is each one defined in it's own namespace?
According to https://docs.python.org/3/tutorial/modules.html
"Each module has its own private namespace, which is used as the global namespace by all functions defined in the module. Thus, the author of a module can use global variables in the module without worrying about accidental clashes with a user’s global variables."
I'm not clear on this. Any help is appreciated.