<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Il 04/06/2013 17:03, Federico Figus ha scritto:
    <blockquote
cite="mid:CAPoBHvEmWsOh=c4iSDr=0LPaL0AXHTTSufAvgRHvOxuFr073zA@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div>
                    <div>
                      <div>
                        <div>
                          <div>Ciao,<br>
                            <br>
                          </div>
                          l'override dell'istruzione print non è
                          possibile in python 2.x, ma lo è in python
                          3.x.<br>
                        </div>
                        Per aggirare il problema potresti definire un
                        file-like object che possieda almeno il metodo
                        write, al cui interno ci implementi la logica di
                        scritura, ad esempio:<br>
                        <br>
                      </div>
                      <div><span style="font-family:courier
                          new,monospace">import sys</span><br>
                      </div>
                      <div><span style="font-family:courier
                          new,monospace">_stdout = sys.stdout</span><br>
                      </div>
                      <div><br>
                      </div>
                      <font face="courier new,monospace">class
                        FaskeStdout</font>(<font face="courier
                        new,monospace">object):<br>
                        <br>
                      </font>
                      <div style="margin-left:40px"><font face="courier
                          new,monospace">can_write = 1</font><br>
                      </div>
                      <div style="margin-left:40px"><br>
                      </div>
                      <div style="margin-left:40px"><font face="courier
                          new,monospace">def write(</font>self, data):<br>
                      </div>
                      <div style="margin-left:80px"><font face="courier
                          new,monospace">if self.can_write:<br>
                        </font></div>
                      <div style="margin-left:80px">
                        <div style="margin-left:40px"><font
                            face="courier new,monospace">_stdout.write(data)<br>
                          </font></div>
                      </div>
                      <br>
                    </div>
                    <span style="font-family:courier new,monospace">sys.stdout
                      = FakeStdout()</span><br>
                    <br>
                  </div>
                  <font face="courier new,monospace">print "stampa sullo
                    stdout"<br>
                  </font></div>
                <font face="courier new,monospace">sys.stdout.can_write
                  = 0<br>
                </font></div>
              <font face="courier new,monospace">print "non stampa sullo
                stdout"<br>
                <br>
              </font></div>
            <font face="courier new,monospace"><font
                face="arial,helvetica,sans-serif">La seconda soluzione
                sarebbe creare la tua funzione print con un alias (e.g.
                <span style="font-family:courier new,monospace">print_log()</span>)
                e modidicare tutto il codice con un semplice
                find&replace, così potrai controllare la meglio
                tutta questa parte in futuro.</font><br>
            </font></div>
        </div>
      </div>
    </blockquote>
    ho pensato a fare un overloading perchè non e' semplice cambiare
    tutti i print con un find&replace.<br>
    la riga <br>
    <blockquote>print "ciao mondo"<br>
    </blockquote>
    dovrebbe diventare<br>
    <blockquote>print_log("ciao mondo")<br>
    </blockquote>
    e l'ultima parentesi tonda chiusa non saprei proprio come
    inserirla...<br>
    Con il file-like object del print ha funzionato, adesso ho un flag
    che funziona così:<br>
    <blockquote>if not flag:<br>
          print "Verbose is OFF!!!"<br>
          from overloadprint import *<br>
          sys.stdout=OverloadPrint()<br>
    </blockquote>
    <br>
    dove overloading.py contiene il codice:<br>
    <blockquote>class OverloadPrint():<br>
          def write(self, text):<br>
              pass<br>
    </blockquote>
    <blockquote
cite="mid:CAPoBHvEmWsOh=c4iSDr=0LPaL0AXHTTSufAvgRHvOxuFr073zA@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div><font face="courier new,monospace">
              <span style="font-family:arial,helvetica,sans-serif"><br>
              </span></font></div>
          <span style="font-family:arial,helvetica,sans-serif">Saluti,<br>
          </span></div>
        <font face="courier new,monospace"><span
            style="font-family:arial,helvetica,sans-serif">Federico F.</span></font><br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Python mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Python@lists.python.it">Python@lists.python.it</a>
<a class="moz-txt-link-freetext" href="http://lists.python.it/mailman/listinfo/python">http://lists.python.it/mailman/listinfo/python</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>