0

This is what my two modules "mod1.py" and "outmod1.py" looks like

--mod1.py

class B:

varb=10

def bkafunc(self):
    print("Mai B class ka func!")

--outmod1.py

from my_package.mod2 import B

class outMod:
    b=B()

    def func_out_mod(self):
        print(b.varb)

om=outMod()
om.func_out_mod()

Error: NameError: name 'b' is not defined. Did you mean: 'B'? ## this is the error im getting

//But when i write the "outmod1.py" code as below it works and prints 10 which is value of 'varb':

from my_package.mod2 import B

class outMod:

     def func_out_mod(self):
          print(B().varb)

om=outMod()

om.func_out_mod()
arin
  • 29
  • 4
  • Does this answer your question? [The pythonic way to access a class attribute within the class](https://stackoverflow.com/questions/50567404/the-pythonic-way-to-access-a-class-attribute-within-the-class) – buran Jun 10 '22 at 07:34
  • Even better reference https://stackoverflow.com/q/25577578/4046632 – buran Jun 10 '22 at 07:35
  • `print(self.b.varb)` – furas Jun 10 '22 at 09:13

0 Answers0