Input statement question
ron
radam2 at tampabay.rr.com
Sat Oct 25 18:46:48 EDT 2003
On Sat, 25 Oct 2003 11:16:50 -0400, mwilson at the-wire.com (Mel Wilson)
wrote:
>In article <1bripv431lfpjdgikhetc2fsbf8e7503ks at 4ax.com>,
>ron <radam2 at tampabay.rr.com> wrote:
>>Is the input() function new? There doesn't seem to be very many
>>examples of it's use.
>>After a lot of searching I did find both the input() and raw_input()
>>statement definitions. I don't understand the reasoning behind making
>>input() equivalent to "eval (raw_imput[prompt])" the default
>>behavior, and "raw_input([prompt])" input standard strings?
>
> It does seem a bit strange. In a statically typed
>language it seems sensible to have a function that could
>parse input and return an object of the type the program
>demands. Python being dynamically typed, you can argue,
>means that the object type matches the input, regardless of
>what the program expects. But that's the strange part.
>
> I've never used `input` in a real program. (It's not new
>.. quite the contrary, AFAIK)
>
>>It seems to me, input() should get a standard string as the default
>>behavior. And raw input should get strings + control characters
>>until the specified ending character is received.
>>
>> variable = input_raw( ['terminate character'] [,'file'] )
>
> This is problematic. In a situation where I'm concerned
>with a variety of terminate characters, I'm also concerned
>with the chance of missing terminate characters. So if my
>input routine skips a few '%' in search of a '$' that isn't
>there, I'm <expletive deleted>.
Why would that be a problem? You would just get the whole input
stream. The only problem I see with this is if you are getting input
from a user and don't tell the user what the new terminating character
is. Input from a file would terminate naturally at EOF or at a
specified character if someone finds that is useful. (?)
>
> Python file input seems to be moving in the direction of
>files of records, where the default record is a text line.
>In non-default situations, you'll subclass the `file`
>class to pick out records according to your need.
>
> Regards. Mel.
In the case of files, a regular file i/o routine would probably be
better in most cases. And the need for raw text input from a user is
probably only needed in special cases.
Actually I think the best way to get that sort of entry from a user is
to use a key press input function.
In the case of people, I think an input() function designed to work
with people has advantages. Just like a file io routine designed to
work with files works best there.
Ron
More information about the Python-list
mailing list