"a better input"

Ian Bicking ianb at colorstudy.com
Thu May 9 18:33:41 EDT 2002


On Thu, 2002-05-09 at 16:07, Gareth McCaughan wrote:
> Steve Holden wrote:
> 
> [I said:]
> > > I don't actually mind if an input() replacement evaluates 2+3.
> > > I do mind if it is able to do arbitrary computation, where
> > > "arbitrary" is fuzzily defined to cover things like
> > >
> > >   1 anything that could take a large amount of time or
> > >     memory to compute;
> > >
> > >     (rationale: we don't want to facilitate DoS attacks;
> > >     users will find it counterintuitive if what they think
> > >     of as reading a value can consume unbounded resources.)
> > 
> > So, for example, 2**100 is OK, but 2**10000000 is right out?
> 
> Er, no. ** should be right out because 2**10000000 should be.
> I'm not proposing that input() should have the semantics
> "any expression that can be evaluated safely is OK", but
> that there should be some simpler set of rules that has that
> as a consequence. If there is no reasonably simple such set
> of rules, then the idea is unworkable.

I think maybe you mean to allowing input to accept any of the types in
Python that are represented directly in the syntax.  The language
reference can make this completely unambiguous.  You might add the
important singletons None, True, and False, which are often useful.

While the complex number 1+1j doesn't seem primitive, the existence and
behavior of complex() seems to make it easy enough to include.  All
other conveniences aren't really necessary (e.g., 2**100), and are
always possible using rexec if that end-user experience is desired.

This *would* imply that lists, tuples, and dictionaries should be
included, as well I think they should -- they are very useful, and while
they complicate the implementation of a new input, they do not
complicate the description of this new input in any way (which is more
important).  However, this doesn't imply that list comprehension should
be included.

Ideally, triple-quoted, multi-lined strings should be included, but are
not necessary and not currently supported in input.

  Ian







More information about the Python-list mailing list