Reading from stdin

2008-10-07 Thread Luis Zarrabeitia
I have a problem with this piece of code: import sys for line in sys.stdin: print "You said!", line Namely, it seems that the stdin buffers the input, so there is no reply until a huge amount of text has bin written. The iterator returned by xreadlines has the same behavior. The

Re: Reading from stdin

2008-10-07 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Luis Zarrabeitia wrote: > I have a problem with this piece of code: > > > import sys > for line in sys.stdin: > print "You said!", line > > > Namely, it seems that the stdin buffers the input, so there is no reply > until a huge amount of text has bi

Re: Reading from stdin

2008-10-07 Thread George Sakkis
Luis Zarrabeitia wrote: > I have a problem with this piece of code: > > > import sys > for line in sys.stdin: > print "You said!", line > > > Namely, it seems that the stdin buffers the input, so there is no reply until > a huge amount of text has bin written. The iterator returned by

Re: Reading from stdin

2008-10-07 Thread Luis Zarrabeitia
On Tuesday 07 October 2008 05:33:18 pm George Sakkis wrote: > Not an answer to your actual question, but you can keep the 'for' loop > instead of rewriting it with 'while' using the iter(function, > sentinel) idiom: > > for line in iter(sys.stdin.readline, ""): > print "You said!", line You're

Re: Reading from stdin

2008-10-07 Thread Luis Zarrabeitia
On Tuesday 07 October 2008 05:12:28 pm Lawrence D'Oliveiro wrote: > In message <[EMAIL PROTECTED]>, Luis > > Zarrabeitia wrote: > > I have a problem with this piece of code: > > > > > > import sys > > for line in sys.stdin: > > print "You said!", line > > > > > > Namely, it seems that

Re: Reading from stdin

2008-10-07 Thread George Sakkis
On Oct 7, 8:13 pm, Luis Zarrabeitia <[EMAIL PROTECTED]> wrote: > On Tuesday 07 October 2008 05:33:18 pm George Sakkis wrote: > > > Not an answer to your actual question, but you can keep the 'for' loop > > instead of rewriting it with 'while' using the iter(function, > > sentinel) idiom: > > > for

Re: Reading from stdin

2008-10-08 Thread Almar Klein
> > I guess the phrasing "hidden read-ahead buffer" implies that buffering > cannot be turned off (or at least it is not intended to even if it's > somehow possible). > I think it can be done, but you would have to use a different approach on linux than on windows. Linux requires fcntl (I dont kno

Re: Reading from stdin

2008-10-08 Thread Luis Zarrabeitia
On Tuesday 07 October 2008 11:27:19 pm George Sakkis wrote: > """ > In order to make a for loop the most efficient way of looping over the > lines of a file (a very common operation), the next() method uses a > hidden read-ahead buffer. As a consequence of using a read-ahead > buffer, combining nex

Re: Reading from stdin

2008-10-08 Thread Jean-Paul Calderone
On Wed, 8 Oct 2008 09:28:55 -0400, Luis Zarrabeitia <[EMAIL PROTECTED]> wrote: On Tuesday 07 October 2008 11:27:19 pm George Sakkis wrote: """ In order to make a for loop the most efficient way of looping over the lines of a file (a very common operation), the next() method uses a hidden read-ah

Re: Reading from stdin

2008-10-09 Thread Hendrik van Rooyen
Luis Zarrabeitia wrote: >But it doesn't say how to put the file object in non-blocking mode. (I was >trying to put the file object in non-blocking mode to test next()'s >behavior). ??Ideas? # Some magic to make a file non blocking - from the internet def unblock(f): """Given file 'f', sets

Re: Reading from stdin

2008-10-14 Thread Gabriel Genellina
En Wed, 08 Oct 2008 10:28:55 -0300, Luis Zarrabeitia <[EMAIL PROTECTED]> escribió: And I may try to find next()'s implementation... I guess I'll be downloading python's source when my bandwidth allows it (or find it on a browseable repository) Try http://svn.python.org - in particular, h

Reading from stdin (in windows)

2008-10-14 Thread [EMAIL PROTECTED]
Hi! I wanna write a file processor in python (Windows XP). I wanna use pipe, and not parameters. When I write this: ... l = [] while 1: t = sys.stdin.read(1) if t == '': break l.append(t) t = "".join(l) ... and use code this: process.py http://mail.python.org/mailman/listi

Re: Reading from stdin (in windows)

2008-10-14 Thread Rob Williscroft
[EMAIL PROTECTED] wrote in news:mailman.2448.1223974725.3487.python- [EMAIL PROTECTED] in comp.lang.python: > Hi! > > I wanna write a file processor in python (Windows XP). > I wanna use pipe, and not parameters. > > When I write this: > > ... > l = [] > while 1: > t = sys.stdin.read(1) >

Reading from stdin first, then use curses

