Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: Accessing an instance variable using a name containing a variable

in python I'm trying to access a instance variable where I need to use the value of another variable to determine the name: Example Instance Variable: user.remote.directory where it point to the value of 'servername:/mnt/.....' and user portion contains the userid of the user, such as joe.remote.directory

from another class I need to be able to access the joe.remote.directory using a variable that contains the user id of joe. I tried variable.remote.directory but it doesn't work, any suggestions?

like image 358
user1110844 Avatar asked Dec 22 '11 00:12

user1110844


1 Answers

Unsure quite what you want, but I think getattr(obj, 'name') might help. See http://docs.python.org/library/functions.html#getattr

like image 103
Rob Cowie Avatar answered Nov 07 '22 03:11

Rob Cowie