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
  • 57,187
  • 13
  • 181
  • 194
softmarshmallow
  • 883
  • 2
  • 12
  • 29

0 Answers0