Re: New assignmens ...

2021-10-22 Thread dn via Python-list
On 23/10/2021 12.51, Greg Ewing wrote: > On 23/10/21 8:49 am, dn wrote: >> Whereas, creating a list (or tuple...) is legal because the structure's >> name is an "identifier"! > > No, the restriction only applies to the LHS. The list construction > is on the RHS. That contention (above) may have

Re: New assignmens ...

2021-10-22 Thread Chris Angelico
On Sat, Oct 23, 2021 at 12:24 PM Paulo da Silva wrote: > > Às 20:34 de 22/10/21, Chris Angelico escreveu: > > On Sat, Oct 23, 2021 at 6:24 AM Jon Ribbens via Python-list > > wrote: > >> > >> On 2021-10-22, Stefan Ram wrote: > >>> Paulo da Silva writes: > Why doesn't this work > i

Re: New assignmens ...

2021-10-22 Thread Paulo da Silva
Às 20:34 de 22/10/21, Chris Angelico escreveu: > On Sat, Oct 23, 2021 at 6:24 AM Jon Ribbens via Python-list > wrote: >> >> On 2021-10-22, Stefan Ram wrote: >>> Paulo da Silva writes: Why doesn't this work if (self.ctr:=self.ctr-1)<=0: while this works if (ctr:=ctr-

Re: New assignmens ...

2021-10-22 Thread Greg Ewing
On 23/10/21 8:49 am, dn wrote: Whereas, creating a list (or tuple...) is legal because the structure's name is an "identifier"! No, the restriction only applies to the LHS. The list construction is on the RHS. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: New assignmens ...

2021-10-22 Thread dn via Python-list
With apologies for pressing Send too early... On 23/10/2021 08.41, dn via Python-list wrote: > On 23/10/2021 08.34, Chris Angelico wrote: >> On Sat, Oct 23, 2021 at 6:24 AM Jon Ribbens via Python-list >> wrote: >>> >>> On 2021-10-22, Stefan Ram wrote: Paulo da Silva writes: > Why doesn

Re: New assignmens ...

2021-10-22 Thread dn via Python-list
On 23/10/2021 08.34, Chris Angelico wrote: > On Sat, Oct 23, 2021 at 6:24 AM Jon Ribbens via Python-list > wrote: >> >> On 2021-10-22, Stefan Ram wrote: >>> Paulo da Silva writes: Why doesn't this work if (self.ctr:=self.ctr-1)<=0: while this works if (ctr:=ctr-1)<=

Re: New assignmens ...

2021-10-22 Thread Chris Angelico
On Sat, Oct 23, 2021 at 6:24 AM Jon Ribbens via Python-list wrote: > > On 2021-10-22, Stefan Ram wrote: > > Paulo da Silva writes: > >>Why doesn't this work > >> if (self.ctr:=self.ctr-1)<=0: > >>while this works > >> if (ctr:=ctr-1)<=0: > > > > assignment_expression ::= [identifier

Re: New assignmens ...

2021-10-22 Thread Jon Ribbens via Python-list
On 2021-10-22, Stefan Ram wrote: > Paulo da Silva writes: >>Why doesn't this work >> if (self.ctr:=self.ctr-1)<=0: >>while this works >> if (ctr:=ctr-1)<=0: > > assignment_expression ::= [identifier ":="] expression, > but the attribute references "self.ctr" is no identifier! This

New assignmens ...

2021-10-22 Thread Paulo da Silva
Hi! Why doesn't this work if (self.ctr:=self.ctr-1)<=0: while this works if (ctr:=ctr-1)<=0: Thanks -- https://mail.python.org/mailman/listinfo/python-list

Re: importing a module from a file without the '.py' suffix

2021-10-22 Thread Chris Angelico
On Fri, Oct 22, 2021 at 10:36 PM Antoon Pardon wrote: > > I have a file with python code but the name doesn't end with the '.py' > suffix. > > What is the easiest way to import this code as a module without changing > its name? > It should be possible to use importlib for this: https://docs.pyth

Re: importing a module from a file without the '.py' suffix

2021-10-22 Thread Chris Johns
The (newer) risc os port does a whole bunch of stuff in importlib to do this, as it natively doesn’t use extensions but file types. I’m not sure if you could do something similar without modifying importlib and re-freezing it. https://github.com/c-jo/cpython/blob/riscos-310/Lib/importlib/_boots

Re: importing a module from a file without the '.py' suffix

2021-10-22 Thread Rob Cliffe via Python-list
As far as I know, it can't be done. If I was REALLY desperate I might try (tested) import os os.rename('myfile.myext', 'myfile.py') import myfile os.rename('myfile.py', 'myfile.myext') # with appropriate modifications if myfile is not in the current directory but this is a horrible solution, sub

importing a module from a file without the '.py' suffix

2021-10-22 Thread Antoon Pardon
I have a file with python code but the name doesn't end with the '.py' suffix. What is the easiest way to import this code as a module without changing its name? -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list