0

I have this sample python 3 code:

class C: a = lambda x: x+1 b = lambda y: a(y)*2 

The class definition happens without any error. But when I attempt to call a class property b (which in turn tries to access a fellow class property a) I get an error:

C.b(1) NameError: name 'a' is not defined 

How can I reference class variables when defining other class variables?

3
  • 3
    b = lambda y: C.a(y)*2 Commented Sep 16, 2018 at 23:26
  • Would C().b(1) work, if there were init? Commented Sep 16, 2018 at 23:28
  • @StephenRauch yup that was it. I was put off from using C.a() b/c my IDE kept red-lining it by saying Undefined variable 'C'. Thanks! Commented Sep 16, 2018 at 23:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.