From jitendrabeura001 at gmail.com Fri Oct 1 00:34:43 2021 From: jitendrabeura001 at gmail.com (jitendrabeura001) Date: Fri, 01 Oct 2021 10:04:43 +0530 Subject: python39.dll not found Message-ID: Please someone help me to find the solution for the problem Whenever I am trying to run python idle after installing, it is showing me- [1]python.exe - Syntax Error The code execution cannot proceed because [2]python39.dll was not found. Re-installing the program may fix the problem. References Visible links 1. http://python.exe/ 2. http://python39.dll/ From shishaozhong at gmail.com Fri Oct 1 05:58:08 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Fri, 1 Oct 2021 10:58:08 +0100 Subject: Definitive guide for Regex In-Reply-To: <11163B70-C9EA-49DA-9235-F44AD64F23CB@barrys-emacs.org> References: <7FE7CB5C-29E9-4C25-9C7A-9F1088A27959@barrys-emacs.org> <3cb68ea8-78cc-8e67-7432-4a2a1c092b17@DancesWithMice.info> <11163B70-C9EA-49DA-9235-F44AD64F23CB@barrys-emacs.org> Message-ID: Hi, Barry, In cases of automating checking, validation and producing reports in the context of data quality control and giving specific feedback to production teams, regex is perhaps the only way. Perhaps, we can give each element of data specifications a name, that are associated with a regex value, so that we can automate checking and reporting on data sets. We can report on which row of records meet specification and requirements and which one is not. And, report on which cell needs to be corrected should a row is found not meeting specification and requirements. What do you think? Regards, David On Thu, 30 Sept 2021 at 22:02, Barry Scott wrote: > > > > On 30 Sep 2021, at 19:35, dn via Python-list > wrote: > > > > On 01/10/2021 06.16, Barry Scott wrote: > >> > >> > >>> On 30 Sep 2021, at 12:29, Shaozhong SHI > wrote: > >>> > >>> Dear All, > >>> > >>> I am trying to look for a definitive guide for Regex in Python. > >>> Can anyone help? > >> > >> Have you read the python docs for the re module? > > > > > > I learned from Jeffrey Friedl's book "Mastering Regular Expressions", > > but that was in a land far away, last century, and under a different > > language (and the original version - I see it's now up to its third > > edition). > > > > Despite their concise exercise of power (and the fact that in my > > Python-life I've never been put into a corner where I absolutely must > > use one), I'm no longer a fan... > > Agreed, regex is the last tool I reach for in python code. > I find I use split() a lot to break up strings for processing. > But there are cases where a regex is the best tool for a particular job > and I then use the re module. But it costs in maintainability. > > I speak as the author of a regex engine and know how to write scary > regex's when the need arises. > > Barry > > > > -- > > Regards, > > =dn > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From sravan.chitikesi at iprotechs.com Fri Oct 1 03:29:46 2021 From: sravan.chitikesi at iprotechs.com (Sravan Kumar Chitikesi) Date: Fri, 1 Oct 2021 03:29:46 -0400 Subject: python39.dll not found In-Reply-To: References: Message-ID: You might copy the installation files from one to another computer, but you missed the copying pytho**.dll from from windows/system32 folder. Regards, *Sravan Chitikesi* AWS Solutions Architect - Associate On Fri, Oct 1, 2021 at 12:38 AM jitendrabeura001 wrote: > Please someone help me to find the solution for the problem > Whenever I am trying to run python idle after installing, it is showing > me- > [1]python.exe - Syntax Error > The code execution cannot proceed because [2]python39.dll was not found. > Re-installing the program may fix the problem. > > References > > Visible links > 1. http://python.exe/ > 2. http://python39.dll/ > -- > https://mail.python.org/mailman/listinfo/python-list > From tonidelmoral at hotmail.com Fri Oct 1 10:56:48 2021 From: tonidelmoral at hotmail.com (TONI MORAL SEGURA) Date: Fri, 1 Oct 2021 14:56:48 +0000 Subject: Problems with desinatlation In-Reply-To: References: Message-ID: Hi, I can not remove the program Python 2.7.10 in my Windows 10 What can I do to resolve this problema? Thank you [cid:image003.png at 01D7B6E5.51F6E520] From anilanvesh at gmail.com Fri Oct 1 01:59:57 2021 From: anilanvesh at gmail.com (Anil Anvesh) Date: Thu, 30 Sep 2021 22:59:57 -0700 (PDT) Subject: How to pass a method as argument? In-Reply-To: References: <8d413a3e-6334-9519-f232-b1aae02cfee6@wichmann.us> <3a55b010-6c93-49b5-8e27-baf9bdb8eb64n@googlegroups.com> Message-ID: <03c0432c-36df-4ed3-a82a-3512d9d3c2d3n@googlegroups.com> On Friday, October 1, 2021 at 6:04:34 AM UTC+5:30, Mats Wichmann wrote: > On 9/29/21 23:11, Anil Anvesh wrote: > > I want to write a python calculator program that has different methods to add, subtract, multiply which takes 2 parameters. I need to have an execute method when passed with 3 parameters, should call respective method and perform the operation. How can I achieve that? > > > let me add - this is probably not the place you are in your Python > learning, so don't worry about this, but the operator module is designed > for these kind of usages, when you want to pass an operator like + - > etc. but of course can't pass the op itself to take actions because it's > not a callable - the operator module has callables that can be used. I solved it with simple if condition and without using init #calculator class with arithmetic methods class calc: def execute(self, func, a, b): self.a = a self.b = b if func == "add": self.add() elif func == "sub": self.sub() elif func == "mul": self.mul() elif func == "div": self.div() def add(self): print (self.a,"+",self.b,"=",self.a + self.b) def sub(self): print (self.a,"-",self.b,"=",self.a - self.b) def mul(self): print (self.a,"*",self.b,"=",self.a* self.b) def div(self): print (self.a,"/",self.b,"=",self.a / self.b) cal = calc() cal.execute("div", 6, 3) From eryksun at gmail.com Sat Oct 2 01:03:31 2021 From: eryksun at gmail.com (Eryk Sun) Date: Sat, 2 Oct 2021 00:03:31 -0500 Subject: python39.dll not found In-Reply-To: References: Message-ID: On 10/1/21, Sravan Kumar Chitikesi wrote: > You might copy the installation files from one to another computer, but you > missed the copying pytho**.dll from from windows/system32 folder.> The PSF installer 3.4 and earlier installs "pythonXY.dll" in the system directory when it peforms an all-users installation. The installer for 3.5+, however, only installs files to the target installation directory and child directories. The file "python3X.dll" should be installed in the same directory as "python.exe". From oscar.j.benjamin at gmail.com Sat Oct 2 10:45:11 2021 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 2 Oct 2021 15:45:11 +0100 Subject: Different "look and feel" of some built-in functions In-Reply-To: References: <24909.63872.434489.521344@ixdm.fritz.box> Message-ID: On Sat, 25 Sept 2021 at 02:11, Oscar Benjamin wrote: > On Sat, 25 Sept 2021 at 02:01, Chris Angelico wrote: > >> On Sat, Sep 25, 2021 at 10:56 AM Oscar Benjamin >> wrote: >> > >> > On Sat, 25 Sept 2021 at 00:37, Greg Ewing >> > wrote: >> > > I suppose they could be fiddled somehow to make it possible, but >> > > that would be turning them into special cases that break the rules. >> > > It would be better to provide separate functions, as was done with >> > > sum(). >> > > >> > >> > A separate union function would be good. Even in a situation where all >> > inputs are assured to be sets the set.union method fails the base case: >> > >> > >>> sets = [] >> > >>> set.union(*sets) >> > Traceback (most recent call last): >> > File "", line 1, in >> > TypeError: descriptor 'union' of 'set' object needs an argument >> > >> > In the case of intersection perhaps the base case should be undefined. >> > >> >> Rather than calling the unbound method, why not just call it on an >> empty set? That defines your base case as well. >> >> set().union(*sets) >> > > That is indeed what I do but it seems unnatural compared to simply > union(*sets). It shouldn't be necessary to create a redundant empty set > just to compute the union of some other sets. If there was a union function > then I don't think I would ever use the union method. > I just hit up against a problem using this with mypy: $ cat y.py from typing import Set, Tuple class Tree: _children: 'Tuple[Tree]' @property def children(self) -> 'Tuple[Tree]': return self._children @property def leaves(self) -> 'Set[Tree]': return set().union(*(child.leaves for child in self.children)) $ mypy y.py y.py:12: error: Incompatible return value type (got "Set[]", expected "Set[Tree]") y.py:12: error: Argument 1 to "union" of "set" has incompatible type "*Generator[Set[Tree], None, None]"; expected "Iterable[]" Found 2 errors in 1 file (checked 1 source file) It seems that mypy is okay with set.union(*stuff) but not set().union(*stuff). I can fix it with: @property def leaves(self) -> 'Set[Tree]': empty: 'Set[Tree]' = set() return empty.union(*(child.leaves for child in self.children)) That's just horrible though. Why should I give a name and type hint for the completely redundant empty set object? Does anyone know of a better way to hint this? -- Oscar From barry at barrys-emacs.org Sat Oct 2 13:27:34 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Sat, 2 Oct 2021 18:27:34 +0100 Subject: Definitive guide for Regex In-Reply-To: References: <7FE7CB5C-29E9-4C25-9C7A-9F1088A27959@barrys-emacs.org> <3cb68ea8-78cc-8e67-7432-4a2a1c092b17@DancesWithMice.info> <11163B70-C9EA-49DA-9235-F44AD64F23CB@barrys-emacs.org> Message-ID: <9EF819E3-E83D-42E0-B03B-D1645CBB7054@barrys-emacs.org> > On 1 Oct 2021, at 10:58, Shaozhong SHI wrote: > > Hi, Barry, > > In cases of automating checking, validation and producing reports in the context of data quality control and giving specific feedback to production teams, regex is perhaps the only way. > > Perhaps, we can give each element of data specifications a name, that are associated with a regex value, so that we can automate checking and reporting on data sets. We can report on which row of records meet specification and requirements and which one is not. And, report on which cell needs to be corrected should a row is found not meeting specification and requirements. > > What do you think? It depends a lot of the details of that you have to validate. There is not enough to guess at a design. It may well be that uses regex's is a good way to do it. Barry > > Regards, > > David > > On Thu, 30 Sept 2021 at 22:02, Barry Scott > wrote: > > > > On 30 Sep 2021, at 19:35, dn via Python-list > wrote: > > > > On 01/10/2021 06.16, Barry Scott wrote: > >> > >> > >>> On 30 Sep 2021, at 12:29, Shaozhong SHI > wrote: > >>> > >>> Dear All, > >>> > >>> I am trying to look for a definitive guide for Regex in Python. > >>> Can anyone help? > >> > >> Have you read the python docs for the re module? > > > > > > I learned from Jeffrey Friedl's book "Mastering Regular Expressions", > > but that was in a land far away, last century, and under a different > > language (and the original version - I see it's now up to its third > > edition). > > > > Despite their concise exercise of power (and the fact that in my > > Python-life I've never been put into a corner where I absolutely must > > use one), I'm no longer a fan... > > Agreed, regex is the last tool I reach for in python code. > I find I use split() a lot to break up strings for processing. > But there are cases where a regex is the best tool for a particular job > and I then use the re module. But it costs in maintainability. > > I speak as the author of a regex engine and know how to write scary > regex's when the need arises. > > Barry > > > > -- > > Regards, > > =dn > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sat Oct 2 19:39:38 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Oct 2021 10:39:38 +1100 Subject: Confusing error message: lambda walruses Message-ID: Using assignment expressions in lambda functions sometimes works, but sometimes doesn't. Python 3.11.0a0 (heads/main:dc878240dc, Oct 3 2021, 10:28:40) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. # Fine if it's a parameter to the lambda function >>> def f(): ... return lambda x: (x, x := 2, x) ... >>> g = f() >>> g(1) (1, 2, 2) # Plain ol' SyntaxError if unparenthesized >>> def f(n): ... return lambda: n := 1 File "", line 2 return lambda: n := 1 ^^ SyntaxError: invalid syntax # Fine if it's a parameter to the outer function >>> def f(n): ... return lambda: (n := 1) ... >>> g = f(3) >>> g() 1 # But a SyntaxError if parenthesized like this?? >>> def f(n): ... return (lambda: n := 1) File "", line 2 return (lambda: n := 1) ^^^^^^^^^ SyntaxError: cannot use assignment expressions with lambda # Oh, and it doesn't actually assign anything. >>> def f(n): ... return (lambda: (n := 1)), (lambda: n) ... >>> g, h = f(5) >>> h() 5 >>> g() 1 >>> h() 5 What's going on here? Disassembly of the last function shows that it's using STORE_FAST to try to assign to n, so I *think* that it's actually like the first example, where the lambda function is able to assign to its own locals, whether they're parameters or not. But the two SyntaxErrors are confusing. ChrisA From hongyi.zhao at gmail.com Sat Oct 2 04:34:15 2021 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Sat, 2 Oct 2021 01:34:15 -0700 (PDT) Subject: Understanding the working mechanis of python unary arithmetic operators. Message-ID: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> See the following testings: In [24]: a=3.1415926535897932384626433832795028841971 In [27]: -a Out[27]: -3.141592653589793 In [28]: +a Out[28]: 3.141592653589793 In [17]: ~-+1 Out[17]: 0 In [18]: -~+1 Out[18]: 2 In [19]: -+~1 Out[19]: 2 In [20]: +~-1 Out[20]: 0 I'm very puzzled by these operators. Any hints will be highly appreciated. Regards, HZ From hongyi.zhao at gmail.com Sat Oct 2 08:48:27 2021 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Sat, 2 Oct 2021 05:48:27 -0700 (PDT) Subject: Understanding the working mechanis of python unary arithmetic operators. In-Reply-To: References: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> Message-ID: On Saturday, October 2, 2021 at 4:59:54 PM UTC+8, ju... at diegidio.name wrote: > On Saturday, 2 October 2021 at 10:34:27 UTC+2, hongy... at gmail.com wrote: > > See the following testings: > > > > In [24]: a=3.1415926535897932384626433832795028841971 > > In [27]: -a > > Out[27]: -3.141592653589793 > You've never heard of floating-point? Double precision has 53 significant bits of mantissa, corresponding approximately to 16 decimal digits. > > > In [17]: ~-+1 > > Out[17]: 0 > << The unary ~ (invert) operator yields the bitwise inversion of its integer argument. The bitwise inversion of x is defined as -(x+1). It only applies to integral numbers or to custom objects that override the __invert__() special method. >> > > > I'm very puzzled by these operators. Any hints will be highly appreciated. > Try and read the proverbial manual: that's truly a fundamental skill... Thank you for your explanation. Then what about the following questions?: 1. Should `+' and `-' be classified as binary operators or unary operators? As we all know, `a + b', and `a - b' are the normal ways we do basic arithmetic operations. 2. See the following testings: In [20]: bool(int(True)) Out[20]: True In [21]: bool(~int(True)) Out[21]: True In [22]: bool(~~int(True)) Out[22]: True In [23]: bool(~~~int(True)) Out[23]: True In [24]: bool(int(False)) Out[24]: False In [25]: bool(~int(False)) Out[25]: True In [26]: bool(~~int(False)) Out[26]: False In [27]: bool(~~~int(False)) Out[27]: True Why can?t/shouldn't we get something similar results for both `True' and `False' in the above testings? HZ From guinness.tony at gmail.com Sat Oct 2 12:16:01 2021 From: guinness.tony at gmail.com (Tony Oliver) Date: Sat, 2 Oct 2021 09:16:01 -0700 (PDT) Subject: Understanding the working mechanis of python unary arithmetic operators. In-Reply-To: References: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> Message-ID: On Saturday, 2 October 2021 at 13:48:39 UTC+1, hongy... at gmail.com wrote: > On Saturday, October 2, 2021 at 4:59:54 PM UTC+8, ju... at diegidio.name wrote: > > On Saturday, 2 October 2021 at 10:34:27 UTC+2, hongy... at gmail.com wrote: > > > See the following testings: > > > > > > In [24]: a=3.1415926535897932384626433832795028841971 > > > In [27]: -a > > > Out[27]: -3.141592653589793 > > You've never heard of floating-point? Double precision has 53 significant bits of mantissa, corresponding approximately to 16 decimal digits. > > > > > In [17]: ~-+1 > > > Out[17]: 0 > > << The unary ~ (invert) operator yields the bitwise inversion of its integer argument. The bitwise inversion of x is defined as -(x+1). It only applies to integral numbers or to custom objects that override the __invert__() special method. >> > > > > > I'm very puzzled by these operators. Any hints will be highly appreciated. > > Try and read the proverbial manual: that's truly a fundamental skill... > Thank you for your explanation. Then what about the following questions?: > > 1. Should `+' and `-' be classified as binary operators or unary operators? Both. See sections 6.6 and 6.7 of the documentation at https://docs.python.org/3/reference/expressions.html > As we all know, `a + b', and `a - b' are the normal ways we do basic arithmetic operations. Really? Don't you ever write something like "x = -y"? Or do you habitually write "x = 0 - y" or "x = 0.0 - y"? > 2. See the following testings: > > In [20]: bool(int(True)) int(True) -> 1 bool(1) -> True > Out[20]: True > > In [21]: bool(~int(True)) int(True) -> 1 ~1 -> -2 bool(-2) -> True > Out[21]: True > > In [22]: bool(~~int(True)) int(True) -> 1 ~1 -> -2 # these two operations ~(-2) -> 1 # cancel each other out bool(1) -> True > Out[22]: True > > In [23]: bool(~~~int(True)) Because two consecutive bit-inversions cancel each other out; this is just a complicated re-statement of operation [21], above > Out[23]: True > > In [24]: bool(int(False)) int(False) -> 0 bool(0) -> False > Out[24]: False > > In [25]: bool(~int(False)) int(False) -> 0 ~0 -> -1 bool(-1) -> True > Out[25]: True > > In [26]: bool(~~int(False)) Again, two consecutive inversions cancel each other out so this is just an over-complicated re-statement of [24] > Out[26]: False > > In [27]: bool(~~~int(False)) Likewise, this is the equivalent of re-stating [25] > Out[27]: True > > Why can?t/shouldn't we get something similar results for both `True' and `False' in the above testings? Sorry, I can't parse that. From drsalists at gmail.com Sun Oct 3 00:05:47 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 2 Oct 2021 21:05:47 -0700 Subject: McCabe complexity for just changed files in a commit? Message-ID: Hi folks. Is there a way of getting the McCabe Complexity of just the functions and methods (in Python) changed in a git commit? I found radon, and it looks good. But I think it wants to do entire files, no? Thanks! From rosuav at gmail.com Sun Oct 3 00:18:53 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Oct 2021 15:18:53 +1100 Subject: McCabe complexity for just changed files in a commit? In-Reply-To: References: Message-ID: On Sun, Oct 3, 2021 at 3:07 PM Dan Stromberg wrote: > > Hi folks. > > Is there a way of getting the McCabe Complexity of just the functions and > methods (in Python) changed in a git commit? > > I found radon, and it looks good. But I think it wants to do entire files, > no? No idea about the complexity calculation, but perhaps the easiest way is to ask git to list all files that changed in a particular commit, then look at those files before and after, and compare the complexities? git diff-tree 1af743 1af743f411aa2b7278d1f1b3c30b447555ea55b8 :100644 100644 b5908b5a36a4749e0bef2a16a2733a7461a818dc e00ba8738dbf3421288d31c60de9ee42a085c148 M auto-volume.py The first line is the commit hash, and then each subsequent line names a file that changed. The two hashes given are the old version and the new version. Then you can: git cat-file -p b5908b5a36a4749e0bef2a16a2733a7461a818dc and git cat-file -p e00ba8738dbf3421288d31c60de9ee42a085c148 to see the files - hopefully you can pipe that into radon and get the complexities, and calculate the increase or decrease from that. If the file was newly created in that commit, you'll see an initial hash of all zeroes, and instead of "M" before the file name, it'll be "A". Similarly, if a file gets deleted, there'll be "D" and the new hash will be all zeroes. Would that work? ChrisA From rosuav at gmail.com Sun Oct 3 00:20:02 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Oct 2021 15:20:02 +1100 Subject: McCabe complexity for just changed files in a commit? In-Reply-To: References: Message-ID: On Sun, Oct 3, 2021 at 3:18 PM Chris Angelico wrote: > git diff-tree 1af743 > 1af743f411aa2b7278d1f1b3c30b447555ea55b8 > :100644 100644 b5908b5a36a4749e0bef2a16a2733a7461a818dc > e00ba8738dbf3421288d31c60de9ee42a085c148 M auto-volume.py > > The first line is the commit hash, and then each subsequent line names > a file that changed. The two hashes given are the old version and the > new version. Note that these are very long lines, so they don't come out too well in this post, but everything from ":100644" to "auto-volume.py" is a single line of text. ChrisA From hjp-python at hjp.at Sun Oct 3 07:44:20 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 3 Oct 2021 13:44:20 +0200 Subject: Confusing error message: lambda walruses In-Reply-To: References: Message-ID: On 2021-10-03 10:39:38 +1100, Chris Angelico wrote: > Using assignment expressions in lambda functions sometimes works, but > sometimes doesn't. > ... return lambda x: (x, x := 2, x) syntax ok > return lambda: n := 1 syntax error > ... return lambda: (n := 1) syntax ok > return (lambda: n := 1) syntax error > ... return (lambda: (n := 1)), (lambda: n) syntax ok, but doesn't assign ... > What's going on here? I think it's the parentheses: The right side of the lambda is defined as an ?expression?, not an an ?assignment_expression?, and there is no direct derivation from one to the other in the grammar. So you can't put an ?assignment_expression? there directly. But if you put it in parentheses, it becomes a ?starred_item? which is a ?starred_expression? which is then part of the ?parenth_form? which is an ?enclosure? which is an ?atom? which is (through several more steps) an ?expression? which can be used on the right side of a lambda. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hjp-python at hjp.at Sun Oct 3 08:02:18 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 3 Oct 2021 14:02:18 +0200 Subject: Confusing error message: lambda walruses In-Reply-To: References: Message-ID: On 2021-10-03 10:39:38 +1100, Chris Angelico wrote: > # Oh, and it doesn't actually assign anything. > >>> def f(n): > ... return (lambda: (n := 1)), (lambda: n) > ... > >>> g, h = f(5) > >>> h() > 5 > >>> g() > 1 > >>> h() > 5 I thought about that one a bit more and I think that the lambda is creating a new scope, just like a regular function would, so it is assigning to its own private ?n?, not the ?n? in ?f(n)?. https://docs.python.org/3/reference/expressions.html#grammar-token-lambda-expr doesn't mention scope explicitely, but | The unnamed object behaves like a function object defined with: | | def (parameters): | return expression implies to me that it should create a new scope because a nested function defined with ?def? would do that, too. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From Gronicus at SGA.Ninja Mon Oct 4 04:39:09 2021 From: Gronicus at SGA.Ninja (Steve) Date: Mon, 4 Oct 2021 04:39:09 -0400 Subject: matplotlib graph white space Message-ID: <000701d7b8fb$4d5ef5d0$e81ce170$@SGA.Ninja> I am using the first bar graph listed at this site: https://matplotlib.org/stable/gallery/index.html The problem I have is that there is too much white space around the graph. My data would be better displayed if I could widen the graph into the space to the right and left of the chart. Steve From mal at europython.eu Mon Oct 4 08:35:41 2021 From: mal at europython.eu (Marc-Andre Lemburg) Date: Mon, 4 Oct 2021 14:35:41 +0200 Subject: EuroPython 2021: Edited videos of the second day available Message-ID: <7a9fbec9-683e-086e-6699-37eb1862ae4a@europython.eu> We?re happy to release another batch of 35 cut videos of EuroPython 2021 covering most of the second day sessions of the conference. Together with the first day videos, we now have 77 videos waiting for you. You can watch them on our YouTube channel: * EuroPython 2021 Playlist * https://www.youtube.com/playlist?list=PL8uoeex94UhFuRtXhkqOrROsdNI6ejuiq We?ll release the final batch of EuroPython 2021 videos next week. In total, we will have more than 115 videos with lots of valuable and interesting content for you, so please stop by and check the playlist for more videos, or subscribe to our YouTube channel. https://europython.tv/ BTW: Our YouTube channel has videos of all EuroPython conferences going back to 2011. Check out more than 1500 Python videos covering 10 conference years. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/europython-2021-edited-videos-of-the-second-day-available/ Tweet: https://twitter.com/europython/status/1445003583116791810 Enjoy, -- EuroPython 2021 Team https://ep2021.europython.eu/ https://www.europython-society.org/ From david at lowryduda.com Mon Oct 4 09:55:52 2021 From: david at lowryduda.com (David Lowry-Duda) Date: Mon, 4 Oct 2021 09:55:52 -0400 Subject: matplotlib graph white space In-Reply-To: <000701d7b8fb$4d5ef5d0$e81ce170$@SGA.Ninja> References: <000701d7b8fb$4d5ef5d0$e81ce170$@SGA.Ninja> Message-ID: > I am using the first bar graph listed at this site: > https://matplotlib.org/stable/gallery/index.html > > The problem I have is that there is too much white space around the graph. > My data would be better displayed if I could widen the graph into the space > to the right and left of the chart. It sounds like you're asking about changing the size and dimension of a graph. Is that right? Then I suggest looking into `figsize` when creating a figure (especially if you are using the object oriented interface). Alternately, you can adjust the size of a figure afterwards with `fig.set_size_inches` (and variants), and you can get the figure if you are using the matlab-style interface with `matplotlib.pyplot.gcf()`. - DLD From Gronicus at SGA.Ninja Mon Oct 4 11:39:11 2021 From: Gronicus at SGA.Ninja (Steve) Date: Mon, 4 Oct 2021 11:39:11 -0400 Subject: matplotlib graph white space In-Reply-To: <20211004115549.jimxzl65por64uyf@gem> References: <000701d7b8fb$4d5ef5d0$e81ce170$@SGA.Ninja> <20211004115549.jimxzl65por64uyf@gem> Message-ID: <003301d7b935$fb20b930$f1622b90$@SGA.Ninja> Yes, I saw that but it is a change for all sides. Is there a setting to change just the left and right padding? -----Original Message----- From: Michel Alwan Sent: Monday, October 4, 2021 7:56 AM To: Steve Cc: python-list at python.org Subject: Re: matplotlib graph white space In the plot window, you can click on the settings (up), and select the option "tight layout" by pressing that button... I think this is what you are looking for... On 21/10/04 04:39AM, Steve wrote: > > I am using the first bar graph listed at this site: > https://matplotlib.org/stable/gallery/index.html > > The problem I have is that there is too much white space around the graph. > My data would be better displayed if I could widen the graph into the > space to the right and left of the chart. > > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list -- Michel Alwan ( support Stallman : stallmansupport.org ) From pablogsal at gmail.com Mon Oct 4 17:03:44 2021 From: pablogsal at gmail.com (Pablo Galindo Salgado) Date: Mon, 4 Oct 2021 22:03:44 +0100 Subject: [RELEASE] Python 3.10.0 is available Message-ID: On behalf of the Python development community and the Python 3.10 release team, I?m pleased to announce the availability of Python 3.10.0. Python 3.10.0 is the newest major release of the Python programming language, and it contains many new features and optimizations. https://www.python.org/downloads/release/python-3100/ # Major new features of the 3.10 series, compared to 3.9 Among the new major new features and changes so far: * [PEP 623](https://www.python.org/dev/peps/pep-0623/) -- Deprecate and prepare for the removal of the wstr member in PyUnicodeObject. * [PEP 604](https://www.python.org/dev/peps/pep-0604/) -- Allow writing union types as X | Y * [PEP 612](https://www.python.org/dev/peps/pep-0612/) -- Parameter Specification Variables * [PEP 626](https://www.python.org/dev/peps/pep-0626/) -- Precise line numbers for debugging and other tools. * [PEP 618 ](https://www.python.org/dev/peps/pep-0618/) -- Add Optional Length-Checking To zip. * [bpo-12782](https://bugs.python.org/issue12782): Parenthesized context managers are now officially allowed. * [PEP 632 ](https://www.python.org/dev/peps/pep-0632/) -- Deprecate distutils module. * [PEP 613 ](https://www.python.org/dev/peps/pep-0613/) -- Explicit Type Aliases * [PEP 634 ](https://www.python.org/dev/peps/pep-0634/) -- Structural Pattern Matching: Specification * [PEP 635 ](https://www.python.org/dev/peps/pep-0635/) -- Structural Pattern Matching: Motivation and Rationale * [PEP 636 ](https://www.python.org/dev/peps/pep-0636/) -- Structural Pattern Matching: Tutorial * [PEP 644 ](https://www.python.org/dev/peps/pep-0644/) -- Require OpenSSL 1.1.1 or newer * [PEP 624 ](https://www.python.org/dev/peps/pep-0624/) -- Remove Py_UNICODE encoder APIs * [PEP 597 ](https://www.python.org/dev/peps/pep-0597/) -- Add optional EncodingWarning [bpo-38605](https://bugs.python.org/issue38605): `from __future__ import annotations` ([PEP 563](https://www.python.org/dev/peps/pep-0563/)) used to be on this list in previous pre-releases but it has been postponed to Python 3.11 due to some compatibility concerns. You can read the Steering Council communication about it [here]( https://mail.python.org/archives/list/python-dev at python.org/thread/CLVXXPQ2T2LQ5MP2Y53VVQFCXYWQJHKZ/) to learn more. # More resources * [Changelog](https://docs.python.org/3.10/whatsnew/changelog.html#changelog ) * [Online Documentation](https://docs.python.org/3.10/) * [PEP 619](https://www.python.org/dev/peps/pep-0619/), 3.10 Release Schedule * Report bugs at [https://bugs.python.org](https://bugs.python.org). * [Help fund Python and its community](/psf/donations/). # And now for something completely different For a Schwarzschild black hole (a black hole with no rotation or electromagnetic charge), given a free fall particle starting at the event horizon, the maximum propper time it will experience to fall into (which happens when it falls without angular velocity) the singularity is `?*M` (in [natural units](https://en.wikipedia.org/wiki/Natural_units)), where M is the mass of the black hole. For Sagittarius A* (the black hole at the center of the milky way) this time is approximately 1 minute. Schwarzschild black holes are also unique because they have a space-like singularity at their core, which means that the singularity doesn't happen at a specific point in *space* but happens at a specific point in *time* (the future). This means once you are inside the event horizon you cannot point with your finger towards the direction the singularity is located because the singularity happens in your future: no matter where you move, you will "fall" into it. # We hope you enjoy the new releases! Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. https://www.python.org/psf/ # More resources Online Documentation https://docs.python.org/3.10/ PEP 619 https://www.python.org/dev/peps/pep-0619/, 3.10 Release Schedule Report bugs at https://bugs.python.org https://bugs.python.org/. Help fund Python and its community https://www.python.org/psf/donations/. Your friendly release team, Ned Deily @nad https://discuss.python.org/u/nad Steve Dower @steve.dower https://discuss.python.org/u/steve.dower Pablo Galindo Salgado @pablogsal https://discuss.python.org/u/pablogsal From ingy at ingy.net Mon Oct 4 18:27:50 2021 From: ingy at ingy.net (Ingy dot Net) Date: Mon, 4 Oct 2021 18:27:50 -0400 Subject: [ANN] PyYAML-6.0b1 Released Message-ID: ======================= Announcing PyYAML-6.0b1 ======================= A new beta release of PyYAML is now available: https://github.com/yaml/pyyaml/releases/tag/6.0b1 The previously-deprecated default loader selection in `yaml.load()` has been removed; `Loader` is now a required argument. Support for Python 2.7 and 3.5 has been dropped, and support for Python 3.10 added. It now includes libyaml 0.2.5 extension wheels for MacOS M1 (Apple Silicon/arm64), Linux s390x and Linux aarch64. Numerous other bugfixes and code cleanups are included in this release. Changes ======= * https://github.com/yaml/pyyaml/pull/327 -- Change README format to Markdown * https://github.com/yaml/pyyaml/pull/483 -- Add a test for YAML 1.1 types * https://github.com/yaml/pyyaml/pull/497 -- fix float resolver to ignore `.` and `._` * https://github.com/yaml/pyyaml/pull/550 -- drop Python 2.7 * https://github.com/yaml/pyyaml/pull/553 -- Fix spelling of ?hexadecimal? * https://github.com/yaml/pyyaml/pull/556 -- fix representation of Enum subclasses * https://github.com/yaml/pyyaml/pull/557 -- fix libyaml extension compiler warnings * https://github.com/yaml/pyyaml/pull/560 -- fix ResourceWarning on leaked file descriptors * https://github.com/yaml/pyyaml/pull/561 -- always require `Loader` arg to `yaml.load()` * https://github.com/yaml/pyyaml/pull/564 -- remove remaining direct distutils usage Resources ========= PyYAML Matrix: https://matrix.to/#/#pyyaml:yaml.io PyYAML IRC Channel: #pyyaml on irc.libera.chat PyYAML homepage: https://github.com/yaml/pyyaml PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation Source and binary installers: https://pypi.org/project/PyYAML/ GitHub repository: https://github.com/yaml/pyyaml/ Bug tracking: https://github.com/yaml/pyyaml/issues YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML ============ YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistence. Example ======= ``` >>> import yaml >>> yaml.full_load(""" ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: https://github.com/yaml/pyyaml ... keywords: [YAML, serialization, configuration, persistence, pickle] ... """) {'keywords': ['YAML', 'serialization', 'configuration', 'persistence', 'pickle'], 'homepage': 'https://github.com/yaml/pyyaml', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} >>> print(yaml.dump(_)) name: PyYAML homepage: https://github.com/yaml/pyyaml description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistence, pickle] ``` Maintainers =========== The following people are currently responsible for maintaining PyYAML: * Ingy d?t Net * Matt Davis and many thanks to all who have contributed! See: https://github.com/yaml/pyyaml/pulls Copyright ========= Copyright (c) 2017-2021 Ingy d?t Net Copyright (c) 2006-2016 Kirill Simonov The PyYAML module was written by Kirill Simonov . It is currently maintained by the YAML and Python communities. PyYAML is released under the MIT license. See the file LICENSE for more details. From miked at dewhirst.com.au Mon Oct 4 18:56:04 2021 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Tue, 5 Oct 2021 09:56:04 +1100 Subject: pythonpapers.org domain name to lapse in November Message-ID: The board of editors of the Python Papers has decided to let the pythonpapers.org domain name to lapse. It will not be renewed in November. Anyone interested in it can get in touch. Cheers Mike -- Signed email is an absolute defence against phishing. This email has been signed with my private key. If you import my public key you can automatically decrypt my signature and be sure it came from me. Just ask and I'll send it to you. Your email software can handle signing. -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 495 bytes Desc: OpenPGP digital signature URL: From kushal at locationd.net Tue Oct 5 00:36:53 2021 From: kushal at locationd.net (Kushal Kumaran) Date: Mon, 04 Oct 2021 21:36:53 -0700 Subject: McCabe complexity for just changed files in a commit? In-Reply-To: (Dan Stromberg's message of "Sat, 2 Oct 2021 21:05:47 -0700") References: Message-ID: <87fstgxf2y.fsf@locationd.net> On Sat, Oct 02 2021 at 09:05:47 PM, Dan Stromberg wrote: > Hi folks. > > Is there a way of getting the McCabe Complexity of just the functions and > methods (in Python) changed in a git commit? > > I found radon, and it looks good. But I think it wants to do entire files, > no? > Calculate your metric for this commit, calculate metric for parent commit, and take the difference? That's how we do coverage metrics to report stuff like "change increases/decreases coverage by N%". -- regards, kushal From rosuav at gmail.com Tue Oct 5 00:55:22 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 5 Oct 2021 15:55:22 +1100 Subject: McCabe complexity for just changed files in a commit? In-Reply-To: <87fstgxf2y.fsf@locationd.net> References: <87fstgxf2y.fsf@locationd.net> Message-ID: On Tue, Oct 5, 2021 at 3:44 PM Kushal Kumaran wrote: > > On Sat, Oct 02 2021 at 09:05:47 PM, Dan Stromberg wrote: > > Hi folks. > > > > Is there a way of getting the McCabe Complexity of just the functions and > > methods (in Python) changed in a git commit? > > > > I found radon, and it looks good. But I think it wants to do entire files, > > no? > > > > Calculate your metric for this commit, calculate metric for parent > commit, and take the difference? That's how we do coverage metrics to > report stuff like "change increases/decreases coverage by N%". > What if it has multiple parents, like a merge commit that resolves conflicts? (A merge that doesn't make any other changes won't affect coverage or complexity, since it's all done by the commits on either side.) ChrisA From kushal at locationd.net Tue Oct 5 01:36:25 2021 From: kushal at locationd.net (Kushal Kumaran) Date: Mon, 04 Oct 2021 22:36:25 -0700 Subject: McCabe complexity for just changed files in a commit? In-Reply-To: (Chris Angelico's message of "Tue, 5 Oct 2021 15:55:22 +1100") References: <87fstgxf2y.fsf@locationd.net> Message-ID: <87lf389go6.fsf@locationd.net> On Tue, Oct 05 2021 at 03:55:22 PM, Chris Angelico wrote: > On Tue, Oct 5, 2021 at 3:44 PM Kushal Kumaran wrote: >> >> On Sat, Oct 02 2021 at 09:05:47 PM, Dan Stromberg wrote: >> > Hi folks. >> > >> > Is there a way of getting the McCabe Complexity of just the functions and >> > methods (in Python) changed in a git commit? >> > >> > I found radon, and it looks good. But I think it wants to do entire files, >> > no? >> > >> >> Calculate your metric for this commit, calculate metric for parent >> commit, and take the difference? That's how we do coverage metrics to >> report stuff like "change increases/decreases coverage by N%". >> > > What if it has multiple parents, like a merge commit that resolves conflicts? > > (A merge that doesn't make any other changes won't affect coverage or > complexity, since it's all done by the commits on either side.) > In my usecases, merges are asymmetric: one of the parents is useful for reporting metric changes, and the others are not. The parent of interest will be whichever parent was on the mainline branch (first parent). Whether the merge commit resolved conflicts or not makes no difference here. In practice, this does not involve doing commit math. The point where this kind of thing is done is in context of a pull request, where it is clearer what commits you're interested in comparing. When merging branch X into branch Y, the tools only need to look at the heads of those branches. https://github.com/vuejs/vue/pull/9373 is a random example of the kind of thing I'm thinking of. -- regards, kushal From Karsten.Hilbert at gmx.net Tue Oct 5 16:34:32 2021 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Tue, 5 Oct 2021 22:34:32 +0200 Subject: Definitive guide for Regex In-Reply-To: References: Message-ID: Am Thu, Sep 30, 2021 at 12:29:16PM +0100 schrieb Shaozhong SHI: > I am trying to look for a definitive guide for Regex in Python. > Can anyone help? If you tell us what you tried in order to look we can perhaps guide you on how to take a better look. Spoonfeeding doesn't seem to be a well-liked activity, neither here nor on the PostgreSQL lists. Best, Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From hongyi.zhao at gmail.com Sun Oct 3 01:16:17 2021 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Sat, 2 Oct 2021 22:16:17 -0700 (PDT) Subject: Understanding the working mechanis of python unary arithmetic operators. In-Reply-To: <5a02d664-8887-41f4-b5ab-558b78f67e25n@googlegroups.com> References: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> <5a02d664-8887-41f4-b5ab-558b78f67e25n@googlegroups.com> Message-ID: <337cac0c-bbd9-4b27-8d42-5590361e8a48n@googlegroups.com> On Sunday, October 3, 2021 at 3:05:23 AM UTC+8, ju... at diegidio.name wrote: > On Saturday, 2 October 2021 at 14:48:39 UTC+2, hongy... at gmail.com wrote: > > On Saturday, October 2, 2021 at 4:59:54 PM UTC+8, ju... at diegidio.name wrote: > > > On Saturday, 2 October 2021 at 10:34:27 UTC+2, hongy... at gmail.com wrote: > > > > See the following testings: > > > > > > > > In [24]: a=3.1415926535897932384626433832795028841971 > > > > In [27]: -a > > > > Out[27]: -3.141592653589793 > > > > > > You've never heard of floating-point? Double precision has 53 significant bits of mantissa, corresponding approximately to 16 decimal digits. > > > > > > > > > > In [17]: ~-+1 > > > > Out[17]: 0 > > > > > > << The unary ~ (invert) operator yields the bitwise inversion of its integer argument. The bitwise inversion of x is defined as -(x+1). It only applies to integral numbers or to custom objects that override the __invert__() special method. >> > > > > > > > > > > I'm very puzzled by these operators. Any hints will be highly appreciated. > > > > > > Try and read the proverbial manual: that's truly a fundamental skill... > > > > Thank you for your explanation. Then what about the following questions?: > > > > 1. Should `+' and `-' be classified as binary operators or unary operators? > "Symbol overloading": a+b is binary *addition*, +a is unary *identity* (or however you may like to call it). The meaning of a symbol or name depends on context. As I understand now, it can be used to identify/normalize the operand by the corresponding precision in the given context. > > As we all know, `a + b', and `a - b' are the normal ways we do basic arithmetic operations. > Nonsense. You yourself wrote ~(-(+1)) above, just without parentheses. Thank you for pointing out my contradictory assertion. > > 2. See the following testings: > Read the bloody manual. > > Given that: > int(True) = 1 > int(False) = 0 > > and that: > bool(x) is True iff x <> 0 In [8]: bool(None) Out[8]: False In [9]: bool('') Out[9]: False In [10]: bool(0) Out[10]: False So, bool(x) is True iff x <> 0 , None, and '', as shown here [1]: In [3]: import numpy as np In [11]: np.array([1, 0.5, 0, None, 'a', '', True, False], dtype=bool) Out[11]: array([ True, True, False, False, True, False, True, False]) [1] https://riptutorial.com/numpy/example/21181/creating-a-boolean-array#example > and that: > ~~x = x for all x (integer) > > These: > ~1 = -(1+1) = -2 > ~~1 = ~-2 = -(-2+1) = 1 > ~~~1 = ~1 = -2 > ... > all evaluate to True. > > And these: > ~0 = -(0+1) = -1 > ~~0 = ~-1 = -(-1+1) = 0 > ~~~0 = ~0 = -1 > ... > evaluate to True and False alternatingly. > > In short, ~1=-2 (and ~-2=1) and 1 and -2 both convert to True, while ~0=1 but 0 converts to False while 1 converts to True. > > Why can?t/shouldn't we get something similar results for both `True' and `False' in the above testings? > Because bitwise complement is not symmetric around 0. For comparison, try with negation instead. Thanks again. I see, as follows: In [1]: ~1 Out[1]: -2 In [2]: ~-1 Out[2]: 0 > But don't just guess, try and unpack those expressions while trying and reading the docs: which is a necessary skill in itself. Thank you for the advice that showed me the way to truth. HZ From hongyi.zhao at gmail.com Sun Oct 3 02:18:05 2021 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Sat, 2 Oct 2021 23:18:05 -0700 (PDT) Subject: Understanding the working mechanis of python unary arithmetic operators. In-Reply-To: References: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> Message-ID: <0910a4c5-bf29-4101-8de9-2315682d98fan@googlegroups.com> On Saturday, October 2, 2021 at 4:59:54 PM UTC+8, ju... at diegidio.name wrote: > On Saturday, 2 October 2021 at 10:34:27 UTC+2, hongy... at gmail.com wrote: > > See the following testings: > > > > In [24]: a=3.1415926535897932384626433832795028841971 > > In [27]: -a > > Out[27]: -3.141592653589793 > You've never heard of floating-point? Double precision has 53 significant bits of mantissa, corresponding approximately to 16 decimal digits. > > > In [17]: ~-+1 > > Out[17]: 0 > << The unary ~ (invert) operator yields the bitwise inversion of its integer argument. The bitwise inversion of x is defined as -(x+1). It only applies to integral numbers or to custom objects that override the __invert__() special method. >> > A further inference based on the above description: Let us consider this equation: -(x+1) = x, the solution is -0.5, which is not an integer. So we can safely come to a conclusion: If bool(a) == True, \forall a \in integer, then ~bool(a) == False; and vice versa. This is exactly the theoretical basis to filter some specific columns in pandas, just as the issue discussed here [1]. [1] https://github.com/pandas-dev/pandas/issues/43832#issue-1013375587 HZ From hongyi.zhao at gmail.com Sun Oct 3 05:24:45 2021 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Sun, 3 Oct 2021 02:24:45 -0700 (PDT) Subject: Understanding the working mechanis of python unary arithmetic operators. In-Reply-To: <0910a4c5-bf29-4101-8de9-2315682d98fan@googlegroups.com> References: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> <0910a4c5-bf29-4101-8de9-2315682d98fan@googlegroups.com> Message-ID: <8e5df6b9-e157-4dd3-ad92-9646774afcean@googlegroups.com> On Sunday, October 3, 2021 at 2:18:17 PM UTC+8, hongy... at gmail.com wrote: > On Saturday, October 2, 2021 at 4:59:54 PM UTC+8, ju... at diegidio.name wrote: > > On Saturday, 2 October 2021 at 10:34:27 UTC+2, hongy... at gmail.com wrote: > > > See the following testings: > > > > > > In [24]: a=3.1415926535897932384626433832795028841971 > > > In [27]: -a > > > Out[27]: -3.141592653589793 > > You've never heard of floating-point? Double precision has 53 significant bits of mantissa, corresponding approximately to 16 decimal digits. > > > > > In [17]: ~-+1 > > > Out[17]: 0 > > << The unary ~ (invert) operator yields the bitwise inversion of its integer argument. The bitwise inversion of x is defined as -(x+1). It only applies to integral numbers or to custom objects that override the __invert__() special method. >> > > > A further inference based on the above description: > > Let us consider this equation: -(x+1) = x, the solution is -0.5, which is not an integer. So we can safely come to a conclusion: > > If bool(a) == True, \forall a \in integer, then ~bool(a) == False; and vice versa. > > This is exactly the theoretical basis to filter some specific columns in pandas, just as the issue discussed here [1]. Sorry my not very precise description above. I should have wanted to express the fact that I observed below: In [3]: import numpy as np In [15]: ~np.array([True]) Out[15]: array([False]) In [16]: ~np.array([False]) Out[16]: array([ True]) But the normal `True' and `False' don't the good symmetric feature as shown above: In [21]: bool(~True) Out[21]: True In [22]: bool(~False) Out[22]: True > [1] https://github.com/pandas-dev/pandas/issues/43832#issue-1013375587 > > HZ From hongyi.zhao at gmail.com Sun Oct 3 08:21:01 2021 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Sun, 3 Oct 2021 05:21:01 -0700 (PDT) Subject: Understanding the working mechanis of python unary arithmetic operators. In-Reply-To: References: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> <0910a4c5-bf29-4101-8de9-2315682d98fan@googlegroups.com> <8e5df6b9-e157-4dd3-ad92-9646774afcean@googlegroups.com> Message-ID: On Sunday, October 3, 2021 at 6:31:05 PM UTC+8, ju... at diegidio.name wrote: > On Sunday, 3 October 2021 at 11:24:58 UTC+2, hongy... at gmail.com wrote: > > On Sunday, October 3, 2021 at 2:18:17 PM UTC+8, hongy... at gmail.com wrote: > > > On Saturday, October 2, 2021 at 4:59:54 PM UTC+8, ju... at diegidio.name wrote: > > > > On Saturday, 2 October 2021 at 10:34:27 UTC+2, hongy... at gmail.com wrote: > > > > > See the following testings: > > > > > > > > > > In [24]: a=3.1415926535897932384626433832795028841971 > > > > > In [27]: -a > > > > > Out[27]: -3.141592653589793 > > > > You've never heard of floating-point? Double precision has 53 significant bits of mantissa, corresponding approximately to 16 decimal digits. > > > > > > > > > In [17]: ~-+1 > > > > > Out[17]: 0 > > > > << The unary ~ (invert) operator yields the bitwise inversion of its integer argument. The bitwise inversion of x is defined as -(x+1). It only applies to integral numbers or to custom objects that override the __invert__() special method. >> > > > > > > > A further inference based on the above description: > > > > > > Let us consider this equation: -(x+1) = x, the solution is -0.5, which is not an integer. So we can safely come to a conclusion: > > > > > > If bool(a) == True, \forall a \in integer, then ~bool(a) == False; and vice versa. > > > > > > This is exactly the theoretical basis to filter some specific columns in pandas, just as the issue discussed here [1]. > > Sorry my not very precise description above. I should have wanted to express the fact that I observed below: > > In [3]: import numpy as np > > In [15]: ~np.array([True]) > > Out[15]: array([False]) > > > > In [16]: ~np.array([False]) > > Out[16]: array([ True]) > > > > But the normal `True' and `False' don't the good symmetric feature as shown above: > > > > In [21]: bool(~True) > > Out[21]: True > > > > In [22]: bool(~False) > > Out[22]: True > You keep missing the point: > << The unary ~ (invert) operator yields the bitwise inversion of its integer argument. The bitwise inversion of x is defined as -(x+1). It only applies to integral numbers or to custom objects that override the __invert__() special method. >> > Then you can guess that numpy overrides it and gives you *logical* negation of boolean values, I try to dig through the numpy source code to pinning point the overriding/monkey patching/decorating code snippets, as follows: $ rg -A5 -uu 'def __invert__' . ./numpy/__init__.pyi 2022: def __invert__(self: NDArray[bool_]) -> NDArray[bool_]: ... 2023- @overload 2024: def __invert__(self: NDArray[_IntType]) -> NDArray[_IntType]: ... 2025- @overload 2026: def __invert__(self: NDArray[object_]) -> Any: ... 2027- 2028- @overload 2029- def __pos__(self: NDArray[_NumberType]) -> NDArray[_NumberType]: ... 2030- @overload 2031- def __pos__(self: NDArray[timedelta64]) -> NDArray[timedelta64]: ... -- 2885: def __invert__(self) -> bool_: ... 2886- __lshift__: _BoolBitOp[int8] 2887- __rlshift__: _BoolBitOp[int8] 2888- __rshift__: _BoolBitOp[int8] 2889- __rrshift__: _BoolBitOp[int8] 2890- __and__: _BoolBitOp[bool_] -- 2993: def __invert__(self: _IntType) -> _IntType: ... 2994- # Ensure that objects annotated as `integer` support bit-wise operations 2995- def __lshift__(self, other: _IntLike_co) -> integer: ... 2996- def __rlshift__(self, other: _IntLike_co) -> integer: ... 2997- def __rshift__(self, other: _IntLike_co) -> integer: ... 2998- def __rrshift__(self, other: _IntLike_co) -> integer: ... ./numpy/array_api/_array_object.py 510: def __invert__(self: Array, /) -> Array: 511- """ 512- Performs the operation __invert__. 513- """ 514- if self.dtype not in _integer_or_boolean_dtypes: 515- raise TypeError("Only integer or boolean dtypes are allowed in __invert__") ./numpy/lib/user_array.py 179: def __invert__(self): 180- return self._rc(invert(self.array)) 181- 182- def _scalarfunc(self, func): 183- if self.ndim == 0: 184- return func(self[0]) ./numpy/lib/mixins.pyi 62: def __invert__(self): ... Which is corresponding to the overriding mentioned above by you? > while on primitives you get the usual *arithmetic* behaviour, where bool(~False) implicitly is bool(~int(False)) = bool(~0) = bool(-1) = True. Implicit cast happens here automatically. > Please take note: (typically!) ~ denotes a bitwise operation on integers, not logical negation on booleans. Thank you for stressing the point again. HZ From hongyi.zhao at gmail.com Sun Oct 3 09:55:02 2021 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Sun, 3 Oct 2021 06:55:02 -0700 (PDT) Subject: Understanding the working mechanis of python unary arithmetic operators. In-Reply-To: <04aebfa3-e686-4fc8-ae4b-4472d35f0bf3n@googlegroups.com> References: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> <0910a4c5-bf29-4101-8de9-2315682d98fan@googlegroups.com> <8e5df6b9-e157-4dd3-ad92-9646774afcean@googlegroups.com> <04aebfa3-e686-4fc8-ae4b-4472d35f0bf3n@googlegroups.com> Message-ID: On Sunday, October 3, 2021 at 8:38:16 PM UTC+8, ju... at diegidio.name wrote: > On Sunday, 3 October 2021 at 14:21:13 UTC+2, hongy... at gmail.com wrote: > > On Sunday, October 3, 2021 at 6:31:05 PM UTC+8, ju... at diegidio.name wrote: > > > > Then you can guess that numpy overrides it and gives you *logical* negation of boolean values, > > > > I try to dig through the numpy source code to pinning point the overriding/monkey patching/decorating code snippets, as follows: > And you keep missing the point: look up numpy's *documentation* for that, not any source code. I find the relevant explanation here [1]: numpy.invert [...] Compute bit-wise inversion, or bit-wise NOT, element-wise. Computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays. This ufunc implements the C/Python operator ~. [...] The ~ operator can be used as a shorthand for np.invert on ndarrays. x1 = np.array([True, False]) ~x1 array([False, True]) [1] https://numpy.org/doc/stable/reference/generated/numpy.invert.html#numpy-invert HZ From unixnut at witheredfire.com Sun Oct 3 17:03:19 2021 From: unixnut at witheredfire.com (Unixnut) Date: Sun, 3 Oct 2021 22:03:19 +0100 Subject: Does loading PDB slow down execution? Message-ID: Hi all, If I run a python3 program with "import pdb" in the code, would it execute slower than without loading the debugger? The program I am running is computationally expensive and mathematically orientated. It is expected to run for a few months (I am a few days in). I found out today that I forgot to comment out the "import pdb" while debugging, and now I am wondering if there would be a performance benefit worth restarting the execution with pdb unloaded. I have tried testing this with a simple sum executable, but I don't see a clear difference with short execution times (<5 mins). Before I investigate further, I thought I would ask and see if anyone knows the answer already. Many thanks! From hongyi.zhao at gmail.com Sun Oct 3 20:24:44 2021 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Sun, 3 Oct 2021 17:24:44 -0700 (PDT) Subject: Understanding the working mechanis of python unary arithmetic operators. In-Reply-To: References: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> <0910a4c5-bf29-4101-8de9-2315682d98fan@googlegroups.com> <8e5df6b9-e157-4dd3-ad92-9646774afcean@googlegroups.com> <04aebfa3-e686-4fc8-ae4b-4472d35f0bf3n@googlegroups.com> Message-ID: <1e02c882-3cc0-410e-b988-e5f12d338397n@googlegroups.com> On Sunday, October 3, 2021 at 9:55:15 PM UTC+8, hongy... at gmail.com wrote: > On Sunday, October 3, 2021 at 8:38:16 PM UTC+8, ju... at diegidio.name wrote: > > On Sunday, 3 October 2021 at 14:21:13 UTC+2, hongy... at gmail.com wrote: > > > On Sunday, October 3, 2021 at 6:31:05 PM UTC+8, ju... at diegidio.name wrote: > > > > > > Then you can guess that numpy overrides it and gives you *logical* negation of boolean values, > > > > > > I try to dig through the numpy source code to pinning point the overriding/monkey patching/decorating code snippets, as follows: > > And you keep missing the point: look up numpy's *documentation* for that, not any source code. > I find the relevant explanation here [1]: > > numpy.invert > [...] > Compute bit-wise inversion, or bit-wise NOT, element-wise. > > Computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays. This ufunc implements the C/Python operator ~. > [...] > The ~ operator can be used as a shorthand for np.invert on ndarrays. > > x1 = np.array([True, False]) > > ~x1 > array([False, True]) > > [1] https://numpy.org/doc/stable/reference/generated/numpy.invert.html#numpy-invert Or use the following commands in IPython: import numpy as np np.invert? np.info(np.invert) > HZ From Cecil at decebal.nl Mon Oct 4 06:31:21 2021 From: Cecil at decebal.nl (Cecil Westerhof) Date: Mon, 04 Oct 2021 12:31:21 +0200 Subject: Big jump in version Message-ID: <87bl45hyiu.fsf@munus.decebal.nl> When I run: pip3 list --outdated I get: Package Version Latest Type ------------ ------- ------ ----- cryptography 3.4.8 35.0.0 wheel pyzstd 0.14.4 0.15.0 wheel The jump from 3 to 35 seems a bit excessive to me. Or is it correct? On a side node. I have not updated pyzstd for a long time, because that breaks py7zr which needs a version lower as 0.15.0. Any chance that py7zr is going to be updated? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From michel at jagajaga.org Mon Oct 4 07:55:49 2021 From: michel at jagajaga.org (Michel Alwan) Date: Mon, 4 Oct 2021 12:55:49 +0100 Subject: matplotlib graph white space In-Reply-To: <000701d7b8fb$4d5ef5d0$e81ce170$@SGA.Ninja> References: <000701d7b8fb$4d5ef5d0$e81ce170$@SGA.Ninja> Message-ID: <20211004115549.jimxzl65por64uyf@gem> In the plot window, you can click on the settings (up), and select the option "tight layout" by pressing that button... I think this is what you are looking for... On 21/10/04 04:39AM, Steve wrote: > > I am using the first bar graph listed at this site: > https://matplotlib.org/stable/gallery/index.html > > The problem I have is that there is too much white space around the graph. > My data would be better displayed if I could widen the graph into the space > to the right and left of the chart. > > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list -- Michel Alwan ( support Stallman : stallmansupport.org ) From michel at jagajaga.org Mon Oct 4 15:45:07 2021 From: michel at jagajaga.org (Michel Alwan) Date: Mon, 4 Oct 2021 20:45:07 +0100 Subject: matplotlib graph white space In-Reply-To: <003301d7b935$fb20b930$f1622b90$@SGA.Ninja> References: <000701d7b8fb$4d5ef5d0$e81ce170$@SGA.Ninja> <20211004115549.jimxzl65por64uyf@gem> <003301d7b935$fb20b930$f1622b90$@SGA.Ninja> Message-ID: <20211004194507.klnylsnx47f2ifrs@gem> u can adjust any side with the other options... (margins) if you don t want to use tight layout... On 21/10/04 11:39AM, Steve wrote: > > Yes, I saw that but it is a change for all sides. > Is there a setting to change just the left and right padding? > > > > > -----Original Message----- > From: Michel Alwan > Sent: Monday, October 4, 2021 7:56 AM > To: Steve > Cc: python-list at python.org > Subject: Re: matplotlib graph white space > > In the plot window, you can click on the settings (up), and select the > option "tight layout" by pressing that button... I think this is what you > are looking for... > > > On 21/10/04 04:39AM, Steve wrote: > > > > I am using the first bar graph listed at this site: > > https://matplotlib.org/stable/gallery/index.html > > > > The problem I have is that there is too much white space around the graph. > > My data would be better displayed if I could widen the graph into the > > space to the right and left of the chart. > > > > Steve > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > -- > Michel Alwan > > > ( support Stallman : stallmansupport.org ) > -- Michel Alwan ( support Stallman : stallmansupport.org ) From mohsen.owzar at gmail.com Tue Oct 5 03:04:05 2021 From: mohsen.owzar at gmail.com (Mohsen Owzar) Date: Tue, 5 Oct 2021 00:04:05 -0700 (PDT) Subject: Open a new window by mouse clicking in the QLineEdit field and not by clicking of a button Message-ID: Hi all, I'm looking for an approach, but couldn't find any appropriate answer to my problem: On my GUI on a tablet, I have bunch of QlineEdit widgets for the settings of my task. Because we have no keyboard connected to the tablet, I have put two buttons ("+" and "-") around each QLineEdit widget to increase or decrease its value. When the target value is far away from the displayed one in the QLineEdit, I have to click lots of times to reach the end value. Due to this ugliness feature, I wanted to offer to the user the possibility to click in the edit field to get another window with a numeric keypad to type the target value. And then by clicking an OK button, the new window will be closed and the typed value will be taken into the QLineEdit widget of my original GUI. In all my searches, I found examples to open new windows by clicking a button and not by clicking in an edit field. I used the following line to have an edit field on window1. self.text_from_window2 = QLineEdit('Setting Value') And wanted to open another window (window2) in which I programmed a numeric keypad. By typing the desired value on this keypad and enter OK, this value should be taken to the edit field of window1. But the following line brings an error that QLineEdit has no attribute "clicked". self.text_from_window2.clicked().connect(self.show_keypad_window) I tried to use other attributes like focus, textChanged or textEdited. None of them could help me. Is it at all possible to use QLineEdit with mouse click to generate an action (open new window)? Has anyone an example of such a code snippet? I am very curious to see if someone has a solution to my problem. Regards Mohsen From grant.b.edwards at gmail.com Tue Oct 5 17:03:50 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 05 Oct 2021 14:03:50 -0700 (PDT) Subject: Big jump in version References: <87bl45hyiu.fsf@munus.decebal.nl> Message-ID: <615cbdb6.1c69fb81.3feb7.acdf@mx.google.com> On 2021-10-04, Cecil Westerhof via Python-list wrote: > When I run: > pip3 list --outdated > > I get: > Package Version Latest Type > ------------ ------- ------ ----- > cryptography 3.4.8 35.0.0 wheel > > The jump from 3 to 35 seems a bit excessive to me. Or is it correct? https://cryptography.io/en/latest/changelog/ From rosuav at gmail.com Tue Oct 5 17:10:01 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Oct 2021 08:10:01 +1100 Subject: Understanding the working mechanis of python unary arithmetic operators. In-Reply-To: <0910a4c5-bf29-4101-8de9-2315682d98fan@googlegroups.com> References: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> <0910a4c5-bf29-4101-8de9-2315682d98fan@googlegroups.com> Message-ID: On Wed, Oct 6, 2021 at 7:52 AM hongy... at gmail.com wrote: > > On Saturday, October 2, 2021 at 4:59:54 PM UTC+8, ju... at diegidio.name wrote: > > On Saturday, 2 October 2021 at 10:34:27 UTC+2, hongy... at gmail.com wrote: > > > See the following testings: > > > > > > In [24]: a=3.1415926535897932384626433832795028841971 > > > In [27]: -a > > > Out[27]: -3.141592653589793 > > You've never heard of floating-point? Double precision has 53 significant bits of mantissa, corresponding approximately to 16 decimal digits. > > > > > In [17]: ~-+1 > > > Out[17]: 0 > > << The unary ~ (invert) operator yields the bitwise inversion of its integer argument. The bitwise inversion of x is defined as -(x+1). It only applies to integral numbers or to custom objects that override the __invert__() special method. >> > > > > A further inference based on the above description: > > Let us consider this equation: -(x+1) = x, the solution is -0.5, which is not an integer. So we can safely come to a conclusion: > > If bool(a) == True, \forall a \in integer, then ~bool(a) == False; and vice versa. > If bool(a) is True, then ~bool(a) is exactly the same as writing ~True, and a has become irrelevant. That is simply how expression evaluation works. ChrisA From barry at barrys-emacs.org Tue Oct 5 17:24:03 2021 From: barry at barrys-emacs.org (Barry) Date: Tue, 5 Oct 2021 22:24:03 +0100 Subject: Open a new window by mouse clicking in the QLineEdit field and not by clicking of a button In-Reply-To: References: Message-ID: > On 5 Oct 2021, at 22:07, Mohsen Owzar wrote: > > ?Hi all, > I'm looking for an approach, but couldn't find any appropriate answer to my problem: > On my GUI on a tablet, I have bunch of QlineEdit widgets for the settings of my task. > Because we have no keyboard connected to the tablet, I have put two buttons ("+" and "-") around each QLineEdit widget to increase or decrease its value. > When the target value is far away from the displayed one in the QLineEdit, I have to click lots of times to reach the end value. > Due to this ugliness feature, I wanted to offer to the user the possibility to click in the edit field to get another window with a numeric keypad to type the target value. And then by clicking an OK button, the new window will be closed and the typed value will be taken into the QLineEdit widget of my original GUI. > In all my searches, I found examples to open new windows by clicking a button and not by clicking in an edit field. What I have done is use mouse move events to change values. I touch the field then drag my finger to change the value. I only use linear scaling but you could have code that can tell slow drag from fast drag and scale the value. > I used the following line to have an edit field on window1. > > self.text_from_window2 = QLineEdit('Setting Value') > > And wanted to open another window (window2) in which I programmed a numeric keypad. By typing the desired value on this keypad and enter OK, this value should be taken to the edit field of window1. > But the following line brings an error that QLineEdit has no attribute "clicked". > > self.text_from_window2.clicked().connect(self.show_keypad_window) > > I tried to use other attributes like focus, textChanged or textEdited. None of them could help me. > Is it at all possible to use QLineEdit with mouse click to generate an action (open new window)? > Has anyone an example of such a code snippet? > I am very curious to see if someone has a solution to my problem. By the way there is a great PyQt mailing list that you might like to join. https://www.riverbankcomputing.com/mailman/listinfo/pyqt Lots of knowledgeable PyQt developers hang out on that list. Barry > > Regards > Mohsen > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Tue Oct 5 19:10:59 2021 From: PythonList at DancesWithMice.info (dn) Date: Wed, 6 Oct 2021 12:10:59 +1300 Subject: Understanding the working mechanis of python unary arithmetic operators. In-Reply-To: References: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> <0910a4c5-bf29-4101-8de9-2315682d98fan@googlegroups.com> Message-ID: <64070f5a-62b4-8368-248e-a9c49cc78f0d@DancesWithMice.info> On 06/10/2021 10.10, Chris Angelico wrote: > On Wed, Oct 6, 2021 at 7:52 AM hongy... at gmail.com wrote: >> >> On Saturday, October 2, 2021 at 4:59:54 PM UTC+8, ju... at diegidio.name wrote: This thread seems to have been very one-sided. Either I've forgotten selective use of the DEL-key, or the above contributor has been forgetting to reply to the list (or didn't intend contribution?) Please share your knowledge with all! >>> On Saturday, 2 October 2021 at 10:34:27 UTC+2, hongy... at gmail.com wrote: > If bool(a) is True, then ~bool(a) is exactly the same as writing > ~True, and a has become irrelevant. That is simply how expression > evaluation works. @Chris and I presented at a recent PUG meeting on the subject of 'operators'. (I was the 'warm-up act', @Chris the 'star'...) I covered unary operators (https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-bitwise-operations) - and very briefly, because that's proportional to their application 'in the real world'. Negation is sometimes used, binary inversion very occasionally, but the 'unary plus' almost never! Thus: >>> a = 3 >>> +a 3 >>> -a -3 Why would one use the plus operator? Particularly when it confuses some, ie if negation changes the sign, won't the unary-plus? >>> b = -3 >>> +b -3 >>> -b 3 What has the unary-plus achieved in either/both of these cases? Not much, but may not be doing something that was 'expected'! The bitwise inversion (~) is also widely misunderstood (just like the story of my life). It is not "bit inversion", as in, a single bit being inverted: (values here are expressed in base-2!) ~0 -> 1 ~1 -> 0 Instead, it involves the inversion of every bit. Thus, if we are talking about a nibble/nybble (because I'm too lazy to type more binary digits): ~0000 -> 1111 ~0001 -> 1110 which accounts for the problem discussed earlier in the thread. To make things work the way you seemed to imagine: ~1111 -> 0000 # and thus, is False ~0000 -> 1111 # and thus, is True ie a bitwise inter-change that works binary ints and booleans. Where some (other) thinking may have come-adrift from Python's model, is the mixing of objects/types, eg the 'truthiness' of any integer other than 0. Also, whilst coercion from one type to another may work satisfactorily in one 'direction', it may not be so amenable in reverse. Another bemusing (OP) point was the concept of "-+~1". I'd never, ever, think of doing that! Hey, maybe that says something about me? The term "unary operator" involves the word "one". Rather than "operator", the "one" is the number of "operands". (yes, you know this) However, having already talked about the infrequency with which unary-operators are employed, the idea of nesting (is that the word?) a series of unary-operators, almost blew my mind. Why? Please show an example scenario... Finally, there is the process of "over-loading" operators. Thus, "1 + 2" translates to "add the value 2 to 1"; whereas "a" + "b" means "concatenate" the two strings. In both cases, the result becomes a third value. When we choose the correct terminology, the words for "+" are different - as are the resultant processes! We could also code "instance_a + instance_b". What does this mean? Addition? Concatenation? Bitwise? If I tell you that both are instances of MyClass, does that answer the question? The only way to work-out what craziness I hold in store, is to find where MyClass is defined and look for the __add__() 'magic method'*. At which point, you discover that the instance-attributes are split into components, and the components merged together in a random sequence, with today's date mixed-in for (no) good measure. * or you could ask me (although neither explanation will have a +impact on your mental health) So, the fact that two object instances, eg an integer and a floating-point number, both utilise the same operator-symbol, enables us to draw analogies (and in this case, probably get it 100% correct), but this does not imply a complete equivalence across-the-board (particularly when crazy-people are let-loose with custom classes! Thus "a" + "b" should not be pronounced "add", even though the operator looks very much like the one we use to add two numbers! For fun, and quickly now, what happens here: 2 + 2 2 + 2.0 2.0 + 2 2.0 + 2.0 "2" + "2" 2 + "2" "2" + 2 (they're all 'the same', except the last two?three - aren't they???) -- Regards, =dn From avigross at verizon.net Tue Oct 5 19:42:56 2021 From: avigross at verizon.net (Avi Gross) Date: Tue, 5 Oct 2021 19:42:56 -0400 Subject: Understanding the working mechanis of python unary arithmetic operators. In-Reply-To: <64070f5a-62b4-8368-248e-a9c49cc78f0d@DancesWithMice.info> References: <4c8c0070-6889-4824-a4c3-a4bced7daa48n@googlegroups.com> <0910a4c5-bf29-4101-8de9-2315682d98fan@googlegroups.com> <64070f5a-62b4-8368-248e-a9c49cc78f0d@DancesWithMice.info> Message-ID: <00c801d7ba42$b9810fd0$2c832f70$@verizon.net> Dave, Just one point. many things are allowed by a language even if normal people would NOT have any reason to do it NOR should use it. Although when used in one context + and - can be considered unary operators, the evaluation may result in successive unary operations being done one after another. Here are examples I just typed: +1 1 +++++1 1 +-+-+-1 -1 ---1 -1 --1 1 Luckily since Python has no ++ or -- pre or post operators, these are legal, albeit a tad weird. -----Original Message----- From: Python-list On Behalf Of dn via Python-list Sent: Tuesday, October 5, 2021 7:11 PM To: python-list at python.org Subject: Re: Understanding the working mechanis of python unary arithmetic operators. On 06/10/2021 10.10, Chris Angelico wrote: > On Wed, Oct 6, 2021 at 7:52 AM hongy... at gmail.com wrote: >> >> On Saturday, October 2, 2021 at 4:59:54 PM UTC+8, ju... at diegidio.name wrote: This thread seems to have been very one-sided. Either I've forgotten selective use of the DEL-key, or the above contributor has been forgetting to reply to the list (or didn't intend contribution?) Please share your knowledge with all! >>> On Saturday, 2 October 2021 at 10:34:27 UTC+2, hongy... at gmail.com wrote: > If bool(a) is True, then ~bool(a) is exactly the same as writing > ~True, and a has become irrelevant. That is simply how expression > evaluation works. @Chris and I presented at a recent PUG meeting on the subject of 'operators'. (I was the 'warm-up act', @Chris the 'star'...) I covered unary operators (https://docs.python.org/3/reference/expressions.html#unary-arithmetic-and-b itwise-operations) - and very briefly, because that's proportional to their application 'in the real world'. Negation is sometimes used, binary inversion very occasionally, but the 'unary plus' almost never! Thus: >>> a = 3 >>> +a 3 >>> -a -3 Why would one use the plus operator? Particularly when it confuses some, ie if negation changes the sign, won't the unary-plus? >>> b = -3 >>> +b -3 >>> -b 3 What has the unary-plus achieved in either/both of these cases? Not much, but may not be doing something that was 'expected'! The bitwise inversion (~) is also widely misunderstood (just like the story of my life). It is not "bit inversion", as in, a single bit being inverted: (values here are expressed in base-2!) ~0 -> 1 ~1 -> 0 Instead, it involves the inversion of every bit. Thus, if we are talking about a nibble/nybble (because I'm too lazy to type more binary digits): ~0000 -> 1111 ~0001 -> 1110 which accounts for the problem discussed earlier in the thread. To make things work the way you seemed to imagine: ~1111 -> 0000 # and thus, is False ~0000 -> 1111 # and thus, is True ie a bitwise inter-change that works binary ints and booleans. Where some (other) thinking may have come-adrift from Python's model, is the mixing of objects/types, eg the 'truthiness' of any integer other than 0. Also, whilst coercion from one type to another may work satisfactorily in one 'direction', it may not be so amenable in reverse. Another bemusing (OP) point was the concept of "-+~1". I'd never, ever, think of doing that! Hey, maybe that says something about me? The term "unary operator" involves the word "one". Rather than "operator", the "one" is the number of "operands". (yes, you know this) However, having already talked about the infrequency with which unary-operators are employed, the idea of nesting (is that the word?) a series of unary-operators, almost blew my mind. Why? Please show an example scenario... Finally, there is the process of "over-loading" operators. Thus, "1 + 2" translates to "add the value 2 to 1"; whereas "a" + "b" means "concatenate" the two strings. In both cases, the result becomes a third value. When we choose the correct terminology, the words for "+" are different - as are the resultant processes! We could also code "instance_a + instance_b". What does this mean? Addition? Concatenation? Bitwise? If I tell you that both are instances of MyClass, does that answer the question? The only way to work-out what craziness I hold in store, is to find where MyClass is defined and look for the __add__() 'magic method'*. At which point, you discover that the instance-attributes are split into components, and the components merged together in a random sequence, with today's date mixed-in for (no) good measure. * or you could ask me (although neither explanation will have a +impact on your mental health) So, the fact that two object instances, eg an integer and a floating-point number, both utilise the same operator-symbol, enables us to draw analogies (and in this case, probably get it 100% correct), but this does not imply a complete equivalence across-the-board (particularly when crazy-people are let-loose with custom classes! Thus "a" + "b" should not be pronounced "add", even though the operator looks very much like the one we use to add two numbers! For fun, and quickly now, what happens here: 2 + 2 2 + 2.0 2.0 + 2 2.0 + 2.0 "2" + "2" 2 + "2" "2" + 2 (they're all 'the same', except the last two?three - aren't they???) -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list From drsalists at gmail.com Tue Oct 5 23:00:31 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 5 Oct 2021 20:00:31 -0700 Subject: python.exe - System Error In-Reply-To: References: Message-ID: Hi. You'll likely get more help if you include more context, like more text in your cut and paste. Also, how did you install it? And where did you get the installer from? HTH. On Thu, Sep 30, 2021 at 8:00 AM jitendrabeura001 wrote: > Hello Sir/Madam, please help me to out from this difficulties, whenever > I'm trying to install python idle it is showing me the error called**** > "[1]python.exe - System Error"****** > I have tried couple of ways to get rid out of this but failed every > time, > please please help me to find the exact solution for this problem. Thank > You. > > References > > Visible links > 1. http://python.exe/ > -- > https://mail.python.org/mailman/listinfo/python-list > From dieter at handshake.de Wed Oct 6 13:30:33 2021 From: dieter at handshake.de (Dieter Maurer) Date: Wed, 6 Oct 2021 19:30:33 +0200 Subject: Does loading PDB slow down execution? In-Reply-To: References: Message-ID: <24925.56633.615436.668290@ixdm.fritz.box> Unixnut wrote at 2021-10-3 22:03 +0100: >If I run a python3 program with "import pdb" in the code, would it >execute slower than without loading the debugger? Importing `pdb` does not slow down the application significantly (it just adds the import time but does not otherwise affect the application). Only when you execute code under debugger control, the execution is significantly slowed down (because the debugger gets informed (via callbacks) about important "event"s (entering a line, function call, function return, exception) during the execution). From tjol at tjol.eu Wed Oct 6 12:32:43 2021 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 6 Oct 2021 18:32:43 +0200 Subject: matplotlib graph white space In-Reply-To: <000701d7b8fb$4d5ef5d0$e81ce170$@SGA.Ninja> References: <000701d7b8fb$4d5ef5d0$e81ce170$@SGA.Ninja> Message-ID: On 04/10/2021 10:39, Steve wrote: > I am using the first bar graph listed at this site: > https://matplotlib.org/stable/gallery/index.html > > The problem I have is that there is too much white space around the graph. > My data would be better displayed if I could widen the graph into the space > to the right and left of the chart. > > Steve > To tweak the amount of padding around the matplotlib axes, you can use pyplot.subplots_adjust [1] or Figure.subplots_adjust [2]. In most cases, the tight_layout function/method [3,4] will give you sensible settings for the various spacing parameters. You probably also have to adjust the figure size (see David Lowry-Duda's reply) to get whatever effect it is that you want. [1] https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots_adjust.html [2] https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure.subplots_adjust [3] https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.tight_layout.html [4] https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure.tight_layout From tjol at tjol.eu Wed Oct 6 12:45:26 2021 From: tjol at tjol.eu (Thomas Jollans) Date: Wed, 6 Oct 2021 18:45:26 +0200 Subject: Confusing error message: lambda walruses In-Reply-To: References: Message-ID: <97233147-d746-96ef-f20a-ec1e45ba6c10@tjol.eu> On 03/10/2021 01:39, Chris Angelico wrote: > Using assignment expressions in lambda functions sometimes works, but > sometimes doesn't. Does this commit by a certain Chris Angelico help clear things up? https://github.com/python/peps/commit/f906b988b20c9a8e7e13a2262f5381bd2b1399e2 From rosuav at gmail.com Wed Oct 6 17:53:58 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Oct 2021 08:53:58 +1100 Subject: Confusing error message: lambda walruses In-Reply-To: <97233147-d746-96ef-f20a-ec1e45ba6c10@tjol.eu> References: <97233147-d746-96ef-f20a-ec1e45ba6c10@tjol.eu> Message-ID: On Thu, Oct 7, 2021 at 8:51 AM Thomas Jollans wrote: > > On 03/10/2021 01:39, Chris Angelico wrote: > > Using assignment expressions in lambda functions sometimes works, but > > sometimes doesn't. > > Does this commit by a certain Chris Angelico help clear things up? > > https://github.com/python/peps/commit/f906b988b20c9a8e7e13a2262f5381bd2b1399e2 No, because the examples I gave don't fit into that :) I was aware of what the PEP originally said. If you try to align the examples with the descriptions in the PEP, you'll find that they don't all match. ChrisA From tjol at tjol.eu Thu Oct 7 01:33:40 2021 From: tjol at tjol.eu (Thomas Jollans) Date: Thu, 7 Oct 2021 07:33:40 +0200 Subject: Confusing error message: lambda walruses In-Reply-To: References: <97233147-d746-96ef-f20a-ec1e45ba6c10@tjol.eu> Message-ID: <06b7ded4-1c50-5e28-9942-f35e90d040b8@tjol.eu> On 06/10/2021 23:53, Chris Angelico wrote: > On Thu, Oct 7, 2021 at 8:51 AM Thomas Jollans wrote: >> On 03/10/2021 01:39, Chris Angelico wrote: >>> Using assignment expressions in lambda functions sometimes works, but >>> sometimes doesn't. >> Does this commit by a certain Chris Angelico help clear things up? >> >> https://github.com/python/peps/commit/f906b988b20c9a8e7e13a2262f5381bd2b1399e2 > No, because the examples I gave don't fit into that :) I was aware of > what the PEP originally said. > > If you try to align the examples with the descriptions in the PEP, > you'll find that they don't all match. > > ChrisA The issue closed by that commit is interesting, if nothing else: Guido van Rossum wrote: > The PEP says very little about lambda. I feel the following two > examples should both be valid: > > foo(f := lambda: 42, flag=True) > foo(lambda: f := 42, flag=True) Chris Angelico wrote: > The second example is kinda bizarre though; it's going to create a > fairly useless name binding within the lambda function. (Unless you > want to give lambda functions the same magic as comprehensions, making > the name f exist in the same scope where foo is being run.) So I would > be okay with the first example doing the obvious thing, and the second > one requiring parentheses lambda: (f := 42) for syntactic validity. I think that at least clears up this part: > # But a SyntaxError if parenthesized like this?? >>>> def f(n): > ... return (lambda: n := 1) > File "", line 2 > return (lambda: n := 1) > ^^^^^^^^^ > SyntaxError: cannot use assignment expressions with lambda > > # Oh, and it doesn't actually assign anything. >>>> def f(n): > ... return (lambda: (n := 1)), (lambda: n) > ... From pablogsal at gmail.com Thu Oct 7 07:59:55 2021 From: pablogsal at gmail.com (Pablo Galindo Salgado) Date: Thu, 7 Oct 2021 12:59:55 +0100 Subject: [RELEASE] Python 3.11.0a1 is available Message-ID: Now that we are on a release spree, here you have the first alpha release of Python 3.11: Python 3.11.0a1. Let the testing and validation games begin! https://www.python.org/downloads/release/python-3110a1/ *Major new features of the 3.11 series, compared with 3.10* Python 3.11 is still in development. This release, 3.11.0a1 is the first of six planned alpha releases. Alpha releases are intended to make it easier to test the current state of new features and bug fixes and to test the release process. During the alpha phase, features may be added up until the start of the beta phase (2022-05-06) and, if necessary, may be modified or deleted up until the release candidate phase (2022-08-01). Please keep in mind that this is a preview release and its use is not recommended for production environments. Many new features for Python 3.11 are still being planned and written. Among the new major new features and changes so far: - PEP 657 ? Include Fine-Grained Error Locations in Tracebacks - PEP 654 ? PEP 654 ? Exception Groups and except* - (Hey, fellow core developer, if a feature you find important is missing from this list, let Pablo know .) The next pre-release of Python 3.11 will be 3.11.0a2, currently scheduled for 2021-11-02. *And now for something completely different* Zero-point energy is the lowest possible energy that a quantum mechanical system may have. Unlike in classical mechanics, quantum systems constantly fluctuate in their lowest energy state as described by the Heisenberg uncertainty principle. As well as atoms and molecules, the empty space of the vacuum has these properties. According to quantum field theory, the universe can be thought of not as isolated particles but as continuous fluctuating fields: matter fields, whose quanta are fermions (i.e., leptons and quarks), and force fields, whose quanta are bosons (e.g., photons and gluons). All these fields have a non zero amount of energy called zero-point energy. Physics currently lacks a full theoretical model for understanding zero-point energy; in particular, the discrepancy between theorized and observed vacuum energy is a source of major contention *We hope you enjoy those new releases!* Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Regards from cloudy London, Your friendly release team, Pablo Galindo @pablogsal Ned Deily @nad Steve Dower @steve.dower From Cecil at decebal.nl Thu Oct 7 06:37:50 2021 From: Cecil at decebal.nl (Cecil Westerhof) Date: Thu, 07 Oct 2021 12:37:50 +0200 Subject: Big jump in version References: <87bl45hyiu.fsf@munus.decebal.nl> <615cbdb6.1c69fb81.3feb7.acdf@mx.google.com> Message-ID: <874k9ti0ht.fsf@munus.decebal.nl> Grant Edwards writes: > On 2021-10-04, Cecil Westerhof via Python-list wrote: >> When I run: >> pip3 list --outdated >> >> I get: >> Package Version Latest Type >> ------------ ------- ------ ----- >> cryptography 3.4.8 35.0.0 wheel >> >> The jump from 3 to 35 seems a bit excessive to me. Or is it correct? > > https://cryptography.io/en/latest/changelog/ Thanks, that takes away my doubts. ;-) Y always being 0 seems strange to me. But who am I to complain? '-) -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From almadarplus at gmail.com Thu Oct 7 12:18:25 2021 From: almadarplus at gmail.com (Almadar Plus) Date: Thu, 7 Oct 2021 17:18:25 +0100 Subject: HELP - uninstall pyton error Message-ID: Could you please help me uninstall python? see attached screenshots files Regards From mohsen.owzar at gmail.com Fri Oct 8 03:03:00 2021 From: mohsen.owzar at gmail.com (Mohsen Owzar) Date: Fri, 8 Oct 2021 00:03:00 -0700 (PDT) Subject: New overriden and generated QLineEdit class will not be placed on the MainWindow as expected Message-ID: <68f0b421-287f-4b31-b643-fa916e7b6022n@googlegroups.com> Hi all Some days ago, I send a question to this community about a clickable QLineEdit. After getting the Hint to use QMouseEvent, I've written the program which is working almost good but with a small or perhaps big ugliness and that is: Below is the imgur link to the screenshots of my program after clicking the buttons in sequence: https://imgur.com/a/rfcP3qB As you will see in the code blow, I override the QlineEdit widget and define a new class " CustomLineEdit " to generate a "clicked" signal, when the user pressed with mouse on this field. I use this "CustomLineEdit" class and place it on the MainWindow with the desired "layout". I couldn't figure out, why this widget is placed not in the MainWindow, but outside this window, as you can see in the top picture of the attached screenshots. When I take the line 12 (self.show()) from the code, the generated class will not appear. The problem here is that at the beginning, the MainWindow with a LineEdit field should appear at the program start. Then, after clicking on this field, the keypad should come up outside the MainWindow. Could anyone see, where my mistake is? Thanks for any help. Mohsen Here is the code: &&&&&&&&&&&&&&&&&&&&&&&&&&& import sys from PyQt5.QtWidgets import (QApplication, QLineEdit, QPushButton, QMainWindow, QVBoxLayout, QHBoxLayout, QGridLayout, QWidget) from PyQt5.QtCore import pyqtSignal, pyqtSlot class CustomLineEdit(QLineEdit): clicked = pyqtSignal() def __init__(self): super().__init__() self.show() def mousePressEvent(self, QMouseEvent): self.clicked.emit() class MainWindow(QMainWindow): def __init__( self, parent=None ): super().__init__(parent) self.title = 'Window 1' self.left = 700 self.top = 300 self.width = 200 self.height = 200 self.initUI() def initUI(self): self.keypad_window = Keypad_Window(self) hbox = QHBoxLayout() self.cle = CustomLineEdit() self.cle.clicked.connect(self.show_keypad_window) self.cle.setFixedSize(220, 60) self.cle.setStyleSheet("color: red;" "background-color: yellow;" "font-family: Arial;" "font-weight: Bold;" "font-size: 30pt") hbox.addWidget(self.cle) self.setLayout(hbox) self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.show() def show_keypad_window(self): self.keypad_window.show() self.hide() def close(self): self.keypad_window.close() super(MainWindow, self).close() @pyqtSlot(str) def update_label(self, txt): self.cle.setText(txt) class Keypad_Window(QWidget): def __init__(self, parent=None): super().__init__() self.parent = parent self.setGeometry(1200, 500, 230, 400) vbox = QVBoxLayout() self.display = QLineEdit() self.display.setFixedSize(220, 60) self.display.setReadOnly(True) self.display.setStyleSheet("color: Blue; " "background-color: lightgreen;" "font-family: Arial;" "font-weight: Bold;" "font-size: 18pt") vbox.addWidget(self.display) """Create the buttons.""" self.buttons = {} self.gridlay = QGridLayout() self.button_name = [['7', '8', '9'], ['4', '5', '6'], ['1', '2', '3'], ['C', '0', '>']] self.command_name = [['7', '8', '9'], ['4', '5', '6'], ['1', '2', '3'], ['delete', '0', 'accept']] for i in range(4): for j in range(3): text = self.button_name[i][j] # keep a reference to the buttons self.buttons[i, j] = QPushButton() self.buttons[i, j].setText(text) self.buttons[i, j].setObjectName(text) self.buttons[i, j].setFixedSize(70, 70) if i == 3: if j == 0: self.buttons[i, j].setToolTip('Each click deletes\na digit to the left') if j == 2: self.buttons[i, j].setToolTip('The whole displayed\nvalue will be taken!') self.buttons[i, j].clicked.connect(self.call_button_fun(i, j, self.command_name)) # add to the GridLayout self.gridlay.addWidget(self.buttons[i, j], i, j) self.buttons[i, j].setStyleSheet("color: blue; " "background-color: cyan;" "font-family: Arial;" "font-weight: Bold;" "font-size: 20pt") vbox.addLayout(self.gridlay) self.setLayout(vbox) def call_button_fun(self, i, j, command_name): def button_fun(): if command_name[i][j] == self.button_name[i][j]: displayed_text = self.display.text() self.new_text = displayed_text + self.button_name[i][j] self.display.setText(self.new_text) if command_name[i][j] == 'accept': print('>-key pressed!') self.parent.cle.setText(self.new_text) self.close() if command_name[i][j] == 'delete': print('C-key pressed!') self.display.setText('') return button_fun if __name__ == "__main__": app = QApplication(sys.argv) mainwindow = MainWindow() # Exception abfangen, wenn sie nicht behandelt wurde sys._excepthook = sys.excepthook def exception_hook(exctype, value, traceback): print(exctype, value, traceback) sys._excepthook(exctype, value, traceback) sys.exit(1) sys.excepthook = exception_hook sys.exit(app.exec_()) From mal at europython.eu Fri Oct 8 09:28:00 2021 From: mal at europython.eu (Marc-Andre Lemburg) Date: Fri, 8 Oct 2021 15:28:00 +0200 Subject: EuroPython Society: Launching the EuroPython Society Fellow Grant Message-ID: <32f3ff29-1b9d-de9b-01e2-fef8b42f3361@europython.eu> We are excited to announce the new EuroPython Society Fellow Grant. The grant is intended to honor and show gratitude towards members of the EuroPython Society (EPS) and the EuroPython Workgroups who have contributed significantly towards our mission, the EuroPython conference and the Society as an organization. EuroPython Fellows ------------------ EuroPython Fellows are eligible to a lifetime free attendance of the EuroPython conference and will be listed on our EuroPython Society Fellow Grant page. https://www.europython-society.org/europython-society-fellow-grant/ The EuroPython Board will decide on new Fellowships based on nominations by the EPS members and its own deliberations. Our first Fellows ----------------- To launch the grant, the current board has decided to make all board members since 2012 who have served at least two terms and are not members of the current board EuroPython Fellows: - Alexander Hendorf - Alexandre Manhaes Savio - Anthon van der Neut - Borja Ayerdi - Christian Calogero Barra - Darya Chyzhyk - Fabio Pliger - Jacob Hall?n - Vicky Twomey-Lee In our last board call, we added two additional Fellows: - Laura Creighton (2021) - Oier Etxaniz Beneitez (2021, posthumously) The board will announce more Fellows in the coming weeks. If you are an EPS member and want to nominate another member as a Fellow, please write to board at europython.eu and include the reasons why you believe the member should become a Fellow. The EPS Board would like to congratulate all of the above Fellows and thank them for their tireless work towards our goals. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog posts: https://www.europython-society.org/launching-the-europython-society-fellow-grant/ https://www.europython-society.org/new-europython-society-fellows/ Tweets: https://twitter.com/europythons/status/1442834034690822147 https://twitter.com/europythons/status/1446446855857086469 Thanks, -- EuroPython Society https://www.europython-society.org/ From mats at wichmann.us Fri Oct 8 10:20:46 2021 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 8 Oct 2021 08:20:46 -0600 Subject: HELP - uninstall pyton error In-Reply-To: References: Message-ID: On 10/7/21 10:18, Almadar Plus wrote: > Could you please help me uninstall python? > see attached screenshots files > Regards > the list doesn't pass on screenshots, so we see nothing. you'll need to describe your problem. From gerhard at renix-electronics.com Fri Oct 8 15:46:34 2021 From: gerhard at renix-electronics.com (Gerhard van Rensburg) Date: Fri, 8 Oct 2021 14:46:34 -0500 Subject: nrfutil icorrect installation Message-ID: <000a01d7bc7d$33338fb0$999aaf10$@renix-electronics.com> Dear python, I installed Python 3.10.0 I then install pip install nrfutil When I try to run nrfutil, I get ModuleNotFoundError: No module named 'constants' C:\Users\ xxxxx\nrfutil keys --help Traceback (most recent call last): File "C:\Users\Gerhard van Rensburg\AppData\Local\Programs\Python\Python310\Scripts\nrfutil-script.py", line 33, in sys.exit(load_entry_point('nrfutil==5.2.0', 'console_scripts', 'nrfutil')()) File "C:\Users\Gerhard van Rensburg\AppData\Local\Programs\Python\Python310\Scripts\nrfutil-script.py", line 25, in importlib_load_entry_point return next(matches).load() File "C:\Users\Gerhard van Rensburg\AppData\Local\Programs\Python\Python310\lib\importlib\metadata\__in it__.py", line 162, in load module = import_module(match.group('module')) File "C:\Users\Gerhard van Rensburg\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1050, in _gcd_import File "", line 1027, in _find_and_load File "", line 1006, in _find_and_load_unlocked File "", line 688, in _load_unlocked File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "C:\Users\Gerhard van Rensburg\AppData\Local\Programs\Python\Python310\lib\site-packages\nordicsem i\__main__.py", line 53, in from nordicsemi.dfu.dfu_transport_serial import DfuTransportSerial File "C:\Users\Gerhard van Rensburg\AppData\Local\Programs\Python\Python310\lib\site-packages\nordicsem i\dfu\dfu_transport_serial.py", line 52, in from nordicsemi.lister.device_lister import DeviceLister File "C:\Users\Gerhard van Rensburg\AppData\Local\Programs\Python\Python310\lib\site-packages\nordicsem i\lister\device_lister.py", line 39, in from nordicsemi.lister.windows.lister_win32 import Win32Lister File "C:\Users\Gerhard van Rensburg\AppData\Local\Programs\Python\Python310\lib\site-packages\nordicsem i\lister\windows\lister_win32.py", line 43, in from constants import DIGCF_PRESENT, DEVPKEY, DIGCF_DEVICEINTERFACE ModuleNotFoundError: No module named 'constants' Any help appreciated Gerhard van Rensburg ____________________________________________________________________________ _______________________ RENIX Electronics, Inc. * 713-503-0855 * Fax: 281-517-0773 * www.Renix-Electronics.com Email: info at Renix-Electronics.com ____________________________________________________________________________ _________ **All communications should be considered RENIX Confidential** From michel at jagajaga.org Sat Oct 9 14:55:44 2021 From: michel at jagajaga.org (Michel) Date: Sat, 9 Oct 2021 19:55:44 +0100 Subject: HELP - uninstall pyton error In-Reply-To: References: Message-ID: give more details OS, Python Version, Method of installation.. etc.. On 10/7/21 17:18, Almadar Plus wrote: > Could you please help me uninstall python? > see attached screenshots files > Regards From studing54 at gmail.com Mon Oct 11 01:56:27 2021 From: studing54 at gmail.com (stefano felli) Date: Mon, 11 Oct 2021 07:56:27 +0200 Subject: installazione numpy Message-ID: l'installazione di numpy con pip install numpy fornisce errore Building wheel for numpy (PEP 517) ERROR: Failed building wheel for numpy Failed to build numpy ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly A cosa ? dovuto e come devo fare per installare anche scipy che non riesce? Grazie From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Fri Oct 8 17:56:53 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Fri, 8 Oct 2021 22:56:53 +0100 Subject: spyder does not work under root! [linux] Message-ID: Hi! I need to debug a python3 script under root. I tried spyder but it does not work. Running as root without --no-sandbox is not supported. See https://crbug.com/638180. Thanks for any comments including alternative solutions to debug as root. Paulo From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Fri Oct 8 18:32:18 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Fri, 8 Oct 2021 23:32:18 +0100 Subject: spyder does not work under root! [linux] References: Message-ID: ?s 22:56 de 08/10/21, Paulo da Silva escreveu: > Hi! > > I need to debug a python3 script under root. I tried spyder but it does > not work. > > Running as root without --no-sandbox is not supported. See > https://crbug.com/638180. > > Thanks for any comments including alternative solutions to debug as root. > I also tried with eric and curiously it gave the same message!! This seems crazy. From keller.steve at gmx.de Sun Oct 10 04:49:50 2021 From: keller.steve at gmx.de (Steve Keller) Date: Sun, 10 Oct 2021 10:49:50 +0200 Subject: sum() vs. loop Message-ID: I have found the sum() function to be much slower than to loop over the operands myself: def sum_products(seq1, seq2): return sum([a * b for a, b in zip(seq1, seq2)]) def sum_products2(seq1, seq2): sum = 0 for a, b in zip(seq1, seq2): sum += a * b return sum In a program I generate about 14 million pairs of sequences of ints each of length 15 which need to be summed. The first version with sum() needs 44 seconds while the second version runs in 37 seconds. Can someone explain this difference? Steve From auriocus at gmx.de Sun Oct 10 05:28:54 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 10 Oct 2021 11:28:54 +0200 Subject: sum() vs. loop In-Reply-To: References: Message-ID: Am 10.10.21 um 10:49 schrieb Steve Keller: > I have found the sum() function to be much slower than to loop over the > operands myself: > > def sum_products(seq1, seq2): > return sum([a * b for a, b in zip(seq1, seq2)]) > > def sum_products2(seq1, seq2): > sum = 0 > for a, b in zip(seq1, seq2): > sum += a * b > return sum > > In a program I generate about 14 million pairs of sequences of ints each > of length 15 which need to be summed. The first version with sum() needs > 44 seconds while the second version runs in 37 seconds. The first version constructs a list, sums it up and throws the list away, while the second version only keeps the running sum in memory. How about a generator expression instead, i.e. sum((a * b for a, b in zip(seq1, seq2))) (untested) ? Christian From keller.steve at gmx.de Sun Oct 10 10:19:40 2021 From: keller.steve at gmx.de (Steve Keller) Date: Sun, 10 Oct 2021 16:19:40 +0200 Subject: sum() vs. loop References: Message-ID: Christian Gollwitzer writes: > > def sum_products(seq1, seq2): > > return sum([a * b for a, b in zip(seq1, seq2)]) > > def sum_products2(seq1, seq2): > > sum = 0 > > for a, b in zip(seq1, seq2): > > sum += a * b > > return sum > > [...] > > The first version constructs a list, sums it up and throws the list > away, while the second version only keeps the running sum in > memory. How about a generator expression instead, i.e. > > > sum((a * b for a, b in zip(seq1, seq2))) Ah, of course. Much cleaner and I should have seen that myself. Thanks. BUT > (untested) ? I have tested it and with () instead of [] it's even slower: explicit loop: 37s ? .5s sum([...]) 44s ? .5s sum((...)) 47.5s ? .5s Now completely surprised. Steve From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Sun Oct 10 18:00:28 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Sun, 10 Oct 2021 23:00:28 +0100 Subject: Assign a value to a var content in an object Message-ID: Hello! Is there a better way of doing this? Why didn't setattr (as commented) work? Thanks for an help/comments. class C: def f(self,v): #setattr(self,n,v) self.__dict__['n']=v c=C() c.f(3) print(c.n) From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Sun Oct 10 19:34:28 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Mon, 11 Oct 2021 00:34:28 +0100 Subject: Assign a value to a var content in an object References: Message-ID: ?s 23:28 de 10/10/21, Stefan Ram escreveu: > Paulo da Silva writes: >> class C: >> def f(self,v): >> #setattr(self,n,v) >> self.__dict__['n']=v > >> Why didn't setattr (as commented) work? > > Because the name n has not been initialized to a suitable > value in the function f. You could write > > setattr( self, "n", v ) Ah, OK - I missed the "" around n! :-( > > , but if you want this, > > self.n = v > > would be better. Of course :-) But that's not the purpose. This is just a toy example. Thanks. From felix.strateg at gmail.com Mon Oct 11 07:49:54 2021 From: felix.strateg at gmail.com (=?UTF-8?Q?Felix_Kjellstr=C3=B6m?=) Date: Mon, 11 Oct 2021 04:49:54 -0700 (PDT) Subject: Beginner problem, please help. Building a simple menu + lists , cannot print list Message-ID: Hello! Please see the link to the code I have uploaded to my account at replit.com https://replit.com/join/lftxpszwrv-felixkjellstrom Problem: When you select the menu option "Add buyer", you can enter three values. See code line 5, "def Add_buyer ():" Then, you use the arrow keys to select the menu option "See list of buyers". When you do that the values you just entered should be printed. See code line 23, "def See_list_of_buyers (): The problem is that the list is DON'T gets printed. Problem: When you select the menu option "Add buyer", you can enter three values. See code line 5, "def Add_buyer ():" Then, you use the arrow keys to select the menu option "See list of buyers". When you do that the values you just entered should be printed. See code line 23, "def See_list_of_buyers (): The problem is that the list is DON'T gets printed. From rosuav at gmail.com Mon Oct 11 17:54:17 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Oct 2021 08:54:17 +1100 Subject: spyder does not work under root! [linux] In-Reply-To: References: Message-ID: On Tue, Oct 12, 2021 at 8:52 AM Paulo da Silva wrote: > > Hi! > > I need to debug a python3 script under root. I tried spyder but it does > not work. > > Running as root without --no-sandbox is not supported. See > https://crbug.com/638180. > > Thanks for any comments including alternative solutions to debug as root. > Did you try reading the linked bug report? Or running it with --no-sandbox? ChrisA From rosuav at gmail.com Mon Oct 11 17:57:42 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Oct 2021 08:57:42 +1100 Subject: sum() vs. loop In-Reply-To: References: Message-ID: On Tue, Oct 12, 2021 at 8:55 AM Steve Keller wrote: > > I have found the sum() function to be much slower than to loop over the > operands myself: > > def sum_products(seq1, seq2): > return sum([a * b for a, b in zip(seq1, seq2)]) > > def sum_products2(seq1, seq2): > sum = 0 > for a, b in zip(seq1, seq2): > sum += a * b > return sum > > In a program I generate about 14 million pairs of sequences of ints each > of length 15 which need to be summed. The first version with sum() needs > 44 seconds while the second version runs in 37 seconds. > > Can someone explain this difference? > When you use sum, you're constructing a list. Try removing the square brackets: return sum(a * b for a, b in zip(seq1, seq2)) It's also possible that the genexp has more overhead than simply iterating directly, but at very least, this will reduce the memory consumption. ChrisA From rosuav at gmail.com Mon Oct 11 18:05:51 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Oct 2021 09:05:51 +1100 Subject: sum() vs. loop In-Reply-To: References: Message-ID: On Tue, Oct 12, 2021 at 9:02 AM Stefan Ram wrote: > > Steve Keller writes: > >Now completely surprised. > > I have observed that here the generator-based sum() call > is slower if both seq1 and seq2 have a length of 1000, but > faster if both seq1 and seq2 have 10000000 entries each > (with float entries). > > However, in any case, the direct for-loop still is fastest. > Maybe, calling "next()" (actually, "PyIter_Next" in C) on > an iterator has some overhead compared to just evaluating > an expression in a loop. > There's overhead whichever way you do it, and ultimately, it depends on what you're doing. The genexp is effectively a callback into Python code. The list comp requires preconstruction of the entire list. The plain for loop involves summing by picking up and putting down in Python code rather than doing that in C. The only way to know which is fastest is to try them all :) ChrisA From rosuav at gmail.com Mon Oct 11 18:06:49 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Oct 2021 09:06:49 +1100 Subject: Assign a value to a var content in an object In-Reply-To: References: Message-ID: On Tue, Oct 12, 2021 at 9:03 AM Paulo da Silva wrote: > > Hello! > > Is there a better way of doing this? > Why didn't setattr (as commented) work? > > Thanks for an help/comments. > > class C: > def f(self,v): > #setattr(self,n,v) > self.__dict__['n']=v > > c=C() > c.f(3) > print(c.n) > Because setattr needs a string, just like the assignment to the dictionary does. Try: setattr(self, "n", v) Or, since it's a constant: self.n = v ChrisA From rosuav at gmail.com Mon Oct 11 18:20:28 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Oct 2021 09:20:28 +1100 Subject: Beginner problem, please help. Building a simple menu + lists , cannot print list In-Reply-To: References: Message-ID: On Tue, Oct 12, 2021 at 9:13 AM Felix Kjellstr?m wrote: > > Hello! Please see the link to the code I have uploaded to my account at replit.com > > https://replit.com/join/lftxpszwrv-felixkjellstrom Unfortunately, it's not public. Are you able to put the code on GitHub as a repository or gist, or in some other public hosting? Alternatively, can you make it short enough to simply include here in your post? ChrisA From torriem at gmail.com Mon Oct 11 21:08:14 2021 From: torriem at gmail.com (Michael Torrie) Date: Mon, 11 Oct 2021 19:08:14 -0600 Subject: spyder does not work under root! [linux] In-Reply-To: References: Message-ID: <30864db3-5bc5-fb13-f90a-d59ff185e586@gmail.com> On 10/8/21 4:32 PM, Paulo da Silva wrote: > ?s 22:56 de 08/10/21, Paulo da Silva escreveu: >> Hi! >> >> I need to debug a python3 script under root. I tried spyder but it does >> not work. >> >> Running as root without --no-sandbox is not supported. See >> https://crbug.com/638180. >> >> Thanks for any comments including alternative solutions to debug as root. >> > I also tried with eric and curiously it gave the same message!! > > This seems crazy. Not so crazy. It's incredibly dangerous to run a web browser as root. There's no reason I can think of for running a python script driving a web browser as root. Python scripts can easily be run as an arbitrary user, perhaps from a bash wrapper script using su, or being started from systemd. From drsalists at gmail.com Mon Oct 11 23:41:35 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 11 Oct 2021 20:41:35 -0700 Subject: sum() vs. loop In-Reply-To: References: Message-ID: On Mon, Oct 11, 2021 at 2:54 PM Steve Keller wrote: > I have found the sum() function to be much slower than to loop over the > operands myself: > > def sum_products(seq1, seq2): > return sum([a * b for a, b in zip(seq1, seq2)]) > > def sum_products2(seq1, seq2): > sum = 0 > for a, b in zip(seq1, seq2): > sum += a * b > return sum > > In a program I generate about 14 million pairs of sequences of ints each > of length 15 which need to be summed. The first version with sum() needs > 44 seconds while the second version runs in 37 seconds. > > Can someone explain this difference? > I can't explain it. It might help to try a line-by-line profiler. If you need speed, maybe try Cython, numpy and/or numba. It seems like the generator expression should be the fastest to me. But writing for speed instead of writing for clarity is usually not a great idea. From shishaozhong at gmail.com Tue Oct 12 04:40:26 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Tue, 12 Oct 2021 09:40:26 +0100 Subject: Connecting to MS accdb and read data into Pandas Message-ID: I tried the following code: import pyodbc conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\my.accdb;') cursor = conn.cursor() cursor.execute('select * from table_name') for row in cursor.fetchall(): print (row) But I could not connect to .accdb. What is the robust way to set the connection string? Regards, David From python at mrabarnett.plus.com Tue Oct 12 08:40:38 2021 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 12 Oct 2021 13:40:38 +0100 Subject: Connecting to MS accdb and read data into Pandas In-Reply-To: References: Message-ID: On 2021-10-12 09:40, Shaozhong SHI wrote: > I tried the following code: > import pyodbc > > conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, > *.accdb)};DBQ=D:\my.accdb;') > cursor = conn.cursor() > cursor.execute('select * from table_name') > > for row in cursor.fetchall(): > print (row) > > > But I could not connect to .accdb. > > What is the robust way to set the connection string? > What does the traceback say? From mal at europython.eu Tue Oct 12 09:55:31 2021 From: mal at europython.eu (Marc-Andre Lemburg) Date: Tue, 12 Oct 2021 15:55:31 +0200 Subject: EuroPython 2021: All edited videos now available Message-ID: We?re happy to release another batch of 41 cut videos of EuroPython 2021 covering the third day sessions of the conference and a number of edited videos for the previous days. In total, we now have 118 videos waiting for you. You can watch them on our YouTube channel. We have created a EuroPython 2021 playlist for this. * EuroPython 2021 Playlist * https://www.youtube.com/playlist?list=PL8uoeex94UhFuRtXhkqOrROsdNI6ejuiq All EuroPython Videos --------------------- Our YouTube channel has videos of all EuroPython conferences going back to 2011. Check out more than 1500 Python videos covering 10 conference years. EuroPython YouTube Channel: https://europython.tv/ All 1500+ videos: https://www.youtube.com/playlist?list=UU98CzaYuFNAA_gOINFB0e4Q Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/europython-2021-all-edited-videos-now-available/ Tweet: https://twitter.com/europython/status/1447922386817490944 Enjoy, -- EuroPython 2021 Team https://ep2021.europython.eu/ https://www.europython-society.org/ From antoon.pardon at vub.be Tue Oct 12 04:06:02 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 12 Oct 2021 10:06:02 +0200 Subject: Mailing list activity low Message-ID: <6f41b6e1-842e-20ad-14b3-2cc81e6001ca@vub.be> Have I missed something and has the maillinglist been moved. Activity is very low here, about one message every five days. Antoon Pardon. From pkpearson at nowhere.invalid Tue Oct 12 11:08:42 2021 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 12 Oct 2021 15:08:42 GMT Subject: nrfutil icorrect installation References: <000a01d7bc7d$33338fb0$999aaf10$@renix-electronics.com> Message-ID: On Fri, 8 Oct 2021 14:46:34 -0500, Gerhard van Rensburg wrote: > > I installed Python 3.10.0 > I then install > pip install nrfutil > > When I try to run nrfutil, I get > ModuleNotFoundError: No module named 'constants' I just asked duckduckgo.com about "nrfutil constants", and got this helpful-looking link: https://devzone.nordicsemi.com/f/nordic-q-a/65889/nrfutil-modulenotfounderror-no-module-named-constants -- To email me, substitute nowhere->runbox, invalid->com. From pkpearson at nowhere.invalid Tue Oct 12 11:13:05 2021 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 12 Oct 2021 15:13:05 GMT Subject: installazione numpy References: Message-ID: On Mon, 11 Oct 2021 07:56:27 +0200, stefano felli wrote: > l'installazione di numpy con > pip install numpy > fornisce errore > Building wheel for numpy (PEP 517) > > ERROR: Failed building wheel for numpy > Failed to build numpy > ERROR: Could not build wheels for numpy which use PEP 517 and cannot be > installed directly I've seen this problem attributed to a Python / Numpy version-number conflict: https://stackoverflow.com/questions/65708176/troubles-installing-numpy-1-19-5-with-python-3-9-1-on-macos-bigsur -- To email me, substitute nowhere->runbox, invalid->com. From python at mrabarnett.plus.com Tue Oct 12 14:05:00 2021 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 12 Oct 2021 19:05:00 +0100 Subject: Mailing list activity low In-Reply-To: <6f41b6e1-842e-20ad-14b3-2cc81e6001ca@vub.be> References: <6f41b6e1-842e-20ad-14b3-2cc81e6001ca@vub.be> Message-ID: <6e76a952-60eb-f464-c8cb-bdad1fd48f7b@mrabarnett.plus.com> On 2021-10-12 09:06, Antoon Pardon wrote: > Have I missed something and has the maillinglist been moved. Activity is > very low here, about one message every five days. > I've had some messages delayed, but activity has been normal otherwise. From david at lowryduda.com Tue Oct 12 14:12:13 2021 From: david at lowryduda.com (David Lowry-Duda) Date: Tue, 12 Oct 2021 14:12:13 -0400 Subject: Mailing list activity low In-Reply-To: <6f41b6e1-842e-20ad-14b3-2cc81e6001ca@vub.be> References: <6f41b6e1-842e-20ad-14b3-2cc81e6001ca@vub.be> Message-ID: > Have I missed something and has the maillinglist been moved. Activity > is very low here, about one message every five days. I think you might need to check how you access the mailing list. There have been more than 5 messages in the last day. See for example the archives: https://mail.python.org/pipermail/python-list/2021-October/date.html Good luck! - DLD From auriocus at gmx.de Tue Oct 12 14:52:21 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 12 Oct 2021 20:52:21 +0200 Subject: sum() vs. loop In-Reply-To: References: Message-ID: Am 12.10.21 um 05:41 schrieb Dan Stromberg: > On Mon, Oct 11, 2021 at 2:54 PM Steve Keller wrote: > >> I have found the sum() function to be much slower than to loop over the >> operands myself: >> >> def sum_products(seq1, seq2): >> return sum([a * b for a, b in zip(seq1, seq2)]) >> >> def sum_products2(seq1, seq2): >> sum = 0 >> for a, b in zip(seq1, seq2): >> sum += a * b >> return sum > It seems like the generator expression should be the fastest to me. But > writing for speed instead of writing for clarity is usually not a great > idea. > Maybe, unless this was just a test, it can be fastest AND clearest with numpy.dot(seq1, seq2) - in case that the sequence consists of floats and, in the best case, is already stored in a numpy array. Then you cannot beat this with Python code. Christian From learn2program at gmail.com Tue Oct 12 18:55:35 2021 From: learn2program at gmail.com (Alan Gauld) Date: Tue, 12 Oct 2021 23:55:35 +0100 Subject: Fwd: Re: sum() vs. loop Message-ID: On 10/10/2021 09:49, Steve Keller wrote: > I have found the sum() function to be much slower than to loop over the > operands myself: > > def sum_products(seq1, seq2): > return sum([a * b for a, b in zip(seq1, seq2)]) > > def sum_products2(seq1, seq2): > sum = 0 > for a, b in zip(seq1, seq2): > sum += a * b > return sum > > In a program I generate about 14 million pairs of sequences of ints each > of length 15 which need to be summed. The first version with sum() needs > 44 seconds while the second version runs in 37 seconds. > > Can someone explain this difference? I'm no expert on Python innards but it looks to me like the first version loops over the length of the list twice, once to generate the list of products and the second time to add them together. The pure Python version only loops once because it does the addition in transit. Presumably, especially for large numbers, a single python loop is faster than 2 C loops? But that's purely my speculation. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From avigross at verizon.net Tue Oct 12 21:34:42 2021 From: avigross at verizon.net (Avi Gross) Date: Tue, 12 Oct 2021 21:34:42 -0400 Subject: sum() vs. loop In-Reply-To: References: Message-ID: <013b01d7bfd2$7f0dfee0$7d29fca0$@verizon.net> Alan, I am also wondering about that zip() function call to bind the two lists into a sort of iterator object. Presumably that calls the iterator N times. I did a test where I made two list called A and B and used zip to make an object holding the two and then removed A and B. I was able to print the list of tuples just fine with print(list(C)) so clearly it is not so much a pure iterator as one that holds yet another copy of both lists! Now the old-fashioned C way, might simply use old fashioned but highly efficient pointer arithmetic to move through two lists or arrays or whatever of the same length adding as it goes so one pass period. Or it could use indexing as in sum += A[i] * B[i] ... But yes, there are many good reasons to use clearer code with well-tested parts even at the cost of some efficiency. Is there a version of zip() or an alternative that might be faster? In particular, I was wondering the usual question of what happens if you might abort early if something is noticed, like say a negative number. If you pre-calculated and copied 100,000 items and abort after 5, ... I note an approach in some languages using a vectorized approach may be faster. Forget lists and as long as A and B are equal length vectors or arrays as in numpy, there are ways to ask to multiply two arrays in vectorized fashion so effectively you can say something akin to: sum(A*B) The above may be highly efficient especially if the underlying code is in C/C++. If there is no objection in your code to using the numpy module and the corresponding objects you can make a similar test with something like this: And the function they seem to want is the dot product of two such arrays as in numpy.dot(A, B) provides the sum of the many products of corresponding entries in A and B. -----Original Message----- From: Python-list On Behalf Of Alan Gauld Sent: Tuesday, October 12, 2021 6:56 PM To: python-list at python.org Subject: Fwd: Re: sum() vs. loop On 10/10/2021 09:49, Steve Keller wrote: > I have found the sum() function to be much slower than to loop over > the operands myself: > > def sum_products(seq1, seq2): > return sum([a * b for a, b in zip(seq1, seq2)]) > > def sum_products2(seq1, seq2): > sum = 0 > for a, b in zip(seq1, seq2): > sum += a * b > return sum > > In a program I generate about 14 million pairs of sequences of ints > each of length 15 which need to be summed. The first version with > sum() needs > 44 seconds while the second version runs in 37 seconds. > > Can someone explain this difference? I'm no expert on Python innards but it looks to me like the first version loops over the length of the list twice, once to generate the list of products and the second time to add them together. The pure Python version only loops once because it does the addition in transit. Presumably, especially for large numbers, a single python loop is faster than 2 C loops? But that's purely my speculation. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Oct 12 21:52:02 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Oct 2021 12:52:02 +1100 Subject: sum() vs. loop In-Reply-To: <013b01d7bfd2$7f0dfee0$7d29fca0$@verizon.net> References: <013b01d7bfd2$7f0dfee0$7d29fca0$@verizon.net> Message-ID: On Wed, Oct 13, 2021 at 12:36 PM Avi Gross via Python-list wrote: > > Alan, > > I am also wondering about that zip() function call to bind the two lists > into a sort of iterator object. Presumably that calls the iterator N times. > I did a test where I made two list called A and B and used zip to make an > object holding the two and then removed A and B. I was able to print the > list of tuples just fine with print(list(C)) so clearly it is not so much a > pure iterator as one that holds yet another copy of both lists! What do you mean by "removed" here? Simply removing the name that refers to it doesn't destroy the list; an iterator will keep the list alive. > Now the old-fashioned C way, might simply use old fashioned but highly > efficient pointer arithmetic to move through two lists or arrays or whatever > of the same length adding as it goes so one pass period. Or it could use > indexing as in sum += A[i] * B[i] ... It's basically that, yup. Of course, it's not defined by C behaviour, but the effect is the same. > Is there a version of zip() or an alternative that might be faster? In > particular, I was wondering the usual question of what happens if you might > abort early if something is noticed, like say a negative number. If you > pre-calculated and copied 100,000 items and abort after 5, ... The purpose of zip is to represent the concept of iterating over two things at once. Aborting early is fine, just as it is with other iterations. It's incredibly convenient to be able to write something like: for tradegood, value in zip(data.tradegoods, data.tradevalues): ... (Not exact code, but something very similar to what I've done while parsing game savefiles.) > I note an approach in some languages using a vectorized approach may be > faster. Forget lists and as long as A and B are equal length vectors or > arrays as in numpy, there are ways to ask to multiply two arrays in > vectorized fashion so effectively you can say something akin to: > > sum(A*B) > > The above may be highly efficient especially if the underlying code is in > C/C++. Or Fortran :) > If there is no objection in your code to using the numpy module and the > corresponding objects you can make a similar test with something like this: > > And the function they seem to want is the dot product of two such arrays as > in numpy.dot(A, B) provides the sum of the many products of corresponding > entries in A and B. If you're worried about the performance of summing pairwise products of numbers, you should probably be using numpy already. It's intellectually entertaining to explore the performance implications of various types of iteration, but numpy is basically always going to win any race that involves large numbers of floats :) It's like having a hundred-yard-dash involving a bunch of schoolchildren, and one Olympic runner - which of the schoolkids was fastest? ChrisA From jkexcel at comcast.net Wed Oct 13 11:11:37 2021 From: jkexcel at comcast.net (jkk) Date: Wed, 13 Oct 2021 11:11:37 -0400 (EDT) Subject: Selenium py3.8+ DepreciationWarnings - where to find doc to update code? Message-ID: <741026852.124539.1634137897922@connect.xfinity.com> Selenium 3.141+ python 3.8+ ubuntu 20.04 or windows 10 I'm trying to upgrade code from py3.6+ to py3.8+ and I'm getting several DepreciationWarnings. Can someone point me to where I can find the documentation that explains how to to remedy these warnings. What are the new preferred coding practices? For example, here is a "DepreciationWarning" that I figured out: py3.6+ from selenium import webdriver browser = browser = webdriver.Firefox() browser.get(url) tables = browser.find_elements_by_tag_name("table") py3.8+ from selenium import webdriver from selenium.webdriver.common.by import By browser = browser = webdriver.Firefox() browser.get(url) tables = browser.find_elements(By.TAG_NAME, "table") or tables = browser.find_elements(By.XPATH, "//table") From oscar.j.benjamin at gmail.com Wed Oct 13 12:49:55 2021 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 13 Oct 2021 17:49:55 +0100 Subject: sum() vs. loop In-Reply-To: References: Message-ID: On Mon, 11 Oct 2021 at 23:00, Christian Gollwitzer wrote: > > Am 10.10.21 um 10:49 schrieb Steve Keller: > > I have found the sum() function to be much slower than to loop over the > > operands myself: > > > > def sum_products(seq1, seq2): > > return sum([a * b for a, b in zip(seq1, seq2)]) > > > > def sum_products2(seq1, seq2): > > sum = 0 > > for a, b in zip(seq1, seq2): > > sum += a * b > > return sum > > > > In a program I generate about 14 million pairs of sequences of ints each > > of length 15 which need to be summed. The first version with sum() needs > > 44 seconds while the second version runs in 37 seconds. > > The first version constructs a list, sums it up and throws the list > away, while the second version only keeps the running sum in memory. How > about a generator expression instead, i.e. > > > sum((a * b for a, b in zip(seq1, seq2))) What really matters in cases like this is interpreter overhead. Typically a generator expression has slightly more overhead compared to a list comprehension. You get a slightly slower per-item speed in exchange for O(1) memory consumption. A list comprehension like result = sum([expr for foo in bar]) Translates internally to something like: def _func(): data = [] for foo in bar: data.append(foo) return foo _stuff = _func() result = sum(_stuff) Running this really does bring in the overhead of a function call _func() because it needs to create a frame with locals and so on. However it is only the cost of a single function call. Afterwards if the elements in the list _stuff are built in types like int etc with builtin __add__ methods then sum(_stuff) does not involve the interpreter at all: it's a built-in function operating on a built-in container of built-in objects. With a generator expression like result = sum(expr for foo in bar) This translates internally to def _genfunc(): for foo in bar: yield foo _gen = _genfunc() result = sum(_gen) Now the _genfunc() function call simply creates the generator and sets up its frame which I think is more or less equivalent to the overhead of the _func() function call. However the sum(_gen) line is no longer a pure built-in operation. Internally each time sum calls _gen.__next__() the execution frame for _genfunc() is reactivated so that the interpreter can execute the bytecodes taking the frame from one yield to the next. This is almost the overhead of a function call for each item in bar although this is often unnoticeable in practice and other factors can affect this. The fastest version eliminates the interpreter altogether at least when operating on pure built-in elements: In [7]: nums1 = nums2 = list(range(10**5)) In [10]: %timeit sum([a*b for a, b in zip(nums1, nums2)]) 9.83 ms ? 21.2 ?s per loop (mean ? std. dev. of 7 runs, 100 loops each) In [11]: %timeit sum((a*b for a, b in zip(nums1, nums2))) 10.3 ms ? 109 ?s per loop (mean ? std. dev. of 7 runs, 100 loops each) In [12]: from operator import mul In [13]: %timeit sum(map(mul, nums1, nums2)) 7.25 ms ? 33 ?s per loop (mean ? std. dev. of 7 runs, 100 loops each) Of course if the elements being multiplied and summed have pure-Python __add__/__mul__ methods or the container has a pure Python __iter__/__next__ then any of those methods will typically dominate the runtime over any of the overheads considered here. -- Oscar From ken at pubbox.net Tue Oct 12 21:37:14 2021 From: ken at pubbox.net (Ken Peng) Date: Wed, 13 Oct 2021 09:37:14 +0800 Subject: Mailing list activity low In-Reply-To: <6f41b6e1-842e-20ad-14b3-2cc81e6001ca@vub.be> References: <6f41b6e1-842e-20ad-14b3-2cc81e6001ca@vub.be> Message-ID: Maybe bounced by your mail provider. Try changing to another ESP such as gmail. On Wed, Oct 13, 2021 at 1:45 AM Antoon Pardon wrote: > Have I missed something and has the maillinglist been moved. Activity is > very low here, about one message every five days. > > Antoon Pardon. > -- > https://mail.python.org/mailman/listinfo/python-list > From avigross at verizon.net Wed Oct 13 14:23:10 2021 From: avigross at verizon.net (Avi Gross) Date: Wed, 13 Oct 2021 14:23:10 -0400 Subject: sum() vs. loop In-Reply-To: References: <013b01d7bfd2$7f0dfee0$7d29fca0$@verizon.net> Message-ID: <0d6301d7c05f$60e140c0$22a3c240$@verizon.net> Yes, Stefan, I realized that and did not test more thoroughly. Chris pointed it out too. I indeed deleted the names but a second reference remained so I may be wrong and the function may just keep track of the position and return one tuple at a time. That would be a good design, unless there was a worry the original might be changed out from under. My apologies if it was understood to mean I had shown it was copied. -----Original Message----- From: Python-list On Behalf Of Stefan Ram Sent: Tuesday, October 12, 2021 9:49 PM To: python-list at python.org Subject: Re: sum() vs. loop "Avi Gross" writes: >I did a test where I made two list called A and B and used zip to make >an object holding the two and then removed A and B. I was able to print >the list of tuples just fine with print(list(C)) so clearly it is not >so much a pure iterator as one that holds yet another copy of both lists! You may have "deleted the names", but not the lists. a =[ 10, 11, 12 ] b =[ 20, 21, 22 ] c = zip( a, b ) del a[ 0 ], a[ 0 ], a[ 0 ] del b[ 0 ], b[ 0 ], b[ 0 ] print( a, b, list( c )) prints [] [] [] here. -- https://mail.python.org/mailman/listinfo/python-list From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Wed Oct 13 14:08:13 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Wed, 13 Oct 2021 19:08:13 +0100 Subject: spyder does not work under root! [linux] References: Message-ID: ?s 22:54 de 11/10/21, Chris Angelico escreveu: > On Tue, Oct 12, 2021 at 8:52 AM Paulo da Silva > wrote: >> >> Hi! >> >> I need to debug a python3 script under root. I tried spyder but it does >> not work. >> >> Running as root without --no-sandbox is not supported. See >> https://crbug.com/638180. >> >> Thanks for any comments including alternative solutions to debug as root. >> > > Did you try reading the linked bug report? Or running it with --no-sandbox? > Yes. It is about a web browser! Why are 2 python debuggers related with a web browser?! As per spyder, there is no such switch --no-sandbox! Thanks. From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Wed Oct 13 14:09:43 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Wed, 13 Oct 2021 19:09:43 +0100 Subject: spyder does not work under root! [linux] References: <30864db3-5bc5-fb13-f90a-d59ff185e586@gmail.com> Message-ID: ?s 02:08 de 12/10/21, Michael Torrie escreveu: > On 10/8/21 4:32 PM, Paulo da Silva wrote: >> ?s 22:56 de 08/10/21, Paulo da Silva escreveu: >>> Hi! >>> >>> I need to debug a python3 script under root. I tried spyder but it does >>> not work. >>> >>> Running as root without --no-sandbox is not supported. See >>> https://crbug.com/638180. >>> >>> Thanks for any comments including alternative solutions to debug as root. >>> >> I also tried with eric and curiously it gave the same message!! >> >> This seems crazy. > > Not so crazy. It's incredibly dangerous to run a web browser as root. > There's no reason I can think of for running a python script driving a > web browser as root. spyder and eric are both python editors/debuggers! Why are they related with web browsers?! Thanks From ingy at ingy.net Wed Oct 13 15:43:13 2021 From: ingy at ingy.net (Ingy dot Net) Date: Wed, 13 Oct 2021 15:43:13 -0400 Subject: [ANN] PyYAML-6.0 Released Message-ID: ===================== Announcing PyYAML-6.0 ===================== A new release of PyYAML is now available: https://github.com/yaml/pyyaml/releases/tag/6.0 The previously-deprecated default loader selection in `yaml.load()` has been removed; `Loader` is now a required argument. Support for Python 2.7 and 3.5 has been dropped, and support for Python 3.10 added. It now includes libyaml 0.2.5 extension wheels for MacOS M1 (Apple Silicon/arm64), Linux s390x and Linux aarch64. Numerous other bugfixes and code cleanups are included in this release. Changes ======= * https://github.com/yaml/pyyaml/pull/327 -- Change README format to Markdown * https://github.com/yaml/pyyaml/pull/483 -- Add a test for YAML 1.1 types * https://github.com/yaml/pyyaml/pull/497 -- fix float resolver to ignore `.` and `._` * https://github.com/yaml/pyyaml/pull/550 -- drop Python 2.7 * https://github.com/yaml/pyyaml/pull/553 -- Fix spelling of ?hexadecimal? * https://github.com/yaml/pyyaml/pull/556 -- fix representation of Enum subclasses * https://github.com/yaml/pyyaml/pull/557 -- fix libyaml extension compiler warnings * https://github.com/yaml/pyyaml/pull/560 -- fix ResourceWarning on leaked file descriptors * https://github.com/yaml/pyyaml/pull/561 -- always require `Loader` arg to `yaml.load()` * https://github.com/yaml/pyyaml/pull/564 -- remove remaining direct distutils usage Resources ========= PyYAML Matrix: https://matrix.to/#/#pyyaml:yaml.io PyYAML IRC Channel: #pyyaml on irc.libera.chat PyYAML homepage: https://github.com/yaml/pyyaml PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation Source and binary installers: https://pypi.org/project/PyYAML/ GitHub repository: https://github.com/yaml/pyyaml/ Bug tracking: https://github.com/yaml/pyyaml/issues YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML ============ YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistence. Example ======= ``` >>> import yaml >>> yaml.full_load(""" ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: https://github.com/yaml/pyyaml ... keywords: [YAML, serialization, configuration, persistence, pickle] ... """) {'keywords': ['YAML', 'serialization', 'configuration', 'persistence', 'pickle'], 'homepage': 'https://github.com/yaml/pyyaml', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} >>> print(yaml.dump(_)) name: PyYAML homepage: https://github.com/yaml/pyyaml description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistence, pickle] ``` Maintainers =========== The following people are currently responsible for maintaining PyYAML: * Ingy d?t Net * Matt Davis and many thanks to all who have contributed! See: https://github.com/yaml/pyyaml/pulls Copyright ========= Copyright (c) 2017-2021 Ingy d?t Net Copyright (c) 2006-2016 Kirill Simonov The PyYAML module was written by Kirill Simonov . It is currently maintained by the YAML and Python communities. PyYAML is released under the MIT license. See the file LICENSE for more details. From hjp-python at hjp.at Wed Oct 13 16:57:28 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 13 Oct 2021 22:57:28 +0200 Subject: spyder does not work under root! [linux] In-Reply-To: References: <30864db3-5bc5-fb13-f90a-d59ff185e586@gmail.com> Message-ID: On 2021-10-13 19:09:43 +0100, Paulo da Silva wrote: > ?s 02:08 de 12/10/21, Michael Torrie escreveu: > > On 10/8/21 4:32 PM, Paulo da Silva wrote: > >> ?s 22:56 de 08/10/21, Paulo da Silva escreveu: > >>> I need to debug a python3 script under root. I tried spyder but it does > >>> not work. > >>> > >>> Running as root without --no-sandbox is not supported. See > >>> https://crbug.com/638180. > >>> > >>> Thanks for any comments including alternative solutions to debug as root. > >>> > >> I also tried with eric and curiously it gave the same message!! > >> > >> This seems crazy. > > > > Not so crazy. It's incredibly dangerous to run a web browser as root. Mostly because a web browser is usually used to interpret untrusted content from other sites ... > > There's no reason I can think of for running a python script driving > > a web browser as root. ... but this doesn't apply if the browser is just a display for a locally running script. The script is already running as root. It can do all the evil stuff without the help of a browser. > spyder and eric are both python editors/debuggers! Why are they > related with web browsers?! They probably use a browser engine to implement the GUI. This isn't uncommon. See Electron (https://www.electronjs.org/) for example. I didn't see anything on the Spyder website about how it is implemented (I didn't look very hard) but the error message hints that there's a Chromium hidden somewhere. And Eric uses Qt5, and Chromium is derived from WebKit which is Qt's browser engine. It's a bit weird that this also refers to Chromium's bug tracker and not Qt's, but there's certainly a common ancestry here. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From torriem at gmail.com Wed Oct 13 18:55:41 2021 From: torriem at gmail.com (Michael Torrie) Date: Wed, 13 Oct 2021 16:55:41 -0600 Subject: spyder does not work under root! [linux] In-Reply-To: References: <30864db3-5bc5-fb13-f90a-d59ff185e586@gmail.com> Message-ID: On 10/13/21 12:09 PM, Paulo da Silva wrote: > spyder and eric are both python editors/debuggers! Why are they related > with web browsers?! Good point. I was going off of the chromium bug report. My bad. I mistook Spyder for Selenium, which is a web scraping scripting engine that does use a real browser. Oops. However, for better or worse, browser engines power all kinds of apps these days, including IDEs. I do not know if Spyder is powered by Chromium or not. VS Code, for example, is powered by a web browser engine. As to Eric and Qt, I can't speak to that. From guinness.tony at gmail.com Wed Oct 13 18:20:01 2021 From: guinness.tony at gmail.com (Tony Oliver) Date: Wed, 13 Oct 2021 15:20:01 -0700 (PDT) Subject: Selenium py3.8+ DepreciationWarnings - where to find doc to update code? In-Reply-To: References: <741026852.124539.1634137897922@connect.xfinity.com> Message-ID: On Wednesday, 13 October 2021 at 16:16:46 UTC+1, jkk wrote: > Selenium 3.141+ > python 3.8+ > ubuntu 20.04 or windows 10 > > I'm trying to upgrade code from py3.6+ to py3.8+ and I'm getting several DepreciationWarnings. > > Can someone point me to where I can find the documentation that explains how to to remedy these warnings. What are the new preferred coding practices? > > For example, here is a "DepreciationWarning" that I figured out: > > py3.6+ > from selenium import webdriver > browser = browser = webdriver.Firefox() > browser.get(url) > tables = browser.find_elements_by_tag_name("table") > > > py3.8+ > from selenium import webdriver > from selenium.webdriver.common.by import By > browser = browser = webdriver.Firefox() > browser.get(url) > tables = browser.find_elements(By.TAG_NAME, "table") > or > tables = browser.find_elements(By.XPATH, "//table") I cannot help you with your immediate problem but am intrigued to discover what your ?browser = browser = ? idiom does that differs from ?browser = ?. From mats at wichmann.us Thu Oct 14 11:16:28 2021 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 14 Oct 2021 09:16:28 -0600 Subject: spyder does not work under root! [linux] In-Reply-To: References: <30864db3-5bc5-fb13-f90a-d59ff185e586@gmail.com> Message-ID: <4e8ae016-fe83-eaf0-dc1a-2793477f25d9@wichmann.us> On 10/13/21 16:55, Michael Torrie wrote: > On 10/13/21 12:09 PM, Paulo da Silva wrote: >> spyder and eric are both python editors/debuggers! Why are they related >> with web browsers?! > > Good point. I was going off of the chromium bug report. My bad. I > mistook Spyder for Selenium, which is a web scraping scripting engine > that does use a real browser. Oops. > > However, for better or worse, browser engines power all kinds of apps > these days, including IDEs. I do not know if Spyder is powered by > Chromium or not. VS Code, for example, is powered by a web browser engine. > > As to Eric and Qt, I can't speak to that. (sorry sent this wrong place first time) The configuration dialog in eric uses its WebBrowser module, which uses qtwebengine, which uses Chromium, which gives you the error. It's not a Python error, fwiw. It seems there's an environment variable you can try in the Qt world (I've never had occasion to check this out): https://forum.qt.io/topic/94721/running-as-root-without-no-sandbox-is-not-supported From jkexcel at comcast.net Thu Oct 14 11:32:52 2021 From: jkexcel at comcast.net (jkk) Date: Thu, 14 Oct 2021 11:32:52 -0400 (EDT) Subject: Selenium py3.8+ DepreciationWarnings - where to find doc to update code? In-Reply-To: References: <741026852.124539.1634137897922@connect.xfinity.com> Message-ID: <734674167.71870.1634225573047@connect.xfinity.com> Sorry, this was simply a typo. Disregard the first "browser = " Again, I'm hoping someone knows where to find "best coding practices" for newer versions of python 3.8+ > On 10/13/2021 6:20 PM Tony Oliver wrote: > > > On Wednesday, 13 October 2021 at 16:16:46 UTC+1, jkk wrote: > > Selenium 3.141+ > > python 3.8+ > > ubuntu 20.04 or windows 10 > > > > I'm trying to upgrade code from py3.6+ to py3.8+ and I'm getting several DepreciationWarnings. > > > > Can someone point me to where I can find the documentation that explains how to to remedy these warnings. What are the new preferred coding practices? > > > > For example, here is a "DepreciationWarning" that I figured out: > > > > py3.6+ > > from selenium import webdriver > > browser = browser = webdriver.Firefox() > > browser.get(url) > > tables = browser.find_elements_by_tag_name("table") > > > > > > py3.8+ > > from selenium import webdriver > > from selenium.webdriver.common.by import By > > browser = browser = webdriver.Firefox() > > browser.get(url) > > tables = browser.find_elements(By.TAG_NAME, "table") > > or > > tables = browser.find_elements(By.XPATH, "//table") > > I cannot help you with your immediate problem but am intrigued to discover what your ?browser = browser = ? idiom does that differs from ?browser = ?. > -- > https://mail.python.org/mailman/listinfo/python-list From amsefente09 at gmail.com Thu Oct 14 07:01:22 2021 From: amsefente09 at gmail.com (Amsalu Fentahun) Date: Thu, 14 Oct 2021 14:01:22 +0300 Subject: about python Message-ID: there is a problem when I install the setup From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Thu Oct 14 02:02:49 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Thu, 14 Oct 2021 07:02:49 +0100 Subject: spyder does not work under root! [linux] References: <30864db3-5bc5-fb13-f90a-d59ff185e586@gmail.com> Message-ID: ?s 23:55 de 13/10/21, Michael Torrie escreveu: > On 10/13/21 12:09 PM, Paulo da Silva wrote: >> spyder and eric are both python editors/debuggers! Why are they related >> with web browsers?! > > Good point. I was going off of the chromium bug report. My bad. I > mistook Spyder for Selenium, which is a web scraping scripting engine > that does use a real browser. Oops. > > However, for better or worse, browser engines power all kinds of apps > these days, including IDEs. I do not know if Spyder is powered by > Chromium or not. VS Code, for example, is powered by a web browser engine. > > As to Eric and Qt, I can't speak to that. Software starts to get sickly complicated these days :-( Thanks Michael and Peter. From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Thu Oct 14 13:18:48 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Thu, 14 Oct 2021 18:18:48 +0100 Subject: spyder does not work under root! [linux] References: <30864db3-5bc5-fb13-f90a-d59ff185e586@gmail.com> <4e8ae016-fe83-eaf0-dc1a-2793477f25d9@wichmann.us> Message-ID: ?s 16:16 de 14/10/21, Mats Wichmann escreveu: > On 10/13/21 16:55, Michael Torrie wrote: >> On 10/13/21 12:09 PM, Paulo da Silva wrote: >>> spyder and eric are both python editors/debuggers! Why are they related >>> with web browsers?! >> >> Good point. I was going off of the chromium bug report. My bad.? I >> mistook Spyder for Selenium, which is a web scraping scripting engine >> that does use a real browser.? Oops. >> >> However, for better or worse, browser engines power all kinds of apps >> these days, including IDEs. I do not know if Spyder is powered by >> Chromium or not.? VS Code, for example,? is powered by a web browser >> engine. >> >> As to Eric and Qt, I can't speak to that. > > (sorry sent this wrong place first time) > > > The configuration dialog in eric uses its WebBrowser module, which uses > qtwebengine, which uses Chromium, which gives you the error.? It's not a > Python error, fwiw. > > It seems there's an environment variable you can try in the Qt world > (I've never had occasion to check this out): > > https://forum.qt.io/topic/94721/running-as-root-without-no-sandbox-is-not-supported > Ok, thank you. From drsalists at gmail.com Thu Oct 14 15:03:16 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 14 Oct 2021 12:03:16 -0700 Subject: about python In-Reply-To: References: Message-ID: Please try to be more specific. What setup? What problem? On Thu, Oct 14, 2021 at 10:29 AM Amsalu Fentahun wrote: > there is a problem when I install the setup > -- > https://mail.python.org/mailman/listinfo/python-list > From seonghark at kookmin.ac.kr Fri Oct 15 19:37:41 2021 From: seonghark at kookmin.ac.kr (=?UTF-8?B?4oCN7KCV7ISx7ZWZKOuMgO2VmeybkOyDnS3snpDrj5nssKhJVOycte2VqeyghOqztSk=?=) Date: Sat, 16 Oct 2021 08:37:41 +0900 Subject: Request to advise error for python. In-Reply-To: References: Message-ID: Dear Sir, resend request =========================================== Seonghark Jeong KUL(Kookmin Unmanned vehicle research Laboratory) GSAEK, Kookmin Univ. E-Mail: seonghark at kookmin.ac.kr HP: 82-10-3600-7143 =========================================== 2021? 10? 16? (?) ?? 8:08, ????(????-???IT????) ?? ??: > Sir, > > I resend the e-mail > > =========================================== > Seonghark Jeong > KUL(Kookmin Unmanned vehicle research Laboratory) > GSAEK, Kookmin Univ. > E-Mail: seonghark at kookmin.ac.kr > HP: 82-10-3600-7143 > =========================================== > > > 2021? 10? 16? (?) ?? 8:04, ????(????-???IT????) ?? > ??: > >> Hi Sir, >> >> I had the error below So, I install python many times, and same error >> occur continuously. >> Would you advise how to handle this error? >> >> >> [image: image.png] >> =========================================== >> Seonghark Jeong >> KUL(Kookmin Unmanned vehicle research Laboratory) >> GSAEK, Kookmin Univ. >> E-Mail: seonghark at kookmin.ac.kr >> HP: 82-10-3600-7143 >> =========================================== >> > -- From torriem at gmail.com Fri Oct 15 22:31:30 2021 From: torriem at gmail.com (Michael Torrie) Date: Fri, 15 Oct 2021 20:31:30 -0600 Subject: Request to advise error for python. In-Reply-To: References: Message-ID: <7ce05ae4-b518-35e8-2f58-288443896d7d@gmail.com> On 10/15/21 5:37 PM, ???(????-???IT????) via Python-list wrote: > Dear Sir, > > resend request Unfortunately your message is still blank. Attachments such as screenshots are not visible to this list. Whenever you ask questions on the list it is helpful to: - state the operating system you are using - which installer you are using and where you downloaded it from - copy and paste any text error messages you saw - state any information you found doing an internet search for the error message you saw. If you are on Windows, please be sure to read this document: https://docs.python.org/3/using/windows.html From akkana at shallowsky.com Sat Oct 16 12:02:39 2021 From: akkana at shallowsky.com (Akkana Peck) Date: Sat, 16 Oct 2021 10:02:39 -0600 Subject: Selenium py3.8+ DepreciationWarnings - where to find doc to update code? In-Reply-To: <741026852.124539.1634137897922@connect.xfinity.com> References: <741026852.124539.1634137897922@connect.xfinity.com> Message-ID: jkk writes: > Selenium 3.141+ > python 3.8+ > ubuntu 20.04 or windows 10 > > I'm trying to upgrade code from py3.6+ to py3.8+ and I'm getting several DepreciationWarnings. > > Can someone point me to where I can find the documentation that explains how to to remedy these warnings. What are the new preferred coding practices? I've also been looking for that (Selenium 4.0.0a1, Python 3.9.5, Ubuntu 21.04). For instance: >>> from selenium import webdriver >>> profiledir = "/path/to/profile/dir" >>> driver = webdriver.Firefox(firefox_profile=profiledir) :1: DeprecationWarning: firefox_profile has been deprecated, please pass in a Service object What is a Service object and how do you use it to pass in profiles? I've found API references like https://www.selenium.dev/selenium/docs/api/rb/Selenium/WebDriver/Service.html https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.common.service but how do you create one, or use it to reference a specific profile? I haven't been able to find any examples. ...Akkana From kaviyavadivel1 at gmail.com Sat Oct 16 07:34:44 2021 From: kaviyavadivel1 at gmail.com (Kaviya Vadivel) Date: Sat, 16 Oct 2021 17:04:44 +0530 Subject: Fwd: Issue in installing python In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Kaviya Vadivel Date: Sat, 16 Oct 2021 at 17:00 Subject: Issue in installing python To: Hello Team, I have downloaded python 3.10.0 from python.org.I have windows 8.1.I have installed the python on my machine .But during installation Im getting application error.It doesn't install on my machine.But Im getting successful after the installation completes.PF the attached screenshot.Kindly help me to resolve the issue. [image: image.png] .Thanks Kaviya Vadivel From abhi.darkness at gmail.com Sat Oct 16 15:54:08 2021 From: abhi.darkness at gmail.com (Abhi R) Date: Sun, 17 Oct 2021 01:24:08 +0530 Subject: Issue in installing python In-Reply-To: References: , Message-ID: <8C99EA35-2A44-4749-AB3B-9372A81A01AC@hxcore.ol> Hello Welcome to the Python Mailing List. Images will not get rendered on a Mailing List. Can you please copy- paste the error you're seeing as text? Regards [1]Abhiram Sent from [2]Mail for Windows From: [3]Kaviya Vadivel Sent: 17 October 2021 01:16 To: [4]python-list at python.org Subject: Fwd: Issue in installing python ---------- Forwarded message --------- From: Kaviya Vadivel Date: Sat, 16 Oct 2021 at 17:00 Subject: Issue in installing python To: Hello Team, I have downloaded python 3.10.0 from python.org.I have windows 8.1.I have installed the python on my machine .But during installation Im getting application error.It doesn't install on my machine.But Im getting successful after the installation completes.PF the attached screenshot.Kindly help me to resolve the issue. [image: image.png] .Thanks Kaviya Vadivel -- https://mail.python.org/mailman/listinfo/python-list References Visible links 1. https://abhiramr.com/ 2. https://go.microsoft.com/fwlink/?LinkId=550986 3. mailto:kaviyavadivel1 at gmail.com 4. mailto:python-list at python.org From PythonList at DancesWithMice.info Sat Oct 16 16:21:34 2021 From: PythonList at DancesWithMice.info (dn) Date: Sun, 17 Oct 2021 09:21:34 +1300 Subject: Selenium py3.8+ DepreciationWarnings - where to find doc to update code? In-Reply-To: References: <741026852.124539.1634137897922@connect.xfinity.com> Message-ID: <50703f8d-59f1-d82f-19ee-8c298b5bcc1c@DancesWithMice.info> The issues illustrated likely have less to do with Python than with Selenium (or even Firefox - depending how far back we need to go). That and our fate with the many web-search engines prioritising 'authoritative sources' in their results. Such definition includes 'clicks' over time. It fails to distinguish (in our case) that software is improved/changes over time, and 'the old stuff' amongst the plethora of web-pages becomes 'wrong'. Plea: every web page should be dated, and all software-related publications include version numbers (just as your posts do here. Well done!) On 17/10/2021 05.02, Akkana Peck wrote: > jkk writes: >> Selenium 3.141+ >> python 3.8+ >> ubuntu 20.04 or windows 10 >> I'm trying to upgrade code from py3.6+ to py3.8+ and I'm getting several DepreciationWarnings. >> Can someone point me to where I can find the documentation that explains how to to remedy these warnings. What are the new preferred coding practices? > I've also been looking for that (Selenium 4.0.0a1, Python 3.9.5, > Ubuntu 21.04). For instance: > >>>> from selenium import webdriver >>>> profiledir = "/path/to/profile/dir" >>>> driver = webdriver.Firefox(firefox_profile=profiledir) > :1: DeprecationWarning: firefox_profile has been deprecated, please pass in a Service object > > What is a Service object and how do you use it to pass in profiles? > I've found API references like > https://www.selenium.dev/selenium/docs/api/rb/Selenium/WebDriver/Service.html > https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.common.service > but how do you create one, or use it to reference a specific profile? > I haven't been able to find any examples. Some of the confusion may have been caused by the fact that there are several 'moving parts', and all have had version upgrades but must still 'play nicely together'. Secondly, when we use 'alpha' or other pre-release versions of software, it is referred-to as "the bleeding edge" for good reason! In this case, a scan of the repo's history will elicit a groan (https://github.com/SeleniumHQ/selenium/blob/trunk/py/CHANGES) Way forward/check list: - upgrade to the *released* (4.0.0) version of Selenium - upgrade Python (likely already done) - upgrade Python-binding (https://pypi.org/project/selenium/4.0.0/) - ensure Firefox/Gecko-engine is compatible (?v48+ which happened long, long, ago!) Some of the question(s) may be answered under "Firefox Legacy" (https://www.selenium.dev/documentation/getting_started/how_to_upgrade_to_selenium_4/). However, going backwards is an awkward way to make progress! The 'new' method of setting a Custom Profile can be found in the docs (https://www.selenium.dev/documentation/webdriver/capabilities/driver_specific_capabilities/#setting-a-custom-profile) NB don't know when they were actually released but see "Last modified" date, and don't feel too bad! If you're interested in getting down-and-dirty with the API, there are new classes/methods. (https://www.selenium.dev/selenium/docs/api/py/api.html#webdriver-firefox) Finally, (Warning: un-read, so un-tested) I recalled that my 'reading pile' includes "How to Create Firefox Profile in Selenium WebDriver" (https://www.guru99.com/firefox-profile-selenium-webdriver.html) which *may* offer hints about the 'new' handling of FF profiles. Again, YMMV! -- Regards, =dn From shima80bd at gmail.com Sun Oct 17 14:50:33 2021 From: shima80bd at gmail.com (Umme Salma) Date: Mon, 18 Oct 2021 00:50:33 +0600 Subject: Is the bug reported to python Recently i upgraded my python version and its directory But when i try to download pyqt5 it gives out a holy error Do i have to install py 3.9 again pls help me take a look on this ty Message-ID: From hongyi.zhao at gmail.com Mon Oct 18 04:43:17 2021 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Mon, 18 Oct 2021 01:43:17 -0700 (PDT) Subject: Get a function definition/implementation hint similar to the one shown in pycharm. Message-ID: I've written the following python code snippet in pycharm: ```python import numpy as np from numpy import pi, sin a = np.array([1], dtype=bool) if np.in|vert(a) == ~a: print('ok') ``` When putting the point/cursor in the above code snippet at the position denoted by `|`, I would like to see information similar to that provided by `pycharm`, as shown in the following screenshots: https://user-images.githubusercontent.com/11155854/137619512-674e0eda-7564-4e76-af86-04a194ebeb8e.png https://user-images.githubusercontent.com/11155854/137619524-a0b584a3-1627-4612-ab1f-05ec1af67d55.png But I wonder if there are any other python packages/tools that can help me achieve this goal? Regards, HZ From cs at cskk.id.au Mon Oct 18 17:22:00 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 19 Oct 2021 08:22:00 +1100 Subject: Get a function definition/implementation hint similar to the one shown in pycharm. In-Reply-To: References: Message-ID: On 18Oct2021 01:43, Hongyi Zhao wrote: >I've written the following python code snippet in pycharm: >```python >import numpy as np >from numpy import pi, sin > >a = np.array([1], dtype=bool) >if np.in|vert(a) == ~a: > print('ok') >``` >When putting the point/cursor in the above code snippet at the position denoted by `|`, I would like to see information similar to that provided by `pycharm`, as shown in the following screenshots: > >https://user-images.githubusercontent.com/11155854/137619512-674e0eda-7564-4e76-af86-04a194ebeb8e.png >https://user-images.githubusercontent.com/11155854/137619524-a0b584a3-1627-4612-ab1f-05ec1af67d55.png > >But I wonder if there are any other python packages/tools that can help >me achieve this goal? Broadly, you want the "inspect" module, which is part of the stdlib, documented here: https://docs.python.org/3/library/inspect.html It has many functions for extracting information about things, and you want the signature() function to get the parameters and type annotations of a function. def f(a): ... sig = signature(f) You also want the function docstring for the help text, which is "f.__doc__" in the example above. This is what gets printed by help(): >>> import numpy as np >>> help(np.invert) It may be that PyCharm has additional information about some libraries allowing it to include a reference to the only documentation. Cheers, Cameron Simpson From hongyi.zhao at gmail.com Mon Oct 18 21:37:11 2021 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Mon, 18 Oct 2021 18:37:11 -0700 (PDT) Subject: Get a function definition/implementation hint similar to the one shown in pycharm. In-Reply-To: References: Message-ID: <6275eae6-0bc6-4243-9464-570c351eb020n@googlegroups.com> On Tuesday, October 19, 2021 at 5:22:25 AM UTC+8, cameron... at gmail.com wrote: > On 18Oct2021 01:43, Hongyi Zhao wrote: > >I've written the following python code snippet in pycharm: > >```python > >import numpy as np > >from numpy import pi, sin > > > >a = np.array([1], dtype=bool) > >if np.in|vert(a) == ~a: > > print('ok') > >``` > >When putting the point/cursor in the above code snippet at the position denoted by `|`, I would like to see information similar to that provided by `pycharm`, as shown in the following screenshots: > > > >https://user-images.githubusercontent.com/11155854/137619512-674e0eda-7564-4e76-af86-04a194ebeb8e.png > >https://user-images.githubusercontent.com/11155854/137619524-a0b584a3-1627-4612-ab1f-05ec1af67d55.png > > > >But I wonder if there are any other python packages/tools that can help > >me achieve this goal? > Broadly, you want the "inspect" module, which is part of the stdlib, > documented here: https://docs.python.org/3/library/inspect.html > > It has many functions for extracting information about things, and you > want the signature() function to get the parameters and type annotations > of a function. > > def f(a): > ... > > sig = signature(f) The following ipython test failed: In [1]: import numpy as np In [2]: from inspect import signature In [3]: signature(np.invert) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) in ----> 1 signature(np.invert) ~/.pyenv/versions/3.9.1/lib/python3.9/inspect.py in signature(obj, follow_wrapped) 3128 def signature(obj, *, follow_wrapped=True): 3129 """Get a signature object for the passed callable.""" -> 3130 return Signature.from_callable(obj, follow_wrapped=follow_wrapped) 3131 3132 ~/.pyenv/versions/3.9.1/lib/python3.9/inspect.py in from_callable(cls, obj, follow_wrapped) 2877 def from_callable(cls, obj, *, follow_wrapped=True): 2878 """Constructs Signature for the given callable object.""" -> 2879 return _signature_from_callable(obj, sigcls=cls, 2880 follow_wrapper_chains=follow_wrapped) 2881 ~/.pyenv/versions/3.9.1/lib/python3.9/inspect.py in _signature_from_callable(obj, follow_wrapper_chains, skip_bound_arg, sigcls) 2441 raise ValueError(msg) 2442 -> 2443 raise ValueError('callable {!r} is not supported by signature'.format(obj)) 2444 2445 ValueError: callable is not supported by signature > You also want the function docstring for the help text, which is > "f.__doc__" in the example above. This is what gets printed by help(): > > >>> import numpy as np > >>> help(np.invert) > > It may be that PyCharm has additional information about some libraries > allowing it to include a reference to the only documentation. > > Cheers, > Cameron Simpson From soyeomul at doraji.xyz Tue Oct 19 00:41:26 2021 From: soyeomul at doraji.xyz (=?utf-8?B?7Zmp67OR7Z2s?=) Date: Tue, 19 Oct 2021 13:41:26 +0900 Subject: Request to advise error for python. References: Message-ID: <87o87ly6bt.fsf@penguin> Dear ???, >>> [image: image.png] If you would like to show us your image, then write down the github/gitlab link. Of course i assume you have github/gitlab account. Because Mailing server does filter for dangerous things such as image file, video clip, action scripts (computer virus), i think... Sincerely, Gopher Byung-Hee From hongyi.zhao at gmail.com Tue Oct 19 01:17:57 2021 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Mon, 18 Oct 2021 22:17:57 -0700 (PDT) Subject: Get a function definition/implementation hint similar to the one shown in pycharm. In-Reply-To: References: Message-ID: On Tuesday, October 19, 2021 at 5:22:25 AM UTC+8, cameron... at gmail.com wrote: > On 18Oct2021 01:43, Hongyi Zhao wrote: > >I've written the following python code snippet in pycharm: > >```python > >import numpy as np > >from numpy import pi, sin > > > >a = np.array([1], dtype=bool) > >if np.in|vert(a) == ~a: > > print('ok') > >``` > >When putting the point/cursor in the above code snippet at the position denoted by `|`, I would like to see information similar to that provided by `pycharm`, as shown in the following screenshots: > > > >https://user-images.githubusercontent.com/11155854/137619512-674e0eda-7564-4e76-af86-04a194ebeb8e.png > >https://user-images.githubusercontent.com/11155854/137619524-a0b584a3-1627-4612-ab1f-05ec1af67d55.png > > > >But I wonder if there are any other python packages/tools that can help > >me achieve this goal? > Broadly, you want the "inspect" module, which is part of the stdlib, > documented here: https://docs.python.org/3/library/inspect.html > > It has many functions for extracting information about things, and you > want the signature() function to get the parameters and type annotations > of a function. > > def f(a): > ... > > sig = signature(f) > > You also want the function docstring for the help text, which is > "f.__doc__" in the example above. This is what gets printed by help(): > > >>> import numpy as np > >>> help(np.invert) But the following doesn't work: In [4]: help(~) File "", line 1 help(~) ^ SyntaxError: invalid syntax > It may be that PyCharm has additional information about some libraries > allowing it to include a reference to the only documentation. > > Cheers, > Cameron Simpson From rosuav at gmail.com Tue Oct 19 14:23:22 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 20 Oct 2021 05:23:22 +1100 Subject: Get a function definition/implementation hint similar to the one shown in pycharm. In-Reply-To: References: Message-ID: On Wed, Oct 20, 2021 at 4:45 AM hongy... at gmail.com wrote: > > On Tuesday, October 19, 2021 at 5:22:25 AM UTC+8, cameron... at gmail.com wrote: > > On 18Oct2021 01:43, Hongyi Zhao wrote: > > >I've written the following python code snippet in pycharm: > > >```python > > >import numpy as np > > >from numpy import pi, sin > > > > > >a = np.array([1], dtype=bool) > > >if np.in|vert(a) == ~a: > > > print('ok') > > >``` > > >When putting the point/cursor in the above code snippet at the position denoted by `|`, I would like to see information similar to that provided by `pycharm`, as shown in the following screenshots: > > > > > >https://user-images.githubusercontent.com/11155854/137619512-674e0eda-7564-4e76-af86-04a194ebeb8e.png > > >https://user-images.githubusercontent.com/11155854/137619524-a0b584a3-1627-4612-ab1f-05ec1af67d55.png > > > > > >But I wonder if there are any other python packages/tools that can help > > >me achieve this goal? > > Broadly, you want the "inspect" module, which is part of the stdlib, > > documented here: https://docs.python.org/3/library/inspect.html > > > > It has many functions for extracting information about things, and you > > want the signature() function to get the parameters and type annotations > > of a function. > > > > def f(a): > > ... > > > > sig = signature(f) > > > > You also want the function docstring for the help text, which is > > "f.__doc__" in the example above. This is what gets printed by help(): > > > > >>> import numpy as np > > >>> help(np.invert) > > But the following doesn't work: > > In [4]: help(~) > File "", line 1 > help(~) > ^ > SyntaxError: invalid syntax > That's because help() is a perfectly ordinary callable, and you can't pass an operator as a parameter. Try passing it a string instead: help("~") ChrisA From shishaozhong at gmail.com Wed Oct 20 05:31:58 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Wed, 20 Oct 2021 10:31:58 +0100 Subject: SQLAlchemy fault Message-ID: I read a txt file into Pandas Dataframe, and found a lot of nulls in a column. Then, I used SQLAlchemy and psycopg2. I created engine. I loaded data onto PostgreSQL. Strange thing happened. The column has no null at all. Does it mean that the data has been modified somewhere along the line? Does anyone know the robust and fast loading of Pandas frame data onto Postgres database? Regards, David From shishaozhong at gmail.com Wed Oct 20 11:46:36 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Wed, 20 Oct 2021 16:46:36 +0100 Subject: Alternatives to Jupyter Notebook Message-ID: Hello, Is anyone familiar with alternatives to Jupyter Notebook. My Jupyter notebook becomes unresponsive in browsers. Are there alternatives to read, edit and run Jupyter Notebook? Regards, David From cs at cskk.id.au Wed Oct 20 19:03:46 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 21 Oct 2021 10:03:46 +1100 Subject: [tkinter]Synchronous image diplay In-Reply-To: References: Message-ID: On 20Oct2021 20:18, Stefan Ram wrote: >ram at zedat.fu-berlin.de (Stefan Ram) writes: >>I want to diplay images fast in a slideshow (i.e., 10 images > > (There's a problem with my [S] key.) > > It seems that update_idletasks() solved my problem! Yes. That causes the event loop to resume, render, then run any pending idle tasks (which run when the event loop is idle, implying that any pending rendering is complete). So you know at that time that a new image will have been displayed. Think of it like flush() for file output, but for a GUI. Cheers, Cameron Simpson From seonghark at kookmin.ac.kr Thu Oct 21 01:10:15 2021 From: seonghark at kookmin.ac.kr (=?UTF-8?B?4oCN7KCV7ISx7ZWZKOuMgO2VmeybkOyDnS3snpDrj5nssKhJVOycte2VqeyghOqztSk=?=) Date: Thu, 21 Oct 2021 14:10:15 +0900 Subject: Request to advise error for python. In-Reply-To: <87o87ly6bt.fsf@penguin> References: <87o87ly6bt.fsf@penguin> Message-ID: Hi There are some errors in order to install numpy as follows. >>> pip install numpy File "", line 1 pip install numpy ^^^^^^^^^^^^^ SyntaxError: invalid syntax. Perhaps you forgot a comma? Would you advise me to correct error and install numpy or pandas? [image: image.png] =========================================== Seonghark Jeong KUL(Kookmin Unmanned vehicle research Laboratory) GSAEK, Kookmin Univ. E-Mail: seonghark at kookmin.ac.kr HP: 82-10-3600-7143 =========================================== 2021? 10? 20? (?) ?? 2:47, ??? ?? ??: > Dear ???, > > >>> [image: image.png] > > If you would like to show us your image, then write down the github/gitlab > link. Of course i assume you have github/gitlab account. Because Mailing > server does filter for dangerous things such as image file, video clip, > action scripts (computer virus), i think... > > Sincerely, Gopher Byung-Hee > > -- > https://mail.python.org/mailman/listinfo/python-list > -- From soyeomul at doraji.xyz Thu Oct 21 01:17:27 2021 From: soyeomul at doraji.xyz (=?utf-8?B?7Zmp67OR7Z2s?=) Date: Thu, 21 Oct 2021 14:17:27 +0900 Subject: Request to advise error for python. References: <87o87ly6bt.fsf@penguin> Message-ID: <877de7nehk.fsf@penguin> ??? writes: > Dear ???, > >>>> [image: image.png] > > If you would like to show us your image, then write down the github/gitlab > link. ... This is example: https://gitlab.com/soyeomul/test/-/commit/80d2b4f5e8eda0238301e9bca5bc33f0127572fd Sincerely, Gopher Byung-Hee From mats at wichmann.us Thu Oct 21 09:09:50 2021 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 21 Oct 2021 07:09:50 -0600 Subject: Request to advise error for python. In-Reply-To: References: <87o87ly6bt.fsf@penguin> Message-ID: On 10/20/21 23:10, ???(????-???IT????) via Python-list wrote: > Hi > > There are some errors in order to install numpy as follows. > >>>> pip install numpy > File "", line 1 > pip install numpy > ^^^^^^^^^^^^^ > SyntaxError: invalid syntax. Perhaps you forgot a comma? > > Would you advise me to correct error and install numpy or pandas? For this one, the command is run outside of Python - in other words, this is a shell command, not a Python command. Quit Python and try again. Extra reading: There are some nuances. If you are on a Linux system, Python is a system program and you don't want to try to install into system locations (you'll run into permission problems anyway), so trying a user install is useful. So: pip install --user numpy In fact, if you're on a Linux system you *may* prefer to install the packaged versions - use the appropriate package manager commands. The numpy site has lots more thoughts on installing - I believe they suggest using the conda installation system. https://numpy.org/install/ From shishaozhong at gmail.com Thu Oct 21 09:23:00 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Thu, 21 Oct 2021 14:23:00 +0100 Subject: df.count() to a Pandas dataframe with column names Message-ID: How to output the result of df.count() to a Pandas dataframe with column names? Regards, David From grant.b.edwards at gmail.com Thu Oct 21 10:33:46 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 21 Oct 2021 07:33:46 -0700 (PDT) Subject: Request to advise error for python. References: <87o87ly6bt.fsf@penguin> Message-ID: <61717a4a.1c69fb81.21e70.3d1d@mx.google.com> On 2021-10-21, Mats Wichmann wrote: > There are some nuances. If you are on a Linux system, Python is a > system program and you don't want to try to install into system > locations (you'll run into permission problems anyway), so trying a user > install is useful. So: > > pip install --user numpy > > In fact, if you're on a Linux system you *may* prefer to install the > packaged versions - use the appropriate package manager commands. Not all systems have a 'pip' executable. If a 'pip' exectuable does exist, it might not be the same version as your defualt python executable. It's usually a better idea to do it this way: $ python -m pip install --user numpy That said, if you're on Linux system, you're almostg always better off using your distro's package manger to install numpy. -- Grant From antoon.pardon at vub.be Fri Oct 22 07:19:18 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 22 Oct 2021 13:19:18 +0200 Subject: importing a module from a file without the '.py' suffix Message-ID: 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. From rob.cliffe at btinternet.com Fri Oct 22 08:00:54 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Fri, 22 Oct 2021 13:00:54 +0100 Subject: importing a module from a file without the '.py' suffix In-Reply-To: References: Message-ID: 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, subject to race conditions, file permission errors, wrong state after a crash, and probably other problems. It could be cleaned up a bit with try ... except, but is still not to be recommended. Can you just create a copy of your file with a .py extension? Best wishes Rob Cliffe On 22/10/2021 12:19, 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? > From chris at lessthan3.org.uk Fri Oct 22 08:17:10 2021 From: chris at lessthan3.org.uk (Chris Johns) Date: Fri, 22 Oct 2021 13:17:10 +0100 Subject: importing a module from a file without the '.py' suffix In-Reply-To: References: Message-ID: 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/_bootstrap_external.py Might help. Or not :) Cheers Chris Sent from my iPhone > On 22 Oct 2021, at 13:02, Rob Cliffe via Python-list wrote: > > ?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, subject to race conditions, file permission errors, wrong state after a crash, and probably other problems. > It could be cleaned up a bit with try ... except, but is still not to be recommended. > > Can you just create a copy of your file with a .py extension? > Best wishes > Rob Cliffe > >> On 22/10/2021 12:19, 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? >> > > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Fri Oct 22 08:26:20 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 22 Oct 2021 23:26:20 +1100 Subject: importing a module from a file without the '.py' suffix In-Reply-To: References: Message-ID: 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.python.org/3/library/importlib.html#importing-a-source-file-directly ChrisA From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Fri Oct 22 13:57:52 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Fri, 22 Oct 2021 18:57:52 +0100 Subject: New assignmens ... Message-ID: Hi! Why doesn't this work if (self.ctr:=self.ctr-1)<=0: while this works if (ctr:=ctr-1)<=0: Thanks From jon+usenet at unequivocal.eu Fri Oct 22 15:15:01 2021 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 22 Oct 2021 19:15:01 -0000 (UTC) Subject: New assignmens ... References: Message-ID: 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 seems a surprising omission. You'd expect at least 'attributeref' and 'subscription' to be allowed, if not the whole of 'target'. From rosuav at gmail.com Fri Oct 22 15:34:59 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Oct 2021 06:34:59 +1100 Subject: New assignmens ... In-Reply-To: References: Message-ID: 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 ":="] expression, > > but the attribute references "self.ctr" is no identifier! > > This seems a surprising omission. You'd expect at least 'attributeref' > and 'subscription' to be allowed, if not the whole of 'target'. That's not the primary use-case for assignment expressions, and they were highly controversial. It is much easier to expand it afterwards than to restrict it, or to have the feature rejected because people are scared of some small aspect of it. If you want to propose relaxing the restrictions, make your use-case and attempt to convince people of the value. ChrisA From PythonList at DancesWithMice.info Fri Oct 22 15:41:04 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 23 Oct 2021 08:41:04 +1300 Subject: New assignmens ... In-Reply-To: References: Message-ID: 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)<=0: >>> >>> assignment_expression ::= [identifier ":="] expression, >>> but the attribute references "self.ctr" is no identifier! >> >> This seems a surprising omission. You'd expect at least 'attributeref' >> and 'subscription' to be allowed, if not the whole of 'target'. > > That's not the primary use-case for assignment expressions, and they > were highly controversial. It is much easier to expand it afterwards > than to restrict it, or to have the feature rejected because people > are scared of some small aspect of it. ie neither can one use subscripted elements, eg list-elements, as the LHS of an assignment expression. -- Regards, =dn From PythonList at DancesWithMice.info Fri Oct 22 15:49:09 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 23 Oct 2021 08:49:09 +1300 Subject: New assignmens ... In-Reply-To: References: Message-ID: <469c6274-109d-65dd-c361-25474b5503e9@DancesWithMice.info> 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'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 seems a surprising omission. You'd expect at least 'attributeref' >>> and 'subscription' to be allowed, if not the whole of 'target'. >> >> That's not the primary use-case for assignment expressions, and they >> were highly controversial. It is much easier to expand it afterwards >> than to restrict it, or to have the feature rejected because people >> are scared of some small aspect of it. > > > ie neither can one use subscripted elements, eg list-elements, as the > LHS of an assignment expression. Whereas, creating a list (or tuple...) is legal because the structure's name is an "identifier"! if ( l := [ 1, 2, 3 ] > [ 1, 2 ] ): print( "True" ) -- Regards, =dn From greg.ewing at canterbury.ac.nz Fri Oct 22 19:51:05 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 23 Oct 2021 12:51:05 +1300 Subject: New assignmens ... In-Reply-To: References: <469c6274-109d-65dd-c361-25474b5503e9@DancesWithMice.info> Message-ID: 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 From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Fri Oct 22 21:10:51 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Sat, 23 Oct 2021 02:10:51 +0100 Subject: New assignmens ... References: Message-ID: ?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-1)<=0: >>> >>> assignment_expression ::= [identifier ":="] expression, >>> but the attribute references "self.ctr" is no identifier! >> >> This seems a surprising omission. You'd expect at least 'attributeref' >> and 'subscription' to be allowed, if not the whole of 'target'. > > That's not the primary use-case for assignment expressions, and they > were highly controversial. It is much easier to expand it afterwards > than to restrict it, or to have the feature rejected because people > are scared of some small aspect of it. > > If you want to propose relaxing the restrictions, make your use-case > and attempt to convince people of the value. > Well, I didn't follow the discussion of this new feature, but the reason I can see behind allowing it seems so valid for for ctr:=ctr-1 as for self.ctr:=self.ctr-1. The kind of use is exactly the same. One is for a normal function, the other for a method. IMHO this makes no sense at all. Arguable may be for example LHS ctrs[i], or something like that. But self.ctr ...! Too weird. Thanks Paulo From rosuav at gmail.com Fri Oct 22 21:41:55 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 23 Oct 2021 12:41:55 +1100 Subject: New assignmens ... In-Reply-To: References: Message-ID: 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 > >>>> 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 seems a surprising omission. You'd expect at least 'attributeref' > >> and 'subscription' to be allowed, if not the whole of 'target'. > > > > That's not the primary use-case for assignment expressions, and they > > were highly controversial. It is much easier to expand it afterwards > > than to restrict it, or to have the feature rejected because people > > are scared of some small aspect of it. > > > > If you want to propose relaxing the restrictions, make your use-case > > and attempt to convince people of the value. > > > Well, I didn't follow the discussion of this new feature, but the reason > I can see behind allowing it seems so valid for for ctr:=ctr-1 as for > self.ctr:=self.ctr-1. The kind of use is exactly the same. One is for a > normal function, the other for a method. > IMHO this makes no sense at all. Arguable may be for example LHS > ctrs[i], or something like that. But self.ctr ...! Too weird. > I've never used ctr:=ctr-1 either, though, so I don't know the actual use cases. Why is this being used in an assignment expression? Is it an ersatz loop? Common use-cases include: if m := re.match(...): while data := thing.read(): etc. All of them are doing exactly two things: testing if something is empty, and if it isn't, using it in a block of code. In what situations do you need to mutate an attribute and also test it, and how much hassle is it to simply break it out into two lines? The onus is on you to show that it needs to be more flexible. ChrisA From PythonList at DancesWithMice.info Fri Oct 22 22:01:05 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 23 Oct 2021 15:01:05 +1300 Subject: New assignmens ... In-Reply-To: References: <469c6274-109d-65dd-c361-25474b5503e9@DancesWithMice.info> Message-ID: 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 been taken slightly out-of-context. Referring back to the previous contribution: mutating a list-element is not legal, because just like an object's attribute addressed with dotted-notation, a subscripted object is not regarded as an identifier. Whereas creating a (whole) new list (for example) IS legal, because the list's name IS an identifier. Yes, the LHS must be an identifier - the point that was made in the first response (quoting "Python Language Reference") and since. -- Regards, =dn From bluebox03 at gmail.com Sat Oct 23 09:53:43 2021 From: bluebox03 at gmail.com (tommy yama) Date: Sat, 23 Oct 2021 22:53:43 +0900 Subject: Request to advise error for python. In-Reply-To: <61717a4a.1c69fb81.21e70.3d1d@mx.google.com> References: <87o87ly6bt.fsf@penguin> <61717a4a.1c69fb81.21e70.3d1d@mx.google.com> Message-ID: It seems you use windows to install. Then, you need conda. Pip works for Linux. Check this out. https://numpy.org/install/ On Thu, Oct 21, 2021, 11:35 PM Grant Edwards wrote: > On 2021-10-21, Mats Wichmann wrote: > > > There are some nuances. If you are on a Linux system, Python is a > > system program and you don't want to try to install into system > > locations (you'll run into permission problems anyway), so trying a user > > install is useful. So: > > > > pip install --user numpy > > > > In fact, if you're on a Linux system you *may* prefer to install the > > packaged versions - use the appropriate package manager commands. > > Not all systems have a 'pip' executable. If a 'pip' exectuable does > exist, it might not be the same version as your defualt python > executable. It's usually a better idea to do it this way: > > $ python -m pip install --user numpy > > That said, if you're on Linux system, you're almostg always better off > using your distro's package manger to install numpy. > > -- > Grant > > > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Sat Oct 23 10:55:37 2021 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 23 Oct 2021 15:55:37 +0100 Subject: Request to advise error for python. In-Reply-To: References: <87o87ly6bt.fsf@penguin> <61717a4a.1c69fb81.21e70.3d1d@mx.google.com> Message-ID: On 2021-10-23 14:53, tommy yama wrote: > It seems you use windows to install. > > > Then, you need conda. Pip works for Linux. > On Windows, 'conda' is for the Anaconda version of Python. If you're using the standard version of Python from python.org you use pip or, preferably, py -m pip. > Check this out. > https://numpy.org/install/ > > > On Thu, Oct 21, 2021, 11:35 PM Grant Edwards > wrote: > >> On 2021-10-21, Mats Wichmann wrote: >> >> > There are some nuances. If you are on a Linux system, Python is a >> > system program and you don't want to try to install into system >> > locations (you'll run into permission problems anyway), so trying a user >> > install is useful. So: >> > >> > pip install --user numpy >> > >> > In fact, if you're on a Linux system you *may* prefer to install the >> > packaged versions - use the appropriate package manager commands. >> >> Not all systems have a 'pip' executable. If a 'pip' exectuable does >> exist, it might not be the same version as your defualt python >> executable. It's usually a better idea to do it this way: >> >> $ python -m pip install --user numpy >> >> That said, if you're on Linux system, you're almostg always better off >> using your distro's package manger to install numpy. >> From gheskett at shentel.net Sat Oct 23 12:16:26 2021 From: gheskett at shentel.net (Gene Heskett) Date: Sat, 23 Oct 2021 12:16:26 -0400 Subject: front end gfx for a redpitaya VNA Message-ID: <202110231216.26981.gheskett@shentel.net> Greetings all; I have acquired the linux version of the front end for a redpitaya Vector Network Analyzer. Putting it on an rpi4b running raspbian buster, it gets to line 32 and bails out with this error: pi at rpi4:/media/pi/workspace/vna-linux-tool $ python3 ./vna.py Traceback (most recent call last): File "./vna.py", line 32, in from mpldatacursor import datacursor ModuleNotFoundError: No module named 'mpldatacursor' I have installed all the stuff that a search for "python-mpl" finds in synaptic, no change in the error above. Does anyone know where this resource might be found? Thanks all. Cheers, Gene Heskett. -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author, 1940) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From gheskett at shentel.net Sat Oct 23 12:29:24 2021 From: gheskett at shentel.net (Gene Heskett) Date: Sat, 23 Oct 2021 12:29:24 -0400 Subject: front end gfx for a redpitaya VNA Message-ID: <202110231229.24263.gheskett@shentel.net> Greetings all; I have acquired the linux version of the front end for a redpitaya Vector Network Analyzer. Putting it on an rpi4b running raspbian buster, it gets to line 32 and bails out with this error: pi at rpi4:/media/pi/workspace/vna-linux-tool $ python3 ./vna.py Traceback (most recent call last): File "./vna.py", line 32, in from mpldatacursor import datacursor ModuleNotFoundError: No module named 'mpldatacursor' I have installed all the stuff that a search for "python-mpl" finds in synaptic, no change in the error above. Does anyone know where this resource might be found? Never mind, I finally remembered pip3, which found it, and the linux front end now runs. All I need to do now is get the device out of my truck and plug it into my network. Progress, for some definition of the word. :o) Thank you all who might have posted the obvious. Cheers, Gene Heskett. -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author, 1940) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From jon+usenet at unequivocal.eu Sat Oct 23 09:42:36 2021 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sat, 23 Oct 2021 13:42:36 -0000 (UTC) Subject: New assignmens ... References: Message-ID: On 2021-10-23, Chris Angelico wrote: > I've never used ctr:=ctr-1 either, though, so I don't know the actual > use cases. Why is this being used in an assignment expression? Is it > an ersatz loop? > > Common use-cases include: > > if m := re.match(...): > > while data := thing.read(): > > etc. All of them are doing exactly two things: testing if something is > empty, and if it isn't, using it in a block of code. > > In what situations do you need to mutate an attribute and also test > it, and how much hassle is it to simply break it out into two lines? It's not hard to imagine something like: def get_expensive(self): return self.expensive or self.expensive := self.calculate_expensive() > The onus is on you to show that it needs to be more flexible. Is it though? It seems to me that the onus is on you to show that this special case is special enough to be given its own unique existence. It's a bit surprising that the PEP doesn't discuss this decision at all. From rosuav at gmail.com Sat Oct 23 14:55:25 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Oct 2021 05:55:25 +1100 Subject: New assignmens ... In-Reply-To: References: Message-ID: On Sun, Oct 24, 2021 at 4:39 AM Jon Ribbens via Python-list wrote: > > On 2021-10-23, Chris Angelico wrote: > > I've never used ctr:=ctr-1 either, though, so I don't know the actual > > use cases. Why is this being used in an assignment expression? Is it > > an ersatz loop? > > > > Common use-cases include: > > > > if m := re.match(...): > > > > while data := thing.read(): > > > > etc. All of them are doing exactly two things: testing if something is > > empty, and if it isn't, using it in a block of code. > > > > In what situations do you need to mutate an attribute and also test > > it, and how much hassle is it to simply break it out into two lines? > > It's not hard to imagine something like: > > def get_expensive(self): > return self.expensive or self.expensive := self.calculate_expensive() I usually write this sort of thing the other way: def get_expensive(self, key): if key not in self.cache: self.cache[key] = ... return self.cache[key] and then if you don't like the duplication, the cleanest way is to put the expensive calculation into the __missing__ method of a dict subclass. > > The onus is on you to show that it needs to be more flexible. > > Is it though? It seems to me that the onus is on you to show that > this special case is special enough to be given its own unique > existence. It's a bit surprising that the PEP doesn't discuss this > decision at all. The PEP was accepted. Thus it is now up to someone proposing a change to show that the change is worthwhile. Python has frequently started with a more restricted rule set, with the option to make it less restricted in the future. Case in point: Decorator syntax used to be limited to a small set of options, aimed at the known use-cases at the time. Then very recently, that was opened up to basically any expression. https://www.python.org/dev/peps/pep-0614/ Read over that document for an excellent example of how to take a tight proposal and recommend that it be made more flexible. Assignment expressions are currently in the restricted form, allowing only simple names, and it's up to you to propose and demonstrate the value of the increased flexibility. ChrisA From jon+usenet at unequivocal.eu Sat Oct 23 15:06:03 2021 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sat, 23 Oct 2021 19:06:03 -0000 (UTC) Subject: New assignmens ... References: Message-ID: On 2021-10-23, Chris Angelico wrote: > On Sun, Oct 24, 2021 at 4:39 AM Jon Ribbens via Python-list > wrote: >> On 2021-10-23, Chris Angelico wrote: >> > In what situations do you need to mutate an attribute and also test >> > it, and how much hassle is it to simply break it out into two lines? >> >> It's not hard to imagine something like: >> >> def get_expensive(self): >> return self.expensive or self.expensive := self.calculate_expensive() > > I usually write this sort of thing the other way: > > def get_expensive(self, key): > if key not in self.cache: > self.cache[key] = ... > return self.cache[key] > > and then if you don't like the duplication, the cleanest way is to put > the expensive calculation into the __missing__ method of a dict > subclass. Sure, but if "there's already another way of doing it" was a winning argument then assignment expressions wouldn't have been accepted into the language at all. >> > The onus is on you to show that it needs to be more flexible. >> >> Is it though? It seems to me that the onus is on you to show that >> this special case is special enough to be given its own unique >> existence. It's a bit surprising that the PEP doesn't discuss this >> decision at all. > > The PEP was accepted. Thus it is now up to someone proposing a change > to show that the change is worthwhile. > > Python has frequently started with a more restricted rule set, with > the option to make it less restricted in the future. Case in point: > Decorator syntax used to be limited to a small set of options, aimed > at the known use-cases at the time. Then very recently, that was > opened up to basically any expression. > > https://www.python.org/dev/peps/pep-0614/ > > Read over that document for an excellent example of how to take a > tight proposal and recommend that it be made more flexible. Assignment > expressions are currently in the restricted form, allowing only simple > names, and it's up to you to propose and demonstrate the value of the > increased flexibility. I think we're allowed to discuss things in this group without them having to turn into formal proposals. Personally I've never written a Python assignment expression, and I think it'll be a few years before Python 3.8 is old enough for them to be conveniently usable. From ethan at stoneleaf.us Sat Oct 23 16:50:54 2021 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 23 Oct 2021 13:50:54 -0700 Subject: New assignmens ... In-Reply-To: References: Message-ID: On 10/23/21 6:42 AM, Jon Ribbens via Python-list wrote: > On 2021-10-23, Chris Angelico wrote: >> The onus is on you to show that it needs to be more flexible. > > Is it though? Yes. > It seems to me that the onus is on you to show that > this special case is special enough to be given its own unique > existence. It already has existence, so no further proof is needed. > It's a bit surprising that the PEP doesn't discuss this > decision at all. In conversations as long as that one was, I'm not surprised this and maybe a couple other options didn't make it back to the PEP. Nevertheless, I recall the decision to start simple, and expand later if needed. -- ~Ethan~ From rosuav at gmail.com Sat Oct 23 17:05:21 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Oct 2021 08:05:21 +1100 Subject: New assignmens ... In-Reply-To: References: Message-ID: On Sun, Oct 24, 2021 at 7:48 AM Jon Ribbens via Python-list wrote: > > On 2021-10-23, Chris Angelico wrote: > > On Sun, Oct 24, 2021 at 4:39 AM Jon Ribbens via Python-list > > wrote: > >> On 2021-10-23, Chris Angelico wrote: > >> > In what situations do you need to mutate an attribute and also test > >> > it, and how much hassle is it to simply break it out into two lines? > >> > >> It's not hard to imagine something like: > >> > >> def get_expensive(self): > >> return self.expensive or self.expensive := self.calculate_expensive() > > > > I usually write this sort of thing the other way: > > > > def get_expensive(self, key): > > if key not in self.cache: > > self.cache[key] = ... > > return self.cache[key] > > > > and then if you don't like the duplication, the cleanest way is to put > > the expensive calculation into the __missing__ method of a dict > > subclass. > > Sure, but if "there's already another way of doing it" was a winning > argument then assignment expressions wouldn't have been accepted into > the language at all. There is always another way of doing it. The question is not so much "is this something that's currently absolutely impossible?" but more "how ugly is the current way of doing things?". Ugly is, of course, somewhat subjective, but if the current way of doing things involves a lot of extra hassle, or is error-prone, etc, etc, then there's room to show improvement. The original PEP showed this improvement in ways that involved simple names. Expanding on this is a separate proposal. > > Read over that document for an excellent example of how to take a > > tight proposal and recommend that it be made more flexible. Assignment > > expressions are currently in the restricted form, allowing only simple > > names, and it's up to you to propose and demonstrate the value of the > > increased flexibility. > > I think we're allowed to discuss things in this group without them > having to turn into formal proposals. Personally I've never written > a Python assignment expression, and I think it'll be a few years > before Python 3.8 is old enough for them to be conveniently usable. Well, if you don't use them, then you don't really have a horse in this race, so it doesn't matter. Someone who *does* want to make use of them can read over that document etc etc, and demonstrate the value of the proposal. BTW, it doesn't have to be a "formal proposal" in any sense; it just needs to be a logical and reasonable argument showing the value of the improvement (or the problems with the status quo). ChrisA From bluebox03 at gmail.com Sun Oct 24 02:45:15 2021 From: bluebox03 at gmail.com (tommy yama) Date: Sun, 24 Oct 2021 15:45:15 +0900 Subject: Request to advise error for python. In-Reply-To: References: <87o87ly6bt.fsf@penguin> <61717a4a.1c69fb81.21e70.3d1d@mx.google.com> Message-ID: Thank you MRAB. As somebody mentioned before, the easiest solution is you can do pip install before typing python. That would work. On Sun, Oct 24, 2021 at 12:00 AM MRAB wrote: > On 2021-10-23 14:53, tommy yama wrote: > > It seems you use windows to install. > > > > > > Then, you need conda. Pip works for Linux. > > > On Windows, 'conda' is for the Anaconda version of Python. If you're > using the standard version of Python from python.org you use pip or, > preferably, py -m pip. > > > Check this out. > > https://numpy.org/install/ > > > > > > On Thu, Oct 21, 2021, 11:35 PM Grant Edwards > > wrote: > > > >> On 2021-10-21, Mats Wichmann wrote: > >> > >> > There are some nuances. If you are on a Linux system, Python is a > >> > system program and you don't want to try to install into system > >> > locations (you'll run into permission problems anyway), so trying a > user > >> > install is useful. So: > >> > > >> > pip install --user numpy > >> > > >> > In fact, if you're on a Linux system you *may* prefer to install the > >> > packaged versions - use the appropriate package manager commands. > >> > >> Not all systems have a 'pip' executable. If a 'pip' exectuable does > >> exist, it might not be the same version as your defualt python > >> executable. It's usually a better idea to do it this way: > >> > >> $ python -m pip install --user numpy > >> > >> That said, if you're on Linux system, you're almostg always better off > >> using your distro's package manger to install numpy. > >> > -- > https://mail.python.org/mailman/listinfo/python-list > From alan at csail.mit.edu Sun Oct 24 03:52:53 2021 From: alan at csail.mit.edu (Alan Bawden) Date: Sun, 24 Oct 2021 03:52:53 -0400 Subject: New assignmens ... References: Message-ID: <86sfwqhnai.fsf@williamsburg.bawden.org> It seemed weird to me that only an identifier was allowed to be the target of an assignment expression. Then it occurred to me that function definitions are another place where only identifiers are allowed, but where I could imagine an attributeref or a subscription being used. E.g. def table[i](x): ... would mean the same thing as: def _temp_(x): ... table[i] = _temp_ I don't immediately see that this would screw up the grammar in any way, so why not allow it? A `def` statement is just another form of assignment, so just as for `:=` expressions, we should allow the target to be as general as possible! I'm guessing that about 70% of you will think that this is a horrible idea, 10% of you will find it compelling, and the remaining 20% will find themselves conflicted. You can count me in that last category... -- Alan Bawden From antoon.pardon at vub.be Sun Oct 24 05:23:48 2021 From: antoon.pardon at vub.be (O365 Dict) Date: Sun, 24 Oct 2021 11:23:48 +0200 Subject: New assignmens ... In-Reply-To: References: Message-ID: Op 23/10/2021 om 03:22 schreef Stefan Ram: > Paulo da Silva writes: >> Well, I didn't follow the discussion of this new feature, but the reason >> I can see behind allowing it seems so valid for for ctr:=ctr-1 as for >> self.ctr:=self.ctr-1. The kind of use is exactly the same. One is for a >> normal function, the other for a method. > The intention of the introduction of the assignment expression > was to allow grab the values of subexpressions so as to be able > to later use these value. This can be done with an identifier: > > if env_base := os.environ.get( "PYTHONUSERBASE", None ): > return env_base > > . I am wondering what use cases are there for having something > different than an identifier on the left side. Well I have the following use case: while (temp_result := calculate_next_couple(a, b))[1]: a, b = temp_result more calculations Which IMO would be clearer if I could just write: while ((a, b) := calculate_next_couple(a,b))[1]: more calculations Of course it would even more clear if I could write something like: while (a, b) := calculate_next_couple(a, b); b: more calculations or do: a, b = calculate_next_couple(a, b) while b: more calculations -- Antoon. From anikdey0110 at gmail.com Sun Oct 24 07:41:08 2021 From: anikdey0110 at gmail.com (Anik Dey) Date: Sun, 24 Oct 2021 17:11:08 +0530 Subject: Unable to Install Matplotlib & Pandas for Python 3.10 Message-ID: Hello, I downloaded & installed Python 3.10 but it didn't replace Python 3.9. And now I can't install Matplotlib & Pandas. What should I do? From rosuav at gmail.com Sun Oct 24 11:18:27 2021 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 25 Oct 2021 02:18:27 +1100 Subject: New assignmens ... In-Reply-To: <86sfwqhnai.fsf@williamsburg.bawden.org> References: <86sfwqhnai.fsf@williamsburg.bawden.org> Message-ID: On Mon, Oct 25, 2021 at 2:13 AM Alan Bawden wrote: > > It seemed weird to me that only an identifier was allowed to be the > target of an assignment expression. Then it occurred to me that > function definitions are another place where only identifiers are > allowed, but where I could imagine an attributeref or a subscription > being used. E.g. > > def table[i](x): > ... > > would mean the same thing as: > > def _temp_(x): > ... > table[i] = _temp_ > > I don't immediately see that this would screw up the grammar in any way, > so why not allow it? A `def` statement is just another form of > assignment, so just as for `:=` expressions, we should allow the target > to be as general as possible! > > I'm guessing that about 70% of you will think that this is a horrible > idea, 10% of you will find it compelling, and the remaining 20% will > find themselves conflicted. You can count me in that last category... This has come up periodically, but it's a bit tricky to define some of the edge cases, like what the function's name should be. But it would definitely help with building dispatch tables. Currently, I tend to build them with a decorator: tools = {} def tool(f): tools[f.__name__] = f return f @tool def frobnicate(): ... @tool def spamify(): ... In theory, it would be possible to do this: def tools["frobnicate"](): ... But I'm not sure that it's truly better. ChrisA From python at mrabarnett.plus.com Sun Oct 24 11:46:53 2021 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 24 Oct 2021 16:46:53 +0100 Subject: Unable to Install Matplotlib & Pandas for Python 3.10 In-Reply-To: References: Message-ID: <3e8f937e-1fe4-0814-7be9-d2bdf09bf90b@mrabarnett.plus.com> On 2021-10-24 12:41, Anik Dey wrote: > Hello, I downloaded & installed Python 3.10 but it didn't replace Python > 3.9. And now I can't install Matplotlib & Pandas. What should I do? > Multiple versions of Python can exist alongside each other. You haven't said what you mean by "can't install". If you're on Windows, you can install libraries by using the Windows Command Prompt and typing: py -3.10 -m pip install matplotlib py -3.10 -m pip install pandas "py" is the Python launcher and "py -3.10" will make it run Python 3.10 specifically. From mats at wichmann.us Sun Oct 24 18:59:36 2021 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 24 Oct 2021 16:59:36 -0600 Subject: Unable to Install Matplotlib & Pandas for Python 3.10 In-Reply-To: <3e8f937e-1fe4-0814-7be9-d2bdf09bf90b@mrabarnett.plus.com> References: <3e8f937e-1fe4-0814-7be9-d2bdf09bf90b@mrabarnett.plus.com> Message-ID: On 10/24/21 09:46, MRAB wrote: > On 2021-10-24 12:41, Anik Dey wrote: >> Hello, I downloaded & installed Python 3.10 but it didn't replace Python >> 3.9. And now I can't install Matplotlib & Pandas. What should I do? >> > Multiple versions of Python can exist alongside each other. > > You haven't said what you mean by "can't install". > > If you're on Windows, you can install libraries by using the Windows > Command Prompt and typing: > > py -3.10 -m pip install matplotlib > py -3.10 -m pip install pandas except... if there aren't wheels yet. easy to check: https://pypi.org/project/matplotlib/#files https://pypi.org/project/pandas/#files and... there aren't. stick with 3.9 for now if you really need these, or go with one of the unofficial builds that can be found with some searching. From avigross at verizon.net Sun Oct 24 19:46:18 2021 From: avigross at verizon.net (Avi Gross) Date: Sun, 24 Oct 2021 19:46:18 -0400 Subject: New assignmens ... In-Reply-To: <86sfwqhnai.fsf@williamsburg.bawden.org> References: <86sfwqhnai.fsf@williamsburg.bawden.org> Message-ID: <00b101d7c931$573d61e0$05b825a0$@verizon.net> No, many things need not be as general as possible once you consider how much work it may take to develop code and how many bugs and oddities might be introduced and even how much it may slow the interpreter. I could make an argument that everywhere you can put in a character string should also allow a regular expression but why? It makes no sense to allow you to supply a filename to create using a regular expression as you are not matching anything. Worse, perfectly valid string that may contain a dollar sign or period or many other characters used in regular expression may really be messed up if evaluated as a regular expression. So is it any wonder NOBODY suggests the above be done? As Chris has said, something was added to Python that is a partial implementation. There are fairly reasonable ways to do additional things and until recently, those were the proper and only way. But the recent change does not preclude a later upgrade if anyone is not only convinced it is worth doing but of higher priority than the scarce resources needed to do lots of other worthy and requested things including fixing bugs. I imagine you can create some fairly complex examples you can suggest should be handled for generality including some very indirect references created dynamically. The code to recognize any abstract use of symbols may not only slow down every operation of even the simplest type but generate all kinds of error messages nobody will understand, let alone translate into other languages properly! Right now, it is simpler. An error message can say that only certain simple usages are allowed. Now if anyone wants to donate a few hundred thousand dollars if used to make the change, or offer to do it free, who knows? Of course, this means anyone using the feature may need to check your version of Python to see if the feature exists before ... -----Original Message----- From: Python-list On Behalf Of Alan Bawden Sent: Sunday, October 24, 2021 3:53 AM To: python-list at python.org Subject: Re: New assignmens ... It seemed weird to me that only an identifier was allowed to be the target of an assignment expression. Then it occurred to me that function definitions are another place where only identifiers are allowed, but where I could imagine an attributeref or a subscription being used. E.g. def table[i](x): ... would mean the same thing as: def _temp_(x): ... table[i] = _temp_ I don't immediately see that this would screw up the grammar in any way, so why not allow it? A `def` statement is just another form of assignment, so just as for `:=` expressions, we should allow the target to be as general as possible! I'm guessing that about 70% of you will think that this is a horrible idea, 10% of you will find it compelling, and the remaining 20% will find themselves conflicted. You can count me in that last category... -- Alan Bawden -- https://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Sun Oct 24 20:04:19 2021 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 25 Oct 2021 01:04:19 +0100 Subject: Unable to Install Matplotlib & Pandas for Python 3.10 In-Reply-To: References: <3e8f937e-1fe4-0814-7be9-d2bdf09bf90b@mrabarnett.plus.com> Message-ID: <0153087f-1d54-eb90-cae4-003b80000ac4@mrabarnett.plus.com> On 2021-10-24 23:59, Mats Wichmann wrote: > On 10/24/21 09:46, MRAB wrote: > > On 2021-10-24 12:41, Anik Dey wrote: > >> Hello, I downloaded & installed Python 3.10 but it didn't replace Python > >> 3.9. And now I can't install Matplotlib & Pandas. What should I do? > >> > > Multiple versions of Python can exist alongside each other. > > > > You haven't said what you mean by "can't install". > > > > If you're on Windows, you can install libraries by using the Windows > > Command Prompt and typing: > > > > py -3.10 -m pip install matplotlib > > py -3.10 -m pip install pandas > > except... if there aren't wheels yet. easy to check: > > https://pypi.org/project/matplotlib/#files > https://pypi.org/project/pandas/#files > > and... there aren't. stick with 3.9 for now if you really need these, > or go with one of the unofficial builds that can be found with some > searching. Ah, yes, Christoph Gohlke's site has them: https://www.lfd.uci.edu/~gohlke/pythonlibs/#matplotlib From mats at wichmann.us Sun Oct 24 21:10:57 2021 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 24 Oct 2021 19:10:57 -0600 Subject: what's unsafe to do in a __getattr__? Message-ID: <476f60c7-0668-3ea1-ef16-f095bdd46eaf@wichmann.us> Have run into a problem on a "mature" project I work on (there are many years of history before I joined), there are a combination of factors that combine to trigger a KeyError when using copy.copy(). I don't want to write a massive essay here but hoping to give enough to set the context. There's a class that's a kind of proxy, so there's some "magic" that could be present. The magic is detected by looking for a kind of memo annotation, so the __getattr__ starts with this: # Methods that make this class act like a proxy. def __getattr__(self, name): attr = getattr(self.__dict__['__subject'], name) and that's what blows up. It happens for a user doing something we... ahem... don't expect. They just picked up the Py3-only version of the project and now they're getting the issue. Nothing in the project defined a __reduce__ex__ function, but one is picked up from the base "object" type, so copy.copy generates some pickle information and passes it to copy._reconstruct as the state parameter. This stanza: if state is not None: ... if hasattr(y, '__setstate__'): y.__setstate__(state) so our class's __getattr__ is called to look for __setstate__. But at this stage, the copy's instance has only been created, the operations that will fill in the details haven't happened yet, so we take a KeyError. So apparently the attempt in the __getattr__ to go fishing in our own dict for something we set ourselves is unsafe. Is there a guideline for what you can / cannot expect to be safe to do? My naiive expectations would be that when __getattr__ is called, you can expect an instance to have been already initialized, but if I'm not reading the copy module wrong, that's not always true. Is a better answer for this class to provide a __copy__ method to more precisely control how copying happens? From eryksun at gmail.com Mon Oct 25 02:48:22 2021 From: eryksun at gmail.com (Eryk Sun) Date: Mon, 25 Oct 2021 01:48:22 -0500 Subject: [tkinter][Windows]Unexpected state report for the tab key In-Reply-To: References: Message-ID: On 10/24/21, Stefan Ram wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: >>tab_down_hllDll.GetKeyState(tab_down_VK_TAB) & 0b1000000000000000 > > In the meantime, I read about "GetAsyncKeyState". I thought that > this would solve my problem, but no. Odd. It works for me in the classic console and the Windows Terminal pseudoconsole. The tab key's up/down state is updated immediately. import ctypes import msvcrt import time kernel32 = ctypes.WinDLL('kernel32', use_last_error=True) user32 = ctypes.WinDLL('user32', use_last_error=True) VK_TAB = 0x09 def tab_down(): return bool(user32.GetAsyncKeyState(VK_TAB) & 0x8000) def flush_console_input(): """Flush the input buffer of the process (pseudo)console.""" try: with open('conin$') as f: h = msvcrt.get_osfhandle(f.fileno()) kernel32.FlushConsoleInputBuffer(h) except OSError: pass def test(): for i in range(100): print('tab down:', tab_down()) time.sleep(0.1) flush_console_input() test() Flushing the console input buffer isn't necessary. I just prefer it instead of leaving the key presses in the buffer. Usually a GUI wants GetKeyState() instead, which is synchronized with input messages in the thread's message queue as they're processed. But GetAsyncKeyState() should do what you want, if you don't need synchronization with input messages. From antoon.pardon at vub.be Mon Oct 25 05:20:52 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 25 Oct 2021 11:20:52 +0200 Subject: New assignmens ... In-Reply-To: <00b101d7c931$573d61e0$05b825a0$@verizon.net> References: <86sfwqhnai.fsf@williamsburg.bawden.org> <00b101d7c931$573d61e0$05b825a0$@verizon.net> Message-ID: <5761dd65-4e87-8b8c-1400-edb8212048db@vub.be> On 25/10/2021 01:46, Avi Gross via Python-list wrote: > No, many things need not be as general as possible once you consider how > much work it may take to develop code and how many bugs and oddities might > be introduced and even how much it may slow the interpreter. ... > I imagine you can create some fairly complex examples you can suggest should > be handled for generality including some very indirect references created > dynamically. The code to recognize any abstract use of symbols may not only > slow down every operation of even the simplest type but generate all kinds > of error messages nobody will understand, let alone translate into other > languages properly! Right now, it is simpler. An error message can say that > only certain simple usages are allowed. I don't consider this a strong argument. Limiting the scope of the walrus operator will just force people organizing there code where they will use a normal assignment. So the resulting code will not be faster, less complex or generate less error messages because the complexity of the assignment that is needed is still the same. Or you force people to be "creative" as follows: Suppose I would like to write a loop as follows: while ((a, b) := next_couple(a, b))[1]: do needed calculations What I can do is write it as follows: while [tmp := next_couple(a,b), a := tmp[0], b := tmp[1]][-1]: do needed calculations I really don't see what is gained by "forcing" me to right the second code over the first. -- Antoon Pardon From rob.cliffe at btinternet.com Mon Oct 25 08:13:46 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 25 Oct 2021 13:13:46 +0100 Subject: [tkinter][Windows]Unexpected state report for the tab key In-Reply-To: References: Message-ID: <4a5e6483-f304-2751-840f-501db2c96710@btinternet.com> On 25/10/2021 02:57, Stefan Ram wrote: > GetKeyState still returns that the tab key > is pressed after the tab key already has been released. > Well, how then am I going to make my slide show stop the > moment the key is being released? > > Does tkinter allow you to trap KeyUp (and KeyDown) events? (I'm not familiar with tkinter, but in wxpython you can.) And if so, does trapping KeyUp solve the problem? Best wishes Rob Cliffe From avigross at verizon.net Mon Oct 25 12:06:22 2021 From: avigross at verizon.net (Avi Gross) Date: Mon, 25 Oct 2021 12:06:22 -0400 Subject: New assignmens ... In-Reply-To: <5761dd65-4e87-8b8c-1400-edb8212048db@vub.be> References: <86sfwqhnai.fsf@williamsburg.bawden.org> <00b101d7c931$573d61e0$05b825a0$@verizon.net> <5761dd65-4e87-8b8c-1400-edb8212048db@vub.be> Message-ID: <007b01d7c9ba$417f97e0$c47ec7a0$@verizon.net> Antoon, Just to be clear. I am talking about a different measure of efficiency. If you have code that handles a limited functionality properly it can be quite simple. If you then expand the code to handle ever more situations, then it may do things like a series of IF statements to determine which of many things to do so it now takes a while to just reach the part that does the most common case. I have seen people use code that knows what arguments to expect and just does things simply, like adding two integers together. Then the code is improved so it detects if either argument is floating point and now does any needed conversions. Soon you add support for complex numbers or character strings that look like "23" and then even parse "twelve dollars and forty two cents" in English and then a few other languages. Next you accept range objects and other things that make sense to add and accept an undefined number of arguments and name the darn thing sum_everything() and proudly show it off. It now has an amazing number of errors it can propagate or warn about. But, you can still use it to add 2 and 2. Now, yes, nobody needs a function to just add two numbers. If that bothers you, make is add the absolute values or something a tad more interesting. But the point is that any code that invokes sum_everything() may now pay a penalty in terms of performance just in the beginning part where it tests how many arguments it got, what types they are, and so on. The topic here is the Python run-time parser though. It is reading your code and doing whatever complex set of things it has to do to parse from a fairly large set of possible valid programs as well as invalid ones. I have never looked deeply at how it works but my guess is that somewhere in there are concepts like: simple_asignment_expression can look like THIS. complex _assignment expression can look like simple_assignment_expression OR THAT OR ... So to parse code you often need to look at alternate ways of connecting symbols and hopefully find the one and only way it has to be looked at. Parentheses as an example have many possible meanings and you may not know which meaning when you encounter it until you keep going and see where there may be a matching one but ignore any within a character string. I won't go on but the point is that the parser can jump through more hoops even in the most usual cases when it has to look for new cases not originally designed in. Your argument that people using other techniques to get the functionality they want is not really relevant as I do not deny it. My point is that the most common ways NORMALLY used are the ones that drive the efficiency of a system. So if adding functionality to include new cases/situations doubles the time it takes to do the most common case and that is used 98% of the time, then how much overall gain for the other 2% is needed to counterbalance it? I find a common pattern in software that often looks like extra layers around a function call. There may be a function to create an object given a character string argument like vector("integer", 1, 2, 3") or vector("character", "a", "b") that lets you create all kinds of vectors. Someone comes along with a bright idea to make programmers instead call make_integer(1, 2, 3) and make_character("a", "b") and more like that. We now have lots of new function that are just going to turn around and call vector() with a different appropriate string as the first argument and pass along the rest. We now have a function calling a second function. Yes, there are many possible advantages here including ways to check if you are using your code as intended. But there is overhead. And in a tight loop repeated millions of times, can you blame a programmer who knows, if they just call vector() directly, or perhaps a deeper function that vector() calls when it knows it is using integers? I will end with this. If someone wants to design a new language from scratch and with a goal of starting with as general a set of concepts as they can, fine. Design it carefully. Build it and if it works well enough, use it. But to ask an existing language to add features or expand existing ones is not at all the same thing and requires much more care. In python, you can find areas that are a bit confusing such as how multiple inheritance in objects is done. It can require some tweaking to make your objects in ways that the right thing is inherited from the other objects the way you want if more than one has the same method and you can have subtle errors. Arguably the darn thing is too general and many other languages instead decide not to support multiple inheritance and may use other interesting ways to get similar functionality. But although this can be a very nice feature allowing you to design quite sophisticated sets of objects that inherit all kinds of nifty powers from other existing objects, it can be a drag on performance if it does a search through a big mess to find the right function to call at run time! Sometimes it may be easier to not use multiple inheritance in some part of your code and use a work-around to get what you want. I am not against extending Python in the direction someone wants. I am FOR careful examination and study before making the change and weighing whether this is likely to be more useful than other things being asked for and other relative costs. Many things turn out not to be needed. I recall programs designed to use every letter of the alphabet (and other symbols) whether needed or not. I mean things like "d" for delete and "a" for add and "t" for transpose. Just to be complete, make up something that "q" or "z" do. Why? Not because anyone wants or needs those. I have seen projects like that then take longer to create and harder to test and the users mostly thought it was too complex and rarely or never used some functionality. I have made macros that allow something in an emacs editor like transpose-letter and transpose-word and continued with sentences, paragraphs, chapters and something beyond like transpose-on-paste-buffers. But most people actually just do a cut and move and paste operation for the more complex scenarios even if they remember the fancy version exists and is bound to some forgotten series of keys clicked together like control-X control-alt-t or something. -----Original Message----- From: Python-list On Behalf Of Antoon Pardon Sent: Monday, October 25, 2021 5:21 AM To: python-list at python.org Subject: Re: New assignmens ... On 25/10/2021 01:46, Avi Gross via Python-list wrote: > No, many things need not be as general as possible once you consider > how much work it may take to develop code and how many bugs and > oddities might be introduced and even how much it may slow the interpreter. ... > I imagine you can create some fairly complex examples you can suggest > should be handled for generality including some very indirect > references created dynamically. The code to recognize any abstract use > of symbols may not only slow down every operation of even the simplest > type but generate all kinds of error messages nobody will understand, > let alone translate into other languages properly! Right now, it is > simpler. An error message can say that only certain simple usages are allowed. I don't consider this a strong argument. Limiting the scope of the walrus operator will just force people organizing there code where they will use a normal assignment. So the resulting code will not be faster, less complex or generate less error messages because the complexity of the assignment that is needed is still the same. Or you force people to be "creative" as follows: Suppose I would like to write a loop as follows: while ((a, b) := next_couple(a, b))[1]: do needed calculations What I can do is write it as follows: while [tmp := next_couple(a,b), a := tmp[0], b := tmp[1]][-1]: do needed calculations I really don't see what is gained by "forcing" me to right the second code over the first. -- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list From dvl at psu.edu Mon Oct 25 12:47:45 2021 From: dvl at psu.edu (Christman, Roger Graydon) Date: Mon, 25 Oct 2021 16:47:45 +0000 Subject: New assignmens ... Message-ID: Message: 8 Date: Mon, 25 Oct 2021 11:20:52 +0200 From: Antoon Pardon To: python-list at python.org Subject: Re: New assignmens ... Message-ID: <5761dd65-4e87-8b8c-1400-edb8212048db at vub.be> Content-Type: text/plain; charset=utf-8; format=flowed On 25/10/2021 11:20, Anton Pardon wrote: > Suppose I would like to write a loop as follows: > while ((a, b) := next_couple(a, b))[1]: > do needed calculations > What I can do is write it as follows: > while [tmp := next_couple(a,b), a := tmp[0], b := tmp[1]][-1]: > do needed calculations > I really don't see what is gained by "forcing" me to right the second code over the first. No, nobody is forcing you to right it the second way over the first. Nobody is forcing you to use the walrus operator at all! Instead, I would recommend something more like: while b: do needed calculations (a,b) = next_couple(a,b) This requires even less typing than what you had before! But it also raises a whole lot of problems with this particular example: -- neither a nor b is defined in your sample while loop. It seems you would need to initialize a and b before your while loop (and mine) -- is b truly a boolean value, or are you short-cutting some other value? -- are a and b truly necessary parameters to next_couple, or are they just there to remind the function of its previous return values? If the latter, poerhaps you want a stream or list or something with yield This example (and some of the others I have seen) just highlight how programmers will take advantage of any new tool to help them write worse code than if they did not have the tool. In my mind, the walrus operator was designed to serve a particular niche case like this one: while (x := input()) > 0: where not having the operator required duplicating the input() operation both before the loop and at the end of the loop -- or more complicated cases where some additional operations had to be performed to get that test value for the while condition (such as getting the b out of (a,b)). But the walrus only adds a benefit if it is there to avoid the duplication of the code that is used to obtain that test condition. This next_couple example does not qualify, since apparently (a,b) are initialized by some other means (and not be a call to next_couple with undefined values) Or the other abuse I saw recently about using the walrus operator: while (self.ctr := self.ctr-1) > 0: -- there was no compelling reason for a loop counter to be a class variable (anyone who peeks at this counter when the loop is down would only see a zero) -- this requires self.ctr to be initialized to a value one higher than the first meaningful value (start at 11 if you want to count down from 10) So my recommended alternative, which furthermore also takes less typing: while ctr > 0: ... ctr = ctr-1 TL;DR: The Walrus operator serves the purpose as described in its PEP just as it is, and I see no compelling reason to expand its use. It is there to reduce code size by eliminating a duplication of code, If the code you write using the walrus operator is longer or more complicated than the code would be without it, you are misusing it. Roger Christman Pennsylvania State University From mats at wichmann.us Mon Oct 25 13:05:23 2021 From: mats at wichmann.us (Mats Wichmann) Date: Mon, 25 Oct 2021 11:05:23 -0600 Subject: what's unsafe to do in a __getattr__? In-Reply-To: <24950.57304.549761.244709@ixdm.fritz.box> References: <476f60c7-0668-3ea1-ef16-f095bdd46eaf@wichmann.us> <24950.57304.549761.244709@ixdm.fritz.box> Message-ID: On 10/25/21 10:48, Dieter Maurer wrote: > Mats Wichmann wrote at 2021-10-24 19:10 -0600: >> Have run into a problem on a "mature" project I work on (there are many >> years of history before I joined), there are a combination of factors >> that combine to trigger a KeyError when using copy.copy(). >> ... >> There's a class that's a kind of proxy ... > > "Proxying" has become very difficult since the introduction > of Python's "new style classes" and looking up "special methods" > on the type rather then the type instance. > > This essentially means that the proxy must implement all > "special methods" that may be relevant to the application. > > All special methods start and end with `"__"`. > Your `__getattr__` could raise an `AttributeError` as soon as > it is called with such a name. > Thanks. Raising an AttributeError here was what I was going to propose so maybe I'll take your reply as validation I was on the right track. This stuff was definitely defined in an era before the new-style classes, might have to examine some other proxying classes to make sure there aren't other holes... thanks again, -- mats From rosuav at gmail.com Mon Oct 25 13:05:56 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Oct 2021 04:05:56 +1100 Subject: New assignmens ... In-Reply-To: <007b01d7c9ba$417f97e0$c47ec7a0$@verizon.net> References: <86sfwqhnai.fsf@williamsburg.bawden.org> <00b101d7c931$573d61e0$05b825a0$@verizon.net> <5761dd65-4e87-8b8c-1400-edb8212048db@vub.be> <007b01d7c9ba$417f97e0$c47ec7a0$@verizon.net> Message-ID: On Tue, Oct 26, 2021 at 3:07 AM Avi Gross via Python-list wrote: > I will end with this. If someone wants to design a new language from scratch > and with a goal of starting with as general a set of concepts as they can, > fine. Design it carefully. Build it and if it works well enough, use it. I'll add to this: Please do exactly that! It's a great mental exercise. Sometimes you'll end up using it as a domain-specific language, or maybe it'll become a sort of ersatz command interpreter, or something; other times, you do the work of designing it purely for the effect of trying it, and you've learned how languages work. What you'll find is that there are extremes that are utterly and completely useless, such as Turing tarpits (almost no language facilities, but technically possible to write anything), or things so generic that they are nothing more than containers ("a script in this language is whatever code will make it happen"). In between, every programming language has to make decisions. What are its goals? What kinds of problems should be easy to solve in this language? Is it meant to be general-purpose and able to do most things, or special-purpose but extremely elegant within its domain? And along the way, you'll gain a better appreciation for every language you work with, plus a mental comprehension that lets you understand WHY this language or that language is good for some task. ChrisA From dieter at handshake.de Mon Oct 25 12:48:24 2021 From: dieter at handshake.de (Dieter Maurer) Date: Mon, 25 Oct 2021 18:48:24 +0200 Subject: what's unsafe to do in a __getattr__? In-Reply-To: <476f60c7-0668-3ea1-ef16-f095bdd46eaf@wichmann.us> References: <476f60c7-0668-3ea1-ef16-f095bdd46eaf@wichmann.us> Message-ID: <24950.57304.549761.244709@ixdm.fritz.box> Mats Wichmann wrote at 2021-10-24 19:10 -0600: >Have run into a problem on a "mature" project I work on (there are many >years of history before I joined), there are a combination of factors >that combine to trigger a KeyError when using copy.copy(). > ... >There's a class that's a kind of proxy ... "Proxying" has become very difficult since the introduction of Python's "new style classes" and looking up "special methods" on the type rather then the type instance. This essentially means that the proxy must implement all "special methods" that may be relevant to the application. All special methods start and end with `"__"`. Your `__getattr__` could raise an `AttributeError` as soon as it is called with such a name. From antoon.pardon at vub.be Mon Oct 25 14:33:42 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 25 Oct 2021 20:33:42 +0200 Subject: New assignmens ... In-Reply-To: <007b01d7c9ba$417f97e0$c47ec7a0$@verizon.net> References: <86sfwqhnai.fsf@williamsburg.bawden.org> <00b101d7c931$573d61e0$05b825a0$@verizon.net> <5761dd65-4e87-8b8c-1400-edb8212048db@vub.be> <007b01d7c9ba$417f97e0$c47ec7a0$@verizon.net> Message-ID: <465d7e85-a6a0-bb24-7148-93019536c355@vub.be> Op 25/10/2021 om 18:06 schreef Avi Gross via Python-list: > Antoon, > > Just to be clear. I am talking about a different measure of efficiency. No you are not. > > The topic here is the Python run-time parser though. Yes and that is what I am talking about. > It is reading your code > and doing whatever complex set of things it has to do to parse from a fairly > large set of possible valid programs as well as invalid ones. I have never > looked deeply at how it works but my guess is that somewhere in there are > concepts like: > > simple_asignment_expression can look like THIS. > complex _assignment expression can look like simple_assignment_expression OR > THAT OR ... > > So to parse code you often need to look at alternate ways of connecting > symbols and hopefully find the one and only way it has to be looked at. > Parentheses as an example have many possible meanings and you may not know > which meaning when you encounter it until you keep going and see where there > may be a matching one but ignore any within a character string. I won't go > on but the point is that the parser can jump through more hoops even in the > most usual cases when it has to look for new cases not originally designed > in. IMO that extra complexity is insignificant. You really don't reduce the complexity of your parser much if you would limit it so that indexes can only be names so that the programmer instead of being able to write: var = tab[some expression] is forced to write it as: index = some expression var = tab[index] Because all that machinery to evaluate some expression needs to be there anyway. In the same way we have already all the machinery present for assignments. By putting limits on the walrus code, you are not reducing complexity, you are increasing it. You are increasing complexity because you can't just reuse the code that handles an ordinary assignment. You now need specific code to limit it's use. -- Antoon Pardon. From rosuav at gmail.com Mon Oct 25 14:39:54 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Oct 2021 05:39:54 +1100 Subject: New assignmens ... In-Reply-To: <465d7e85-a6a0-bb24-7148-93019536c355@vub.be> References: <86sfwqhnai.fsf@williamsburg.bawden.org> <00b101d7c931$573d61e0$05b825a0$@verizon.net> <5761dd65-4e87-8b8c-1400-edb8212048db@vub.be> <007b01d7c9ba$417f97e0$c47ec7a0$@verizon.net> <465d7e85-a6a0-bb24-7148-93019536c355@vub.be> Message-ID: On Tue, Oct 26, 2021 at 5:35 AM Antoon Pardon wrote: > By putting limits on the walrus code, you are not reducing complexity, you are increasing it. > You are increasing complexity because you can't just reuse the code that handles an ordinary > assignment. You now need specific code to limit it's use. > What does this code do? while x, y := foo(): ... Is it more complicated or less complicated when arbitrary assignment targets are permitted? ChrisA From antoon.pardon at vub.be Mon Oct 25 16:16:47 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Mon, 25 Oct 2021 22:16:47 +0200 Subject: New assignmens ... In-Reply-To: References: <86sfwqhnai.fsf@williamsburg.bawden.org> <00b101d7c931$573d61e0$05b825a0$@verizon.net> <5761dd65-4e87-8b8c-1400-edb8212048db@vub.be> <007b01d7c9ba$417f97e0$c47ec7a0$@verizon.net> <465d7e85-a6a0-bb24-7148-93019536c355@vub.be> Message-ID: <8050c5b1-86f1-05d1-c4e5-3c17ce1a77d1@vub.be> Op 25/10/2021 om 20:39 schreef Chris Angelico: > On Tue, Oct 26, 2021 at 5:35 AM Antoon Pardon wrote: >> By putting limits on the walrus code, you are not reducing complexity, you are increasing it. >> You are increasing complexity because you can't just reuse the code that handles an ordinary >> assignment. You now need specific code to limit it's use. >> > What does this code do? > > while x, y := foo(): > ... > > Is it more complicated or less complicated when arbitrary assignment > targets are permitted? Well I would guess it would do something similar to while [x, y := foo()]: ... From rosuav at gmail.com Mon Oct 25 17:03:41 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Oct 2021 08:03:41 +1100 Subject: New assignmens ... In-Reply-To: <8050c5b1-86f1-05d1-c4e5-3c17ce1a77d1@vub.be> References: <86sfwqhnai.fsf@williamsburg.bawden.org> <00b101d7c931$573d61e0$05b825a0$@verizon.net> <5761dd65-4e87-8b8c-1400-edb8212048db@vub.be> <007b01d7c9ba$417f97e0$c47ec7a0$@verizon.net> <465d7e85-a6a0-bb24-7148-93019536c355@vub.be> <8050c5b1-86f1-05d1-c4e5-3c17ce1a77d1@vub.be> Message-ID: On Tue, Oct 26, 2021 at 7:18 AM Antoon Pardon wrote: > > Op 25/10/2021 om 20:39 schreef Chris Angelico: > > On Tue, Oct 26, 2021 at 5:35 AM Antoon Pardon wrote: > >> By putting limits on the walrus code, you are not reducing complexity, you are increasing it. > >> You are increasing complexity because you can't just reuse the code that handles an ordinary > >> assignment. You now need specific code to limit it's use. > >> > > What does this code do? > > > > while x, y := foo(): > > ... > > > > Is it more complicated or less complicated when arbitrary assignment > > targets are permitted? > > Well I would guess it would do something similar to > > while [x, y := foo()]: > ... > And does it unpack what foo returns? Should it? ChrisA From avigross at verizon.net Mon Oct 25 17:41:21 2021 From: avigross at verizon.net (Avi Gross) Date: Mon, 25 Oct 2021 17:41:21 -0400 Subject: New assignmens ... In-Reply-To: References: Message-ID: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> We have had discussions debating if Python is a good language for teaching. The short answer is NO unless you only teach a small subset and the students know there is more they can learn as needed. The language is too rich and has too many ways to do seemingly anything and that is before you add more functionality. But that can make it a great language for developers. Assignments in middle of expressions are often syntactic sugar that may be re-arranged internally to similar code than what could be done other ways without it. It can lead to ambiguities. And it can make it harder for anyone other than the programmer that wrote it (or them a day later) to understand. So, while we are at it, why not add the ++ and --- operators that were deliberately NOT included in Python? Why not throw back pointers? The short answer is that there are plenty of programming languages to choose from and some of those do have the features you want and some do not want them. Sure, you might push in what you want but have you considered all the places it might be tried? Can you do it in a comprehension where an assignment is implicitly being done? [ var := 5 in range(10) ] The old adage is that some people will be given a finger and take a hand. I had NOTHING to do with the process but others here know more. Chris suggests that there was a compromise of sorts here and a choice to implement a limited subset of fuller functionality for NOW without ruling out doing some more later. So those wanting more, feel free to petition for it as an ADDITION but I suggest a more polite tone than trying to say the people who did it were idiots who did it badly. Personally, I don't care what is done and suspect I will rarely feel much need to use the current walrus operator, let alone an enhanced Odobenus rosmarus operator like ::== ... -----Original Message----- From: Python-list On Behalf Of Christman, Roger Graydon Sent: Monday, October 25, 2021 12:48 PM To: python-list at python.org Subject: Re: New assignmens ... Message: 8 Date: Mon, 25 Oct 2021 11:20:52 +0200 From: Antoon Pardon To: python-list at python.org Subject: Re: New assignmens ... Message-ID: <5761dd65-4e87-8b8c-1400-edb8212048db at vub.be> Content-Type: text/plain; charset=utf-8; format=flowed On 25/10/2021 11:20, Anton Pardon wrote: > Suppose I would like to write a loop as follows: > while ((a, b) := next_couple(a, b))[1]: > do needed calculations > What I can do is write it as follows: > while [tmp := next_couple(a,b), a := tmp[0], b := tmp[1]][-1]: > do needed calculations > I really don't see what is gained by "forcing" me to right the second code over the first. No, nobody is forcing you to right it the second way over the first. Nobody is forcing you to use the walrus operator at all! Instead, I would recommend something more like: while b: do needed calculations (a,b) = next_couple(a,b) This requires even less typing than what you had before! But it also raises a whole lot of problems with this particular example: -- neither a nor b is defined in your sample while loop. It seems you would need to initialize a and b before your while loop (and mine) -- is b truly a boolean value, or are you short-cutting some other value? -- are a and b truly necessary parameters to next_couple, or are they just there to remind the function of its previous return values? If the latter, poerhaps you want a stream or list or something with yield This example (and some of the others I have seen) just highlight how programmers will take advantage of any new tool to help them write worse code than if they did not have the tool. In my mind, the walrus operator was designed to serve a particular niche case like this one: while (x := input()) > 0: where not having the operator required duplicating the input() operation both before the loop and at the end of the loop -- or more complicated cases where some additional operations had to be performed to get that test value for the while condition (such as getting the b out of (a,b)). But the walrus only adds a benefit if it is there to avoid the duplication of the code that is used to obtain that test condition. This next_couple example does not qualify, since apparently (a,b) are initialized by some other means (and not be a call to next_couple with undefined values) Or the other abuse I saw recently about using the walrus operator: while (self.ctr := self.ctr-1) > 0: -- there was no compelling reason for a loop counter to be a class variable (anyone who peeks at this counter when the loop is down would only see a zero) -- this requires self.ctr to be initialized to a value one higher than the first meaningful value (start at 11 if you want to count down from 10) So my recommended alternative, which furthermore also takes less typing: while ctr > 0: ... ctr = ctr-1 TL;DR: The Walrus operator serves the purpose as described in its PEP just as it is, and I see no compelling reason to expand its use. It is there to reduce code size by eliminating a duplication of code, If the code you write using the walrus operator is longer or more complicated than the code would be without it, you are misusing it. Roger Christman Pennsylvania State University -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Mon Oct 25 17:45:41 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Oct 2021 08:45:41 +1100 Subject: New assignmens ... In-Reply-To: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> Message-ID: On Tue, Oct 26, 2021 at 8:42 AM Avi Gross via Python-list wrote: > Personally, I don't care what is done and suspect I will rarely feel much > need to use the current walrus operator, let alone an enhanced Odobenus > rosmarus operator like ::== ... > ..... wait what? Ah. Had to look that one up. :) ChrisA From PythonList at DancesWithMice.info Mon Oct 25 18:17:51 2021 From: PythonList at DancesWithMice.info (dn) Date: Tue, 26 Oct 2021 11:17:51 +1300 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> Message-ID: On 26/10/2021 10.45, Chris Angelico wrote: > On Tue, Oct 26, 2021 at 8:42 AM Avi Gross via Python-list > wrote: >> Personally, I don't care what is done and suspect I will rarely feel much >> need to use the current walrus operator, let alone an enhanced Odobenus >> rosmarus operator like ::== ... >> > > ..... wait what? > > Ah. Had to look that one up. :) Each year I assist friends who own one of local orchards, at harvest time. I usually run the sealing machine, to preserve fruit which will be transported refrigerated. It is such a novelty to be asked to fill-out a time-sheet. Under "name" it asks for "position", so I entered "Erignathus barbatus" (bearded seal), which caused similar consternation, and for some days, until someone thought to look it up... Back on-topic, I am slightly curious:- aside from 'starting small' with an option to widen/'open-up' later, is there a particular reason why 'the walrus' has not been made available (could not be ...?) for use with object-attributes? -- Regards, =dn From kiankayson at gmail.com Mon Oct 25 18:12:24 2021 From: kiankayson at gmail.com (Kian Kwame) Date: Mon, 25 Oct 2021 15:12:24 -0700 (PDT) Subject: Beginner in python Message-ID: <64a80cc8-d6b9-4b51-8273-3805347c7b79n@googlegroups.com> hi buddie am new to python somebody kindly advice the coding which will count odd number from 1 to 10 , and counting number from 1 tp 100 From rosuav at gmail.com Mon Oct 25 18:24:45 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Oct 2021 09:24:45 +1100 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> Message-ID: On Tue, Oct 26, 2021 at 9:19 AM dn via Python-list wrote: > Back on-topic, I am slightly curious:- > > aside from 'starting small' with an option to widen/'open-up' later, is > there a particular reason why 'the walrus' has not been made available > (could not be ...?) for use with object-attributes? I can't think of any other reasons. But the one you cite is quite an important one. In order to get real-world usage examples, the feature was rolled out in the restricted form, because threads like this are *exactly* how the value can be judged. So I do not in any way regret that assignment expressions were accepted in their current form, but also, don't be afraid to propose an opening up of the syntax. Be specific, and cite usage examples that would benefit. TBH, I don't think there's a lot of value in multiple-assignment, since it has a number of annoying conflicts of syntax and few viable use-cases. But if you have great examples of "x.y :=" or "x[y] :=", then by all means, post on python-ideas to propose widening the scope. ChrisA From rosuav at gmail.com Mon Oct 25 18:25:08 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Oct 2021 09:25:08 +1100 Subject: Beginner in python In-Reply-To: <64a80cc8-d6b9-4b51-8273-3805347c7b79n@googlegroups.com> References: <64a80cc8-d6b9-4b51-8273-3805347c7b79n@googlegroups.com> Message-ID: On Tue, Oct 26, 2021 at 9:23 AM Kian Kwame wrote: > > hi buddie > am new to python somebody kindly advice the coding which will count odd number from 1 to 10 , and counting number from 1 tp 100 Sounds like homework. What have you written so far? ChrisA From avigross at verizon.net Mon Oct 25 18:31:24 2021 From: avigross at verizon.net (Avi Gross) Date: Mon, 25 Oct 2021 18:31:24 -0400 Subject: Beginner in python In-Reply-To: References: <64a80cc8-d6b9-4b51-8273-3805347c7b79n@googlegroups.com> Message-ID: <000c01d7c9f0$0b5d31f0$221795d0$@verizon.net> Chris, I was just about to suggest: 1+3+5+7+9 and 50*101 but that would mean helping with what does seem like fairly simple homework with no effort to show us what they already tried and got stuck with! So, ignore my attempts at trivial humor as I suspect some form of loop was anticipated. Avi -----Original Message----- From: Python-list On Behalf Of Chris Angelico Sent: Monday, October 25, 2021 6:25 PM To: Python Subject: Re: Beginner in python On Tue, Oct 26, 2021 at 9:23 AM Kian Kwame wrote: > > hi buddie > am new to python somebody kindly advice the coding which will count odd number from 1 to 10 , and counting number from 1 tp 100 Sounds like homework. What have you written so far? ChrisA -- https://mail.python.org/mailman/listinfo/python-list From avigross at verizon.net Mon Oct 25 19:16:30 2021 From: avigross at verizon.net (Avi Gross) Date: Mon, 25 Oct 2021 19:16:30 -0400 Subject: New assignmens ... In-Reply-To: References: <86sfwqhnai.fsf@williamsburg.bawden.org> <00b101d7c931$573d61e0$05b825a0$@verizon.net> <5761dd65-4e87-8b8c-1400-edb8212048db@vub.be> <007b01d7c9ba$417f97e0$c47ec7a0$@verizon.net> Message-ID: <007b01d7c9f6$5878ab80$096a0280$@verizon.net> Stefan, Yes, I often pass even fairly trivial functions like "add" or "+" or whatever the language makes me say, to other functions in various forms of functional programing. My point is that my example may seem trivial and not necessary as an EXAMPLE of the greater point that may be easier to understand than something complex. A sum() is often a generalization of adding two things by allowing a second addition to the sub-sum and so on. But in a straightforward program where I am asking to add exactly two things, few would use sum(a,b) versus just a+b. On the other hand, in agreement with you, if I have two vectors or matrices or some other such data holder and I want to add each position to a corresponding position, then some kind of call to a function where I pass the two objects and the name of a function that adds two things, is a decent way to go. But it need not be a souped-up generalized_sum() function when a simple one will do and be faster when invoked so many times. And note often what is used is a temporary lambda anonymous function that may look like \(x,y) x+y ... or whatever syntax your language uses. -----Original Message----- From: Python-list On Behalf Of Stefan Ram Sent: Monday, October 25, 2021 12:57 PM To: python-list at python.org Subject: Re: New assignmens ... "Avi Gross" writes: >Now, yes, nobody needs a function to just add two numbers. If one uses a framework like "functools.reduce", the only way to reduce an iterable to its sum, is to do just that: Write a function to add two numbers. Of course, one can circumvent "functools.reduce" (or use "operator.add"), but in other cases there are frameworks that need to be used and where one sometimes does need to write functions (callbacks) as simple as "lambda: None". -- https://mail.python.org/mailman/listinfo/python-list From lindtraxx57 at gmail.com Tue Oct 26 01:40:29 2021 From: lindtraxx57 at gmail.com (anders Limpan) Date: Mon, 25 Oct 2021 22:40:29 -0700 (PDT) Subject: Create a contact book Message-ID: <3ba51db0-7e7c-4243-998c-606146dd5b60n@googlegroups.com> i would like to create a contact book were you can keep track of your friends. With this contact book you will both be able to add friends and view which friends that you have added. anyone interested in helping me out with this one ?=) From rosuav at gmail.com Tue Oct 26 02:35:58 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 26 Oct 2021 17:35:58 +1100 Subject: Create a contact book In-Reply-To: <3ba51db0-7e7c-4243-998c-606146dd5b60n@googlegroups.com> References: <3ba51db0-7e7c-4243-998c-606146dd5b60n@googlegroups.com> Message-ID: On Tue, Oct 26, 2021 at 5:30 PM anders Limpan wrote: > > i would like to create a contact book were you can keep track of your friends. With this contact book you will both be able to add friends and view which friends that you have added. anyone interested in helping me out with this one ?=) > Here at Homeworks Anonymous, the first step is admitting that what you have is a homework problem. :) This isn't a project, this is something you're doing for a course, and it's not really fair to pretend otherwise :) ChrisA From liedtke at punkt.de Tue Oct 26 08:37:35 2021 From: liedtke at punkt.de (Lars Liedtke) Date: Tue, 26 Oct 2021 14:37:35 +0200 Subject: Create a contact book In-Reply-To: References: <3ba51db0-7e7c-4243-998c-606146dd5b60n@googlegroups.com> Message-ID: ? > Here at Homeworks Anonymous, the first step is admitting that what you > have is a homework problem. :) > > ChrisA -- punkt.de GmbH Lars Liedtke .infrastructure Kaiserallee 13a 76133 Karlsruhe Tel. +49 721 9109 500 https://infrastructure.punkt.de info at punkt.de AG Mannheim 108285 Gesch?ftsf?hrer: J?rgen Egeling, Daniel Lienert, Fabian Stein From avigross at verizon.net Tue Oct 26 11:16:51 2021 From: avigross at verizon.net (Avi Gross) Date: Tue, 26 Oct 2021 11:16:51 -0400 Subject: Create a contact book In-Reply-To: References: <3ba51db0-7e7c-4243-998c-606146dd5b60n@googlegroups.com> Message-ID: <027001d7ca7c$80fd2c30$82f78490$@verizon.net> Chris, I think it is time someone set up a business where they do the homework for people for a mere $1,000 or so per hour. Anonymously, of course. And we can refer requests for free homework advice there. Maybe the answer to this request is to suggest they use FACEBOOK which seemingly keeps you in contact and lets you add friends and view them .... -----Original Message----- From: Python-list On Behalf Of Chris Angelico Sent: Tuesday, October 26, 2021 2:36 AM To: Python Subject: Re: Create a contact book On Tue, Oct 26, 2021 at 5:30 PM anders Limpan wrote: > > i would like to create a contact book were you can keep track of your > friends. With this contact book you will both be able to add friends > and view which friends that you have added. anyone interested in > helping me out with this one ?=) > Here at Homeworks Anonymous, the first step is admitting that what you have is a homework problem. :) This isn't a project, this is something you're doing for a course, and it's not really fair to pretend otherwise :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list From antoon.pardon at vub.be Tue Oct 26 11:42:22 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 26 Oct 2021 17:42:22 +0200 Subject: New assignmens ... In-Reply-To: References: <86sfwqhnai.fsf@williamsburg.bawden.org> <00b101d7c931$573d61e0$05b825a0$@verizon.net> <5761dd65-4e87-8b8c-1400-edb8212048db@vub.be> <007b01d7c9ba$417f97e0$c47ec7a0$@verizon.net> <465d7e85-a6a0-bb24-7148-93019536c355@vub.be> <8050c5b1-86f1-05d1-c4e5-3c17ce1a77d1@vub.be> Message-ID: <685a11ee-cd76-0eef-96ec-47573cb2a9e0@vub.be> Op 25/10/2021 om 23:03 schreef Chris Angelico: > On Tue, Oct 26, 2021 at 7:18 AM Antoon Pardon wrote: >> Op 25/10/2021 om 20:39 schreef Chris Angelico: >>> On Tue, Oct 26, 2021 at 5:35 AM Antoon Pardon wrote: >>>> By putting limits on the walrus code, you are not reducing complexity, you are increasing it. >>>> You are increasing complexity because you can't just reuse the code that handles an ordinary >>>> assignment. You now need specific code to limit it's use. >>>> >>> What does this code do? >>> >>> while x, y := foo(): >>> ... >>> >>> Is it more complicated or less complicated when arbitrary assignment >>> targets are permitted? >> Well I would guess it would do something similar to >> >> while [x, y := foo()]: >> ... >> > And does it unpack what foo returns? > > Should it? 1) No it doesn't. 2) I don't care. This is IMO not a question of what should or should not, but just a question of deciding how you want to treat this. I guess that since it doesn't unpack already, this behaviour is more or less fixed for futere releases. Should the python developers in the future decide that de walrus operator can unpack things. The above code will not unpack in order to not break already existing code and if you want to unpack one will have to write something like: while [(x, y) := foo()]: ... But the answer to that second question has very little relevance to how complicated the parser will be. It is just deciding which of , or := has a higher precedence. Since that decision has already been more or less made, there is not much to decide here either. -- Antoon Pardon. From Joseph.Schachner at Teledyne.com Tue Oct 26 13:46:54 2021 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Tue, 26 Oct 2021 17:46:54 +0000 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> Message-ID: Why force unpacking? Why not assign a tuple? That would look like a simple assignment: x := (alpha, beta, gamma) And you could access x[0], x[1] and x[2]. I think asking := to support x, y := alpha, beta is a request to address an unnecessary, easily worked around, issue. And as previously pointed out you can still just use = . --- Joseph S. Teledyne Confidential; Commercially Sensitive Business Data -----Original Message----- From: Chris Angelico Sent: Monday, October 25, 2021 6:25 PM To: Python Subject: Re: New assignmens ... On Tue, Oct 26, 2021 at 9:19 AM dn via Python-list wrote: > Back on-topic, I am slightly curious:- > > aside from 'starting small' with an option to widen/'open-up' later, > is there a particular reason why 'the walrus' has not been made > available (could not be ...?) for use with object-attributes? I can't think of any other reasons. But the one you cite is quite an important one. In order to get real-world usage examples, the feature was rolled out in the restricted form, because threads like this are *exactly* how the value can be judged. So I do not in any way regret that assignment expressions were accepted in their current form, but also, don't be afraid to propose an opening up of the syntax. Be specific, and cite usage examples that would benefit. TBH, I don't think there's a lot of value in multiple-assignment, since it has a number of annoying conflicts of syntax and few viable use-cases. But if you have great examples of "x.y :=" or "x[y] :=", then by all means, post on python-ideas to propose widening the scope. ChrisA From varietyjones10 at gmail.com Tue Oct 26 07:20:59 2021 From: varietyjones10 at gmail.com (variety jones) Date: Tue, 26 Oct 2021 04:20:59 -0700 (PDT) Subject: matrix row comparison and fetch data with numpy Message-ID: <1ce53936-fb8f-487e-bf59-df0926f130e4n@googlegroups.com> I have 2 matrix with , M and M' , The M' matrix is the result of calculation "order preserving" of the matrix M so i will explain more by examples , so here is the matrix M : M= np.array([ [15,4,-1,9,10,7], [-4,2,29,11,98,5], [101,24,3,19,77,53], [0,88,34,62,13,-9], [52,93,44,46,24,125], [0,17,26,8,87,0], [103,19,52,173,66,24], [26,78,123,-5,13,41] ]) so lets take the row L1 from the matrix M so the smallest integer is - 1 so we take the position of -1 from the matrix M which is in the column C3 and write 1 in L1 of the matrix M', and here we go for the other numbers we compare them and take the right order , in case of similarity we give them the same order , this part is looking fine i write a program who take a matrix and calculate the order preserving of it and show the results in the second matrix , here is my code : https://pastebin.com/jpaZfVsB so the second step is , We will take the columns similar to X% from the matrix M' In this case there are two conditions : X% = 100% similar The number of minimum similar columns : ???? ??? ???=2 so from the matrix M' we will compare row by row : L1 to L2 , L2 to L 3 until we find similar rows and here is the results : Seed1= {L1 l2 c2 c4 c6} Seed2= {L1 l3 c1 c3 c5} Seed3={L3 l6 c2 c4 c5} Seed4={L4l6 c3 c6} Seed5= {L7 l8 c3 c5 c6} In order to build a bi-group , We must combine the seeds with each other: we will unite the rows of the seed and the intersection of the columns of the seed By respecting: ???? ??? ??? = 2 the final results : Bi-groupe 1={L1 l2 l3 l6 c2 c4} Bi-groupe2={L1 l3 l7 l8 c3 c5} Bi-groupe 3={L4 l6 l7 l8 c3 c6} i just want a function or away to figured out the seeds by rows comparison and show the bi-groupe results Many Thanks From auriocus at gmx.de Tue Oct 26 09:30:07 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 26 Oct 2021 15:30:07 +0200 Subject: Create a contact book In-Reply-To: <3ba51db0-7e7c-4243-998c-606146dd5b60n@googlegroups.com> References: <3ba51db0-7e7c-4243-998c-606146dd5b60n@googlegroups.com> Message-ID: Am 26.10.21 um 07:40 schrieb anders Limpan: > i would like to create a contact book were you can keep track of your friends. With this contact book you will both be able to add friends and view which friends that you have added. anyone interested in helping me out with this one ?=) > Here is how to do it: https://facebook.com/ Christian From python.list at tim.thechases.com Tue Oct 26 14:27:04 2021 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 26 Oct 2021 13:27:04 -0500 Subject: Create a contact book In-Reply-To: <3ba51db0-7e7c-4243-998c-606146dd5b60n@googlegroups.com> References: <3ba51db0-7e7c-4243-998c-606146dd5b60n@googlegroups.com> Message-ID: <20211026132704.50f086ca@bigbox.attlocal.net> On 2021-10-25 22:40, anders Limpan wrote: > i would like to create a contact book were you can keep track of > your friends. With this contact book you will both be able to add > friends and view which friends that you have added. anyone > interested in helping me out with this one ?=) -- Python provides the shelve module for just this sort of thing: import shelve class Contact: def __init__(self, name): self.name = name self.address = "" self.phone = "" with shelve.open("contacts") as db: dave = Contact("Dave Smith") dave.address = "123 Main St\nAnytown, NY 12345" dave.phone = "800-555-1212" db["dave"] = dave ellen = Contact("Ellen Waite") ellen.phone = "+1234567890" db["ellen"] = ellen Then at some future point you can use with shelve.open("contacts") as db: dave = db["dave"] print(f"Dave lives at {dave.address}") ellen = db["ellen"] print(f"Ellen's phonenumber is {ellen.phonenumber}") I'll leave to you the details of implementing an actual address-book out of these parts. Be sure to read the docs for the shelve module https://docs.python.org/3/library/shelve.html including the various security warnings and caveats. -tkc From PythonList at DancesWithMice.info Tue Oct 26 17:52:05 2021 From: PythonList at DancesWithMice.info (dn) Date: Wed, 27 Oct 2021 10:52:05 +1300 Subject: The task is to invent names for things Message-ID: Some time ago I watched a video of a Raymond Hettinger talk. In it he recounted answering his son's question of 'what do you do, Dad?' by suggesting that programmers spend much?most of their time thinking of names - and good names are better than "n = name", etc. This theme developed throughout the talk. Have searched, but been unable to re-locate this video. Do you recall the talk? Please advise its URL... -- Regards, =dn From shishaozhong at gmail.com Tue Oct 26 18:34:26 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Tue, 26 Oct 2021 23:34:26 +0100 Subject: How to store the result of df.count() as a new dataframe in Pandas? Message-ID: Hello, The result of df.count() appears to be a series object. How to store the result of df.count() as a new dataframe in Pandas? That is data anyhow. Regards, David From PythonList at DancesWithMice.info Tue Oct 26 19:05:09 2021 From: PythonList at DancesWithMice.info (dn) Date: Wed, 27 Oct 2021 12:05:09 +1300 Subject: The task is to invent names for things In-Reply-To: References: Message-ID: <2f6d3c8b-d498-c5e4-b399-3363642deba1@DancesWithMice.info> On 27/10/2021 11.16, Stefan Ram wrote: > dn writes: >> Some time ago I watched a video of a Raymond Hettinger talk. In it he >> recounted answering his son's question of 'what do you do, Dad?' > > The Mental Game of Python - Raymond Hettinger (PyBay 2019) > > Around minute 21, Raymond says: > > |I often, doo, uh, try to describe, uh, computer programming, > |uh, to kids. > | > |How many of you can tell, uh, uh, a child what a, uh, a > |software engineer does? > | > |At least one man, uh, uh, can. - One man who has. > | > |Here's my explanation: > | "The computer gives us words that do ### things. > | What daddy does is make new words to make computers easier to use." > > . An awesome explanation! > > But please help me to understand the word marked "###" above! That was quick. Thank you! (and yes, I had "Bay Piggies" in my head, but after starting to re-watch that video, moved-on because the agenda didn't seem to match) OTOH it is not exactly as I remember (which may say more about me!). Perhaps he re-used the story elsewhere - I shall investigate further... Meantime, the tape will reinforce a 'learning-opportunity' for a certain trainee and his 'algebraic habit'... Your question: Firstly, Raymond often needs to "er" in order to let his mind catch-up with his words. A lot of us do this, not because we've forgotten what to say, but because we're also listening, in QA-mode as it were, and sometimes question our choice of words - ah, back to names/words again! In this case, I'll suggest that he was already struggling with the subject of the sentence - is he talking about 'a programmer' talking to a child, or his own situation in-conversation with his son? Secondly, there is the issue of singular/plural forms - especially when formulating the sentence's object - or final clause. Thus, do I use the singular "does" because "computer" is singular, or should it be the plural "do" because "words" is plural? His first choice was grammatically-correct. Think of the pause as running pytest prior to further execution... Alternately, if your question was to identify the mumbled word, it is (seemed to me to be) "does". Thanks again! -- Regards, =dn From PythonList at DancesWithMice.info Tue Oct 26 19:15:04 2021 From: PythonList at DancesWithMice.info (dn) Date: Wed, 27 Oct 2021 12:15:04 +1300 Subject: The task is to invent names for things In-Reply-To: References: Message-ID: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> On 27/10/2021 11.21, Stefan Ram wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: >> The Mental Game of Python - Raymond Hettinger (PyBay 2019) >> |What daddy does is make new words to make computers easier to use." > > BTW: It now also reminds me of: > > |What I Do > | > |I build paradigms. > |I work on complex ideas and make up words for them. > |It is the only way. > | > Ted Nelson (1937-) in 1998 or earlier > > , which might precede Raymonds talk. Indeed, this is how we 'invent' jargon - a short-cut to enable subject-specialists (SMEs) to inter-communicate succinctly or more accurately. What really gets me into 'grumpy old man' mode, is the predilection for our TV folk to imitate their foreign peers, or to use their own jargon/slang in a public forum. Over the decades of my career I've listened (as politely as possible) to so many (so, so, many) ordinary-folk complaining that we computer-guys talk gobbledegook, and need to down-shift and explain things in ordinary language. Sometimes this is valid - there is no point in talking to my neighbors about "ternary operators" and certainly "walrus" would create complete misunderstanding. However, a public broadcaster to think it acceptable to use such (of their) terms as "presser" (Press Briefing, or is it Press Release?), only goes to show that IT people (without specific training in (public) communication) aren't 'that bad' after all! Programmers of the world unite! You have nothing to lose but your 0 - or your 1 -- Regards, =dn From rosuav at gmail.com Tue Oct 26 19:20:19 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Oct 2021 10:20:19 +1100 Subject: The task is to invent names for things In-Reply-To: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: On Wed, Oct 27, 2021 at 10:16 AM dn via Python-list wrote: > Programmers of the world unite! > You have nothing to lose but your 0 > - or your 1 Many operations in computing are fully reversible. After you do something, you can undo it. After you assign, you can unassign. And after you ite, you can unite! ChrisA From DomainAdmin at DancesWithMice.info Tue Oct 26 20:48:27 2021 From: DomainAdmin at DancesWithMice.info (David L Neil) Date: Wed, 27 Oct 2021 13:48:27 +1300 Subject: The task is to invent names for things In-Reply-To: References: <2f6d3c8b-d498-c5e4-b399-3363642deba1@DancesWithMice.info> Message-ID: <88b41400-f0d2-59ab-275a-80aa5a437d37@DancesWithMice.info> On 27/10/2021 12.29, Stefan Ram wrote: > dn writes: >> On 27/10/2021 11.16, Stefan Ram wrote: >>> The Mental Game of Python - Raymond Hettinger (PyBay 2019) >>> | "The computer gives us words that do ### things. > ... >> Alternately, if your question was to identify the mumbled word, it is >> (seemed to me to be) "does". > > Thanks! > > Yes, my question was about the word at the place of the > "###". It does not even seem mumbled to me, but pronounced > with certainty and intention. That's why it makes me wonder. > As if there was a term "does things". That is a colloquialism: - my computer does things - my program[me] does stuff The "stuff" is something of a euphemism. In our profession, I would suggest it is used to avoid detail, eg as a 'signal' to a non-IT person that a more detailed answer would likely bore, or 'go over your head'. In PM-circles we identify the beginning and end of a project - the rest of the project plan 'stuff', is known as 'the miracle that happens in the middle'. Want more detail? Do we have more detail? What do I know? If a dog owner said: "my dog does things" it would again be a euphemism, but in this case employed to avoid saying something distasteful, ie that the puppy is not (yet) house-trained. That said, I suspect if you tried to use it in an English (language/literature) essay, the teacher/prof would take exception to such informality, and demand a 'better' noun! Believe it or not, my second trainee-discussion of the day included a question similarly-worded: 'why does the computer/interpreter/run-time do these things?'. Rather than 'literature', I taught this guy one of my favorite excursions into the world of poetry (the specific type of poetic stuff is "doggerel"): I really hate this dumb* machine, I wish that they would sell it. It never does quite what I want, but only what I tell it! * you might regard this word as a euphemism for another Upon which note, and your observation that I am no English-major, it's probably time we went to do things... -- Regards =dn From PythonList at DancesWithMice.info Wed Oct 27 00:15:22 2021 From: PythonList at DancesWithMice.info (dn) Date: Wed, 27 Oct 2021 17:15:22 +1300 Subject: Create a contact book In-Reply-To: <027001d7ca7c$80fd2c30$82f78490$@verizon.net> References: <3ba51db0-7e7c-4243-998c-606146dd5b60n@googlegroups.com> <027001d7ca7c$80fd2c30$82f78490$@verizon.net> Message-ID: On 27/10/2021 04.16, Avi Gross via Python-list wrote: > Chris, > > I think it is time someone set up a business where they do the homework for > people for a mere $1,000 or so per hour. Anonymously, of course. And we can > refer requests for free homework advice there. > > Maybe the answer to this request is to suggest they use FACEBOOK which > seemingly keeps you in contact and lets you add friends and view them .... > > On Tue, Oct 26, 2021 at 5:30 PM anders Limpan wrote: >> >> i would like to create a contact book were you can keep track of your >> friends. With this contact book you will both be able to add friends >> and view which friends that you have added. anyone interested in >> helping me out with this one ?=) >> > > Here at Homeworks Anonymous, the first step is admitting that what you have > is a homework problem. :) This isn't a project, this is something you're > doing for a course, and it's not really fair to pretend otherwise :) > > ChrisA It's a balancing-act: - on the one hand writing (their) code is not helping a trainee to learn (and certainly not in the manner the trainer intended) - on the other, we should try to welcome and encourage new-comers to our list/the Python eco-system. That said, I've often recommended folk switch/also subscribe to the Tutor list, but can't say if many actually did. "Essay Mills" are back in the news in the UK with a proposal to make them completely illegal. The Times Educational Supplement printed an article two~three weeks ago (https://www.timeshighereducation.com/student/advice/tempted-pay-your-essays-here-are-six-reasons-not - likely behind a pay-wall - if so, apologies). The author identified six reasons for not using an Essay Mill: (the labels are his, the summaries beyond them are mine) 1 Harsh penalties - if caught 2. Fool no more - plagiarism software these days is not only comparing 'this work' with others' assignment returns, but this with your other submissions, ie noting if your personal writing style changes! 3. Career impact - how it impacts employment (possibilities) if such is either on your record or becomes evident later 4. On the record - if the 'mill' has your record, what if they're hacked? Do they have better security than the many organisations which have been breached? 5. No guarantee of anonymity - your shadow-author will have a 'hold' over you, forever 6. Bribery - perhaps that essay should be about blackmail, how it could start, and what might be its effects? -- Regards, =dn From antoon.pardon at vub.be Wed Oct 27 02:18:42 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Oct 2021 08:18:42 +0200 Subject: New assignmens ... In-Reply-To: References: Message-ID: Op 25/10/2021 om 18:47 schreef Christman, Roger Graydon: > Message: 8 > Date: Mon, 25 Oct 2021 11:20:52 +0200 > From: Antoon Pardon > To: python-list at python.org > Subject: Re: New assignmens ... > Message-ID: <5761dd65-4e87-8b8c-1400-edb8212048db at vub.be> > Content-Type: text/plain; charset=utf-8; format=flowed > On 25/10/2021 11:20, Anton Pardon wrote: >> Suppose I would like to write a loop as follows: > > while ((a, b) := next_couple(a, b))[1]: > > do needed calculations > > >> What I can do is write it as follows: >> while [tmp := next_couple(a,b), a := tmp[0], b := tmp[1]][-1]: > > do needed calculations > >> I really don't see what is gained by "forcing" me to right the second code over the first. > No, nobody is forcing you to right it the second way over the first. > Nobody is forcing you to use the walrus operator at all! > > Instead, I would recommend something more like: > > while b: > do needed calculations > (a,b) = next_couple(a,b) But AIU the walrus operator was introduced so we no longer needed, to write such code, with the calculation of the next candidate at the bottom and the test at the top. You just confirmed the walrus operator is not very useful once the next candidate is no longer just a name. -- Antoon. From antoon.pardon at vub.be Wed Oct 27 02:35:20 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Oct 2021 08:35:20 +0200 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> Message-ID: <5799bb42-911e-f8cc-2149-c7ccd0f49210@vub.be> Op 26/10/2021 om 19:46 schreef Schachner, Joseph: > Why force unpacking? Why not assign a tuple? That would look like a simple assignment: x := (alpha, beta, gamma) > And you could access x[0], x[1] and x[2]. > > I think asking := to support x, y := alpha, beta is a request to address an unnecessary, easily worked around, issue. And as previously pointed out you can still just use = . Because the names usually have meaning, while the tuple has not. And you just confirmed my point that the walrus operator isn't very useful here by suggesting that I should abandon it and use an assignment. -- Antoon Pardon. From antoon.pardon at vub.be Wed Oct 27 02:58:38 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Oct 2021 08:58:38 +0200 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> Message-ID: <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> Op 26/10/2021 om 00:24 schreef Chris Angelico: > TBH, I don't think there's a lot of value in multiple-assignment, > since it has a number of annoying conflicts of syntax and few viable > use-cases. But if you have great examples of "x.y :=" or "x[y] :=", > then by all means, post on python-ideas to propose widening the scope. I think you should seperate the costs from the benefits. It is not because the costs can be high there is little value. And how do you count use cases? What about the following pattern: while (a, b) := next_couple(a,b)[-1]: ... Is that one use case or is that a use case for each kind of couple? And even if the benefits are little per case, they can add up with every occasion such a case pops up. -- Antoon Pardon. From rosuav at gmail.com Wed Oct 27 04:05:52 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Oct 2021 19:05:52 +1100 Subject: New assignmens ... In-Reply-To: <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> Message-ID: On Wed, Oct 27, 2021 at 6:00 PM Antoon Pardon wrote: > > > > Op 26/10/2021 om 00:24 schreef Chris Angelico: > > TBH, I don't think there's a lot of value in multiple-assignment, > > since it has a number of annoying conflicts of syntax and few viable > > use-cases. But if you have great examples of "x.y :=" or "x[y] :=", > > then by all means, post on python-ideas to propose widening the scope. > > I think you should seperate the costs from the benefits. It is not because > the costs can be high there is little value. > > And how do you count use cases? What about the following pattern: > > while (a, b) := next_couple(a,b)[-1]: > ... > > Is that one use case or is that a use case for each kind of couple? > > And even if the benefits are little per case, they can add up with every > occasion such a case pops up. > I'm not sure that it's much of a use-case; isn't it an infinite loop as written? And that's the problem. With multiple-assignment, the overall value is going to be the tuple, so you then have to add extra parentheses and subscripting to get what you want to check. That makes it far less clean, far less tempting, far less valuable. You have to parenthesize the assignment target (otherwise it'll build a tuple out of one value and the assigned target), then parenthesize again, and subscript at the end. So if you want this added, show a use-case that makes it look way better than the alternatives (including a generator, a mid-loop break, etc). ChrisA From antoon.pardon at vub.be Wed Oct 27 04:24:21 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Oct 2021 10:24:21 +0200 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> Message-ID: <92134359-3597-861e-0ce1-da311944d0de@vub.be> Op 27/10/2021 om 10:05 schreef Chris Angelico: > On Wed, Oct 27, 2021 at 6:00 PM Antoon Pardon wrote: >> >> >> Op 26/10/2021 om 00:24 schreef Chris Angelico: >>> TBH, I don't think there's a lot of value in multiple-assignment, >>> since it has a number of annoying conflicts of syntax and few viable >>> use-cases. But if you have great examples of "x.y :=" or "x[y] :=", >>> then by all means, post on python-ideas to propose widening the scope. >> I think you should seperate the costs from the benefits. It is not because >> the costs can be high there is little value. >> >> And how do you count use cases? What about the following pattern: >> >> while (a, b) := next_couple(a,b)[-1]: >> ... >> >> Is that one use case or is that a use case for each kind of couple? >> >> And even if the benefits are little per case, they can add up with every >> occasion such a case pops up. >> > I'm not sure that it's much of a use-case; isn't it an infinite loop as written? > > And that's the problem. With multiple-assignment, the overall value is > going to be the tuple, so you then have to add extra parentheses and > subscripting to get what you want to check. That makes it far less > clean, far less tempting, far less valuable. You have to parenthesize > the assignment target (otherwise it'll build a tuple out of one value > and the assigned target), then parenthesize again, and subscript at > the end. > > So if you want this added, show a use-case that makes it look way > better than the alternatives (including a generator, a mid-loop break, > etc). > > ChrisA From PythonList at DancesWithMice.info Wed Oct 27 04:38:16 2021 From: PythonList at DancesWithMice.info (dn) Date: Wed, 27 Oct 2021 21:38:16 +1300 Subject: New assignmens ... In-Reply-To: References: Message-ID: On 24/10/2021 22.23, O365 Dict wrote: > Well I have the following use case: > > while (temp_result := calculate_next_couple(a, b))[1]: > a, b = temp_result > more calculations > > Which IMO would be clearer if I could just write: > > while ((a, b) := calculate_next_couple(a,b))[1]: > more calculations > > Of course it would even more clear if I could write something like: > > while (a, b) := calculate_next_couple(a, b); b: > more calculations > > or > > do: > a, b = calculate_next_couple(a, b) > while b: > more calculations Found (all of) the above less-than-obvious to read. Putting it in front of trainees this morning caused only confusion - even the currently-legal variation. Accordingly: is this a job for the walrus operator at all? Let's "talk of many [other] things"*. Is this an algorithmic complexity, or a complicated way to look at (and manipulate) data? Well, judging from the code (above), use of the walrus certainly presumes the former. Instead let's review any possibility of the latter (if only for academic interest)... What do we want out of the first line? (in no particular order) 1 use calculate_next_couple() to compute (new) a from an (old) a and b 2 use calculate_next_couple() to compute (new) b from an (old) a and b 3 use (new) b to decide if the loop should execute or terminate The 'problem' then, has been phrased as these three objectives ask too much of the (current implementation of the) walrus-operator. NB after one (or more) cycles, when the loop 'returns to the top', what I've termed 'new' a and b (above), will become (my reference) the 'old' pair/tuple. That all looks simple. What is dn complaining about? Could we use a data structure to continue to keep things straight-forward? class my_class(): def __init__( self, a, b )->None; self.a = a self.b = b instance = my_class( a, b ) Sorry, you're probably becoming impatient with me. Surely I'm typing more code than necessary? Maybe, but there are other measures of code-quality/good-practice/etc, and there's likely more to 'it' than just these few lines... First consideration: the algorithm needs us to 'feed' the while-condition. So let's flesh-out: def is_more( self )->bool: # you know what goes here - I don't, but that's not the issue # the return value is all that matters return is_there_any_more_data_to_calculate? In which case, the loop becomes: while instance.is_more(): more calculations and 'readability' improves immeasurably! NB for extra credit, turn the boolean function into a "property", and be able to omit the (unsightly?) parentheses from the 'call'! But, not so fast - what about the calculation itself, currently embedded in calculate_next_couple()? Well, those details are out of my sight, and I'm assuming include reasonable complexity - otherwise you wouldn't propose this as a good-example. Allow me to muddle-through with: def calculate_next_couple( self )->None: self.a = calculation of 'new' a self.b = calculation of 'new' b To avoid an 'extra' call against the instance from the while-loop, execute the 'calculate' method from either __init__() or is_more(), as appropriate (given that it likely needs to precede the return from the latter - particularly if the computation is 'expensive'). The choice may be subject-dependent ... Now within "more calculations", one assumes, references to "a" and "b" will need to be amended to become 'instance.a' and 'instance.b'. More typing! What about preserving our fingers? Readability will further improve when "a" and "b" (etc) are replaced by 'real names'. The processing steps within "more calculations" could be reviewed. Some may be candidates for inclusion as my_class methods - which would even enable further simplifications and/or encapsulation of code-suites relevant to the application, and/or "a" and "b" and the processes around them. If the "calculation" of 'next_couple' currently involves looking-up another data-structure, eg a list of data-points, then combining such with/into my_class may well yield further simplifications, encapsulations, and benefits - but all in-theory and complete ignorance of your application... Hope the above gives you some ideas/pause for thought! * this gratuitous and somewhat awkward expression is me claiming to be clever by quoting Lewis Carroll - if he isn't sick of me baiting-the-hook, it might earn extra brownie-points (or another groan) from @Chris... -- Regards, =dn From antoon.pardon at vub.be Wed Oct 27 04:45:08 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Oct 2021 10:45:08 +0200 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> Message-ID: <19860f15-c931-27b5-3ae5-7e935fa9e7cb@vub.be> Op 27/10/2021 om 10:05 schreef Chris Angelico: > On Wed, Oct 27, 2021 at 6:00 PM Antoon Pardon wrote: >> >> >> Op 26/10/2021 om 00:24 schreef Chris Angelico: >>> TBH, I don't think there's a lot of value in multiple-assignment, >>> since it has a number of annoying conflicts of syntax and few viable >>> use-cases. But if you have great examples of "x.y :=" or "x[y] :=", >>> then by all means, post on python-ideas to propose widening the scope. >> I think you should seperate the costs from the benefits. It is not because >> the costs can be high there is little value. >> >> And how do you count use cases? What about the following pattern: >> >> while (a, b) := next_couple(a,b)[-1]: >> ... >> >> Is that one use case or is that a use case for each kind of couple? >> >> And even if the benefits are little per case, they can add up with every >> occasion such a case pops up. >> > I'm not sure that it's much of a use-case; isn't it an infinite loop as written? > > And that's the problem. With multiple-assignment, the overall value is > going to be the tuple, so you then have to add extra parentheses and > subscripting to get what you want to check. That makes it far less > clean, far less tempting, far less valuable. You have to parenthesize > the assignment target (otherwise it'll build a tuple out of one value > and the assigned target), then parenthesize again, and subscript at > the end. That is only a problem if you want to consider it one. This wouldn't be the only place in python where you have to be careful with parentheses. IMO it should be the responsibility of each programmer to decide which way to program will be most clean. Maybe you are completly right and at the same time it could still be more clean than the other possibilitie python allows. > So if you want this added, show a use-case that makes it look way > better than the alternatives (including a generator, a mid-loop break, > etc). Way better according to which criteria? IMO to realy make something like this you would need a one and a half loop. But although at some time there was a strong indication it would get included, the idea was eventually discarted. So I'll argue for incremental better if I see a possibility. A few incremental betters can eventually result in something that is way better than the original. From rosuav at gmail.com Wed Oct 27 04:49:33 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Oct 2021 19:49:33 +1100 Subject: New assignmens ... In-Reply-To: <19860f15-c931-27b5-3ae5-7e935fa9e7cb@vub.be> References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> <19860f15-c931-27b5-3ae5-7e935fa9e7cb@vub.be> Message-ID: On Wed, Oct 27, 2021 at 7:46 PM Antoon Pardon wrote: > > So if you want this added, show a use-case that makes it look way > > better than the alternatives (including a generator, a mid-loop break, > > etc). > > Way better according to which criteria? IMO to realy make something like > this you would need a one and a half loop. But although at some time there > was a strong indication it would get included, the idea was eventually discarted. > > So I'll argue for incremental better if I see a possibility. A few incremental > betters can eventually result in something that is way better than the original. According to any criteria you like. Remember, the onus is not on the status quo to justify itself; the onus is on someone who wants to make a change. Demonstrate that a change is needed by showing the benefits. ChrisA From rosuav at gmail.com Wed Oct 27 04:54:01 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Oct 2021 19:54:01 +1100 Subject: New assignmens ... In-Reply-To: References: Message-ID: On Wed, Oct 27, 2021 at 7:39 PM dn via Python-list wrote: > Accordingly: is this a job for the walrus operator at all? Let's "talk > of many [other] things"*. +1 > Could we use a data structure to continue to keep things straight-forward? > > class my_class(): > def __init__( self, a, b )->None; > self.a = a > self.b = b > > instance = my_class( a, b ) > > > Sorry, you're probably becoming impatient with me. Surely I'm typing > more code than necessary? Maybe, but there are other measures of > code-quality/good-practice/etc, and there's likely more to 'it' than > just these few lines... > > > First consideration: the algorithm needs us to 'feed' the > while-condition. So let's flesh-out: > > def is_more( self )->bool: > # you know what goes here - I don't, but that's not the issue > # the return value is all that matters > return is_there_any_more_data_to_calculate? > > In which case, the loop becomes: > > while instance.is_more(): > more calculations > > and 'readability' improves immeasurably! I'd be inclined to write all of this as a generator function, yielding a series of tuples, but YMMV. > * this gratuitous and somewhat awkward expression is me claiming to be > clever by quoting Lewis Carroll - if he isn't sick of me > baiting-the-hook, it might earn extra brownie-points (or another groan) > from @Chris... Given that you were talking about a walrus, I think it was quite apt :) ChrisA From antoon.pardon at vub.be Wed Oct 27 05:09:35 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Oct 2021 11:09:35 +0200 Subject: New assignmens ... In-Reply-To: References: Message-ID: <019d5754-e58e-4089-6afb-5f2e2feca7c7@vub.be> Op 27/10/2021 om 10:38 schreef dn via Python-list: > On 24/10/2021 22.23, O365 Dict wrote: >> Well I have the following use case: >> >> while (temp_result := calculate_next_couple(a, b))[1]: >> a, b = temp_result >> more calculations >> >> Which IMO would be clearer if I could just write: >> >> while ((a, b) := calculate_next_couple(a,b))[1]: >> more calculations >> >> Of course it would even more clear if I could write something like: >> >> while (a, b) := calculate_next_couple(a, b); b: >> more calculations >> >> or >> >> do: >> a, b = calculate_next_couple(a, b) >> while b: >> more calculations > > Found (all of) the above less-than-obvious to read. Putting it in front > of trainees this morning caused only confusion - even the > currently-legal variation. A lot of python idioms are less than obvious for trainees when they first encounter them. I don't think "Is obvious for trainess" is a good measure to evaluate possible future programming constructs. > Accordingly: is this a job for the walrus operator at all? Let's "talk > of many [other] things"*. > > ... > > > That all looks simple. What is dn complaining about? > > > Could we use a data structure to continue to keep things straight-forward? Yes off course we could. Before the walrus operator was introduced, we could also introduce extra code so that we wouldn't need the walrus operator at all. > ... > Hope the above gives you some ideas/pause for thought! No they don't. You have taken an example to illustrate an idea and treated it as if it was some production code you had to review. What you are suggesting boils downto that if one has a loop in which one has two work variables, with a condition on those variable to control a loop. In order to make use of the walrus operator we should combine those two work variables into some kind of instance no matter how contrived. -- Antoon Pardon. From antoon.pardon at vub.be Wed Oct 27 05:19:29 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Oct 2021 11:19:29 +0200 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> <19860f15-c931-27b5-3ae5-7e935fa9e7cb@vub.be> Message-ID: Op 27/10/2021 om 10:49 schreef Chris Angelico: > On Wed, Oct 27, 2021 at 7:46 PM Antoon Pardon wrote: >>> So if you want this added, show a use-case that makes it look way >>> better than the alternatives (including a generator, a mid-loop break, >>> etc). >> Way better according to which criteria? IMO to realy make something like >> this you would need a one and a half loop. But although at some time there >> was a strong indication it would get included, the idea was eventually discarted. >> >> So I'll argue for incremental better if I see a possibility. A few incremental >> betters can eventually result in something that is way better than the original. > According to any criteria you like. Remember, the onus is not on the > status quo to justify itself; the onus is on someone who wants to make > a change. Then don't answer that I can justify it according to any criteria I like. It will have to be done according to criteria that are important to the people who like the status quo. That it will be justified according to criteria I like, will be totally unimportant. > Demonstrate that a change is needed by showing the benefits. Nothing is needed. But the walrus operator wasn't needed either. Asking to show something is needed is putting a burden on who wants to advocate for this, that isn't put on others. -- Antoon Pardon. From hjp-python at hjp.at Wed Oct 27 05:34:56 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 27 Oct 2021 11:34:56 +0200 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> Message-ID: On 2021-10-27 19:05:52 +1100, Chris Angelico wrote: > On Wed, Oct 27, 2021 at 6:00 PM Antoon Pardon wrote: > > while (a, b) := next_couple(a,b)[-1]: > > ... [...] > I'm not sure that it's much of a use-case; isn't it an infinite loop as written? > > And that's the problem. With multiple-assignment, the overall value is > going to be the tuple, so you then have to add extra parentheses and > subscripting to get what you want to check. Right. I think for that you would want something like what Go does in if: if [assignment-statement ;] condition { statements } Then you could write while a, b = next_couple(a,b); b: ... That doesn't even need the walrus operator. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hjp-python at hjp.at Wed Oct 27 05:52:02 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 27 Oct 2021 11:52:02 +0200 Subject: New assignmens ... In-Reply-To: References: Message-ID: On 2021-10-24 11:23:48 +0200, O365 Dict wrote: > do: > a, b = calculate_next_couple(a, b) > while b: > more calculations I actually like that syntax. -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From rosuav at gmail.com Wed Oct 27 05:59:09 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Oct 2021 20:59:09 +1100 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> <19860f15-c931-27b5-3ae5-7e935fa9e7cb@vub.be> Message-ID: On Wed, Oct 27, 2021 at 8:20 PM Antoon Pardon wrote: > > > > Op 27/10/2021 om 10:49 schreef Chris Angelico: > > On Wed, Oct 27, 2021 at 7:46 PM Antoon Pardon wrote: > >>> So if you want this added, show a use-case that makes it look way > >>> better than the alternatives (including a generator, a mid-loop break, > >>> etc). > >> Way better according to which criteria? IMO to realy make something like > >> this you would need a one and a half loop. But although at some time there > >> was a strong indication it would get included, the idea was eventually discarted. > >> > >> So I'll argue for incremental better if I see a possibility. A few incremental > >> betters can eventually result in something that is way better than the original. > > According to any criteria you like. Remember, the onus is not on the > > status quo to justify itself; the onus is on someone who wants to make > > a change. > > Then don't answer that I can justify it according to any criteria I like. > It will have to be done according to criteria that are important to the > people who like the status quo. That it will be justified according to > criteria I like, will be totally unimportant. > > > Demonstrate that a change is needed by showing the benefits. > > Nothing is needed. But the walrus operator wasn't needed either. Asking to > show something is needed is putting a burden on who wants to advocate for > this, that isn't put on others. > You can argue the word "need" all you like, but the fact remains that YOU want a change, so YOU have to convince people of the benefits. ChrisA From tjandacw at gmail.com Wed Oct 27 06:25:29 2021 From: tjandacw at gmail.com (Tim Williams) Date: Wed, 27 Oct 2021 06:25:29 -0400 Subject: How to store the result of df.count() as a new dataframe in Pandas? In-Reply-To: References: Message-ID: On Tue, Oct 26, 2021 at 6:36 PM Shaozhong SHI wrote: > Hello, > > The result of df.count() appears to be a series object. How to store the > result of df.count() as a new dataframe in Pandas? > > That is data anyhow. > > Regards, > > David > -- > https://mail.python.org/mailman/listinfo/python-list Have you tried something like df_count = pd.DataFrame(df.count()) ? (Untested, but I've converted Series objects to DataFrames doing something similar before.) This is more of a pandas question. Why don't you ask this on stackoverflow? https://stackoverflow.com/questions/tagged/pandas From Karsten.Hilbert at gmx.net Wed Oct 27 06:40:20 2021 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 27 Oct 2021 12:40:20 +0200 Subject: The task is to invent names for things In-Reply-To: References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: Am Wed, Oct 27, 2021 at 10:20:19AM +1100 schrieb Chris Angelico: > Many operations in computing are fully reversible. After you do > something, you can undo it. After you assign, you can unassign. And > after you ite, you can unite! I wonder whether Japanese programmers would agree. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From Karsten.Hilbert at gmx.net Wed Oct 27 06:41:56 2021 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 27 Oct 2021 12:41:56 +0200 Subject: The task is to invent names for things In-Reply-To: References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: Am Tue, Oct 26, 2021 at 11:36:33PM +0000 schrieb Stefan Ram: > xyzzy = lambda x: 2 * x > > . Sometimes, this can even lead to "naming paralysis", where > one thinks excessively long about a good name. To avoid this > naming paralysis, one can start out with a mediocre name. In > the course of time, often a better name will come to one's mind. In that situation, is it preferable to choose a nonsensical name over a mediocre one ? Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From antoon.pardon at vub.be Wed Oct 27 06:45:25 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Oct 2021 12:45:25 +0200 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> <19860f15-c931-27b5-3ae5-7e935fa9e7cb@vub.be> Message-ID: <0cc76ebd-ffc4-a001-27f5-1ac6fcf5db04@vub.be> Op 27/10/2021 om 11:59 schreef Chris Angelico: > You can argue the word "need" all you like, but the fact remains that > YOU want a change, so YOU have to convince people of the benefits. That is true. But there is nothing wrong in asking what might convince people. But I'll give you my thought below and you can decide in how far this is convincing to you. I regularly come with a problem for which a one and a half loop is very suited to solve it. Unfortunately python doesn't have a one and a half loop. However with the introduction of the walrus operator there is a way to simulate a significant number of one and a half loops. Consider the following: do a = expr1 b = expr2 while 2 * a > b: more calculations We could write that now as while [ a := expr1, b := expr2, 2 * a > b][-1]: more calculations Now there is some ugly side on the above and it may not be obvious at first what is going on, but once you understand it is a rather easy idiom. I certainly prefer it over writing something like while True: a = expr1 b = expr2 if not (2 * a > b): break more calculations. So for me any limitation on the walrus operator that is removed is a plus because it will allow me to write more one and a half loops in more natural way. Off course should the python developers decide to intoduce a real one and a half loop all the above is probably a whole let useful. -- Antoon Pardon From rosuav at gmail.com Wed Oct 27 07:00:16 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Oct 2021 22:00:16 +1100 Subject: The task is to invent names for things In-Reply-To: References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: On Wed, Oct 27, 2021 at 9:41 PM Karsten Hilbert wrote: > > Am Wed, Oct 27, 2021 at 10:20:19AM +1100 schrieb Chris Angelico: > > > Many operations in computing are fully reversible. After you do > > something, you can undo it. After you assign, you can unassign. And > > after you ite, you can unite! > > I wonder whether Japanese programmers would agree. > Not sure. My knowledge of Japanese is extremely scanty. Can you elaborate? ChrisA From hjp-python at hjp.at Wed Oct 27 08:55:07 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 27 Oct 2021 14:55:07 +0200 Subject: The task is to invent names for things In-Reply-To: References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: On 2021-10-27 22:00:16 +1100, Chris Angelico wrote: > On Wed, Oct 27, 2021 at 9:41 PM Karsten Hilbert wrote: > > Am Wed, Oct 27, 2021 at 10:20:19AM +1100 schrieb Chris Angelico: > > > Many operations in computing are fully reversible. After you do > > > something, you can undo it. After you assign, you can unassign. And > > > after you ite, you can unite! > > > > I wonder whether Japanese programmers would agree. > > Not sure. My knowledge of Japanese is extremely scanty. Can you elaborate? Don't know about Japanese but it works in Latin (FSVO "works"). hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From dvl at psu.edu Wed Oct 27 12:16:11 2021 From: dvl at psu.edu (Christman, Roger Graydon) Date: Wed, 27 Oct 2021 16:16:11 +0000 Subject: New assignmens ... Message-ID: On 27/10/2021 at 12:45 Antoon Pardon wrote: > However with the introduction of the walrus operator there is a > way to simulate a significant number of one and a half loops. > Consider the following: > do > a = expr1 > b = expr2 > while 2 * a > b: > more calculations > We could write that now as > while [ > a := expr1, > b := expr2, > 2 * a > b][-1]: > more calculations Why don't you try this? while 2 * (a := expr1) > (b := expr2): more calculations It seems you are just compelled to create tuple and lists in all of your use-cases, even when they serve no purpose. Roger Christman From antoon.pardon at vub.be Wed Oct 27 13:01:44 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 27 Oct 2021 19:01:44 +0200 Subject: New assignmens ... In-Reply-To: References: Message-ID: <0dbbf741-7e9e-83f7-5607-5cc0de137526@vub.be> Op 27/10/2021 om 18:16 schreef Christman, Roger Graydon: > On 27/10/2021 at 12:45 Antoon Pardon wrote: >> However with the introduction of the walrus operator there is a >> way to simulate a significant number of one and a half loops. >> Consider the following: > > do > > a = expr1 > > b = expr2 > > while 2 * a > b: > > more calculations > >> We could write that now as > > while [ > > a := expr1, > > b := expr2, > > 2 * a > b][-1]: > > more calculations > > Why don't you try this? Because this is about a general idea, not about the specifics of the example. > while 2 * (a := expr1) > (b := expr2): > more calculations > > It seems you are just compelled to create tuple and lists > in all of your use-cases, even when they serve no purpose. Do you have a procedure that will always eliminate a list and will be more or less as readable as the one and a half loop? I know the list serves no purpose, other than to provide a way to easily write the calculations in the order that seems most natural. But being able to write calculations in the order that makes them more understandable is IMO worth more than eliminating the list. Even if the list serves no real purpose in the calculations. So suppose I have an arbitrary number of simple statements. The latter possible using results from previous assignment and at the end a condition to control the one and a half loop. How do you write the python code so that the one and a half loop is easy to recognize? -- Antoon Pardon From dvl at psu.edu Wed Oct 27 11:05:23 2021 From: dvl at psu.edu (Christman, Roger Graydon) Date: Wed, 27 Oct 2021 15:05:23 +0000 Subject: New assignmens ... Message-ID: On 27/10/2021 8:28, Anton Pardon wrote: >>> Suppose I would like to write a loop as follows: >>. > while ((a, b) := next_couple(a, b))[1]: >> > do needed calculations >> >> >>> What I can do is write it as follows: >>> while [tmp := next_couple(a,b), a := tmp[0], b := tmp[1]][-1]: >> > do needed calculations >> >>> I really don't see what is gained by "forcing" me to right the second code over the first. >> No, nobody is forcing you to write it the second way over the first. >> Nobody is forcing you to use the walrus operator at all! >> >> Instead, I would recommend something more like: >> >> while b: >> do needed calculations >> (a,b) = next_couple(a,b) > But AIU the walrus operator was introduced so we no longer needed, to write such code, > with the calculation of the next candidate at the bottom and the test at the top. > You just confirmed the walrus operator is not very useful once the next candidate is > no longer just a name. I must disagree with the first sentence here regarding why the walrus operator was introduced. I read through the PEP, and saw nothing about that in the Rationale. I do see the loop-and-a-half example, but that actually had its next candidate value near the top (just before a break). I'm going to provide two loop-and-a-half segments to illustrate my interpretation of this PEP and the purpose of the walrus operator: Without the walrus: total = 0 value = input() while value >= 0: total += value value = input() print(total) With the walrus: total = 0 while (value := input()) > 0: total += value print(total) In terms of the PEP -- I want to compare each input value to 0 for the loop test, but I also want to preserve that value, to add to the total. There is a subexpression (input()) within a larger expression (compared to 0) that I wish to name for reuse. Now contrast with this example: Without the walrus: replay = True while replay: play_game() replay = input("Play again? ") in ['y','Y','yes','Yes'] (I think it silly to ask about playing again at first). With the walrus: replay = None while replay==None or (replay := input("Play again? ") in ['y','Y','yes','Yes']: play_game() To use the walrus operator here, I have to fabricate a value that would allow me to bypass the input operation, that cannot be otherwise produced. I do not find this second version any clearer or more intuitive than the first (and the PEP did emphasize the value of clarity). Now reading this in terms of the PEP, where I subexpression (the input) in a larger expression (seeing if it is the list), I do not really seem to have a compelling reason to name the value of that subexpression, since I am not using it for any other purpose, so I could keep the input in the while condition without using the walrus operator: first_play = True while first_play or input("Play again? ") in ['y','Y','yes','Yes']: play_game() first_play = False I do not find this particularly clearer or better than my first version with the test at the bottom, again since it requires me to do some extra machinery to avoid the undesired input before the first repetition. But I might also still argue that this is a little bit clearer than the walrus alternative above. My claim from these two examples is that the walrus is helpful to reduce duplicating or recomputing subexpressions, not simply just to facilitate code movement. It is not at all useful for a while loop condition if the subexpression you wish to evaluate depends on whether or not this is the first iteration of the loop. Which then gets me back to your own illustrated use-case for which I had raised a few questions/objections to before: while ((a, b) := next_couple(a, b))[1]: do needed calculations What is the name of the value you wish to test? b What is this actually testing? element [1] of a tuple So already the code is unclear (and was made worse when you said the existing walrus operator forced you to make a list of three elements, two assigned with the walrus, and then using a subscript of [-1] to get what you wanted. My proposed solution explicitly tested b, since that seemed to be what was of interest: while b: do needed calculations (a,b) = next_couple(a,b) To which you had replied: > But AIU the walrus operator was introduced so we no longer needed, to write such code, > with the calculation of the next candidate at the bottom and the test at the top. > You just confirmed the walrus operator is not very useful once the next candidate is > no longer just a name. Okay, I would be happy to confirm my belief that the walrus is not very useful when the thing you wish to test is not the same as the thing you with to assign. But to relate this use case to my earlier loop-and-a-half examples: (a,b) := next_couple(a,b) presumes that there is are values for a and b to begin with for that first call to next_couple. How do you initialize them correctly? If you initialize them to the "first" couple (whatever that is), then your loop will start off finding the second couple and you would be missing your first iteration. Do you put special code in next_couple() to recognize that the provided arguments are actually the first couple so it can return those unmodified, but then require its own mental note not to give you an infinite loop forever returning that first couple? Do you have to define a special case such as (a,b) = (0,0) or (None,None) to tell next_couple that you really want the first one? That seems a little counter-intuitive to have something named "next" need a special input to mean "first", Not to mention whatever you use to initialize is probably not going to be very meaningful or clear on its own terms. In my earlier note, I objected to "(ctr := ctr-1) > 0" on the grounds that it required initializing the counter to 11 when you really wanted to count down from 10. I favor using the walrus operator when it actually makes the code simpler and clearer; I don't favor using it willy-nilly just because you wish to do an assignment operation inside of a test condition, if its usage makes the code less clear. I interpret the PEP has using the walrus to define a name for a particular value that would be both tested and reused, and not that it would be used to assign to a value that was not being tested (such as the a part of (a,b)). Or in short, I do not find your choice of use-case really lines up with the rationale given for walrus operator. You are free to disagree with me, but fortunately, we have one of those PEP authors participating in this list regularly if you want his opinion. Roger Christman Pennsylvania State University From avigross at verizon.net Wed Oct 27 14:20:44 2021 From: avigross at verizon.net (Avi Gross) Date: Wed, 27 Oct 2021 14:20:44 -0400 Subject: New assignmens ... In-Reply-To: <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> Message-ID: <034401d7cb5f$5b5619e0$12024da0$@verizon.net> I think anyone who suggests we should separate costs from benefits belongs securely within the academic world and should remain there. Practical things need to be built considering costs. Theoretical things, sure, cost is not an issue. Python is not only a real-world set of applications but an evolving one with a huge embedded base. We have seen how hard it was for some to move when 2.X and 3.X versions were not upward compatible. Some have refused to move. So adding new features must not only be done carefully with an eye for path upward but also to not destroy existing programs when possible. When a change is needed, it is often done in stages with some things being deprecated for a while before the change. So the half-submerged walrus operator was added instead of the flying walrus operator with anti-gravity built in. If the proposal had been to allow EVERYTHING you and others are suggesting, it is quite possible we would never have had anything changed and no walrus. True, in another decade or so, they might have gotten around to adding the unrestricted walrus. or not. What we have today is a path that may lead to more functionality incrementally. If people are using the walrus and like it and it makes coding easier AND they ask for more, it may come, at incremental cost. -----Original Message----- From: Python-list On Behalf Of Antoon Pardon Sent: Wednesday, October 27, 2021 2:59 AM To: python-list at python.org Subject: Re: New assignmens ... Op 26/10/2021 om 00:24 schreef Chris Angelico: > TBH, I don't think there's a lot of value in multiple-assignment, > since it has a number of annoying conflicts of syntax and few viable > use-cases. But if you have great examples of "x.y :=" or "x[y] :=", > then by all means, post on python-ideas to propose widening the scope. I think you should seperate the costs from the benefits. It is not because the costs can be high there is little value. And how do you count use cases? What about the following pattern: while (a, b) := next_couple(a,b)[-1]: ... Is that one use case or is that a use case for each kind of couple? And even if the benefits are little per case, they can add up with every occasion such a case pops up. -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Oct 27 14:35:54 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Oct 2021 05:35:54 +1100 Subject: New assignmens ... In-Reply-To: <0dbbf741-7e9e-83f7-5607-5cc0de137526@vub.be> References: <0dbbf741-7e9e-83f7-5607-5cc0de137526@vub.be> Message-ID: On Thu, Oct 28, 2021 at 4:03 AM Antoon Pardon wrote: > > So suppose I have an arbitrary number of simple statements. The > latter possible using results from previous assignment and at the > end a condition to control the one and a half loop. How do you write > the python code so that the one and a half loop is easy to recognize? > The most general way to write a loop-and-a-half is to invert the condition and break. For cases too complicated to fit into the loop header, that would be the obvious solution. ChrisA From unixnut at witheredfire.com Wed Oct 27 13:01:42 2021 From: unixnut at witheredfire.com (Unixnut) Date: Wed, 27 Oct 2021 18:01:42 +0100 Subject: Does loading PDB slow down execution? In-Reply-To: References: <24925.56633.615436.668290@ixdm.fritz.box> Message-ID: <20ef8bcc-9fdb-7894-2c7f-9fab3c0532c0@witheredfire.com> On 06/10/2021 18:30, Dieter Maurer wrote: > Unixnut wrote at 2021-10-3 22:03 +0100: >> If I run a python3 program with "import pdb" in the code, would it >> execute slower than without loading the debugger? > > Importing `pdb` does not slow down the application significantly > (it just adds the import time but does not otherwise affect the > application). > > Only when you execute code under debugger control, the > execution is significantly slowed down (because the debugger > gets informed (via callbacks) about important "event"s (entering > a line, function call, function return, exception) during > the execution). > Excellent, many thanks for confirming. I can leave the execution running then. From rosuav at gmail.com Wed Oct 27 14:42:45 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Oct 2021 05:42:45 +1100 Subject: New assignmens ... In-Reply-To: References: Message-ID: On Thu, Oct 28, 2021 at 4:34 AM Christman, Roger Graydon wrote: > Do you put special code in next_couple() to recognize that the provided arguments > are actually the first couple so it can return those unmodified, but then require its > own mental note not to give you an infinite loop forever returning that first couple? > > Do you have to define a special case such as (a,b) = (0,0) or (None,None) to tell > next_couple that you really want the first one? That seems a little counter-intuitive > to have something named "next" need a special input to mean "first", In some cases, there is a very real special startup value (a seed). For instance, if we're calculating something relating to the Mandelbrot set: # The point we're working with c = (0.25 + 0.125j) # Always start here z = (0 + 0j) # or just 0 while abs(z := z*z+c) < 2: ... Though in this case, you don't look for a next_couple, you look for a single next value, and the other value is constant. But it all depends on the exact process being done, which is why I've been asking for real examples. ChrisA From arj.python at gmail.com Wed Oct 27 14:47:37 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 27 Oct 2021 22:47:37 +0400 Subject: New assignmens ... In-Reply-To: References: Message-ID: I no longer track the threads on the subject ... Many simultaneous ones ongoing! Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius From joel.dcosta83 at gmail.com Wed Oct 27 15:00:16 2021 From: joel.dcosta83 at gmail.com (Python 4 Fun) Date: Wed, 27 Oct 2021 12:00:16 -0700 (PDT) Subject: Get a Joke in Python Message-ID: <406a1138-3c2c-47f5-89c8-364460ac7d20n@googlegroups.com> Get a Joke in Python. Pyjokes - is a python library / module for one line joke program based on programmers. You can get funny one-liner random jokes at every run also available in following " languages " & " categories ". Supported Languages By Pyjokes English ? ?en? Spanish ? ?es? Italian ? ?it? German ? ?de? Galician ? ?gl? Basque ? ?eu? Categories Included In Pyjokes For geeky jokes -?neutral? (It is chosen by default) For Chris Norris Jokes ? ?chuck?. If you want all type of jokes ? ?all? There is one more category known as ?twister? which only works for the German Language (?de?) and mostly includes tongue twister. Read the documentation available on https://pyjok.es for more info. :::Lets Code::: Install pyjokes if you haven't pip install pyjokes This Program will give you one-liner Joke #pip install pyjokes # importing module i [Read More...] https://pysnakeblog.blogspot.com From bschollnick at schollnick.net Wed Oct 27 15:47:08 2021 From: bschollnick at schollnick.net (Benjamin Schollnick) Date: Wed, 27 Oct 2021 15:47:08 -0400 Subject: Does loading PDB slow down execution? In-Reply-To: <20ef8bcc-9fdb-7894-2c7f-9fab3c0532c0@witheredfire.com> References: <24925.56633.615436.668290@ixdm.fritz.box> <20ef8bcc-9fdb-7894-2c7f-9fab3c0532c0@witheredfire.com> Message-ID: > On Oct 27, 2021, at 1:01 PM, Unixnut wrote: > > On 06/10/2021 18:30, Dieter Maurer wrote: >> Unixnut wrote at 2021-10-3 22:03 +0100: >>> If I run a python3 program with "import pdb" in the code, would it >>> execute slower than without loading the debugger? >> Importing `pdb` does not slow down the application significantly >> (it just adds the import time but does not otherwise affect the >> application). >> Only when you execute code under debugger control, the >> execution is significantly slowed down (because the debugger >> gets informed (via callbacks) about important "event"s (entering >> a line, function call, function return, exception) during >> the execution). > Excellent, many thanks for confirming. I can leave the execution running then. But it?s pointless to import pdb, if you aren?t going to use it. I would suggest that a best practice would be to only import pdb, if and when you were going to be performing the debugging. (So maybe set a boolean constant, that would cause the import, and debugging code to be executed. From arj.python at gmail.com Wed Oct 27 15:49:59 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 27 Oct 2021 23:49:59 +0400 Subject: Why so fast a web framework? Message-ID: See this: https://github.com/walkor/webman Why similar frameworks do not exist in Python. Is it because of lack of lib contributors or due to an inherent difference in Py and PHP? Thanks! Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius From hjp-python at hjp.at Wed Oct 27 15:52:10 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 27 Oct 2021 21:52:10 +0200 Subject: Does loading PDB slow down execution? In-Reply-To: References: <24925.56633.615436.668290@ixdm.fritz.box> <20ef8bcc-9fdb-7894-2c7f-9fab3c0532c0@witheredfire.com> Message-ID: On 2021-10-27 15:47:08 -0400, Benjamin Schollnick wrote: > > On Oct 27, 2021, at 1:01 PM, Unixnut wrote: [...] > > Excellent, many thanks for confirming. I can leave the execution running then. > > But it?s pointless to import pdb, if you aren?t going to use it. Please read the first mail in this thread. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From rosuav at gmail.com Wed Oct 27 15:56:29 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Oct 2021 06:56:29 +1100 Subject: Why so fast a web framework? In-Reply-To: References: Message-ID: On Thu, Oct 28, 2021 at 6:52 AM Abdur-Rahmaan Janhangeer wrote: > > See this: > https://github.com/walkor/webman > > Why similar frameworks do not exist in Python. Is it because > of lack of lib contributors or due to an inherent difference in Py > and PHP? Thanks! > It depends entirely on what that benchmark is measuring, and how tightly that framework was optimized for the benchmark. In real-world code, performance is seldom dictated by the framework. I can get 100TPS with naive code on a naive database implementation, and improving that is going to be more about improving the database or the application rather than the framework. Of course, tools that can't brag about readability, usability, maintainability, etc, will naturally brag about their benchmark results, regardless of how significant - or otherwise - they really are. ChrisA From hjp-python at hjp.at Wed Oct 27 15:57:16 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 27 Oct 2021 21:57:16 +0200 Subject: Why so fast a web framework? In-Reply-To: References: Message-ID: On 2021-10-27 23:49:59 +0400, Abdur-Rahmaan Janhangeer wrote: > See this: > https://github.com/walkor/webman > > Why similar frameworks do not exist in Python. Is it because > of lack of lib contributors or due to an inherent difference in Py > and PHP? Thanks! The comparison table contains only PHP based frameworks. How do you know that no Python based frameworks of similar performance exist? (And is the benchmark even meaningful?) hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From Karsten.Hilbert at gmx.net Wed Oct 27 16:52:38 2021 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 27 Oct 2021 22:52:38 +0200 Subject: The task is to invent names for things In-Reply-To: References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: Am Wed, Oct 27, 2021 at 10:00:16PM +1100 schrieb Chris Angelico: > > Am Wed, Oct 27, 2021 at 10:20:19AM +1100 schrieb Chris Angelico: > > > > > Many operations in computing are fully reversible. After you do > > > something, you can undo it. After you assign, you can unassign. And > > > after you ite, you can unite! > > > > I wonder whether Japanese programmers would agree. > > Not sure. My knowledge of Japanese is extremely scanty. Can you elaborate? ite is the -te form (in some uses like a gerundium) of aru (to go, to walk) so, to un-go, revert-the-having-gone-ness, I genuinely wonder ... On the other hand, Japanese is full of wondrous word-play at levels undreamt of by us ASCIInarians. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From Karsten.Hilbert at gmx.net Wed Oct 27 16:53:31 2021 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Wed, 27 Oct 2021 22:53:31 +0200 Subject: The task is to invent names for things In-Reply-To: References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: Am Wed, Oct 27, 2021 at 12:41:56PM +0200 schrieb Karsten Hilbert: > Am Tue, Oct 26, 2021 at 11:36:33PM +0000 schrieb Stefan Ram: > > > xyzzy = lambda x: 2 * x > > > > . Sometimes, this can even lead to "naming paralysis", where > > one thinks excessively long about a good name. To avoid this > > naming paralysis, one can start out with a mediocre name. In > > the course of time, often a better name will come to one's mind. > > In that situation, is it preferable to choose a nonsensical > name over a mediocre one ? That one was a genuine question, BTW, not a snark remark. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From rosuav at gmail.com Wed Oct 27 16:56:42 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Oct 2021 07:56:42 +1100 Subject: The task is to invent names for things In-Reply-To: References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: On Thu, Oct 28, 2021 at 7:54 AM Karsten Hilbert wrote: > > Am Wed, Oct 27, 2021 at 10:00:16PM +1100 schrieb Chris Angelico: > > > > Am Wed, Oct 27, 2021 at 10:20:19AM +1100 schrieb Chris Angelico: > > > > > > > Many operations in computing are fully reversible. After you do > > > > something, you can undo it. After you assign, you can unassign. And > > > > after you ite, you can unite! > > > > > > I wonder whether Japanese programmers would agree. > > > > Not sure. My knowledge of Japanese is extremely scanty. Can you elaborate? > > ite is the -te form (in some uses like a gerundium) of aru > (to go, to walk) > > so, to un-go, revert-the-having-gone-ness, I genuinely wonder ... > > On the other hand, Japanese is full of wondrous word-play at > levels undreamt of by us ASCIInarians. > Ah ha, neat :) Thank you. ChrisA From PythonList at DancesWithMice.info Wed Oct 27 17:28:38 2021 From: PythonList at DancesWithMice.info (dn) Date: Thu, 28 Oct 2021 10:28:38 +1300 Subject: The task is to invent names for things In-Reply-To: References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: On 27/10/2021 23.41, Karsten Hilbert wrote: > Am Tue, Oct 26, 2021 at 11:36:33PM +0000 schrieb Stefan Ram: > >> xyzzy = lambda x: 2 * x >> >> . Sometimes, this can even lead to "naming paralysis", where >> one thinks excessively long about a good name. To avoid this >> naming paralysis, one can start out with a mediocre name. In >> the course of time, often a better name will come to one's mind. > > In that situation, is it preferable to choose a nonsensical > name over a mediocre one ? I've often debated this with myself - it's related to adding: """Docstring.""" immediately after typing a class/function/method definition - because my head is too full of the code to be written - and those linters can be clamorously insistent! Thus, isn't the answer "yes!". Cognitive over-load is the issue: We can only hold so many thoughts in-mind at a given point in time. (the size of "many" being up for debate, highly variable between individuals, and between the same person at different times or under different conditions - see also "in the zone") With today's powerful IDEs, in particular Find-and-Replace-All functions (noted that PyCharm has a Refactor facility which includes such, and with code-aware 'intelligence' cf 'blind' string-matching), it really is easier to go with a 'first thought name' and the promise of re-visiting the choice later. When 'later' arrives, eg when the value is being utilised differently (an earlier comment in this thread), there is a natural/QA process to (re-)think the name according to its different aspects over time. That said... there is a risk that you (OK, "I") don't re-visit the choice and "asdf" (easy for US-keyboard users) 'slips through' to Code Review. Oops! You do Code Review don't you? An opposing thought might be that if you have sat-down and sketched-out a design - a high-level 'how' you are going to deliver the requirements, many 'names' will be 'set' during that process - I think an integral component of Domain-Driven Design (DDD) philosophy. An eminently-sensible piece of advice underlying such thinking is that the spec/requirement should be written in the user's terms (those of the "domain"). Thus, the easiest (and accuracy/consistency promoting) path, is to maintain the use of that terminology/names all the way through from spec to code. Above also reduces my cognitive load - an appealing characteristic for such a lazy "bear of little brain"... -- Regards, =dn From hjp-python at hjp.at Wed Oct 27 18:41:41 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 28 Oct 2021 00:41:41 +0200 Subject: The task is to invent names for things In-Reply-To: References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: On 2021-10-27 12:41:56 +0200, Karsten Hilbert wrote: > Am Tue, Oct 26, 2021 at 11:36:33PM +0000 schrieb Stefan Ram: > > xyzzy = lambda x: 2 * x > > . Sometimes, this can even lead to "naming paralysis", where > > one thinks excessively long about a good name. To avoid this > > naming paralysis, one can start out with a mediocre name. In > > the course of time, often a better name will come to one's mind. > > In that situation, is it preferable to choose a nonsensical > name over a mediocre one ? I don't know. A mediocre name conveys at least some information, and that seems to be better than none. On the other hand it might be just enough to lead the reader astray which wouldn't happen with a non-sensical name. But since perfect names are hard to find, using nonsensical instead of mediocre names would mean choosing nonsensical names most of the time. So I'll stick with mediocre names if in doubt. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From avigross at verizon.net Wed Oct 27 19:54:58 2021 From: avigross at verizon.net (Avi Gross) Date: Wed, 27 Oct 2021 19:54:58 -0400 Subject: Create a contact book In-Reply-To: References: <3ba51db0-7e7c-4243-998c-606146dd5b60n@googlegroups.com> <027001d7ca7c$80fd2c30$82f78490$@verizon.net> Message-ID: <010601d7cb8e$0c741e10$255c5a30$@verizon.net> I used to be on the Tutor list for python and found it was not for me. Yes, we should refer people there especially those who seem to have HW and would like some gentle coaching but not outright answers. What frustrated me is that rarely would we be told by people what they had learned and were allowed to use. Beginners rarely are supposed to use advanced features or modules like numpy or pandas or often even list comprehensions. Most conversations there have to be a back and forth asking questions and waiting for answers and repeat ad nauseum. Or give them general advice like what kinds of data structures and algorithm they think make sense before making an actual program, then finding out what python commands and techniques would be useful. The idea is to have them show us their solution and point out what may be wrong or bridge a minor gap or explain an error message. It was not really a place to discuss language design like here, or offer obscure algorithms for finding primes. It is more a place where you might program the Sieve of ???????????? more plainly and simply! LOL! The reality is that many forms of "assistance" do verge on cheating BUT anyone with a browser can now find tons of information on so many things online. I just did a search with these words: "python prime numbers from 1 to 100 " I found answers ranging from complete to hints. Other similar requests returned plenty more. So why ask here? Why waste the valuable time of so many (albeit mine is not that valuable, LOL) when most here probably have no interest? And, if someone here answered, would that make it less or more likely they were caught if anyone wondered why their answer was so good? I do not mind helping people when I have the time and inclination and especially not if the request is properly shown and it is easy to maybe even copy and run it and quickly see some minor thing they were not aware of. But spending days tutoring someone who starts seeming to know very little, not something I want to do. If I wanted, I might even get $15 an hour tutoring any number of subjects, but then again, a job at McDonalds might pay as well and with benefits. My view is that the goal of Education includes learning how to do it by yourself, or do something similar again after getting minimal help. People taking classes should normally have enough local help. -----Original Message----- From: Python-list On Behalf Of dn via Python-list Sent: Wednesday, October 27, 2021 12:15 AM To: python-list at python.org Subject: Re: Create a contact book On 27/10/2021 04.16, Avi Gross via Python-list wrote: > Chris, > > I think it is time someone set up a business where they do the > homework for people for a mere $1,000 or so per hour. Anonymously, of > course. And we can refer requests for free homework advice there. > > Maybe the answer to this request is to suggest they use FACEBOOK which > seemingly keeps you in contact and lets you add friends and view them .... > > On Tue, Oct 26, 2021 at 5:30 PM anders Limpan wrote: >> >> i would like to create a contact book were you can keep track of your >> friends. With this contact book you will both be able to add friends >> and view which friends that you have added. anyone interested in >> helping me out with this one ?=) >> > > Here at Homeworks Anonymous, the first step is admitting that what you > have is a homework problem. :) This isn't a project, this is something > you're doing for a course, and it's not really fair to pretend > otherwise :) > > ChrisA It's a balancing-act: - on the one hand writing (their) code is not helping a trainee to learn (and certainly not in the manner the trainer intended) - on the other, we should try to welcome and encourage new-comers to our list/the Python eco-system. That said, I've often recommended folk switch/also subscribe to the Tutor list, but can't say if many actually did. "Essay Mills" are back in the news in the UK with a proposal to make them completely illegal. The Times Educational Supplement printed an article two~three weeks ago (https://www.timeshighereducation.com/student/advice/tempted-pay-your-essays-here-are-six-reasons-not - likely behind a pay-wall - if so, apologies). The author identified six reasons for not using an Essay Mill: (the labels are his, the summaries beyond them are mine) 1 Harsh penalties - if caught 2. Fool no more - plagiarism software these days is not only comparing 'this work' with others' assignment returns, but this with your other submissions, ie noting if your personal writing style changes! 3. Career impact - how it impacts employment (possibilities) if such is either on your record or becomes evident later 4. On the record - if the 'mill' has your record, what if they're hacked? Do they have better security than the many organisations which have been breached? 5. No guarantee of anonymity - your shadow-author will have a 'hold' over you, forever 6. Bribery - perhaps that essay should be about blackmail, how it could start, and what might be its effects? -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list From avigross at verizon.net Wed Oct 27 20:06:57 2021 From: avigross at verizon.net (Avi Gross) Date: Wed, 27 Oct 2021 20:06:57 -0400 Subject: New assignmens ... In-Reply-To: References: Message-ID: <013201d7cb8f$b95869a0$2c093ce0$@verizon.net> Dave, You make me wonder about unintended side effects. Are we allowing the ++ and --- operations into Python through a side door? any context that allows you to insert the walrus operator like: index := index + 1 index := index - 1 Is now similar to notations in C/C++ and others like ++index --index If you can set or reset a variable this way, it can even look more efficient that counting by 2 or more which in C would look like: ++(++index) Of course we now would get suggestions to just add the pre-increment operator to Python, and while we are added, for completeness, add the post-increment version of index++ ... I mean if cost is no object, and worrying how it may impact current programs or conflicts is nothing to be concerned about in the interest of some academic purity ... -----Original Message----- From: Python-list On Behalf Of dn via Python-list Sent: Wednesday, October 27, 2021 4:38 AM To: python-list at python.org Subject: Re: New assignmens ... On 24/10/2021 22.23, O365 Dict wrote: > Well I have the following use case: > > while (temp_result := calculate_next_couple(a, b))[1]: > a, b = temp_result > more calculations > > Which IMO would be clearer if I could just write: > > while ((a, b) := calculate_next_couple(a,b))[1]: > more calculations > > Of course it would even more clear if I could write something like: > > while (a, b) := calculate_next_couple(a, b); b: > more calculations > > or > > do: > a, b = calculate_next_couple(a, b) > while b: > more calculations Found (all of) the above less-than-obvious to read. Putting it in front of trainees this morning caused only confusion - even the currently-legal variation. Accordingly: is this a job for the walrus operator at all? Let's "talk of many [other] things"*. Is this an algorithmic complexity, or a complicated way to look at (and manipulate) data? Well, judging from the code (above), use of the walrus certainly presumes the former. Instead let's review any possibility of the latter (if only for academic interest)... What do we want out of the first line? (in no particular order) 1 use calculate_next_couple() to compute (new) a from an (old) a and b 2 use calculate_next_couple() to compute (new) b from an (old) a and b 3 use (new) b to decide if the loop should execute or terminate The 'problem' then, has been phrased as these three objectives ask too much of the (current implementation of the) walrus-operator. NB after one (or more) cycles, when the loop 'returns to the top', what I've termed 'new' a and b (above), will become (my reference) the 'old' pair/tuple. That all looks simple. What is dn complaining about? Could we use a data structure to continue to keep things straight-forward? class my_class(): def __init__( self, a, b )->None; self.a = a self.b = b instance = my_class( a, b ) Sorry, you're probably becoming impatient with me. Surely I'm typing more code than necessary? Maybe, but there are other measures of code-quality/good-practice/etc, and there's likely more to 'it' than just these few lines... First consideration: the algorithm needs us to 'feed' the while-condition. So let's flesh-out: def is_more( self )->bool: # you know what goes here - I don't, but that's not the issue # the return value is all that matters return is_there_any_more_data_to_calculate? In which case, the loop becomes: while instance.is_more(): more calculations and 'readability' improves immeasurably! NB for extra credit, turn the boolean function into a "property", and be able to omit the (unsightly?) parentheses from the 'call'! But, not so fast - what about the calculation itself, currently embedded in calculate_next_couple()? Well, those details are out of my sight, and I'm assuming include reasonable complexity - otherwise you wouldn't propose this as a good-example. Allow me to muddle-through with: def calculate_next_couple( self )->None: self.a = calculation of 'new' a self.b = calculation of 'new' b To avoid an 'extra' call against the instance from the while-loop, execute the 'calculate' method from either __init__() or is_more(), as appropriate (given that it likely needs to precede the return from the latter - particularly if the computation is 'expensive'). The choice may be subject-dependent ... Now within "more calculations", one assumes, references to "a" and "b" will need to be amended to become 'instance.a' and 'instance.b'. More typing! What about preserving our fingers? Readability will further improve when "a" and "b" (etc) are replaced by 'real names'. The processing steps within "more calculations" could be reviewed. Some may be candidates for inclusion as my_class methods - which would even enable further simplifications and/or encapsulation of code-suites relevant to the application, and/or "a" and "b" and the processes around them. If the "calculation" of 'next_couple' currently involves looking-up another data-structure, eg a list of data-points, then combining such with/into my_class may well yield further simplifications, encapsulations, and benefits - but all in-theory and complete ignorance of your application... Hope the above gives you some ideas/pause for thought! * this gratuitous and somewhat awkward expression is me claiming to be clever by quoting Lewis Carroll - if he isn't sick of me baiting-the-hook, it might earn extra brownie-points (or another groan) from @Chris... -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Oct 27 20:50:08 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Oct 2021 11:50:08 +1100 Subject: New assignmens ... In-Reply-To: <013201d7cb8f$b95869a0$2c093ce0$@verizon.net> References: <013201d7cb8f$b95869a0$2c093ce0$@verizon.net> Message-ID: On Thu, Oct 28, 2021 at 11:08 AM Avi Gross via Python-list wrote: > > Dave, > > You make me wonder about unintended side effects. Are we allowing the ++ and > --- operations into Python through a side door? > class IncrementableInteger(int): def __pos__(self): return HalfIncremented(self) def __neg__(self): return HalfDecremented(self) class HalfIncremented(IncrementableInteger): def __pos__(self): return IncrementableInteger(self + 1) class HalfDecremented(IncrementableInteger): def __neg__(self): return IncrementableInteger(self - 1) Up to you to make the actual mutation work but have fun making a nightmare for subsequent maintainers! ChrisA PS. Nobody's ever stopping you from def __add_(self, other): return self * other + 3 Just sayin'. From * at eli.users.panix.com Wed Oct 27 20:38:17 2021 From: * at eli.users.panix.com (Eli the Bearded) Date: Thu, 28 Oct 2021 00:38:17 -0000 (UTC) Subject: The task is to invent names for things References: Message-ID: In comp.lang.python, Peter J. Holzer wrote: ^^^^^^ > On 2021-10-27 12:41:56 +0200, Karsten Hilbert wrote: >> In that situation, is it preferable to choose a nonsensical >> name over a mediocre one ? > I don't know. A mediocre name conveys at least some information, and > that seems to be better than none. On the other hand it might be just > enough to lead the reader astray which wouldn't happen with a > non-sensical name. C is named as a pun on the earlier B, which was derived from BCPL, the Barely Complete Programming Language. Unix is a pun on Multix, Linux a personalization of Unix. sed is a portmanteaux of "stream editor". AWK is named for the authors' initials. Perl started out as an initialism (Practical Extraction and Report Language, I think), which the manpage used to lead with. Ruby is named as a play on Perl, it's a different four letter gem, and Ruby has obvious Perl influence. But "Python"? What's Python named for? Hint, it's a pretty "non-sensical name" for a computer language. > But since perfect names are hard to find, using nonsensical instead of > mediocre names would mean choosing nonsensical names most of the time. > So I'll stick with mediocre names if in doubt. The choice of a non-sensical is perfectly fine _when_ it's a major component. Kafka, Python, Java, Rust. Those are all non-sensically named, in that the name doesn't fit what it is, by pun, initials, or reference. Someone just liked the name and applied it to thing being build. The designer of Kafka liked the author. Guido liked Monty Python. Java is named for coffee. Rust is named for a fungus. Those all work. But if you are writing a new web framework and you name your method to log stuff to a remote server "Britney" because you were listening the singer, that's not perfectly fine, even you want to make "Oops, I did it again" jokes about your logged errors. Where naming has a great importance to understanding, it needs to be done carefully. Mediocre names work, but can be confusing. For the remote logging example, there's probably not a lot of difficulty with mediocre. If you're doing something with a multiple of things, do you call it a "pod", "cluster", "group", "set", etc? You can pick one but then when you have multiples of multiples, you'll want to pick another and if you do it wrong it will confuse people. A Kubernetes "cluster" will run replica "sets" of "pods" (each of which have one or more "containers", but "containers" is a word that predates Kubernetes). If your framework runs "sets" of "clusters" that reversal of heirarchy ends up being more likely to confuse. Or look at the mess that AWS has for Elasticache Redis: you can have a "cluster" that provides redundancy in case something fails. Or you can run in "cluster mode" which shards the data across multiple independent nodes. If you want redundancy in "cluster mode" you can can have groups of replicas. Redis no replication or sharding: Node Redis non-cluster mode cluster: Node Replica-Node1 ... Redis cluster mode cluster no replicaion: Shard-1-Primary-Node Shard-2-Primary-Node ... Redis cluster mode cluster with replicas: Shard-1-Primary-Node Shard-1-Replica-Node-1 ... Shard-2-Primary-Node Shard-2-Replica-Node-1 ... ... Maybe this is Redis's fault or maybe it's AWS's, I don't know the history of these names, I've only used it on AWS. But whoever did the naming did a "mediocre" job to come up with something that's called a "Redis cluster-mode enabled cluster". https://aws.amazon.com/blogs/database/work-with-cluster-mode-on-amazon-elasticache-for-redis/ Elijah ------ naming is hard, unless it's easy From avigross at verizon.net Wed Oct 27 20:56:59 2021 From: avigross at verizon.net (Avi Gross) Date: Wed, 27 Oct 2021 20:56:59 -0400 Subject: walrus with a twist :+= or ... References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> Message-ID: <030e01d7cb96$b69ffc30$23dff490$@verizon.net> I realized that the person seeking completeness in Python may next ask why the Walrus operator, :=, is not properly extended to include a whole assortment of allowed assignment operators I mean in normal python programs you are allowed to abbreviate x = x + 5 with x += 5 Similarly you have other operators like x *= 2 And, of course, the constantly used operator: x %= 2 So how does one extend a walrus operator if they ever decide to give in and add it to the language just for completeness? Sadly, a simple test shows they neglected to use a :+= operator in the latest: >>> (walrus := 2) 2 >>> walrus 2 >>> (wallrus :+= 2) File "", line 1 (wallrus :+= 2) ^ SyntaxError: invalid syntax (Yes, I know how to spell walrus, but making a point.) On a serious note, if it was ever considered a good idea, what would be an acceptable sequence of symbols that might not break or confuse existing programs and what would we call it? I mean what animal, of course. What do these look like in some fonts? :+= :-= :*= :/= :%= Or do we not just add a colon in front and make it a tad different as in :=+ or :+=: or maybe realize the futility of perfection! After all, you can easily use some functions to get a result such as: x := func(x, "+", 5) x := func_add(x, 5) or many other work-arounds. Can we all forget I asked? I am sort of being sarcastic. From avigross at verizon.net Wed Oct 27 21:06:02 2021 From: avigross at verizon.net (Avi Gross) Date: Wed, 27 Oct 2021 21:06:02 -0400 Subject: walrus with a twist :+= or ... In-Reply-To: <030e01d7cb96$b69ffc30$23dff490$@verizon.net> References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> Message-ID: <033701d7cb97$fa593710$ef0ba530$@verizon.net> I just realized I left out **= so my apologies. Are there other such abbreviations and does anyone use them? -----Original Message----- From: Python-list On Behalf Of Avi Gross via Python-list Sent: Wednesday, October 27, 2021 8:57 PM To: python-list at python.org Subject: walrus with a twist :+= or ... I realized that the person seeking completeness in Python may next ask why the Walrus operator, :=, is not properly extended to include a whole assortment of allowed assignment operators I mean in normal python programs you are allowed to abbreviate x = x + 5 with x += 5 Similarly you have other operators like x *= 2 And, of course, the constantly used operator: x %= 2 So how does one extend a walrus operator if they ever decide to give in and add it to the language just for completeness? Sadly, a simple test shows they neglected to use a :+= operator in the latest: >>> (walrus := 2) 2 >>> walrus 2 >>> (wallrus :+= 2) File "", line 1 (wallrus :+= 2) ^ SyntaxError: invalid syntax (Yes, I know how to spell walrus, but making a point.) On a serious note, if it was ever considered a good idea, what would be an acceptable sequence of symbols that might not break or confuse existing programs and what would we call it? I mean what animal, of course. What do these look like in some fonts? :+= :-= :*= :/= :%= Or do we not just add a colon in front and make it a tad different as in :=+ or :+=: or maybe realize the futility of perfection! After all, you can easily use some functions to get a result such as: x := func(x, "+", 5) x := func_add(x, 5) or many other work-arounds. Can we all forget I asked? I am sort of being sarcastic. -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Oct 27 21:10:58 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Oct 2021 12:10:58 +1100 Subject: walrus with a twist :+= or ... In-Reply-To: <030e01d7cb96$b69ffc30$23dff490$@verizon.net> References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> Message-ID: On Thu, Oct 28, 2021 at 11:58 AM Avi Gross via Python-list wrote: > On a serious note, if it was ever considered a good idea, what would be an > acceptable sequence of symbols that might not break or confuse existing > programs and what would we call it? I mean what animal, of course. > > > > What do these look like in some fonts? :+= :-= :*= :/= :%= > What we need is a few more generic operators that can be put together appropriately. For instance, when you need a copy of a list, you can use the "robot face" operator: stuff[:] Perhaps we need some more slice variants. We can already grin: stuff[ :D ] and stick out our tongues: stuff[ :P ] and even gasp in surprise: stuff[ :O ] but the language has an emotional bias towards sadness: stuff[ :( )] since there's no corresponding happiness emoji, nor even ambivalence: stuff[ :| ] However, a wry smile is permitted. stuff[ :\ ] The lack of language support for such a fundamental emotion as happiness is a major flaw and needs to be corrected ASAP. ChrisA From python at mrabarnett.plus.com Wed Oct 27 21:20:33 2021 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 28 Oct 2021 02:20:33 +0100 Subject: walrus with a twist :+= or ... In-Reply-To: <033701d7cb97$fa593710$ef0ba530$@verizon.net> References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> <033701d7cb97$fa593710$ef0ba530$@verizon.net> Message-ID: <1432ee00-ed82-372c-6437-056133ce79b1@mrabarnett.plus.com> On 2021-10-28 02:06, Avi Gross via Python-list wrote: > I just realized I left out **= so my apologies. Are there other such > abbreviations and does anyone use them? > You forgot about the bitwise operators: |= &= ^= > -----Original Message----- > From: Python-list On > Behalf Of Avi Gross via Python-list > Sent: Wednesday, October 27, 2021 8:57 PM > To: python-list at python.org > Subject: walrus with a twist :+= or ... > > I realized that the person seeking completeness in Python may next ask why > the Walrus operator, :=, is not properly extended to include a whole > assortment of allowed assignment operators > > > I mean in normal python programs you are allowed to abbreviate > > x = x + 5 > > with > > x += 5 > > Similarly you have other operators like > > x *= 2 > > And, of course, the constantly used operator: > > x %= 2 > > So how does one extend a walrus operator if they ever decide to give in and > add it to the language just for completeness? > > Sadly, a simple test shows they neglected to use a :+= operator in the > latest: > >>>> (walrus := 2) > > 2 > >>>> walrus > > 2 > >>>> (wallrus :+= 2) > > File "", line 1 > > (wallrus :+= 2) > > ^ > > SyntaxError: invalid syntax > > (Yes, I know how to spell walrus, but making a point.) > > On a serious note, if it was ever considered a good idea, what would be an > acceptable sequence of symbols that might not break or confuse existing > programs and what would we call it? I mean what animal, of course. > > What do these look like in some fonts? :+= :-= :*= :/= :%= > > Or do we not just add a colon in front and make it a tad different as in :=+ > or :+=: or maybe realize the futility of perfection! After all, you can > easily use some functions to get a result such as: > > x := func(x, "+", 5) > > x := func_add(x, 5) > > or many other work-arounds. > > Can we all forget I asked? I am sort of being sarcastic. > From rosuav at gmail.com Wed Oct 27 21:20:52 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 28 Oct 2021 12:20:52 +1100 Subject: The task is to invent names for things In-Reply-To: References: Message-ID: On Thu, Oct 28, 2021 at 11:55 AM Eli the Bearded <*@eli.users.panix.com> wrote: > The choice of a non-sensical is perfectly fine _when_ it's a major > component. Kafka, Python, Java, Rust. Those are all non-sensically named, > in that the name doesn't fit what it is, by pun, initials, or reference. > Someone just liked the name and applied it to thing being build. The > designer of Kafka liked the author. Guido liked Monty Python. Java is > named for coffee. Rust is named for a fungus. > > Those all work. But if you are writing a new web framework and you name > your method to log stuff to a remote server "Britney" because you were > listening the singer, that's not perfectly fine, even you want to make > "Oops, I did it again" jokes about your logged errors. > More generally: You can pick any name you like if the identity of your creation is, well, entirely your creation. What does "Python" mean in terms of programming languages? It means exactly what Guido and the subsequent developers made of it. What's LPC? Originally, "Lars Pensjo C". But it became "this language", if that makes sense. I'm known as "Rosuav". What does that word mean? It means me. Nothing more and nothing less. But when you need the name to evoke some other meaning, you need to be as close as possible to that meaning. Obviously that's never going to be perfect, but the closer you can come, the more useful the name will be. The purest example would be "X meets Y" names, like a Python interface to libcurl called.... pycurl. Nobody has any doubts or disagreements about what that name means! ChrisA From avigross at verizon.net Wed Oct 27 22:15:09 2021 From: avigross at verizon.net (Avi Gross) Date: Wed, 27 Oct 2021 22:15:09 -0400 Subject: walrus with a twist :+= or ... In-Reply-To: References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> Message-ID: <034301d7cba1$a2378640$e6a692c0$@verizon.net> My apologies, again. I got Chris going and although quite humorous, we may want to allow a slew of emoticons! But a serious question is now that we sort of have UNICODE, and even many editors and other programs support it, perhaps it might make sense for some operations in computer languages to make use of them. Some languages might replace something like <- with an arrow symbol and those with special symbols like Inf might use the infinity symbol instead. More importantly, adding new operators might get easier. Some existing languages like APL used overstrikes to create some symbols. Some languages have a built-in extension method such as R that allows you to create arbitrary functions by placing them between % signs as in %>% or %percentile% If Python wanted to add more flexibility than admittedly it already has, then possibly something like I jokingly suggested as a walrus version of := might be doable by just defining some new function bound to a symbol which, when run, is told of the operands on either side. But dreaming aside, from an academician and programmer as well as a lazy bum side of me, it is often perhaps easiest to design a new language practically from scratch with ideas that it completely follow the paradigms you want. SCALA is an example among others. Both a strength and weakness in Python as it has grown is that it does so many things in so many ways as more and more is grafted on. The relatively few existing symbols are overloaded too much so it takes some context to figure out when a : or parenthesis or even % sign means one of multiple things. The recent discussion sort of highlighted how a comma meaning multiple things may be confusing. if we extend a feature. One reasonable design might be to expand the allowed symbols and use them as needed. A colon might be used only one way. If you need a :: operator, it can be a single token and a single character, perhaps clearly having the two parts closer together or one part slightly raised or lowered. A += and >= operator may again be the one symbol version so that + and = always mean the same thing. But it is a tad too late to make an existing language or users on existing keyboards, do this. A language course I am using makes compromises so using a partial pop-up keyboard lets me select characters with special twists like an umlaut rather than showing a plain U or perhaps a :U instead of ? or allowing an SS to be typed instead of ?. When used on character-only scenarios, obviously you let the users mis-spell these ways but that is not an ideal way to learn a language or write in it. -----Original Message----- From: Python-list On Behalf Of Chris Angelico Sent: Wednesday, October 27, 2021 9:11 PM To: Python Subject: Re: walrus with a twist :+= or ... On Thu, Oct 28, 2021 at 11:58 AM Avi Gross via Python-list wrote: > On a serious note, if it was ever considered a good idea, what would > be an acceptable sequence of symbols that might not break or confuse > existing programs and what would we call it? I mean what animal, of course. > > > > What do these look like in some fonts? :+= :-= :*= :/= :%= > What we need is a few more generic operators that can be put together appropriately. For instance, when you need a copy of a list, you can use the "robot face" operator: stuff[:] Perhaps we need some more slice variants. We can already grin: stuff[ :D ] and stick out our tongues: stuff[ :P ] and even gasp in surprise: stuff[ :O ] but the language has an emotional bias towards sadness: stuff[ :( )] since there's no corresponding happiness emoji, nor even ambivalence: stuff[ :| ] However, a wry smile is permitted. stuff[ :\ ] The lack of language support for such a fundamental emotion as happiness is a major flaw and needs to be corrected ASAP. ChrisA -- https://mail.python.org/mailman/listinfo/python-list From arj.python at gmail.com Wed Oct 27 22:44:06 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 Oct 2021 06:44:06 +0400 Subject: Why so fast a web framework? In-Reply-To: References: Message-ID: @Chris @Peter See that famous benchmark https://www.techempower.com/benchmarks/#section=data-r20 Like routinely PHP frameworks appear higher up than py From avigross at verizon.net Wed Oct 27 22:50:56 2021 From: avigross at verizon.net (Avi Gross) Date: Wed, 27 Oct 2021 22:50:56 -0400 Subject: walrus with a twist :+= or ... In-Reply-To: <1432ee00-ed82-372c-6437-056133ce79b1@mrabarnett.plus.com> References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> <033701d7cb97$fa593710$ef0ba530$@verizon.net> <1432ee00-ed82-372c-6437-056133ce79b1@mrabarnett.plus.com> Message-ID: <035601d7cba6$a1da7fe0$e58f7fa0$@verizon.net> Correct, I left out a bit, not wisely. I am trying to remember the last time (outside of classes) I have ever had to use bitwise operators nontrivially and it may have been around 1980 when I had to implement an encryption algorithm. Of course, when I was working in UNIX, I often had to combine bitwise things to specify all kinds on 1-bit flags when say opening a file. So we now have so many candidates FOR COMPLETENESS to add as variants of the Walrus operator, that I might vote to do NONE of them, if anyone ever asked. I do want to remind people though that these operators often serve a purpose in Python as using them means you do not need to specify an argument twice and you can specify some dunder methods that make it more efficient to type: obj += obj2 rather than obj = obj + obj2 So there may be a valid argument, not just about completeness, to implement something BUT as we got along fine before a walrus came along, ... or did we? -----Original Message----- From: Python-list On Behalf Of MRAB Sent: Wednesday, October 27, 2021 9:21 PM To: python-list at python.org Subject: Re: walrus with a twist :+= or ... On 2021-10-28 02:06, Avi Gross via Python-list wrote: > I just realized I left out **= so my apologies. Are there other such > abbreviations and does anyone use them? > You forgot about the bitwise operators: |= &= ^= > -----Original Message----- > From: Python-list > On Behalf Of Avi > Gross via Python-list > Sent: Wednesday, October 27, 2021 8:57 PM > To: python-list at python.org > Subject: walrus with a twist :+= or ... > > I realized that the person seeking completeness in Python may next ask > why the Walrus operator, :=, is not properly extended to include a > whole assortment of allowed assignment operators > > > I mean in normal python programs you are allowed to abbreviate > > x = x + 5 > > with > > x += 5 > > Similarly you have other operators like > > x *= 2 > > And, of course, the constantly used operator: > > x %= 2 > > So how does one extend a walrus operator if they ever decide to give > in and add it to the language just for completeness? > > Sadly, a simple test shows they neglected to use a :+= operator in the > latest: > >>>> (walrus := 2) > > 2 > >>>> walrus > > 2 > >>>> (wallrus :+= 2) > > File "", line 1 > > (wallrus :+= 2) > > ^ > > SyntaxError: invalid syntax > > (Yes, I know how to spell walrus, but making a point.) > > On a serious note, if it was ever considered a good idea, what would > be an acceptable sequence of symbols that might not break or confuse > existing programs and what would we call it? I mean what animal, of course. > > What do these look like in some fonts? :+= :-= :*= :/= :%= > > Or do we not just add a colon in front and make it a tad different as in :=+ > or :+=: or maybe realize the futility of perfection! After all, you can > easily use some functions to get a result such as: > > x := func(x, "+", 5) > > x := func_add(x, 5) > > or many other work-arounds. > > Can we all forget I asked? I am sort of being sarcastic. > -- https://mail.python.org/mailman/listinfo/python-list From Karsten.Hilbert at gmx.net Thu Oct 28 02:49:33 2021 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 28 Oct 2021 08:49:33 +0200 Subject: Aw: Re: The task is to invent names for things In-Reply-To: References: Message-ID: > > I don't know. A mediocre name conveys at least some information, and > > that seems to be better than none. On the other hand it might be just > > enough to lead the reader astray which wouldn't happen with a > > non-sensical name. I was thinking that a nonsensical name might lead readers to go beyond the name when trying to understand code, and would prompt me to improve upon the name upon reading my own code (and having acquired, likely, a better understanding of the concept that's to be named). Karsten From Karsten.Hilbert at gmx.net Thu Oct 28 02:58:30 2021 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 28 Oct 2021 08:58:30 +0200 Subject: Aw: Re: The task is to invent names for things In-Reply-To: References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: > Karsten Hilbert writes: > >ite is the -te form (in some uses like a gerundium) of aru > >(to go, to walk) > > This form, "???", is written with two "t", as "itte", > in many transcriptions to convey the gemination (?) of > the "t". There is, however, "ite", "??", the -te form of > "??" ("iru" - "to be"), which usually is transcribed "ite". I stand corrected, thanks. Not the first time that ite/itte slipped :-/ At any rate, it, eh, is rather malleable to word play. Karsten From antoon.pardon at vub.be Thu Oct 28 03:03:18 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 28 Oct 2021 09:03:18 +0200 Subject: New assignmens ... In-Reply-To: <034401d7cb5f$5b5619e0$12024da0$@verizon.net> References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> <034401d7cb5f$5b5619e0$12024da0$@verizon.net> Message-ID: <83918585-0e37-f785-43d8-2a26350c3695@vub.be> Op 27/10/2021 om 20:20 schreef Avi Gross: > I think anyone who suggests we should separate costs from benefits belongs > securely within the academic world and should remain there. > > Practical things need to be built considering costs. Theoretical things, > sure, cost is not an issue. Seperating costs from benefits doesn't mean costs are not an issue. It means you don't deny de benefits because there are costs. Sure in the end the costs may outweight the benefits but that is still not the same as there being no benefits at all. If you want to weight the costs against the benefits you need to acknowledge both and not start by denying the benefits because you presume they will not outweight the costs. -- Antoon. From arj.python at gmail.com Thu Oct 28 03:13:47 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 Oct 2021 11:13:47 +0400 Subject: walrus with a twist :+= or ... In-Reply-To: <030e01d7cb96$b69ffc30$23dff490$@verizon.net> References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> Message-ID: The proposal is very interesting, my only concern is readability unless a team has a tool check and flag it out as a process. Else i fear one day i'll be seeing =+_+= in Python code. But jokes aside @Avi why would someone want to immediately add a 2 after walrus defining it? in :+=2 Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius From antoon.pardon at vub.be Thu Oct 28 04:04:11 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 28 Oct 2021 10:04:11 +0200 Subject: New assignmens ... In-Reply-To: References: Message-ID: <0998cb6f-6a96-a90f-39ea-78635478e6a0@vub.be> Op 27/10/2021 om 17:05 schreef Christman, Roger Graydon: > I'm going to provide two loop-and-a-half segments to illustrate my interpretation > of this PEP and the purpose of the walrus operator: > > [ first example ] > > Now contrast with this example: > > Without the walrus: > > replay = True > while replay: > play_game() > replay = input("Play again? ") in ['y','Y','yes','Yes'] > > (I think it silly to ask about playing again at first). > > With the walrus: > > replay = None > while replay==None or (replay := input("Play again? ") in ['y','Y','yes','Yes']: > play_game() > > To use the walrus operator here, I have to fabricate a value that would > allow me to bypass the input operation, that cannot be otherwise produced. > I do not find this second version any clearer or more intuitive than the first > (and the PEP did emphasize the value of clarity). But the above is not a one and a half loop. The above is essentially a do loop (repeat loop in pascal), where you have the test at the end of the loop body. But because python doesn't have that loop you have to use a boolean to control the loop that is initialized to True and then later assign that boolean the result of the test which you use to control this loop. Should I think it worth the trouble to rewrite your example, quod non, it would be like below, with that unneeded list. while [ play_game(), input("Play again? ") in ['y', 'Y', 'yes', 'Yes']][-1]: pass -- Antoon Pardon. From arj.python at gmail.com Thu Oct 28 04:09:52 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 Oct 2021 12:09:52 +0400 Subject: FlaskCon 2021: The Last Call Message-ID: Greetings everybody, FlaskCon's CFP closes soon. If you plan to push in some talks, please do so. Don't worry about reviewing and push it in, like it's very simple to get started with and this year might be the last online one. This year it's pre-recorded with optional live QnA. So internet connection should not be an issue. Submit talks: https://flaskcon.com/y/2021/ Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius From hjp-python at hjp.at Thu Oct 28 05:07:53 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 28 Oct 2021 11:07:53 +0200 Subject: walrus with a twist :+= or ... In-Reply-To: <034301d7cba1$a2378640$e6a692c0$@verizon.net> References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> <034301d7cba1$a2378640$e6a692c0$@verizon.net> Message-ID: On 2021-10-27 22:15:09 -0400, Avi Gross via Python-list wrote: > But a serious question is now that we sort of have UNICODE, and even many > editors and other programs support it, perhaps it might make sense for some > operations in computer languages to make use of them. I have thought so since the 1990's. But while the large variety of unicode symbols is great for displaying programs, it is awful for entering them. Keyboards have a limited number of keys (and those are fairly standardized, if a different standard in each country), so you either have to combine several keys or need to pick characters by a different method (e.g. the mouse). Both are cumbersome, shift the attention of the programmer from the algorithm to the mechanics of entry, and are different from editor to editor. I sometimes use Greek letters in variable names. But I do that only for personal projects, not at work. I can't expect my co-workers to find out how enter Greek letters in PyCharm or Visual Studio Code or Notepad++ or whatever they are using and I don't want to do that research myself (I know how to use digraphs im vim, thank you). And we are a small team. Think of the diversity in a large multi-national company ... It might work if the language is tightly integrated with an IDE. Then the designers of the IDE and the designers of the language can work together to make it easy to edit programs. And everyone who uses the language has to use the IDE anyway (because of the tight integration), so "but how do I type that in Notepad++?" is not a concern. But tying together a language to an IDE that tightly will turn away all programmers who are already used to a different IDE (or just plain editor) and want to continue to use that. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From olivbruno8 at gmail.com Thu Oct 28 06:22:44 2021 From: olivbruno8 at gmail.com (Bruno Oliveira) Date: Thu, 28 Oct 2021 11:22:44 +0100 Subject: Python and Flask Book Message-ID: Hello all, I would like to spread the word about a new Python book I have released, on how to develop a web application using Flask and deploying it on Heroku. It's geared more towards beginners or towards anyone who is willing to learn Python and Flask! I would be very glad if you know of people, friends, or colleagues who are interested in learning Python and could spread words about my book: https://brunooliv.gumroad.com/l/cookpythonbook Best regards, Bruno From jon+usenet at unequivocal.eu Thu Oct 28 05:53:53 2021 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 28 Oct 2021 09:53:53 -0000 (UTC) Subject: New assignmens ... References: <87ilxhudmf.fsf@nightsong.com> Message-ID: On 2021-10-28, Paul Rubin wrote: > Chris Angelico writes: >> But it all depends on the exact process being done, which is why I've >> been asking for real examples. > > My most frequent use case for walrus is so common that I have sometimes > implemented a special class for it: > > if g := re.search(pat1, text): > hack(g.group(1)) > elif g := re.search(pat2, text): > smack(g.group(2), "foo") > ... > > It's way messier if you have to separate the assignment and test the old > way. That said, I'm still on Python 3.7 so I haven't yet gotten to use > walrus or the new match statement (or is it expression). > > I do feel surprised that you can't use an arbitrary lvalue (to use C > terminology) on the lhs of a walrus. That seems downright weird to me. > But, I haven't studied the PEP so I don't know if there was a particular > rationale. Well, that's what I was saying: there's no rationale - the limitation is not even mentioned, let alone explained. From cspealma at redhat.com Thu Oct 28 12:45:42 2021 From: cspealma at redhat.com (Calvin Spealman) Date: Thu, 28 Oct 2021 12:45:42 -0400 Subject: Why so fast a web framework? In-Reply-To: References: Message-ID: Who cares? On Wed, Oct 27, 2021 at 10:47 PM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > @Chris @Peter > > > See that famous benchmark > > https://www.techempower.com/benchmarks/#section=data-r20 > > Like routinely PHP frameworks appear higher up than py > -- > https://mail.python.org/mailman/listinfo/python-list > > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER calvin.spealman at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From arj.python at gmail.com Thu Oct 28 12:49:27 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Thu, 28 Oct 2021 20:49:27 +0400 Subject: Why so fast a web framework? In-Reply-To: References: Message-ID: Me Like why exactly is that the case, i would not be surprised for rust, C, CPP etc But as to where the difference comes for two comparatively similar langs. Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius From avigross at verizon.net Thu Oct 28 13:23:46 2021 From: avigross at verizon.net (Avi Gross) Date: Thu, 28 Oct 2021 13:23:46 -0400 Subject: The task is to invent names for things In-Reply-To: References: Message-ID: <004801d7cc20$90f8c040$b2ea40c0$@verizon.net> Names can be taken too far as the same variable may have different connotations in one place than another. Say I am counting how many of something and incrementing variable HowMany as I go along and initialized to zero. Then I want to test if I have any and instead of: if (HowMany > 0) I decide to be cute and depend on the truthiness of HowMany like: if (HowMany) The latter is a tad hard to parse for some people and if it had been named WeHaveAny then the code would sort of make sense: if (WeHaveAny) Somewhere else in the code some other names might make sense and make the program easier to read. So, the obvious solution is to ask the language, like Python, to allow variables that are synonyms. In languages with pointers, this can often be done fairly easily. In some languages with some optimizations, it can be dangerous as some copies of this kind can later be changed to an actual copy when the underlying data changes. So, since at the moment you might not be able to do this: HowMany = 0 alias HowMany WeHaveAny Then if this feature matters to you, you could cautiously write code that declares a second variable and copies either the current value of the first or a Boolean true/false. I am sure many of us (meaning me) have often named a variable and later reconsidered once we saw the role it plays in various parts of the program and had to go back and change everything. As other have noted, it is not a trivial task and really good names often end up being really long names which are also a pain especially when other really long names start with the same characters. Compilers don't care but humans reading the code may give up! Worse, many times the code consists of longer combinations and trying to keep within reasonable (printable) line lengths gets hard. MyHumoungousDictionaryContainingElectionResults[SomeCountyInSomeStateOfTheUS ] = MyHumoungousDictionaryContainingElectionResults[SomeCountyInSomeStateOfTheUS ] + TheOfficialCertifiedVoteCountOfThisRegion -----Original Message----- From: Python-list On Behalf Of Karsten Hilbert Sent: Thursday, October 28, 2021 2:50 AM Cc: python-list at python.org Subject: Aw: Re: The task is to invent names for things > > I don't know. A mediocre name conveys at least some information, and > > that seems to be better than none. On the other hand it might be > > just enough to lead the reader astray which wouldn't happen with a > > non-sensical name. I was thinking that a nonsensical name might lead readers to go beyond the name when trying to understand code, and would prompt me to improve upon the name upon reading my own code (and having acquired, likely, a better understanding of the concept that's to be named). Karsten -- https://mail.python.org/mailman/listinfo/python-list From avigross at verizon.net Thu Oct 28 13:36:10 2021 From: avigross at verizon.net (Avi Gross) Date: Thu, 28 Oct 2021 13:36:10 -0400 Subject: New assignmens ... In-Reply-To: <83918585-0e37-f785-43d8-2a26350c3695@vub.be> References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> <034401d7cb5f$5b5619e0$12024da0$@verizon.net> <83918585-0e37-f785-43d8-2a26350c3695@vub.be> Message-ID: <004a01d7cc22$4c055050$e40ff0f0$@verizon.net> Antoon, You keep beating a dead horse. NOBODY denies there are benefits to suggestions like the one we are describing. It is a logical fallacy to keep arguing this way. And nobody (meaning me) suggests costs are a dominant factor in decisions no matter the benefits. The realistic suggestion is to not only weight costs and benefits for one proposal but for all reasonable proposals and then choose. I have no idea what the actual cost of changing the parser is. It may be trivial or very nontrivial. I do not know if the actual chosen change, from a range of possible implementations, will leave the speed of typical programs untouched or will add lots of overhead for all programs including the ones not using this feature. Nor do I know how many existing features might clash with the choice of implementation and need to be changed to resolve them or face lots of bug reports later. So what I and others have said here is not based completely on known and measured facts. But before approving a proposal, some analysis and estimates must be made including a decision to just cancel any work if it over-runs targeted costs of various kinds. Now for a dumb question. Many languages allow a form of setting a variable to a value like: assign(var, 5+sin(x)) If we had a function that then returned var or the value of var, cleanly, then would that allow an end run on the walrus operator? if (assign(sign, 5+sin(x)) <= assign(cosign, 5+cos(x))) ? Not necessarily pretty and I am sure there may well be reasons it won?t work, but I wonder if it will work in more places than the currently minimal walrus operator. From: Antoon Pardon Sent: Thursday, October 28, 2021 3:03 AM To: Avi Gross ; python-list at python.org Subject: Re: New assignmens ... Op 27/10/2021 om 20:20 schreef Avi Gross: I think anyone who suggests we should separate costs from benefits belongs securely within the academic world and should remain there. Practical things need to be built considering costs. Theoretical things, sure, cost is not an issue. Seperating costs from benefits doesn't mean costs are not an issue. It means you don't deny de benefits because there are costs. Sure in the end the costs may outweight the benefits but that is still not the same as there being no benefits at all. If you want to weight the costs against the benefits you need to acknowledge both and not start by denying the benefits because you presume they will not outweight the costs. -- Antoon. From rosuav at gmail.com Thu Oct 28 13:56:36 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Oct 2021 04:56:36 +1100 Subject: New assignmens ... In-Reply-To: <004a01d7cc22$4c055050$e40ff0f0$@verizon.net> References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> <034401d7cb5f$5b5619e0$12024da0$@verizon.net> <83918585-0e37-f785-43d8-2a26350c3695@vub.be> <004a01d7cc22$4c055050$e40ff0f0$@verizon.net> Message-ID: On Fri, Oct 29, 2021 at 4:37 AM Avi Gross via Python-list wrote: > Now for a dumb question. Many languages allow a form of setting a variable to a value like: > > assign(var, 5+sin(x)) > > If we had a function that then returned var or the value of var, cleanly, then would that allow an end run on the walrus operator? > > if (assign(sign, 5+sin(x)) <= assign(cosign, 5+cos(x))) ? > > Not necessarily pretty and I am sure there may well be reasons it won?t work, but I wonder if it will work in more places than the currently minimal walrus operator. For that to work, the language needs one of three things: 1) A way to pass an lvalue to a function, which it can then change 2) A form of pointer or reference (same thing, but you'd adorn it at the call site - eg in C, you can write &var) 3) Magical compiler support for the assign function, so it isn't really a function, just something that looks like one. (Are there any other ways? I can't think of any.) Python currently doesn't have any of those, so you'd have to pick which one you're advocating for and show how it would be beneficial. Personally, I'm dubious of all three, but I would be most interested in the second option and its consequences. ChrisA From martinp.dipaola at gmail.com Thu Oct 28 14:03:30 2021 From: martinp.dipaola at gmail.com (Martin Di Paola) Date: Thu, 28 Oct 2021 18:03:30 +0000 Subject: The task is to invent names for things In-Reply-To: References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: <20211028180330.jjg73g6wx56zg4hf@gmail.com> IMHO, I prefer really weird names. For example if I'm not sure how to name a class that I'm coding, I name it like XXXYYY (literally). Really ugly. This is a way to avoid the so called "naming paralysis". Once I finish coding the class I look back and it should be easy to see "what it does" and from there, the correct name. If the "what it does" results in multiple things I refactor it, splitting it into two or more pieces and name each separately. Some people prefer using more generic names like "Manager", "Helper", "Service" but those names are problematic. Yes, they fit in any place but that's the problem. If I'm coding a class and I name it as "FooHelper", I may not realize later that the class is doing too many things (unrelated things), because "it is a helper". The thing gets wrong with the time; I bet that most of us saw a "Helper" class with thousands of lines (~5000 lines was my record) that just grows over time. On Wed, Oct 27, 2021 at 12:41:56PM +0200, Karsten Hilbert wrote: >Am Tue, Oct 26, 2021 at 11:36:33PM +0000 schrieb Stefan Ram: > >> xyzzy = lambda x: 2 * x >> >> . Sometimes, this can even lead to "naming paralysis", where >> one thinks excessively long about a good name. To avoid this >> naming paralysis, one can start out with a mediocre name. In >> the course of time, often a better name will come to one's mind. > >In that situation, is it preferable to choose a nonsensical >name over a mediocre one ? > >Karsten >-- >GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B >-- >https://mail.python.org/mailman/listinfo/python-list From avigross at verizon.net Thu Oct 28 14:52:26 2021 From: avigross at verizon.net (Avi Gross) Date: Thu, 28 Oct 2021 14:52:26 -0400 Subject: walrus with a twist :+= or ... In-Reply-To: References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> <034301d7cba1$a2378640$e6a692c0$@verizon.net> Message-ID: <009a01d7cc2c$f363a4a0$da2aede0$@verizon.net> Good points, Peter. Although we are discussing Python, I think it would be reasonable to look a bit more broadly. Ages ago, IBM used a different encoding than ASCII called EBCDIC (Extended Binary Coded Decimal Interchange Code ) which let them use all 8 bits and thus add additional symbols. ? ? ? So if you chose a specific set of symbols as a subset of UNICODE and declared it to be PROGRAMMER symbols, it might be possible to provide special keyboards that had something like the numeric keypad with a few more symbols or in the place where the F1 keys are or wherever. All programming languages that wished to use the symbols might be expected to mainly, or exclusively, only use these symbols for unary or binary operators or other purposes. Look at one of the annoyances in Python (and similar in other languages) where the matched symbols that come in left and right versions are overused. () is used in oodles of contexts. So is {} and []. We do not use <> as matching pairs because of other meanings. So a python dictionary and a python set use the same general notation but can be disambiguated by the contents sometimes. And I note that single and double quotes are currently unique while other programs like WORD make them in pairs with a clear open and close quote slanted differently. Would we be better able to write clear constructs if our programs also clearly marked beginning and ends of text in some contexts, perhaps allowing even things like nested text? I have no idea of details here and clearly too many symbols is as bad as too few. I have taken lots of courses in topics like mathematics and physics where I was bombarded by all kinds of notations and symbols that forced me to learn the Greek and other alphabets so I could sort of pronounce them in my mind, as well as funny "script" letters and all kinds of invented symbols including many you now find in a wingding section. So having an assortment of these be the same as used by programmers might be good for others. Think not just Greek letters that would also give you pi, but the Integral sign the symbol used for partial derivatives and of course you need an aleph from Hebrew :=) Is there a reasonable extension to a keyboard that might be reasonable, perhaps with an accommodation to those without such a keyboard so that entering some sequence gets it converted into what you want on the screen but more mnemonic than 0X234f ?? Now once there was some sort of standard developed, all IDE for all languages might have the option to adopt it. Of course, some symbols would not be used or allowed in a particular language, albeit if they were all otherwise valid UNICODE symbols, would be allowed in other contexts such as within text or perhaps in variable names. But back to python, I am not suggesting that it would be wise to modify much of what exists even if this was available. Sets and Dictionaries might remain as is, or there might be a second optional way to use them with new symbols. I happen to be one of the people who reads/writes/speaks in multiple languages. Many decades ago I was forced to switch encodings carefully to say ISO-8859-1 (Latin 1) if I wanted to write properly in German but Hungarian required ISO 8859-2 and Hebrew needed ISO 8859-8 and Japanese needed others like Shift JIS. For a while, much of my work included being able to take in text and perform conversions and it was a royal pain. If everyone used a small set of common encoding, as in UNICODE, things get easier from one perspective. What I am suggesting is not as drastic but that we choose a set of symbols that are clear and unambiguous and not huge but larger than what we have now and gradually migrate to using more of it. Obviously brand new languages could be designed to use it and existing languages MIGHT use it more for new features and extensions. So anyone know if anything like I am describing (or something much better) is being looked at? -----Original Message----- From: Python-list On Behalf Of Peter J. Holzer Sent: Thursday, October 28, 2021 5:08 AM To: python-list at python.org Subject: Re: walrus with a twist :+= or ... On 2021-10-27 22:15:09 -0400, Avi Gross via Python-list wrote: > But a serious question is now that we sort of have UNICODE, and even > many editors and other programs support it, perhaps it might make > sense for some operations in computer languages to make use of them. I have thought so since the 1990's. But while the large variety of unicode symbols is great for displaying programs, it is awful for entering them. Keyboards have a limited number of keys (and those are fairly standardized, if a different standard in each country), so you either have to combine several keys or need to pick characters by a different method (e.g. the mouse). Both are cumbersome, shift the attention of the programmer from the algorithm to the mechanics of entry, and are different from editor to editor. I sometimes use Greek letters in variable names. But I do that only for personal projects, not at work. I can't expect my co-workers to find out how enter Greek letters in PyCharm or Visual Studio Code or Notepad++ or whatever they are using and I don't want to do that research myself (I know how to use digraphs im vim, thank you). And we are a small team. Think of the diversity in a large multi-national company ... It might work if the language is tightly integrated with an IDE. Then the designers of the IDE and the designers of the language can work together to make it easy to edit programs. And everyone who uses the language has to use the IDE anyway (because of the tight integration), so "but how do I type that in Notepad++?" is not a concern. But tying together a language to an IDE that tightly will turn away all programmers who are already used to a different IDE (or just plain editor) and want to continue to use that. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" From cspealma at redhat.com Thu Oct 28 15:15:53 2021 From: cspealma at redhat.com (Calvin Spealman) Date: Thu, 28 Oct 2021 15:15:53 -0400 Subject: Why so fast a web framework? In-Reply-To: References: Message-ID: I don't think there's anything meaningful being compared in that so-called "benchmark" at all. There is no evidence that its worth even the smallest bit of attention. You want to write a web service? Do it. Use Python or PHP, or whatever you prefer. Do you think your service is "slow"? You won't know until you measure *your* service and compare that against actual requirements you have. There is no context here to discuss performance and performance can *only* be discussed in a context. "SQL queries per second" is pointless. Why are you making so many SQL queries? If you want your service to be more efficient, make fewer queries! On Thu, Oct 28, 2021 at 12:49 PM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > Me > > Like why exactly is that the case, i would not be surprised for rust, C, > CPP etc > But as to where the difference comes for two comparatively similar langs. > > Kind Regards, > > Abdur-Rahmaan Janhangeer > about | blog > > github > Mauritius > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER calvin.spealman at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From rosuav at gmail.com Thu Oct 28 15:23:42 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Oct 2021 06:23:42 +1100 Subject: walrus with a twist :+= or ... In-Reply-To: <009a01d7cc2c$f363a4a0$da2aede0$@verizon.net> References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> <034301d7cba1$a2378640$e6a692c0$@verizon.net> <009a01d7cc2c$f363a4a0$da2aede0$@verizon.net> Message-ID: On Fri, Oct 29, 2021 at 5:53 AM Avi Gross via Python-list wrote: > Is there a reasonable extension to a keyboard that might be reasonable, > perhaps with an accommodation to those without such a keyboard so that > entering some sequence gets it converted into what you want on the screen > but more mnemonic than 0X234f ?? It's called Compose key sequences and they're supported by every X11-based system, plus Windows and Mac OS if you set them up. ChrisA From bursejan at gmail.com Thu Oct 28 14:57:49 2021 From: bursejan at gmail.com (Mostowski Collapse) Date: Thu, 28 Oct 2021 11:57:49 -0700 (PDT) Subject: Get a Joke in Python In-Reply-To: <406a1138-3c2c-47f5-89c8-364460ac7d20n@googlegroups.com> References: <406a1138-3c2c-47f5-89c8-364460ac7d20n@googlegroups.com> Message-ID: QA engineer walks into a bar. Orders a beer. Orders 0 beers. Orders 999999999 beers. Orders a lizard. Orders -1 beers. Orders a sfdeljknesv. LoL joel.d... at gmail.com schrieb am Mittwoch, 27. Oktober 2021 um 21:00:29 UTC+2: > Get a Joke in Python. Pyjokes - is a python library / module for one line joke program based on programmers. You can get funny one-liner random jokes at every run also available in following " languages " & " categories ". Supported Languages By Pyjokes English ? ?en? Spanish ? ?es? Italian ? ?it? German ? ?de? Galician ? ?gl? Basque ? ?eu? Categories Included In Pyjokes For geeky jokes -?neutral? (It is chosen by default) For Chris Norris Jokes ? ?chuck?. If you want all type of jokes ? ?all? There is one more category known as ?twister? which only works for the German Language (?de?) and mostly includes tongue twister. Read the documentation available on https://pyjok.es for more info. :::Lets Code::: Install pyjokes if you haven't pip install pyjokes This Program will give you one-liner Joke #pip install pyjokes # importing module i > [Read More...] > > https://pysnakeblog.blogspot.com From rosuav at gmail.com Thu Oct 28 15:28:33 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Oct 2021 06:28:33 +1100 Subject: Why so fast a web framework? In-Reply-To: References: Message-ID: On Fri, Oct 29, 2021 at 6:17 AM Calvin Spealman wrote: > > I don't think there's anything meaningful being compared in that so-called > "benchmark" at all. There is no evidence that its worth even the smallest > bit of attention. > > You want to write a web service? Do it. Use Python or PHP, or whatever you > prefer. Do you think your service is "slow"? You won't know until you > measure *your* service and compare that against actual requirements you > have. There is no context here to discuss performance and performance can > *only* be discussed in a context. > > "SQL queries per second" is pointless. Why are you making so many SQL > queries? If you want your service to be more efficient, make fewer queries! > In my experience, using PostgreSQL, a more viable metric is "transactions per second" - throughput is very similar regardless of the number of queries per transaction. As a general rule, a web service should be doing at most one transaction per query, so throughput in requests per second will be equal to transactions per second plus however many can be returned from cache (which, for some applications, will be zero). Sadly, many people still bow down in worship at the little tin god, while completely ignoring the fact that proper transactional integrity will improve *business* performance by, yaknow, not losing data... and it still often works out faster than doing things wrongly. ChrisA From rosuav at gmail.com Thu Oct 28 18:34:56 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Oct 2021 09:34:56 +1100 Subject: Get a Joke in Python In-Reply-To: References: <406a1138-3c2c-47f5-89c8-364460ac7d20n@googlegroups.com> Message-ID: On Fri, Oct 29, 2021 at 7:31 AM Mostowski Collapse wrote: > > QA engineer walks into a bar. Orders a beer. Orders 0 beers. > Orders 999999999 beers. Orders a lizard. Orders -1 beers. > Orders a sfdeljknesv. > Orders 1 ???? and is served a ????????. QA engineer sighs "not again". ChrisA From avigross at verizon.net Thu Oct 28 19:12:16 2021 From: avigross at verizon.net (Avi Gross) Date: Thu, 28 Oct 2021 19:12:16 -0400 Subject: The task is to invent names for things In-Reply-To: References: <004801d7cc20$90f8c040$b2ea40c0$@verizon.net> Message-ID: <00c501d7cc51$403dfae0$c0b9f0a0$@verizon.net> Stefan, I choose not to get involved in a discussion about arbitrary naming rules as many languages and programmers have their own ideas and preferences and rules. My examples were EXAMPLES and the actual names are irrelevant. Feel free not to use them and I assure you I have no plans to either. My POINT was that people choose names as being descriptive in many ways, often unique to themselves or to their organizations. A name that may be considered quite useful and explanatory in one context is not in another. Specifically, names chosen using American English may mean little if looked at by programmers elsewhere or if they are chosen with a sense of humor or the like, may not make sense to those who are not in on the ideas involved. Naming a variable PINK (in any combination of upper or lower case you feel like may make you think it fits when using it to count Breast Cancer patients but many will have no idea why you chose that. I strenuously disagree with many things you quote as being obviously true. Nonsense! Programs need whatever number of variables they need. There is no reason you must reuse the same variable of "i" or "index" for every loop nor why it must be different every time. Nor must names lengths be determined by the length of scopes. You are quoting, presumably, from some document outlining what a corporation or University or such are doing to try to get a consistency across their programmers. Fine, I have seen multiple CONTRADICTORY such declarations and it is often a matter of taste. In some languages I use periods in longer variable names and in others I use underscores and many times I use camelCase, Hungarian notation and others. The compiler and interpreter generally do NOT care. To bring this back to python, does it have any serious rules or informal ones as compared to others? I have seen places that suggest constants be all CAPS and Classes should be capitalized and regular variables never capitalized and endless variations on such themes. I have seen places they suggest adding parts to names such as the units so you have xxxDollars versus xxxFeet or where they want each variable to contain a similar suffix (or prefix) specifying the type of the object such as int or char or objectXY as one way to make things clearer or help prevent errors. There are MANY schools of thought and I suggest no one right way. My thought was that no matter what methodology for naming you have, it may not work quite well if the same variable is used in contexts ranging from does it currently exist, how much does it hold, is it "true" as in non-empty, or the value it has when switched to another form of measurement. It is common often to encapsulate something into an object and then use instance variables or functions to address it different ways. So an object called incomedata might be used as incomedata.count in one context and incomedata.nonempty() in another. That is not the same as my talking about synonyms. And note many languages allow you to create somewhat dynamic synonyms such as a view of a subset of something like an array using another variable and allowing it to represent the current state of the main data structure or even change selected parts. It is not at all a foreign concept to have multiple names point to the same things. Often, it helps make the code clearer. -----Original Message----- From: Python-list On Behalf Of Stefan Ram Sent: Thursday, October 28, 2021 2:07 PM To: python-list at python.org Subject: Re: The task is to invent names for things Supersedes: [corrected two typos] "Avi Gross" writes: >if (WeHaveAny) |Function names should be lowercase, with words separated by underscores |as necessary to improve readability. |Variable names follow the same convention as function names. PEP 8 (2019) The name should not be "optimized" for a certain use case (as for the use in an if expression) only. "We", "have", and "any" carry little information. A name should pack as much information as possible in as least characters as possible. So, for me, it'd be something like: if word_count: . >So, the obvious solution is to ask the language, like Python, to allow >variables that are synonyms. Programs already have too many names in them. There is no need to add even more, especially when they are equivalent, and the average human can only hold 7 ? 2 objects (like names) in his short- term memory. >really good names often end up being really long names If they are really long, they are not really good, /except/ when they have a really large scope. Names for a small scope can and should be short, names for a large scope may be longer. Some very short names have traditional meanings and are ok when used as such: for i in range( 10 ): . And, as a "golden rule" for refactoring, I'd say: When you see: i = 0 # word count , then remove the comment and rename "i" to "word_count"! -- https://mail.python.org/mailman/listinfo/python-list From avigross at verizon.net Thu Oct 28 19:48:06 2021 From: avigross at verizon.net (Avi Gross) Date: Thu, 28 Oct 2021 19:48:06 -0400 Subject: walrus with a twist :+= or ... In-Reply-To: References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> <034301d7cba1$a2378640$e6a692c0$@verizon.net> <009a01d7cc2c$f363a4a0$da2aede0$@verizon.net> Message-ID: <016301d7cc56$419449d0$c4bcdd70$@verizon.net> Thank, Chris. I found and installed one from here: https://github.com/samhocevar/wincompose My right ALT key now lets me type in all kinds of nonsense like ? and ? and ? and ?0 and ? and ? and ? and ?and although :- makes ? I see := makes ? which is just a longer equals sign. Not sure this mailing list allows this stuff, so if your mailer does not show it, never mind. Now I have to locate the list of available sequences as the built-in does not show many I want to se and I have already guessed some! And, yes, as long as the list of additional program symbols is easily available, that should do even on standard keyboards. ? -----Original Message----- From: Python-list On Behalf Of Chris Angelico Sent: Thursday, October 28, 2021 3:24 PM To: Python Subject: Re: walrus with a twist :+= or ... On Fri, Oct 29, 2021 at 5:53 AM Avi Gross via Python-list wrote: > Is there a reasonable extension to a keyboard that might be > reasonable, perhaps with an accommodation to those without such a > keyboard so that entering some sequence gets it converted into what > you want on the screen but more mnemonic than 0X234f ?? It's called Compose key sequences and they're supported by every X11-based system, plus Windows and Mac OS if you set them up. ChrisA -- https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Thu Oct 28 19:17:44 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 29 Oct 2021 12:17:44 +1300 Subject: Get a Joke in Python In-Reply-To: References: <406a1138-3c2c-47f5-89c8-364460ac7d20n@googlegroups.com> Message-ID: On 29/10/21 11:34 am, Chris Angelico wrote: > On Fri, Oct 29, 2021 at 7:31 AM Mostowski Collapse wrote: >> >> QA engineer walks into a bar. Orders a beer. Orders 0 beers. >> Orders 999999999 beers. Orders a lizard. Orders -1 beers. >> Orders a sfdeljknesv. >> > > Orders 1 ???? and is served a ????????. QA engineer sighs "not again". Orders NaN beers and -- Greg From grant.b.edwards at gmail.com Thu Oct 28 20:33:11 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 Oct 2021 17:33:11 -0700 (PDT) Subject: walrus with a twist :+= or ... References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> <034301d7cba1$a2378640$e6a692c0$@verizon.net> <009a01d7cc2c$f363a4a0$da2aede0$@verizon.net> <016301d7cc56$419449d0$c4bcdd70$@verizon.net> Message-ID: <617b4147.1c69fb81.4a6d0.6d55@mx.google.com> On 2021-10-28, Avi Gross via Python-list wrote: > I see := makes ? which is just a longer equals sign. On my screen it's an assignment operator that looks like := only a bit smaller. > Not sure this mailing list allows this stuff, so if your mailer does > not show it, never mind. Everything renders fine for me. From jon+usenet at unequivocal.eu Thu Oct 28 21:00:39 2021 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Fri, 29 Oct 2021 01:00:39 -0000 (UTC) Subject: Get a Joke in Python References: <406a1138-3c2c-47f5-89c8-364460ac7d20n@googlegroups.com> Message-ID: On 2021-10-28, Greg Ewing wrote: > On 29/10/21 11:34 am, Chris Angelico wrote: >> On Fri, Oct 29, 2021 at 7:31 AM Mostowski Collapse wrote: >>> QA engineer walks into a bar. Orders a beer. Orders 0 beers. >>> Orders 999999999 beers. Orders a lizard. Orders -1 beers. >>> Orders a sfdeljknesv. >>> >> >> Orders 1 ???? and is served a ????????. QA engineer sighs "not again". > > Orders NaN beers and The variant of this I saw the other day follows the above and after the QA engineer has ordered various things it follows: A real customer walks into the bar and doesn't order anything, but asks where the toilets are. The bar explodes in flames. From rosuav at gmail.com Thu Oct 28 22:13:43 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Oct 2021 13:13:43 +1100 Subject: Get a Joke in Python In-Reply-To: References: <406a1138-3c2c-47f5-89c8-364460ac7d20n@googlegroups.com> Message-ID: On Fri, Oct 29, 2021 at 12:29 PM Jon Ribbens via Python-list wrote: > > On 2021-10-28, Greg Ewing wrote: > > On 29/10/21 11:34 am, Chris Angelico wrote: > >> On Fri, Oct 29, 2021 at 7:31 AM Mostowski Collapse wrote: > >>> QA engineer walks into a bar. Orders a beer. Orders 0 beers. > >>> Orders 999999999 beers. Orders a lizard. Orders -1 beers. > >>> Orders a sfdeljknesv. > >>> > >> > >> Orders 1 ???? and is served a ????????. QA engineer sighs "not again". > > > > Orders NaN beers and > > The variant of this I saw the other day follows the above and after > the QA engineer has ordered various things it follows: > > A real customer walks into the bar and doesn't order anything, > but asks where the toilets are. > > The bar explodes in flames. ... and the owner just bulldozes the bar, builds a new one on the same spot, and pretends nothing happened. ChrisA From drsalists at gmail.com Fri Oct 29 00:47:27 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 28 Oct 2021 21:47:27 -0700 Subject: Why so fast a web framework? In-Reply-To: References: Message-ID: I care, and I suspect the OP does too. Usually machine time doesn't matter as much as developer time, but API overhead Can matter - especially on a busy server. I wonder if Pypy would do any better? Or Micropython? Or Cython? CPython != Python. Sometimes this group reminds me of a certain large company I worked for. If they didn't have a solution addressing a problem, they'd pretend it didn't matter and belittle anyone who questioned that version of reality. On Thu, Oct 28, 2021 at 9:46 AM Calvin Spealman wrote: > Who cares? > > On Wed, Oct 27, 2021 at 10:47 PM Abdur-Rahmaan Janhangeer < > arj.python at gmail.com> wrote: > > > @Chris @Peter > > > > > > See that famous benchmark > > > > https://www.techempower.com/benchmarks/#section=data-r20 > > > > Like routinely PHP frameworks appear higher up than py > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > > > -- > > CALVIN SPEALMAN > > SENIOR QUALITY ENGINEER > > calvin.spealman at redhat.com M: +1.336.210.5107 > [image: https://red.ht/sig] > TRIED. TESTED. TRUSTED. > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Fri Oct 29 00:52:17 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 29 Oct 2021 15:52:17 +1100 Subject: Why so fast a web framework? In-Reply-To: References: Message-ID: On Fri, Oct 29, 2021 at 3:49 PM Dan Stromberg wrote: > > I care, and I suspect the OP does too. Usually machine time doesn't matter > as much as developer time, but API overhead Can matter - especially on a > busy server. > > I wonder if Pypy would do any better? Or Micropython? Or Cython? > > CPython != Python. > > Sometimes this group reminds me of a certain large company I worked for. > If they didn't have a solution addressing a problem, they'd pretend it > didn't matter and belittle anyone who questioned that version of reality. > That's not strictly true; what's happening here is that someone's published a cool-looking bar graph but nobody knows what it really means. I don't feel the need to delve into everyone's benchmarks to explain why Python is purportedly worse. If someone uses those kinds of numbers to decide which programming language to use, they have bigger problems. ChrisA From antoon.pardon at vub.be Fri Oct 29 02:15:51 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 29 Oct 2021 08:15:51 +0200 Subject: New assignmens ... In-Reply-To: <004a01d7cc22$4c055050$e40ff0f0$@verizon.net> References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> <034401d7cb5f$5b5619e0$12024da0$@verizon.net> <83918585-0e37-f785-43d8-2a26350c3695@vub.be> <004a01d7cc22$4c055050$e40ff0f0$@verizon.net> Message-ID: Op 28/10/2021 om 19:36 schreef Avi Gross via Python-list: > Antoon, > > > You keep beating a dead horse. NOBODY denies there are benefits to suggestions like the one we are describing. It is a logical fallacy to keep arguing this way. Please point to the specific logical falacy you think I am commiting. Don't hand wave about what I supposedly am doing. > And nobody (meaning me) suggests costs are a dominant factor in decisions no matter the benefits. The realistic suggestion is to not only weight costs and benefits for one proposal but for all reasonable proposals and then choose. So what if *you* don't suggest that. Others have. Then when I responded to those with a remark about seperating costs and benefits, you budded in with the assertion that those who suggest seperating benefits and cost belong in the accademic world because you understood that remark as implying costs are not as issue. I then explain you misunderdood en now you come with the above. Maybe you should be more aware of the history of a thread before coming with this kind of statements. -- Antoon Pardon From arj.python at gmail.com Fri Oct 29 02:54:17 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 29 Oct 2021 10:54:17 +0400 Subject: Why so fast a web framework? In-Reply-To: References: Message-ID: Well, They don't choose languages per se but choose frameworks based on that and ... by virtue of that choose languages. Like just to get faster web services. The benchmark is pretty much referred to in the Python world, web side like https://www.starlette.io/ "Independent TechEmpower benchmarks show Starlette applications running under Uvicorn as one of the fastest Python frameworks available. (*)" https://github.com/tiangolo/fastapi ... (thanks to Starlette and Pydantic). One of the fastest Python frameworks available. Both with links to the benchmarks. So, while non-web folks don't care, web folks seem to care. And as a web someone i wanted to know why is that so. Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius From hjp-python at hjp.at Fri Oct 29 03:56:05 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 29 Oct 2021 09:56:05 +0200 Subject: walrus with a twist :+= or ... In-Reply-To: <016301d7cc56$419449d0$c4bcdd70$@verizon.net> References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> <034301d7cba1$a2378640$e6a692c0$@verizon.net> <009a01d7cc2c$f363a4a0$da2aede0$@verizon.net> <016301d7cc56$419449d0$c4bcdd70$@verizon.net> Message-ID: On 2021-10-28 19:48:06 -0400, Avi Gross via Python-list wrote: > My right ALT key now lets me type in all kinds of nonsense like ? and > ? and ? and ?0 and ? and ? and ? and ?and although :- makes ? I see > := makes ? which is just a longer equals sign. Ah, yes. That's another problem with using a large number of characters: Some of them will be visually very similar, especially with monospaced fonts. I'm not getting any younger and with my preferred font (which is quite small) I already have to squint to distinguish between : and ; or between () and {}. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From bschollnick at schollnick.net Fri Oct 29 06:38:57 2021 From: bschollnick at schollnick.net (Benjamin Schollnick) Date: Fri, 29 Oct 2021 06:38:57 -0400 Subject: Why so fast a web framework? In-Reply-To: References: Message-ID: <6D759514-74E6-4FBD-9ED3-F4A93044E4ED@schollnick.net> >> Sometimes this group reminds me of a certain large company I worked for. >> If they didn't have a solution addressing a problem, they'd pretend it >> didn't matter and belittle anyone who questioned that version of reality. >> > > That's not strictly true; what's happening here is that someone's > published a cool-looking bar graph but nobody knows what it really > means. I don't feel the need to delve into everyone's benchmarks to > explain why Python is purportedly worse. If someone uses those kinds > of numbers to decide which programming language to use, they have > bigger problems. If you dig a bit, the benchmark is scary? As in stupid-scary. It consists of, 7 tests, and then a composite score is generated: JSON Serialization - In this test, each response is a JSON serialization of a freshly-instantiated object that maps the key message to the value Hello, World! Single Query - In this test, each request is processed by fetching a single row from a simple database table. That row is then serialized as a JSON response. Multiple Queries - In this test, each request is processed by fetching multiple rows from a simple database table and serializing these rows as a JSON response. The test is run multiple times: testing 1, 5, 10, 15, and 20 queries per request. All tests are run at 512 concurrency. Cached Queries - In this test, each request is processed by fetching multiple cached objects from an in-memory database (the cache having been populated from a database table either as needed or prior to testing) and serializing these objects as a JSON response. The test is run multiple times: testing 1, 5, 10, 15, and 20 cached object fetches per request. All tests are run at 512 concurrency. Conceptually, this is similar to the multiple-queries test except that it uses a caching layer. Fortunes - In this test, the framework's ORM is used to fetch all rows from a database table containing an unknown number of Unix fortune cookie messages (the table has 12 rows, but the code cannot have foreknowledge of the table's size). An additional fortune cookie message is inserted into the list at runtime and then the list is sorted by the message text. Finally, the list is delivered to the client using a server-side HTML template. The message text must be considered untrusted and properly escaped and the UTF-8 fortune messages must be rendered properly. Whitespace is optional and may comply with the framework's best practices. data Updates - This test exercises database writes. Each request is processed by fetching multiple rows from a simple database table, converting the rows to in-memory objects, modifying one attribute of each object in memory, updating each associated row in the database individually, and then serializing the list of objects as a JSON response. The test is run multiple times: testing 1, 5, 10, 15, and 20 updates per request. Note that the number of statements per request is twice the number of updates since each update is paired with one query to fetch the object. All tests are run at 512 concurrency. The response is analogous to the multiple-query test. plain text - In this test, the framework responds with the simplest of responses: a "Hello, World" message rendered as plain text. The size of the response is kept small so that gigabit Ethernet is not the limiting factor for all implementations. HTTP pipelining is enabled and higher client-side concurrency levels are used for this test (see the "Data table" view). Here, I instead benchmark my django gallery app, using Apache Bench, and so forth. I guess I?ve been over-achieving? I have to admit, though, that these benchmarks certainly allow everyone to play. 431 cherrypy 587 0.0%(0.0%) Even cherrypy with it?s 587 per second replies with plain-text. The tasks seem deceptively (?) simple? But looking closer, the data table for each task, gives more details. For example the plain text is run 4 different times, at 4 different client-side concurrency levels are used? But the levels are: 256, 1024, 4096, and 16384. That can?t be the concurrency/thread count??!?!?!?? I can believe 1,000 - 3,000, outrageously high, but believable. But 16K worth of concurrency/threads? I doubt that Wikipedia even has to dial it that high? I have to give them points for providing API latency, and framework overhead?. - Benjamin From antoon.pardon at vub.be Fri Oct 29 10:03:37 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 29 Oct 2021 16:03:37 +0200 Subject: New assignmens ... In-Reply-To: <004a01d7cc22$4c055050$e40ff0f0$@verizon.net> References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> <034401d7cb5f$5b5619e0$12024da0$@verizon.net> <83918585-0e37-f785-43d8-2a26350c3695@vub.be> <004a01d7cc22$4c055050$e40ff0f0$@verizon.net> Message-ID: Op 28/10/2021 om 19:36 schreef Avi Gross via Python-list: > Now for a dumb question. Many languages allow a form of setting a variable to a value like: > > > > assign(var, 5+sin(x)) > > > > If we had a function that then returned var or the value of var, cleanly, then would that allow an end run on the walrus operator? > > > > if (assign(sign, 5+sin(x)) <= assign(cosign, 5+cos(x))) ? > > > > Not necessarily pretty and I am sure there may well be reasons it won?t work, but I wonder if it will work in more places than the currently minimal walrus operator. This was the orginal code to illustrate the question: if (self.ctr:=self.ctr-1)<=0 So if I understand your sugested solution it would be something like: def setxattr(obj, attr, value): setattr(obj, attr, value) return value if setxattr(self, 'ctr', self.ctr - 1) <= 0 Did I get that right? -- Antoon Pardon. From alister.ware at ntlworld.com Fri Oct 29 16:35:10 2021 From: alister.ware at ntlworld.com (alister) Date: Fri, 29 Oct 2021 20:35:10 -0000 (UTC) Subject: The task is to invent names for things References: <27138c0a-9db1-bdc1-fcc3-0942c860e5e0@DancesWithMice.info> Message-ID: On Thu, 28 Oct 2021 00:41:41 +0200, Peter J. Holzer wrote: > On 2021-10-27 12:41:56 +0200, Karsten Hilbert wrote: >> Am Tue, Oct 26, 2021 at 11:36:33PM +0000 schrieb Stefan Ram: >> > xyzzy = lambda x: 2 * x >> > . Sometimes, this can even lead to "naming paralysis", where one >> > thinks excessively long about a good name. To avoid this naming >> > paralysis, one can start out with a mediocre name. In the course of >> > time, often a better name will come to one's mind. >> >> In that situation, is it preferable to choose a nonsensical name over a >> mediocre one ? > > I don't know. A mediocre name conveys at least some information, and > that seems to be better than none. On the other hand it might be just > enough to lead the reader astray which wouldn't happen with a > non-sensical name. > > But since perfect names are hard to find, using nonsensical instead of > mediocre names would mean choosing nonsensical names most of the time. > So I'll stick with mediocre names if in doubt. > > hp Although if a mediocre name is chosen there is less impetus on the programmer to change it, "its not great but it'll do" where as a nonsense name sticks out like a saw thumb until it is corrected. I am firmly undecided -- Riches cover a multitude of woes. -- Menander From alister.ware at ntlworld.com Fri Oct 29 16:38:22 2021 From: alister.ware at ntlworld.com (alister) Date: Fri, 29 Oct 2021 20:38:22 -0000 (UTC) Subject: The task is to invent names for things References: Message-ID: On Thu, 28 Oct 2021 00:38:17 +0000, Eli the Bearded wrote: > In comp.lang.python, Peter J. Holzer wrote: > ^^^^^^ > > Those all work. But if you are writing a new web framework and you name > your method to log stuff to a remote server "Britney" because you were > listening the singer, that's not perfectly fine, even you want to make > "Oops, I did it again" jokes about your logged errors. Although Oops would be aq pretty reasonable name for a logger or error handler... > > > Elijah ------ > naming is hard, unless it's easy -- After a number of decimal places, nobody gives a damn. From shishaozhong at gmail.com Fri Oct 29 18:42:38 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Fri, 29 Oct 2021 23:42:38 +0100 Subject: Python script seems to stop running when handling very large dataset Message-ID: Python script works well, but seems to stop running at a certain point when handling very large dataset. Can anyone shed light on this? Regards, David From PythonList at DancesWithMice.info Fri Oct 29 19:03:44 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 30 Oct 2021 12:03:44 +1300 Subject: Python script seems to stop running when handling very large dataset In-Reply-To: References: Message-ID: <358661f9-2ea6-3195-abff-3732858d4224@DancesWithMice.info> On 30/10/2021 11.42, Shaozhong SHI wrote: > Python script works well, but seems to stop running at a certain point when > handling very large dataset. > > Can anyone shed light on this? Storage space? Taking time to load/format/process data-set? -- Regards, =dn From PythonList at DancesWithMice.info Fri Oct 29 19:04:06 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 30 Oct 2021 12:04:06 +1300 Subject: The task is to invent names for things In-Reply-To: References: <004801d7cc20$90f8c040$b2ea40c0$@verizon.net> Message-ID: <48da8f66-9a13-f9b7-02c3-85e5b4833319@DancesWithMice.info> On 29/10/2021 07.07, Stefan Ram wrote: > The name should not be "optimized" for a certain use case > (as for the use in an if expression) only. "We", "have", > and "any" carry little information. A name should pack as > much information as possible in as least characters as > possible. So, for me, it'd be something like: Although, does that not imply that "pack[ing]...information" is primary, and "least characters..." secondary? How else to define "readability" (wrt 'names')? > if word_count: Yes, but this does open the door to the 'gotchas' of truthiness, ie there ain't no such thing as a free lunch/"silver bullet". Whereas, names such as: is_valid words help to imply a boolean and a collection, resp. (cf the micro-softy way of imposing the language-technicalities over naming-readability, eg bValid Thereafter, to counter the idea of not having too many names, there may be an argument for setting-up one's data to be able to code: if is_valid: while word_count: # pop word from words and do something... so now we have a data-set which includes: words: a collection, eg arriving to us from some input word: one item from words, isolated for processing word_count: a convenient expression of len( words ) is_valid: an indicator that the words received are ready for our process (not that I 'like' "is_valid" but need a specific context to improve that) The "is_" prefix appeals to me because it is so English-like (dare I say COBOL-like?) that readability is in no doubt. At the same time, whilst it could be considered and 'extra' name/extra-effort, it adds precision to the logic. YMMV! Indeed some may wish to argue that the data-set includes unnecessary verbiage, and that this in-and-of-itself might contribute to cognitive-overload... import this >> So, the obvious solution is to ask the language, like Python, to allow >> variables that are synonyms. > > Programs already have too many names in them. > There is no need to add even more, especially > when they are equivalent, and the average human can > only hold 7 ? 2 objects (like names) in his short- > term memory. +1 aka "cognitive overload" @Martin's term is "naming paralysis", which fits as a component of "analysis paralysis", cf 'let's get on with it'! (which summed-up how I felt abstracting and refactoring a function this morning - dithering and vacillating like I couldn't decide between chocolate cake or chocolate pudding...) Which point, when referred to synonym variables, gives the optimal answer: "both" (cake and pudding!) When you think about it, passing values to functions, ie an argument becomes a parameter, that can be considered a form of synonym. (and (before someone disappears off on another unintended tangent) some circumstances where it is not!) >> really good names often end up being really long names > > If they are really long, they are not really good, > /except/ when they have a really large scope. > > Names for a small scope can and should be short, > names for a large scope may be longer. Interesting! Surely as something becomes more specific, there is more meaning and/or greater precision to be embedded within the name. Thus: operator assignment_operator walrus_operator > Some very short names have traditional meanings > and are ok when used as such: > > for i in range( 10 ): For historical (?hysterical) reasons I find myself agreeing with this. (in FORTRAN any variable beginning with the letters "I" through "N" was regarded as an integer - all others being real/floating-point - thus, it is a familiar idiom. That said, this form of for-loop is reminiscent of other languages which use "pointers" to access data-collections, etc, and keep track of where to logic is within the process using "counters" - none of which are necessary in pythonic for-loops. Accordingly, there is an argument for using: for ptr in range( 10 ): for ctr in range( 10 ): (or even the complete word, if that is the functionality required) The above allowing for the fact that I have my own 'set' of 'standard abbreviations' which are idiomatic and readable to me (!). One of which is: for ndx in range( 10 ): This abbreviation originated in the days when variable-names had to be short. So, one tactic was to remove vowels*. Once again, more readable (to me) than "i", but possibly less-than idiomatic to others... That said, watching a video from EuroPython 2021, I was amused to see: for idx in range( 10 ): and doubly-amused when I experimented with the idea as-presented and 'copied' the code by 'translating' his "idx" into the English "index", and whilst typing into my own REPL, cogno-translated the thought into my own "ndx" expression. Now, I don't know if the EuroPython author uses "idx" because that relates somehow to his home-language. However, if we analyse such abbreviations, their writing is a personal exercise. Whereas, measuring/assessing "readability" involve neither "writing" nor "personal" at its core. Thus, if there is a "jargon" abbreviation which is readily understandable, is it so 'bad' just because it is not a complete (English) word? Until I spent more (?too much) time with folk who formed their Style Guides as super-sets of PEP-008, I didn't worry too much about these abbreviations. People 'here' are amongst those who dislike(d) my use of: idNR - id = identification (?), number (NB suffix) NUMwords = number in/len() of a collection (NB prefix) arrayPTR = pointer to specific member within array The interesting thing about some of these (aside from PEP-008) is that they are very historial - as above. Accordingly, it is 'the youngsters' who object more vociferously (aside from pedants, like trainers, er, cough, splutter). Yet, until a few years ago I would not have understood "OMG" and similar 'text-isms' that have escaped into the real-world from cell-phones. Yet, asking (a youngster) what (s)he means will stereotypically involve a shrug or eye-roll (patent-pending) indicating that I should not need to ask because 'everyone' knows! (OK, so am I allowed to give you a few PTRs about politesse?) NB I find that 'modern IDEs' and sundry plug-ins are possibly more responsible for making me PEP-008-compliant than any human(s). The nagging splatters of queries and criticisms are even less politically-correct than aforementioned ageist youngsters! > . And, as a "golden rule" for refactoring, I'd say: > When you see: > > i = 0 # word count > > , then remove the comment and rename "i" to "word_count"! Yes, a beautiful illustration of why comments can cause more damage than they should (theoretically) be helping us, readers, avoid... Two for the price of one: criticising the choice of name, and the choice of comment! * see also written Classical Arabic -- Regards, =dn From drsalists at gmail.com Fri Oct 29 19:23:28 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 29 Oct 2021 16:23:28 -0700 Subject: Python script seems to stop running when handling very large dataset In-Reply-To: <358661f9-2ea6-3195-abff-3732858d4224@DancesWithMice.info> References: <358661f9-2ea6-3195-abff-3732858d4224@DancesWithMice.info> Message-ID: On Fri, Oct 29, 2021 at 4:04 PM dn via Python-list wrote: > On 30/10/2021 11.42, Shaozhong SHI wrote: > > Python script works well, but seems to stop running at a certain point > when > > handling very large dataset. > > > > Can anyone shed light on this? > > Storage space? > Taking time to load/format/process data-set? > It could be many things. What operating system are you on? If you're on Linux, you can use strace to attach to a running process to see what it's up to. Check out the -p option. See https://stromberg.dnsalias.org/~strombrg/debugging-with-syscall-tracers.html macOS has dtruss, but it's a little hard to enable. dtruss is similar to strace. Both of these tools are better for processes doing system calls (kernel interactions). They do not help nearly as much with CPU-bound processes. It could also be that you're running out of virtual memory, and the system's virtual memory system is thrashing. Does the load average on the system go up significantly when the process seems to get stuck? You could try attaching to the process with a debugger, too, EG with pudb: https://github.com/inducer/pudb/issues/31 Barring those, you could sprinkle some print statements in your code, to see where it's getting stuck. This tends to be an iterative process, where you add some prints, run, observe the result, and repeat. HTH. From pbryan at anode.ca Fri Oct 29 19:33:41 2021 From: pbryan at anode.ca (Paul Bryan) Date: Fri, 29 Oct 2021 16:33:41 -0700 Subject: Python script seems to stop running when handling very large dataset In-Reply-To: References: Message-ID: <84c1a27050b3f0cb3a46cb9137dc71dfe7e09bb9.camel@anode.ca> With so little information provided, not much light will be shed. When it stops running, are there any errors? How is the dataset being processed? How large is the dataset? How large a dataset can be successfully processed? What libraries are being used? What version of Python are you using? On what operating system? With how much memory? With how much disk space is used? How much is free? Are you processing files or using a database? If the latter, what database? Does it write intermediate files during processing? Can you monitor memory usage during processing (e.g. with a system monitor) to see how much memory is consumed? On Fri, 2021-10-29 at 23:42 +0100, Shaozhong SHI wrote: > Python script works well, but seems to stop running at a certain > point when > handling very large dataset. > > Can anyone shed light on this? > > Regards, David From drsalists at gmail.com Fri Oct 29 19:38:09 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 29 Oct 2021 16:38:09 -0700 Subject: CWD + relative path + import name == resultant relative path? Message-ID: Is there a predefined function somewhere that can accept the 3 things on the LHS in the subject line, and give back a resultant relative path - relative to the unchanged CWD? To illustrate, imagine: 1) You're sitting in /home/foo/coolprog 2) You look up the AST for /home/foo/coolprog/a/b/c.py 3) /home/foo/coolprog/a/b/c.py has a relative import of ..blah Is there something preexisting that can figure out what path blah is supposed to have, assuming 100% pure python code? Or is it necessary to actually import to get that? I think I could import and then check __file__, but I'd rather avoid that if possible. Thanks! From avigross at verizon.net Fri Oct 29 19:43:47 2021 From: avigross at verizon.net (Avi Gross) Date: Fri, 29 Oct 2021 19:43:47 -0400 Subject: New assignmens ... In-Reply-To: References: <00a701d7c9e9$0d745650$285d02f0$@verizon.net> <7fe4dae1-0144-8e99-cc32-17d733961df1@vub.be> <034401d7cb5f$5b5619e0$12024da0$@verizon.net> <83918585-0e37-f785-43d8-2a26350c3695@vub.be> <004a01d7cc22$4c055050$e40ff0f0$@verizon.net> Message-ID: <024201d7cd1e$d1be1f90$753a5eb0$@verizon.net> Antoon, As long as we understand that my suggestion is not meant to be taken seriously, your extension is along the lines I intended. You might indeed have a family of helper functions whose purpose is to bot make a change on the side and return the value to be used in a computation. Your specific implementation of something like that: def setxattr(obj, attr, value): setattr(obj, attr, value) return value Would need to have access to the original object and change it in a way that propagates properly. So when you do this: if setxattr(self, 'ctr', self.ctr - 1) <= 0 : Then assuming passing it 'ctr' as a string makes sense, and the object self is passed by reference, I can see it working without a walrus operator. But it is extra overhead. This being python, setting values WITHIN an object is a challenge. I mean there are ways to make a value readable but not writeable or writeable only using a designated method, or an attempt to set the value may be intercepted and the interceptor may choose to do something different such as ignoring the request if someone tries to set the time to thirteen o'clock or even setting it to 1 o'clock instead. The above kind of code perhaps should not return value but obj.attr so we see what was stored. But again, Python lets you intercept things in interesting ways so I can imagine it showing something other that what you stored. Sigh As noted, the general case implemented walrus style may have challenges and even efforts like the above may not always be straightforward. Language design is not as trivial as some think and like with many things, adding a neat new feature may open up holes including security holes if people figure out how to abuse it. Shutting down some such abilities is exactly why people code defensively and try to hide the inner aspects of an object by doing things like having a proxy in front of it and creating getters and setters. -----Original Message----- From: Python-list On Behalf Of Antoon Pardon Sent: Friday, October 29, 2021 10:04 AM To: python-list at python.org Subject: Re: New assignmens ... Op 28/10/2021 om 19:36 schreef Avi Gross via Python-list: > Now for a dumb question. Many languages allow a form of setting a variable to a value like: > > > > assign(var, 5+sin(x)) > > > > If we had a function that then returned var or the value of var, cleanly, then would that allow an end run on the walrus operator? > > > > if (assign(sign, 5+sin(x)) <= assign(cosign, 5+cos(x))) ? > > > > Not necessarily pretty and I am sure there may well be reasons it won?t work, but I wonder if it will work in more places than the currently minimal walrus operator. This was the orginal code to illustrate the question: if (self.ctr:=self.ctr-1)<=0 So if I understand your sugested solution it would be something like: def setxattr(obj, attr, value): setattr(obj, attr, value) return value if setxattr(self, 'ctr', self.ctr - 1) <= 0 Did I get that right? -- Antoon Pardon. -- https://mail.python.org/mailman/listinfo/python-list From bob.martin at excite.com Fri Oct 29 02:02:02 2021 From: bob.martin at excite.com (Bob Martin) Date: 29 Oct 2021 06:02:02 GMT Subject: walrus with a twist :+ In-Reply-To: References: <030e01d7cb96$b69ffc30$23dff490$.ref@verizon.net> <030e01d7cb96$b69ffc30$23dff490$@verizon.net> <034301d7cba1$a2378640$e6a692c0$@verizon.net> <009a01d7cc2c$f363a4a0$da2aede0$@verizon.net> Message-ID: On 28 Oct 2021 at 18:52:26, "Avi Gross" wrote: > > Ages ago, IBM used a different encoding than ASCII called EBCDIC (Extended > Binary Coded Decimal Interchange Code ) which let them use all 8 bits and > thus add additional symbols. =B1 =A6 =AC IBM started using EBCDIC with System 360 and it is still used on mainframes. From grant.b.edwards at gmail.com Fri Oct 29 20:00:45 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 29 Oct 2021 17:00:45 -0700 (PDT) Subject: Python script seems to stop running when handling very large dataset References: Message-ID: <617c8b2d.1c69fb81.d3dcb.55b4@mx.google.com> On 2021-10-29, Shaozhong SHI wrote: > Python script works well, but seems to stop running at a certain point when > handling very large dataset. > > Can anyone shed light on this? No. Nobody can help you with the amount of information you have provided. -- Grant From dieter at handshake.de Sat Oct 30 13:57:47 2021 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 30 Oct 2021 19:57:47 +0200 Subject: CWD + relative path + import name == resultant relative path? In-Reply-To: References: Message-ID: <24957.34715.3598.835667@ixdm.fritz.box> Dan Stromberg wrote at 2021-10-29 16:38 -0700: >Is there a predefined function somewhere that can accept the 3 things on >the LHS in the subject line, and give back a resultant relative path - >relative to the unchanged CWD? > >To illustrate, imagine: >1) You're sitting in /home/foo/coolprog >2) You look up the AST for /home/foo/coolprog/a/b/c.py >3) /home/foo/coolprog/a/b/c.py has a relative import of ..blah Look at the functions provided by `os.path`. Maybe, you do not need relative path: look at `importlib` (which also supports import via absolute paths). From dieter at handshake.de Sat Oct 30 14:00:31 2021 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 30 Oct 2021 20:00:31 +0200 Subject: Python script seems to stop running when handling very large dataset In-Reply-To: References: Message-ID: <24957.34879.756097.363961@ixdm.fritz.box> Shaozhong SHI wrote at 2021-10-29 23:42 +0100: >Python script works well, but seems to stop running at a certain point when >handling very large dataset. > >Can anyone shed light on this? Some algorithms have non linear runtime. For example, it is quite easy to write code with quadratic runtime in Python: s = "" for x in ...: s += f(x) You will see the problem only for large data sets. From shishaozhong at gmail.com Sat Oct 30 19:34:40 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Sun, 31 Oct 2021 00:34:40 +0100 Subject: Python script seems to stop running when handling very large dataset In-Reply-To: <24957.34879.756097.363961@ixdm.fritz.box> References: <24957.34879.756097.363961@ixdm.fritz.box> Message-ID: On Saturday, 30 October 2021, Dieter Maurer wrote: > Shaozhong SHI wrote at 2021-10-29 23:42 +0100: > >Python script works well, but seems to stop running at a certain point > when > >handling very large dataset. > > > >Can anyone shed light on this? > > Some algorithms have non linear runtime. > > > For example, it is quite easy to write code with > quadratic runtime in Python: > s = "" > for x in ...: s += f(x) > You will see the problem only for large data sets. > Has anyone compared this with iterrow? which looping option is faster? Regards, David From sjeik_appie at hotmail.com Sun Oct 31 09:01:08 2021 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sun, 31 Oct 2021 14:01:08 +0100 Subject: Ansible, pip and virtualenv Message-ID: Hi I wrote an Ansible .yml to deploy a Flask webapp. I use python 3.6 for the ansible-playbook executable. The yml starts with some yum installs, amongst which python-pip. That installs an ancient pip version (v9). Then I create a virtualenv where I use a requirements.txt for pip install -r. Should I precede that step with a separate --upgrade pip step? Or should pip just be in my requirements.txt? Separate question: what locations do I need to specify in my pip --trusted-host list? Could it be that this has recently changed? I suddenly got SSL errors. Thanks in advance! Albert-Jan From shishaozhong at gmail.com Sun Oct 31 13:25:12 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Sun, 31 Oct 2021 17:25:12 +0000 Subject: How to apply a self defined function in Pandas In-Reply-To: References: Message-ID: I defined a function and apply it to a column in Pandas. But it does not return correct values. I am trying to test which url in a column full of url to see which one can be connected to or not def connect(url): try: urllib.request.urlopen(url) return True except: return False df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) I ran without any error, but did not return any true. I just could not find any error with it. Can anyone try and find out why Regards, David From python at mrabarnett.plus.com Sun Oct 31 14:08:51 2021 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 31 Oct 2021 18:08:51 +0000 Subject: How to apply a self defined function in Pandas In-Reply-To: References: Message-ID: On 2021-10-31 17:25, Shaozhong SHI wrote: > I defined a function and apply it to a column in Pandas. But it does not > return correct values. > > I am trying to test which url in a column full of url to see which one can > be connected to or not > > def connect(url): > try: > urllib.request.urlopen(url) > return True > except: > return False > > df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) > > I ran without any error, but did not return any true. > > I just could not find any error with it. > > Can anyone try and find out why > You're passing a function to '.apply'. That has one argument,' x'. But what is the function doing with that argument? Nothing. The function is just returning the result of connect(df['URL']). df['URL'] is a column, so you're passing a column to '.urlopen', which, of course, it doesn't understand. So 'connect' returns False. From sjeik_appie at hotmail.com Sun Oct 31 14:19:55 2021 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sun, 31 Oct 2021 19:19:55 +0100 Subject: How to apply a self defined function in Pandas In-Reply-To: Message-ID: > df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) I think you need axis=0. Or use the Series, df['URL'] = df.URL.apply(connect) From shishaozhong at gmail.com Sun Oct 31 14:42:49 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Sun, 31 Oct 2021 18:42:49 +0000 Subject: How to apply a self defined function in Pandas In-Reply-To: References: Message-ID: On Sunday, 31 October 2021, Albert-Jan Roskam wrote: > > > > df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) > > > I think you need axis=0. Or use the Series, df['URL'] = > df.URL.apply(connect) > Any details? I will try and let you know. Regards, David From shishaozhong at gmail.com Sun Oct 31 14:48:10 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Sun, 31 Oct 2021 18:48:10 +0000 Subject: How to apply a self defined function in Pandas In-Reply-To: References: Message-ID: On Sunday, 31 October 2021, MRAB wrote: > On 2021-10-31 17:25, Shaozhong SHI wrote: > >> I defined a function and apply it to a column in Pandas. But it does not >> return correct values. >> >> I am trying to test which url in a column full of url to see which one can >> be connected to or not >> >> def connect(url): >> try: >> urllib.request.urlopen(url) >> return True >> except: >> return False >> >> df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) >> >> I ran without any error, but did not return any true. >> >> I just could not find any error with it. >> >> Can anyone try and find out why >> >> You're passing a function to '.apply'. That has one argument,' x'. > > But what is the function doing with that argument? > > Nothing. > > The function is just returning the result of connect(df['URL']). > > df['URL'] is a column, so you're passing a column to '.urlopen', which, of > course, it doesn't understand. > > So 'connect' returns False. > > Please expand on how. David > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Sun Oct 31 15:23:56 2021 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 31 Oct 2021 19:23:56 +0000 Subject: How to apply a self defined function in Pandas In-Reply-To: References: Message-ID: <368fea32-2066-bd5a-8f43-4753fc39c849@mrabarnett.plus.com> On 2021-10-31 18:48, Shaozhong SHI wrote: > > On Sunday, 31 October 2021, MRAB wrote: > > On 2021-10-31 17:25, Shaozhong SHI wrote: > > I defined a function and apply it to a column in Pandas.? But > it does not > return correct values. > > I am trying to test which url in a column full of url to see > which one can > be connected to or not > > def connect(url): > ? ? ?try: > ? ? ? ? ?urllib.request.urlopen(url) > ? ? ? ? ?return True > ? ? ?except: > ? ? ? ? ?return False > > df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) > > I ran without any error, but did not return any true. > > I just could not find any error with it. > > Can anyone try and find out why > > You're passing a function to '.apply'. That has one argument,' x'. > > But what is the function doing with that argument? > > Nothing. > > The function is just returning the result of connect(df['URL']). > > df['URL'] is a column, so you're passing a column to '.urlopen', > which, of course, it doesn't understand. > > So 'connect' returns False. > > > Please expand on how. > It's as simple as passing 'connect' to '.apply' as? the first argument. From shishaozhong at gmail.com Sun Oct 31 15:52:18 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Sun, 31 Oct 2021 19:52:18 +0000 Subject: How to apply a self defined function in Pandas In-Reply-To: <368fea32-2066-bd5a-8f43-4753fc39c849@mrabarnett.plus.com> References: <368fea32-2066-bd5a-8f43-4753fc39c849@mrabarnett.plus.com> Message-ID: On Sun, 31 Oct 2021 at 19:28, MRAB wrote: > On 2021-10-31 18:48, Shaozhong SHI wrote: > > > > On Sunday, 31 October 2021, MRAB wrote: > > > > On 2021-10-31 17:25, Shaozhong SHI wrote: > > > > I defined a function and apply it to a column in Pandas. But > > it does not > > return correct values. > > > > I am trying to test which url in a column full of url to see > > which one can > > be connected to or not > > > > def connect(url): > > try: > > urllib.request.urlopen(url) > > return True > > except: > > return False > > > > df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) > > > > I ran without any error, but did not return any true. > > > > I just could not find any error with it. > > > > Can anyone try and find out why > > > > You're passing a function to '.apply'. That has one argument,' x'. > > > > But what is the function doing with that argument? > > > > Nothing. > > > > The function is just returning the result of connect(df['URL']). > > > > df['URL'] is a column, so you're passing a column to '.urlopen', > > which, of course, it doesn't understand. > > > > So 'connect' returns False. > > > > > > Please expand on how. > > > It's as simple as passing 'connect' to '.apply' as the first argument. > Well, can you expand the the simplicity? Regards, David > -- > https://mail.python.org/mailman/listinfo/python-list > From Karsten.Hilbert at gmx.net Sun Oct 31 15:59:36 2021 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sun, 31 Oct 2021 20:59:36 +0100 Subject: How to apply a self defined function in Pandas In-Reply-To: References: <368fea32-2066-bd5a-8f43-4753fc39c849@mrabarnett.plus.com> Message-ID: Am Sun, Oct 31, 2021 at 07:52:18PM +0000 schrieb Shaozhong SHI: > Well, can you expand the the simplicity? Not sure how expanding is going to help but here's one way to do it: Python 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] on linux Type "help", "copyright", "credits" or "license" for more information. >>> list('simplicity') ['s', 'i', 'm', 'p', 'l', 'i', 'c', 'i', 't', 'y'] >>> Best, Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From shishaozhong at gmail.com Sun Oct 31 16:08:49 2021 From: shishaozhong at gmail.com (Shaozhong SHI) Date: Sun, 31 Oct 2021 20:08:49 +0000 Subject: How to apply a self defined function in Pandas In-Reply-To: References: Message-ID: On Sun, 31 Oct 2021 at 18:42, Shaozhong SHI wrote: > > > On Sunday, 31 October 2021, Albert-Jan Roskam > wrote: > >> >> >> > df['URL'] = df.apply(lambda x: connect(df['URL']), axis=1) >> >> >> I think you need axis=0. Or use the Series, df['URL'] = >> df.URL.apply(connect) >> > > Just experimented with your suggestion, but have not seen any difference. > Regards, David From elbarbun at gmail.com Sun Oct 31 18:59:49 2021 From: elbarbun at gmail.com (Marco Sulla) Date: Sun, 31 Oct 2021 23:59:49 +0100 Subject: Python C API: how to mark a type as subclass of another type Message-ID: I have two types declared as PyTypeObject PyX_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) etc. How can I mark one of the types as subclass of the other one? I tried to use tp_base but it didn't work. From avigross at verizon.net Sun Oct 31 19:56:43 2021 From: avigross at verizon.net (Avi Gross) Date: Sun, 31 Oct 2021 19:56:43 -0400 Subject: How to apply a self defined function in Pandas In-Reply-To: References: <368fea32-2066-bd5a-8f43-4753fc39c849@mrabarnett.plus.com> Message-ID: <017701d7ceb2$f4d77360$de865a20$@verizon.net> When people post multiple comments and partial answers and the reply every time is to ask for more; there may be a disconnect. Some assume that the person is just stuck but generally can go forward with a little hint. But when you keep being asked for more, maybe it means they want you to do it for them, as in some asking about HW. I am not joining this one. ? -----Original Message----- From: Python-list On Behalf Of Karsten Hilbert Sent: Sunday, October 31, 2021 4:00 PM To: python-list at python.org Subject: Re: How to apply a self defined function in Pandas Am Sun, Oct 31, 2021 at 07:52:18PM +0000 schrieb Shaozhong SHI: > Well, can you expand the the simplicity? Not sure how expanding is going to help but here's one way to do it: Python 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] on linux Type "help", "copyright", "credits" or "license" for more information. >>> list('simplicity') ['s', 'i', 'm', 'p', 'l', 'i', 'c', 'i', 't', 'y'] >>> Best, Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mail.python.org/mailman/listinfo/python-list