Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to use a string variable as a variable name in python

#works only inside classes
name  = 'varname'
value = 'something'

setattr(self, name, value) #equivalent to: self.varname= 'something'

print (self.varname)
#will print 'something'
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #string #variable #variable #python
ADD COMMENT
Topic
Name
4+2 =