Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refer to class variable in another class variable definition

Tags:

python

class SomeClass:
    SOME_CONST = "hello"
    SOME_OTHER_CONST = SomeClass.SOME_CONST + " world"

This doesn't work.

NameError: name 'SomeClass' is not defined

Is there any way to refer to the class within the class?

like image 943
Aram Kocharyan Avatar asked Apr 06 '12 05:04

Aram Kocharyan


1 Answers

You don't need the class name

class SomeClass:
   SOME_CONST = "hello"
   SOME_OTHER_CONST = SOME_CONST + " world"
like image 125
Anthony Kong Avatar answered Oct 21 '22 07:10

Anthony Kong