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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -