I have the following project structure:
main.py
utils
----hudi.py
project
----stage.py
The main file will create an instance of the class in stage.py, that will create an instance of the hudi utils class. What I want is to set some attributes of Stage class as default values of the Hudi class.
The code of hudi.py is
class Hudi:
def __init__(self, spark):
self.spark = spark
def test_hudi(self):
print(self.spark)
My stage.py code is:
from utils.hudi import Hudi
class Stage:
def __init__(self):
self.spark="spark"
def a(self):
hudi = Hudi(spark=self.spark)
hudi.test_hudi()
Reading the answer https://stackoverflow.com/a/15189304/9621172 I have tried with the following code:
class Hudi:
def __init__(self, spark=None):
self.spark = spark or self.spark
def test_hudi(self):
print(self.spark)
from utils.hudi import Hudi
class Stage:
def __init__(self):
self.spark="spark"
def a(self):
hudi = Hudi()
hudi.test_hudi()
This way I expected that self.spark will be "transfered" to Hudi class without having to explicitly pass it (let's say that I want Hudi.spark = Stage.spark), but I get the error AttributeError: 'Hudi' object has no attribute 'spark'. What I want is even possible?