How pass an argument as method of a module?

I would recommend against passing method names around in strings if you can avoid it (pass a reference to the method itself instead), but if you can't, what you want is getattr() a function that gets an attribute of an object by a name contained in a string. This will let you get a reference to the desired method, and then you can call it as usual.

Up vote 0 down vote favorite share g+ share fb share tw.

More','arguments',a=1,b=2) but append is a method(function) of pyquery module so arg0 is my method I want make e. Arg0('') run like e. Append('') -- so I want pass "append" as argument import pyquery d = pq('') d.

Append('') str(d) def f (*arg,**kargs): e = pq('') e. Arg0('') # ' python argument-passing link|improve this question edited Feb 18 '11 at 17:23 asked Feb 18 '11 at 16:53macm344.

3 Your question is not clear. Can you rephrase and add more context? – Joe Holloway Feb 18 '11 at 16:55 Could you rephrase your question to slow clearly: (1) What pyquery does, (2) how you're trying to use it, and (3) why you're trying to use it that way?

– Karmastan Feb 18 '11 at 17:09 There is nothing about pyquery. It is about pass argument and use this argument as a method of a module. So d.

Append('') works fine ok, but now I want pass 'append' to a function f() like f('append') ok, My function f() instance a module like e = pq('') and now I want use arg0 {could be (append, after, before, appendTo, clone..)} in e. Arg0('...') like e. Append('...'), so I want e.

Arg0('..') run like e. Append('...') – macm Feb 18 '11 at 17:22.

I would recommend against passing method names around in strings if you can avoid it (pass a reference to the method itself instead), but if you can't, what you want is getattr(), a function that gets an attribute of an object by a name contained in a string. This will let you get a reference to the desired method, and then you can call it as usual. Def f (*arg, **kargs): e = pq('') getattr(e, arg0)('') return str(e).

Yes, thanks. Works fine. Sorry I cant vote, every question I make I loose points.

:( – macm Feb 18 '11 at 17:32 You should still be able to accept an answer. – kindall Feb 18 '11 at 19:11.

Pass d. Append as the first argument. Functions are first class objects!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions