[Python-ideas] Yielding from the command line

Terry Reedy tjreedy at udel.edu
Thu Sep 11 19:09:51 CEST 2014


On 9/11/2014 9:42 AM, Martin Teichmann wrote:
> Hi List,
>
> I'm currently trying to convince my company that asyncio is a great
> thing. After a lot of critique, the newest thing is, people complain:
> I cannot test my code on the command line!

I view this as a flimsy excuse, not a reason.  (Asyncio can be hard to 
wrap one's head around, but what do they propose as the alternative for 
the things asyncio does well?)  Do the same people oppose 'yield' (and 
generators) and nonlocal (and writable closures) for the same reason?

 >>> yield from a
SyntaxError: 'yield' outside function
 >>> yield x
SyntaxError: 'yield' outside function
 >>> nonlocal z
SyntaxError: nonlocal declaration not allowed at module level

> I am thinking about a python interpreter whose internal loop is
> something like
>
>      @coroutine
>      def commandline():
>          while True:
>              cmd = yield from input_async()
>              code = compile(cmd, "<stdin>", "generator")
>              yield from exec(code)
>
> A new compile mode would allow to directly, always create a
> generator, and exec should be certainly be able to handle this.

Alternate command line or interactive input interpretation could well 
make sense, but it should stand on its own with real use cases.

> I think this would not only make people happy that want to test
> code on the command line, but also all those people developing
> command line-GUI combinations (IPython comes to mind),
> which have to keep several event loops in sync.

-- 
Terry Jan Reedy



More information about the Python-ideas mailing list