[Python-ideas] Re: Implementing a 'but' statement in for-iterations

2021-06-28 Thread Johnathan Irvin
What do we gain from this?

Three characters.

I'm not sure how useful this would be.

On Mon, Jun 28, 2021, 9:29 PM David Mertz  wrote:

> Umm?!
>
> items = (j for j in range(10) if j not in {2, 8})
>
> We don't need a new keyword. Nor a tortured use of an old one.
>
> On Mon, Jun 28, 2021, 8:46 PM Rob Cliffe via Python-ideas <
> python-ideas@python.org> wrote:
>
>> Another wild idea:  Suppose that after a line that introduces a suite,
>> including the final colon, you could write further lines on the same
>> physical line, and this would be semantically equivalent to having them
>> on separate lines with increasing indents, but a smaller indent than the
>> following lines in the suite body.  Example:
>>
>>  with open('file1') as f: with open('file2') as g:
>>  
>>
>> Then you could write:
>>
>>  for i in range(0, 10): if i not in range(2, 8):
>>  
>> # This is arguably slightly easier to read than having two separate
>> lines, as it puts both aspects of a single concept ("what values of i do
>> I loop over?") together.  It also avoids a physical indentation level.
>>
>> Rob Cliffe
>>
>> On 29/06/2021 00:44, Richard Damon wrote:
>> > On 6/28/21 5:40 PM, Max Shouman wrote:
>> >> This is more of a syntactic sugar than an actual new feature, but...
>> >> Exactly, 'but' is the idea: a special keyword to be used in for
>> statements to exclude values ​​from the iterable.
>> >>
>> >> E.g., when iterating over a generator:
>> > for i in range(0, 10) but (2, 8):
>> >> would implicitly create a new generator comprehensively, as in:
>> > for i in (j for j in range(0, 10) if j not in [2, 8]):
>> >> It might not add such a feature to justify the definition of a
>> but_stmt in python.gram, but it's fully compliant with Python's philosophy
>> of concise, clear and elegant code.
>> >>
>> >> #road to a programming natural language (jk)
>> > Wild idea, but could we avoid a new keyword by reusing one that can't go
>> > there, like except?
>> >
>> >
>> > for i in range(0,10) except (2, 8):
>> >
>> >
>> > don't know if it is actually worth it, but at least it doesn't add a new
>> > keyword.
>> >
>>
>> ___
>> Python-ideas mailing list -- python-ideas@python.org
>> To unsubscribe send an email to python-ideas-le...@python.org
>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>> Message archived at
>> https://mail.python.org/archives/list/python-ideas@python.org/message/RFD3U3HKCWLRKSRZUEQF5IL3F65S66LD/
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/TNEUSZWVEE4KJZORSFHUANUXHMJSPOVK/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/2OOSCPBNTN2XUHGBTBMEJOALV4ZWRGJC/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Define functions without parentheses (if no parameters given)

2021-06-11 Thread Johnathan Irvin
non sequitur

Route functions as seen in flask or fastapi.

These functions are often decorated by a route, and may not apply here but
are often found with routes that return a page that doesn't take parameters
such as a home page or a contact page.

On Thu, Jun 10, 2021, 10:30 PM Cameron Simpson  wrote:

> On 11Jun2021 10:01, Cameron Simpson  wrote:
> >So your idea does not suck. But it may not motivate anyone to implement
> >it, or even to agreed that it should be implemented.
>
> It also struck me: functions with _no_ parameters are pretty rare.
>
> I had a glance through my own code and aside from some closures
> (functions within a running function, getting their variables from the
> enclosing scope) I've got a few which either access state from some
> global or which generate something standalone, eg a primes() function
> which just generates the primes starting from 2, a function I maybe even
> don't use. They are very few.
>
> So these seem pretty rare. Just how often do you write such a function
> yourself? Got a real world example?
>
> I'm making an argument that this is already a pretty niche situation
> here.
>
> Cheers,
> Cameron Simpson 
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/UXDUUDLJT4JASMBOM7TJXL36MGD3BYI2/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DNDJHT3BYQGFV6ZF56U5KGQQVKXBBZVM/
Code of Conduct: http://python.org/psf/codeofconduct/