0

in C# nameof(variable) returns "variable"

cant i do something like this in python?

class ClassName:
   someVariable = "im in love with a coco"

if its a class, i can use ClassName.__name__ and this will return

"ClassName"

but what if ClassName.someVariable.__name__

it will raise an error

AttributeError: 'str' object has no attribute '__name__'

how to get "someVariable"?

what code does the same as nameof() in python?

Tseng
  • 61,549
  • 15
  • 193
  • 205
softmarshmallow
  • 1,034
  • 2
  • 16
  • 31

0 Answers0