Mailing List Archive

Re: []=[]
On 23/09/23 4:51 am, Stefan Ram wrote:
> []=[]
>
> (Executes with no error.)

#####
[]=[]
( 1 )
#\_/#

(Executes with no error.)

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list
Re: []=[] [ In reply to ]
On 23/09/2023 09.41, Stefan Ram wrote:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> []=[]
>
> I was watching a video of a David Beazley talk "Python
> Concurrency From the Ground Up" , where he wrote
>
> can_recv, can_send, [] = select(recv_wait, send_wait, [])
>
> . Later, he clarified that he actually wanted to write
>
> can_recv, can_send, _ = select(recv_wait, send_wait, [])
>
> and that he was surprised how the "[]" gave no error.
> ("I wonder why that works.")

If you try:

[] = [1]

and check the error, it will be clear how it works.
Maybe not why... :-)

bye,

--

piergiorgio

--
https://mail.python.org/mailman/listinfo/python-list
Re: []=[] [ In reply to ]
It's not a bug, it's an empty unpacking.
Just as you can write
    [A,B] = [1,2] # Sets A to 1, B to 2
Best wishes
Rob Cliffe

On 23/09/2023 04:41, Greg Ewing via Python-list wrote:
> On 23/09/23 4:51 am, Stefan Ram wrote:
>> []=[]
>>
>>    (Executes with no error.)
>
> #####
> []=[]
> ( 1 )
> #\_/#
>
> (Executes with no error.)
>

--
https://mail.python.org/mailman/listinfo/python-list
Re: []=[] [ In reply to ]
On Tue, 26 Sept 2023 at 02:52, Piergiorgio Sartor via Python-list
<python-list@python.org> wrote:
>
> On 23/09/2023 09.41, Stefan Ram wrote:
> > ram@zedat.fu-berlin.de (Stefan Ram) writes:
> >> []=[]
> >
> > I was watching a video of a David Beazley talk "Python
> > Concurrency From the Ground Up" , where he wrote
> >
> > can_recv, can_send, [] = select(recv_wait, send_wait, [])
> >
> > . Later, he clarified that he actually wanted to write
> >
> > can_recv, can_send, _ = select(recv_wait, send_wait, [])
> >
> > and that he was surprised how the "[]" gave no error.
> > ("I wonder why that works.")
>
> If you try:
>
> [] = [1]
>
> and check the error, it will be clear how it works.
> Maybe not why... :-)
>

Note that the reason it gives no error is that select() returned an
empty iterable as the third value. And you can be sure that it will
ALWAYS return an empty iterable, because select() returns three values
that correspond to the three parameters, and are subsets of them -
that is to say, everything in can_recv must have previously been in
recv_wait, and everything in can_send must have been in send_wait.
Since the third (waiting for exceptional conditions) was empty, there
can't ever be anything to return, and so [] will work, and unpack zero
elements.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list