python use the string as not string -


i url this

response.url 

i more date response.

i wonder if there way in can pass things want , use in response this:

x = 'url' return response.x 

you can use getattr:

x = "url" return getattr(response, x) 

from docs:

getattr(object, name[, default])

return value of named attribute of object. name must string. if string name of 1 of object’s attributes, result value of attribute. example, getattr(x, 'foobar') equivalent x.foobar. if named attribute not exist, default returned if provided, otherwise attributeerror raised.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -