In PHP, I can do the following:
$myVar = 'name'; print $myClass->$myVar; // Identical to $myClass->name
I want to do this in Python, but can't find out how
In python, this is a built-in getattr function.
class Something( object ): def __init__( self ): self.a= 2 self.b= 3 x= Something() getattr( x, 'a' ) getattr( x, 'b' )
You want to use the built-in getattr function.
myvar = 'name' //both should produce the same results value = obj.name value = getattr(obj, myvar)
Source: https://habr.com/ru/post/1702873/More articles:Failed to load link library - visual-studioMicrosoft Visual Studio License - licensingf # - loop through an array - f #Как я могу обновить код контроллера просмотра, когда он попадает в верхнюю часть стека представлений? - iphoneAutomatic variable replacement #defines - c32-bit build server and 64-bit production server for .NET Web Apps - .netHow to embed a gem in a RubyCocoa application? - ruby | fooobar.comDynamic Security - securityCSS opacity in image - csshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1702878/what-are-some-programming-techniques-for-converting-sd-images-to-hd-images&usg=ALkJrhg4mTecbmSYO1rcfQjg0XKFG6fZ_QAll Articles