Re: [Python] script bash-pipe compatibile

2009-10-26 Per discussione Daniele Varrazzo
On Sat, 24 Oct 2009 14:32:38 +0200, Matteo Bertini wrote: > Supponiamo di voler scrivere uno script python che consuma sys.stdin e > scrive su sys.stdout, ad esempio: > > ### > $ cat echo.py > import sys > for line in sys.stdin: > sys.stdout.write(line) > ### > > Purtroppo l'implementazion

Re: [Python] script bash-pipe compatibile

2009-10-24 Per discussione Matteo Bertini
Dopo ulteriori indagini, la cosa sembra legata al http://bugs.python.org/issue1488934 in particolare: ### $ cat produce.py import sys for x in range(400): print 'line '*20 if 'flush' in sys.argv: try: sys.stdout.flush() except IOError: if 'pass' in

Re: [Python] script bash-pipe compatibile

2009-10-24 Per discussione Matteo Bertini
> > 2009/10/24 Manlio Perillo > > Su molti run, a volte ottieni un eccezione. > L'eccezione è causata dal runtime di Python, che chiama il distruttore > di stdout/stderr, il quale a sua volta chiama close che fallisce. > > Il problema è che: > > * non sembra sia possibile evitare che il tracebac

Re: [Python] script bash-pipe compatibile

2009-10-24 Per discussione Manlio Perillo
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Pietro Battiston ha scritto: > [...] > #! /usr/bin/python > > import sys > > while True: > r = sys.stdin.readline() > if not r: > break > try : > sys.stdout.write(r) > except: > brea

Re: [Python] script bash-pipe compatibile

2009-10-24 Per discussione Matteo Bertini
Il 24/10/09 15.33, crap0101 ha scritto: > Ho fatto qualche prova e così dovrebbe funzionare, ma penso anch'io che > la soluzione migliore sia popen > > crap0...@gns01:~/Scrivania$ cat echo2.py > import sys > > def gs (): > for line in sys.stdin: >yield line > > > if __name__ == '__main

Re: [Python] script bash-pipe compatibile

2009-10-24 Per discussione Pietro Battiston
Il giorno sab, 24/10/2009 alle 14.32 +0200, Matteo Bertini ha scritto: > Supponiamo di voler scrivere uno script python che consuma sys.stdin e > scrive su sys.stdout, ad esempio: > > ### > $ cat echo.py > import sys > for line in sys.stdin: > sys.stdout.write(line) > ### > > Purtroppo l'im

Re: [Python] script bash-pipe compatibile

2009-10-24 Per discussione Matteo Bertini
Il 24/10/09 15.45, Manlio Perillo ha scritto: > Matteo Bertini ha scritto: > >> Supponiamo di voler scrivere uno script python che consuma sys.stdin e >> scrive su sys.stdout, ad esempio: >> >> ### >> $ cat echo.py >> import sys >> for line in sys.stdin: >> sys.stdout.write(line) >> ### >

Re: [Python] script bash-pipe compatibile

2009-10-24 Per discussione crap0101
Il giorno sab, 24/10/2009 alle 14.32 +0200, Matteo Bertini ha scritto: > > Ho provato un po' a giocare con try except senza però beccare il punto > giusto... > > Suggerimenti? > Matteo Bertini > > ___ Ho fatto qualche prova e così dovrebbe funzionare, ma penso anch'io che

Re: [Python] script bash-pipe compatibile

2009-10-24 Per discussione Manlio Perillo
Matteo Bertini ha scritto: > Supponiamo di voler scrivere uno script python che consuma sys.stdin e > scrive su sys.stdout, ad esempio: > > ### > $ cat echo.py > import sys > for line in sys.stdin: > sys.stdout.write(line) > ### > > Purtroppo l'implementazione banale non si accoppia bene co

Re: [Python] script bash-pipe compatibile

2009-10-24 Per discussione crap0101
Il giorno sab, 24/10/2009 alle 15.15 +0200, Matteo Bertini ha scritto: > Il 24/10/09 14.43, Giorgio Zoppi ha scritto: > > popen? > > > Non capisco in che modo, non ho sottoprocessi, forse mi sono spiegato male. già... ho inteso male. m. signature.asc Description: Questa è una parte del messa

Re: [Python] script bash-pipe compatibile

2009-10-24 Per discussione Matteo Bertini
Il 24/10/09 14.43, Giorgio Zoppi ha scritto: > popen? > Non capisco in che modo, non ho sottoprocessi, forse mi sono spiegato male. Per essere più specifici, né ciò che sta davanti né ciò che segue echo.py nella pipeline è vincolato ad essere uno script python, immagina pure: $ cat file-bell

Re: [Python] script bash-pipe compatibile

2009-10-24 Per discussione Giorgio Zoppi
popen? -- Quiero ser el rayo de sol que cada día te despierta para hacerte respirar y vivir en me. "Favola -Moda". ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python

[Python] script bash-pipe compatibile

2009-10-24 Per discussione Matteo Bertini
Supponiamo di voler scrivere uno script python che consuma sys.stdin e scrive su sys.stdout, ad esempio: ### $ cat echo.py import sys for line in sys.stdin: sys.stdout.write(line) ### Purtroppo l'implementazione banale non si accoppia bene con altri tools tipo 'head': ### $ python -c "for