[Python-ideas] Otherwise clause in for statement to run when a empty iterable is used

2021-09-14 Thread Andre Delfino
When working with generators, AFAIK, there's currently no easy way to handle the case of an empty generator (which can be useful if such case is an error). Converting the generator to a, say, list, is not a solution if the generator is intrinsically infinite. I propose to have an "otherwise" cl

[Python-ideas] Re: Otherwise clause in for statement to run when a empty iterable is used

2021-09-14 Thread Andre Delfino
This should have been: When working with generators in a for statement, AFAIK, there's currently no easy way to handle the case of an empty generator (which can be useful if such case is an error). ___ Python-ideas mailing list -- python-ideas@python.o

[Python-ideas] Re: Otherwise clause in for statement to run when a empty iterable is used

2021-09-19 Thread Andre Delfino
Your code has an unpacking error in the first line. I think you mean this, right? no_items = object() item = no_items for item in get_items(): frob(item) if item is no_items: raise ValueError() ___ Python-ideas mailing list -- python-ideas@pyt

[Python-ideas] Make fnmatch.filter accept a tuple of patterns

2018-10-30 Thread Andre Delfino
Frequently, while globbing, one needs to work with multiple extensions. I’d like to propose for fnmatch.filter to handle a tuple of patterns (while preserving the single str argument functionality, alas str.endswith), as a first step for glob.i?glob to accept multiple patterns as well. Here is the

[Python-ideas] Re: Expand the try-expect syntax to support conditional expect block

2022-05-24 Thread Andre Delfino
I believe this would make the code more legible. Serhiy's take is very confusing to me (I get it, but don't think one should write like to get this behavior). ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to pytho

[Python-ideas] dict method to retrieve a key from a value

2023-06-29 Thread Andre Delfino
A dict method to retrieve the key of a value from a bijective dict would have come in handy to me in several occasions: >>> names = {'one': 1} >>> names.inverse()[1] 'one' >>> names = {'one': 1, 'uno': 1} >>> names.inverse()[1] ValueError: dict is not bijective My usual use case is when both key