2013-08-11 Thread Timo Schmiade
Hi all, I wrote a replacement for urlview to properly extract URLs from emails. You can find the first draft here: https://github.com/the-isz/pyurlview When I call it with an email file passed to the '-f' argument, it does pretty much what I want already. However, I intend to use it in mutt, w

Reading From stdin After Command Line Redirection

2013-10-23 Thread Tim Daneliuk
I have a program that runs like this: foo.py https://mail.python.org/mailman/listinfo/python-list

Re: Reading from stdin first, then use curses

2013-08-31 Thread Timo Schmiade
Hi again, sorry for replying to my own mail, but is there really no solution? Can curses really not be used in this situation? Thanks again, Timo On Sun, Aug 11, 2013 at 02:05:11PM +0200, Timo Schmiade wrote: > Hi all, > > I wrote a replacement for urlview to properly extract URLs from emails.

Re: Reading from stdin first, then use curses

2013-09-01 Thread Antoon Pardon
Op 11-08-13 14:05, Timo Schmiade schreef: Hi all, I wrote a replacement for urlview to properly extract URLs from emails. You can find the first draft here: https://github.com/the-isz/pyurlview When I call it with an email file passed to the '-f' argument, it does pretty much what I want al

Re: Reading from stdin first, then use curses

2013-09-04 Thread Veritatem Ignotam
I'd like to bump this. I asked a similar question a few weeks ago and had no reply. Here's my question: I'm fairly new to python and even newer to curses. Does any one have a good solution for how to embed the output of a subprocess (ex. subprocess.Popen("htop", stdout=subprocess.PIPE)) into an nc

Re: Reading from stdin first, then use curses

