Re: program in interactive mode

2004-12-27 Thread Mike Meyer
"John Machin" <[EMAIL PROTECTED]> writes: > Mike Meyer wrote: >> >> I've discovered a truly elegant trick with python programs that >> interpret other data. > Q0. Other than what? Other than Python code. >> You make them ignore lines that start with # at >> the beginning of the line, > Q1. After

Re: program in interactive mode

2004-12-26 Thread John Machin
Mike Meyer wrote: > > I've discovered a truly elegant trick with python programs that > interpret other data. Q0. Other than what? > You make them ignore lines that start with # at > the beginning of the line, Q1. After the first user accidentally gets a # at the start of a real data line, a fe

Re: program in interactive mode

2004-12-26 Thread Mike Meyer
"B.G.R." <[EMAIL PROTECTED]> writes: > Hi all, > > I'm working on an interpreter for a university subject, which is programmed > in python under linux. > I got most of the work done and I'm just trying to settle some problems I've > found on my way. > Right now, the most important is reading the u

Re: program in interactive mode

2004-12-26 Thread Scott David Daniels
B.G.R. wrote: numline=0 for line in sys.stdin: numline+=1 workwithline(line) I'd use: for numline, line in enumerate(sys.stdin): workwithline(line) Note: The line numbers start at 0, but that is often acceptable. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/

Re: program in interactive mode

2004-12-26 Thread B.G.R.
"Alex Martelli" <[EMAIL PROTECTED]> escribió en el mensaje news:[EMAIL PROTECTED] > B.G.R. <[EMAIL PROTECTED]> wrote: >... > > numline=0 > > for line in sys.stdin: > > numline+=1 > > workwithline(line) > > Consider the alternative: > for numline, line in enumerate(sys.stdin): > > N

Re: program in interactive mode

2004-12-26 Thread Alex Martelli
B.G.R. <[EMAIL PROTECTED]> wrote: ... > numline=0 > for line in sys.stdin: > numline+=1 > workwithline(line) Consider the alternative: for numline, line in enumerate(sys.stdin): Nothing to do with your main program, but still neater... > that's ok, but if the user only does "./myp

Re: program in interactive mode

2004-12-26 Thread M.E.Farmer
B.G.R. wrote: > Hi all, [snip] > A little bit more complex, but that's the idea. That will work if the user > does something like "./myprog.py < code" or "cat code | ./myprog.py", and > that's ok, but if the user only does "./myprog.py" then I got to get into > interactive mode and show a prompt in