pyt...@bdurham.com wrote:
> Peter,
>
>> Another eval-free variant:
>>
>> [x() for x in vars().values() if hasattr(x, "_included")]
>>
>> If you use getattr(x, "_included", False) instead of hasattr()
>> you can "un-include" functions with ...
>
> YES! That's what I was struggling to do with my
Peter,
> Another eval-free variant:
>
> [x() for x in vars().values() if hasattr(x, "_included")]
>
> If you use getattr(x, "_included", False) instead of hasattr()
> you can "un-include" functions with ...
YES! That's what I was struggling to do with my in-elegant use of
eval(), eg. replacing
pyt...@bdurham.com wrote:
> For completeness, here is the corrected version of my original code for
> the archives:
>
> [ eval(x)() for x in dir() if hasattr( eval(x), '_included') ]
Another eval-free variant:
[x() for x in vars().values() if hasattr(x, "_included")]
If you use getattr(x, "_in
Scott,
Thank you for your example - very clean.
For completeness, here is the corrected version of my original code for
the archives:
[ eval(x)() for x in dir() if hasattr( eval(x), '_included') ]
Regards,
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list
"D'Arcy J.M. Cain" writes:
> On 17 Apr 2009 07:03:18 -0700
> a...@pythoncraft.com (Aahz) wrote:
>> Go to all that trouble, you might as well make it easier:
>>
>> for func in funclist:
>> func()
>
> And if you need the return values:
>
> retlist = [func() for func in funclist]
And if yo
pyt...@bdurham.com wrote:
Scott,
Newbie question (and I'm not the OP): What are your thoughts on having
your decorator add an attribute to the functions vs. placing the
functions in a global variable?
def _included(f):
f._included = True
return f
I tried experimenting with this techniq
Scott,
Newbie question (and I'm not the OP): What are your thoughts on having
your decorator add an attribute to the functions vs. placing the
functions in a global variable?
def _included(f):
f._included = True
return f
I tried experimenting with this technique, but could not find a way
gitulyar wrote:
On Apr 17, 5:23 pm, Scott David Daniels wrote:
Marco Mariani wrote:
Piet van Oostrum wrote:
funclist = [func01, func02, func03, ... ]
for i in range(1,n):
funclist[i]()
Or myscript.funclist[i]() from another module.
...
For example, you could do it like:
funclist = [
On 17 Apr 2009 07:03:18 -0700
a...@pythoncraft.com (Aahz) wrote:
> Go to all that trouble, you might as well make it easier:
>
> for func in funclist:
> func()
And if you need the return values:
retlist = [func() for func in funclist]
--
D'Arcy J.M. Cain | Democracy is three
On 17 Apr 2009 07:03:18 -0700, Aahz wrote:
> In article , Piet van Oostrum wrote:
>>
>>funclist = [func01, func02, func03, ... ]
>>for i in range(1,n):
>>funclist[i]()
>
> Go to all that trouble, you might as well make it easier:
>
> for func in funclist:
> func()
Yes. Especially because
On Apr 17, 5:23 pm, Scott David Daniels wrote:
> Marco Mariani wrote:
> > Piet van Oostrum wrote:
>
> >> funclist = [func01, func02, func03, ... ]
> >> for i in range(1,n):
> >> funclist[i]()
>
> >> Or myscript.funclist[i]() from another module.
>
> > Ehm, calling a bazillion things in the rig
Marco Mariani wrote:
Piet van Oostrum wrote:
funclist = [func01, func02, func03, ... ]
for i in range(1,n):
funclist[i]()
Or myscript.funclist[i]() from another module.
Ehm, calling a bazillion things in the right order should be a
responsibility of the myscript module anyway.
For ex
In article , Piet van Oostrum wrote:
>
>Others have suggested getattr. I think a cleaner (more pythonic) way
>would be:
>
>funclist = [func01, func02, func03, ... ]
>for i in range(1,n):
>funclist[i]()
Go to all that trouble, you might as well make it easier:
for func in funclist:
func
Piet van Oostrum wrote:
funclist = [func01, func02, func03, ... ]
for i in range(1,n):
funclist[i]()
Or myscript.funclist[i]() from another module.
Ehm, calling a bazillion things in the right order should be a
responsibility of the myscript module anyway.
--
http://mail.python.org/mai
> "Stefano" (S) wrote:
>S> I have a script like this
>S> myscript.py
>S>def func01()
>S>def func02()
>S>def func03()
>S>
>S>def funcnn()
>S> How can i execute my func in the code ?
>S> import myscript
>S> for i in range(1,n):
>S>myscript.func??
Others have sugg
On Apr 17, 5:00 pm, "Stefano" wrote:
> How can i execute my func in the code ?
>
> import myscript
> for i in range(1,n):
> myscript.func??
for i in range(1,n):
getattr(myscript, 'func%d' % i)()
--
http://mail.python.org/mailman/listinfo/python-list
Stefano wrote:
> I have a script like this
>
> myscript.py
>
> def func01()
> def func02()
> def func03()
>
> def funcnn()
>
> How can i execute my func in the code ?
>
> import myscript
> for i in range(1,n):
getattr(myscript, "func%02d" % i)()
--
http://mail.p
On Fri, Apr 17, 2009 at 12:00 AM, Stefano wrote:
> I have a script like this
>
> myscript.py
>
> def func01()
> def func02()
> def func03()
>
> def funcnn()
>
> How can i execute my func in the code ?
>
> import myscript
> for i in range(1,n):
> myscript.func??
getattr(myscrip
18 matches
Mail list logo