Well, you can't keep Python from _executing_ the print statements, but
you can keep it from displaying the results.
Any python object which has a "write" method can be used as target for
the "print" statement, so...
<code>
def test(n):
    for i in range(n):
        print 'I is =', i

class blackHole(object):
    def write(self,*args):
        pass

import sys
test(3)
sys.stdout = blackHole()
test(100)
print >> sys.stderr, 'It worked!'
</code>
--
Error messages (which are send to sys.stderr rather than sys.stdout)
will still display normally.
Vernon Cole


On Thu, Jan 8, 2009 at 11:12 AM, Nalli Dinesh <nalli.din...@gmail.com> wrote:
> Thanks Vernon, Jim, Micheal.
>
> I kind of knew the different ways of modelling any python application as you
> guys have described in your email. I appreciate your inputs though. But I am
> looking for a different solution.
>
> Here is what I am looking at -
>
> I do not want to remodel my application at this stage. I have print
> statements all over the place. I looking at a solution where, without
> touching the print statements at all, I want to tell the python interpreter
> to not execute print statements inside my application, when the application
> is running. Like, is there a way to tell the Python interpreter do not
> bother to execute print lines in my application. Or is there a way to just
> define a python builtin variable which dictates executing print statements
> or not.
>
> Hope I am able to describe clearly what solution I am looking for.
>
> To my understanding, I do not think any language supports stuff like this.
> If I am right about it, then we all know to what level of growth all the s/w
> languages must grow too!!!!
>
> On Thu, Jan 8, 2009 at 8:02 AM, Vernon Cole <vernondc...@gmail.com> wrote:
>>
>> How about --
>>  if debug: print x
>> or, in a more complex setting, have a "verbose" attribute in each module
>> and --
>>  if self.verbose > 2: print x   # so you can have levels of debug
>> printouts
>> ??
>> --
>> Vernon Cole
>>
>> On Wed, Jan 7, 2009 at 11:30 PM, Michel Claveau <m...@mclaveau.com> wrote:
>> > Hi!
>> >
>> > 1) Define your print function. Example:
>> >   def mprint(*par):
>> >       for i in par:
>> >           print i,
>> >       print
>> >
>> > 2) in your code, replace all  'print'  by  'mprint'
>> >
>> > 3) when you want cancel the print, modify only the mprint function.
>> >
>> > @-salutations
>> > --
>> > Michel Claveau
>> > _______________________________________________
>> > python-win32 mailing list
>> > python-win32@python.org
>> > http://mail.python.org/mailman/listinfo/python-win32
>> >
>> _______________________________________________
>> python-win32 mailing list
>> python-win32@python.org
>> http://mail.python.org/mailman/listinfo/python-win32
>
>
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to