I'm trying to do the following:
import sys; sys.path.append('/var/www/python/includes')
import functionname
x = 'testarg'
fn = "functionname"
func = getattr(fn, fn)
func (x)
but am getting an error:
"TypeError: getattr(): attribute name must be string"
I have tried this before calling getattr but it still doesn't work:
str(fn)
I don't understand why this is happening, any advice is appreciated
getattrshould be an objectgetattr(x, fn)wherexis anything at all (that doesn't produce aSyntaxError;-) andfnis a string, will not produce the error you report. So, we know that's not what you're doing. It remains for you to show us what you are doing, in a version as simplified as you can make it and still reproduce that exact error message -- iffnis the second argument, I can tell you confidently that it cannot possibly be a string, but I can't guess how exactly you bungled things w/o seeing some code of yours;-).imports are totally irrelevant: the two lines that assignfnand callgetattr, if right next to each other, cannot possibly produce the error you say they produce.