A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-February/152142.html below:

[Python-Dev] A minimal Python interpreter written in Python for experimenting with language changes

[Python-Dev] A minimal Python interpreter written in Python for experimenting with language changesSteven D'Aprano steve at pearwood.info
Mon Feb 5 22:40:13 EST 2018
On Sat, Feb 03, 2018 at 11:45:15AM +0100, asrp wrote:

> > Can you give an example of how you would do that? I don't mean the 
> > mechanism used, I mean how would a developer implement a new syntactic 
> > feature. Suppose I wanted to add a new clause to for...else, let's say:
> >
> >     for ... :
> >        block
> >     otherwise:
> >        # runs only if the for-loop was empty
> > 
> > How would do I do that?
[...]
> If you tell me a bit more about the intended behaviour of "otherwise", 
> I'd be happy to do an example with that clause.


Here's a faked session showing the sort of thing I am referring to. 
(Note that this is just an example, not a proposal for a new language 
feature.)

for x in [1, 2, 3]:
    print(x)
otherwise:
    print("nothing there")


prints 1, 2, 3.

for x in []:
    print(x)
otherwise:
    print("nothing there")

prints "nothing there". In other words, the otherwise block runs if, and 
only if, the loop iterable is empty and the for block does NOT run.

Can you do something like that?



-- 
Steve
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4