On Sun, Aug 10, 2008 at 4:03 PM, <[EMAIL PROTECTED]> wrote: > > Hi all, > > I've continued playing about with mocking raw_input in doctests in light of > Kent's reply. > > I've hit an odd thing---if my substitute for raw_input returns '', I get an > EOFError. The code below shows the problem. It arises equally if myrawalt is > used in the doctest in place of myraw, so I am sure the problem has nothing > to do with the use of iter. I can work around the problem in my actual > target code---that code, like the toy code below, calls strip() on the > results of raw_input, so I can get away with having my raw_input substitute > return ' ' in place of ''. But, I cannot figure out why the EOFError comes > up. Any thoughts?
My guess, to verify look at the source for raw_input() or experiment... readline() normally includes the \n in the line it returns. It will only return an empty string on EOF. So the raw_input() is seeing the empty line, interpreting it as EOF, and raising EOFError. My suggestion - in your mock stdin, append a \n to the provided data. Also you might want to change the name, you are replacing sys.stdin, not raw_input(). Kent _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
