Re: script question

2009-04-18 Thread Peter Otten
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

Re: script question

2009-04-17 Thread python
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

Re: script question

2009-04-17 Thread Peter Otten
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

Re: script question

2009-04-17 Thread python
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

Re: script question

2009-04-17 Thread Arnaud Delobelle
"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

Re: script question

2009-04-17 Thread Scott David Daniels
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

Re: script question

2009-04-17 Thread python
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

Re: script question

2009-04-17 Thread Scott David Daniels
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 = [

Re: script question

2009-04-17 Thread D'Arcy J.M. Cain
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

Re: script question

2009-04-17 Thread Peter Pearson
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

Re: script question

2009-04-17 Thread gitulyar
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

Re: script question

2009-04-17 Thread Scott David Daniels
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

Re: script question

2009-04-17 Thread Aahz
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

Re: script question

2009-04-17 Thread Marco Mariani
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

Re: script question

2009-04-17 Thread Piet van Oostrum
> "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

Re: script question

2009-04-17 Thread alex23
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

Re: script question

2009-04-17 Thread Peter Otten
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

Re: script question

2009-04-17 Thread Chris Rebert
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