[Tutor] paste question

Alan Gauld alan.gauld at btinternet.com
Sun Sep 28 10:37:26 CEST 2008

"Alan Gauld" <alan.gauld at btinternet.com> wrote

>> questions(answered and unaswered). I copy the unanswered questions
>> and paste it in console: here a question is displayed in 5 rows, 
>> and
>> I have 20 questions/page.
> I'm beginning to suspect you really want something like
> this pseudo code:
> s = raw_input('Paste here> ')
> for count, line in enumerate(s): pass
> print "You have ", count/5," questions left in ", count/100," pages"

Had a rethink...

I don't know enough about how the X paste mechanism and the
console stdin work together but this may not work because
raw_input will probably stop reading at the first \n character.
You probably need to use sys.stdin.read:

print 'paste now'
s = sys.stdin.read()
count = s.split('\n)  # no need for a loop.
print "You have ", count/5," questions left in ", count/100," pages"


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list