[Tutor] Defining functions
keridee at jayco.net
Sun Mar 27 05:54:17 CEST 2005
sys.stdout.write(prompt) ## Since they're thinking of bonking off
print as well.
a = sys.stdin.readline()
It leaves the '\n' on the end... so it sucks.
I know there is a better way... Someone else-help?
> So, as a newbie, I see this thread and I check out the PEP and I see
> that for future compatibility we should use sys.stdin.readline(). So
> I import sys to see how it works. Of course, sys.stdin.readline('type
> anything: ') doesn't work in quite the same way as raw_input('type
> anything: ') does. The closest I can get after a few newbie stabs is:
>>>>print 'type anything: ', sys.stdin.readline()
> type anything: hello
> What is the easiest way to get the exact functionality of raw_input()
> (i.e. a prompt, no whitespace at the front, and no trailing \n) using
> On Fri, Mar 25, 2005 at 11:02:43AM -0500, Jacob S. wrote:
>> Yeah. And they're thinking of removing raw_input() too. I think it's
>> to have a __builtin__ user input function. Why should we have to import
>> sys everytime we want user input? Almost every program that newbies write
>> uses it, and advanced programmers also if they're using console programs.
>> IMHO, I see no reason to remove it.
>> ## end rant
>> >Michael Dunn wrote:
>> >>Something I've always wondered: if input() is so dangerous, why is it
>> >>there? What valid uses does it have in the wild?
>> >It's a mistake planned to be removed in Python 3.0, the "hypothetical
>> >future release of Python that can break backwards compatibility with the
>> >existing body of Python code."
>> >Python tries very hard to maintain backward compatibility so things like
>> >input() are not removed.
>> >Tutor maillist - Tutor at python.org
>> Tutor maillist - Tutor at python.org
> Tutor maillist - Tutor at python.org
More information about the Tutor