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

script question

2009-04-17 Thread Stefano
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?? many thanks stefano -- http://mail.python.org/mailman/listinfo/python-list

Re: execute python script question

2008-03-11 Thread Piet van Oostrum
> Gabriel Rossetti <[EMAIL PROTECTED]> (GR) wrote: >GR> not a stupid question, I think that may be it. I tried setting PYTHONPATH >GR> like Sam suggested and it worked, but I was unable to do it programmically. >GR> I tried putting it in the __init__.py file like a web post suggested but it >G

Re: execute python script question

2008-03-11 Thread Gabriel Rossetti
Michael Wieher wrote: > stupid question: you have myPackage somewhere on sys.path? > > I mean, module1.py only knows it lives in a directory, it doesn't know > anything about anything above it. > > > > 2008/3/10, Gabriel Rossetti <[EMAIL PROTECTED] > >: > > Hello, >

Re: execute python script question

2008-03-11 Thread Gabriel Rossetti
Sam wrote: > Hello, > > I may misunderstand your problem, but it may be related to the > execution environment, especially the PYTHONPATH variable. Have a look > at the following log: > > [EMAIL PROTECTED]:/$ pwd > / > [EMAIL PROTECTED]:/$ cat -n /tmp/test_import.py > 1 class A(object): >

Re: execute python script question

2008-03-10 Thread Sam
Hello, I may misunderstand your problem, but it may be related to the execution environment, especially the PYTHONPATH variable. Have a look at the following log: [EMAIL PROTECTED]:/$ pwd / [EMAIL PROTECTED]:/$ cat -n /tmp/test_import.py 1 class A(object): 2 def __init__(self):

execute python script question

2008-03-10 Thread Gabriel Rossetti
Hello, I have been developping something in python that has the following hierarchy : project/src/myPackage/ project/src/myPackage/__init__.py project/src/myPackage/module1.py project/src/myPackage/module2.py project/src/myPackage/test/ project/src/myPackage/test/__init__.py project/src/myPackag

Re: newbee: Simple Backend Python Script Question

2007-09-14 Thread Steve Holden
joe shoemaker wrote: > I need to create python script that is threaded. So the main program > will run in infinite loop and just retrieving messages and putting them > in a queue. (Main thread) > > I need child threads from a pool to process the queue. When there is no > stuff in the queue, the

newbee: Simple Backend Python Script Question

2007-09-14 Thread joe shoemaker
I need to create python script that is threaded. So the main program will run in infinite loop and just retrieving messages and putting them in a queue. (Main thread) I need child threads from a pool to process the queue. When there is no stuff in the queue, they go to the pool and become availabl