2013-09-04 Thread Antoon Pardon
Op 04-09-13 20:45, Veritatem Ignotam schreef: I'd like to bump this. I asked a similar question a few weeks ago and had no reply. Here's my question: I'm fairly new to python and even newer to curses. Does any one have a good solution for how to embed the output of a subprocess (ex. subprocess.P

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread Chris Angelico
On Thu, Oct 24, 2013 at 4:25 AM, Tim Daneliuk wrote: > I have a program that runs like this: > > foo.py > I want to reconnect stdin to the tty as usual after 'inputfile' > has been read so that things like raw_input and getpass > will work as expected. > > So, after I do = sys.stdin.readli

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread Ben Finney
Tim Daneliuk writes: > I have a program that runs like this: > > foo.py I want to reconnect stdin to the tty as usual after 'inputfile' > has been read so that things like raw_input and getpass > will work as expected. Why? That's at odds with how the user has already chosen to run the progra

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread Chris Angelico
On Thu, Oct 24, 2013 at 7:46 AM, Ben Finney wrote: > Can you speak more about how you intend your program to be used? The > above request is incoherent, and I suspect you've made a design mistake. There are times when this is correct behaviour - like asking for passwords (SSH and sudo work like t

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread random832
On Wed, Oct 23, 2013, at 16:52, Chris Angelico wrote: > There are times when this is correct behaviour - like asking for > passwords (SSH and sudo work like this). Less (or pagers generally, or an interactive text editor that allows creating a file from standard input) would be another example of

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread Ben Finney
random...@fastmail.us writes: > On Wed, Oct 23, 2013, at 16:52, Chris Angelico wrote: > > There are times when this is correct behaviour - like asking for > > passwords (SSH and sudo work like this). > > Less (or pagers generally, or an interactive text editor that allows > creating a file from st

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread Chris Angelico
On Thu, Oct 24, 2013 at 9:20 AM, Ben Finney wrote: > random...@fastmail.us writes: > >> On Wed, Oct 23, 2013, at 16:52, Chris Angelico wrote: >> > There are times when this is correct behaviour - like asking for >> > passwords (SSH and sudo work like this). >> >> Less (or pagers generally, or an i

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread Tim Daneliuk
On 10/23/2013 05:20 PM, Ben Finney wrote: random...@fastmail.us writes: On Wed, Oct 23, 2013, at 16:52, Chris Angelico wrote: There are times when this is correct behaviour - like asking for passwords (SSH and sudo work like this). Less (or pagers generally, or an interactive text editor tha

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread Ben Finney
Tim Daneliuk writes: > 'Easy there Rainman I'll thank you not to use mental deficiency as some kind of insult. Calling someone “Rainman” is to use autistic people as the punchline of a joke. We're a community that doesn't welcome such ableist slurs. > The goal of the exercise was: > > - Read a

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread Tim Daneliuk
On 10/23/2013 10:53 PM, Ben Finney wrote: Right. Congratulations for learning more about the design of the OS and making a program that fits in well:-) It's only possible because, after some 30 years of doing this, I feel very abelist ... --

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread Tim Daneliuk
On 10/23/2013 10:53 PM, Ben Finney wrote: Congratulations for learning more about the design of the OS and making a program that fits in well It's only because of some 30 years of doing this that I now feel quite abelist ... -- --

Re: Reading From stdin After Command Line Redirection

2013-10-23 Thread Ben Finney
Tim Daneliuk writes: > On 10/23/2013 10:53 PM, Ben Finney wrote: > > Right. Congratulations for learning more about the design of the OS and > > making a program that fits in well:-) > > It's only possible because, after some 30 years of doing this, I feel > very abelist ... You may be unaware,

Re: Reading From stdin After Command Line Redirection

2013-10-24 Thread Mark Lawrence
On 24/10/2013 04:53, Ben Finney wrote: Tim Daneliuk writes: 'Easy there Rainman I'll thank you not to use mental deficiency as some kind of insult. Calling someone “Rainman” is to use autistic people as the punchline of a joke. We're a community that doesn't welcome such ableist slurs. I

Re: Reading From stdin After Command Line Redirection

2013-10-24 Thread Ben Finney
Mark Lawrence writes: > On 24/10/2013 04:53, Ben Finney wrote: > > Tim Daneliuk writes: > > > >> 'Easy there Rainman > > > > I'll thank you not to use mental deficiency as some kind of insult. > > Calling someone “Rainman” is to use autistic people as the punchline > > of a joke. We're a communi

Re: Reading From stdin After Command Line Redirection

2013-10-24 Thread Tim Chase
On 2013-10-24 14:53, Ben Finney wrote: > I think the request is incoherent: If you want to allow the user to > primarily interact with the program, this is incompatible with also > wanting to redirect standard input. As a counter-example, might I suggest one I use regularly: gimme_stuff_on_stdo

Re: Reading From stdin After Command Line Redirection

2013-10-24 Thread Oscar Benjamin
On 24 October 2013 01:09, Tim Daneliuk wrote: > > Now that I think about it, as I recall from the prehistoric era of writing > lots of assembler and C, if you use shell redirection, stdin shows > up as a handle to the file Yes this is true. A demonstration using seek (on Windows but it is the sam

Re: Reading From stdin After Command Line Redirection

2013-10-24 Thread Tim Daneliuk
On 10/23/2013 11:54 PM, Ben Finney wrote: we don't welcome ableist (nor sexist) behaviour. Well now I just feel so very awful ... -- Tim Daneliuk tun...@tundraware.com PGP Key: http://www.tundraware.com/PG

Re: Reading From stdin After Command Line Redirection

2013-10-24 Thread Oscar Benjamin
On 24 October 2013 12:58, Tim Daneliuk wrote: > On 10/23/2013 11:54 PM, Ben Finney wrote: >> >> we don't welcome ableist (nor sexist) behaviour. > > Well now I just feel so very awful ... Please end this line of discussion. Ben is right: your comment was entirely unnecessary and could easily offe

Re: Reading From stdin After Command Line Redirection

2013-10-24 Thread Tim Daneliuk
On 10/24/2013 07:10 AM, Oscar Benjamin wrote: On 24 October 2013 12:58, Tim Daneliuk wrote: On 10/23/2013 11:54 PM, Ben Finney wrote: we don't welcome ableist (nor sexist) behaviour. Well now I just feel so very awful ... Please end this line of discussion. Ben is right: your comment was

Re: Reading From stdin After Command Line Redirection

2013-10-24 Thread feedthetroll
Am Donnerstag, 24. Oktober 2013 15:41:52 UTC+2 schrieb Tim Daneliuk: > On 10/24/2013 07:10 AM, Oscar Benjamin wrote: >> On 24 October 2013 12:58, Tim Daneliuk wrote: >>> On 10/23/2013 11:54 PM, Ben Finney wrote: we don't welcome ableist (nor sexist) behaviour. >>> Well now I just feel so very

Re: Reading From stdin After Command Line Redirection

2013-10-24 Thread Ethan Furman
On 10/24/2013 06:41 AM, Tim Daneliuk wrote: But now I feel bad about myself and it's all your fault. Really? *plonk* -- https://mail.python.org/mailman/listinfo/python-list

Re: Reading From stdin After Command Line Redirection

2013-10-24 Thread Tim Daneliuk
On 10/24/2013 09:36 AM, feedthetr...@gmx.de wrote: Am Donnerstag, 24. Oktober 2013 15:41:52 UTC+2 schrieb Tim Daneliuk: On 10/24/2013 07:10 AM, Oscar Benjamin wrote: On 24 October 2013 12:58, Tim Daneliuk wrote: On 10/23/2013 11:54 PM, Ben Finney wrote: we don't welcome ableist (nor sexist)

Re: Reading From stdin After Command Line Redirection

2013-10-24 Thread Ethan Furman
On 10/24/2013 01:14 AM, Mark Lawrence wrote: On 24/10/2013 04:53, Ben Finney wrote: Tim Daneliuk writes: 'Easy there Rainman I'll thank you not to use mental deficiency as some kind of insult. Calling someone “Rainman” is to use autistic people as the punchline of a joke. We're a community