From rosuav at gmail.com Sat Apr 1 03:50:36 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Apr 2023 18:50:36 +1100 Subject: Windows installer from python source code without access to source code In-Reply-To: References: <6b7e32a0-77a4-1d53-a7d3-0ca9887da30b@tompassin.net> Message-ID: On Sat, 1 Apr 2023 at 13:16, <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > On 2023-04-01 at 10:49:18 +1100, > Chris Angelico wrote: > > > [...] I don't have access to the Gmail source code but I'm using the > > service [...] > > You have access to Gmail's front end source code. Your web browser runs > it every time you use the service (and probably while you aren't using > the service, too). Yes, and I'm talking about their back end source code, which I most definitely do NOT have access to, and therefore cannot copy. > My educated guess is that Google expended some > effort to hinder you from looking at and/or analyzing (or do you say > analysing?) that code, and that their lawyers will come knocking at your > metaphorical door if they so much as think you are using that code in > some way other than running it inside your web browser. If only this > situation were a cruel April Fool's Day joke. They haven't done very much, I happen to know this relating to other services. From what I can tell, Google's front ends aren't very well protected, for the simple reason that they're quite useless without the corresponding back ends. > You don't have access to Gmail's back end source code. > > Many/Most web apps follow this pattern to varying degrees. I do not > know whether this setup meets the OP's requirements. Exactly. That's why I pointed it out. This is the only way to truly protect your source code: Don't give it out. ChrisA From jschwar at sbcglobal.net Sat Apr 1 05:24:44 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Sat, 1 Apr 2023 04:24:44 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: References: Message-ID: I am writing an app but I?m not sure I?ll sell it yet. I have it in a private GitHub location and GitHub prompts me for a license. I don?t really understand licenses so I just picked Apache 2.0. Maybe I?m going too far with my worry about which license I pick. I?m not selling it now so it doesn?t matter. I have to do a lot more work before I get to that point Sent from my iPhone > On Mar 31, 2023, at 6:52 PM, Chris Angelico wrote: > > ?On Sat, 1 Apr 2023 at 10:34, Jim Schwartz wrote: >> >> Yea. You?re right. I probably need a lawyer someday. Thanks. >> > > If your needs are basic, you shouldn't need a lawyer. Copyright law > and treaties DO protect you. But it's important to be aware that no > amount of legal protection - whether you hire a lawyer or not, and > whether you identify copyright and license or not - will stop people > from copying your code. NOTHING will stop people from copying your > code if they have access to it. All you can do is discourage them. > > So that brings us back to the original question: Why protect your > *source code* specifically? There are two extremes available to > everyone: > > 1) Distribute the source code. Let everyone see it. Stick a license on > it that permits them to use it, modify it, distribute modified > versions. Set your code free and let it be used. > > 2) Don't distribute the program *at all*. Don't distribute the source > OR the binary. Instead, permit people to *access* the program - which, > in today's world, usually means a web service. > > Both of these are very popular and work well. I don't have access to > the Gmail source code but I'm using the service. I don't have access > to the Twitch.tv source code but I'm using the service. Meanwhile, I > have Python programs running on a Debian system using the Linux > kernel, invoked using bash, served from an ext4 mass storage device, > etc, etc. I have the binary code for all of these, and I'm legally > guaranteed access to the source if I want it, so there's no incentive > to steal it. > > The middle ground of "distribute binaries but stop people from > accessing the source" is a much narrower use-case, and I would say > that it's not actually a single use-case but a family of them, each > with different needs and requirements. So it's essential to know what > you're actually trying to protect, and why. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From barry at barrys-emacs.org Sat Apr 1 05:52:53 2023 From: barry at barrys-emacs.org (Barry Scott) Date: Sat, 1 Apr 2023 10:52:53 +0100 Subject: Python not showing correct version In-Reply-To: References: <34dcfb4d-28ed-0d26-8816-826fd63c1848@tompassin.net> Message-ID: <4F251711-2F64-4B29-8E23-16E792C23009@barrys-emacs.org> > On 31 Mar 2023, at 22:02, Eryk Sun wrote: > > > The OP installed the standard Python 3.8 distribution, which does > install the launcher by default. The launcher can run all installed > versions, including store app installations. By default it runs the > highest available version, which will probably be the 3.10 store app > in the OP's case. To make 3.8 the default without having to remove > 3.10, set the environment variables "PY_PYTHON=3.8" and > "PY_PYTHON3=3.8" in the user environment. I find user environment on windows to be less flexible to work with then adding a py.ini. On my Windows 11 I added %userprofile%\AppData\Local\py.ini. To make python 3.8 the default that py.exe uses put this in py.ini: [defaults] python=3.8-64 python3=3.8-64 Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From nulla.epistola at web.de Sat Apr 1 06:09:57 2023 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 1 Apr 2023 12:09:57 +0200 Subject: Ole version set as default In-Reply-To: References: Message-ID: Am 29.03.2023 um 18:46 schrieb Pranav Bhardwaj: > Dear sir, > I am Pranav Bhardwaj and I stuck in a problem. My problem is > that in my system I have python 3.11.2 but when I type python in my command > prompt, my command prompt show that python version 2.7.13 as a default. And > I can't be able to find python 2.7.13 in my system in any file and I tried > various methods to set python 3.11.2 as a default but can't be able to do > so. I tried to change environment variables, try to find and delete python > 2.7.13 , try to set python 3.11.2 as default, but I can't be able to do so. > So can you help me how can I solve this problem? Which OS is this? And what happens if you enter "python3" in your command prompt? HTH Sibylle From rosuav at gmail.com Sat Apr 1 06:26:20 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Apr 2023 21:26:20 +1100 Subject: Windows installer from python source code without access to source code In-Reply-To: References: Message-ID: On Sat, 1 Apr 2023 at 20:24, Jim Schwartz wrote: > > I am writing an app but I?m not sure I?ll sell it yet. I have it in a private GitHub location and GitHub prompts me for a license. I don?t really understand licenses so I just picked Apache 2.0. Maybe I?m going too far with my worry about which license I pick. I?m not selling it now so it doesn?t matter. I have to do a lot more work before I get to that point > When you put license terms on something, that is a *legal statement*. Read the license you're applying and don't just pick for the sake of picking. By applying this license, you are granting legal permission for anyone to redistribute your code in source or object form. On the plus side, you've just made all questions of obfuscating your source code completely irrelevant :) ChrisA From jschwar at sbcglobal.net Sat Apr 1 07:59:50 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Sat, 1 Apr 2023 06:59:50 -0500 Subject: Windows Gui Frontend References: <027401d96491$7736dce0$65a496a0$.ref@sbcglobal.net> Message-ID: <027401d96491$7736dce0$65a496a0$@sbcglobal.net> I have another question. I have an app written in python, but I want to add a windows GUI front end to it. Can this be done in python? What packages would allow me to do that? Thanks. From list1 at tompassin.net Sat Apr 1 08:51:43 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 1 Apr 2023 08:51:43 -0400 Subject: Windows installer from python source code without access to source code In-Reply-To: References: Message-ID: On 4/1/2023 5:24 AM, Jim Schwartz wrote: > I am writing an app but I?m not sure I?ll sell it yet. I have it in a private GitHub location and GitHub prompts me for a license. I don?t really understand licenses so I just picked Apache 2.0. Maybe I?m going too far with my worry about which license I pick. I?m not selling it now so it doesn?t matter. I have to do a lot more work before I get to that point You can dual-license it - one license for free uses, one for commercial users. But read GitHub's terms of service to make sure your repo is going to continue to qualify - you might need to start paying them if your code goes commercial. From eryksun at gmail.com Sat Apr 1 11:08:49 2023 From: eryksun at gmail.com (Eryk Sun) Date: Sat, 1 Apr 2023 10:08:49 -0500 Subject: Python not showing correct version In-Reply-To: <4F251711-2F64-4B29-8E23-16E792C23009@barrys-emacs.org> References: <34dcfb4d-28ed-0d26-8816-826fd63c1848@tompassin.net> <4F251711-2F64-4B29-8E23-16E792C23009@barrys-emacs.org> Message-ID: On 4/1/23, Barry Scott wrote: > > I find user environment on windows to be less flexible to work with then > adding a py.ini. On my Windows 11 I added > %userprofile%\AppData\Local\py.ini. > To make python 3.8 the default that py.exe uses put this in py.ini: > > [defaults] > python=3.8-64 > python3=3.8-64 Using "py.ini" has the advantage that launcher always reads the file. The value of the environment variables, on the other hand, may be stale. If you keep a lot of shells running, it would be tedious to have to manually update the PY_PYTHON* variables in each shell. That said, it should be rare that one needs to change the persisted default versions. For temporary changes, the PY_PYTHON* environment variables are more flexible and take precedence over "py.ini". If one doesn't use "py.ini" to set the defaults, it's easy to modify the persisted user environment using "setx.exe"[^1]. For example: setx.exe PY_PYTHON 3.8 setx.exe PY_PYTHON3 3.8 setx.exe broadcasts a WM_SETTINGCHANGE "Environment" window message, which causes Explorer to update its environment. Thus any program run from Explorer will see the new values. A program launched in a new tab in Windows Terminal also gets a fresh environment. However, existing CLI shells (CMD, PowerShell, bash), and programs started by them, will still have the old environment values. The latter is where using "py.ini" to set the defaults has the advantage. --- [^1]: Note that "setx.exe" should never be used to set the persisted user or machine "Path" value to the current %PATH%. When loading the environment, the user "Path" gets appended to the machine "Path". Setting the entire expanded and concatenated value to one or the other leads to a bloated, redundant PATH value, and it also loses the flexible configuration based on REG_EXPAND_SZ values. From list1 at tompassin.net Sat Apr 1 08:59:39 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 1 Apr 2023 08:59:39 -0400 Subject: Windows Gui Frontend In-Reply-To: <027401d96491$7736dce0$65a496a0$@sbcglobal.net> References: <027401d96491$7736dce0$65a496a0$.ref@sbcglobal.net> <027401d96491$7736dce0$65a496a0$@sbcglobal.net> Message-ID: On 4/1/2023 7:59 AM, Jim Schwartz wrote: > I have another question. I have an app written in python, but I want to add > a windows GUI front end to it. Can this be done in python? What packages > would allow me to do that? WxWindows, Tk, and PyQt are some of the common ones. Be aware that GUI programming can soak up a lot of your time, so be prepared. If you want it to work on Linux as well (always a good idea), you will need to pay attention to file locations, paths, and path separators as well. From eryksun at gmail.com Sat Apr 1 11:37:34 2023 From: eryksun at gmail.com (Eryk Sun) Date: Sat, 1 Apr 2023 10:37:34 -0500 Subject: Windows Gui Frontend In-Reply-To: <027401d96491$7736dce0$65a496a0$@sbcglobal.net> References: <027401d96491$7736dce0$65a496a0$.ref@sbcglobal.net> <027401d96491$7736dce0$65a496a0$@sbcglobal.net> Message-ID: On 4/1/23, Jim Schwartz wrote: > I have another question. I have an app written in python, but I want to > add a windows GUI front end to it. Can this be done in python? What > packages would allow me to do that? Here are a few of the GUI toolkit libraries in common use: * tkinter (Tk) * PyQt (Qt) * PySide (Qt) * wxPython (wxWidgets) * PyGObject (GTK) tkinter is included in Python's standard library. From jschwar at sbcglobal.net Sat Apr 1 13:21:55 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Sat, 1 Apr 2023 12:21:55 -0500 Subject: Windows Gui Frontend In-Reply-To: References: Message-ID: Are there any ide?s that will let me design the screen and convert it to python? I doubt it because it was mentioned that this is time consuming. Thanks for the responses everyone. I appreciate it. Sent from my iPhone > On Apr 1, 2023, at 10:37 AM, Eryk Sun wrote: > > ?On 4/1/23, Jim Schwartz wrote: >> I have another question. I have an app written in python, but I want to >> add a windows GUI front end to it. Can this be done in python? What >> packages would allow me to do that? > > Here are a few of the GUI toolkit libraries in common use: > > * tkinter (Tk) > * PyQt (Qt) > * PySide (Qt) > * wxPython (wxWidgets) > * PyGObject (GTK) > > tkinter is included in Python's standard library. From list1 at tompassin.net Sat Apr 1 13:28:42 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 1 Apr 2023 13:28:42 -0400 Subject: Windows Gui Frontend In-Reply-To: References: Message-ID: <9660a85e-00bd-5c6c-6be0-de6f4b6c8615@tompassin.net> On 4/1/2023 1:21 PM, Jim Schwartz wrote: > Are there any ide?s that will let me design the screen and convert it to python? I doubt it because it was mentioned that this is time consuming. Depends on what you mean by "let me design the screen", but Pyside (which I think is now called Pyside2) may be suitable. It is part the Qt framework. > Thanks for the responses everyone. I appreciate it. > > Sent from my iPhone > >> On Apr 1, 2023, at 10:37 AM, Eryk Sun wrote: >> >> ?On 4/1/23, Jim Schwartz wrote: >>> I have another question. I have an app written in python, but I want to >>> add a windows GUI front end to it. Can this be done in python? What >>> packages would allow me to do that? >> >> Here are a few of the GUI toolkit libraries in common use: >> >> * tkinter (Tk) >> * PyQt (Qt) >> * PySide (Qt) >> * wxPython (wxWidgets) >> * PyGObject (GTK) >> >> tkinter is included in Python's standard library. > From ikorot01 at gmail.com Sat Apr 1 13:30:08 2023 From: ikorot01 at gmail.com (Igor Korot) Date: Sat, 1 Apr 2023 12:30:08 -0500 Subject: Windows Gui Frontend In-Reply-To: References: Message-ID: Hi, On Sat, Apr 1, 2023 at 12:24?PM Jim Schwartz wrote: > > Are there any ide?s that will let me design the screen and convert it to python? I doubt it because it was mentioned that this is time consuming. Look at wxGlade (a project designed for wxWidgets). You will design you layout and then just save it as a py file. No conversion needed. And it's pretty straightforward. And very easy. You can do it in 5 min or less.. Thank you. I'm sure other libraries mentioned have their own RAD tool. > > Thanks for the responses everyone. I appreciate it. > > Sent from my iPhone > > > On Apr 1, 2023, at 10:37 AM, Eryk Sun wrote: > > > > ?On 4/1/23, Jim Schwartz wrote: > >> I have another question. I have an app written in python, but I want to > >> add a windows GUI front end to it. Can this be done in python? What > >> packages would allow me to do that? > > > > Here are a few of the GUI toolkit libraries in common use: > > > > * tkinter (Tk) > > * PyQt (Qt) > > * PySide (Qt) > > * wxPython (wxWidgets) > > * PyGObject (GTK) > > > > tkinter is included in Python's standard library. > > -- > https://mail.python.org/mailman/listinfo/python-list From eryksun at gmail.com Sat Apr 1 13:34:27 2023 From: eryksun at gmail.com (Eryk Sun) Date: Sat, 1 Apr 2023 12:34:27 -0500 Subject: Windows Gui Frontend In-Reply-To: References: Message-ID: On 4/1/23, Jim Schwartz wrote: > Are there any ide?s that will let me design the screen and convert it to > python? I doubt it because it was mentioned that this is time consuming. > > Thanks for the responses everyone. I appreciate it. For Qt, the WYSIWYG UI editor is Qt Designer. The basics are covered in the following PySide tutorial: https://www.pythonguis.com/pyside2-tutorial From list1 at tompassin.net Sat Apr 1 13:37:38 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 1 Apr 2023 13:37:38 -0400 Subject: Windows Gui Frontend In-Reply-To: <9660a85e-00bd-5c6c-6be0-de6f4b6c8615@tompassin.net> References: <9660a85e-00bd-5c6c-6be0-de6f4b6c8615@tompassin.net> Message-ID: On 4/1/2023 1:28 PM, Thomas Passin wrote: > On 4/1/2023 1:21 PM, Jim Schwartz wrote: >> Are there any ide?s that will let me design the screen and convert it >> to python?? I doubt it because it was mentioned that this is time >> consuming. > > Depends on what you mean by "let me design the screen", but Pyside > (which I think is now called Pyside2) may be suitable.? It is part the > Qt framework. I should have added that in my experience, the screen layout of controls is not the hardest and most time-consuming part of developing GUIs. The hard part is getting the screen elements and other components to do what you want in the way that you want it. For example, the Tk.Text class can be used as a fairly full-featured editor, but try figuring out how to highlight part of the text - not so obvious. Or say you decide you want to have a button flash when clicked, but you don't like the standard flash effect and want to change it. Those are a few of the kinds of things that you have to deal with and that soak up the time. It's not usually screen design. >> >> Sent from my iPhone >> >>> On Apr 1, 2023, at 10:37 AM, Eryk Sun wrote: >>> >>> ?On 4/1/23, Jim Schwartz wrote: >>>> I have another question.? I have an app written in python, but I >>>> want to >>>> add a windows GUI front end to it.? Can this be done in python?? What >>>> packages would allow me to do that? >>> >>> Here are a few of the GUI toolkit libraries in common use: >>> >>> ??? * tkinter (Tk) >>> ??? * PyQt (Qt) >>> ??? * PySide (Qt) >>> ??? * wxPython (wxWidgets) >>> ??? * PyGObject (GTK) >>> >>> tkinter is included in Python's standard library. >> > From ikorot01 at gmail.com Sat Apr 1 13:47:33 2023 From: ikorot01 at gmail.com (Igor Korot) Date: Sat, 1 Apr 2023 12:47:33 -0500 Subject: Windows Gui Frontend In-Reply-To: References: <9660a85e-00bd-5c6c-6be0-de6f4b6c8615@tompassin.net> Message-ID: Hi, Thomas, On Sat, Apr 1, 2023 at 12:40?PM Thomas Passin wrote: > > On 4/1/2023 1:28 PM, Thomas Passin wrote: > > On 4/1/2023 1:21 PM, Jim Schwartz wrote: > >> Are there any ide?s that will let me design the screen and convert it > >> to python? I doubt it because it was mentioned that this is time > >> consuming. > > > > Depends on what you mean by "let me design the screen", but Pyside > > (which I think is now called Pyside2) may be suitable. It is part the > > Qt framework. > > I should have added that in my experience, the screen layout of controls > is not the hardest and most time-consuming part of developing GUIs. The > hard part is getting the screen elements and other components to do what > you want in the way that you want it. > > For example, the Tk.Text class can be used as a fairly full-featured > editor, but try figuring out how to highlight part of the text - not so > obvious. Or say you decide you want to have a button flash when > clicked, but you don't like the standard flash effect and want to change > it. Those are a few of the kinds of things that you have to deal with > and that soak up the time. It's not usually screen design. I suggest going with wxPython/wxGlade. Thank you. > > >> > >> Sent from my iPhone > >> > >>> On Apr 1, 2023, at 10:37 AM, Eryk Sun wrote: > >>> > >>> ?On 4/1/23, Jim Schwartz wrote: > >>>> I have another question. I have an app written in python, but I > >>>> want to > >>>> add a windows GUI front end to it. Can this be done in python? What > >>>> packages would allow me to do that? > >>> > >>> Here are a few of the GUI toolkit libraries in common use: > >>> > >>> * tkinter (Tk) > >>> * PyQt (Qt) > >>> * PySide (Qt) > >>> * wxPython (wxWidgets) > >>> * PyGObject (GTK) > >>> > >>> tkinter is included in Python's standard library. > >> > > > > -- > https://mail.python.org/mailman/listinfo/python-list From maillist at schwertberger.de Sat Apr 1 13:47:50 2023 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Sat, 1 Apr 2023 19:47:50 +0200 Subject: Windows Gui Frontend In-Reply-To: References: Message-ID: <54420baf-d4f8-b64e-bd3c-f331e6cb3c73@schwertberger.de> On 01.04.2023 19:30, Igor Korot wrote: > Look at wxGlade (a project designed for wxWidgets). You will design > you layout and then just save it as a py file. wxGlade also includes a tutorial to get you started with wxPython itself. You should be able create basic GUIs within a few hours. See https://discuss.wxpython.org/ for support on wxPython and the wxGlade mailing list. Regards, Dietmar From ericfahlgren at gmail.com Sat Apr 1 14:33:32 2023 From: ericfahlgren at gmail.com (Eric Fahlgren) Date: Sat, 1 Apr 2023 11:33:32 -0700 Subject: [Python-Dev] Small lament... In-Reply-To: References: Message-ID: Oh, man, it has been a while. The last one I remember is PEP 404 (if you can find it :) ), dated 2011 and it wasn't an April Fool's... On Sat, Apr 1, 2023 at 11:23?AM Skip Montanaro wrote: > Just wanted to throw this out there... I lament the loss of waking up on > April 1st to see a creative April Fool's Day joke on one or both of these > lists, often from our FLUFL... Maybe such frivolity still happens, just not in > the Python ecosystem? I know you can still import "this" or > "antigravity", but those are now old (both introduced before 2010). When > was the last time a clever easter egg was introduced or an April Fool's Day > joke played? > > ?\_(?)_/? > > Skip > > _______________________________________________ > Python-Dev mailing list -- python-dev at python.org > To unsubscribe send an email to python-dev-leave at python.org > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at > https://mail.python.org/archives/list/python-dev at python.org/message/Q62W2Q6R6XMX57WK2CUGEENHMT3C3REF/ > Code of Conduct: http://python.org/psf/codeofconduct/ > From mats at wichmann.us Sat Apr 1 14:47:51 2023 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 1 Apr 2023 12:47:51 -0600 Subject: Windows Gui Frontend In-Reply-To: References: Message-ID: <29adf712-50c9-e705-e993-ee361b6bd80b@wichmann.us> On 4/1/23 11:34, Eryk Sun wrote: > On 4/1/23, Jim Schwartz wrote: >> Are there any ide?s that will let me design the screen and convert it to >> python? I doubt it because it was mentioned that this is time consuming. >> >> Thanks for the responses everyone. I appreciate it. > > For Qt, the WYSIWYG UI editor is Qt Designer. The basics are covered > in the following PySide tutorial: > > https://www.pythonguis.com/pyside2-tutorial Also here is a decent tutorial: https://realpython.com/qt-designer-python/ From eryksun at gmail.com Sat Apr 1 15:23:12 2023 From: eryksun at gmail.com (Eryk Sun) Date: Sat, 1 Apr 2023 14:23:12 -0500 Subject: [Python-Dev] Small lament... In-Reply-To: References: Message-ID: On 4/1/23, Skip Montanaro wrote: > Just wanted to throw this out there... I lament the loss of waking up on > April 1st to see a creative April Fool's Day joke on one or both of these > lists, often from our FLUFL... Maybe such frivolity still happens, just not > in the Python ecosystem? I thought this one was funny: https://github.com/python/cpython/issues/103172 From egon at frerich.eu Sat Apr 1 15:16:28 2023 From: egon at frerich.eu (Egon Frerich) Date: Sat, 1 Apr 2023 21:16:28 +0200 Subject: Windows Gui Frontend In-Reply-To: <027401d96491$7736dce0$65a496a0$@sbcglobal.net> References: <027401d96491$7736dce0$65a496a0$.ref@sbcglobal.net> <027401d96491$7736dce0$65a496a0$@sbcglobal.net> Message-ID: tkinter is part of python e. Am 01.04.23 um 13:59 schrieb Jim Schwartz: > I have another question. I have an app written in python, but I want to add > a windows GUI front end to it. Can this be done in python? What packages > would allow me to do that? > > > > Thanks. > From jschwar at sbcglobal.net Sat Apr 1 16:11:33 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Sat, 1 Apr 2023 15:11:33 -0500 Subject: [Python-Dev] Small lament... In-Reply-To: References: Message-ID: <02a801d964d6$28a4fae0$79eef0a0$@sbcglobal.net> Yea, it is funny. I commented on it. -----Original Message----- From: Python-list On Behalf Of Eryk Sun Sent: Saturday, April 1, 2023 2:23 PM To: Skip Montanaro Cc: Python ; python-dev Dev Subject: Re: [Python-Dev] Small lament... On 4/1/23, Skip Montanaro wrote: > Just wanted to throw this out there... I lament the loss of waking up > on April 1st to see a creative April Fool's Day joke on one or both of > these lists, often from our FLUFL... Maybe such frivolity still > happens, just not in the Python ecosystem? I thought this one was funny: https://github.com/python/cpython/issues/103172 -- https://mail.python.org/mailman/listinfo/python-list From barry at barrys-emacs.org Sat Apr 1 17:11:56 2023 From: barry at barrys-emacs.org (Barry Scott) Date: Sat, 1 Apr 2023 22:11:56 +0100 Subject: Windows Gui Frontend In-Reply-To: References: <9660a85e-00bd-5c6c-6be0-de6f4b6c8615@tompassin.net> Message-ID: <0A71B998-71D6-4E36-B551-5AA6824E7321@barrys-emacs.org> > On 1 Apr 2023, at 18:47, Igor Korot wrote: > > I suggest going with wxPython/wxGlade. I ported all my wxPython code to PyQt and have not regretted it. wxPython was (its been a while so may not be an issue now) far to hard to make consistent across OS, my apps run on Linux, macOS and Windows. I found that PyQt was easier to get working. Barry From list1 at tompassin.net Sat Apr 1 17:33:16 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 1 Apr 2023 17:33:16 -0400 Subject: Windows Gui Frontend In-Reply-To: <0A71B998-71D6-4E36-B551-5AA6824E7321@barrys-emacs.org> References: <9660a85e-00bd-5c6c-6be0-de6f4b6c8615@tompassin.net> <0A71B998-71D6-4E36-B551-5AA6824E7321@barrys-emacs.org> Message-ID: On 4/1/2023 5:11 PM, Barry Scott wrote: > > >> On 1 Apr 2023, at 18:47, Igor Korot wrote: >> >> I suggest going with wxPython/wxGlade. > > I ported all my wxPython code to PyQt and have not regretted it. > > wxPython was (its been a while so may not be an issue now) far to > hard to make consistent across OS, my apps run on Linux, macOS and Windows. > I found that PyQt was easier to get working. > > Barry > Having worked with both, I'd rather use PyQt, although Tk might be easier to get a toy app going with. Both editing windows and packing are easier for me to understand with PyQt, for one thing. OTOH, Qt isn't free for commercial use and the OP seems to be speculating on coming up with a product to sell at some point. From grant.b.edwards at gmail.com Sat Apr 1 18:22:50 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 01 Apr 2023 15:22:50 -0700 (PDT) Subject: Windows Gui Frontend References: <9660a85e-00bd-5c6c-6be0-de6f4b6c8615@tompassin.net> <0A71B998-71D6-4E36-B551-5AA6824E7321@barrys-emacs.org> Message-ID: <6428aeba.050a0220.b17f9.182c@mx.google.com> On 2023-04-01, Thomas Passin wrote: > Having worked with both, I'd rather use PyQt, although Tk might be > easier to get a toy app going with. Both editing windows and packing > are easier for me to understand with PyQt, for one thing. With tk it is _very_ easy to get small apps going. As the apps get larger and more complex, I find it easier to use wxPython or pyGTK (never tried pyQt). However, if you want to package that small app using cxfreeze (or whatever) tk tends to produce pretty large bundles compared to others. -- Grant From learn2program at gmail.com Sat Apr 1 19:13:36 2023 From: learn2program at gmail.com (Alan Gauld) Date: Sun, 2 Apr 2023 00:13:36 +0100 Subject: Windows Gui Frontend In-Reply-To: References: Message-ID: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> On 01/04/2023 18:21, Jim Schwartz wrote: > Are there any ide?s that will let me design the screen and convert it to python? There is nothing remotely like the VB or Delphi GUI builders. There are some tools somewhat similar to the Java Swing and FX GUI builders with varying degrees of bugginess. And there are a few bespoke GUI type tools such as Dabo for building specific types of applications. But most Python GUI developers seem to prefer to just hard code the Python, once you get used to it there's not much time saving with the GUI tools. The real time consuming stuff in building GUIs is getting the basic design right and keeping all the controls, keyboard bindings and menus in sync. State management in other words. I did a deep dive examination of GUI builders back around v2.6 and came away less than enthused. Things may have improved since then but I've seen no real evidence of that. -- 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 torriem at gmail.com Sat Apr 1 21:19:17 2023 From: torriem at gmail.com (Michael Torrie) Date: Sat, 1 Apr 2023 19:19:17 -0600 Subject: Windows Gui Frontend In-Reply-To: References: <9660a85e-00bd-5c6c-6be0-de6f4b6c8615@tompassin.net> <0A71B998-71D6-4E36-B551-5AA6824E7321@barrys-emacs.org> Message-ID: On 4/1/23 15:33, Thomas Passin wrote: > OTOH, Qt isn't free for commercial use and the OP seems to be > speculating on coming up with a product to sell at some point. Careful. That's not actually true, even though the marketing team at Qt lets people believe it is. Qt is licensed under the LGPL, which you can definitely use in a proprietary, close-source app, provided you use the dynamically-linked version (which PySide does of course) and do not modify it. Qt's commerical licensing is very hostile to small companies, I can say that much. It's too bad really. But the LGPL will work for most companies, except for those that might wish to use the embedded version, such as in cars where being able to abide by the terms of the LGPL becomes difficult. From Karsten.Hilbert at gmx.net Sun Apr 2 04:42:06 2023 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sun, 2 Apr 2023 10:42:06 +0200 Subject: Aw: Re: Windows Gui Frontend In-Reply-To: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> Message-ID: > The real time consuming stuff in building GUIs is getting > the basic design right and keeping all the controls, > keyboard bindings and menus in sync. State management > in other words. And cominmg up with sensible design choices _at all_. > I did a deep dive examination of GUI builders back around > v2.6 and came away less than enthused. Things may have > improved since then but I've seen no real evidence of > that. Is this available anywhere ? What GUI builders do (for me) is to make creating the GUI in a WYSIWYM way. Like LyX for LaTeX. Karsten From maillist at schwertberger.de Sun Apr 2 07:09:03 2023 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Sun, 2 Apr 2023 13:09:03 +0200 Subject: Windows Gui Frontend In-Reply-To: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> Message-ID: On 02.04.2023 01:13, Alan Gauld wrote: > I did a deep dive examination of GUI builders back around > v2.6 and came away less than enthused. Things may have > improved since then but I've seen no real evidence of > that. I also did evaluate all the GUI builder from time to time between 2000 and 2016 to find one that I could recommend to colleagues, but could not find one. Then I started contributing to wxGlade and I can say that since a few years it's as easy again to build GUIs as it was with VB6. I don't want to go back to coding GUIs manually. For most use cases it's a waste of time and often it does not result in the best GUI as it's not so easy to try out and rearrange elements. Regards, Dietmar From torriem at gmail.com Sun Apr 2 10:45:46 2023 From: torriem at gmail.com (Michael Torrie) Date: Sun, 2 Apr 2023 08:45:46 -0600 Subject: Windows Gui Frontend In-Reply-To: References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> Message-ID: On 4/2/23 05:09, Dietmar Schwertberger wrote: > I also did evaluate all the GUI builder from time to time between > 2000 and 2016 to find one that I could recommend to colleagues, > but could not find one. Then I started contributing to wxGlade > and I can say that since a few years it's as easy again to > build GUIs as it was with VB6. > > I don't want to go back to coding GUIs manually. For most use > cases it's a waste of time and often it does not result in the > best GUI as it's not so easy to try out and rearrange elements. But any modern GUI toolkit has sizers and layout managers. If you're manually placing elements you cannot deal with HiDPI or changing window sizes. Rearranging happens automatically when using sizers and layout managers. That said, the future of GUIs is declarative, using XAML or some other domain-specific language like QML. Examples of this include QtQuick (the long-term direction Qt is heading), and the various dot Net GUI toolkits now popular including MS' own MAUI, WPF, Avalonia. GUI designer tools (Qt Creator, Visual Studio) can be used to assist and help layout the skeleton, but ultimately the GUI is defined by code. And it works very well, is adaptive, and can automatically size and rearrange. If you want portability to mobile devices, this is where it's at. I've tried wxGlade but never could get into it, or wxWidgets in general. I used to use GTK a lot and did use Glade back then, and dynamically loaded the UI definition files at run time. Lately used more Qt with QtDesigner, and even extended Designer to support using some custom widgets I made. but the future of Qt is clearly QtQuick, so I've been learning that. Has its warts, but in general I like the declarative paradigm. It's a learning curve. Overall it's fairly powerful, flexible and portable. I have used the designer in Qt Creator a bit, but it's often faster and just as intuitive to write it in QML, since you're going to be dropping into QML frequently anyway to set properties (not unlike having to set widget properties in Qt Designer. So I guess it's 6s using the graphical designer vs straight Qt. From torriem at gmail.com Sun Apr 2 10:46:34 2023 From: torriem at gmail.com (Michael Torrie) Date: Sun, 2 Apr 2023 08:46:34 -0600 Subject: Windows Gui Frontend In-Reply-To: References: <027401d96491$7736dce0$65a496a0$.ref@sbcglobal.net> <027401d96491$7736dce0$65a496a0$@sbcglobal.net> Message-ID: <3194adf0-5c45-1732-af4a-5568931d3be3@gmail.com> On 4/1/23 09:37, Eryk Sun wrote: > Here are a few of the GUI toolkit libraries in common use: > > * tkinter (Tk) > * PyQt (Qt) > * PySide (Qt) > * wxPython (wxWidgets) > * PyGObject (GTK) > > tkinter is included in Python's standard library. Another good one is Kivy. Especially if you ever want to target mobile in the future. https://kivy.org/ From maillist at schwertberger.de Sun Apr 2 11:09:06 2023 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Sun, 2 Apr 2023 17:09:06 +0200 Subject: Windows Gui Frontend In-Reply-To: References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> Message-ID: <3bf17b63-674c-9cdb-3d01-af2dc5e95da3@schwertberger.de> On 02.04.2023 16:45, Michael Torrie wrote: > But any modern GUI toolkit has sizers and layout managers. If you're > manually placing elements you cannot deal with HiDPI or changing window > sizes. Rearranging happens automatically when using sizers and layout > managers. I did not talk about pixel placement with wxGlade. That's not supported. It's of course using sizers and with a hierarchy of sizers it's much easier to rearrange things than it would be with pixel placement. > GUI designer tools (Qt Creator, Visual Studio) can be used to assist and > help layout the skeleton, but ultimately the GUI is defined by code. And That's what I hated with Qt Designer: it does not output Python code but? a .ui file. This was the point where I could not recommend it to anyone. > I've tried wxGlade but never could get into it, or wxWidgets in general. Which version? Up to 0.7.2 I agree. > but the future of Qt is clearly QtQuick, so I've been learning that. > Has its warts, but in general I like the declarative paradigm. It's a > learning curve. Overall it's fairly powerful, flexible and portable. I For me QtQuick and QML are a step backwards by some ten years when it comes to development speed. It's as much 'fun' as doing GUIs with HTML and JavaScript. Unfortunately, The Qt Company refused to provide an API for QtQuick to be able to use it without QML. Anyway, desktop development has long moved out of their focus (around 15 years ago when Nokia acquired Trolltech). It's not where their commercial customers are. Regards, Dietmar From torriem at gmail.com Sun Apr 2 12:20:53 2023 From: torriem at gmail.com (Michael Torrie) Date: Sun, 2 Apr 2023 10:20:53 -0600 Subject: Windows Gui Frontend In-Reply-To: <3bf17b63-674c-9cdb-3d01-af2dc5e95da3@schwertberger.de> References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> <3bf17b63-674c-9cdb-3d01-af2dc5e95da3@schwertberger.de> Message-ID: On 2023-04-02 9:09 a.m., Dietmar Schwertberger wrote: > That's what I hated with Qt Designer: it does not output Python code > but? a .ui file. > This was the point where I could not recommend it to anyone. Well the thing is you don't need to generate Python code at all. Qt provides a UI loader class that loads the UI file at run time, builds the objects in memory, and connects all your signals for you. So much nicer than code generation. From torriem at gmail.com Sun Apr 2 12:26:32 2023 From: torriem at gmail.com (Michael Torrie) Date: Sun, 2 Apr 2023 10:26:32 -0600 Subject: Windows Gui Frontend In-Reply-To: <3bf17b63-674c-9cdb-3d01-af2dc5e95da3@schwertberger.de> References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> <3bf17b63-674c-9cdb-3d01-af2dc5e95da3@schwertberger.de> Message-ID: <93b76186-ec01-0d4a-4a03-e051d0e2beb8@gmail.com> On 2023-04-02 9:09 a.m., Dietmar Schwertberger wrote: >> I've tried wxGlade but never could get into it, or wxWidgets in general. > > Which version? Up to 0.7.2 I agree. Been a long time. I was initially turned off by the event handling system of wx compared to the signals and slots of Gtk and Qt. > For me QtQuick and QML are a step backwards by some ten years when > it comes to development speed. > It's as much 'fun' as doing GUIs with HTML and JavaScript. > Unfortunately, The Qt Company refused to provide an API for QtQuick to > be able to use it without QML. > Anyway, desktop development has long moved out of their focus > (around 15 years ago when Nokia acquired Trolltech). It's not where > their commercial customers are. There are a number of desktop apps built in QtQuick. KDE is transitioning to QtQuick and it's been alright, not without some consistency issues. The Cura slicer is another example of a complete desktop app written in QtQuick which looks and feels quite nicely on all platforms. For me, more and more I need to be able to run on mobile as well as desktop. Qt, GTK, or wx are just not good fits when you need that kind of portability. But traditional Qt will be with us or decades yet. From maillist at schwertberger.de Sun Apr 2 13:52:05 2023 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Sun, 2 Apr 2023 19:52:05 +0200 Subject: Windows Gui Frontend In-Reply-To: References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> <3bf17b63-674c-9cdb-3d01-af2dc5e95da3@schwertberger.de> Message-ID: <3c1e0abb-2bfb-33eb-5080-7b43c3f0cbec@schwertberger.de> On 02.04.2023 18:20, Michael Torrie wrote: >> Well the thing is you don't need to generate Python code at all. Qt >> provides a UI loader class that loads the UI file at run time, builds >> the objects in memory, and connects all your signals for you. I know, but having to load the .ui file is awkward. Even worse, you lose things like code completion. > So much > nicer than code generation. I absolutely disagree on this. Regards, Dietmar From maillist at schwertberger.de Sun Apr 2 14:02:49 2023 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Sun, 2 Apr 2023 20:02:49 +0200 Subject: Windows Gui Frontend In-Reply-To: <93b76186-ec01-0d4a-4a03-e051d0e2beb8@gmail.com> References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> <3bf17b63-674c-9cdb-3d01-af2dc5e95da3@schwertberger.de> <93b76186-ec01-0d4a-4a03-e051d0e2beb8@gmail.com> Message-ID: <781c6940-2499-5945-dce9-ef70cf2320eb@schwertberger.de> On 02.04.2023 18:26, Michael Torrie wrote: > Been a long time. I was initially turned off by the event handling > system of wx compared to the signals and slots of Gtk and Qt. When starting with Python GUIs in 1999, I evaluated both. Qt event handling had an advantage for C++ where the wxWidgets people had to use event tables. I don't know when wxWidgets added dynamic event binding, but with wxPython I don't know anything else than dynamic binding. Regards, Dietmar From ikorot01 at gmail.com Sun Apr 2 15:11:34 2023 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 2 Apr 2023 14:11:34 -0500 Subject: Windows Gui Frontend In-Reply-To: <781c6940-2499-5945-dce9-ef70cf2320eb@schwertberger.de> References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> <3bf17b63-674c-9cdb-3d01-af2dc5e95da3@schwertberger.de> <93b76186-ec01-0d4a-4a03-e051d0e2beb8@gmail.com> <781c6940-2499-5945-dce9-ef70cf2320eb@schwertberger.de> Message-ID: Hi, Dietmer, On Sun, Apr 2, 2023 at 1:14?PM Dietmar Schwertberger wrote: > > On 02.04.2023 18:26, Michael Torrie wrote: > > Been a long time. I was initially turned off by the event handling > > system of wx compared to the signals and slots of Gtk and Qt. > When starting with Python GUIs in 1999, I evaluated both. > Qt event handling had an advantage for C++ where the wxWidgets > people had to use event tables. I don't know when wxWidgets > added dynamic event binding, but with wxPython I don't know > anything else than dynamic binding. I think Bind() was added sometime in 2.9 as GSoC project. And https://docs.wxwidgets.org/latest/classwx_evt_handler.html#a3b4a42f7263fd0a257a996a078ef802f proves me correct: it is in "Since 2.9.0" Thank you. > > > Regards, > > Dietmar > > -- > https://mail.python.org/mailman/listinfo/python-list From grant.b.edwards at gmail.com Sun Apr 2 16:50:45 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 02 Apr 2023 13:50:45 -0700 (PDT) Subject: Windows Gui Frontend References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> Message-ID: <6429eaa5.5d0a0220.85d9d.247e@mx.google.com> On 2023-04-02, Michael Torrie wrote: > On 4/2/23 05:09, Dietmar Schwertberger wrote: >> I also did evaluate all the GUI builder from time to time between >> 2000 and 2016 to find one that I could recommend to colleagues, >> but could not find one. Then I started contributing to wxGlade >> and I can say that since a few years it's as easy again to >> build GUIs as it was with VB6. > > [...] > > But any modern GUI toolkit has sizers and layout managers. If you're > manually placing elements you cannot deal with HiDPI or changing window > sizes. Ah, that's the brilliant thing about VB6 apps! They only work properly on machines with the same resoultion and display/font configuration as the developer. -- Grant From PythonList at DancesWithMice.info Sun Apr 2 18:33:35 2023 From: PythonList at DancesWithMice.info (dn) Date: Mon, 3 Apr 2023 10:33:35 +1200 Subject: Windows Gui Frontend In-Reply-To: References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> Message-ID: <4d9d43b8-cdb7-12e9-ff8f-d7663e8da4fc@DancesWithMice.info> On 03/04/2023 02.45, Michael Torrie wrote: > On 4/2/23 05:09, Dietmar Schwertberger wrote: >> I also did evaluate all the GUI builder from time to time between >> 2000 and 2016 to find one that I could recommend to colleagues, >> but could not find one. Then I started contributing to wxGlade >> and I can say that since a few years it's as easy again to >> build GUIs as it was with VB6. >> >> I don't want to go back to coding GUIs manually. For most use >> cases it's a waste of time and often it does not result in the >> best GUI as it's not so easy to try out and rearrange elements. > > But any modern GUI toolkit has sizers and layout managers. If you're > manually placing elements you cannot deal with HiDPI or changing window > sizes. Rearranging happens automatically when using sizers and layout > managers. > > That said, the future of GUIs is declarative, using XAML or some other > domain-specific language like QML. Examples of this include QtQuick > (the long-term direction Qt is heading), and the various dot Net GUI > toolkits now popular including MS' own MAUI, WPF, Avalonia. > > GUI designer tools (Qt Creator, Visual Studio) can be used to assist and > help layout the skeleton, but ultimately the GUI is defined by code. And > it works very well, is adaptive, and can automatically size and > rearrange. If you want portability to mobile devices, this is where it's at. > > I've tried wxGlade but never could get into it, or wxWidgets in general. > I used to use GTK a lot and did use Glade back then, and dynamically > loaded the UI definition files at run time. Lately used more Qt with > QtDesigner, and even extended Designer to support using some custom > widgets I made. > > but the future of Qt is clearly QtQuick, so I've been learning that. > Has its warts, but in general I like the declarative paradigm. It's a > learning curve. Overall it's fairly powerful, flexible and portable. I > have used the designer in Qt Creator a bit, but it's often faster and > just as intuitive to write it in QML, since you're going to be dropping > into QML frequently anyway to set properties (not unlike having to set > widget properties in Qt Designer. So I guess it's 6s using the > graphical designer vs straight Qt. Do the two approaches acknowledge each other and enable 'round tripping'? ie to use the best?better tool for particular jobs (and to cope with later-maintenance) can one start using one approach, switch to using the other, and then go back to the first? -- Regards, =dn From rolfblum at ewe.net Mon Apr 3 05:09:55 2023 From: rolfblum at ewe.net (Rolf Blum) Date: Mon, 3 Apr 2023 11:09:55 +0200 Subject: Windows Gui Frontend In-Reply-To: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> Message-ID: <0908f575-f8e7-c152-2eb2-ead7d70a9fdb@ewe.net> Am 02.04.2023 um 01:13 schrieb Alan Gauld: > On 01/04/2023 18:21, Jim Schwartz wrote: >> Are there any ide?s that will let me design the screen and convert it to python? > > There is nothing remotely like the VB or Delphi GUI builders. The latest Delphi versions themself can create GUIs for Python. I use Delphi 10.4.2 (Sidney) Professional. From pranavbhardwaj773 at gmail.com Mon Apr 3 12:40:02 2023 From: pranavbhardwaj773 at gmail.com (Pranav Bhardwaj) Date: Mon, 3 Apr 2023 22:10:02 +0530 Subject: Problem in using libraries Message-ID: Why can't I able to use python libraries such as numpy, nudenet, playsound, in python 3.11.2 From pranavbhardwaj773 at gmail.com Mon Apr 3 12:43:37 2023 From: pranavbhardwaj773 at gmail.com (Pranav Bhardwaj) Date: Mon, 3 Apr 2023 22:13:37 +0530 Subject: Problem in using libraries Message-ID: Why can't I able to use python libraries such as numpy, nudenet, playsound, pandas, etc in my python 3.11.2. It always through the error "import 'numpy' or any other libraries could not be resolved". From barry at barrys-emacs.org Mon Apr 3 13:05:16 2023 From: barry at barrys-emacs.org (Barry) Date: Mon, 3 Apr 2023 18:05:16 +0100 Subject: Problem in using libraries In-Reply-To: References: Message-ID: <50F3597C-722D-4909-8553-B90C9CF97EFF@barrys-emacs.org> > On 3 Apr 2023, at 17:46, Pranav Bhardwaj wrote: > > ?Why can't I able to use python libraries such as numpy, nudenet, playsound, > pandas, etc in my python 3.11.2. It always through the error "import > 'numpy' or any other libraries could not be resolved". You need to provide enough details for people to help you. Include which OS you are using. Where you got python from. How you installed the libraries you are trying to use. Commands and error messages you are seeing. Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From bowman at montana.com Sat Apr 1 16:26:01 2023 From: bowman at montana.com (rbowman) Date: 1 Apr 2023 20:26:01 GMT Subject: Windows Gui Frontend References: <027401d96491$7736dce0$65a496a0$.ref@sbcglobal.net> <027401d96491$7736dce0$65a496a0$@sbcglobal.net> Message-ID: On Sat, 1 Apr 2023 10:37:34 -0500, Eryk Sun wrote: > On 4/1/23, Jim Schwartz wrote: >> I have another question. I have an app written in python, but I want >> to add a windows GUI front end to it. Can this be done in python? >> What packages would allow me to do that? > > Here are a few of the GUI toolkit libraries in common use: > > * tkinter (Tk) > * PyQt (Qt) > * PySide (Qt) > * wxPython (wxWidgets) > * PyGObject (GTK) > > tkinter is included in Python's standard library. Not to go into a lot of history, if this is a commercial application, go with PySide rather than PyQt. They are very close, if not identical, until you get to licensing. From bowman at montana.com Sat Apr 1 22:26:14 2023 From: bowman at montana.com (rbowman) Date: 2 Apr 2023 02:26:14 GMT Subject: Windows Gui Frontend References: <9660a85e-00bd-5c6c-6be0-de6f4b6c8615@tompassin.net> <0A71B998-71D6-4E36-B551-5AA6824E7321@barrys-emacs.org> Message-ID: On Sat, 1 Apr 2023 19:19:17 -0600, Michael Torrie wrote: > Qt's commerical licensing is very hostile to small companies, I can say > that much. It's too bad really. But the LGPL will work for most > companies, except for those that might wish to use the embedded version, > such as in cars where being able to abide by the terms of the LGPL > becomes difficult. Even when the trolls had it the arcane requirements for commercial licensing drove many away. I sometimes think 'Side' is actually Finnish for 'up yours, Riverbank Computing'. From bowman at montana.com Sun Apr 2 16:55:57 2023 From: bowman at montana.com (rbowman) Date: 2 Apr 2023 20:55:57 GMT Subject: Windows Gui Frontend References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> <3bf17b63-674c-9cdb-3d01-af2dc5e95da3@schwertberger.de> <3c1e0abb-2bfb-33eb-5080-7b43c3f0cbec@schwertberger.de> Message-ID: On Sun, 2 Apr 2023 19:52:05 +0200, Dietmar Schwertberger wrote: > On 02.04.2023 18:20, Michael Torrie wrote: >>> Well the thing is you don't need to generate Python code at all. Qt >>> provides a UI loader class that loads the UI file at run time, builds >>> the objects in memory, and connects all your signals for you. > > I know, but having to load the .ui file is awkward. > Even worse, you lose things like code completion. One advantage is customization. It's not Python but we use a GUI system that supports uids. The underlying data is the same but some clients may not want certain fields or want them labeled or arranged differently. From bowman at montana.com Sun Apr 2 23:29:43 2023 From: bowman at montana.com (rbowman) Date: 3 Apr 2023 03:29:43 GMT Subject: Windows Gui Frontend References: <514b86e4-a956-cd9e-d45f-6dc0aee6d2a5@yahoo.co.uk> <6429eaa5.5d0a0220.85d9d.247e@mx.google.com> Message-ID: On Sun, 02 Apr 2023 13:50:45 -0700 (PDT), Grant Edwards wrote: > On 2023-04-02, Michael Torrie wrote: >> On 4/2/23 05:09, Dietmar Schwertberger wrote: >>> I also did evaluate all the GUI builder from time to time between 2000 >>> and 2016 to find one that I could recommend to colleagues, but could >>> not find one. Then I started contributing to wxGlade and I can say >>> that since a few years it's as easy again to build GUIs as it was with >>> VB6. >> >> [...] >> >> But any modern GUI toolkit has sizers and layout managers. If you're >> manually placing elements you cannot deal with HiDPI or changing window >> sizes. > > Ah, that's the brilliant thing about VB6 apps! They only work properly > on machines with the same resoultion and display/font configuration as > the developer. VB6 isn't the only thing that goes to hell in a hand basket when you start playing around with fonts and resolutions. If I were emperor of the world there would only be monospaced fonts and a limited selection of those. From andreas.eisele at gmail.com Sat Apr 1 11:16:46 2023 From: andreas.eisele at gmail.com (Andreas Eisele) Date: Sat, 1 Apr 2023 08:16:46 -0700 (PDT) Subject: built-in pow() vs. math.pow() In-Reply-To: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> References: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> Message-ID: Andreas Eisele schrieb am Donnerstag, 30. M?rz 2023 um 11:16:02 UTC+2: > I sometimes make use of the fact that the built-in pow() function has an optional third argument for modulo calculation, which is handy when dealing with tasks from number theory, very large numbers, problems from Project Euler, etc. I was unpleasantly surprised that math.pow() does not have this feature, hence "from math import *" overwrites the built-in pow() function with a function that lacks functionality. I am wondering for the rationale of this. Does math.pow() do anything that the built-in version can not do, and if not, why is it even there? > Thanks in advance for any enlightening comment on this. > Best regards, Andreas Thanks a lot to all of you for the insightful replies! I now understand why math.pow() behaves the way it does and whoever tells me I should have read the doc of the math module before using it is 100% on point. BTW, there is another difference: built-in pow() deals with complex arguments, while functions in math won't accept them at all. I also agree with the warning that importing * from any module is generally a bad idea, and I normally would not do it. But here I had written a little tool that evaluates an expression given on the command line, and in this case having math functions available without further ado is very convenient, so it seemed appropriate to make an exeption to this rule. I ended up assigning the built-in pow function to a different name before importing the math module, which is a good way to keep both variants accessible. Best regards, and thanks again, Andreas From skip.montanaro at gmail.com Sat Apr 1 14:19:54 2023 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 1 Apr 2023 13:19:54 -0500 Subject: Small lament... Message-ID: Just wanted to throw this out there... I lament the loss of waking up on April 1st to see a creative April Fool's Day joke on one or both of these lists, often from our FLUFL... Maybe such frivolity still happens, just not in the Python ecosystem? I know you can still import "this" or "antigravity", but those are now old (both introduced before 2010). When was the last time a clever easter egg was introduced or an April Fool's Day joke played? ?\_(?)_/? Skip From jfong at ms4.hinet.net Sat Apr 1 22:12:58 2023 From: jfong at ms4.hinet.net (Jach Feng) Date: Sat, 1 Apr 2023 19:12:58 -0700 (PDT) Subject: Windows Gui Frontend In-Reply-To: References: <027401d96491$7736dce0$65a496a0$.ref@sbcglobal.net> <027401d96491$7736dce0$65a496a0$@sbcglobal.net> Message-ID: Jim Schwartz ? 2023?4?1? ?????8:00:19 [UTC+8] ?????? > I have another question. I have an app written in python, but I want to add > a windows GUI front end to it. Can this be done in python? What packages > would allow me to do that? > > > > Thanks. There is a GUI Generator for tkinter https://page.sourceforge.net/ --Jach From aewindhorn at gmail.com Sun Apr 2 15:05:04 2023 From: aewindhorn at gmail.com (windhorn) Date: Sun, 2 Apr 2023 12:05:04 -0700 (PDT) Subject: Python file location In-Reply-To: <87355mpxrc.fsf@debian-BULLSEYE-live-builder-AMD64> References: <4f75241c-3396-4b0d-a3c8-92895aaf3ef9n@googlegroups.com> <87355mpxrc.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: <56ad2eea-abe6-4a9a-8e09-bedfc74ce98an@googlegroups.com> Thanks to all for suggestions. Linux has "too much freedom" :-) Regards, Allen From garyfallidis at gmail.com Sun Apr 2 21:35:34 2023 From: garyfallidis at gmail.com (Eleftherios Garyfallidis) Date: Sun, 2 Apr 2023 21:35:34 -0400 Subject: Hurry up! Book your spot for the DIPY Workshop in LA! April 24-28 2023!! Message-ID: Dear all, Only a few spots are left. Register now: https://dipy.org/workshops/latest !!! The complete program for the highly anticipated workshop is updated and available in the link above. DIPY is a powerful software library for analyzing and processing diffusion MRI data. It is an open-source project with a large and active community of contributors who are dedicated to advancing the field of medical imaging. The DIPY workshop provides an excellent opportunity for individuals to learn how to use this software effectively. The workshop covers a broad range of topics, from basic concepts to advanced techniques, and provides hands-on experience with the software. By attending the DIPY workshop, you will not only learn how to use this powerful tool, but also gain a deeper understanding of diffusion imaging and machine learning for imaging in general. The workshop is led by expert instructors who have extensive experience in both diffusion imaging and DIPY, so attendees can be confident that they are receiving accurate and up-to-date information. [image: image.png] In summary, the workshop offers: - Hands-on tutorials - Every single day of the 5 days !!! - Guided practice sessions (bring your data - optional) - Personalized certificates of attendance - Effective networking opportunities with one-to-one follow ups - Comprehensive explanation of theoretical foundations with practical examples - Access to latest and established methods with code and interfaces - Pointers to move beyond the current challenges and navigate hard to do analyses - Multiple clinical use cases (AZ, Parkinson?s etc.) See above one of the many highlights of the workshop. Building synthetic b0s (with Synb0) in DIPY 1.7.0! More highlights here . Please allow us to finish this email with a testimonial from one of our last in person workshops: This one is from an expert neuropsychologist: ?In recent years, I've found that many scientific conferences have become plagued with pitfalls such as repetitive content, superficial networking, and a focus on self-promotion rather than genuine knowledge exchange. Attendees often leave these events with a sense of disillusionment, feeling that their time could have been better spent elsewhere. The DIPY workshop, however, was a breath of fresh air in this sea of mediocrity. It was highly interactive, engaging, and hands-on, with a genuine emphasis on learning and collaboration. The organizers went above and beyond to create a welcoming and supportive environment, encouraging researchers of all backgrounds and expertise levels to contribute their ideas and gain valuable insights. By addressing the shortcomings of traditional conferences, the DIPY workshop has rekindled my enthusiasm for scientific events and has set a new standard for what a truly productive and inspiring gathering should be.? We kept our promise! Get your tickets! See you in the workshop! Eleftherios Garyfallidis, PhD Associate Professor Intelligent Systems Engineering Indiana University Luddy Hall 700 N Woodlawn Bloomington, IN 47408 DIPY | FURY From list1 at tompassin.net Mon Apr 3 13:25:48 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 3 Apr 2023 13:25:48 -0400 Subject: Problem in using libraries In-Reply-To: References: Message-ID: <1f02be62-1a33-72dc-e259-5c24be15801a@tompassin.net> On 4/3/2023 12:43 PM, Pranav Bhardwaj wrote: > Why can't I able to use python libraries such as numpy, nudenet, playsound, > pandas, etc in my python 3.11.2. It always through the error "import > 'numpy' or any other libraries could not be resolved". You need to realize that no one can help you without some specific information. You have not told us anything. You might as well have said, if your car didn't start, "My car won't run. Why can't I start it?. Let's start with the most obvious thing - are those libraries installed? If not, install them. If you think they have been installed, then tell us how you installed them and how you know they have been successfully installed *for the version of python* you are trying to use. Let's take numpy. The standard way to install it is using pip. You have to make sure that you run the pip program that goes with the version of Python you plan to use. I'm going to assume that if you type "py" (without quotes), you will get that version. If not, use the command you have been using to run Python 3.11. On my system: C:\Users\tom>py -V Python 3.10.9 C:\Users\tom>py -m pip show numpy Name: numpy Version: 1.23.4 Summary: NumPy is the fundamental package for array computing with Python. Home-page: https://www.numpy.org Author: Travis E. Oliphant et al. Author-email: License: BSD Location: c:\users\tom\appdata\local\programs\python\python310\lib\site-packages Requires: Required-by: bokeh, causal-curve, cftime, contourpy, csaps, dcor, emd, frechetdist, imageio, localreg, matplotlib, mizani, netCDF4, numba, pandas, patsy, plotnine, pwlf, pyDOE, pygam, PyWavelets, scaleogram, scikit-image, scikit-learn, scipy, seaborn, sparse, statsforecast, statsmodels, tifffile If a library is not installed (I'll use a non-existent library name) - C:\Users\tom>py -m pip show numpyx WARNING: Package(s) not found: numpyx To install numpy with pip *for that version of Python* - py -m pip install numpy (or a form you may see sometimes: py -m install --user numpy) Please reply with this information. From 2QdxY4RzWzUUiLuE at potatochowder.com Mon Apr 3 15:49:45 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Mon, 3 Apr 2023 15:49:45 -0400 Subject: built-in pow() vs. math.pow() In-Reply-To: References: <831c6c1c-c4ee-4a59-bba8-d8c2df0e982cn@googlegroups.com> Message-ID: On 2023-04-01 at 08:16:46 -0700, Andreas Eisele wrote: > BTW, there is another difference: built-in pow() deals with complex > arguments, while functions in math won't accept them at all. See also . From pranavbhardwaj773 at gmail.com Mon Apr 3 13:25:55 2023 From: pranavbhardwaj773 at gmail.com (pranavbhardwaj773 at gmail.com) Date: Mon, 3 Apr 2023 22:55:55 +0530 Subject: problems in using libraries Message-ID: <2C2C8CB8-F09B-44B7-BA2C-CA9096CF0ACB@hxcore.ol> ? ? Sent from [1]Mail for Windows Why can't I able to use python libraries in my python 3.11.2. It always throw an error such as ? and and many more. I installed python from python official website and I installed libraries using cmd prompt by typing- pip install ?Library name? References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From guido at python.org Mon Apr 3 20:14:36 2023 From: guido at python.org (Guido van Rossum) Date: Mon, 3 Apr 2023 17:14:36 -0700 Subject: [Python-Dev] Small lament... In-Reply-To: References: Message-ID: A bit late, this reached my inbox: https://peternorvig.medium.com/new-python-operators-9f31b56ddcc7 On Sat, Apr 1, 2023 at 11:23?AM Skip Montanaro wrote: > Just wanted to throw this out there... I lament the loss of waking up on > April 1st to see a creative April Fool's Day joke on one or both of these > lists, often from our FLUFL... Maybe such frivolity still happens, just not in > the Python ecosystem? I know you can still import "this" or > "antigravity", but those are now old (both introduced before 2010). When > was the last time a clever easter egg was introduced or an April Fool's Day > joke played? > > ?\_(?)_/? > > Skip > > _______________________________________________ > Python-Dev mailing list -- python-dev at python.org > To unsubscribe send an email to python-dev-leave at python.org > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at > https://mail.python.org/archives/list/python-dev at python.org/message/Q62W2Q6R6XMX57WK2CUGEENHMT3C3REF/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* From barry at python.org Mon Apr 3 20:31:29 2023 From: barry at python.org (Barry Warsaw) Date: Mon, 3 Apr 2023 17:31:29 -0700 Subject: [Python-Dev] Small lament... In-Reply-To: References: Message-ID: I heard it on reasonably believable authority that the FLUFL took the year off. Lamentable. -Barry > On Apr 1, 2023, at 11:19, Skip Montanaro wrote: > > Just wanted to throw this out there... I lament the loss of waking up on April 1st to see a creative April Fool's Day joke on one or both of these lists, often from our FLUFL... Maybe such frivolity still happens, just not in the Python ecosystem? I know you can still import "this" or "antigravity", but those are now old (both introduced before 2010). When was the last time a clever easter egg was introduced or an April Fool's Day joke played? > > ?\_(?)_/? > > Skip > > _______________________________________________ > Python-Dev mailing list -- python-dev at python.org > To unsubscribe send an email to python-dev-leave at python.org > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at https://mail.python.org/archives/list/python-dev at python.org/message/Q62W2Q6R6XMX57WK2CUGEENHMT3C3REF/ > Code of Conduct: http://python.org/psf/codeofconduct/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: Message signed with OpenPGP URL: From avi.e.gross at gmail.com Mon Apr 3 22:09:02 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Mon, 3 Apr 2023 22:09:02 -0400 Subject: [Python-Dev] Small lament... In-Reply-To: References: Message-ID: <003801d9669a$6d8a09a0$489e1ce0$@gmail.com> Sadly, between Daylight Savings time and a newer irrational PI ? Day, I am afraid some April Foolers got thrown off albeit some may shower us with nonsense in May I. -----Original Message----- From: Python-list On Behalf Of Barry Warsaw Sent: Monday, April 3, 2023 8:31 PM To: Skip Montanaro Cc: Python ; Python Dev Subject: Re: [Python-Dev] Small lament... I heard it on reasonably believable authority that the FLUFL took the year off. Lamentable. -Barry > On Apr 1, 2023, at 11:19, Skip Montanaro wrote: > > Just wanted to throw this out there... I lament the loss of waking up on April 1st to see a creative April Fool's Day joke on one or both of these lists, often from our FLUFL... Maybe such frivolity still happens, just not in the Python ecosystem? I know you can still import "this" or "antigravity", but those are now old (both introduced before 2010). When was the last time a clever easter egg was introduced or an April Fool's Day joke played? > > ?\_(?)_/? > > Skip > > _______________________________________________ > Python-Dev mailing list -- python-dev at python.org > To unsubscribe send an email to python-dev-leave at python.org > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at https://mail.python.org/archives/list/python-dev at python.org/message/Q62W2Q6R6XMX57WK2CUGEENHMT3C3REF/ > Code of Conduct: http://python.org/psf/codeofconduct/ From list1 at tompassin.net Mon Apr 3 22:16:44 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 3 Apr 2023 22:16:44 -0400 Subject: problems in using libraries In-Reply-To: <2C2C8CB8-F09B-44B7-BA2C-CA9096CF0ACB@hxcore.ol> References: <2C2C8CB8-F09B-44B7-BA2C-CA9096CF0ACB@hxcore.ol> Message-ID: <9ca67f8b-9fc7-3d99-716f-79f3d53a4b1c@tompassin.net> On 4/3/2023 1:25 PM, pranavbhardwaj773 at gmail.com wrote: > > > > > Sent from [1]Mail for Windows > > Why can't I able to use python libraries in my python 3.11.2. It always > throw an error such as > > and > > and many more. > > I installed python from python official website and I installed libraries > using cmd prompt by typing- pip install ?Library name? You have not done what I suggested that you do in my last post. As I recall from earlier messages, you have several versions of Python installed. You have to be sure that when you run "pip" it is being run by the version of Python that you want. I asked you to check that and gave you examples of how. So please do that. From PythonList at DancesWithMice.info Mon Apr 3 22:30:47 2023 From: PythonList at DancesWithMice.info (dn) Date: Tue, 4 Apr 2023 14:30:47 +1200 Subject: [Python-Dev] Small lament... In-Reply-To: References: Message-ID: <813ab8ad-3aae-59cf-acd5-b7b5e144852a@DancesWithMice.info> On 04/04/2023 12.14, Guido van Rossum wrote: > A bit late, this reached my inbox: > https://peternorvig.medium.com/new-python-operators-9f31b56ddcc7 Did you notice that Peter Norvig's factorial-operator attempts to replace one of the very first diamond-grade provisions of [the] FLUFL? Disgraceful behavior! So disrespectful! Send him to the Spanish Inquisition... Saying that, he (Peter) lost the opportunity to promote our new dev.movement. As he pointed-out, tests are likely to give one a false sense of security with regard to the correctness of code. Accordingly, join us in the noTDD philosophy. Like NoSQL is schema-less, noTDD is scheme-less (we have NO idea what we're doing). Don't be led-astray by tests. We're all [adult-]optimists here... > On Sat, Apr 1, 2023 at 11:23?AM Skip Montanaro > wrote: > >> Just wanted to throw this out there... I lament the loss of waking up on >> April 1st to see a creative April Fool's Day joke on one or both of these >> lists, often from our FLUFL... Maybe such frivolity still happens, just not in >> the Python ecosystem? I know you can still import "this" or >> "antigravity", but those are now old (both introduced before 2010). When >> was the last time a clever easter egg was introduced or an April Fool's Day >> joke played? >> >> ?\_(?)_/? >> >> Skip >> >> _______________________________________________ >> Python-Dev mailing list -- python-dev at python.org >> To unsubscribe send an email to python-dev-leave at python.org >> https://mail.python.org/mailman3/lists/python-dev.python.org/ >> Message archived at >> https://mail.python.org/archives/list/python-dev at python.org/message/Q62W2Q6R6XMX57WK2CUGEENHMT3C3REF/ >> Code of Conduct: http://python.org/psf/codeofconduct/ >> > > -- Regards, =dn From greg.ewing at canterbury.ac.nz Tue Apr 4 04:22:50 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 4 Apr 2023 20:22:50 +1200 Subject: [Python-Dev] Small lament... In-Reply-To: References: <003801d9669a$6d8a09a0$489e1ce0$@gmail.com> Message-ID: On 4/04/23 2:09 pm, avi.e.gross at gmail.com wrote: > Sadly, between Daylight Savings time and a newer irrational PI ? Day, I am afraid some April Foolers got thrown off albeit some may shower us with nonsense in May I. Pi day isn't responsible, but it is because of changes to daylight saving. The International Bureau of Weights and Measures announced that, in order to gain a few more days of summer weather, all clocks would be put back by 96 hours at midnight on 31 March 2023. So April 1 is now occurring on what would have been April 4. Expect the usual torrent of silliness to arrive shortly. -- Greg From ssfirodia at gmail.com Tue Apr 4 07:44:19 2023 From: ssfirodia at gmail.com (Sumeet Firodia) Date: Tue, 4 Apr 2023 17:14:19 +0530 Subject: Python not showing correct version In-Reply-To: References: <34dcfb4d-28ed-0d26-8816-826fd63c1848@tompassin.net> <4F251711-2F64-4B29-8E23-16E792C23009@barrys-emacs.org> Message-ID: So I disabled the manage app execution for python 3.10, created the py.ini file and executed setx.exe PY_PYTHON 3.8, setx.exe PY_PYTHON3 3.8. After that i uninstalled 3.8 and reinstalled and now the version is showing correctly. Thanks everyone for the help. Thanks Sumeet On Sat, 1 Apr 2023 at 20:40, Eryk Sun wrote: > On 4/1/23, Barry Scott wrote: > > > > I find user environment on windows to be less flexible to work with then > > adding a py.ini. On my Windows 11 I added > > %userprofile%\AppData\Local\py.ini. > > To make python 3.8 the default that py.exe uses put this in py.ini: > > > > [defaults] > > python=3.8-64 > > python3=3.8-64 > > Using "py.ini" has the advantage that launcher always reads the file. > The value of the environment variables, on the other hand, may be > stale. If you keep a lot of shells running, it would be tedious to > have to manually update the PY_PYTHON* variables in each shell. That > said, it should be rare that one needs to change the persisted default > versions. For temporary changes, the PY_PYTHON* environment variables > are more flexible and take precedence over "py.ini". > > If one doesn't use "py.ini" to set the defaults, it's easy to modify > the persisted user environment using "setx.exe"[^1]. For example: > > setx.exe PY_PYTHON 3.8 > setx.exe PY_PYTHON3 3.8 > > setx.exe broadcasts a WM_SETTINGCHANGE "Environment" window message, > which causes Explorer to update its environment. Thus any program run > from Explorer will see the new values. A program launched in a new tab > in Windows Terminal also gets a fresh environment. However, existing > CLI shells (CMD, PowerShell, bash), and programs started by them, will > still have the old environment values. The latter is where using > "py.ini" to set the defaults has the advantage. > > --- > > [^1]: Note that "setx.exe" should never be used to set the persisted > user or machine "Path" value to the current %PATH%. When loading the > environment, the user "Path" gets appended to the machine "Path". > Setting the entire expanded and concatenated value to one or the other > leads to a bloated, redundant PATH value, and it also loses the > flexible configuration based on REG_EXPAND_SZ values. > -- > https://mail.python.org/mailman/listinfo/python-list > From jschwar at sbcglobal.net Tue Apr 4 11:25:34 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Tue, 4 Apr 2023 10:25:34 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: References: <01fd01d963c8$547e9090$fd7bb1b0$.ref@sbcglobal.net> <01fd01d963c8$547e9090$fd7bb1b0$@sbcglobal.net> Message-ID: <01a501d96709$b3f86f70$1be94e50$@sbcglobal.net> Where can I download that cl program? I've used gcc before, but I hear that cl can use a setup.py program to run the compile and link and create a windows .msi installer. Is that true? -----Original Message----- From: Eryk Sun Sent: Friday, March 31, 2023 12:55 PM To: Jim Schwartz Cc: python-list at python.org Subject: Re: Windows installer from python source code without access to source code On 3/31/23, Jim Schwartz wrote: > I want a windows installer to install my application that's written in > python, but I don't want the end user to have access to my source code. Cython can compile a script to C source code for a module or executable (--embed). The source can be compiled and linked normally. For example, the following builds a "hello.exe" executable based on a "hello.py" script. > cython -3 --embed hello.py > set "PYI=C:\Program Files\Python311\include" > set "PYL=C:\Program Files\Python311\libs" > cl /I"%PYI%" hello.c /link /libpath:"%PYL%" > copy hello.exe embed > embed\hello.exe Hello, World! I extracted the complete embeddable distribution of Python 3.11 into the "embed" directory. You can reduce the size of the installation, if needed, by minimizing the zipped standard library and removing pyd extensions and DLLs that your application doesn't use. The generated "hello.c" is large and not particularly easy to read, but here are some snippets [...]: [...] /* Implementation of 'hello' */ static PyObject *__pyx_builtin_print; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_print[] = "print"; static const char __pyx_k_Hello_World[] = "Hello, World!"; [...] /* "hello.py":1 * print("Hello, World!") # <<<<<<<<<<<<<< */ __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Hello_World); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 1, __pyx_L1_error) [...] /* "hello.py":1 * print("Hello, World!") # <<<<<<<<<<<<<< */ __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) [...] int wmain(int argc, wchar_t **argv) { [...] if (argc && argv) Py_SetProgramName(argv[0]); Py_Initialize(); if (argc && argv) PySys_SetArgv(argc, argv); [...] m = PyInit_hello(); [...] if (Py_FinalizeEx() < 0) return 2; [...] return 0; [...] From loris.bennett at fu-berlin.de Tue Apr 4 07:58:24 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Tue, 04 Apr 2023 13:58:24 +0200 Subject: When is logging.getLogger(__name__) needed? References: <877cux2hy0.fsf@hornfels.zedat.fu-berlin.de> <3783122a-28d9-776d-b4d1-979cb1d3ac1d@web.de> Message-ID: <87edozamfz.fsf@debian-BULLSEYE-live-builder-AMD64> Peter Otten <__peter__ at web.de> writes: > On 31/03/2023 15:01, Loris Bennett wrote: [snip (53 lines)] > Your problem has nothing to do with logging -- it's about visibility > ("scope") of names: > >>>> def use_name(): > print(name) > > >>>> def define_name(): > name = "Loris" > > >>>> use_name() > Traceback (most recent call last): > File "", line 1, in > use_name() > File "", line 2, in use_name > print(name) > NameError: name 'name' is not defined > > Binding (=assigning to) a name inside a function makes it local to that > function. If you want a global (module-level) name you have to say so: > >>>> def define_name(): > global name > name = "Peter" > > >>>> define_name() >>>> use_name() > Peter Thanks for the example and reminding me about Python's scopes. With global name def use_name(): print(name) def define_name(): name = "Peter" define_name() use_name() I was initially surprised by the following error: ~/tmp $ python3 global.py Traceback (most recent call last): File "/home/loris/tmp/global.py", line 10, in use_name() File "/home/loris/tmp/global.py", line 4, in use_name print(name) NameError: name 'name' is not defined but I was misinterpreting global name to mean define a global variable 'name' whereas it actually seems to mean more like use the global variable 'name' Correct? -- This signature is currently under constuction. From dieter at handshake.de Tue Apr 4 13:32:24 2023 From: dieter at handshake.de (Dieter Maurer) Date: Tue, 4 Apr 2023 19:32:24 +0200 Subject: Problem in using libraries In-Reply-To: References: Message-ID: <25644.24360.366268.46518@ixdm.fritz.box> Pranav Bhardwaj wrote at 2023-4-3 22:13 +0530: >Why can't I able to use python libraries such as numpy, nudenet, playsound, >pandas, etc in my python 3.11.2. It always through the error "import >'numpy' or any other libraries could not be resolved". The "libraries" you speak of are extensions (i.e. not part of the Python download). Extensions are Python minor version specific. You must install them for each Python minor version. E.g. you can use an extension installation for Python 3.10 for any Python 3.10.x, but you must install it again for Python 3.11. From barry at barrys-emacs.org Tue Apr 4 14:25:24 2023 From: barry at barrys-emacs.org (Barry) Date: Tue, 4 Apr 2023 19:25:24 +0100 Subject: Windows installer from python source code without access to source code In-Reply-To: <01a501d96709$b3f86f70$1be94e50$@sbcglobal.net> References: <01a501d96709$b3f86f70$1be94e50$@sbcglobal.net> Message-ID: <79F9B803-CE16-418C-B5CA-E88155DD42C5@barrys-emacs.org> > On 4 Apr 2023, at 16:28, Jim Schwartz wrote: > > ?Where can I download that cl program? I've used gcc before, but I hear that cl can use a setup.py program to run the compile and link and create a windows .msi installer. Is that true? It is part of visual studio C++. Once you have that installed there are bat files that setup environment in the terminal. Then you can use cl, nmake etc Barry > > -----Original Message----- > From: Eryk Sun > Sent: Friday, March 31, 2023 12:55 PM > To: Jim Schwartz > Cc: python-list at python.org > Subject: Re: Windows installer from python source code without access to source code > >> On 3/31/23, Jim Schwartz wrote: >> I want a windows installer to install my application that's written in >> python, but I don't want the end user to have access to my source code. > > Cython can compile a script to C source code for a module or executable (--embed). The source can be compiled and linked normally. > For example, the following builds a "hello.exe" executable based on a "hello.py" script. > >> cython -3 --embed hello.py >> set "PYI=C:\Program Files\Python311\include" >> set "PYL=C:\Program Files\Python311\libs" >> cl /I"%PYI%" hello.c /link /libpath:"%PYL%" >> copy hello.exe embed >> embed\hello.exe > Hello, World! > > I extracted the complete embeddable distribution of Python 3.11 into the "embed" directory. You can reduce the size of the installation, if needed, by minimizing the zipped standard library and removing pyd extensions and DLLs that your application doesn't use. > > The generated "hello.c" is large and not particularly easy to read, but here are some snippets [...]: > > [...] > /* Implementation of 'hello' */ > static PyObject *__pyx_builtin_print; > static const char __pyx_k_main[] = "__main__"; > static const char __pyx_k_name[] = "__name__"; > static const char __pyx_k_test[] = "__test__"; > static const char __pyx_k_print[] = "print"; > static const char __pyx_k_Hello_World[] = "Hello, World!"; > [...] > /* "hello.py":1 > * print("Hello, World!") # <<<<<<<<<<<<<< > */ > __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Hello_World); > if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 1, __pyx_L1_error) > [...] > /* "hello.py":1 > * print("Hello, World!") # <<<<<<<<<<<<<< > */ > __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_, > NULL); > if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) > [...] > int wmain(int argc, wchar_t **argv) { > [...] > if (argc && argv) > Py_SetProgramName(argv[0]); > Py_Initialize(); > if (argc && argv) > PySys_SetArgv(argc, argv); > [...] > m = PyInit_hello(); > [...] > if (Py_FinalizeEx() < 0) > return 2; > [...] > return 0; > [...] > > -- > https://mail.python.org/mailman/listinfo/python-list > From cafulque at gmail.com Tue Apr 4 12:56:50 2023 From: cafulque at gmail.com (Carlos Fulqueris) Date: Tue, 4 Apr 2023 13:56:50 -0300 Subject: Python's Plugins for NetBeans 16 Message-ID: Dear Python Support, I'm looking for "Python Plugins for NetBeans 16". I already installed Python 3.11.2 for Windows 11 and I can't find such plugins to create python projects. I would appreciate it if you tell me where to download these plugins or if there is any other issue that I should do differently. Thank you very much in advance. Best to all. Carlos Fulqueris +54 911 2251 9302 From mats at wichmann.us Tue Apr 4 17:27:50 2023 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 4 Apr 2023 15:27:50 -0600 Subject: Problem in using libraries In-Reply-To: References: Message-ID: <38f28bdc-eb40-40fe-d791-10827b0e283d@wichmann.us> On 4/3/23 10:43, Pranav Bhardwaj wrote: > Why can't I able to use python libraries such as numpy, nudenet, playsound, > pandas, etc in my python 3.11.2. It always through the error "import > 'numpy' or any other libraries could not be resolved". Will restate what others have said in the hopes it might be even more clear that way. Python has an internal search path that it uses to find the module when you ask to "import". If a module is not found, that means it's not in the search path ("it's always a path problem"). You installed it, sure - but it went somewhere else. The search path is installation-specific (not just version-specific: for example if you have a system install of 3.10.x, and a virtualenv using the same 3.10.x, those will have different search paths). The search path can be amended or changed, but that's a different story. If you're going to install with pip, use the same Python you're going to do your work with. Don't trust that a command named "pip" maps to the same installation as that Python command. For that, either use an activated virtualenv, or do "name-of-my-python -m pip install". You can always check your work by doing "name-of-my-python -m pip list" - what does that particular installation see as installed? Or - if you're using the classic set of "scientific" packages like numpy and pandas, you might look at installing it all using conda instead of pip: it to a large extent exists to help with getting those very common bundles of things set up without going through the wrestling match you're going though. From thomas at python.org Wed Apr 5 08:28:54 2023 From: thomas at python.org (Thomas Wouters) Date: Wed, 5 Apr 2023 14:28:54 +0200 Subject: [RELEASE] Python 3.11.3, 3.10.11 and 3.12.0 alpha 7 released Message-ID: It's time for another set of Python releases! *Python 3.11.3, 3.10.11 and 3.12 alpha 7 are now available*. Python 3.12.0 alpha 7 The final alpha release of Python 3.12! The next release will be beta 1, which is also the feature freeze. Last chance to get your new features and API changes into 3.12! https://www.python.org/downloads/release/python-3120a7/ *246 new commits since 3.12.0a6.* Python 3.11.3 More bugfixes and security fixes for the best Python version (so far). https://www.python.org/downloads/release/python-3113/ *167 new commits since 3.11.2* Python 3.10.11 The final regular bugfix release for Python 3.10! It is now entering security-fix-only mode. This also means this is the last version for which we will ship Windows and macOS installers. If you rely on these binary releases, it's time to upgrade to Python 3.11. https://www.python.org/downloads/release/python-31011/ *121 new commits since 3.10.10.* 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/ >From the release team, Thomas Wouters @thomas Pablo Galindo Salgado @pablogsal ?ukasz Langa @ambv Ned Deily @nad Steve Dower @steve.dower From loris.bennett at fu-berlin.de Wed Apr 5 08:45:03 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Wed, 05 Apr 2023 14:45:03 +0200 Subject: When is logging.getLogger(__name__) needed? References: <877cux2hy0.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <87sfde7b1s.fsf@hornfels.zedat.fu-berlin.de> dn writes: > On 01/04/2023 02.01, Loris Bennett wrote: >> Hi, >> In my top level program file, main.py, I have >> def main_function(): >> parser = argparse.ArgumentParser(description="my prog") >> ... >> args = parser.parse_args() >> config = configparser.ConfigParser() >> if args.config_file is None: >> config_file = DEFAULT_CONFIG_FILE >> else: >> config_file = args.config_file >> config.read(config_file) >> logging.config.fileConfig(fname=config_file) >> logger = logging.getLogger(__name__) >> do_some_stuff() >> my_class_instance = myprog.MyClass() >> def do_some_stuff(): >> logger.info("Doing stuff") >> This does not work, because 'logger' is not known in the function >> 'do_some_stuff'. >> However, if in 'my_prog/my_class.py' I have >> class MyClass: >> def __init__(self): >> logger.debug("created instance of MyClass") >> this 'just works'. >> I can add >> logger = logging.getLogger(__name__) >> to 'do_some_stuff', but why is this necessary in this case but not >> in >> the class? >> Or should I be doing this entirely differently? > > Yes: differently. > > To complement @Peter's response, two items for consideration: > > 1 once main_function() has completed, have it return logger and other > such values/constructs. The target-identifiers on the LHS of the > function-call will thus be within the global scope. > > 2 if the purposes of main_function() are condensed-down to a few > (English, or ..., language) phrases, the word "and" will feature, eg > - configure env according to cmdLN args, > - establish log(s), > - do_some_stuff(), ** AND ** > - instantiate MyClass. > > If these (and do_some_stuff(), like MyClass' methods) were split into > separate functions* might you find it easier to see them as separate > sub-solutions? Each sub-solution would be able to contribute to the > whole - the earlier ones as creating (outputting) a description, > constraint, or basis; which becomes input to a later function/method. So if I want to modify the logging via the command line I might have the following: --------------------------------------------------------------------- #!/usr/bin/env python3 import argparse import logging def get_logger(log_level): """Get global logger""" logger = logging.getLogger('example') logger.setLevel(log_level) ch = logging.StreamHandler() formatter = logging.Formatter('%(levelname)s - %(message)s') ch.setFormatter(formatter) logger.addHandler(ch) return logger def do_stuff(): """Do some stuff""" # logger.info("Doing stuff!") def main(): """Main""" parser = argparse.ArgumentParser() parser.add_argument("--log-level", dest="log_level", type=int) args = parser.parse_args() print(f"log level: {args.log_level}") logger = get_logger(args.log_level) logger.debug("Logger!") do_stuff() if __name__ == "__main__": main() --------------------------------------------------------------------- How can I get logging for 'do_stuff' in this case without explicitly passing 'logger' as an argument or using 'global'? Somehow I am failing to understand how to get 'logger' defined sufficiently high up in the program that all references 'lower down' in the program will be automatically resolved. > * there is some debate amongst developers about whether "one function, > one purpose" should be a rule, a convention, or tossed in the > trash. YMMV! > > Personal view: SOLID's "Single" principle applies: there should be > only one reason (hanging over the head of each method/function, like > the Sword of Damocles) for it to change - or one 'user' who could > demand a change to that function. In other words, an updated cmdLN > option shouldn't affect a function which establishes logging, for > example. > > > Web.Refs: > https://people.engr.tamu.edu/choe/choe/courses/20fall/315/lectures/slide23-solid.pdf > https://www.hanselminutes.com/145/solid-principles-with-uncle-bob-robert-c-martin > https://idioms.thefreedictionary.com/sword+of+Damocles > https://en.wikipedia.org/wiki/Damocles I don't really get the "one reason" idea and the Sword of Damocles analogy. The later to me is more like "there's always a downside", since the perks of being king may mean someone might try to usurp the throne and kill you. Where is the "single principle" aspect? However, the idea of "one responsibility" in the sense of "do only one thing" seems relatively clear, especially if I think in terms of writing unit tests. Cheers, Loris -- This signature is currently under constuction. From loris.bennett at fu-berlin.de Wed Apr 5 09:06:22 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Wed, 05 Apr 2023 15:06:22 +0200 Subject: When is logging.getLogger(__name__) needed? References: <877cux2hy0.fsf@hornfels.zedat.fu-berlin.de> <87sfde7b1s.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <87o7o27a29.fsf@hornfels.zedat.fu-berlin.de> "Loris Bennett" writes: > dn writes: > >> On 01/04/2023 02.01, Loris Bennett wrote: >>> Hi, >>> In my top level program file, main.py, I have >>> def main_function(): >>> parser = argparse.ArgumentParser(description="my prog") >>> ... >>> args = parser.parse_args() >>> config = configparser.ConfigParser() >>> if args.config_file is None: >>> config_file = DEFAULT_CONFIG_FILE >>> else: >>> config_file = args.config_file >>> config.read(config_file) >>> logging.config.fileConfig(fname=config_file) >>> logger = logging.getLogger(__name__) >>> do_some_stuff() >>> my_class_instance = myprog.MyClass() >>> def do_some_stuff(): >>> logger.info("Doing stuff") >>> This does not work, because 'logger' is not known in the function >>> 'do_some_stuff'. >>> However, if in 'my_prog/my_class.py' I have >>> class MyClass: >>> def __init__(self): >>> logger.debug("created instance of MyClass") >>> this 'just works'. >>> I can add >>> logger = logging.getLogger(__name__) >>> to 'do_some_stuff', but why is this necessary in this case but not >>> in >>> the class? >>> Or should I be doing this entirely differently? >> >> Yes: differently. >> >> To complement @Peter's response, two items for consideration: >> >> 1 once main_function() has completed, have it return logger and other >> such values/constructs. The target-identifiers on the LHS of the >> function-call will thus be within the global scope. >> >> 2 if the purposes of main_function() are condensed-down to a few >> (English, or ..., language) phrases, the word "and" will feature, eg >> - configure env according to cmdLN args, >> - establish log(s), >> - do_some_stuff(), ** AND ** >> - instantiate MyClass. >> >> If these (and do_some_stuff(), like MyClass' methods) were split into >> separate functions* might you find it easier to see them as separate >> sub-solutions? Each sub-solution would be able to contribute to the >> whole - the earlier ones as creating (outputting) a description, >> constraint, or basis; which becomes input to a later function/method. > > So if I want to modify the logging via the command line I might have the > following: > > --------------------------------------------------------------------- > > #!/usr/bin/env python3 > > import argparse > import logging > > > def get_logger(log_level): > """Get global logger""" > > logger = logging.getLogger('example') > logger.setLevel(log_level) > ch = logging.StreamHandler() > formatter = logging.Formatter('%(levelname)s - %(message)s') > ch.setFormatter(formatter) > logger.addHandler(ch) > > return logger > > > def do_stuff(): > """Do some stuff""" > > # logger.info("Doing stuff!") Looks like I just need logger = logging.getLogger('example) logger.info("Doing stuff!") > > def main(): > """Main""" > > parser = argparse.ArgumentParser() > parser.add_argument("--log-level", dest="log_level", type=int) > args = parser.parse_args() > > print(f"log level: {args.log_level}") > > logger = get_logger(args.log_level) > logger.debug("Logger!") > do_stuff() > > > if __name__ == "__main__": > main() > > --------------------------------------------------------------------- > > How can I get logging for 'do_stuff' in this case without explicitly > passing 'logger' as an argument or using 'global'? > > Somehow I am failing to understand how to get 'logger' defined > sufficiently high up in the program that all references 'lower down' in > the program will be automatically resolved. > >> * there is some debate amongst developers about whether "one function, >> one purpose" should be a rule, a convention, or tossed in the >> trash. YMMV! >> >> Personal view: SOLID's "Single" principle applies: there should be >> only one reason (hanging over the head of each method/function, like >> the Sword of Damocles) for it to change - or one 'user' who could >> demand a change to that function. In other words, an updated cmdLN >> option shouldn't affect a function which establishes logging, for >> example. >> >> >> Web.Refs: >> https://people.engr.tamu.edu/choe/choe/courses/20fall/315/lectures/slide23-solid.pdf >> https://www.hanselminutes.com/145/solid-principles-with-uncle-bob-robert-c-martin >> https://idioms.thefreedictionary.com/sword+of+Damocles >> https://en.wikipedia.org/wiki/Damocles > > I don't really get the "one reason" idea and the Sword of Damocles > analogy. The later to me is more like "there's always a downside", > since the perks of being king may mean someone might try to usurp the > throne and kill you. Where is the "single principle" aspect? > > However, the idea of "one responsibility" in the sense of "do only one > thing" seems relatively clear, especially if I think in terms of writing > unit tests. > > Cheers, > > Loris -- Dr. Loris Bennett (Herr/Mr) ZEDAT, Freie Universit?t Berlin From PythonList at DancesWithMice.info Wed Apr 5 20:33:08 2023 From: PythonList at DancesWithMice.info (dn) Date: Thu, 6 Apr 2023 12:33:08 +1200 Subject: When is logging.getLogger(__name__) needed? In-Reply-To: <87o7o27a29.fsf@hornfels.zedat.fu-berlin.de> References: <877cux2hy0.fsf@hornfels.zedat.fu-berlin.de> <87sfde7b1s.fsf@hornfels.zedat.fu-berlin.de> <87o7o27a29.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <34d45701-291d-3f08-2536-38b63b523b47@DancesWithMice.info> Thank you for carefully considering suggestions (and implications) - and which will 'work' for you. Further comment below (and with apologies that, unusually for me, there are many personal opinions mixed-in):- On 06/04/2023 01.06, Loris Bennett wrote: > "Loris Bennett" writes: >> dn writes: >>> On 01/04/2023 02.01, Loris Bennett wrote: >>>> Hi, >>>> In my top level program file, main.py, I have >>>> def main_function(): >>>> parser = argparse.ArgumentParser(description="my prog") >>>> ... >>>> args = parser.parse_args() >>>> config = configparser.ConfigParser() >>>> if args.config_file is None: >>>> config_file = DEFAULT_CONFIG_FILE >>>> else: >>>> config_file = args.config_file >>>> config.read(config_file) >>>> logging.config.fileConfig(fname=config_file) >>>> logger = logging.getLogger(__name__) >>>> do_some_stuff() >>>> my_class_instance = myprog.MyClass() >>>> def do_some_stuff(): >>>> logger.info("Doing stuff") >>>> This does not work, because 'logger' is not known in the function >>>> 'do_some_stuff'. >>>> However, if in 'my_prog/my_class.py' I have >>>> class MyClass: >>>> def __init__(self): >>>> logger.debug("created instance of MyClass") >>>> this 'just works'. >>>> I can add >>>> logger = logging.getLogger(__name__) >>>> to 'do_some_stuff', but why is this necessary in this case but not >>>> in >>>> the class? >>>> Or should I be doing this entirely differently? >>> >>> Yes: differently. >>> >>> To complement @Peter's response, two items for consideration: >>> >>> 1 once main_function() has completed, have it return logger and other >>> such values/constructs. The target-identifiers on the LHS of the >>> function-call will thus be within the global scope. >>> >>> 2 if the purposes of main_function() are condensed-down to a few >>> (English, or ..., language) phrases, the word "and" will feature, eg >>> - configure env according to cmdLN args, >>> - establish log(s), >>> - do_some_stuff(), ** AND ** >>> - instantiate MyClass. >>> >>> If these (and do_some_stuff(), like MyClass' methods) were split into >>> separate functions* might you find it easier to see them as separate >>> sub-solutions? Each sub-solution would be able to contribute to the >>> whole - the earlier ones as creating (outputting) a description, >>> constraint, or basis; which becomes input to a later function/method. >> >> So if I want to modify the logging via the command line I might have the >> following: >> >> --------------------------------------------------------------------- >> >> #!/usr/bin/env python3 >> >> import argparse >> import logging >> >> >> def get_logger(log_level): >> """Get global logger""" >> >> logger = logging.getLogger('example') >> logger.setLevel(log_level) >> ch = logging.StreamHandler() >> formatter = logging.Formatter('%(levelname)s - %(message)s') >> ch.setFormatter(formatter) >> logger.addHandler(ch) >> >> return logger >> >> >> def do_stuff(): >> """Do some stuff""" >> >> # logger.info("Doing stuff!") > > Looks like I just need > > logger = logging.getLogger('example) > logger.info("Doing stuff!") > >> >> def main(): >> """Main""" >> >> parser = argparse.ArgumentParser() >> parser.add_argument("--log-level", dest="log_level", type=int) >> args = parser.parse_args() >> >> print(f"log level: {args.log_level}") >> >> logger = get_logger(args.log_level) >> logger.debug("Logger!") >> do_stuff() >> >> >> if __name__ == "__main__": >> main() >> >> --------------------------------------------------------------------- >> >> How can I get logging for 'do_stuff' in this case without explicitly >> passing 'logger' as an argument or using 'global'? >> >> Somehow I am failing to understand how to get 'logger' defined >> sufficiently high up in the program that all references 'lower down' in >> the program will be automatically resolved. At the risk of 'heresy', IMHO the idea of main() is (almost always) unnecessary in Python, and largely a habit carried-over from other languages (need for an entry-/end-point). NB be sure of the difference between a "script" and a "module"... My script template-overview: ''' Script docstring. ''' - author, license, etc docs global constants such as import-s set environment if __name__ == "__main__": do_this() do_that() ie the business of the script Despite its frequent use, I'm somewhat amused by the apparent duplication within: if __name__ == "__main__": main() ie if this .py file is being executed as a script, call main() - where main() is the purpose of the script. Whereas if the file is an import-ed module, do not execute any of the contained-code. Thus, the if-statement achieves the same separation as the main() function encapsulation. Also, the word main() conveys considerably less meaning than (say) establish_logging(). NB others may care to offer alternate advice for your consideration... There is a good argument for main(), in that it might enable tests to be written which assure the integration of several tasks called by the script. Plus, if one excludes non-TDD test-able code, such as user interfaces, even 'fancy headings' and printing of conclusions; there's little left. Accordingly, I don't mind the apparent duplication involved in coding an integration test which checks that do_this() and do_that() are playing-nicely together. YMMV! I'm not sure why, but my 'mainlines' never seem to be very long. Once I had been introduced to "Modular Programming" (1970s?), it seemed that the purpose of a mainline was merely calling one do-it function after another. To me mainline's seem highly unlikely to be re-usable. Thus, the possibility that main() might need to be import-able to some other script, is beyond my experience/recollection. Further, my .py file scripts/mainlines tend to be short and often don't contain any of the functions or classes which actually do-the-work - all are import-ed (and thus, they are easier to re-use!?) Returning to 'set environment': the code-examples include argparse and logger. Both (in my thinking) are part of creating the environment in which the code will execute. Logging for example, is the only choice when we need to be aware of how a web-based system is running (or running into problems) - otherwise, as some would argue, we might as well use print(). Similarly, argparse will often influence the way a script executes, the data it should use, etc. Much of such forms the (global) environment in which (this run of) the code will execute. Hence locating such setting of priorities and constraints, adjacent to the import statements. These must be established before getting on with 'the business'. That said, if someone prefers to put it under if __main__, I won't burst into tears. (see earlier comment about the .py file as a script cf module) You have answered your own question about logging. Well done! The logging instance can either be explicitly passed into each (relevant) function, or it can be treated as a global and thus available implicitly. (see also: "Zen of Python") I prefer your approach of get_logger() - even if that name doesn't quite describe the establishment of a logger and its settings. All of that part of setting the environment is collected into one place. Which in-turn, makes it easy to work on any changes, or work-in any parameters which may come from other environment-setting activity. As well as 'the documentation' there is a HowTo (https://docs.python.org/3/howto/logging.html). Other logging-learners have found the DigitalOcean tutorial helpful (https://www.digitalocean.com/community/tutorials/how-to-use-logging-in-python-3) >>> * there is some debate amongst developers about whether "one function, >>> one purpose" should be a rule, a convention, or tossed in the >>> trash. YMMV! >>> >>> Personal view: SOLID's "Single" principle applies: there should be >>> only one reason (hanging over the head of each method/function, like >>> the Sword of Damocles) for it to change - or one 'user' who could >>> demand a change to that function. In other words, an updated cmdLN >>> option shouldn't affect a function which establishes logging, for >>> example. >>> >>> >>> Web.Refs: >>> https://people.engr.tamu.edu/choe/choe/courses/20fall/315/lectures/slide23-solid.pdf >>> https://www.hanselminutes.com/145/solid-principles-with-uncle-bob-robert-c-martin >>> https://idioms.thefreedictionary.com/sword+of+Damocles >>> https://en.wikipedia.org/wiki/Damocles >> >> I don't really get the "one reason" idea and the Sword of Damocles >> analogy. The later to me is more like "there's always a downside", >> since the perks of being king may mean someone might try to usurp the >> throne and kill you. Where is the "single principle" aspect? >> >> However, the idea of "one responsibility" in the sense of "do only one >> thing" seems relatively clear, especially if I think in terms of writing >> unit tests. +1 Users are notoriously unable to write clear specifications. Ultimately, and not necessarily unkindly, they often do not know what they want - and particularly not specified at the level of detail we need. This is the downfall of the "waterfall" SDLC development model, and the reason why short 'Agile' sprints are (often/in-theory) more successful. The sooner a mistake, misunderstanding, or omission is realised, the better! Not wanting to do more than state the above, things change, life goes on, etc, etc. So, when one first demonstrates code to a user, it is rare that they won't want to change something. Similarly, over time, it is highly unlikely that someone won't dream up some 'improvement' - or similar need to amend the code be imposed by an externality, eg government legislation or regulation. Such changes may be trivial, eg cosmetic; others may be more far-reaching, eg imposition of a tax where previously there was none (or v-v). Accordingly, adding the fourth dimension to one's code, and program[me]-design - and the advice about being kind to those who will maintain the code after you or your six-months-time-self. So, the 'sword of Damocles' is knowing that our code should not be considered secure (or static). That change is inevitable. We don't need to be worrying about danger afflicting us when we least expect it - your users are unlikely to actually kill you. However, it is a good idea to be aware that change may be required, and that it could come from any random direction or "stakeholder". Perhaps worse, change implies risk. We make a change to suit one aspect, and something else 'breaks'. That is the reason many programmers actively resist 'change'. That is also one of the promises of TDD - if we can quickly run tests which assure (if not "prove") code-correctness, then the risks of change decrease. Whereas, if there are no tests to ensure 'life goes on' after a change, well, unhappiness reigns! Hence the allusion. (apologies if it was too oblique) Accordingly, the idea that if a function does one job (and does it well), should you decide/be required to change that function, then the impacts, any side-effects, etc, of such will only affect that one function (and its tests), and whatever is 'downstream' (integrating) from there. Which also reduces the chance that some change 'over here', will have some unforeseen impact 'over there'. The structure and the flow work together to achieve both a degree of separation and a bringing-together or unity. The tension of team-work if you like, cf the dysfunction of disorganisation. NB not that a 'small change' means running only that one test in TDD - still run the entire suite of tests (auto-magically) to ensure that there are no surprises... Change is inevitable. Thus, consider that your throne as code-author is illusory - the user/client is able/likely to want change. Then, if the code is organised according to functionality, the logging environment (for example) can be changed without any need to re-code somewhere else - and/or that tinkering with cmdLN arguments and such code-changes can be done quite separately from the establishment of logging. Ultimately, the smaller the function (think of establishing logging), the more likely it will be able to be re-used in the next assignment which requires a log! (whereas if it is mixed-in with argparse, re-use is unlikely because the cmdLN args will be different) There's plenty of references about such on the web. Will be happy to discuss whichever sub-topics might be of-interest, further... -- Regards, =dn From jschwar at sbcglobal.net Thu Apr 6 15:49:50 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Thu, 6 Apr 2023 14:49:50 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: <79F9B803-CE16-418C-B5CA-E88155DD42C5@barrys-emacs.org> References: <01a501d96709$b3f86f70$1be94e50$@sbcglobal.net> <79F9B803-CE16-418C-B5CA-E88155DD42C5@barrys-emacs.org> Message-ID: <00b201d968c0$f3c1e380$db45aa80$@sbcglobal.net> I downloaded VS community 2022 and I know how to access the developer command prompt. I'm using the one called x64 Native Tools Command Prompt for VS 2022 I ran a command to compile my python code that was converted to c with the following command: H:\Users\LindaJim\Documents\SourceCode\Software\aws_pc_backup\src\c>cl /O2 /I"C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\include\\" aws_pc_backup.c C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\libs\\python311.lib Microsoft (R) C/C++ Optimizing Compiler Version 19.35.32216.1 for x64 Copyright (C) Microsoft Corporation. All rights reserved. aws_pc_backup.c Microsoft (R) Incremental Linker Version 14.35.32216.1 Copyright (C) Microsoft Corporation. All rights reserved. /out:aws_pc_backup.exe aws_pc_backup.obj C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\libs\\python311.lib Creating library aws_pc_backup.lib and object aws_pc_backup.exp When I ran the program, I got this, though. Obviously, it doesn't know about the requests package. Do I have to link something in with the executable? H:\Users\LindaJim\Documents\SourceCode\Software\aws_pc_backup\src\c>aws_pc_backup.exe -m:lb Traceback (most recent call last): File "src\\python\\aws_pc_backup_main.py", line 7, in init python.aws_pc_backup_main ModuleNotFoundError: No module named 'requests' -----Original Message----- From: Barry Sent: Tuesday, April 4, 2023 1:25 PM To: Jim Schwartz Cc: Eryk Sun ; python-list at python.org Subject: Re: Windows installer from python source code without access to source code > On 4 Apr 2023, at 16:28, Jim Schwartz wrote: > > ?Where can I download that cl program? I've used gcc before, but I hear that cl can use a setup.py program to run the compile and link and create a windows .msi installer. Is that true? It is part of visual studio C++. Once you have that installed there are bat files that setup environment in the terminal. Then you can use cl, nmake etc Barry > > -----Original Message----- > From: Eryk Sun > Sent: Friday, March 31, 2023 12:55 PM > To: Jim Schwartz > Cc: python-list at python.org > Subject: Re: Windows installer from python source code without access > to source code > >> On 3/31/23, Jim Schwartz wrote: >> I want a windows installer to install my application that's written >> in python, but I don't want the end user to have access to my source code. > > Cython can compile a script to C source code for a module or executable (--embed). The source can be compiled and linked normally. > For example, the following builds a "hello.exe" executable based on a "hello.py" script. > >> cython -3 --embed hello.py >> set "PYI=C:\Program Files\Python311\include" >> set "PYL=C:\Program Files\Python311\libs" >> cl /I"%PYI%" hello.c /link /libpath:"%PYL%" >> copy hello.exe embed >> embed\hello.exe > Hello, World! > > I extracted the complete embeddable distribution of Python 3.11 into the "embed" directory. You can reduce the size of the installation, if needed, by minimizing the zipped standard library and removing pyd extensions and DLLs that your application doesn't use. > > The generated "hello.c" is large and not particularly easy to read, but here are some snippets [...]: > > [...] > /* Implementation of 'hello' */ > static PyObject *__pyx_builtin_print; > static const char __pyx_k_main[] = "__main__"; > static const char __pyx_k_name[] = "__name__"; > static const char __pyx_k_test[] = "__test__"; > static const char __pyx_k_print[] = "print"; > static const char __pyx_k_Hello_World[] = "Hello, World!"; > [...] > /* "hello.py":1 > * print("Hello, World!") # <<<<<<<<<<<<<< > */ > __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Hello_World); > if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 1, __pyx_L1_error) > [...] > /* "hello.py":1 > * print("Hello, World!") # <<<<<<<<<<<<<< > */ > __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_, > NULL); > if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) > [...] > int wmain(int argc, wchar_t **argv) { > [...] > if (argc && argv) > Py_SetProgramName(argv[0]); > Py_Initialize(); > if (argc && argv) > PySys_SetArgv(argc, argv); > [...] > m = PyInit_hello(); > [...] > if (Py_FinalizeEx() < 0) > return 2; > [...] > return 0; > [...] > > -- > https://mail.python.org/mailman/listinfo/python-list > From jschwar at sbcglobal.net Thu Apr 6 18:14:41 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Thu, 6 Apr 2023 17:14:41 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: References: Message-ID: Could someone please help Carlos? ?I?m not sure how to answer his question? Sent from my iPhone On Apr 6, 2023, at 3:53 PM, Carlos Fulqueris wrote: ? Hello Jim, How can I unsubscribe?to this email list? I'm waiting for your response. Thanks Carlos El jue, 6 abr 2023 a las 16:52, Jim Schwartz (<[1]jschwar at sbcglobal.net>) escribi?: I downloaded VS community 2022 and I know how to access the developer command prompt.? I'm using the one called x64 Native Tools Command Prompt for VS 2022 I ran a command to compile my python code that was converted to c with the following command: H:\Users\LindaJim\Documents\SourceCode\Software\aws_pc_backup\src\c>cl /O2 /I"C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\include\\" aws_pc_backup.c C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\libs\\python311.lib Microsoft (R) C/C++ Optimizing Compiler Version 19.35.32216.1 for x64 Copyright (C) Microsoft Corporation.? All rights reserved. aws_pc_backup.c Microsoft (R) Incremental Linker Version 14.35.32216.1 Copyright (C) Microsoft Corporation.? All rights reserved. /out:aws_pc_backup.exe aws_pc_backup.obj C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\libs\\python311.lib ? ?Creating library aws_pc_backup.lib and object aws_pc_backup.exp When I ran the program, I got this, though.? Obviously, it doesn't know about the requests package.? Do I have to link something in with the executable? H:\Users\LindaJim\Documents\SourceCode\Software\aws_pc_backup\src\c>aws_pc_backup.exe -m:lb Traceback (most recent call last): ? File "src\\python\\aws_pc_backup_main.py", line 7, in init python.aws_pc_backup_main ModuleNotFoundError: No module named 'requests' -----Original Message----- From: Barry <[2]barry at barrys-emacs.org> Sent: Tuesday, April 4, 2023 1:25 PM To: Jim Schwartz <[3]jschwar at sbcglobal.net> Cc: Eryk Sun <[4]eryksun at gmail.com>; [5]python-list at python.org Subject: Re: Windows installer from python source code without access to source code > On 4 Apr 2023, at 16:28, Jim Schwartz <[6]jschwar at sbcglobal.net> wrote: > > ?Where can I download that cl program?? I've used gcc before, but I hear that cl can use a setup.py program to run the compile and link and create a windows .msi installer.? Is that true?? It is part of visual studio C++. Once you have that installed there are bat files that setup environment in the terminal. Then you can use cl, nmake etc Barry > > -----Original Message----- > From: Eryk Sun <[7]eryksun at gmail.com> > Sent: Friday, March 31, 2023 12:55 PM > To: Jim Schwartz <[8]jschwar at sbcglobal.net> > Cc: [9]python-list at python.org > Subject: Re: Windows installer from python source code without access > to source code > >> On 3/31/23, Jim Schwartz <[10]jschwar at sbcglobal.net> wrote: >> I want a windows installer to install my application that's written >> in python, but I don't want the end user to have access to my source code. > > Cython can compile a script to C source code for a module or executable (--embed). The source can be compiled and linked normally. > For example, the following builds a "hello.exe" executable based on a "hello.py" script. > >> cython -3 --embed hello.py >> set "PYI=C:\Program Files\Python311\include" >> set "PYL=C:\Program Files\Python311\libs" >> cl /I"%PYI%" hello.c /link /libpath:"%PYL%" >> copy hello.exe embed >> embed\hello.exe >? ? Hello, World! > > I extracted the complete embeddable distribution of Python 3.11 into the "embed" directory. You can reduce the size of the installation, if needed, by minimizing the zipped standard library and removing pyd extensions and DLLs that your application doesn't use. > > The generated "hello.c" is large and not particularly easy to read, but here are some snippets [...]: > >? ? [...] >? ? /* Implementation of 'hello' */ >? ? static PyObject *__pyx_builtin_print; >? ? static const char __pyx_k_main[] = "__main__"; >? ? static const char __pyx_k_name[] = "__name__"; >? ? static const char __pyx_k_test[] = "__test__"; >? ? static const char __pyx_k_print[] = "print"; >? ? static const char __pyx_k_Hello_World[] = "Hello, World!"; >? ? [...] >? ? ? /* "hello.py":1 >? ? ?* print("Hello, World!")? ? ? ? ? ? ?# <<<<<<<<<<<<<< >? ? ?*/ >? ? ? __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Hello_World); >? ? ? ? ? ? if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 1, __pyx_L1_error) >? ? [...] >? ? ? /* "hello.py":1 >? ? ?* print("Hello, World!")? ? ? ? ? ? ?# <<<<<<<<<<<<<< >? ? ?*/ >? ? ? __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_, >? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL); >? ? ? ? ? ? if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) >? ? [...] >? ? int wmain(int argc, wchar_t **argv) { >? ? [...] >? ? ? ? if (argc && argv) >? ? ? ? ? ? Py_SetProgramName(argv[0]); >? ? ? ? Py_Initialize(); >? ? ? ? if (argc && argv) >? ? ? ? ? ? PySys_SetArgv(argc, argv); >? ? [...] >? ? ? ? ? ? ? m = PyInit_hello(); >? ? [...] >? ? ? ? if (Py_FinalizeEx() < 0) >? ? ? ? ? ? return 2; >? ? [...] >? ? ? ? return 0; >? ? [...] > > -- > [11]https://mail.python.org/mailman/listinfo/python-list > -- [12]https://mail.python.org/mailman/listinfo/python-list References Visible links 1. mailto:jschwar at sbcglobal.net 2. mailto:barry at barrys-emacs.org 3. mailto:jschwar at sbcglobal.net 4. mailto:eryksun at gmail.com 5. mailto:python-list at python.org 6. mailto:jschwar at sbcglobal.net 7. mailto:eryksun at gmail.com 8. mailto:jschwar at sbcglobal.net 9. mailto:python-list at python.org 10. mailto:jschwar at sbcglobal.net 11. https://mail.python.org/mailman/listinfo/python-list 12. https://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Thu Apr 6 18:49:37 2023 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 6 Apr 2023 23:49:37 +0100 Subject: Windows installer from python source code without access to source code In-Reply-To: References: Message-ID: <30a87229-e0c7-f326-5e7a-702389b9b8c1@mrabarnett.plus.com> On 2023-04-06 23:14, Jim Schwartz wrote: > Could someone please help Carlos? ?I?m not sure how to answer his > question > > Sent from my iPhone > > On Apr 6, 2023, at 3:53 PM, Carlos Fulqueris wrote: > > ? > Hello Jim, > How can I unsubscribe?to this email list? > I'm waiting for your response. > Thanks > Carlos [snip] At the bottom of the post is a link to the page that explains how to unsubscribe. It's the link: > https://mail.python.org/mailman/listinfo/python-list From jschwar at sbcglobal.net Thu Apr 6 19:47:55 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Thu, 6 Apr 2023 18:47:55 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: <00b201d968c0$f3c1e380$db45aa80$@sbcglobal.net> References: <01a501d96709$b3f86f70$1be94e50$@sbcglobal.net> <79F9B803-CE16-418C-B5CA-E88155DD42C5@barrys-emacs.org> <00b201d968c0$f3c1e380$db45aa80$@sbcglobal.net> Message-ID: <00cc01d968e2$36b094e0$a411bea0$@sbcglobal.net> Never mind. I found it on the web. I needed to point my PYTHONPATH to sitepackages: https://stackoverflow.com/questions/56857449/importerror-after-cython-embed -----Original Message----- From: Python-list On Behalf Of Jim Schwartz Sent: Thursday, April 6, 2023 2:50 PM To: 'Barry' Cc: python-list at python.org Subject: RE: Windows installer from python source code without access to source code I downloaded VS community 2022 and I know how to access the developer command prompt. I'm using the one called x64 Native Tools Command Prompt for VS 2022 I ran a command to compile my python code that was converted to c with the following command: H:\Users\LindaJim\Documents\SourceCode\Software\aws_pc_backup\src\c>cl /O2 /I"C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\include\\" aws_pc_backup.c C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\libs\\python311.lib Microsoft (R) C/C++ Optimizing Compiler Version 19.35.32216.1 for x64 Copyright (C) Microsoft Corporation. All rights reserved. aws_pc_backup.c Microsoft (R) Incremental Linker Version 14.35.32216.1 Copyright (C) Microsoft Corporation. All rights reserved. /out:aws_pc_backup.exe aws_pc_backup.obj C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\libs\\python311.lib Creating library aws_pc_backup.lib and object aws_pc_backup.exp When I ran the program, I got this, though. Obviously, it doesn't know about the requests package. Do I have to link something in with the executable? H:\Users\LindaJim\Documents\SourceCode\Software\aws_pc_backup\src\c>aws_pc_backup.exe -m:lb Traceback (most recent call last): File "src\\python\\aws_pc_backup_main.py", line 7, in init python.aws_pc_backup_main ModuleNotFoundError: No module named 'requests' -----Original Message----- From: Barry Sent: Tuesday, April 4, 2023 1:25 PM To: Jim Schwartz Cc: Eryk Sun ; python-list at python.org Subject: Re: Windows installer from python source code without access to source code > On 4 Apr 2023, at 16:28, Jim Schwartz wrote: > > ?Where can I download that cl program? I've used gcc before, but I hear that cl can use a setup.py program to run the compile and link and create a windows .msi installer. Is that true? It is part of visual studio C++. Once you have that installed there are bat files that setup environment in the terminal. Then you can use cl, nmake etc Barry > > -----Original Message----- > From: Eryk Sun > Sent: Friday, March 31, 2023 12:55 PM > To: Jim Schwartz > Cc: python-list at python.org > Subject: Re: Windows installer from python source code without access > to source code > >> On 3/31/23, Jim Schwartz wrote: >> I want a windows installer to install my application that's written >> in python, but I don't want the end user to have access to my source code. > > Cython can compile a script to C source code for a module or executable (--embed). The source can be compiled and linked normally. > For example, the following builds a "hello.exe" executable based on a "hello.py" script. > >> cython -3 --embed hello.py >> set "PYI=C:\Program Files\Python311\include" >> set "PYL=C:\Program Files\Python311\libs" >> cl /I"%PYI%" hello.c /link /libpath:"%PYL%" >> copy hello.exe embed >> embed\hello.exe > Hello, World! > > I extracted the complete embeddable distribution of Python 3.11 into the "embed" directory. You can reduce the size of the installation, if needed, by minimizing the zipped standard library and removing pyd extensions and DLLs that your application doesn't use. > > The generated "hello.c" is large and not particularly easy to read, but here are some snippets [...]: > > [...] > /* Implementation of 'hello' */ > static PyObject *__pyx_builtin_print; > static const char __pyx_k_main[] = "__main__"; > static const char __pyx_k_name[] = "__name__"; > static const char __pyx_k_test[] = "__test__"; > static const char __pyx_k_print[] = "print"; > static const char __pyx_k_Hello_World[] = "Hello, World!"; > [...] > /* "hello.py":1 > * print("Hello, World!") # <<<<<<<<<<<<<< > */ > __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Hello_World); > if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 1, __pyx_L1_error) > [...] > /* "hello.py":1 > * print("Hello, World!") # <<<<<<<<<<<<<< > */ > __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_, > NULL); > if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) > [...] > int wmain(int argc, wchar_t **argv) { > [...] > if (argc && argv) > Py_SetProgramName(argv[0]); > Py_Initialize(); > if (argc && argv) > PySys_SetArgv(argc, argv); > [...] > m = PyInit_hello(); > [...] > if (Py_FinalizeEx() < 0) > return 2; > [...] > return 0; > [...] > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list From eryksun at gmail.com Thu Apr 6 21:05:40 2023 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 6 Apr 2023 20:05:40 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: <00cc01d968e2$36b094e0$a411bea0$@sbcglobal.net> References: <01a501d96709$b3f86f70$1be94e50$@sbcglobal.net> <79F9B803-CE16-418C-B5CA-E88155DD42C5@barrys-emacs.org> <00b201d968c0$f3c1e380$db45aa80$@sbcglobal.net> <00cc01d968e2$36b094e0$a411bea0$@sbcglobal.net> Message-ID: On 4/6/23, Jim Schwartz wrote: > Never mind. I found it on the web. I needed to point my PYTHONPATH to > sitepackages: In most cases an application should be isolated from PYTHON* environment variables. If you're creating a Python application or embedding Python in an application, use the embeddable distribution, and add any additional required sys.path directories to the included "._pth" file (e.g. "python311._pth"). https://docs.python.org/3/library/sys_path_init.html#pth-files From jschwar at sbcglobal.net Fri Apr 7 06:33:25 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Fri, 7 Apr 2023 05:33:25 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: References: <01a501d96709$b3f86f70$1be94e50$@sbcglobal.net> <79F9B803-CE16-418C-B5CA-E88155DD42C5@barrys-emacs.org> <00b201d968c0$f3c1e380$db45aa80$@sbcglobal.net> <00cc01d968e2$36b094e0$a411bea0$@sbcglobal.net> Message-ID: <00ea01d9693c$62da53d0$288efb70$@sbcglobal.net> Yea, thanks a lot. That makes sense. I was testing it on my development environment and got it to work that way, but I need to package it and test it on my dual boot "user" environment. Thanks again for the help. I've deleted that environment variable. -----Original Message----- From: Eryk Sun Sent: Thursday, April 6, 2023 8:06 PM To: Jim Schwartz Cc: python-list at python.org Subject: Re: Windows installer from python source code without access to source code On 4/6/23, Jim Schwartz wrote: > Never mind. I found it on the web. I needed to point my PYTHONPATH > to > sitepackages: In most cases an application should be isolated from PYTHON* environment variables. If you're creating a Python application or embedding Python in an application, use the embeddable distribution, and add any additional required sys.path directories to the included "._pth" file (e.g. "python311._pth"). https://docs.python.org/3/library/sys_path_init.html#pth-files From jschwar at sbcglobal.net Fri Apr 7 08:28:20 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Fri, 7 Apr 2023 07:28:20 -0500 Subject: Windows installer from python source code without access to source code References: <01a501d96709$b3f86f70$1be94e50$@sbcglobal.net> <79F9B803-CE16-418C-B5CA-E88155DD42C5@barrys-emacs.org> <00b201d968c0$f3c1e380$db45aa80$@sbcglobal.net> <00cc01d968e2$36b094e0$a411bea0$@sbcglobal.net> Message-ID: <00ef01d9694c$70c6fba0$5254f2e0$@sbcglobal.net> Is this what you'd recommend doing when distributing a cython-generated code compiled with cl. I want to distribute this in a windows or other operating system installer. I'll start with windows first. I don't think I can use cx_freeze to create the installer, unless I know which files to include in the package and list them. https://stackoverflow.com/questions/62390978/minimal-set-of-files-required-to-distribute-an-embed-cython-compiled-code-and-ma -----Original Message----- From: Jim Schwartz Sent: Friday, April 7, 2023 5:33 AM To: 'Eryk Sun' Cc: 'python-list at python.org' Subject: RE: Windows installer from python source code without access to source code Yea, thanks a lot. That makes sense. I was testing it on my development environment and got it to work that way, but I need to package it and test it on my dual boot "user" environment. Thanks again for the help. I've deleted that environment variable. -----Original Message----- From: Eryk Sun Sent: Thursday, April 6, 2023 8:06 PM To: Jim Schwartz Cc: python-list at python.org Subject: Re: Windows installer from python source code without access to source code On 4/6/23, Jim Schwartz wrote: > Never mind. I found it on the web. I needed to point my PYTHONPATH > to > sitepackages: In most cases an application should be isolated from PYTHON* environment variables. If you're creating a Python application or embedding Python in an application, use the embeddable distribution, and add any additional required sys.path directories to the included "._pth" file (e.g. "python311._pth"). https://docs.python.org/3/library/sys_path_init.html#pth-files From nntp.mbourne at spamgourmet.com Fri Apr 7 07:16:07 2023 From: nntp.mbourne at spamgourmet.com (Mark Bourne) Date: Fri, 7 Apr 2023 12:16:07 +0100 Subject: Windows installer from python source code without access to source code In-Reply-To: References: <30a87229-e0c7-f326-5e7a-702389b9b8c1@mrabarnett.plus.com> Message-ID: MRAB wrote: > On 2023-04-06 23:14, Jim Schwartz wrote: >> ??? Could someone please help Carlos? ?I?m not sure how to answer his >> ??? question >> >> ??? Sent from my iPhone >> >> ????? On Apr 6, 2023, at 3:53 PM, Carlos Fulqueris >> wrote: >> >> ????? ? >> ????? Hello Jim, >> ????? How can I unsubscribe?to this email list? >> ????? I'm waiting for your response. >> ????? Thanks >> ????? Carlos > [snip] > At the bottom of the post is a link to the page that explains how to > unsubscribe. It's the link: > >> ??????? https://mail.python.org/mailman/listinfo/python-list I read this list via the newsgroup, so don't see those links. However, I've always thought those Mailman pages are confusing for anyone not already familiar when it comes to subscribing. The option to unsubscribe is right at the bottom of the page under the "Python-list Subscribers" section, which looks like it's only for list administrators! Ignore the admin address and password boxes, just fill in your email address in the box below those and click "Unsubscribe or edit options". -- Mark. From jschwar at sbcglobal.net Thu Apr 6 18:14:41 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Thu, 6 Apr 2023 17:14:41 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: References: Message-ID: Could someone please help Carlos? ?I?m not sure how to answer his question? Sent from my iPhone On Apr 6, 2023, at 3:53 PM, Carlos Fulqueris wrote: ? Hello Jim, How can I unsubscribe?to this email list? I'm waiting for your response. Thanks Carlos El jue, 6 abr 2023 a las 16:52, Jim Schwartz (<[1]jschwar at sbcglobal.net>) escribi?: I downloaded VS community 2022 and I know how to access the developer command prompt.? I'm using the one called x64 Native Tools Command Prompt for VS 2022 I ran a command to compile my python code that was converted to c with the following command: H:\Users\LindaJim\Documents\SourceCode\Software\aws_pc_backup\src\c>cl /O2 /I"C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\include\\" aws_pc_backup.c C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\libs\\python311.lib Microsoft (R) C/C++ Optimizing Compiler Version 19.35.32216.1 for x64 Copyright (C) Microsoft Corporation.? All rights reserved. aws_pc_backup.c Microsoft (R) Incremental Linker Version 14.35.32216.1 Copyright (C) Microsoft Corporation.? All rights reserved. /out:aws_pc_backup.exe aws_pc_backup.obj C:\\Users\\jschw\\AppData\\Local\\Programs\\Python\\Python3112\\libs\\python311.lib ? ?Creating library aws_pc_backup.lib and object aws_pc_backup.exp When I ran the program, I got this, though.? Obviously, it doesn't know about the requests package.? Do I have to link something in with the executable? H:\Users\LindaJim\Documents\SourceCode\Software\aws_pc_backup\src\c>aws_pc_backup.exe -m:lb Traceback (most recent call last): ? File "src\\python\\aws_pc_backup_main.py", line 7, in init python.aws_pc_backup_main ModuleNotFoundError: No module named 'requests' -----Original Message----- From: Barry <[2]barry at barrys-emacs.org> Sent: Tuesday, April 4, 2023 1:25 PM To: Jim Schwartz <[3]jschwar at sbcglobal.net> Cc: Eryk Sun <[4]eryksun at gmail.com>; [5]python-list at python.org Subject: Re: Windows installer from python source code without access to source code > On 4 Apr 2023, at 16:28, Jim Schwartz <[6]jschwar at sbcglobal.net> wrote: > > ?Where can I download that cl program?? I've used gcc before, but I hear that cl can use a setup.py program to run the compile and link and create a windows .msi installer.? Is that true?? It is part of visual studio C++. Once you have that installed there are bat files that setup environment in the terminal. Then you can use cl, nmake etc Barry > > -----Original Message----- > From: Eryk Sun <[7]eryksun at gmail.com> > Sent: Friday, March 31, 2023 12:55 PM > To: Jim Schwartz <[8]jschwar at sbcglobal.net> > Cc: [9]python-list at python.org > Subject: Re: Windows installer from python source code without access > to source code > >> On 3/31/23, Jim Schwartz <[10]jschwar at sbcglobal.net> wrote: >> I want a windows installer to install my application that's written >> in python, but I don't want the end user to have access to my source code. > > Cython can compile a script to C source code for a module or executable (--embed). The source can be compiled and linked normally. > For example, the following builds a "hello.exe" executable based on a "hello.py" script. > >> cython -3 --embed hello.py >> set "PYI=C:\Program Files\Python311\include" >> set "PYL=C:\Program Files\Python311\libs" >> cl /I"%PYI%" hello.c /link /libpath:"%PYL%" >> copy hello.exe embed >> embed\hello.exe >? ? Hello, World! > > I extracted the complete embeddable distribution of Python 3.11 into the "embed" directory. You can reduce the size of the installation, if needed, by minimizing the zipped standard library and removing pyd extensions and DLLs that your application doesn't use. > > The generated "hello.c" is large and not particularly easy to read, but here are some snippets [...]: > >? ? [...] >? ? /* Implementation of 'hello' */ >? ? static PyObject *__pyx_builtin_print; >? ? static const char __pyx_k_main[] = "__main__"; >? ? static const char __pyx_k_name[] = "__name__"; >? ? static const char __pyx_k_test[] = "__test__"; >? ? static const char __pyx_k_print[] = "print"; >? ? static const char __pyx_k_Hello_World[] = "Hello, World!"; >? ? [...] >? ? ? /* "hello.py":1 >? ? ?* print("Hello, World!")? ? ? ? ? ? ?# <<<<<<<<<<<<<< >? ? ?*/ >? ? ? __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_Hello_World); >? ? ? ? ? ? if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 1, __pyx_L1_error) >? ? [...] >? ? ? /* "hello.py":1 >? ? ?* print("Hello, World!")? ? ? ? ? ? ?# <<<<<<<<<<<<<< >? ? ?*/ >? ? ? __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple_, >? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NULL); >? ? ? ? ? ? if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) >? ? [...] >? ? int wmain(int argc, wchar_t **argv) { >? ? [...] >? ? ? ? if (argc && argv) >? ? ? ? ? ? Py_SetProgramName(argv[0]); >? ? ? ? Py_Initialize(); >? ? ? ? if (argc && argv) >? ? ? ? ? ? PySys_SetArgv(argc, argv); >? ? [...] >? ? ? ? ? ? ? m = PyInit_hello(); >? ? [...] >? ? ? ? if (Py_FinalizeEx() < 0) >? ? ? ? ? ? return 2; >? ? [...] >? ? ? ? return 0; >? ? [...] > > -- > [11]https://mail.python.org/mailman/listinfo/python-list > -- [12]https://mail.python.org/mailman/listinfo/python-list References Visible links 1. mailto:jschwar at sbcglobal.net 2. mailto:barry at barrys-emacs.org 3. mailto:jschwar at sbcglobal.net 4. mailto:eryksun at gmail.com 5. mailto:python-list at python.org 6. mailto:jschwar at sbcglobal.net 7. mailto:eryksun at gmail.com 8. mailto:jschwar at sbcglobal.net 9. mailto:python-list at python.org 10. mailto:jschwar at sbcglobal.net 11. https://mail.python.org/mailman/listinfo/python-list 12. https://mail.python.org/mailman/listinfo/python-list From jschwar at sbcglobal.net Sun Apr 9 07:22:13 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Sun, 9 Apr 2023 06:22:13 -0500 Subject: Windows installer from python source code without access to source code In-Reply-To: <00ef01d9694c$70c6fba0$5254f2e0$@sbcglobal.net> References: <01a501d96709$b3f86f70$1be94e50$@sbcglobal.net> <79F9B803-CE16-418C-B5CA-E88155DD42C5@barrys-emacs.org> <00b201d968c0$f3c1e380$db45aa80$@sbcglobal.net> <00cc01d968e2$36b094e0$a411bea0$@sbcglobal.net> <00ef01d9694c$70c6fba0$5254f2e0$@sbcglobal.net> Message-ID: <004101d96ad5$89959440$9cc0bcc0$@sbcglobal.net> Thanks everyone for the help. I got my app working with using cython to generate the c code, cl to compile, and visual studio to create the setup.exe and the msi installer. I appreciate the help. -----Original Message----- From: Python-list On Behalf Of Jim Schwartz Sent: Friday, April 7, 2023 7:28 AM To: 'Eryk Sun' Cc: python-list at python.org Subject: RE: Windows installer from python source code without access to source code Is this what you'd recommend doing when distributing a cython-generated code compiled with cl. I want to distribute this in a windows or other operating system installer. I'll start with windows first. I don't think I can use cx_freeze to create the installer, unless I know which files to include in the package and list them. https://stackoverflow.com/questions/62390978/minimal-set-of-files-required-t o-distribute-an-embed-cython-compiled-code-and-ma -----Original Message----- From: Jim Schwartz Sent: Friday, April 7, 2023 5:33 AM To: 'Eryk Sun' Cc: 'python-list at python.org' Subject: RE: Windows installer from python source code without access to source code Yea, thanks a lot. That makes sense. I was testing it on my development environment and got it to work that way, but I need to package it and test it on my dual boot "user" environment. Thanks again for the help. I've deleted that environment variable. -----Original Message----- From: Eryk Sun Sent: Thursday, April 6, 2023 8:06 PM To: Jim Schwartz Cc: python-list at python.org Subject: Re: Windows installer from python source code without access to source code On 4/6/23, Jim Schwartz wrote: > Never mind. I found it on the web. I needed to point my PYTHONPATH > to > sitepackages: In most cases an application should be isolated from PYTHON* environment variables. If you're creating a Python application or embedding Python in an application, use the embeddable distribution, and add any additional required sys.path directories to the included "._pth" file (e.g. "python311._pth"). https://docs.python.org/3/library/sys_path_init.html#pth-files -- https://mail.python.org/mailman/listinfo/python-list From yogeshtirthkar-vendor at gic.com.sg Sun Apr 9 22:14:36 2023 From: yogeshtirthkar-vendor at gic.com.sg (Yogesh Tirthkar) Date: Mon, 10 Apr 2023 02:14:36 +0000 Subject: [Request for Assistance] To uninstall python installed in other user profile (Win 10) In-Reply-To: References: Message-ID: Hi, Is there any way I can uninstall python installed (as user) in someone else' account - without login as that user, but login as local admin ? Regards, Yogesh. _________________________________________________________________________________ Technology Group | GIC Private Limited | 168 Robinson Road, #37-01, Capital Tower, Singapore 068912 -----Original Message----- From: Python-list On Behalf Of Thomas Passin Sent: Wednesday, March 29, 2023 12:19 AM To: python-list at python.org Subject: Re: [Request for Assistance] To uninstall python installed in other user profile (Win 10) [[External Mail] Do not click on links or attachment from unknown senders.] On 3/28/2023 12:56 AM, Yogesh Tirthkar wrote: > Hi Team, > > Could you please advise on the scenario in windows 10 machine : Where we need to uninstall/remove python from user profile A (installed by user A in its own profile folder) - via an admin user or system account. > > Currently when we try to uninstall it via admin/system account - it displays that the python product is not installed for this user (admin/system). > > Appreciate your assistance. It depends on where the Python installation is located, but I would just delete the entire folder tree at %APPDATA%\Python\Python3xxx. If Python was installed for all users, its main set of files will probably be in "c:\Program Files" and Window's "Add or Remove" page should remove it. If it was installed just for User A, then the "Add or Remove" page will find it if run from User A's account. If for some reason User A will not or cannot cooperate, the admin could change User A's password and then run "Add or Remove". Of course the admin would not be able to change the pw back, but if User A is not cooperating maybe that wouldn't matter. -- https://mail.python.org/mailman/listinfo/python-list This email from GIC may contain confidential information. Unauthorised communication and disclosure of any information in this email is prohibited. If you are not the intended recipient, please notify the sender and delete this email immediately. From list1 at tompassin.net Sun Apr 9 23:34:07 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 9 Apr 2023 23:34:07 -0400 Subject: [Request for Assistance] To uninstall python installed in other user profile (Win 10) In-Reply-To: References: Message-ID: <22a0934f-399d-c6b6-3685-1c5be42906bf@tompassin.net> On 4/9/2023 10:14 PM, Yogesh Tirthkar wrote: > Hi, > > Is there any way I can uninstall python installed (as user) in someone else' account - without login as that user, but login as local admin ? It depends on whether you can use that user's password. With the password, it's very feasible. Without it, some people seem to have found ways. There some discussion of this here - https://serverfault.com/questions/773038/run-as-a-different-user-without-a-password-from-an-elevated-prompt-in-windows > Technology Group | GIC Private Limited | 168 Robinson Road, #37-01, Capital Tower, Singapore 068912 > > -----Original Message----- > From: Python-list On Behalf Of Thomas Passin > Sent: Wednesday, March 29, 2023 12:19 AM > To: python-list at python.org > Subject: Re: [Request for Assistance] To uninstall python installed in other user profile (Win 10) > > [[External Mail] Do not click on links or attachment from unknown senders.] > > > On 3/28/2023 12:56 AM, Yogesh Tirthkar wrote: >> Hi Team, >> >> Could you please advise on the scenario in windows 10 machine : Where we need to uninstall/remove python from user profile A (installed by user A in its own profile folder) - via an admin user or system account. >> >> Currently when we try to uninstall it via admin/system account - it displays that the python product is not installed for this user (admin/system). >> >> Appreciate your assistance. > > It depends on where the Python installation is located, but I would just delete the entire folder tree at %APPDATA%\Python\Python3xxx. > > If Python was installed for all users, its main set of files will probably be in "c:\Program Files" and Window's "Add or Remove" page should remove it. > > If it was installed just for User A, then the "Add or Remove" page will find it if run from User A's account. If for some reason User A will not or cannot cooperate, the admin could change User A's password and then run "Add or Remove". Of course the admin would not be able to change the pw back, but if User A is not cooperating maybe that wouldn't matter. > > -- > https://mail.python.org/mailman/listinfo/python-list > This email from GIC may contain confidential information. Unauthorised communication and disclosure of any information in this email is prohibited. If you are not the intended recipient, please notify the sender and delete this email immediately. > From yogeshtirthkar-vendor at gic.com.sg Mon Apr 10 02:19:40 2023 From: yogeshtirthkar-vendor at gic.com.sg (Yogesh Tirthkar) Date: Mon, 10 Apr 2023 06:19:40 +0000 Subject: [Request for Assistance] To uninstall python installed in other user profile (Win 10) In-Reply-To: References: Message-ID: Hello, Thank you for your response. May I know how to uninstall it from user A profile ? if user A is no longer available. Is there any means - where I can use local admin account to uninstall the app (installed in User A profile, without user A?s intervention) Regards, Yogesh. From: Sravan Kumar Chitikesi Sent: Monday, April 10, 2023 2:17 PM To: Yogesh Tirthkar Cc: python-list at python.org Subject: Re: [Request for Assistance] To uninstall python installed in other user profile (Win 10) [cid:image001.png at 01D96BB7.7B62F3D0] If Python was installed by user A in their own profile folder, it is likely that it was installed just for that user. In this case, you may need to log in as user A to uninstall Python from their profile. Have you tried logging in as user A and uninstalling Python from there? Regards, Sravan Chitikesi AWS Solutions Architect - Associate On Tue, Mar 28, 2023 at 11:30?AM Yogesh Tirthkar > wrote: Hi Team, Could you please advise on the scenario in windows 10 machine : Where we need to uninstall/remove python from user profile A (installed by user A in its own profile folder) - via an admin user or system account. Currently when we try to uninstall it via admin/system account - it displays that the python product is not installed for this user (admin/system). Appreciate your assistance. Regards, Yogesh. _________________________________________________________________________________ Technology Group | GIC Private Limited | 168 Robinson Road, #37-01, Capital Tower, Singapore 068912 This email from GIC may contain confidential information. Unauthorised communication and disclosure of any information in this email is prohibited. If you are not the intended recipient, please notify the sender and delete this email immediately. -- https://mail.python.org/mailman/listinfo/python-list This email from GIC may contain confidential information. Unauthorised communication and disclosure of any information in this email is prohibited. If you are not the intended recipient, please notify the sender and delete this email immediately. From cl at isbd.net Sun Apr 9 04:40:51 2023 From: cl at isbd.net (Chris Green) Date: Sun, 9 Apr 2023 09:40:51 +0100 Subject: Looking for package/library to extract MP4 metadata Message-ID: I'm looking for a Python (3) library to access (read only at present) the metadata in MP4 video files, in particular I want to get at dates and times. What's available to do this? Ideally something available in the Ubuntu repositories but I can install with PIP if necessary. -- Chris Green ? From bowman at montana.com Sun Apr 9 12:31:46 2023 From: bowman at montana.com (rbowman) Date: 9 Apr 2023 16:31:46 GMT Subject: Looking for package/library to extract MP4 metadata References: Message-ID: On Sun, 9 Apr 2023 09:40:51 +0100, Chris Green wrote: > I'm looking for a Python (3) library to access (read only at present) > the metadata in MP4 video files, in particular I want to get at dates > and times. > > What's available to do this? Ideally something available in the Ubuntu > repositories but I can install with PIP if necessary. https://mutagen.readthedocs.io/en/latest/ From cl at isbd.net Sun Apr 9 13:05:56 2023 From: cl at isbd.net (Chris Green) Date: Sun, 9 Apr 2023 18:05:56 +0100 Subject: Looking for package/library to extract MP4 metadata References: Message-ID: rbowman wrote: > On Sun, 9 Apr 2023 09:40:51 +0100, Chris Green wrote: > > > I'm looking for a Python (3) library to access (read only at present) > > the metadata in MP4 video files, in particular I want to get at dates > > and times. > > > > What's available to do this? Ideally something available in the Ubuntu > > repositories but I can install with PIP if necessary. > > https://mutagen.readthedocs.io/en/latest/ > Oh, OK, thanks. I already have mutagen installed on my systems because I use QuodLibet. I hadn't realised it would let me look at MP4 video files but I guess it should. -- Chris Green ? From nospam at please.ty Sun Apr 9 14:23:52 2023 From: nospam at please.ty (jak) Date: Sun, 9 Apr 2023 20:23:52 +0200 Subject: Looking for package/library to extract MP4 metadata In-Reply-To: References: Message-ID: rbowman ha scritto: > On Sun, 9 Apr 2023 09:40:51 +0100, Chris Green wrote: > >> I'm looking for a Python (3) library to access (read only at present) >> the metadata in MP4 video files, in particular I want to get at dates >> and times. >> >> What's available to do this? Ideally something available in the Ubuntu >> repositories but I can install with PIP if necessary. > > https://mutagen.readthedocs.io/en/latest/ > I thought it only dealt about audio. From cl at isbd.net Sun Apr 9 15:19:37 2023 From: cl at isbd.net (Chris Green) Date: Sun, 9 Apr 2023 20:19:37 +0100 Subject: Looking for package/library to extract MP4 metadata References: Message-ID: <9nfbgj-90uc1.ln1@esprimo.zbmc.eu> jak wrote: > rbowman ha scritto: > > On Sun, 9 Apr 2023 09:40:51 +0100, Chris Green wrote: > > > >> I'm looking for a Python (3) library to access (read only at present) > >> the metadata in MP4 video files, in particular I want to get at dates > >> and times. > >> > >> What's available to do this? Ideally something available in the Ubuntu > >> repositories but I can install with PIP if necessary. > > > > https://mutagen.readthedocs.io/en/latest/ > > > > I thought it only dealt about audio. That's why I hadn't thought it would help me as I'm after getting metadata from an MP4 video file but I guess the metadata format may be the same regardless of whether it's video or audio. -- Chris Green ? From bowman at montana.com Sun Apr 9 23:01:00 2023 From: bowman at montana.com (rbowman) Date: 10 Apr 2023 03:01:00 GMT Subject: Looking for package/library to extract MP4 metadata References: <9nfbgj-90uc1.ln1@esprimo.zbmc.eu> Message-ID: On Sun, 9 Apr 2023 20:19:37 +0100, Chris Green wrote: > That's why I hadn't thought it would help me as I'm after getting > metadata from an MP4 video file but I guess the metadata format may be > the same regardless of whether it's video or audio. If yuo chase back through the various ISOs you tend to wind up at Apple's QuickTime container format as the parent. The compression methods for the media etc will differ but at least the structure of the file is documented. It's tedious but you can walk through the atoms (chunks, blocks, boxes) and find the metadata. There is the disclaimer https://mutagen.readthedocs.io/en/latest/user/mp4.html so it may not work for your intended purposes, particularly for modifying the data. That gets tricky since it may change the size of the chunk. https://pypi.org/project/tinytag/ is another one but it's only for reading the metadata. From nospam at please.ty Mon Apr 10 06:59:00 2023 From: nospam at please.ty (jak) Date: Mon, 10 Apr 2023 12:59:00 +0200 Subject: Looking for package/library to extract MP4 metadata In-Reply-To: <9nfbgj-90uc1.ln1@esprimo.zbmc.eu> References: <9nfbgj-90uc1.ln1@esprimo.zbmc.eu> Message-ID: Chris Green ha scritto: > jak wrote: >> rbowman ha scritto: >>> On Sun, 9 Apr 2023 09:40:51 +0100, Chris Green wrote: >>> >>>> I'm looking for a Python (3) library to access (read only at present) >>>> the metadata in MP4 video files, in particular I want to get at dates >>>> and times. >>>> >>>> What's available to do this? Ideally something available in the Ubuntu >>>> repositories but I can install with PIP if necessary. >>> >>> https://mutagen.readthedocs.io/en/latest/ >>> >> >> I thought it only dealt about audio. > > That's why I hadn't thought it would help me as I'm after getting > metadata from an MP4 video file but I guess the metadata format may be > the same regardless of whether it's video or audio. > Easiest way I found was run ffprobe command via popen. It can output the information you need in json format which is easily readable with the json library. command: ffprobe -v warning -i "input.mp4" -show_streams -of json python: Popen(command, stderr=STDOUT, stdout=PIPE, encoding='utf8') json: json.loads(''.join(p.stdout.readlines())) It's easy to find a version of ffmpeg/ffprobe for every platform. From cl at isbd.net Mon Apr 10 08:10:05 2023 From: cl at isbd.net (Chris Green) Date: Mon, 10 Apr 2023 13:10:05 +0100 Subject: Looking for package/library to extract MP4 metadata References: <9nfbgj-90uc1.ln1@esprimo.zbmc.eu> Message-ID: jak wrote: > Chris Green ha scritto: > > jak wrote: > >> rbowman ha scritto: > >>> On Sun, 9 Apr 2023 09:40:51 +0100, Chris Green wrote: > >>> > >>>> I'm looking for a Python (3) library to access (read only at present) > >>>> the metadata in MP4 video files, in particular I want to get at dates > >>>> and times. > >>>> > >>>> What's available to do this? Ideally something available in the Ubuntu > >>>> repositories but I can install with PIP if necessary. > >>> > >>> https://mutagen.readthedocs.io/en/latest/ > >>> > >> > >> I thought it only dealt about audio. > > > > That's why I hadn't thought it would help me as I'm after getting > > metadata from an MP4 video file but I guess the metadata format may be > > the same regardless of whether it's video or audio. > > > > Easiest way I found was run ffprobe command via popen. It can output the > information you need in json format which is easily readable with the > json library. > > command: > ffprobe -v warning -i "input.mp4" -show_streams -of json > python: > Popen(command, stderr=STDOUT, stdout=PIPE, encoding='utf8') > json: > json.loads(''.join(p.stdout.readlines())) > > It's easy to find a version of ffmpeg/ffprobe for every platform. Thank you, that worked straight away, ffprobe is installed on my systems already and I can probably just grep for the tag I want as all I'm looking for is the date of its creation which appears (twice) with the tag "creation_time". This is just to handle the occasional MP4 that a python program which basically manages JPEGs can't handle. It throws an exception so I can just get that to run a simple bash script to get the creation date. -- Chris Green ? From sravan.chitikesi at iprotechs.com Mon Apr 10 02:16:57 2023 From: sravan.chitikesi at iprotechs.com (Sravan Kumar Chitikesi) Date: Mon, 10 Apr 2023 02:16:57 -0400 Subject: [Request for Assistance] To uninstall python installed in other user profile (Win 10) In-Reply-To: References: Message-ID: If Python was installed by user A in their own profile folder, it is likely that it was installed just for that user. In this case, you may need to log in as user A to uninstall Python from their profile. Have you tried logging in as user A and uninstalling Python from there? Regards, *Sravan Chitikesi* AWS Solutions Architect - Associate On Tue, Mar 28, 2023 at 11:30?AM Yogesh Tirthkar < yogeshtirthkar-vendor at gic.com.sg> wrote: > Hi Team, > > Could you please advise on the scenario in windows 10 machine : Where we > need to uninstall/remove python from user profile A (installed by user A in > its own profile folder) - via an admin user or system account. > > Currently when we try to uninstall it via admin/system account - it > displays that the python product is not installed for this user > (admin/system). > > Appreciate your assistance. > > > Regards, > Yogesh. > > _________________________________________________________________________________ > Technology Group | GIC Private Limited | 168 Robinson Road, #37-01, > Capital Tower, Singapore 068912 > > > This email from GIC may contain confidential information. Unauthorised > communication and disclosure of any information in this email is > prohibited. If you are not the intended recipient, please notify the sender > and delete this email immediately. > -- > https://mail.python.org/mailman/listinfo/python-list > From 00jhenryg at gmail.com Mon Apr 10 09:59:30 2023 From: 00jhenryg at gmail.com (Jack Gilbert) Date: Mon, 10 Apr 2023 08:59:30 -0500 Subject: Need help please Message-ID: I D/L 3.11.3, I can see it in CMD running W10 64bit I have IDL on my desktop, HOW do I get 3.11.3 on my desktop? Thanks Jack g From sravan.chitikesi at iprotechs.com Mon Apr 10 12:41:46 2023 From: sravan.chitikesi at iprotechs.com (Sravan Kumar Chitikesi) Date: Mon, 10 Apr 2023 12:41:46 -0400 Subject: Need help please In-Reply-To: References: Message-ID: use where cmd to find out the path of the binary and create a shortcut to that file on desktop Regards, *Sravan Chitikesi* AWS Solutions Architect - Associate On Mon, Apr 10, 2023 at 10:03?AM Jack Gilbert <00jhenryg at gmail.com> wrote: > I D/L 3.11.3, I can see it in CMD > > running W10 64bit > > I have IDL on my desktop, > > HOW do I get 3.11.3 on my desktop? > > Thanks > > Jack g > -- > https://mail.python.org/mailman/listinfo/python-list > From list1 at tompassin.net Mon Apr 10 13:17:41 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 10 Apr 2023 13:17:41 -0400 Subject: Need help please In-Reply-To: References: Message-ID: <752c8b98-0487-20f9-1bf7-8e7b9375ff78@tompassin.net> On 4/10/2023 9:59 AM, Jack Gilbert wrote: > I D/L 3.11.3, I can see it in CMD > > running W10 64bit > > I have IDL on my desktop, > > HOW do I get 3.11.3 on my desktop? If you mean "How can I create a shortcut to Python 3.11.3 on my desktop that opens an interactive Python session", here is one way: 1. Find where your Python 3.11.3 program has been installed. On the command line in a console, type: py -c "import sys; print(sys.executable)" You will get a response like this: C:\Users\tom\AppData\Local\Programs\Python\Python311\python.exe NOTE: If the "py" command is not on your computer or does not open Python 3.11, then open a python 3.11 session and type the same commands: import sys print(sys.executable) 2. Open the Windows file browser ("Windows Explorer") and navigate to that directory. On my computer this is C:\Users\tom\AppData\Local\Programs\Python\Python311 3. Press and hold both the CTRL and SHIFT keys down at the same time, and with the mouse drag the icon for "python.exe" to a blank space on the desktop. This will not drag the program itself but will create a shortcut and drag that. 4. Test the new shortcut by double-clicking on it and seeing that a new console window opens with the Python interpreter running in it. If you do not like the size, shape, or font of this new console, change them by clicking on the icon in the upper left, then selecting "Properties", and making changes in the dialog box that opens. The new choices will be used whenever you use this shortcut again. 5. The new shortcut will probably be named "python.ex". I suggest that you rename it to "Python 3.11". This way you can create other python shortcuts without having their names conflict. From list1 at tompassin.net Mon Apr 10 08:29:06 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 10 Apr 2023 08:29:06 -0400 Subject: [Request for Assistance] To uninstall python installed in other user profile (Win 10) In-Reply-To: References: Message-ID: <188650b9-c470-ffa0-504c-2e29ae4a96df@tompassin.net> On 4/10/2023 2:19 AM, Yogesh Tirthkar wrote: > Hello, > > Thank you for your response. > > May I know how to uninstall it from user A profile ? if user A is no longer available. > > Is there any means - where I can use local admin account to uninstall the app (installed in User A profile, without user A?s intervention) If user A is no longer available, then an administrator can change the password for User A and then, logged into the A account, perform the un-install. > From: Sravan Kumar Chitikesi > Sent: Monday, April 10, 2023 2:17 PM > To: Yogesh Tirthkar > Cc: python-list at python.org > Subject: Re: [Request for Assistance] To uninstall python installed in other user profile (Win 10) > > [cid:image001.png at 01D96BB7.7B62F3D0] > > If Python was installed by user A in their own profile folder, it is likely that it was installed just for that user. In this case, you may need to log in as user A to uninstall Python from their profile. Have you tried logging in as user A and uninstalling Python from there? > > Regards, > Sravan Chitikesi > AWS Solutions Architect - Associate > > > On Tue, Mar 28, 2023 at 11:30?AM Yogesh Tirthkar > wrote: > Hi Team, > > Could you please advise on the scenario in windows 10 machine : Where we need to uninstall/remove python from user profile A (installed by user A in its own profile folder) - via an admin user or system account. > > Currently when we try to uninstall it via admin/system account - it displays that the python product is not installed for this user (admin/system). > From cs at cskk.id.au Mon Apr 10 20:27:35 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 11 Apr 2023 10:27:35 +1000 Subject: Looking for package/library to extract MP4 metadata In-Reply-To: References: Message-ID: On 10Apr2023 13:10, Chris Green wrote: >> command: >> ffprobe -v warning -i "input.mp4" -show_streams -of json >> python: >> Popen(command, stderr=STDOUT, stdout=PIPE, encoding='utf8') >> json: >> json.loads(''.join(p.stdout.readlines())) >> >> It's easy to find a version of ffmpeg/ffprobe for every platform. > >Thank you, that worked straight away, ffprobe is installed on my >systems already and I can probably just grep for the tag I want as all >I'm looking for is the date of its creation which appears (twice) with >the tag "creation_time". > >This is just to handle the occasional MP4 that a python program which >basically manages JPEGs can't handle. It throws an exception so I can >just get that to run a simple bash script to get the creation date. Yes, ffprobe is great, particularly the JSON output mode, very parsable. If you want to get into the knitty gritty you could try my `cs.iso14496` package, which has a full MP4/MOV parser and a hook for getting the metadata. Not as convenient as ffprobe, but if you care about the innards... Cheers, Cameron Simpson From miked at dewhirst.com.au Tue Apr 11 00:12:45 2023 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Tue, 11 Apr 2023 14:12:45 +1000 Subject: Christoph Gohlke and compiled packages Message-ID: It seems Christoph Gohlke has been cut adrift and his extremely valuable web page ... https://www.lfd.uci.edu/~gohlke/pythonlibs/ ... turned into an archive getting staler by the day. What does the Python Software Foundation and the community think about this? Cheers Mike From rosuav at gmail.com Tue Apr 11 03:21:14 2023 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Apr 2023 17:21:14 +1000 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: Message-ID: On Tue, 11 Apr 2023 at 14:20, Mike Dewhirst wrote: > > It seems Christoph Gohlke has been cut adrift and his extremely valuable > web page ... > > https://www.lfd.uci.edu/~gohlke/pythonlibs/ > > ... turned into an archive getting staler by the day. > > What does the Python Software Foundation and the community think about this? My personal view? Windows is *really really really* hard to support, and ONE PERSON did a stellar job of supporting the platform for an incredibly long job. I don't know if he'll ever read this, but if he does, thank you Christoph for your amazing contribution to the community. The fact that we have a problem now is a testament to the length of time that we *didn't* have a problem, thanks to him. ChrisA From miked at dewhirst.com.au Tue Apr 11 04:22:20 2023 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Tue, 11 Apr 2023 18:22:20 +1000 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: Message-ID: <384a4082-9bcf-4e7b-c1dc-466dcec22443@dewhirst.com.au> On 11/04/2023 5:21 pm, Chris Angelico wrote: > On Tue, 11 Apr 2023 at 14:20, Mike Dewhirst wrote: >> It seems Christoph Gohlke has been cut adrift and his extremely valuable >> web page ... >> >> https://www.lfd.uci.edu/~gohlke/pythonlibs/ >> >> ... turned into an archive getting staler by the day. >> >> What does the Python Software Foundation and the community think about this? > My personal view? Windows is *really really really* hard to support, > and ONE PERSON did a stellar job of supporting the platform for an > incredibly long job. I have to agree - but what you are really saying is that without Christoph, Python on Windows is *really really really* not viable. Mike > > I don't know if he'll ever read this, but if he does, thank you > Christoph for your amazing contribution to the community. > > The fact that we have a problem now is a testament to the length of > time that we *didn't* have a problem, thanks to him. > > ChrisA -- 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. 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 rosuav at gmail.com Tue Apr 11 04:49:30 2023 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Apr 2023 18:49:30 +1000 Subject: Christoph Gohlke and compiled packages In-Reply-To: <384a4082-9bcf-4e7b-c1dc-466dcec22443@dewhirst.com.au> References: <384a4082-9bcf-4e7b-c1dc-466dcec22443@dewhirst.com.au> Message-ID: On Tue, 11 Apr 2023 at 18:22, Mike Dewhirst wrote: > > On 11/04/2023 5:21 pm, Chris Angelico wrote: > >> My personal view? Windows is *really really really* hard to support, >> and ONE PERSON did a stellar job of supporting the platform for an >> incredibly long job. > > > I have to agree - but what you are really saying is that without Christoph, Python on Windows is > > *really really really* > > not viable. > This may well be true, but before writing Windows off completely [1], do check out some of the commercial distributions. It may be that it's possible to do everything through Conda, for instance. [1] Much as I would like to, this isn't a good idea From jschwar at sbcglobal.net Tue Apr 11 06:14:58 2023 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Tue, 11 Apr 2023 05:14:58 -0500 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: Message-ID: What?s the problem now? Is it with python on windows? I use python on windows so I?d like to know. Thanks Sent from my iPhone > On Apr 11, 2023, at 2:24 AM, Chris Angelico wrote: > > ?On Tue, 11 Apr 2023 at 14:20, Mike Dewhirst wrote: >> >> It seems Christoph Gohlke has been cut adrift and his extremely valuable >> web page ... >> >> https://www.lfd.uci.edu/~gohlke/pythonlibs/ >> >> ... turned into an archive getting staler by the day. >> >> What does the Python Software Foundation and the community think about this? > > My personal view? Windows is *really really really* hard to support, > and ONE PERSON did a stellar job of supporting the platform for an > incredibly long job. > > I don't know if he'll ever read this, but if he does, thank you > Christoph for your amazing contribution to the community. > > The fact that we have a problem now is a testament to the length of > time that we *didn't* have a problem, thanks to him. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Apr 11 06:58:22 2023 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Apr 2023 20:58:22 +1000 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: Message-ID: On Tue, 11 Apr 2023 at 20:15, Jim Schwartz wrote: > > What?s the problem now? Is it with python on windows? I use python on windows so I?d like to know. Thanks > Python itself is fine, but a lot of third-party packages are hard to obtain. So if you need numpy, for instance, or psycopg2, you might need to find an alternative source. ChrisA From oscar.j.benjamin at gmail.com Tue Apr 11 07:54:05 2023 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 11 Apr 2023 12:54:05 +0100 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: Message-ID: On Tue, 11 Apr 2023 at 12:01, Chris Angelico wrote: > > On Tue, 11 Apr 2023 at 20:15, Jim Schwartz wrote: > > > > What?s the problem now? Is it with python on windows? I use python on windows so I?d like to know. Thanks > > > > Python itself is fine, but a lot of third-party packages are hard to > obtain. So if you need numpy, for instance, or psycopg2, you might > need to find an alternative source. Both numpy and psycopg2 have binary wheels for Windows that can be pip installed from PyPI. I haven't used psycopg2 myself and I don't use Windows so I can't say if there is any difficulty using them but I presume that they can install and run just fine. Certainly the numpy wheels have been there for Windows for years and work just fine. Before numpy provided wheels they also provided MSI installers for Windows anyway so there was always an alternative to Christoph's stack. Christoph's Windows binaries project predated the wheel format and so the alternative options have improved massively since then. I presume that there are some projects where Christoph's binaries are still the only non-conda option (besides build yourself). I would not be surprised if all of those are installable by conda though and we are probably talking about projects that would seem obscure to most Python users. Certainly for the more widely used libraries like numpy installing binaries with pip is not a problem these days on Windows or other popular OS. I notice that psycopg2 *only* provides binaries for Windows and not e.g. OSX or Linux but the list of binaries provided by numpy is extensive with the current release listing wheels for all combinations of CPython 3.8-3.11, win32, win amd64, manylinux amd64, manylinux aarch64, OSX x64, OSX arm64: https://pypi.org/project/numpy/1.24.2/#files The difference now since the days when Cristoph started generating and hosting binaries is that it is typically expected that a project like numpy should produce its own binary wheels for popular platforms and host them on PyPI. Of course that is a burden on the numpy maintainers but tooling for this is much better than it used to be with things like cibuildwheel, free CI systems including Windows/OSX runners etc. It is *much* easier for a project to support generating Windows wheels now than it used to be and to a certain extent it just forms part of the normal CI setup that a project like numpy would want to have anyway. -- Oscar From roel at roelschroeven.net Tue Apr 11 08:03:44 2023 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 11 Apr 2023 14:03:44 +0200 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: Message-ID: <16bc870f-c99b-8efd-44c1-b818324eef64@roelschroeven.net> Op 11/04/2023 om 12:58 schreef Chris Angelico: > On Tue, 11 Apr 2023 at 20:15, Jim Schwartz wrote: > > > > What?s the problem now? Is it with python on windows? I use python on windows so I?d like to know. Thanks > > > > Python itself is fine, but a lot of third-party packages are hard to > obtain. So if you need numpy, for instance, or psycopg2, you might > need to find an alternative source. These days I use pip to install packages, and so far for the things I need it simply works. "pip install numpy" works, same for psycopg2, pillow, pandas, and other packages I use. Conda should work too, for those who use the Anaconda Python distribution. I honestly don't even know how it's done: are there some kind souls who provide the wheels (binary packages) for all those things, or if there is maybe a build farm that does the hard work to make things easy for us. In the past I've used Christoph Gohlke's site and I'm very grateful for the service it provided, but these days I don't really need it anymore, luckily. -- "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson From rosuav at gmail.com Tue Apr 11 08:55:45 2023 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Apr 2023 22:55:45 +1000 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: Message-ID: On Tue, 11 Apr 2023 at 21:55, Oscar Benjamin wrote: > > Both numpy and psycopg2 have binary wheels for Windows that can be pip > installed from PyPI. Ah good. It's been a long time since I've needed to care about Windows, so I'm a bit out of the loop. That's good news. While not at all detracting from his amazing contributions over the years, I'm delighted that it's less necessary now. ChrisA From hjp-python at hjp.at Tue Apr 11 08:52:19 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 11 Apr 2023 14:52:19 +0200 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: Message-ID: <20230411125219.m3czk3x33bzt4jcn@hjp.at> On 2023-04-11 12:54:05 +0100, Oscar Benjamin wrote: > Certainly for the more widely used libraries like numpy installing > binaries with pip is not a problem these days on Windows or other > popular OS. I notice that psycopg2 *only* provides binaries for > Windows and not e.g. OSX or Linux For Linux there is a separate package psycopg2-binary on PyPI. That split happened a few years ago and I forgot why it was necessary. For the distributions I use (Debian and Ubuntu) both packages work (but for the source package I need to install the necessary development packages first). 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 list1 at tompassin.net Tue Apr 11 09:39:21 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 11 Apr 2023 09:39:21 -0400 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: Message-ID: <82d2b185-c8b9-d1d4-06a7-0d3d1cf8d1da@tompassin.net> On 4/11/2023 6:58 AM, Chris Angelico wrote: > On Tue, 11 Apr 2023 at 20:15, Jim Schwartz wrote: >> >> What?s the problem now? Is it with python on windows? I use python on windows so I?d like to know. Thanks >> > > Python itself is fine, but a lot of third-party packages are hard to > obtain. So if you need numpy, for instance, or psycopg2, you might > need to find an alternative source. I've noticed a big change in the last few years in that PyPi has many, many amd-64 packages than it used to in the heyday of Christoph Gohlke's efforts. I haven't needed to go there for some time whereas I used to need to all the time. So if I "need numpy, for instance, or psycopg2" for Windows, I get them from PyPi. Yes, I know that some projects haven't caught up to Python 3.11x yet. And I'm glad I haven't needed to create a binary wheel for Windows myself. But the situation is way better than it used to be. I've had more trouble with Python and Python packages on Linux than on Windows. From mats at wichmann.us Tue Apr 11 09:53:04 2023 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 11 Apr 2023 07:53:04 -0600 Subject: Christoph Gohlke and compiled packages In-Reply-To: <16bc870f-c99b-8efd-44c1-b818324eef64@roelschroeven.net> References: <16bc870f-c99b-8efd-44c1-b818324eef64@roelschroeven.net> Message-ID: <0b9d0f10-4800-0515-bd73-d6e2dce2b89e@wichmann.us> On 4/11/23 06:03, Roel Schroeven wrote: > Op 11/04/2023 om 12:58 schreef Chris Angelico: >> Python itself is fine, but a lot of third-party packages are hard to >> obtain. So if you need numpy, for instance, or psycopg2, you might >> need to find an alternative source. > These days I use pip to install packages, and so far for the things I > need it simply works. "pip install numpy" works, same for psycopg2, > pillow, pandas, and other packages I use. Conda should work too, for > those who use the Anaconda Python distribution. I honestly don't even > know how it's done: are there some kind souls who provide the wheels > (binary packages) for all those things, or if there is maybe a build > farm that does the hard work to make things easy for us. > > In the past I've used Christoph Gohlke's site and I'm very grateful for > the service it provided, but these days I don't really need it anymore, > luckily. The deal really is, the instant a new Python version drops (3.11, 3.12, etc.) a million people rush to install it, some of whom should know better and be more patient. 3rd party packages are their own projects, some have binary wheels ready on Python release day, some soon after, some months after. That's the main hole this site filled in more recent times: for people who feel they must jump forward but their key packages were not yet ready, they were probably here. (I should add - it's not always impatience, sometimes folks are also being proactive and want to test Python betas, etc. so they're prepared, and they'll of course hit the same problem of some wheels not being available). There's even a "readiness" site folks can check (also volunteer-run), https://pyreadiness.org/ but often the lure of the new shiny thing just wins out. I predict we'll have a flood of anguish again in the fall when 3.12.0 comes out. From oscar.j.benjamin at gmail.com Tue Apr 11 13:48:08 2023 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 11 Apr 2023 18:48:08 +0100 Subject: Christoph Gohlke and compiled packages In-Reply-To: <0b9d0f10-4800-0515-bd73-d6e2dce2b89e@wichmann.us> References: <16bc870f-c99b-8efd-44c1-b818324eef64@roelschroeven.net> <0b9d0f10-4800-0515-bd73-d6e2dce2b89e@wichmann.us> Message-ID: On Tue, 11 Apr 2023 at 14:55, Mats Wichmann wrote: > > On 4/11/23 06:03, Roel Schroeven wrote: > > Op 11/04/2023 om 12:58 schreef Chris Angelico: > > >> Python itself is fine, but a lot of third-party packages are hard to > >> obtain. So if you need numpy, for instance, or psycopg2, you might > >> need to find an alternative source. > > These days I use pip to install packages, and so far for the things I > > need it simply works. "pip install numpy" works, same for psycopg2, > > pillow, pandas, and other packages I use. Conda should work too, for > > those who use the Anaconda Python distribution. I honestly don't even > > know how it's done: are there some kind souls who provide the wheels > > (binary packages) for all those things, or if there is maybe a build > > farm that does the hard work to make things easy for us. > > > > In the past I've used Christoph Gohlke's site and I'm very grateful for > > the service it provided, but these days I don't really need it anymore, > > luckily. > > The deal really is, the instant a new Python version drops (3.11, 3.12, > etc.) a million people rush to install it, some of whom should know > better and be more patient. 3rd party packages are their own projects, > some have binary wheels ready on Python release day, some soon after, > some months after. You can hardly blame a lot of people for doing this. A seb search for "download python" gives this as the first hit: https://www.python.org/downloads/ I am guessing that the release process automatically updates that page so that the minute 3.12 gets released the big yellow button will suggest downloading 3.12.0 as the default option. Perhaps it is really package authors who should be getting a release out that is compatible with Python 3.12 before 3.12 itself is released. It's tricky though because as a maintainer it makes more sense to wait until you see the finished 3.12 product before making a release that is fully tested with it (even if you are testing the alphas etc in CI and making incremental fixes before 3.12 is released). The other option could be changing the downloads page so that it does not suggest 3.12.0 as the default option until it is clear that at least some baseline of widely used packages have uploaded compatible wheels. -- Oscar From loris.bennett at fu-berlin.de Tue Apr 11 10:29:58 2023 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Tue, 11 Apr 2023 16:29:58 +0200 Subject: Initialising a Config class Message-ID: <87sfd6trtl.fsf@debian-BULLSEYE-live-builder-AMD64> Hi, Having solved my problem regarding setting up 'logger' such that it is accessible throughout my program (thanks to the help on this list), I now have problem related to a slightly similar issue. My reading suggests that setting up a module with a Config class which can be imported by any part of the program might be a reasonable approach: import configparser class Config: def __init__(self, config_file): config = configparser.ConfigParser() config.read(config_file) However, in my config file I am using sections, so 'config' is a dict of dicts. Is there any cleverer generic way of initialising the class than self.config = config ? This seems a bit clunky, because I'll end up with something like import config ... c = config.Config(config_file) uids = get_uids(int(c.config["uids"]["minimum_uid"])) rather than something like, maybe uids = get_uids(int(c.minimum_uid)) or uids = get_uids(int(c.uids_minimum_uid)) So the question is: How can I map a dict of dicts onto class attributes in a generic way such that only code which wants to use a new configuration parameter needs to be changed and not the Config class itself? Or should I be doing this differently? Note that the values from ConfigParser are all strings, so I am fine with the attributes being strings - I'll just convert them as needed at the point of use (but maybe there is also a better way of handling that within a class). Cheers, Loris -- This signature is currently under constuction. From mats at wichmann.us Tue Apr 11 14:30:01 2023 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 11 Apr 2023 12:30:01 -0600 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: <16bc870f-c99b-8efd-44c1-b818324eef64@roelschroeven.net> <0b9d0f10-4800-0515-bd73-d6e2dce2b89e@wichmann.us> Message-ID: <38a3954f-ce5c-d26b-100a-3193b97c9bc7@wichmann.us> On 4/11/23 11:48, Oscar Benjamin wrote: > On Tue, 11 Apr 2023 at 14:55, Mats Wichmann wrote: >> >> On 4/11/23 06:03, Roel Schroeven wrote: >>> Op 11/04/2023 om 12:58 schreef Chris Angelico: >> >>>> Python itself is fine, but a lot of third-party packages are hard to >>>> obtain. So if you need numpy, for instance, or psycopg2, you might >>>> need to find an alternative source. >>> These days I use pip to install packages, and so far for the things I >>> need it simply works. "pip install numpy" works, same for psycopg2, >>> pillow, pandas, and other packages I use. Conda should work too, for >>> those who use the Anaconda Python distribution. I honestly don't even >>> know how it's done: are there some kind souls who provide the wheels >>> (binary packages) for all those things, or if there is maybe a build >>> farm that does the hard work to make things easy for us. >>> >>> In the past I've used Christoph Gohlke's site and I'm very grateful for >>> the service it provided, but these days I don't really need it anymore, >>> luckily. >> >> The deal really is, the instant a new Python version drops (3.11, 3.12, >> etc.) a million people rush to install it, some of whom should know >> better and be more patient. 3rd party packages are their own projects, >> some have binary wheels ready on Python release day, some soon after, >> some months after. > > You can hardly blame a lot of people for doing this. A seb search for > "download python" gives this as the first hit: > https://www.python.org/downloads/ > > I am guessing that the release process automatically updates that page > so that the minute 3.12 gets released the big yellow button will > suggest downloading 3.12.0 as the default option. Yes, you're quite right about that. > Perhaps it is really package authors who should be getting a release > out that is compatible with Python 3.12 before 3.12 itself is > released. It's tricky though because as a maintainer it makes more > sense to wait until you see the finished 3.12 product before making a > release that is fully tested with it (even if you are testing the > alphas etc in CI and making incremental fixes before 3.12 is > released). If you can find the incantation there are often pending builds for packages that need binary wheels, it may be "pip --pre" or it may be pointing to test.pypi.org... or there may not be. The projects may not tell you. And for many less experienced users (and yes this is a known issue), they have no idea they need to look. > The other option could be changing the downloads page so that it does > not suggest 3.12.0 as the default option until it is clear that at > least some baseline of widely used packages have uploaded compatible > wheels. There's been some suggestion of that before. Apparently the choice of what goes there is at least a bit political. Like many projects, I believe python prefers to recommend "the latest and best release", while user prudence (and especially organizational prudence) tends to say "hold off for a while until it's been fully vetted, and the ecosystem catches up". I don't think we can cast too much blame on either: I don't expect Microsoft will say "Don't download Windows 12 for the first six months", even if they know perfectly well that many enterprise customers will take an approach like that. Not sure there's any really good answer, TBH. From torriem at gmail.com Tue Apr 11 14:51:08 2023 From: torriem at gmail.com (Michael Torrie) Date: Tue, 11 Apr 2023 12:51:08 -0600 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: <16bc870f-c99b-8efd-44c1-b818324eef64@roelschroeven.net> <0b9d0f10-4800-0515-bd73-d6e2dce2b89e@wichmann.us> Message-ID: On 4/11/23 11:48, Oscar Benjamin wrote: > You can hardly blame a lot of people for doing this. A seb search for > "download python" gives this as the first hit: > https://www.python.org/downloads/ Very true, but it points to the difference between how people install Python on Windows compared to Linux, which is what Chris was probably referring to when he said Windows was a nightmare to support. Usually when a full version bump of python hits my distros, all the other packages that need to be rebuilt get rebuilt and install along with the new python package. Or often the older version of Python is patched and continued to be used, not requiring new packages. So most linux users never have to go searching for an appropriate version of Numpy, etc. Whereas Windows only recently has gained a package manager, and as near as I can tell is not widely used outside of serious developers who use Visual Studio. And to make matters worse, MS offers Python in the Windows Store, which is its own thing and causes much confusion with users who often end up with more than one version of Python installed. And nevermind the MingW/MSVC split that affects the distribution of pre-built binaries, although MS's move to the universal C runtime dll system might fix this finally (unless C++ is involved). These are all extremely hard problems to solve, and every solution has its drawbacks, including the packaging systems used by Linux. Especially by an open source organization like the PSF. From David.Raymond at tomtom.com Tue Apr 11 15:38:31 2023 From: David.Raymond at tomtom.com (David Raymond) Date: Tue, 11 Apr 2023 19:38:31 +0000 Subject: Initialising a Config class In-Reply-To: <87sfd6trtl.fsf@debian-BULLSEYE-live-builder-AMD64> References: <87sfd6trtl.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: Not sure if I'm fully understanding the question. But one option instead of making everything class attributes is to just define __getattr__ for when it doesn't find an attribute. Won't work for every single valid section and option name (because of spaces, name overlaps, etc) but should cover most things. For example, you could use a dunder to separate section and option. Then something like this? import configparser class Config: def __init__(self, configFile): self._config = configparser.ConfigParser() self._config.read(configFile) def __getattr__(self, option): if "__" in option: section, option = option.split("__", 1) else: section = self._config.default_section return self._config[section][option] c = Config("SomeConfigFile.txt") print(c.uids__minimum_uid) #Will check for the option "minimum_uid" in the "uids" section print(c.minimum_uid) #Will check the default section Not sure if that works as you said the Config class itself should not need to be changed > Hi, > > Having solved my problem regarding setting up 'logger' such that it is > accessible throughout my program (thanks to the help on this list), I > now have problem related to a slightly similar issue. > > My reading suggests that setting up a module with a Config class which > can be imported by any part of the program might be a reasonable approach: > > > import configparser > > class Config: > > def __init__(self, config_file): > > config = configparser.ConfigParser() > config.read(config_file) > > > However, in my config file I am using sections, so 'config' is a dict of > dicts. Is there any cleverer generic way of initialising the class than > > > self.config = config > > > ? > > This seems a bit clunky, because I'll end up with something like > > > import config > ... > c = config.Config(config_file) > uids = get_uids(int(c.config["uids"]["minimum_uid"])) > > > rather than something like, maybe > > > uids = get_uids(int(c.minimum_uid)) > > > or > > > uids = get_uids(int(c.uids_minimum_uid)) > > > So the question is: How can I map a dict of dicts onto class attributes > in a generic way such that only code which wants to use a new > configuration parameter needs to be changed and not the Config class > itself? Or should I be doing this differently? > > Note that the values from ConfigParser are all strings, so I am fine > with the attributes being strings - I'll just convert them as needed at > the point of use (but maybe there is also a better way of handling that > within a class). > > Cheers, > > Loris > From PythonList at DancesWithMice.info Tue Apr 11 16:26:45 2023 From: PythonList at DancesWithMice.info (dn) Date: Wed, 12 Apr 2023 08:26:45 +1200 Subject: Initialising a Config class In-Reply-To: <87sfd6trtl.fsf@debian-BULLSEYE-live-builder-AMD64> References: <87sfd6trtl.fsf@debian-BULLSEYE-live-builder-AMD64> Message-ID: <733f4cc0-41a0-c1ce-4f2c-3ff780e31005@DancesWithMice.info> On 12/04/2023 02.29, Loris Bennett wrote: > Hi, > > Having solved my problem regarding setting up 'logger' such that it is ... > My reading suggests that setting up a module with a Config class which > can be imported by any part of the program might be a reasonable approach: ... > However, in my config file I am using sections, so 'config' is a dict of > dicts. Is there any cleverer generic way of initialising the class than ... > This seems a bit clunky, because I'll end up with something like ... > So the question is: How can I map a dict of dicts onto class attributes > in a generic way such that only code which wants to use a new > configuration parameter needs to be changed and not the Config class > itself? Or should I be doing this differently? > > Note that the values from ConfigParser are all strings, so I am fine > with the attributes being strings - I'll just convert them as needed at > the point of use (but maybe there is also a better way of handling that > within a class). Good progress! The first achievement has been related to the (OO) concept of "encapsulation" - collecting related data into one place. The second, has been the making of this, globally-accessible within the application. The balancing-act may now have become: making sub-sets of the data available. Thus, describing which database server and schema/view to use is part of the application's environment/config, just as much as the labels, eg company name, used in the GUI or reporting. Such data has been collected together (into a single 'source of truth'), but will be used in quite separate and/or disparate functionality within the application. The config file has been (sensibly) split into sections - when the code is dealing with the DB it does not need to be concerned with GUI-settings - or vice-versa. Accordingly, and like any other class (encapsulation), having been collected en-masse (or 'amassed', eg cmdLN options combined with a JSON/YAML/.ini file's settings) the data should be delivered appropriately. Thus, a 'getter' method (or property) to deliver the name of the company (likely a string). The one for the database may deliver a dict or key-value pairs which can be immediately 'pasted' into some db-open function-call... Such retrieval-methods will be targeted to the sub-systems of the application. They can perform formatting and coercion tasks, as necessary, eg construct full-name from two or more separate data-items, eg first_name and family_name, or perhaps providing floats where the config-collection only receives strings. (best to 'hide' all that within the class, than require the application to deal with the 'clunkiness'). Plus, they could?should provide whatever combination of data-items is appropriate to THAT part of the application's need for config-data or constraints. (etc) Stuff as much as is possible into the config class - how to collect environment-data, and satisfying any/all demands for its use. Then, the application can be relieved of all detail ("give me what I want"), only asking for whatever it requires, when it requires, and in the format it requires - tailored and ready for immediate-use... -- Regards, =dn From PythonList at DancesWithMice.info Wed Apr 12 00:58:56 2023 From: PythonList at DancesWithMice.info (dn) Date: Wed, 12 Apr 2023 16:58:56 +1200 Subject: Dataclasses, immutability(?), and ChatGPT Message-ID: Are dataclasses (or instances thereof) mutable or immutable? - and in what sense? Have been experimenting with ChatGPT. In particular: its possibilities as a trainer, good ideas for methods of introducing new topics, its capability for drawing-up demonstrations or examples, its interpretation of assessment questions (ie evaluating my own work, eg do they test desired specifics, is it possible/likely to misinterpret the question, ...) Conversed with ChatGPT about the differences between (standard) custom-classes and dataclasses, and when one might prefer one over the other. We(?) started discussing how dataclasses might be introduced to trainees currently only familiar with Python's built-ins: "...how they are superior to using built-in data-constructs..." Amongst the four benefits ChatGPT listed was: ? Immutable instances: By default, instances of dataclasses are immutable, which means that once created, their attributes cannot be modified. This can help to prevent unintended modifications to the data. ? Huh? If we'd been discussing namedtuples over (say) dictionaries, I'd perhaps have accepted the reply. The next step was to write some code to double-check my understanding (reproduced below). No change there. (given that I'm perfect...cough, cough, splutter) Thus, back to ChatGPT to seek clarification: ? You said "Immutable instances: By default, instances of dataclasses are immutable, which means that once created, their attributes cannot be modified. This can help to prevent unintended modifications to the data." The attribute-values within a data-class can be changed. In what way are Python dataclasses immutable? ? ChatGPT did indeed clarify that: ? You're correct that the attribute values within a dataclass can be changed, even though the instance itself is considered immutable. ? That's better. The machine is as smart as I am - or I, as smart as it - or something(?) However, the supporting-explanation then appears to argue against its own clarification (and the assertion in the question): ? So to clarify, when we say that instances of dataclasses are immutable, we mean that the attributes of an instance cannot be changed after it is created. In other words, if you create an instance of a dataclass, its attributes cannot be modified by any external code. If you want to change the value of an attribute, you need to create a new instance of the dataclass with the updated attribute value. ... [code excised - see below] This is because the instance is considered immutable, and its attributes cannot be changed directly. Instead, we need to create a new instance of the dataclass with the updated attribute value, like this... Now, new_person is a new instance of the Person dataclass with the updated attribute values, while the original person instance remains unchanged. So to summarize, while the attribute values within a dataclass can be changed, instances of dataclasses are considered immutable because their attributes cannot be modified directly once they are created. Any updates to the attributes require the creation of a new instance of the dataclass. ? [Note] In and amongst the above explanatory-paragraphs it gives example code-snippets. Those are condensed into: >>> from dataclasses import dataclass >>> >>> @dataclass ... class Person: ... name: str ... age: int ... >>> person = Person(name='Alice', age=20) >>> >>> person.name = 'Bob' # raises AttributeError: can't set attribute >>> person.age = 21 # raises AttributeError: can't set attribute - note the erroneous comments about exceptions being raised (they weren't/aren't)! Here's a home-grown version illustrating all the points made during the investigation, by way of proof/disproof: """ PythonTraining:dataclass.py Prove/disprove claim made by Chat-GPT. """ __author__ = "dn, IT&T Consultant" __python__ = "3.11" __created__ = "PyCharm, 12 Apr 2023" __copyright__ = "Copyright ? 2023~" __license__ = "MIT" # PSL from dataclasses import dataclass @dataclass class Coordinates(): """Sample dataclass. """ x:int y:int if __name__ == "__main__": print( "\nCommencing execution\n" ) coordinates = Coordinates( 1, 2, ) print( coordinates, id( coordinates ), ) coordinates.x = 3 print( coordinates, id( coordinates ), ) coordinates.z = 4 print( coordinates, id( coordinates ), ) print( coordinates.x, coordinates.y, coordinates.z, ) ### output: Commencing execution Coordinates(x=1, y=2) 140436963150928 Coordinates(x=3, y=2) 140436963150928 Coordinates(x=3, y=2) 140436963150928 3 2 4 Terminating ### Not only are a dataclass instance's attribute-values mutable, but further attributes can be dynamically-added to the object-instance! Yes, if the code included: coordinates = Coordinates( 5, 6, ) the new "coordinates" identifier would point to a different id() 'address', ie a fresh immutable-instance. The 'book of words' (https://docs.python.org/3/library/dataclasses.html) does mention immutability (wrt to dataclasses) in that it is possible to add a __hash__() method (any object defined with is (technically) immutable). However, apart from the default_factory argument, there doesn't appear to be other discussion of [im]mutability. Anything I've 'missed'? - or a salutary tale of not depending upon ChatGPT etc? -- Regards, =dn From roel at roelschroeven.net Wed Apr 12 04:02:51 2023 From: roel at roelschroeven.net (Roel Schroeven) Date: Wed, 12 Apr 2023 10:02:51 +0200 Subject: Dataclasses, immutability(?), and ChatGPT In-Reply-To: References: Message-ID: <35c0528d-2ca3-062a-35ee-20de4b372971@roelschroeven.net> Op 12/04/2023 om 6:58 schreef dn via Python-list: > Are dataclasses (or instances thereof) mutable or immutable? > - and in what sense? Instances of dataclasses are mutable, just like normal classes. Dataclasses *are* normal classes, with some extra special methods. They are totally different from namedtuples, even though the use cases somewhat overlap. They *can* be immutable, I think, if the programmer takes care to make them so. I don't think adding __hash__() is enough: as I understand it's an indication that a class is immutable, but doesn't actually by itself make it so. "Mutability is a complicated property that depends on the programmer?s intent, the existence and behavior of |__eq__()|, and the values of the |eq| and |frozen| flags in the |dataclass()| decorator.", says the documentation. > Amongst the four benefits ChatGPT listed was: > ? > Immutable instances: By default, instances of dataclasses are > immutable, which means that once created, their attributes cannot be > modified. This can help to prevent unintended modifications to the data. > ? > > Huh? If we'd been discussing namedtuples over (say) dictionaries, I'd > perhaps have accepted the reply. ChatGPT is wrong. > Anything I've 'missed'? > - or a salutary tale of not depending upon ChatGPT etc? You didn't miss anything, ChatGPT is wrong. The thing to look out for is that when ChatGPT is wrong, it sounds just as convincing as when it's right; there is no indication in it's tone or style that it's making things up. Always double check! -- "A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools." -- Douglas Adams From miked at dewhirst.com.au Wed Apr 12 04:13:42 2023 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Wed, 12 Apr 2023 18:13:42 +1000 Subject: Christoph Gohlke and compiled packages In-Reply-To: <82d2b185-c8b9-d1d4-06a7-0d3d1cf8d1da@tompassin.net> References: <82d2b185-c8b9-d1d4-06a7-0d3d1cf8d1da@tompassin.net> Message-ID: Well thank you Christoph Gohlke and thank you Ian Bicking and colleagues. I just used pip to nakedly install psycopg2 and Pillow without a hitch. My distrust of Windows has kept me going back to Christoff's well for years. Maybe it is time to assume innocence unless proven guilty ;-) Thanks to all who showed me the way. Cheers Mike On 11/04/2023 11:39 pm, Thomas Passin wrote: > On 4/11/2023 6:58 AM, Chris Angelico wrote: >> On Tue, 11 Apr 2023 at 20:15, Jim Schwartz >> wrote: >>> >>> What?s the problem now?? Is it with python on windows?? I use python >>> on windows so I?d like to know. Thanks >>> >> >> Python itself is fine, but a lot of third-party packages are hard to >> obtain. So if you need numpy, for instance, or psycopg2, you might >> need to find an alternative source. > > I've noticed a big change in the last few years in that PyPi has many, > many amd-64 packages than it used to in the heyday of Christoph > Gohlke's efforts. I haven't needed to go there for some time whereas I > used to need to all the time.? So if I "need numpy, for instance, or > psycopg2" for Windows, I get them from PyPi. > > Yes, I know that some projects haven't caught up to Python 3.11x yet. > And I'm glad I haven't needed to create a binary wheel for Windows > myself.? But the situation is way better than it used to be.? I've had > more trouble with Python and Python packages on Linux than on Windows. > -- 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. 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 grant.b.edwards at gmail.com Wed Apr 12 08:00:36 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 12 Apr 2023 05:00:36 -0700 (PDT) Subject: Dataclasses, immutability(?), and ChatGPT References: <35c0528d-2ca3-062a-35ee-20de4b372971@roelschroeven.net> Message-ID: <64369d64.050a0220.44313.581e@mx.google.com> On 2023-04-12, Roel Schroeven wrote: >> Huh? If we'd been discussing namedtuples over (say) dictionaries, I'd >> perhaps have accepted the reply. > > ChatGPT is wrong. > >> Anything I've 'missed'? >> - or a salutary tale of not depending upon ChatGPT etc? > You didn't miss anything, ChatGPT is wrong. The thing to look out for is > that when ChatGPT is wrong, it sounds just as convincing as when it's > right; there is no indication in it's tone or style that it's making > things up. Yep, that's how ChatGPT works. It's a program to generate output language that sounds right based on a huge training set of text. Whether that "right sounding" language agrees with real world facts or not is irrelevent to the language-generating algorithm. -- Grant From list1 at tompassin.net Wed Apr 12 08:26:47 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 12 Apr 2023 08:26:47 -0400 Subject: Dataclasses, immutability(?), and ChatGPT In-Reply-To: References: Message-ID: <1247feb7-17a6-0f95-e4b2-3d8c18fe6be5@tompassin.net> On 4/12/2023 12:58 AM, dn via Python-list wrote: > Are dataclasses (or instances thereof) mutable or immutable? > - and in what sense? > > > Have been experimenting with ChatGPT. In particular: its possibilities > as a trainer, good ideas for methods of introducing new topics, its > capability for drawing-up demonstrations or examples, its interpretation > of assessment questions (ie evaluating my own work, eg do they test > desired specifics, is it possible/likely to misinterpret the question, ...) > > > Conversed with ChatGPT about the differences between (standard) > custom-classes and dataclasses, and when one might prefer one over the > other. > > We(?) started discussing how dataclasses might be introduced to trainees > currently only familiar with Python's built-ins: "...how they are > superior to using built-in data-constructs..." > > Amongst the four benefits ChatGPT listed was: > ? > Immutable instances: By default, instances of dataclasses are immutable, > which means that once created, their attributes cannot be modified. This > can help to prevent unintended modifications to the data. > ? > > Huh? If we'd been discussing namedtuples over (say) dictionaries, I'd > perhaps have accepted the reply. > > > The next step was to write some code to double-check my understanding > (reproduced below). No change there. > (given that I'm perfect...cough, cough, splutter) > > > Thus, back to ChatGPT to seek clarification: > ? > You said "Immutable instances: By default, instances of dataclasses are > immutable, which means that once created, their attributes cannot be > modified. This can help to prevent unintended modifications to the > data." The attribute-values within a data-class can be changed. In what > way are Python dataclasses immutable? > ? > > ChatGPT did indeed clarify that: > ? > You're correct that the attribute values within a dataclass can be > changed, even though the instance itself is considered immutable. > ? > > That's better. The machine is as smart as I am - or I, as smart as it - > or something(?) > > > However, the supporting-explanation then appears to argue against its > own clarification (and the assertion in the question): > ? > So to clarify, when we say that instances of dataclasses are immutable, > we mean that the attributes of an instance cannot be changed after it is > created. > > In other words, if you create an instance of a dataclass, its attributes > cannot be modified by any external code. If you want to change the value > of an attribute, you need to create a new instance of the dataclass with > the updated attribute value. > > ... [code excised - see below] > > This is because the instance is considered immutable, and its attributes > cannot be changed directly. Instead, we need to create a new instance of > the dataclass with the updated attribute value, like this... > > Now, new_person is a new instance of the Person dataclass with the > updated attribute values, while the original person instance remains > unchanged. > > So to summarize, while the attribute values within a dataclass can be > changed, instances of dataclasses are considered immutable because their > attributes cannot be modified directly once they are created. Any > updates to the attributes require the creation of a new instance of the > dataclass. > ? > > [Note] > In and amongst the above explanatory-paragraphs it gives example > code-snippets. Those are condensed into: > > >>> from dataclasses import dataclass > >>> > >>> @dataclass > ... class Person: > ...???? name: str > ...???? age: int > ... > >>> person = Person(name='Alice', age=20) > >>> > >>> person.name = 'Bob'? # raises AttributeError: can't set attribute > >>> person.age = 21????? # raises AttributeError: can't set attribute > > - note the erroneous comments about exceptions being raised > (they weren't/aren't)! > > > Here's a home-grown version illustrating all the points made during the > investigation, by way of proof/disproof: > > """ PythonTraining:dataclass.py > ??? Prove/disprove claim made by Chat-GPT. > """ > > __author__ = "dn, IT&T Consultant" > __python__ = "3.11" > __created__ = "PyCharm, 12 Apr 2023" > __copyright__ = "Copyright ? 2023~" > __license__ = "MIT" > > # PSL > from dataclasses import dataclass > > > @dataclass > class Coordinates(): > ??? """Sample dataclass. """ > ??? x:int > ??? y:int > > > if __name__ == "__main__": > ??? print( "\nCommencing execution\n" ) > > ??? coordinates = Coordinates( 1, 2, ) > ??? print( coordinates, id( coordinates ), ) > ??? coordinates.x = 3 > ??? print( coordinates, id( coordinates ), ) > ??? coordinates.z = 4 > ??? print( coordinates, id( coordinates ), ) > ??? print( coordinates.x, coordinates.y, coordinates.z, ) > > > ### output: > Commencing execution > > Coordinates(x=1, y=2) 140436963150928 > Coordinates(x=3, y=2) 140436963150928 > Coordinates(x=3, y=2) 140436963150928 > 3 2 4 > > Terminating > ### > > Not only are a dataclass instance's attribute-values mutable, but > further attributes can be dynamically-added to the object-instance! > > Yes, if the code included: > > coordinates = Coordinates( 5, 6, ) > > the new "coordinates" identifier would point to a different id() > 'address', ie a fresh immutable-instance. > > > The 'book of words' (https://docs.python.org/3/library/dataclasses.html) > does mention immutability (wrt to dataclasses) in that it is possible to > add a __hash__() method (any object defined with is (technically) > immutable). However, apart from the default_factory argument, there > doesn't appear to be other discussion of [im]mutability. > > > Anything I've 'missed'? > - or a salutary tale of not depending upon ChatGPT etc? People need to remember that ChatGPT-like systems put words together the way that many humans usually do. So what they emit usually sounds smooth and human-like. If it's code they emit, it will tend to seem plausible because lines of code are basically sentences, and learning how to construct plausible sentences is what these systems are built to do. That's **plausible**, not "logical" or "correct". The vast size of these systems means that they can include a larger context in figuring out what words to place next compared with earlier, smaller systems. But consider: what if you wrote code as a stream-of-consciousness process? That code might seem plausible, but why would you have any confidence in it? Or to put it another way, what if most of ChatGPT's exposure to code came from StackOverflow archives? On top of that, ChapGPT-like systems do not know your requirements nor the reasons behind your requests. They only know that when other people put words and phrases together like you did, they tended to make responses that sound like what the chatbot emits next. It's basically cargo-culting its responses. Apparently researchers have been learning that the more parameters that a system like this has, the more likely it is to learn how to emit responses that the questioner likes. Essentially, it could become the ultimate yes-man! So there is some probability that the system will tell you interesting or useful things, some probability that it will try to tell you what it thinks you want hear, some probability that it will tell you incorrect things that other people have repeated, and some probability that it will perseverate - simply make things up. If I were going to write a novel about an alternate history, I think that a chatGPT-like system would be a fantastic writing assistant. Code? Not so much. From miked at dewhirst.com.au Wed Apr 12 08:59:03 2023 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Wed, 12 Apr 2023 22:59:03 +1000 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: <82d2b185-c8b9-d1d4-06a7-0d3d1cf8d1da@tompassin.net> Message-ID: <0db1af84-212e-566a-2a8f-bed5226987f5@dewhirst.com.au> Sadly Windows is still in the dock. The jury is still out. Turns out the "without a hitch" was based on cached wheels. I'm going to start from scratch with new projects using Pythons 3.8, 3.10 and 3.11 and report back. Cheers Mike On 12/04/2023 6:13 pm, Mike Dewhirst wrote: > Well thank you Christoph Gohlke and thank you Ian Bicking and colleagues. > > I just used pip to nakedly install psycopg2 and Pillow without a > hitch. My distrust of Windows has kept me going back to Christoff's > well for years. > > Maybe it is time to assume innocence unless proven guilty ;-) > > Thanks to all who showed me the way. > > Cheers > > Mike > > On 11/04/2023 11:39 pm, Thomas Passin wrote: >> On 4/11/2023 6:58 AM, Chris Angelico wrote: >>> On Tue, 11 Apr 2023 at 20:15, Jim Schwartz >>> wrote: >>>> >>>> What?s the problem now?? Is it with python on windows?? I use >>>> python on windows so I?d like to know. Thanks >>>> >>> >>> Python itself is fine, but a lot of third-party packages are hard to >>> obtain. So if you need numpy, for instance, or psycopg2, you might >>> need to find an alternative source. >> >> I've noticed a big change in the last few years in that PyPi has >> many, many amd-64 packages than it used to in the heyday of Christoph >> Gohlke's efforts. I haven't needed to go there for some time whereas >> I used to need to all the time.? So if I "need numpy, for instance, >> or psycopg2" for Windows, I get them from PyPi. >> >> Yes, I know that some projects haven't caught up to Python 3.11x yet. >> And I'm glad I haven't needed to create a binary wheel for Windows >> myself.? But the situation is way better than it used to be.? I've >> had more trouble with Python and Python packages on Linux than on >> Windows. >> > > > -- 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. 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 list1 at tompassin.net Wed Apr 12 09:19:59 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 12 Apr 2023 09:19:59 -0400 Subject: Christoph Gohlke and compiled packages In-Reply-To: <0db1af84-212e-566a-2a8f-bed5226987f5@dewhirst.com.au> References: <82d2b185-c8b9-d1d4-06a7-0d3d1cf8d1da@tompassin.net> <0db1af84-212e-566a-2a8f-bed5226987f5@dewhirst.com.au> Message-ID: <3331243b-5d19-1ada-efde-20da781ce287@tompassin.net> On 4/12/2023 8:59 AM, Mike Dewhirst wrote: > Sadly Windows is still in the dock. The jury is still out. > > Turns out the "without a hitch" was based on cached wheels. > > I'm going to start from scratch with new projects using Pythons 3.8, > 3.10 and 3.11 and report back. Sorry for the length to come, but here's what I've got so far - on Windows, python 3.11 - all pip-installed. Note especially numpy, scipy, statsmodels, mysql-connector-python, scikit-learn - C:\Users\tom>py -V Python 3.11.3 C:\Users\tom>py -m pip list Package Version ----------------------------- ------------------- accessible-pygments 0.0.4 alabaster 0.7.13 argcomplete 3.0.5 asciidoc 10.2.0 asciidoc3 3.2.3 astroid 2.15.2 asttokens 2.2.1 async-generator 1.10 attrs 22.2.0 Babel 2.12.1 beautifulsoup4 4.12.1 black 23.3.0 bleach 6.0.0 bokeh 2.4.3 build 0.10.0 certifi 2022.12.7 cffi 1.15.1 cftime 1.6.2 charset-normalizer 3.1.0 click 8.1.3 colorama 0.4.6 colorcet 3.0.1 contourpy 1.0.7 csaps 1.1.0 cycler 0.11.0 datatable 1.1.0a0+pr3440.2228 defusedxml 0.7.1 dialite 0.5.3 dill 0.3.6 docutils 0.19 exceptiongroup 1.1.1 fastjsonschema 2.16.3 fire 0.5.0 flexx 0.8.4 fonttools 4.39.3 frechetdist 0.6 GenDoc 1.0.1 ghp-import 2.1.0 h11 0.14.0 holoviews 1.15.4 idna 3.4 imageio 2.27.0 imagesize 1.4.1 importlib-metadata 6.1.0 iniconfig 2.0.0 isort 5.12.0 jaraco.classes 3.2.3 jill 0.11.3 Jinja2 3.1.2 joblib 1.2.0 jsonschema 4.17.3 jupyter_client 8.1.0 jupyter_core 5.3.0 jupyterlab-pygments 0.2.2 karma-sphinx-theme 0.0.8 keyring 23.13.1 kiwisolver 1.4.4 lazy_loader 0.2 lazy-object-proxy 1.9.0 leo 6.7.2 linkify-it-py 2.0.0 localreg 0.5.0 lxml 4.9.2 lz4 4.3.2 Markdown 3.3.7 markdown-it-py 2.2.0 MarkupSafe 2.1.2 matplotlib 3.6.3 mccabe 0.7.0 mdit-py-plugins 0.3.5 mdurl 0.1.2 mergedeep 1.3.4 meta 1.0.2 mistune 2.0.5 mizani 0.8.1 mkdocs 1.4.2 mkdocs-exclude 1.0.2 more-itertools 9.1.0 mpmath 1.3.0 multidict 6.0.4 mypy 1.2.0 mypy-extensions 1.0.0 mysql-connector-python 8.0.32 mysqlclient 2.1.1 nbclient 0.7.3 nbconvert 7.3.0 nbformat 5.8.0 nest-asyncio 1.5.6 netCDF4 1.6.3 networkx 3.1 nltk 3.8.1 numpy 1.24.2 outcome 1.2.0 packaging 23.0 palettable 3.3.1 pandas 2.0.0 pandoc 2.3 pandocfilters 1.5.0 panel 0.14.4 param 1.13.0 pathspec 0.11.1 patsy 0.5.3 pep517 0.13.0 Pillow 9.5.0 pip 23.0.1 pipx 1.2.0 pkginfo 1.9.6 platformdirs 3.2.0 plotly 5.14.1 plotnine 0.10.1 pluggy 1.0.0 plumbum 1.8.1 ply 3.11 progressbar2 4.2.0 protobuf 4.22.1 pscript 0.7.7 pwlf 2.2.1 pycodestyle 2.10.0 pycparser 2.21 pyct 0.5.0 pydata-sphinx-theme 0.13.3 pyDOE 0.3.8 pyenchant 3.2.2 pyflakes 3.0.1 pygam 0.9.0 Pygments 2.14.0 pylint 2.17.2 pyparsing 3.0.9 pyperclip 1.8.2 pyproject_hooks 1.0.0 PyQt5 5.15.9 PyQt5-Qt5 5.15.2 PyQt5-sip 12.11.1 PyQt6 6.4.2 PyQt6-Qt6 6.4.3 PyQt6-sip 13.4.1 PyQt6-WebEngine 6.4.0 PyQt6-WebEngine-Qt6 6.4.3 PyQtWebEngine 5.15.6 PyQtWebEngine-Qt5 5.15.2 pyrsistent 0.19.3 pyshortcuts 1.8.3 PySocks 1.7.1 pytest 7.2.2 python-dateutil 2.8.2 python-dotenv 1.0.0 python-gnupg 0.5.0 python-utils 3.5.2 pytz 2023.3 pyviz-comms 2.2.1 PyWavelets 1.4.1 pywin32 306 pywin32-ctypes 0.2.0 PyYAML 6.0 pyyaml_env_tag 0.1 pyzmq 25.0.2 readme-renderer 37.3 regex 2023.3.23 requests 2.28.2 requests-futures 1.0.0 requests-toolbelt 0.10.1 rfc3986 2.0.0 rich 13.3.3 scaleogram 0.9.5 scikit-image 0.20.0 scikit-learn 1.2.2 scipy 1.10.1 seaborn 0.12.2 selenium 4.8.3 semantic-version 2.10.0 setuptools 67.6.1 six 1.16.0 sniffio 1.3.0 snowballstemmer 2.2.0 sortedcontainers 2.4.0 soupsieve 2.4 Sphinx 6.1.3 sphinx-panels 0.6.0 sphinx-rtd-theme 1.2.0 sphinxcontrib-applehelp 1.0.4 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 2.0.1 sphinxcontrib-jquery 4.1 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-mermaid 0.8.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.5 statsmodels 0.13.5 tabulate 0.9.0 tenacity 8.2.2 termcolor 2.2.0 textblob 0.17.1 textual 0.18.0 threadpoolctl 3.1.0 tifffile 2023.3.21 tinycss2 1.2.1 tk 0.1.0 tomli 2.0.1 tomlkit 0.11.7 tornado 6.2 tqdm 4.65.0 traitlets 5.9.0 trio 0.22.0 trio-websocket 0.10.2 twine 4.0.2 types-docutils 0.19.1.7 typing_extensions 4.5.0 tzdata 2023.3 uc-micro-py 1.0.1 urllib3 1.26.15 userpath 1.8.0 watchdog 3.0.0 webdriver-manager 3.8.5 webencodings 0.5.1 webruntime 0.5.8 websockets 11.0.1 wget 3.2 wheel 0.40.0 Whoosh 2.7.4 windows-curses 2.3.1 wrapt 1.15.0 wsproto 1.2.0 xyzservices 2023.2.0 yapf 0.32.0 yarl 1.8.2 zipp 3.15.0 From garyfallidis at gmail.com Tue Apr 11 22:50:42 2023 From: garyfallidis at gmail.com (Eleftherios Garyfallidis) Date: Tue, 11 Apr 2023 22:50:42 -0400 Subject: DIPY Workshop 2023 now to be held online! April 24-28. Message-ID: Dear all, Due to unexpected events we have had to make the decision to transition our workshop to a virtual format. While this change was unexpected, we are well-prepared due to our previous experience with our own online platform. Rest assured, we are fully equipped to ensure that the virtual workshop will run smoothly. It's worth noting that all talks this year will be conducted live, as opposed to pre-recorded. So now we are offering the following updated and flexible registration options: Silver : Starts from $200 1. Listen to the talks live. Learn from the experts. 2. 3 days workshop, get the basic kit to strive in the diffusion imaging world. 3. Ability to upgrade during the workshop. Gold : Starts from $500 Everything in Silver plus: 1. Ability to attend study groups and to present your work. 2. Full 5 days workshop. 3. Certificate of attendance (Linkedin verifiable). Platinum : Starts from $995 Everything in Gold plus: 1. Provides additional preset hourly meetings with the DIPY developers beyond the workshop's duration. These will be 1 to 1 meetings to set up or improve your pipeline for your needs. Maximum 6 meetings. Each meeting will be 1 hour long. 2. Provides access to the talks and all materials after the workshop. 3. Ability to move to yearly long support. Register now ! In summary, the workshop offers: - Hands-on tutorials - Every single day !!! - Guided practice sessions (bring your data) - Personalized certificates of attendance - Effective networking opportunities with one-to-one follow ups - Comprehensive explanation of theoretical foundations with practical examples - Access to latest and established methods with code and interfaces - Pointers to move beyond the current challenges and navigate hard to do analyses - Multiple clinical use cases (AZ, Parkinson?s, Stroke, etc.) This year there is a higher level of focus in AI and ML. These technologies have been transforming various industries, and now they are revolutionizing medical imaging. By harnessing the power of advanced algorithms and vast data sets, we have successfully integrated machine learning into our imaging solutions, providing unparalleled accuracy and efficiency. For those of you who are new to this. DIPY is an open source software project used for processing structural and diffusion imaging data. Join us for an exciting in person workshop hosted online April 24-28. https://dipy.org/workshops/latest Our team of expert instructors will guide you through the fundamentals of diffusion theory, data pre-processing, fiber tracking, and much more. You'll have the opportunity to learn from industry-leading professionals, ask questions, and network with like-minded peers. Register today to secure your spot in this highly anticipated event. Now online!! https://dipy.org/workshops/dipy-workshop-2023#Registration Happy to answer any questions you may have. Thank you!, DIPY team From ali.mohseniroodbari at gmail.com Wed Apr 12 04:03:13 2023 From: ali.mohseniroodbari at gmail.com (Ali Mohseni Roodbari) Date: Wed, 12 Apr 2023 11:33:13 +0330 Subject: Weak Type Ability for Python Message-ID: Hi all, Please make this command for Python (if possible): >>> x=1 >>> y='a' >>> wprint (x+y) >>> 1a In fact make a new type of print command which can print and show strings and integers together. Sincerely yours, Ali. From info at cmcc.it Wed Apr 12 06:05:39 2023 From: info at cmcc.it (info cmcc) Date: Wed, 12 Apr 2023 12:05:39 +0200 Subject: Post Degree in Machine Learning | Job position at CMCC Foundation, Italy In-Reply-To: References: Message-ID: *POST-DEGREE IN MACHINE LEARNING* [Job Opening Code: 12404] *Lecce (Italy) - Deadline: 15/04/2023* Our Division of Advanced Scientific Computing (ASC Division) is considering the possibility to hire a talented and proactive Post Degree candidate to support CMCC research activities. The contract will be jointly funded by CMCC and the HPC Training and Research for Earth Sciences (HPC-TRES) program. The job location is CMCC Headquarters in Lecce, Italy. We are looking for a motivated person with the following requirements: - M.Sc. degree in Computer Science or Computer Engineering or equivalent fields; - 2+ years? experience in scientific software development; - Excellent knowledge of Python programming language; - Good knowledge of Python scientific (numpy, scipy, scikit-learn, pandas) and visualization (e.g., matplotlib) libraries; - Good theoretical knowledge of Machine Learning algorithms and techniques for regression and classification tasks; - Good knowledge of at least one Machine/Deep Learning framework (e.g., TensorFlow, Keras, Pytorch); - Good capabilities in writing technical reports and scientific papers as well as documenting code; - Good knowledge of both written and spoken English language. Additional preferred experience: - Experience with HPC systems - Experience in training ML models in distributed environments and corresponding strategies Belonging to legally protected categories (ex L. 68/99) will constitute a preferential condition. *More details and info about HOW TO APPLY:* https://cmccfoundation.applytojob.com/apply/c4A2a92Co7/12404-POST-DEGREEMachine-Learning-Skills?source=Our%20Career%20Page%20Widget -- Fondazione CMCCCentro Euro-Mediterraneo sui Cambiamenti Climatici Via Marco Biagi, 5 - 73100 Lecce info at cmcc.it - www.cmcc.it From nospam at please.ty Wed Apr 12 06:29:59 2023 From: nospam at please.ty (jak) Date: Wed, 12 Apr 2023 12:29:59 +0200 Subject: for a 'good python' Message-ID: Hi everyone, some time ago I wrote a class to determine if an ipv4 address belonged to a subnet. Seldom using python I'm pretty sure it's not written in 'good python' nor too portable. Could you give me some advice to make it better? class calcip: def __init__(self, psubnet: str): ssubnet, scidr = psubnet.replace(' ', '').split('/') subnet = int.from_bytes(tuple( map(lambda n: (int(n)), ssubnet.split('.'))), 'big') cidr = int(scidr) mask = ((2 ** cidr) - 1) << (32 - cidr) self.__network = subnet & mask self.__wildcard = ~mask & 0xffffffff self.__broadcast = (subnet | self.__wildcard) & 0xffffffff self.__tsubnet = tuple(subnet.to_bytes(4, 'big')) self.__tnetwork = tuple(self.__network.to_bytes(4, 'big')) self.__tbroadcast = tuple(self.__broadcast.to_bytes(4, 'big')) self.__tmask = tuple(mask.to_bytes(4, 'big')) self.__twildcard = tuple(self.__wildcard.to_bytes(4, 'big')) self.__host_min = tuple((self.__network + 1).to_bytes(4, 'big')) self.__host_max = tuple((self.__broadcast - 1).to_bytes(4, 'big')) @staticmethod def __to_str(val: tuple): return '.'.join(str(v) for v in val) @property def subnet(self): return self.__to_str(self.__tsubnet) @property def network(self): return self.__to_str(self.__tnetwork) @property def broadcast(self): return self.__to_str(self.__tbroadcast) @property def mask(self): return self.__to_str(self.__tmask) @property def wildcard(self): return self.__to_str(self.__twildcard) @property def host_min(self): return self.__to_str(self.__host_min) @property def host_max(self): return self.__to_str(self.__host_max) @property def hosts_num(self): return self.__wildcard - 1 @property def net_class(self): tst = (self.__tnetwork[0] & 0xf0) >> 4 if (tst & 0x8) == 0: clx = 'A' elif (tst & 0xc) == 0x8: clx = 'B' elif (tst & 0xe) == 0xc: clx = 'C' elif (tst & 0xf) == 0xe: clx = 'D' elif (tst & 0xf) == 0xf: clx = 'E' return clx def __contains__(self, item): ret = True row_hdr = None try: row_hdr = int.from_bytes(tuple(map(lambda n: (int(n)), item.split('.'))), 'big') except: ret = False if ret: if not self.__network < row_hdr < self.__broadcast: ret = False return ret def main(): sn = calcip('10.0.0.0/26') print(f"subnet: {sn.subnet}") print(f"network: {sn.network}") print(f"broadcast: {sn.broadcast}") print(f"mask: {sn.mask}") print(f"wildcard: {sn.wildcard}") print(f"host_min: {sn.host_min}") print(f"host_max: {sn.host_max}") print(f"Avaible hosts: {sn.hosts_num}") print(f"Class: {sn.net_class}") tst_hdr = '10.0.0.31' is_not = 'is ' if not tst_hdr in sn: is_not = 'is NOT ' print("hdr %s %sin range %s - %s" % (tst_hdr, is_not, sn.host_min, sn.host_max)) if __name__ == '__main__': main() From nospam at please.ty Wed Apr 12 08:50:29 2023 From: nospam at please.ty (jak) Date: Wed, 12 Apr 2023 14:50:29 +0200 Subject: for a 'good python' In-Reply-To: References: Message-ID: Stefan Ram ha scritto: > jak writes: >> @property >> def subnet(self): >> return self.__to_str(self.__tsubnet) > > Maybe each of those attributes should be an object of a > special class where your "__to_str" is "__str__"? E.g., > > # code in "calcip.__init__" > self.tsubnet = ip_address_class.from_int( subnet ) > > where "ip_address_class" is as in: > > import collections > import random > > class ip_address_class( collections.UserList ): > def __init__( self, bytes_address ): > super().__init__( bytes_address ) > @classmethod > def from_int( cls, int_address ): > return cls( int_address.to_bytes( 4, 'big' )) > def __str__( self ): > return '.'.join( str( byte_ )for byte_ in self.data ) > > if __name__ == '__main__': > ip_address = \ > ip_address_class.from_int( random.randint( 0, 4294967295 )) > print( ip_address[ 0 ]) > print( ip_address ) > > . Now the client can access each byte individually and also > get a "nice" string representation. > > (You may add more "from_..." methods for all the various > formats you create addresses from.) > > But you should also research the standard library to see > if something like this doesn't already exist ready-made > specifically for IP addresses in the standard library. > > ok. thanks a lot. now i try to do that. From rosuav at gmail.com Wed Apr 12 13:11:35 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Apr 2023 03:11:35 +1000 Subject: Weak Type Ability for Python In-Reply-To: References: Message-ID: On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari wrote: > > Hi all, > Please make this command for Python (if possible): > > >>> x=1 > >>> y='a' > >>> wprint (x+y) > >>> 1a > > In fact make a new type of print command which can print and show strings > and integers together. > Try: print(x, y) ChrisA From mats at wichmann.us Wed Apr 12 14:57:39 2023 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 12 Apr 2023 12:57:39 -0600 Subject: Weak Type Ability for Python In-Reply-To: References: Message-ID: <5d7514ec-d6b0-85e8-1c3f-d05c14ff0c24@wichmann.us> On 4/12/23 11:11, Chris Angelico wrote: > On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari > wrote: >> >> Hi all, >> Please make this command for Python (if possible): >> >>>>> x=1 >>>>> y='a' >>>>> wprint (x+y) >>>>> 1a >> >> In fact make a new type of print command which can print and show strings >> and integers together. >> > > Try: > > print(x, y) > > ChrisA To continue on, what do you want "addition" of dissimilar types to do - since that's what you have asked for above. You can write yourself an object which is happy with certain combinations, so you don't have this scenario: >>> x + y Traceback (most recent call last): File "", line 1, in x + y ~~^~~ TypeError: can only concatenate str (not "int") to str >>> y + x Traceback (most recent call last): File "", line 1, in y + x ~~^~~ TypeError: unsupported operand type(s) for +: 'int' and 'str' >>> Or you can help out the print function by doing some of the fiddling yourself: >>> print(f"{x}{y}") 1a From list1 at tompassin.net Wed Apr 12 14:51:44 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 12 Apr 2023 14:51:44 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: Message-ID: On 4/12/2023 1:11 PM, Chris Angelico wrote: > On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari > wrote: >> >> Hi all, >> Please make this command for Python (if possible): >> >>>>> x=1 >>>>> y='a' >>>>> wprint (x+y) >>>>> 1a >> >> In fact make a new type of print command which can print and show strings >> and integers together. >> > > Try: > > print(x, y) > > ChrisA It puts a space between "1" and "a", whereas the question does not want the space. print(f'{x}{y}') would do it, but only works for variables named "x" and "y". As happens so often, the OP has not specified what he actually wants to do so we can only answer the very specific question. From python at mrabarnett.plus.com Wed Apr 12 15:11:32 2023 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Apr 2023 20:11:32 +0100 Subject: Weak Type Ability for Python In-Reply-To: <5d7514ec-d6b0-85e8-1c3f-d05c14ff0c24@wichmann.us> References: <5d7514ec-d6b0-85e8-1c3f-d05c14ff0c24@wichmann.us> Message-ID: <86423bf1-aa48-5ce4-f144-81024cc3c351@mrabarnett.plus.com> On 2023-04-12 19:57, Mats Wichmann wrote: > On 4/12/23 11:11, Chris Angelico wrote: >> On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari >> wrote: >>> >>> Hi all, >>> Please make this command for Python (if possible): >>> >>>>>> x=1 >>>>>> y='a' >>>>>> wprint (x+y) >>>>>> 1a >>> >>> In fact make a new type of print command which can print and show strings >>> and integers together. >>> >> >> Try: >> >> print(x, y) >> >> ChrisA > > > To continue on, what do you want "addition" of dissimilar types to do - > since that's what you have asked for above. > > You can write yourself an object which is happy with certain > combinations, so you don't have this scenario: > > >>> x + y > Traceback (most recent call last): > File "", line 1, in > x + y > ~~^~~ > TypeError: can only concatenate str (not "int") to str > >>> y + x > Traceback (most recent call last): > File "", line 1, in > y + x > ~~^~~ > TypeError: unsupported operand type(s) for +: 'int' and 'str' > >>> > > > Or you can help out the print function by doing some of the fiddling > yourself: > > >>> print(f"{x}{y}") > 1a > Or: >>> print(x, y, sep='') 1a From grant.b.edwards at gmail.com Wed Apr 12 15:22:44 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 12 Apr 2023 12:22:44 -0700 (PDT) Subject: Weak Type Ability for Python References: Message-ID: <64370504.050a0220.fb954.4fef@mx.google.com> On 2023-04-12, Ali Mohseni Roodbari wrote: > Hi all, > Please make this command for Python (if possible): > >>>> x=1 >>>> y='a' >>>> wprint (x+y) >>>> 1a If that's what you want, use PHP or some other language. Don't try to ruin Python. > In fact make a new type of print command which can print and show strings > and integers together. From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Apr 12 15:17:17 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Wed, 12 Apr 2023 15:17:17 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: Message-ID: On 2023-04-12 at 14:51:44 -0400, Thomas Passin wrote: > On 4/12/2023 1:11 PM, Chris Angelico wrote: > > On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari > > wrote: > > > > > > Hi all, > > > Please make this command for Python (if possible): > > > > > > > > > x=1 > > > > > > y='a' > > > > > > wprint (x+y) > > > > > > 1a > > > > > > In fact make a new type of print command which can print and show strings > > > and integers together. > > > > > > > Try: > > > > print(x, y) > > > > ChrisA > > It puts a space between "1" and "a", whereas the question does not want the > space. print(f'{x}{y}') would do it, but only works for variables named "x" > and "y". Or possibly print(x, y, sep=''). > As happens so often, the OP has not specified what he actually wants to do > so we can only answer the very specific question. Agreed. From barry at barrys-emacs.org Wed Apr 12 17:36:57 2023 From: barry at barrys-emacs.org (Barry) Date: Wed, 12 Apr 2023 22:36:57 +0100 Subject: for a 'good python' Message-ID: ? > On 12 Apr 2023, at 18:10, jak wrote: > ?Hi everyone, > some time ago I wrote a class to determine if an ipv4 address belonged > to a subnet. Seldom using python I'm pretty sure it's not written in > 'good python' nor too portable. Could you give me some advice to make it > better? > > class calcip: > def __init__(self, psubnet: str): > ssubnet, scidr = psubnet.replace(' ', '').split('/') > subnet = int.from_bytes(tuple( > map(lambda n: (int(n)), ssubnet.split('.'))), > 'big') > cidr = int(scidr) > mask = ((2 ** cidr) - 1) << (32 - cidr) > self.__network = subnet & mask > self.__wildcard = ~mask & 0xffffffff > self.__broadcast = (subnet | self.__wildcard) & 0xffffffff > self.__tsubnet = tuple(subnet.to_bytes(4, 'big')) > self.__tnetwork = tuple(self.__network.to_bytes(4, 'big')) > self.__tbroadcast = tuple(self.__broadcast.to_bytes(4, 'big')) > self.__tmask = tuple(mask.to_bytes(4, 'big')) > self.__twildcard = tuple(self.__wildcard.to_bytes(4, 'big')) > self.__host_min = tuple((self.__network + 1).to_bytes(4, 'big')) > self.__host_max = tuple((self.__broadcast - 1).to_bytes(4, 'big')) > > @staticmethod > def __to_str(val: tuple): > return '.'.join(str(v) for v in val) > > @property > def subnet(self): > return self.__to_str(self.__tsubnet) > > @property > def network(self): > return self.__to_str(self.__tnetwork) > > @property > def broadcast(self): > return self.__to_str(self.__tbroadcast) > > @property > def mask(self): > return self.__to_str(self.__tmask) > > @property > def wildcard(self): > return self.__to_str(self.__twildcard) > > @property > def host_min(self): > return self.__to_str(self.__host_min) > > @property > def host_max(self): > return self.__to_str(self.__host_max) > > @property > def hosts_num(self): > return self.__wildcard - 1 > > @property > def net_class(self): > tst = (self.__tnetwork[0] & 0xf0) >> 4 > if (tst & 0x8) == 0: > clx = 'A' > elif (tst & 0xc) == 0x8: > clx = 'B' > elif (tst & 0xe) == 0xc: > clx = 'C' > elif (tst & 0xf) == 0xe: > clx = 'D' > elif (tst & 0xf) == 0xf: > clx = 'E' > return clx > > def __contains__(self, item): > ret = True > row_hdr = None > try: > row_hdr = int.from_bytes(tuple(map(lambda n: (int(n)), item.split('.'))), 'big') > except: > ret = False > if ret: > if not self.__network < row_hdr < self.__broadcast: > ret = False > return ret > > > def main(): > sn = calcip('10.0.0.0/26') > > print(f"subnet: {sn.subnet}") > print(f"network: {sn.network}") > print(f"broadcast: {sn.broadcast}") > print(f"mask: {sn.mask}") > print(f"wildcard: {sn.wildcard}") > print(f"host_min: {sn.host_min}") > print(f"host_max: {sn.host_max}") > print(f"Avaible hosts: {sn.hosts_num}") > print(f"Class: {sn.net_class}") > > tst_hdr = '10.0.0.31' > is_not = 'is ' > if not tst_hdr in sn: > is_not = 'is NOT ' > print("hdr %s %sin range %s - %s" % > (tst_hdr, is_not, sn.host_min, sn.host_max)) > > if __name__ == '__main__': > main() There is this https://docs.python.org/3/howto/ipaddress.html if you just want a solution. Or are you after code review feedback? Barry > -- > https://mail.python.org/mailman/listinfo/python-list From nospam at please.ty Wed Apr 12 18:21:58 2023 From: nospam at please.ty (jak) Date: Thu, 13 Apr 2023 00:21:58 +0200 Subject: for a 'good python' In-Reply-To: References: Message-ID: Barry ha scritto: > ? > > >> On 12 Apr 2023, at 18:10, jak wrote: >> ?Hi everyone, >> some time ago I wrote a class to determine if an ipv4 address belonged >> to a subnet. Seldom using python I'm pretty sure it's not written in >> 'good python' nor too portable. Could you give me some advice to make it >> better? >> >> class calcip: >> def __init__(self, psubnet: str): >> ssubnet, scidr = psubnet.replace(' ', '').split('/') >> subnet = int.from_bytes(tuple( >> map(lambda n: (int(n)), ssubnet.split('.'))), >> 'big') >> cidr = int(scidr) >> mask = ((2 ** cidr) - 1) << (32 - cidr) >> self.__network = subnet & mask >> self.__wildcard = ~mask & 0xffffffff >> self.__broadcast = (subnet | self.__wildcard) & 0xffffffff >> self.__tsubnet = tuple(subnet.to_bytes(4, 'big')) >> self.__tnetwork = tuple(self.__network.to_bytes(4, 'big')) >> self.__tbroadcast = tuple(self.__broadcast.to_bytes(4, 'big')) >> self.__tmask = tuple(mask.to_bytes(4, 'big')) >> self.__twildcard = tuple(self.__wildcard.to_bytes(4, 'big')) >> self.__host_min = tuple((self.__network + 1).to_bytes(4, 'big')) >> self.__host_max = tuple((self.__broadcast - 1).to_bytes(4, 'big')) >> >> @staticmethod >> def __to_str(val: tuple): >> return '.'.join(str(v) for v in val) >> >> @property >> def subnet(self): >> return self.__to_str(self.__tsubnet) >> >> @property >> def network(self): >> return self.__to_str(self.__tnetwork) >> >> @property >> def broadcast(self): >> return self.__to_str(self.__tbroadcast) >> >> @property >> def mask(self): >> return self.__to_str(self.__tmask) >> >> @property >> def wildcard(self): >> return self.__to_str(self.__twildcard) >> >> @property >> def host_min(self): >> return self.__to_str(self.__host_min) >> >> @property >> def host_max(self): >> return self.__to_str(self.__host_max) >> >> @property >> def hosts_num(self): >> return self.__wildcard - 1 >> >> @property >> def net_class(self): >> tst = (self.__tnetwork[0] & 0xf0) >> 4 >> if (tst & 0x8) == 0: >> clx = 'A' >> elif (tst & 0xc) == 0x8: >> clx = 'B' >> elif (tst & 0xe) == 0xc: >> clx = 'C' >> elif (tst & 0xf) == 0xe: >> clx = 'D' >> elif (tst & 0xf) == 0xf: >> clx = 'E' >> return clx >> >> def __contains__(self, item): >> ret = True >> row_hdr = None >> try: >> row_hdr = int.from_bytes(tuple(map(lambda n: (int(n)), item.split('.'))), 'big') >> except: >> ret = False >> if ret: >> if not self.__network < row_hdr < self.__broadcast: >> ret = False >> return ret >> >> >> def main(): >> sn = calcip('10.0.0.0/26') >> >> print(f"subnet: {sn.subnet}") >> print(f"network: {sn.network}") >> print(f"broadcast: {sn.broadcast}") >> print(f"mask: {sn.mask}") >> print(f"wildcard: {sn.wildcard}") >> print(f"host_min: {sn.host_min}") >> print(f"host_max: {sn.host_max}") >> print(f"Avaible hosts: {sn.hosts_num}") >> print(f"Class: {sn.net_class}") >> >> tst_hdr = '10.0.0.31' >> is_not = 'is ' >> if not tst_hdr in sn: >> is_not = 'is NOT ' >> print("hdr %s %sin range %s - %s" % >> (tst_hdr, is_not, sn.host_min, sn.host_max)) >> >> if __name__ == '__main__': >> main() > > There is this https://docs.python.org/3/howto/ipaddress.html if you just want a solution. > > Or are you after code review feedback? > > Barry > >> -- >> https://mail.python.org/mailman/listinfo/python-list Thank you too. I had seen this library but I always try not to use libraries outside the standard ones. Now I don't remember why I was convinced that this wasn't part of it, perhaps because it was like that at the time or because I got confused. Only now I realized that it is not necessary to install it. Now I'm considering whether to use 'ipaddress' or 'socket'. What is certain is that this one you have suggested is really comfortable. Thanks again for the report. From miked at dewhirst.com.au Wed Apr 12 21:27:10 2023 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Thu, 13 Apr 2023 11:27:10 +1000 Subject: Christoph Gohlke and compiled packages In-Reply-To: <0db1af84-212e-566a-2a8f-bed5226987f5@dewhirst.com.au> References: <82d2b185-c8b9-d1d4-06a7-0d3d1cf8d1da@tompassin.net> <0db1af84-212e-566a-2a8f-bed5226987f5@dewhirst.com.au> Message-ID: <72ff043f-0aa4-1855-fd5f-542b13912dfb@dewhirst.com.au> On 12/04/2023 10:59 pm, Mike Dewhirst wrote: > Sadly Windows is still in the dock. The jury is still out. > > Turns out the "without a hitch" was based on cached wheels. > > I'm going to start from scratch with new projects using Pythons 3.8, > 3.10 and 3.11 and report back. Report summary: pip install works well with Python 3.8 and 3.10 (and presumably 3.9) but 3.11 fails. Report conclusion: As indicated in this thread, pip cannot find Python 3.11 wheels and therefore needs to compile from source. It is looking for Microsoft's C++ compiler version 14. I'll (gulp) attempt to swallow the Koolaid. See error below ... Cheers Mike (xreq) D:\Users\mike\envs\xreq>pip install -r requirements\dev.txt ... Collecting psycopg2==2.9.3 ? Downloading psycopg2-2.9.3.tar.gz (380 kB) ???? --------------------------------------- 380.6/380.6 kB 6.0 MB/s eta 0:00:00 ? Preparing metadata (setup.py) ... done Collecting Pillow==9.1.1 ? Downloading Pillow-9.1.1.tar.gz (49.8 MB) ???? ---------------------------------------- 49.8/49.8 MB 4.5 MB/s eta 0:00:00 ? Preparing metadata (setup.py) ... done ... Installing collected packages: psycopg2, Pillow, ... ? DEPRECATION: psycopg2 is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found athttps://github.com/pypa/pip/issues/8559 ? Running setup.py install for psycopg2 ... error ? error: subprocess-exited-with-error ? ? Running setup.py install for psycopg2 did not run successfully. ? ? exit code: 1 ? ??> [24 lines of output] ????? D:\Users\mike\envs\xreq\Lib\site-packages\setuptools\config\setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead. ??????? warnings.warn(msg, warning_class) ????? running install ????? D:\Users\mike\envs\xreq\Lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. ??????? warnings.warn( ????? running build ????? running build_py ????? creating build ????? creating build\lib.win-amd64-cpython-311 ????? creating build\lib.win-amd64-cpython-311\psycopg2 ????? copying lib\errorcodes.py -> build\lib.win-amd64-cpython-311\psycopg2 ????? copying lib\errors.py -> build\lib.win-amd64-cpython-311\psycopg2 ????? copying lib\extensions.py -> build\lib.win-amd64-cpython-311\psycopg2 ????? copying lib\extras.py -> build\lib.win-amd64-cpython-311\psycopg2 ????? copying lib\pool.py -> build\lib.win-amd64-cpython-311\psycopg2 ????? copying lib\sql.py -> build\lib.win-amd64-cpython-311\psycopg2 ????? copying lib\tz.py -> build\lib.win-amd64-cpython-311\psycopg2 ????? copying lib\_ipaddress.py -> build\lib.win-amd64-cpython-311\psycopg2 ????? copying lib\_json.py -> build\lib.win-amd64-cpython-311\psycopg2 ????? copying lib\_range.py -> build\lib.win-amd64-cpython-311\psycopg2 ????? copying lib\__init__.py -> build\lib.win-amd64-cpython-311\psycopg2 ????? running build_ext ????? building 'psycopg2._psycopg' extension ????? error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools":https://visualstudio.microsoft.com/visual-cpp-build-tools/ ????? [end of output] ? note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure ? Encountered error while trying to install package. ??> psycopg2 note: This is an issue with the package mentioned above, not pip. hint: See above for output from the failure. (xreq) D:\Users\mike\envs\xreq> > > Cheers > > Mike > > On 12/04/2023 6:13 pm, Mike Dewhirst wrote: >> Well thank you Christoph Gohlke and thank you Ian Bicking and >> colleagues. >> >> I just used pip to nakedly install psycopg2 and Pillow without a >> hitch. My distrust of Windows has kept me going back to Christoff's >> well for years. >> >> Maybe it is time to assume innocence unless proven guilty ;-) >> >> Thanks to all who showed me the way. >> >> Cheers >> >> Mike >> >> On 11/04/2023 11:39 pm, Thomas Passin wrote: >>> On 4/11/2023 6:58 AM, Chris Angelico wrote: >>>> On Tue, 11 Apr 2023 at 20:15, Jim Schwartz >>>> wrote: >>>>> >>>>> What?s the problem now?? Is it with python on windows?? I use >>>>> python on windows so I?d like to know. Thanks >>>>> >>>> >>>> Python itself is fine, but a lot of third-party packages are hard to >>>> obtain. So if you need numpy, for instance, or psycopg2, you might >>>> need to find an alternative source. >>> >>> I've noticed a big change in the last few years in that PyPi has >>> many, many amd-64 packages than it used to in the heyday of >>> Christoph Gohlke's efforts. I haven't needed to go there for some >>> time whereas I used to need to all the time.? So if I "need numpy, >>> for instance, or psycopg2" for Windows, I get them from PyPi. >>> >>> Yes, I know that some projects haven't caught up to Python 3.11x >>> yet. And I'm glad I haven't needed to create a binary wheel for >>> Windows myself.? But the situation is way better than it used to >>> be.? I've had more trouble with Python and Python packages on Linux >>> than on Windows. >>> >> >> >> > > > -- 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. 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 python at mrabarnett.plus.com Wed Apr 12 21:46:47 2023 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Apr 2023 02:46:47 +0100 Subject: Christoph Gohlke and compiled packages In-Reply-To: <72ff043f-0aa4-1855-fd5f-542b13912dfb@dewhirst.com.au> References: <82d2b185-c8b9-d1d4-06a7-0d3d1cf8d1da@tompassin.net> <0db1af84-212e-566a-2a8f-bed5226987f5@dewhirst.com.au> <72ff043f-0aa4-1855-fd5f-542b13912dfb@dewhirst.com.au> Message-ID: <353beaa3-1803-b0c2-06ee-23f63e7ecb2e@mrabarnett.plus.com> On 2023-04-13 02:27, Mike Dewhirst wrote: > On 12/04/2023 10:59 pm, Mike Dewhirst wrote: >> Sadly Windows is still in the dock. The jury is still out. >> >> Turns out the "without a hitch" was based on cached wheels. >> >> I'm going to start from scratch with new projects using Pythons 3.8, >> 3.10 and 3.11 and report back. > > Report summary: > > pip install works well with Python 3.8 and 3.10 (and presumably 3.9) but > 3.11 fails. > > Report conclusion: > > As indicated in this thread, pip cannot find Python 3.11 wheels and > therefore needs to compile from source. It is looking for Microsoft's > C++ compiler version 14. > > I'll (gulp) attempt to swallow the Koolaid. > > See error below ... > > Cheers > > Mike > > (xreq) D:\Users\mike\envs\xreq>pip install -r requirements\dev.txt > > ... > > Collecting psycopg2==2.9.3 > > ? Downloading psycopg2-2.9.3.tar.gz (380 kB) > > ???? --------------------------------------- 380.6/380.6 kB 6.0 MB/s eta 0:00:00 > > ? Preparing metadata (setup.py) ... done > > Collecting Pillow==9.1.1 > > ? Downloading Pillow-9.1.1.tar.gz (49.8 MB) > > ???? ---------------------------------------- 49.8/49.8 MB 4.5 MB/s eta 0:00:00 > > ? Preparing metadata (setup.py) ... done > > ... > > Installing collected packages: psycopg2, Pillow, ... > > ? DEPRECATION: psycopg2 is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found athttps://github.com/pypa/pip/issues/8559 > > ? Running setup.py install for psycopg2 ... error > > ? error: subprocess-exited-with-error > > ? ? Running setup.py install for psycopg2 did not run successfully. > > ? ? exit code: 1 > > ? ??> [24 lines of output] > > ????? D:\Users\mike\envs\xreq\Lib\site-packages\setuptools\config\setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead. > > ??????? warnings.warn(msg, warning_class) > > ????? running install > > ????? D:\Users\mike\envs\xreq\Lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. > > ??????? warnings.warn( > > ????? running build > > ????? running build_py > > ????? creating build > > ????? creating build\lib.win-amd64-cpython-311 > > ????? creating build\lib.win-amd64-cpython-311\psycopg2 > > ????? copying lib\errorcodes.py -> build\lib.win-amd64-cpython-311\psycopg2 > > ????? copying lib\errors.py -> build\lib.win-amd64-cpython-311\psycopg2 > > ????? copying lib\extensions.py -> build\lib.win-amd64-cpython-311\psycopg2 > > ????? copying lib\extras.py -> build\lib.win-amd64-cpython-311\psycopg2 > > ????? copying lib\pool.py -> build\lib.win-amd64-cpython-311\psycopg2 > > ????? copying lib\sql.py -> build\lib.win-amd64-cpython-311\psycopg2 > > ????? copying lib\tz.py -> build\lib.win-amd64-cpython-311\psycopg2 > > ????? copying lib\_ipaddress.py -> build\lib.win-amd64-cpython-311\psycopg2 > > ????? copying lib\_json.py -> build\lib.win-amd64-cpython-311\psycopg2 > > ????? copying lib\_range.py -> build\lib.win-amd64-cpython-311\psycopg2 > > ????? copying lib\__init__.py -> build\lib.win-amd64-cpython-311\psycopg2 > > ????? running build_ext > > ????? building 'psycopg2._psycopg' extension > > ????? error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools":https://visualstudio.microsoft.com/visual-cpp-build-tools/ > > ????? [end of output] > > ? note: This error originates from a subprocess, and is likely not a problem with pip. > > error: legacy-install-failure > > ? Encountered error while trying to install package. > > ??> psycopg2 > > note: This is an issue with the package mentioned above, not pip. > > hint: See above for output from the failure. > > (xreq) D:\Users\mike\envs\xreq> > [snip] C:\Users\mrab>py -3.11 -m pip install psycopg2 Collecting psycopg2 Downloading psycopg2-2.9.6-cp311-cp311-win_amd64.whl (1.2 MB) ---------------------------------------- 1.2/1.2 MB 2.4 MB/s eta 0:00:00 Installing collected packages: psycopg2 Successfully installed psycopg2-2.9.6 C:\Users\mrab>py -3.11 -m pip install Pillow Requirement already satisfied: Pillow in c:\python311\lib\site-packages (9.2.0) From eryksun at gmail.com Wed Apr 12 22:00:02 2023 From: eryksun at gmail.com (Eryk Sun) Date: Wed, 12 Apr 2023 21:00:02 -0500 Subject: Christoph Gohlke and compiled packages In-Reply-To: <72ff043f-0aa4-1855-fd5f-542b13912dfb@dewhirst.com.au> References: <82d2b185-c8b9-d1d4-06a7-0d3d1cf8d1da@tompassin.net> <0db1af84-212e-566a-2a8f-bed5226987f5@dewhirst.com.au> <72ff043f-0aa4-1855-fd5f-542b13912dfb@dewhirst.com.au> Message-ID: On 4/12/23, Mike Dewhirst wrote: > > Collecting psycopg2==2.9.3 x86 and x64 wheels are available for Python 3.11 if you can use Psycopg 2 version 2.9.5 or 2.9.6 instead of 2.9.3: https://pypi.org/project/psycopg2/2.9.5/#files https://pypi.org/project/psycopg2/2.9.6/#files From avi.e.gross at gmail.com Wed Apr 12 22:12:27 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 12 Apr 2023 22:12:27 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: Message-ID: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> As originally written, the question posed has way too many possible answers but the subject line may give a hint. Forget printing. The Python statement 1 + "a" SHOULD fail. The first is an integer and the second is string. These two are native Python objects that neither define what to do if they are paired with an object of the other type on the left or the right. In any case, what should the answer be? Since "a" has no integer value, it presumably was intended to be the string "1a". So why NOT use the built-in conversion and instead of: print(x+y) # where x=1, y='a' It should be: print(str(x) + y) Could this behavior be added to Python? Sure. I wonder how many would not like it as it often will be an error not caught! If you defined your own object derived from string and added a __radd__() method then the method could be made to accept whatever types you wanted (such as integer or double or probably anything) and simply have code that converts it to the str() representation and then concatenates them with, or if you prefer without, any padding between. I suspect the OP is thinking of languages like PERL or JAVA which guess for you and make such conversions when it seems to make sense. Python does not generally choose that as it is quite easy to use one of so many methods, and lately an f-string is an easy way as others mentioned. -----Original Message----- From: Python-list On Behalf Of Thomas Passin Sent: Wednesday, April 12, 2023 2:52 PM To: python-list at python.org Subject: Re: Weak Type Ability for Python On 4/12/2023 1:11 PM, Chris Angelico wrote: > On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari > wrote: >> >> Hi all, >> Please make this command for Python (if possible): >> >>>>> x=1 >>>>> y='a' >>>>> wprint (x+y) >>>>> 1a >> >> In fact make a new type of print command which can print and show strings >> and integers together. >> > > Try: > > print(x, y) > > ChrisA It puts a space between "1" and "a", whereas the question does not want the space. print(f'{x}{y}') would do it, but only works for variables named "x" and "y". As happens so often, the OP has not specified what he actually wants to do so we can only answer the very specific question. -- https://mail.python.org/mailman/listinfo/python-list From miked at dewhirst.com.au Wed Apr 12 22:18:06 2023 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Thu, 13 Apr 2023 12:18:06 +1000 Subject: Christoph Gohlke and compiled packages In-Reply-To: References: <82d2b185-c8b9-d1d4-06a7-0d3d1cf8d1da@tompassin.net> <0db1af84-212e-566a-2a8f-bed5226987f5@dewhirst.com.au> <72ff043f-0aa4-1855-fd5f-542b13912dfb@dewhirst.com.au> Message-ID: <64c39139-33ad-7a9c-b570-44cc23e58b01@dewhirst.com.au> On 13/04/2023 12:00 pm, Eryk Sun wrote: > On 4/12/23, Mike Dewhirst wrote: >> Collecting psycopg2==2.9.3 > x86 and x64 wheels are available for Python 3.11 if you can use > Psycopg 2 version 2.9.5 or 2.9.6 instead of 2.9.3: > > https://pypi.org/project/psycopg2/2.9.5/#files > https://pypi.org/project/psycopg2/2.9.6/#files Many thanks to both of you ... I'll uninstall Microsoft Build Tools as soon as its finished installing (37.3GB and I had to clear space for it) 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. 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 cs at cskk.id.au Wed Apr 12 22:21:58 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 13 Apr 2023 12:21:58 +1000 Subject: Weak Type Ability for Python In-Reply-To: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> Message-ID: On 12Apr2023 22:12, avi.e.gross at gmail.com wrote: >I suspect the OP is thinking of languages like PERL or JAVA which guess >for >you and make such conversions when it seems to make sense. JavaScript guesses. What a nightmare. Java acts like Python and will forbid it on type grounds (at compile time with Java, being staticly typed). Cheers, Cameron Simpson From python at mrabarnett.plus.com Wed Apr 12 22:28:37 2023 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Apr 2023 03:28:37 +0100 Subject: Weak Type Ability for Python In-Reply-To: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> Message-ID: On 2023-04-13 03:12, avi.e.gross at gmail.com wrote: > As originally written, the question posed has way too many possible answers > but the subject line may give a hint. Forget printing. > > The Python statement > 1 + "a" > > SHOULD fail. The first is an integer and the second is string. These two > are native Python objects that neither define what to do if they are paired > with an object of the other type on the left or the right. > > In any case, what should the answer be? Since "a" has no integer value, it > presumably was intended to be the string "1a". > > So why NOT use the built-in conversion and instead of: > > print(x+y) # where x=1, y='a' > > It should be: > > print(str(x) + y) > > Could this behavior be added to Python? Sure. I wonder how many would not > like it as it often will be an error not caught! > > If you defined your own object derived from string and added a __radd__() > method then the method could be made to accept whatever types you wanted > (such as integer or double or probably anything) and simply have code that > converts it to the str() representation and then concatenates them with, or > if you prefer without, any padding between. > > I suspect the OP is thinking of languages like PERL or JAVA which guess for > you and make such conversions when it seems to make sense. > In the case of Perl, there are distinct operators for addition and string concatenation, with automatic type conversion (non-numeric strings have a numeric value of 0, which can hide bugs). > Python does not generally choose that as it is quite easy to use one of so > many methods, and lately an f-string is an easy way as others mentioned. > > > -----Original Message----- > From: Python-list On > Behalf Of Thomas Passin > Sent: Wednesday, April 12, 2023 2:52 PM > To: python-list at python.org > Subject: Re: Weak Type Ability for Python > > On 4/12/2023 1:11 PM, Chris Angelico wrote: >> On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari >> wrote: >>> >>> Hi all, >>> Please make this command for Python (if possible): >>> >>>>>> x=1 >>>>>> y='a' >>>>>> wprint (x+y) >>>>>> 1a >>> >>> In fact make a new type of print command which can print and show strings >>> and integers together. >>> >> >> Try: >> >> print(x, y) >> >> ChrisA > > It puts a space between "1" and "a", whereas the question does not want > the space. print(f'{x}{y}') would do it, but only works for variables > named "x" and "y". > > As happens so often, the OP has not specified what he actually wants to > do so we can only answer the very specific question. > From python at mrabarnett.plus.com Wed Apr 12 22:36:22 2023 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Apr 2023 03:36:22 +0100 Subject: Weak Type Ability for Python In-Reply-To: References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> Message-ID: On 2023-04-13 03:21, Cameron Simpson wrote: > On 12Apr2023 22:12, avi.e.gross at gmail.com wrote: >>I suspect the OP is thinking of languages like PERL or JAVA which guess >>for >>you and make such conversions when it seems to make sense. > > JavaScript guesses. What a nightmare. Java acts like Python and will > forbid it on type grounds (at compile time with Java, being staticly > typed). > I thought that in Java you can, in fact, concatenate a string and an int, so I did a quick search online and it appears that you can. From avi.e.gross at gmail.com Wed Apr 12 22:37:36 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 12 Apr 2023 22:37:36 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: Message-ID: <00ae01d96db0$e8a61350$b9f239f0$@gmail.com> On closer reading, the OP may be asking how to make a function doing what they want, albeit without a plus. Here is a python function as a one-liner that takes exactly two arguments of any kind (including string and integer) and concatenates them into one string without anything between and prints them: def strprint(first, second): print(str(first) + str(second)) >>> strprint(5,1) 51 >>> strprint("a5",1) a51 >>> strprint(12,"o'clock") 12o'clock >>> strprint(3.1415926535,complex(3,4)) 3.1415926535(3+4j) Want something similar for any number of arguments? Here is a slightly longer one-liner: def strprintall(*many): print(''.join([str(each) for each in many])) >>> strprintall(1,"=egy\n",2,"=kett?\n",3,"=h?rom\n",4,"=n?gy\n",5,"=?t\n","in my childhood language.\n") 1=egy 2=kett? 3=h?rom 4=n?gy 5=?t in my childhood language. Note my meager attempt is not using a plus sign as I addressed a sort of way that could be done using a __radd__ method or other ways like an f-string. I can not repeat this often enough. The easiest way to do something you want in a new language is to work within the existing language as-is and not to ask the language to change to be the way you want. That can take years or never happen, and especially if the designers did not want the feature you ask for. -----Original Message----- From: Python-list On Behalf Of 2QdxY4RzWzUUiLuE at potatochowder.com Sent: Wednesday, April 12, 2023 3:17 PM To: python-list at python.org Subject: Re: Weak Type Ability for Python On 2023-04-12 at 14:51:44 -0400, Thomas Passin wrote: > On 4/12/2023 1:11 PM, Chris Angelico wrote: > > On Thu, 13 Apr 2023 at 03:05, Ali Mohseni Roodbari > > wrote: > > > > > > Hi all, > > > Please make this command for Python (if possible): > > > > > > > > > x=1 > > > > > > y='a' > > > > > > wprint (x+y) > > > > > > 1a > > > > > > In fact make a new type of print command which can print and show strings > > > and integers together. > > > > > > > Try: > > > > print(x, y) > > > > ChrisA > > It puts a space between "1" and "a", whereas the question does not want the > space. print(f'{x}{y}') would do it, but only works for variables named "x" > and "y". Or possibly print(x, y, sep=''). > As happens so often, the OP has not specified what he actually wants to do > so we can only answer the very specific question. Agreed. -- https://mail.python.org/mailman/listinfo/python-list From cs at cskk.id.au Wed Apr 12 23:42:38 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 13 Apr 2023 13:42:38 +1000 Subject: Weak Type Ability for Python In-Reply-To: References: Message-ID: On 13Apr2023 03:36, MRAB wrote: >I thought that in Java you can, in fact, concatenate a string and an >int, so I did a quick search online and it appears that you can. I stand corrected. I could have sworn it didn't, but it has been a long time. - Cameron Simpson From avi.e.gross at gmail.com Thu Apr 13 01:38:58 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 13 Apr 2023 01:38:58 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: Message-ID: <015501d96dca$3ef2c820$bcd85860$@gmail.com> Given the significant number of languages other than Python that have some version of a feature that allows implicit conversion of unlike operands to concatenate something like a "number" and a string into a string, the question may not be silly as to how or why Python chose as it chose. As I see it, python did put in quite a bit of customizability and flexibility including the ability to create your own object types that alter the behavior of an operator like plus. I have seen plenty of code that takes advantage and makes the user of the code assume that different types can interact seamlessly. But it is like many other things. Languages that support a wide variety of integer types such as signed and unsigned versions of integers in 8 bits, sixteen bits, 32 bits and even 64 bits or perhaps higher, will often look like they allow you to mix them in various combinations for not just addition. But underneath it all can be lots of hidden complexity. I have seen languages that make lots of functions with the same names but different signatures and then dispatch a call like add(int8, unsignedint32) to the right function that best matches their signature. The functions internally can do many things but often convert their arguments to a common format, perform the operations, then perhaps convert back to whatever result output was expected. In the case being discussed we might have to create something that looks like do_plus(int, int) and then do_plus(int, char) and so on. The other alternatives can include tables of "generality" and "convertibility" with rules that govern how to perform a calculation by changing or upgrading or downgrading things to make a match that can then be handled. The issue here is a sort of operator overloading. In Python, "+" does not mean plus at all. It means whatever the programmer wanted it to mean. An infix line of code that includes "obj1 + obj2" is supposed to investigate how to do it. I am not sure if some built-in objects may be different, but it does a sequence of operations till it finds what it needs and does it. I believe it looks a bit like this. The LHS object, obj1, is examined to see if it has defined a __add__() method. If found, it is called and either produces a result or signals it cannot handle obj2 for some reason. If that method is not found, or fails, then it looks to see if the RHS, obj2, has a __radd__() method defined. That can be given obj1 and return an answer or signal failure. If obj1 is 5 and obj2 is "pm" then we are using the built-in predefined classes that currently have no interest in concatenating or adding unlike types like this. If you could add or change these dunder methods (and note you may also need to deal with __iadd__() to handle the case where x=5 and you write "x += "pm" albeit that could weirdly change the type of x without a linter having a clue. I suggest the latter argument may be a good enough reason that Python did not implement this. There are many good reasons. Does anyone like a language that lets you type 2 + "three" and quietly makes that be 5? Sure, it can be made to work on a subset of number in say English, but will it work in other languages. It can be hard enough now to write code in UNICODE (I have seen some) that tries to determine if a code point represents a number in some language or representation and treats it as a numeral. I have seen the numeric bullets such as a dark circle containing a white nine be treated as if the user had put in a nine, for example. As was mentioned, some languages have different operators for addition versus concatenation and in that context, it may be intuitive that using the wrong object type is an implicit call to conversion. Python uses "+" for both purposes depending on context and potentially for many more purposes the programmer can devise. Consider the asterisk operator as a companion concept. It gladly accepts a string and a number in either order and does something somewhat intuitive with them by treating multiplication as a sort of repeated addition: >>> 5 * "6" '66666' >>> "5" * 6 '555555' >>> 3 * "Hello? " 'Hello? Hello? Hello? But it will not handle float. >>> "Hello" * 2.5 TypeError: can't multiply sequence by non-int of type 'float' If you want to either truncate a float to an into or round it or take a ceiling, though, it will not guess for you and you must do something explicit like this: >>> "Hello" * round(2.5) 'HelloHello' >>> "Hello" * round(2.6) 'HelloHelloHello' >>> "Hello" * int(2.6) 'HelloHello' There is a parallel argument here in arguing it should accept a float and truncate it. But since you can easily cast a float to an int, in any of many ways, why have the program choose when it quite likely reflects an error in the code. And, no, I do not suggest 2.5 be interpreted as putting in an approximate percentage so that .8 * "Hello" should result in "Hell" ... -----Original Message----- From: Python-list On Behalf Of Cameron Simpson Sent: Wednesday, April 12, 2023 11:43 PM To: python-list at python.org Subject: Re: Weak Type Ability for Python On 13Apr2023 03:36, MRAB wrote: >I thought that in Java you can, in fact, concatenate a string and an >int, so I did a quick search online and it appears that you can. I stand corrected. I could have sworn it didn't, but it has been a long time. - Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Thu Apr 13 03:01:41 2023 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 13 Apr 2023 17:01:41 +1000 Subject: Weak Type Ability for Python In-Reply-To: <015501d96dca$3ef2c820$bcd85860$@gmail.com> References: <015501d96dca$3ef2c820$bcd85860$@gmail.com> Message-ID: On Thu, 13 Apr 2023 at 15:40, wrote: > And, no, I do not suggest 2.5 be interpreted as putting in an > approximate percentage so that .8 * "Hello" should result in "Hell" ... $ pike Pike v8.1 release 15 running Hilfe v3.5 (Incremental Pike Frontend) Ok. > "Hello, world! " * 2.5; (1) Result: "Hello, world! Hello, world! Hello, " > "Hello, world! Hello, world! Hello, " / 10; (2) Result: ({ /* 3 elements */ "Hello, wor", "ld! Hello,", " world! He" }) > "Hello, world! Hello, world! Hello, " % 10; (3) Result: "llo, " > "Hello, world! Hello, world! Hello, " / 10.0; (4) Result: ({ /* 4 elements */ "Hello, wor", "ld! Hello,", " world! He", "llo, " }) > Multiplying and dividing strings by floats makes perfect sense. (The ({ }) notation is Pike's array literal syntax; consider it equivalent to Python's square brackets for a list.) ChrisA From guenther.sohler at gmail.com Thu Apr 13 03:40:39 2023 From: guenther.sohler at gmail.com (Guenther Sohler) Date: Thu, 13 Apr 2023 09:40:39 +0200 Subject: Embedded python is not 100% stable Message-ID: Hi Python LIst, I have been working on adding embedded python into OpenSCAD ( www.openscad.org) for some time already. For that i coded/added an additional Python Type Object which means to hold openscad geometric data. It works quite well but unfortunately its not 100% stable and i have been heavily checking all the functions which are referenced in the PyType Object and tried to match them with the documentation which i found in the python web site but now i am stuck and i cant progress any further I am specially interested why the program constantly crashes when i activate the lines 14 and 15 in pyopenscad.cc. I have attached the two most relevant files and I would be happy if anybody interested could tell me, if there is an obvious bug popping into your eyes. If anybody is interested to see the complete picture, all source code is available checked in in github @ https://github.com/gsohler/openscad.git branch "libfive" Thank you for reading. Any spotted bug found will make me happy From lal at solute.de Thu Apr 13 03:42:24 2023 From: lal at solute.de (Lars Liedtke) Date: Thu, 13 Apr 2023 09:42:24 +0200 Subject: for a 'good python' In-Reply-To: References: Message-ID: Lars Liedtke Software Entwickler [Tel.] +49 721 98993- [Fax] +49 721 98993- [E-Mail] lal at solute.de solute GmbH Zeppelinstra?e 15 76185 Karlsruhe Germany [Logo Solute] Marken der solute GmbH | brands of solute GmbH [Marken] [Advertising Partner] Gesch?ftsf?hrer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten Webseite | www.solute.de Sitz | Registered Office: Karlsruhe Registergericht | Register Court: Amtsgericht Mannheim Registernummer | Register No.: HRB 110579 USt-ID | VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 13.04.23 um 00:21 schrieb jak: Barry ha scritto: ? On 12 Apr 2023, at 18:10, jak wrote: ?Hi everyone, some time ago I wrote a class to determine if an ipv4 address belonged to a subnet. Seldom using python I'm pretty sure it's not written in 'good python' nor too portable. Could you give me some advice to make it better? class calcip: def __init__(self, psubnet: str): ssubnet, scidr = psubnet.replace(' ', '').split('/') subnet = int.from_bytes(tuple( map(lambda n: (int(n)), ssubnet.split('.'))), 'big') cidr = int(scidr) mask = ((2 ** cidr) - 1) << (32 - cidr) self.__network = subnet & mask self.__wildcard = ~mask & 0xffffffff self.__broadcast = (subnet | self.__wildcard) & 0xffffffff self.__tsubnet = tuple(subnet.to_bytes(4, 'big')) self.__tnetwork = tuple(self.__network.to_bytes(4, 'big')) self.__tbroadcast = tuple(self.__broadcast.to_bytes(4, 'big')) self.__tmask = tuple(mask.to_bytes(4, 'big')) self.__twildcard = tuple(self.__wildcard.to_bytes(4, 'big')) self.__host_min = tuple((self.__network + 1).to_bytes(4, 'big')) self.__host_max = tuple((self.__broadcast - 1).to_bytes(4, 'big')) @staticmethod def __to_str(val: tuple): return '.'.join(str(v) for v in val) @property def subnet(self): return self.__to_str(self.__tsubnet) @property def network(self): return self.__to_str(self.__tnetwork) @property def broadcast(self): return self.__to_str(self.__tbroadcast) @property def mask(self): return self.__to_str(self.__tmask) @property def wildcard(self): return self.__to_str(self.__twildcard) @property def host_min(self): return self.__to_str(self.__host_min) @property def host_max(self): return self.__to_str(self.__host_max) @property def hosts_num(self): return self.__wildcard - 1 @property def net_class(self): tst = (self.__tnetwork[0] & 0xf0) >> 4 if (tst & 0x8) == 0: clx = 'A' elif (tst & 0xc) == 0x8: clx = 'B' elif (tst & 0xe) == 0xc: clx = 'C' elif (tst & 0xf) == 0xe: clx = 'D' elif (tst & 0xf) == 0xf: clx = 'E' return clx def __contains__(self, item): ret = True row_hdr = None try: row_hdr = int.from_bytes(tuple(map(lambda n: (int(n)), item.split('.'))), 'big') except: ret = False if ret: if not self.__network < row_hdr < self.__broadcast: ret = False return ret def main(): sn = calcip('10.0.0.0/26') print(f"subnet: {sn.subnet}") print(f"network: {sn.network}") print(f"broadcast: {sn.broadcast}") print(f"mask: {sn.mask}") print(f"wildcard: {sn.wildcard}") print(f"host_min: {sn.host_min}") print(f"host_max: {sn.host_max}") print(f"Avaible hosts: {sn.hosts_num}") print(f"Class: {sn.net_class}") tst_hdr = '10.0.0.31' is_not = 'is ' if not tst_hdr in sn: is_not = 'is NOT ' print("hdr %s %sin range %s - %s" % (tst_hdr, is_not, sn.host_min, sn.host_max)) if __name__ == '__main__': main() There is this https://docs.python.org/3/howto/ipaddress.html if you just want a solution. Or are you after code review feedback? Barry -- https://mail.python.org/mailman/listinfo/python-list Thank you too. I had seen this library but I always try not to use libraries outside the standard ones. Now I don't remember why I was convinced that this wasn't part of it, perhaps because it was like that at the time or because I got confused. Only now I realized that it is not necessary to install it. Now I'm considering whether to use 'ipaddress' or 'socket'. What is certain is that this one you have suggested is really comfortable. Thanks again for the report. Unless I am not mistakes, ipadress is "standard" because it is in the standard library From jpic at yourlabs.org Thu Apr 13 07:35:16 2023 From: jpic at yourlabs.org (J. Pic) Date: Thu, 13 Apr 2023 13:35:16 +0200 Subject: Weak Type Ability for Python In-Reply-To: References: Message-ID: print(f'{x}{y}') ? On Wed, Apr 12, 2023 at 7:06?PM Ali Mohseni Roodbari < ali.mohseniroodbari at gmail.com> wrote: > Hi all, > Please make this command for Python (if possible): > > >>> x=1 > >>> y='a' > >>> wprint (x+y) > >>> 1a > > In fact make a new type of print command which can print and show strings > and integers together. > > Sincerely yours, > Ali. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Personnel et confidentiel From list1 at tompassin.net Thu Apr 13 08:10:30 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 13 Apr 2023 08:10:30 -0400 Subject: Weak Type Ability for Python In-Reply-To: <015501d96dca$3ef2c820$bcd85860$@gmail.com> References: <015501d96dca$3ef2c820$bcd85860$@gmail.com> Message-ID: On 4/13/2023 1:38 AM, avi.e.gross at gmail.com wrote: > In Python, "+" does not > mean plus at all. It means whatever the programmer wanted it to mean. An > infix line of code that includes "obj1 + obj2" is supposed to investigate > how to do it. I am not sure if some built-in objects may be different, but > it does a sequence of operations till it finds what it needs and does it. A really nice example of this is pathlib in the standard library. You can write things like this, overloading the "/" operator: >>> from pathlib import PurePath >>> pth = PurePath('c:/') / 'temp' / 'python' >>> pth PureWindowsPath('c:/temp/python') >>> str(pth) 'c:\\temp\\python' From dieter at handshake.de Thu Apr 13 10:21:36 2023 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 13 Apr 2023 16:21:36 +0200 Subject: Embedded python is not 100% stable In-Reply-To: References: Message-ID: <25656.4080.567997.179911@ixdm.fritz.box> Guenther Sohler wrote at 2023-4-13 09:40 +0200: > ... >I have been working on adding embedded python into OpenSCAD ( >www.openscad.org) >for some time already. For that i coded/added an additional Python Type >Object >which means to hold openscad geometric data. > >It works quite well but unfortunately its not 100% stable and i have been >heavily checking >all the functions which are referenced in the PyType Object and tried to >match >them with the documentation which i found in the python web site The Python C/C++ interface is complex: it is easy to make mistakes which may lead to crashes. Often, `cython` (--> PyPI) can help you to define extension types in a much safer way. Maybe, you check its documentation? From barry at barrys-emacs.org Thu Apr 13 11:00:59 2023 From: barry at barrys-emacs.org (Barry) Date: Thu, 13 Apr 2023 16:00:59 +0100 Subject: for a 'good python' Message-ID: ? > On 13 Apr 2023, at 00:19, jak wrote: > > ?Barry ha scritto: >> ? >>>> On 12 Apr 2023, at 18:10, jak wrote: >>> ?Hi everyone, >>> some time ago I wrote a class to determine if an ipv4 address belonged >>> to a subnet. Seldom using python I'm pretty sure it's not written in >>> 'good python' nor too portable. Could you give me some advice to make it >>> better? >>> class calcip: >>> def __init__(self, psubnet: str): >>> ssubnet, scidr = psubnet.replace(' ', '').split('/') >>> subnet = int.from_bytes(tuple( >>> map(lambda n: (int(n)), ssubnet.split('.'))), >>> 'big') >>> cidr = int(scidr) >>> mask = ((2 ** cidr) - 1) << (32 - cidr) >>> self.__network = subnet & mask >>> self.__wildcard = ~mask & 0xffffffff >>> self.__broadcast = (subnet | self.__wildcard) & 0xffffffff >>> self.__tsubnet = tuple(subnet.to_bytes(4, 'big')) >>> self.__tnetwork = tuple(self.__network.to_bytes(4, 'big')) >>> self.__tbroadcast = tuple(self.__broadcast.to_bytes(4, 'big')) >>> self.__tmask = tuple(mask.to_bytes(4, 'big')) >>> self.__twildcard = tuple(self.__wildcard.to_bytes(4, 'big')) >>> self.__host_min = tuple((self.__network + 1).to_bytes(4, 'big')) >>> self.__host_max = tuple((self.__broadcast - 1).to_bytes(4, 'big')) >>> @staticmethod >>> def __to_str(val: tuple): >>> return '.'.join(str(v) for v in val) >>> @property >>> def subnet(self): >>> return self.__to_str(self.__tsubnet) >>> @property >>> def network(self): >>> return self.__to_str(self.__tnetwork) >>> @property >>> def broadcast(self): >>> return self.__to_str(self.__tbroadcast) >>> @property >>> def mask(self): >>> return self.__to_str(self.__tmask) >>> @property >>> def wildcard(self): >>> return self.__to_str(self.__twildcard) >>> @property >>> def host_min(self): >>> return self.__to_str(self.__host_min) >>> @property >>> def host_max(self): >>> return self.__to_str(self.__host_max) >>> @property >>> def hosts_num(self): >>> return self.__wildcard - 1 >>> @property >>> def net_class(self): >>> tst = (self.__tnetwork[0] & 0xf0) >> 4 >>> if (tst & 0x8) == 0: >>> clx = 'A' >>> elif (tst & 0xc) == 0x8: >>> clx = 'B' >>> elif (tst & 0xe) == 0xc: >>> clx = 'C' >>> elif (tst & 0xf) == 0xe: >>> clx = 'D' >>> elif (tst & 0xf) == 0xf: >>> clx = 'E' >>> return clx >>> def __contains__(self, item): >>> ret = True >>> row_hdr = None >>> try: >>> row_hdr = int.from_bytes(tuple(map(lambda n: (int(n)), item.split('.'))), 'big') >>> except: >>> ret = False >>> if ret: >>> if not self.__network < row_hdr < self.__broadcast: >>> ret = False >>> return ret >>> def main(): >>> sn = calcip('10.0.0.0/26') >>> print(f"subnet: {sn.subnet}") >>> print(f"network: {sn.network}") >>> print(f"broadcast: {sn.broadcast}") >>> print(f"mask: {sn.mask}") >>> print(f"wildcard: {sn.wildcard}") >>> print(f"host_min: {sn.host_min}") >>> print(f"host_max: {sn.host_max}") >>> print(f"Avaible hosts: {sn.hosts_num}") >>> print(f"Class: {sn.net_class}") >>> tst_hdr = '10.0.0.31' >>> is_not = 'is ' >>> if not tst_hdr in sn: >>> is_not = 'is NOT ' >>> print("hdr %s %sin range %s - %s" % >>> (tst_hdr, is_not, sn.host_min, sn.host_max)) >>> if __name__ == '__main__': >>> main() >> There is this https://docs.python.org/3/howto/ipaddress.html if you just want a solution. >> Or are you after code review feedback? >> Barry >>> -- >>> https://mail.python.org/mailman/listinfo/python-list > > > Thank you too. I had seen this library but I always try not to use > libraries outside the standard ones. Now I don't remember why I was > convinced that this wasn't part of it, perhaps because it was like that > at the time or because I got confused. Only now I realized that it is > not necessary to install it. Now I'm considering whether to use > 'ipaddress' or 'socket'. What is certain is that this one you have > suggested is really comfortable. Thanks again for the report. Ipaddress was developed outside of the std lib and later added i recall. Barry > > -- > https://mail.python.org/mailman/listinfo/python-list From grant.b.edwards at gmail.com Thu Apr 13 11:25:51 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 13 Apr 2023 08:25:51 -0700 (PDT) Subject: Weak Type Ability for Python References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> Message-ID: <64381eff.920a0220.9f55.07ce@mx.google.com> On 2023-04-13, Cameron Simpson wrote: > On 12Apr2023 22:12, avi.e.gross at gmail.com wrote: > >>I suspect the OP is thinking of languages like PERL or JAVA which guess >>for you and make such conversions when it seems to make sense. > > JavaScript guesses. What a nightmare. So does PHP. What's really impressive is that it never seems to guess correctly. :) From avi.e.gross at gmail.com Thu Apr 13 12:05:53 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 13 Apr 2023 12:05:53 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: <015501d96dca$3ef2c820$bcd85860$@gmail.com> Message-ID: <002201d96e21$d3995dc0$7acc1940$@gmail.com> Chris, I was not suggesting it for Python as one of many possible implementations. I do see perfectly valid uses in other contexts. For example, if I have a program that displays my text as pixels in some font and size, I may indeed want the text clipped at 2 1/2 repetitions. But as always, when there are choices to be made, you have to very clearly document the choice or offer ways to do it another way. In a non-fixed-width font, 2.5 may mean knowing how many pixels and adjusting so that a narrow letter "i" may be shown in one font and not another, for example. If you want completeness, sure, you can define fractional parts of a string in this context by the percentage of CHARACTERS in it. But as we have often seen, in other encodings you need to differentiate between varying numbers of bytes versus the underlying symbols they represent. Your example from the Pike language not only supports the multiplication of a string but division and mod. Python currently does not allow those. So why not extend it to allow complex numbers? >>> "Hello" * complex(5,0) TypeError: can't multiply sequence by non-int of type 'complex' >>> "Hello" * complex(0,5) TypeError: can't multiply sequence by non-int of type 'complex' The first one above is actually perfectly valid in the sense that the real part is 5 and there is no imaginary component. With a bit of effort, I can use the complexity to work: >>> "Hello" * int(complex(5,0).real) 'HelloHelloHelloHelloHello' Let me reiterate. There are languages that do all kinds of interesting things and some of what Python has done is seen by others as interesting. They regularly borrow from each other or use parts and innovate further. I have no serious objection to making well-thought-out changes if they are determined to be not only useful, but of higher priority than a long shopping list of other requests. I am wary of overly bloating a language by placing too many things in the core. It strikes me as doable to create a module that encapsulates a feature like this in a limited way. What may be needed is just a carefully constructed class that starts off as similar to str and adds some methods. Any user wanting to use the new feature would either start using the new class directly or cast their str to it when they want it to be useable. But the good news is that I am nowhere in the python hierarchy and have no ability to make any changes. This is purely academic for me. And, if I want such features and see tons of existing ways to get what I want or can roll it for myself, ... -----Original Message----- From: Python-list On Behalf Of Chris Angelico Sent: Thursday, April 13, 2023 3:02 AM To: python-list at python.org Subject: Re: Weak Type Ability for Python On Thu, 13 Apr 2023 at 15:40, wrote: > And, no, I do not suggest 2.5 be interpreted as putting in an > approximate percentage so that .8 * "Hello" should result in "Hell" ... $ pike Pike v8.1 release 15 running Hilfe v3.5 (Incremental Pike Frontend) Ok. > "Hello, world! " * 2.5; (1) Result: "Hello, world! Hello, world! Hello, " > "Hello, world! Hello, world! Hello, " / 10; (2) Result: ({ /* 3 elements */ "Hello, wor", "ld! Hello,", " world! He" }) > "Hello, world! Hello, world! Hello, " % 10; (3) Result: "llo, " > "Hello, world! Hello, world! Hello, " / 10.0; (4) Result: ({ /* 4 elements */ "Hello, wor", "ld! Hello,", " world! He", "llo, " }) > Multiplying and dividing strings by floats makes perfect sense. (The ({ }) notation is Pike's array literal syntax; consider it equivalent to Python's square brackets for a list.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Thu Apr 13 12:11:45 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Apr 2023 02:11:45 +1000 Subject: Weak Type Ability for Python In-Reply-To: <002201d96e21$d3995dc0$7acc1940$@gmail.com> References: <015501d96dca$3ef2c820$bcd85860$@gmail.com> <002201d96e21$d3995dc0$7acc1940$@gmail.com> Message-ID: On Fri, 14 Apr 2023 at 02:05, wrote: > So why not extend it to allow complex numbers? > > >>> "Hello" * complex(5,0) > TypeError: can't multiply sequence by non-int of type 'complex' > >>> "Hello" * complex(0,5) > TypeError: can't multiply sequence by non-int of type 'complex' > Clearly a missed opportunity to rotate the text through a specified angle. ChrisA From avi.e.gross at gmail.com Thu Apr 13 12:55:13 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 13 Apr 2023 12:55:13 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: <015501d96dca$3ef2c820$bcd85860$@gmail.com> <002201d96e21$d3995dc0$7acc1940$@gmail.com> Message-ID: <002f01d96e28$b74d1650$25e742f0$@gmail.com> [THIS CLAIMER: a bit off a bit off a bit off topic, imagine that] Chris, You have a gift of taking things I think about but censor myself from including in my post and then blurting it out! LOL! The original question in this thread now seems a dim memory but we are now discussing not how to add a number to a string but how to multiply a string to make n combined copies and then what it means to have a fractional copy and finally a way to specify a rotation to the result. Argh!!!! But since you brought it up as a way of looking at what multiplying by an imaginary number might mean, as in rotating text, I am now going to throw in a May Tricks even if it is only April. So should I now extend a language so a rotation matrix is allowed to multiply text or even a nested list like: [ [ cos(theta), -sin(theta) ], [ sin(theta), cos(theta) ] While we are at it, why stop with imaginary numbers when you can imagine extensions thereof? Unfortunately, it has been proven there are and can only be two additional such constructs. Quaternions have three distinct imaginary axes called i,j,k and some see them as interesting to show multidimensional objects in all kinds of places such as computer vision or orbital mechanics. Octonions have seven such other imaginary axes and have uses in esoteric places like String Theory or Quantum Logic. And, yes, you can use these critters in python. You can add a quaternion type to numpy for example. Yep, octonions too. See modules like pyoctonion and pyquaternion and much more. The immoral moral of this story is that once you start opening some doors, you may find people clamoring to let in ever more things and features. You can easily bog down your code to the point where finding the commonly used parts becomes a chore as you trudge through lots of code that is rarely used but there for completeness. Oh, I want to make something clear before I get another message spelling out what I was thinking but chose to omit. I slightly misled you above. Yes, it has been proven no number higher than 8 (meaning one real dimension and seven distinct imaginary ones) can exist so octonions are the final part of that story. Well, not exactly. You lose commutativity when going from quaternions to octonions and you lose full associativity if you go higher. But you can make all kinds of mathematical constructs like sedenions with 16 dimensions. I cannot imagine ever trying to multiply a string by these critters but who knows? As I noted above, if you set some parts of each of the above to zero, they all can look like something with a real part like 3, and no (meaning zero point zero) imaginary parts. So you could argue you should support all kinds of things that MAY on examination turn out to be convertible to an integer or double. -----Original Message----- From: Python-list On Behalf Of Chris Angelico Sent: Thursday, April 13, 2023 12:12 PM To: python-list at python.org Subject: Re: Weak Type Ability for Python On Fri, 14 Apr 2023 at 02:05, wrote: > So why not extend it to allow complex numbers? > > >>> "Hello" * complex(5,0) > TypeError: can't multiply sequence by non-int of type 'complex' > >>> "Hello" * complex(0,5) > TypeError: can't multiply sequence by non-int of type 'complex' > Clearly a missed opportunity to rotate the text through a specified angle. ChrisA -- https://mail.python.org/mailman/listinfo/python-list From mkarkera98 at gmail.com Thu Apr 13 13:10:06 2023 From: mkarkera98 at gmail.com (Meghna Karkera) Date: Thu, 13 Apr 2023 22:40:06 +0530 Subject: Hide my query about covariance matrix syntax from google Message-ID: Respected Sir I kindly request you to hide my query about covariance matrix syntax from google which was emailed to you a few years back as it appears on google page. Hoping that you do the needful. Dr. Meghna Raviraj Karkera From wlfraed at ix.netcom.com Wed Apr 12 22:47:17 2023 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Wed, 12 Apr 2023 22:47:17 -0400 Subject: Weak Type Ability for Python References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> Message-ID: <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson declaimed the following: >On 12Apr2023 22:12, avi.e.gross at gmail.com wrote: >>I suspect the OP is thinking of languages like PERL or JAVA which guess >>for >>you and make such conversions when it seems to make sense. > >JavaScript guesses. What a nightmare. Java acts like Python and will >forbid it on type grounds (at compile time with Java, being staticly >typed). > REXX -- where everything is considered a string until it needs to be something else. REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022 rexxtry.rex lets you interactively try REXX statements. Each string is executed when you hit Enter. Enter 'call tell' for a description of the features. Go on - try a few... Enter 'exit' to end. x = 1; ........................................... rexxtry.rex on WindowsNT y = "a"; ........................................... rexxtry.rex on WindowsNT say x||y; 1a ........................................... rexxtry.rex on WindowsNT From wlfraed at ix.netcom.com Wed Apr 12 22:52:29 2023 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Wed, 12 Apr 2023 22:52:29 -0400 Subject: for a 'good python' References: Message-ID: On Thu, 13 Apr 2023 00:21:58 +0200, jak declaimed the following: >Thank you too. I had seen this library but I always try not to use >libraries outside the standard ones. Now I don't remember why I was >convinced that this wasn't part of it, perhaps because it was like that >at the time or because I got confused. Only now I realized that it is >not necessary to install it. Now I'm considering whether to use >'ipaddress' or 'socket'. What is certain is that this one you have >suggested is really comfortable. Thanks again for the report. It is useful to skim the contents of the standard library documentation every couple of releases. ipaddress came in with Python 3.3 https://docs.python.org/3.10/library/index.html (I dropped down to 3.10 just as that is the version I have installed; some 3rd party modules weren't ready when I tried to install on 3.11) From nospam at please.ty Thu Apr 13 02:42:39 2023 From: nospam at please.ty (jak) Date: Thu, 13 Apr 2023 08:42:39 +0200 Subject: for a 'good python' In-Reply-To: References: Message-ID: Dennis Lee Bieber ha scritto: > On Thu, 13 Apr 2023 00:21:58 +0200, jak declaimed the > following: > > >> Thank you too. I had seen this library but I always try not to use >> libraries outside the standard ones. Now I don't remember why I was >> convinced that this wasn't part of it, perhaps because it was like that >> at the time or because I got confused. Only now I realized that it is >> not necessary to install it. Now I'm considering whether to use >> 'ipaddress' or 'socket'. What is certain is that this one you have >> suggested is really comfortable. Thanks again for the report. > > It is useful to skim the contents of the standard library documentation > every couple of releases. ipaddress came in with Python 3.3 > > https://docs.python.org/3.10/library/index.html (I dropped down to 3.10 > just as that is the version I have installed; some 3rd party modules > weren't ready when I tried to install on 3.11) > Then it was my fault. The version was 3.8.6 From aapost at idontexist.club Thu Apr 13 12:27:44 2023 From: aapost at idontexist.club (aapost) Date: Thu, 13 Apr 2023 12:27:44 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: Message-ID: On 4/12/23 04:03, Ali Mohseni Roodbari wrote: > On 4/13/23 07:50, Stefan Ram wrote: > If tomorrow Python would allow "string+int" and "int+string" > in the sense of "string+str(int)" and "str(int)+string", > what harm would be there? > > But for now, I think a typical approach would be to just use "str", > i.e., "string+str(int)" and "str(int)+string". I agree with Py Zen rule 2 in this case: Explicit is better than implicit. I hate when things try to guess what I am doing... It is why I can't use lxml. From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Apr 13 13:47:17 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 13 Apr 2023 13:47:17 -0400 Subject: Weak Type Ability for Python In-Reply-To: <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> Message-ID: On 2023-04-12 at 22:47:17 -0400, Dennis Lee Bieber wrote: > REXX -- where everything is considered a string until it needs to be > something else. I see your REXX, and raise you an awk,? except that awk won't add a string to a number, or a number to string, but it will concatenate in both cases: $ echo 1 a | awk '{print $1 $2}{print $1 + $2}' 1a 1 $ echo 1 a | awk '{print $2 $1}{print $2 + $1}' a1 1 $ echo 1 2 | awk '{print $1 $2}{print $2 + $1}' 12 3 ? GNU Awk 5.2.1, API 3.2, PMA Avon 8-g1, (GNU MPFR 4.2.0, GNU MP 6.2.1) Dan From aapost at idontexist.club Thu Apr 13 13:54:25 2023 From: aapost at idontexist.club (aapost) Date: Thu, 13 Apr 2023 13:54:25 -0400 Subject: Embedded python is not 100% stable In-Reply-To: References: Message-ID: On 4/13/23 03:40, Guenther Sohler wrote: > Attachments are stripped, so they weren't included. Glancing at the branch and the 2 lines you mentioned. You have a comment with a link for python 2.3 documentation. Yet you have python 3.10 code included elsewhere (and openscad itself requires the modern spec C++17, so I assume your aim is at current versions) https://docs.python.org/3.10/extending/newtypes.html is the equivalent doc for that. I am not experienced in defining PyType objects in C, but notice syntactical discrepancies, missing "static" on dealloc, use of typecasted malloc rather than PyType_GenericAlloc() https://docs.python.org/3.10/c-api/typeobj.html#c.PyTypeObject.tp_alloc Without digging in deeper and learning more I can't say for certain whether or not those are issues, but intuitively I assume they would be and that the implementation needs to more closely mirror the syntactical flow implementations of modern working examples.. From avi.e.gross at gmail.com Thu Apr 13 14:36:47 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 13 Apr 2023 14:36:47 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: Message-ID: <006401d96e36$e8003f80$b800be80$@gmail.com> This reminds me a bit of complaints that the parser does not do what you want when you do not supply parentheses in an expression like: 5 * 4 + 3 In many and maybe most languages it is seen as (5*4)+3 UNLESS you tell it you want 5*(4+3). There are precedence and associativity rules. Of course the computer might guess you meant the latter or could refuse to do it and offer you a choice before calculating it. Or the language may insist on parentheses always so you would need to also say ((5*4)+3) with no default behavior. The golden rule remains. If there is more than one way something can be done, then either the programmer must make the choice explicit OR the documentation must very clearly warn which path was chosen and perhaps point to ways to do other choices. Some people take more complex (but not Complex) arithmetic than the above and break it up into quite a few simple parts like: temp1 = 4 + 3 result = 5 + temp1 Of course, the latter can be hard to read and understand for some people, and some (others?) find fully parenthesized versions hard. But having precedence rules and also allowing the other methods, should work fine for a good segment of people except perhaps the ones who like Reverse Polish Notation and insist on 5 4 3 + * instead. -----Original Message----- From: Python-list On Behalf Of aapost Sent: Thursday, April 13, 2023 12:28 PM To: python-list at python.org Subject: Re: Weak Type Ability for Python On 4/12/23 04:03, Ali Mohseni Roodbari wrote: > On 4/13/23 07:50, Stefan Ram wrote: > If tomorrow Python would allow "string+int" and "int+string" > in the sense of "string+str(int)" and "str(int)+string", > what harm would be there? > > But for now, I think a typical approach would be to just use "str", > i.e., "string+str(int)" and "str(int)+string". I agree with Py Zen rule 2 in this case: Explicit is better than implicit. I hate when things try to guess what I am doing... It is why I can't use lxml. -- https://mail.python.org/mailman/listinfo/python-list From martin.schoon at gmail.com Thu Apr 13 14:41:19 2023 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 13 Apr 2023 18:41:19 GMT Subject: Problem with Matplotlib example Message-ID: Anyone had success running this example? https://tinyurl.com/yhhyc9r When I try I get this error: "TypeError: __init__() got an unexpected keyword argument 'transform'" This is for the line " m = MarkerStyle(SUCESS_SYMBOLS[mood], transform=t)" Yes, I know, I could dive into the documentation myself but I hope some kind soul here will help out. As far as I know I have an up-to-date matplotlib installed. Pip has nothing more modern to offer me. TIA /Martin From list1 at tompassin.net Thu Apr 13 15:04:02 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 13 Apr 2023 15:04:02 -0400 Subject: Weak Type Ability for Python In-Reply-To: <006401d96e36$e8003f80$b800be80$@gmail.com> References: <006401d96e36$e8003f80$b800be80$@gmail.com> Message-ID: On 4/13/2023 2:36 PM, avi.e.gross at gmail.com wrote: > But having > precedence rules and also allowing the other methods, should work fine for a > good segment of people except perhaps the ones who like Reverse Polish > Notation and insist on 5 4 3 + * instead. For *reading*, I prefer the usual 5 * (4 + 3) form. But for using a calculator, I much prefer RPN. From rosuav at gmail.com Thu Apr 13 15:28:06 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Apr 2023 05:28:06 +1000 Subject: Hide my query about covariance matrix syntax from google In-Reply-To: References: Message-ID: On Fri, 14 Apr 2023 at 03:11, Meghna Karkera wrote: > > Respected Sir > > I kindly request you to hide my query about covariance matrix syntax from > google which was emailed to you a few years back as it appears on google > page. > > Hoping that you do the needful. These posts are public. While it's possible to ask for something to be removed from the official python-list archive, that won't remove it from Google Groups or any other third-party archive. Also, there's nothing we can do here to remove your post; you'll have to contact the list admins. And just in case it's of interest to you: https://en.wikipedia.org/wiki/Streisand_effect ChrisA From rosuav at gmail.com Thu Apr 13 15:30:55 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Apr 2023 05:30:55 +1000 Subject: Weak Type Ability for Python In-Reply-To: <002f01d96e28$b74d1650$25e742f0$@gmail.com> References: <015501d96dca$3ef2c820$bcd85860$@gmail.com> <002201d96e21$d3995dc0$7acc1940$@gmail.com> <002f01d96e28$b74d1650$25e742f0$@gmail.com> Message-ID: On Fri, 14 Apr 2023 at 02:55, wrote: > And, yes, you can use these critters in python. You can add a quaternion > type to numpy for example. Yep, octonions too. Hang on hang on hang on. I can multiply a string by an onion? The possibilities of script-controlled culinary arts just became that much more awesome... ChrisA From list1 at tompassin.net Thu Apr 13 15:32:38 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 13 Apr 2023 15:32:38 -0400 Subject: Problem with Matplotlib example In-Reply-To: References: Message-ID: <8dd48769-7584-9220-7cc2-8e97dcd7df61@tompassin.net> On 4/13/2023 2:41 PM, Martin Sch??n wrote: > Anyone had success running this example? > https://tinyurl.com/yhhyc9r > > When I try I get this error: > "TypeError: __init__() got an unexpected keyword argument 'transform'" > > This is for the line > " m = MarkerStyle(SUCESS_SYMBOLS[mood], transform=t)" > > Yes, I know, I could dive into the documentation myself but I hope > some kind soul here will help out. > > As far as I know I have an up-to-date matplotlib installed. Pip has > nothing more modern to offer me. It works for me, copy-pasted as is. Python 3.11.3 C:\Users\tom>py -m pip show matplotlib Name: matplotlib Version: 3.6.3 C:\Users\tom>py -m pip show numpy Name: numpy Version: 1.24.2 From rosuav at gmail.com Thu Apr 13 15:35:22 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Apr 2023 05:35:22 +1000 Subject: Weak Type Ability for Python In-Reply-To: <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> Message-ID: On Fri, 14 Apr 2023 at 03:29, Dennis Lee Bieber wrote: > > On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson > declaimed the following: > > >On 12Apr2023 22:12, avi.e.gross at gmail.com wrote: > >>I suspect the OP is thinking of languages like PERL or JAVA which guess > >>for > >>you and make such conversions when it seems to make sense. > > > >JavaScript guesses. What a nightmare. Java acts like Python and will > >forbid it on type grounds (at compile time with Java, being staticly > >typed). > > > > REXX -- where everything is considered a string until it needs to be > something else. > > REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022 > rexxtry.rex lets you interactively try REXX statements. > Each string is executed when you hit Enter. > Enter 'call tell' for a description of the features. > Go on - try a few... Enter 'exit' to end. > x = 1; > ........................................... rexxtry.rex on WindowsNT > y = "a"; > ........................................... rexxtry.rex on WindowsNT > say x||y; > 1a > ........................................... rexxtry.rex on WindowsNT REXX - where everything is a string, arithmetic can be done on strings, and data structures are done in the variable name instead of the value. I've seen quite a few strings-only languages, but I can't think of any other language than REXX where you create arrays and dictionaries by using computed variable names. It was quite the experience back in the day (as OS/2's native scripting language), and one that I'm truly glad to have had, as it taught me so much about the differences between languages. (It also taught me to treasure good documentation and value it as truly precious, because SysSetObjectData was an incredibly powerful function whose docs just referred to WinSetObjectData, and the window manager's docs weren't part of what I had available.) ChrisA From python at mrabarnett.plus.com Thu Apr 13 15:34:23 2023 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 13 Apr 2023 20:34:23 +0100 Subject: Problem with Matplotlib example In-Reply-To: References: Message-ID: <4cef1b3b-30fd-378e-5fe7-7944bf5aec61@mrabarnett.plus.com> On 2023-04-13 19:41, Martin Sch??n wrote: > Anyone had success running this example? > https://tinyurl.com/yhhyc9r > > When I try I get this error: > "TypeError: __init__() got an unexpected keyword argument 'transform'" > > This is for the line > " m = MarkerStyle(SUCESS_SYMBOLS[mood], transform=t)" > > Yes, I know, I could dive into the documentation myself but I hope > some kind soul here will help out. > > As far as I know I have an up-to-date matplotlib installed. Pip has > nothing more modern to offer me. > All I can say is that it works for me! Python 3.10 and 3.11, matplotlib 3.6.1 and then 3.7.1 after updating it. From gheskett at shentel.net Thu Apr 13 19:15:17 2023 From: gheskett at shentel.net (gene heskett) Date: Thu, 13 Apr 2023 19:15:17 -0400 Subject: Weak Type Ability for Python In-Reply-To: <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> Message-ID: <3c90812e-7dbc-89b6-6bc7-6ec4810bfbd9@shentel.net> On 4/13/23 13:34, Dennis Lee Bieber wrote: > On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson > declaimed the following: > >> On 12Apr2023 22:12, avi.e.gross at gmail.com wrote: >>> I suspect the OP is thinking of languages like PERL or JAVA which guess >>> for >>> you and make such conversions when it seems to make sense. >> >> JavaScript guesses. What a nightmare. Java acts like Python and will >> forbid it on type grounds (at compile time with Java, being staticly >> typed). >> > > REXX -- where everything is considered a string until it needs to be > something else. > > REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022 > rexxtry.rex lets you interactively try REXX statements. > Each string is executed when you hit Enter. > Enter 'call tell' for a description of the features. > Go on - try a few... Enter 'exit' to end. You missed the best REXX, Dennis. ARexx for the amiga's. Bill Hawes wrote in a link to everything amigados had and we wrote, in ARexx, stuff that Amigados didn't have starting with a cron, a better cron than Paul Vixies. Worst, Bill never got a dime from commode-door for the best language it had, We served our WDTV web page with it in the middle 90's. Using ARexx and early php. Now its farmed out and 99% commercial junk. > x = 1; > ........................................... rexxtry.rex on WindowsNT > y = "a"; > ........................................... rexxtry.rex on WindowsNT > say x||y; > 1a > ........................................... rexxtry.rex on WindowsNT 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 avi.e.gross at gmail.com Thu Apr 13 19:25:45 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 13 Apr 2023 19:25:45 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> Message-ID: <00b801d96e5f$46008d10$d201a730$@gmail.com> Can I bring a part of this discussion a bit closer to Python? I stipulate that quite a few languages, including fairly early ones, treated text often as numbers. Ultimately, much of programming is about taking in text and often segregating parts into various buckets either explicitly or by checking if it has a decimal point or looks like scientific notation or in how it seems to be used. Is there any concept in Python of storing information in some way, such as text, and implementing various ideas or interfaces so that you can query if the contents are willing and able to be viewed in one of many other ways? As an example, an object may store a fairly large number as a text string in decimal format. The number is big enough that it cannot be fully represented in an 8 bit storage as in a byte or in a signed or unsigned 16-bit integer but can be stored in something larger. It may be possible to store it in a double precision floating point but not smaller. Yes, I know Python by default uses indefinite length integers, but you get the idea. Or it may be storing text in some format but the object is willing to transform the text into one of several other formats when needed. The text may also have attributes such as whether it is in English or Hungarian or is mixed-language. So for some applications, perhaps leaving the object as a string all the time may be reasonable. If some operation wishes to use the contents, the interface can be queried to see what other formats it can be coerced into and perhaps a specified set of methods need to be included that perform your transition for you such as object.return_as_int64() This can have wider implications. Imagine an object holding text in French that has been tested by humans using a program like Google Translate and deemed reasonable for translating into a specific dozen languages such as Esperanto and not certified into others like Klingon or High Valyrian or ASL. The object could contain interfaces for the languages it supports but does not store the translations, especially when the content is dynamic, such as a form letter that has been instantiated with a name and address and perhaps a part detailing what is being billed or shipped. Instead, the object can present an interface that lets a user determine if it supports dynamic translation to one or more target, such as the Quebec version of French or a British versus American version of English. I am being quite general here and lots of programs out there already probably have their own way of providing such facilities on a case-by-case basis. But do some languages have some support within the language itself? I do note some languages allow objects to oddly belong to multiple classes at once and have used that feature as a way to check if an object has some capabilities. Some languages have concepts like a mix-in and Python does allow thing like multiple inheritance albeit it often is best not to use it much. It does have ideas about how to test if a class implements some things by seeing if various dunder methods are in place. My reason for asking, is based on the discussion. If I want to use plus with an integer and a string, it may be reasonable for the interpreter to ask one or the other operand if they are able to be seen another way. If an integer indicates it can be seen as text, great. If a string indicates it believes it can deliver a number, great. Unfortunately, if they BOTH are flexible, how do you decide whether to add them as numbers or concatenate them as strings? Sigh! -----Original Message----- From: Python-list On Behalf Of Chris Angelico Sent: Thursday, April 13, 2023 3:35 PM To: python-list at python.org Subject: Re: Weak Type Ability for Python On Fri, 14 Apr 2023 at 03:29, Dennis Lee Bieber wrote: > > On Thu, 13 Apr 2023 12:21:58 +1000, Cameron Simpson > declaimed the following: > > >On 12Apr2023 22:12, avi.e.gross at gmail.com wrote: > >>I suspect the OP is thinking of languages like PERL or JAVA which guess > >>for > >>you and make such conversions when it seems to make sense. > > > >JavaScript guesses. What a nightmare. Java acts like Python and will > >forbid it on type grounds (at compile time with Java, being staticly > >typed). > > > > REXX -- where everything is considered a string until it needs to be > something else. > > REXX-ooRexx_5.0.0(MT)_64-bit 6.05 23 Dec 2022 > rexxtry.rex lets you interactively try REXX statements. > Each string is executed when you hit Enter. > Enter 'call tell' for a description of the features. > Go on - try a few... Enter 'exit' to end. > x = 1; > ........................................... rexxtry.rex on WindowsNT > y = "a"; > ........................................... rexxtry.rex on WindowsNT > say x||y; > 1a > ........................................... rexxtry.rex on WindowsNT REXX - where everything is a string, arithmetic can be done on strings, and data structures are done in the variable name instead of the value. I've seen quite a few strings-only languages, but I can't think of any other language than REXX where you create arrays and dictionaries by using computed variable names. It was quite the experience back in the day (as OS/2's native scripting language), and one that I'm truly glad to have had, as it taught me so much about the differences between languages. (It also taught me to treasure good documentation and value it as truly precious, because SysSetObjectData was an incredibly powerful function whose docs just referred to WinSetObjectData, and the window manager's docs weren't part of what I had available.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list From learn2program at gmail.com Thu Apr 13 19:49:45 2023 From: learn2program at gmail.com (Alan Gauld) Date: Fri, 14 Apr 2023 00:49:45 +0100 Subject: Weak Type Ability for Python In-Reply-To: References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> Message-ID: <899fcb5e-016b-1717-de5c-a68ad435cf37@yahoo.co.uk> On 13/04/2023 20:35, Chris Angelico wrote: > REXX - where everything is a string, > It was quite the experience back in the day (as OS/2's native > scripting language), I briefly met REXX on a mainframe, but I did play with OS/2 for a year or two. Back when it looked like it might be a rival to M$ OS/2 running NeXTstep now that would have been a platform for the 90s... both so near yet so far. -- 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 learn2program at gmail.com Thu Apr 13 20:13:56 2023 From: learn2program at gmail.com (Alan Gauld) Date: Fri, 14 Apr 2023 01:13:56 +0100 Subject: Weak Type Ability for Python In-Reply-To: <00b801d96e5f$46008d10$d201a730$@gmail.com> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> <00b801d96e5f$46008d10$d201a730$@gmail.com> Message-ID: <62cbbe2b-be03-75d9-ed27-ed8e93cea36a@yahoo.co.uk> On 14/04/2023 00:25, avi.e.gross at gmail.com wrote: > Is there any concept in Python of storing information in some way, such as > text, and implementing various ideas or interfaces so that you can query if > the contents are willing and able to be viewed in one of many other ways? Are you talking about something like a C union type (or a Pascal variant record)? I'm not aware of any such feature in Python but have often thought it would be a nice to have for the rare cases where its useful. > Or it may be storing text in some format but the object is willing to > transform the text into one of several other formats when needed. The text > may also have attributes such as whether it is in English or Hungarian or is > mixed-language. Or are you meaning something like an extension to the struct module that can interpret a bytestring in any way defined by a format string? > basis. But do some languages have some support within the language itself? The closest to what you seem to mean is, I think, the C union type, at least in my experience. But you have to define all the ways you can interpret the type up front in the type definition. > My reason for asking, is based on the discussion. If I want to use plus with > an integer and a string, it may be reasonable for the interpreter to ask one > or the other operand if they are able to be seen another way. You can achieve that in a slightly different way in Tcl which allows you to redefine all the operators (commands in Tcl-speak) in the language so redefining plus is easy. Doing it based on type is more tricky but doable. > Unfortunately, if they BOTH are flexible, how do you decide whether to add > them as numbers or concatenate them as strings? Yes, that's where it becomes a designer's arbitrary choice. -- 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 rosuav at gmail.com Thu Apr 13 20:19:03 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Apr 2023 10:19:03 +1000 Subject: Weak Type Ability for Python In-Reply-To: <899fcb5e-016b-1717-de5c-a68ad435cf37@yahoo.co.uk> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> <899fcb5e-016b-1717-de5c-a68ad435cf37@yahoo.co.uk> Message-ID: On Fri, 14 Apr 2023 at 09:49, Alan Gauld wrote: > > On 13/04/2023 20:35, Chris Angelico wrote: > > > REXX - where everything is a string, > > > It was quite the experience back in the day (as OS/2's native > > scripting language), > > I briefly met REXX on a mainframe, but I did play with OS/2 for > a year or two. Back when it looked like it might be a rival to M$ > > OS/2 running NeXTstep now that would have been a platform > for the 90s... both so near yet so far. > OS/2 was the primary operating system in our house from about 1992ish until maybe the early 2000s - possibly 2010 even, depending on how you count things. After a while we needed to permit the occasional Windows system due to software that didn't work, and then I started deploying some Linux systems. Eventually the Linux boxes outnumbered the OS/2, and finally the last OS/2 system was virtualized under Linux, completing the transition. But along the way, I spent many years learning the way that OS/2 works, and that's been so valuable to me ever since. The system was built from the ground up with threads in mind, so every programmer, as a matter of course, just learned about threads. It's that simple. Want to make a GUI app? The rule is, you respond to a window message within a very few milliseconds; if you can't do your processing in that much time, you spin off a thread. Easy. VX-REXX actually did that for every message automatically, running thread zero for the system GUI message loop, and feeding messages to a REXX message loop; you could, of course, still spawn your own REXX threads as needed. The entire Presentation Manager and Workplace Shell (broadly equivalent to a Linux "desktop manager", I think? Kinda?) were object oriented; you would have a WPDataFile for every, well, data file, but some of those might be subclasses of WPDataFile. And it was fairly straight-forward to write your own subclass of WPDataFile, and there was an API to say "if you would ever create a WPDataFile, instead create one of my class instead". This brilliant technique allowed anyone to enhance the desktop in any way, quite impressive especially for its time. I've yearned for that ever since, in various systems, although I'm aware that it would make quite a mess of Python if you could say "class EnhancedInt(int): ..." and then "any time you would create an int, create an EnhancedInt instead". A bit tricky to implement. Ahh, the memories. Clinging onto several old Realtek RTL8029 cards long past the days when ten megabit networking was considered adequate, because I knew that I could ALWAYS rely on them. Seriously, those things just never gave me issues. Problems with networking? Slap in an 8029 and see if it's the card or something else. Need to download the driver before your network card works? Grab an 8029, boot with that, fetch driver, try again. Good times. ChrisA From hjp-python at hjp.at Thu Apr 13 20:19:27 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Fri, 14 Apr 2023 02:19:27 +0200 Subject: Weak Type Ability for Python In-Reply-To: <64381eff.920a0220.9f55.07ce@mx.google.com> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <64381eff.920a0220.9f55.07ce@mx.google.com> Message-ID: <20230414001927.6slclkq4xenuyop3@hjp.at> On 2023-04-13 08:25:51 -0700, Grant Edwards wrote: > On 2023-04-13, Cameron Simpson wrote: > > On 12Apr2023 22:12, avi.e.gross at gmail.com wrote: > > > >>I suspect the OP is thinking of languages like PERL or JAVA which guess > >>for you and make such conversions when it seems to make sense. > > > > JavaScript guesses. What a nightmare. > > So does PHP. Not in this case. Like Perl (Not PERL) it has different operators for concatenation and addition. So $a + $b is always addition, never concatenation. Well, at least numbers and strings. For arrays its a (somewhat bizarre) union. 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 Richard at Damon-Family.org Thu Apr 13 20:53:21 2023 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 13 Apr 2023 20:53:21 -0400 Subject: Weak Type Ability for Python In-Reply-To: <00b801d96e5f$46008d10$d201a730$@gmail.com> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> <00b801d96e5f$46008d10$d201a730$@gmail.com> Message-ID: <8969c20b-5683-73fc-9c6c-5c06ed881c01@Damon-Family.org> On 4/13/23 7:25 PM, avi.e.gross at gmail.com wrote: > s there any concept in Python of storing information in some way, such as > text, and implementing various ideas or interfaces so that you can query if > the contents are willing and able to be viewed in one of many other ways? There is nothing that I know of built into Python that does this. There is no reason you can't write your own class to implement this. Something that by "default" looks like a string, but in some contexts (operated on by certain types) sees if its string could be treated as a value of some other type, and if so, converts its value to that type and does the operation. -- Richard Damon From greg.ewing at canterbury.ac.nz Thu Apr 13 20:54:45 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 14 Apr 2023 12:54:45 +1200 Subject: Weak Type Ability for Python In-Reply-To: References: <015501d96dca$3ef2c820$bcd85860$@gmail.com> <002201d96e21$d3995dc0$7acc1940$@gmail.com> <002f01d96e28$b74d1650$25e742f0$@gmail.com> Message-ID: On 14/04/23 4:55 am, avi.e.gross at gmail.com wrote: > While we are at it, why stop with imaginary numbers when you can imagine > extensions thereof? Unfortunately, it has been proven there are and can only > be two additional such constructs. You can go beyond that if you broaden your horizons enough. There are Clifford algebras, Lie algebras, ... Not sure what any of those should do to strings, though. :-) -- Greg From avi.e.gross at gmail.com Thu Apr 13 22:14:25 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 13 Apr 2023 22:14:25 -0400 Subject: Weak Type Ability for Python In-Reply-To: <62cbbe2b-be03-75d9-ed27-ed8e93cea36a@yahoo.co.uk> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> <00b801d96e5f$46008d10$d201a730$@gmail.com> <62cbbe2b-be03-75d9-ed27-ed8e93cea36a@yahoo.co.uk> Message-ID: <00c901d96e76$d6066580$82133080$@gmail.com> Alan, Your guess is not quite what I intended. Something like a C union is just a piece of memory large enough to hold one of several kinds of content and some way to figure out which is currently in place. I am looking at a data structure that is an object of some class and stores the data in any way that it feels like. But it may be a bit of a chameleon that shows one face or another as needed. I can write code now that simply adds various access methods to the class used and also provides a way to query if it supports some interfaces. Consider a dumb example. I have an object that holds a temperature and stores it in say degrees Celsius. There are simple formulas that can convert it to Fahrenheit or Kelvin or Rankine. So you can create access methods like get_as_Rankine() but this will only be useful for some programs that know about the interface. So what if you had a variable in the class such as supported_formats that presented something like a list of scales supported using an official set of names? It may even be possible to get a reference to the function to call to get that functionality, or perhaps you have one access function that accepts any argument on the list and delivers what is wanted. The temperature would only need to be stored in one format but be available in many. Of course, you could choose to precalculate and store others, or cache them when one request has come in and so forth. Another example would be dates stored in some format in a class that can deliver the result in all kinds of formats. Yes, we have functions that do things like that. But can you see advantages to the class hiding lots of details internally? These are just examples but the point is motivated by some interfaces I have seen. How do you know if something can be used by a context manner such as in a "with" statement? There may be other ways, but it seems two dunder methods, if present, likely mean it is. They are __enter__() and __exit__(). There are other interfaces like for iterators, that sometimes are more complex as when some things are not present, it uses others. Can you have a general function like is_iterator() or is_context_manager() that pretty much guarantees it is safe for the rest of the code to use the object in the way it wants? My comments about overloading plus were a sort of extra idea. I think we have discussed the general algorithm for how Python tries to resolve something like "obj1 op obj2" and not just for the plus operator. There are quite a few dunder methods that cover many such operators. What I was thinking about was a bit of a twist on that algorithm. I did something very vaguely like this years ago when I was working on how to translate documents from one format to another, such as WANG, Multimate, Wordperfect, plain text, etc. The goal was for a sender of an email to add an attachment and send it to many people at once. Each recipient would have a known preference for the type of document format they preferred. I wrote an algorithm in C++ which I got early access to as I was working at Bell Labs that effectively used a registered series of translator software along with info on how well or fast they worked, to do as few translations as possible and send each recipient the format they wanted. Yes, there were major incompatibilities and you sometimes ended up with some features being dropped or changed. But that is not the point. If format A had do direct translator to format Z, I would find the intersection of formats we had software for to translate to from A, and anther set of languages that could be used to translate from to Z. Sometimes it needed multiple hops. It worked fine but never saw the light of day as, weirdly, the project had been canceled months earlier and they were stalling while planning the next project and thus let me do what I wanted even though I was integrating my C++ code into a project that was otherwise al in C. Now back to Python in this regard. If I type alpha + beta then maybe after trying the methods we have described, if still failing, the algorithm could see if alpha and beta registered what types they could output and see if a match could be made. If a number object offered a string version, that would be a match. If the string offered a numeric version, again problem solved. And even if the match was not precise, sometimes the interpreter might know enough to do a bit more and say convert an integer into a double if the sizes of the contents allowed. The problem with this, and there are many, is that there is a certain nondeterministic aspect that may cause surprises and plenty of cost. It was just a academic thought that probably is not needed in the context albeit may be implemented in some projects to bridge things as described or in other novel ways. -----Original Message----- From: Alan Gauld Sent: Thursday, April 13, 2023 8:14 PM To: avi.e.gross at gmail.com; python-list at python.org Subject: Re: RE: Weak Type Ability for Python On 14/04/2023 00:25, avi.e.gross at gmail.com wrote: > Is there any concept in Python of storing information in some way, such as > text, and implementing various ideas or interfaces so that you can query if > the contents are willing and able to be viewed in one of many other ways? Are you talking about something like a C union type (or a Pascal variant record)? I'm not aware of any such feature in Python but have often thought it would be a nice to have for the rare cases where its useful. > Or it may be storing text in some format but the object is willing to > transform the text into one of several other formats when needed. The text > may also have attributes such as whether it is in English or Hungarian or is > mixed-language. Or are you meaning something like an extension to the struct module that can interpret a bytestring in any way defined by a format string? > basis. But do some languages have some support within the language itself? The closest to what you seem to mean is, I think, the C union type, at least in my experience. But you have to define all the ways you can interpret the type up front in the type definition. > My reason for asking, is based on the discussion. If I want to use plus with > an integer and a string, it may be reasonable for the interpreter to ask one > or the other operand if they are able to be seen another way. You can achieve that in a slightly different way in Tcl which allows you to redefine all the operators (commands in Tcl-speak) in the language so redefining plus is easy. Doing it based on type is more tricky but doable. > Unfortunately, if they BOTH are flexible, how do you decide whether to add > them as numbers or concatenate them as strings? Yes, that's where it becomes a designer's arbitrary choice. -- 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 2QdxY4RzWzUUiLuE at potatochowder.com Thu Apr 13 22:26:53 2023 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 13 Apr 2023 22:26:53 -0400 Subject: Weak Type Ability for Python In-Reply-To: <00c901d96e76$d6066580$82133080$@gmail.com> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> <00b801d96e5f$46008d10$d201a730$@gmail.com> <62cbbe2b-be03-75d9-ed27-ed8e93cea36a@yahoo.co.uk> <00c901d96e76$d6066580$82133080$@gmail.com> Message-ID: On 2023-04-13 at 22:14:25 -0400, avi.e.gross at gmail.com wrote: > I am looking at a data structure that is an object of some class and > stores the data in any way that it feels like. But it may be a bit of > a chameleon that shows one face or another as needed. I can write code > now that simply adds various access methods to the class used and also > provides a way to query if it supports some interfaces. Python dicts act mostly like hash tables. All by themselves, hash tables are unordered (and in return for giving up that order, you get O(1) access to an item if you know its key). But when you ask a Python dict for the keys, you always get them in the same order, skipping those that have been deleted since the last time you asked, and appending the new keys to the end of the list in the order in which you added them. There's your chameleon. From list1 at tompassin.net Thu Apr 13 23:10:19 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 13 Apr 2023 23:10:19 -0400 Subject: Weak Type Ability for Python In-Reply-To: <00c901d96e76$d6066580$82133080$@gmail.com> References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> <00b801d96e5f$46008d10$d201a730$@gmail.com> <62cbbe2b-be03-75d9-ed27-ed8e93cea36a@yahoo.co.uk> <00c901d96e76$d6066580$82133080$@gmail.com> Message-ID: <369a53e8-6701-c606-c7b3-2fb974e9f7c9@tompassin.net> On 4/13/2023 10:14 PM, avi.e.gross at gmail.com wrote: > Alan, > > Your guess is not quite what I intended. > > Something like a C union is just a piece of memory large enough to hold one of several kinds of content and some way to figure out which is currently in place. > > I am looking at a data structure that is an object of some class and stores the data in any way that it feels like. But it may be a bit of a chameleon that shows one face or another as needed. I can write code now that simply adds various access methods to the class used and also provides a way to query if it supports some interfaces. > > Consider a dumb example. I have an object that holds a temperature and stores it in say degrees Celsius. There are simple formulas that can convert it to Fahrenheit or Kelvin or Rankine. So you can create access methods like get_as_Rankine() but this will only be useful for some programs that know about the interface. > > So what if you had a variable in the class such as supported_formats that presented something like a list of scales supported using an official set of names? It may even be possible to get a reference to the function to call to get that functionality, or perhaps you have one access function that accepts any argument on the list and delivers what is wanted. Now you are starting to sound like COM. You ask an object for its IUnknown interface, and from that interface you can query what other interfaces it has available. You go on from there. From avi.e.gross at gmail.com Thu Apr 13 23:44:56 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 13 Apr 2023 23:44:56 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> <00b801d96e5f$46008d10$d201a730$@gmail.com> <62cbbe2b-be03-75d9-ed27-ed8e93cea36a@yahoo.co.uk> <00c901d96e76$d6066580$82133080$@gmail.com> Message-ID: <00ef01d96e83$7af814b0$70e83e10$@gmail.com> Yes, Dave, there are many data structures that can be used to maintain a list of output types the class claims to support. Dictionaries have the interesting property that you can presumably have a value that holds a member function to access the way the key specifies. Ideally, the order is not important for what I am looking for. Generally, I would think that any class like the ones I have been discussing, would want to broadcast a fairly short list of output types it would support. Of course, if you look at my date example, the list could be quite big but if you simply use something like strftime() for many of the formats, perhaps you may not need to list all possible ones. Any valid format could be accepted as an argument and passed to such a utility function. Your dictionary might simply store some commonly used formats known to work. But I repeat. This is not a serious request. I know how to build limited functionality like this if I ever want it, but wonder if anyone has ever created a proposal for some protocols and perhaps helpers like say an embedded object that handles aspects of it once you have initialized your dictionary and also handles requests to show part of what is stored for any shoppers wondering if you are compatible with their needs. -----Original Message----- From: Python-list On Behalf Of 2QdxY4RzWzUUiLuE at potatochowder.com Sent: Thursday, April 13, 2023 10:27 PM To: python-list at python.org Subject: Re: RE: Weak Type Ability for Python On 2023-04-13 at 22:14:25 -0400, avi.e.gross at gmail.com wrote: > I am looking at a data structure that is an object of some class and > stores the data in any way that it feels like. But it may be a bit of > a chameleon that shows one face or another as needed. I can write code > now that simply adds various access methods to the class used and also > provides a way to query if it supports some interfaces. Python dicts act mostly like hash tables. All by themselves, hash tables are unordered (and in return for giving up that order, you get O(1) access to an item if you know its key). But when you ask a Python dict for the keys, you always get them in the same order, skipping those that have been deleted since the last time you asked, and appending the new keys to the end of the list in the order in which you added them. There's your chameleon. -- https://mail.python.org/mailman/listinfo/python-list From wlfraed at ix.netcom.com Fri Apr 14 00:06:09 2023 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Fri, 14 Apr 2023 00:06:09 -0400 Subject: Weak Type Ability for Python References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> Message-ID: On Fri, 14 Apr 2023 05:35:22 +1000, Chris Angelico declaimed the following: >It was quite the experience back in the day (as OS/2's native >scripting language), and one that I'm truly glad to have had, as it >taught me so much about the differences between languages. > I still miss the Amiga ARexx implementation which piggy-backed on the Amiga IPC scheme* such that any application that opened a "RexxPort" could be the target for "ADDRESS ", and hence scripted using ARexx (Did IBM ever get beyond the two choices of command-line and a line-editor?). * Granted, that IPC relied upon the fact that all applications shared one memory space, so there wasn't the overhead of copying data structures from sending application to the port's linked list and thence to the receiving application. From Keith.S.Thompson+u at gmail.com Fri Apr 14 00:11:21 2023 From: Keith.S.Thompson+u at gmail.com (Keith Thompson) Date: Thu, 13 Apr 2023 21:11:21 -0700 Subject: Hide my query about covariance matrix syntax from google References: Message-ID: <87sfd3drx2.fsf@nosuchdomain.example.com> Chris Angelico writes: > On Fri, 14 Apr 2023 at 03:11, Meghna Karkera wrote: >> >> Respected Sir >> >> I kindly request you to hide my query about covariance matrix syntax from >> google which was emailed to you a few years back as it appears on google >> page. >> >> Hoping that you do the needful. > > These posts are public. While it's possible to ask for something to be > removed from the official python-list archive, that won't remove it > from Google Groups or any other third-party archive. > > Also, there's nothing we can do here to remove your post; you'll have > to contact the list admins. > > And just in case it's of interest to you: > https://en.wikipedia.org/wiki/Streisand_effect It's also mirrored to Usenet (comp.lang.python). There's basically no way to delete articles from Usenet. (The protocol includes a command to cancel an article, but servers ignore it due to past abuse.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u at gmail.com Working, but not speaking, for XCOM Labs void Void(void) { Void(); } /* The recursive call of the void */ From wlfraed at ix.netcom.com Fri Apr 14 00:22:43 2023 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Fri, 14 Apr 2023 00:22:43 -0400 Subject: Weak Type Ability for Python References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> <00b801d96e5f$46008d10$d201a730$@gmail.com> <8969c20b-5683-73fc-9c6c-5c06ed881c01@Damon-Family.org> Message-ID: On Thu, 13 Apr 2023 20:53:21 -0400, Richard Damon declaimed the following: >On 4/13/23 7:25 PM, avi.e.gross at gmail.com wrote: >> s there any concept in Python of storing information in some way, such as >> text, and implementing various ideas or interfaces so that you can query if >> the contents are willing and able to be viewed in one of many other ways? > >There is nothing that I know of built into Python that does this. > >There is no reason you can't write your own class to implement this. >Something that by "default" looks like a string, but in some contexts >(operated on by certain types) sees if its string could be treated as a >value of some other type, and if so, converts its value to that type and >does the operation. I sure don't want to see the documentation for that... a = thisType(3) b = thisType(7) c = 9 #plain integer print(a + b + c) (Since I presume left to right evaluation of equal level operations) Does this result in 46 ("3" + "7" => "37", int("37") + 9 => 46) or 19 (as int("3") + int("7") => 10, + 9 => 19) Worse... changing order of a/b/c would make completely different results... 82 (b + a + c) 127 (int(a) + c returning thisType(12) + b as strings) and does (c + a) result in returning an integer (a conforming to c); or a string (a coercing c to thisType). From rosuav at gmail.com Fri Apr 14 03:22:47 2023 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 14 Apr 2023 17:22:47 +1000 Subject: Weak Type Ability for Python In-Reply-To: References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> Message-ID: On Fri, 14 Apr 2023 at 17:17, Dennis Lee Bieber wrote: > > On Fri, 14 Apr 2023 05:35:22 +1000, Chris Angelico > declaimed the following: > > >It was quite the experience back in the day (as OS/2's native > >scripting language), and one that I'm truly glad to have had, as it > >taught me so much about the differences between languages. > > > > I still miss the Amiga ARexx implementation which piggy-backed on the > Amiga IPC scheme* such that any application that opened a "RexxPort" could > be the target for "ADDRESS ", and hence scripted using ARexx (Did > IBM ever get beyond the two choices of command-line and a line-editor?). > > > * Granted, that IPC relied upon the fact that all applications shared one > memory space, so there wasn't the overhead of copying data structures from > sending application to the port's linked list and thence to the receiving > application. Yeah, the "ADDRESS" command has so much potential. Back in the day, I built a MUD with REXX scripting, and within those scripts, the default ADDRESS target was "send message to the invoker of the command", so you could do something like this: /* A bare string gets sent to the client */ "Hello!" /* You can still invoke shell commands, if you actually need to */ address cmd "do_a_thing" Rabid proponents of OOP say that it's all about sending messages to things. Well, the ADDRESS command truly lets you send messages, so.... that means REXX is the most object oriented language there is, right? ChrisA From wlfraed at ix.netcom.com Fri Apr 14 10:32:30 2023 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Fri, 14 Apr 2023 10:32:30 -0400 Subject: Weak Type Ability for Python References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> Message-ID: {one more entry in the thread drift, and then I think I'll shut up} On Fri, 14 Apr 2023 17:22:47 +1000, Chris Angelico declaimed the following: >Yeah, the "ADDRESS" command has so much potential. Back in the day, I >built a MUD with REXX scripting, and within those scripts, the default >ADDRESS target was "send message to the invoker of the command", so >you could do something like this: I used to think (Open)VMS would have been a potential platform for an effective ADDRESS command. Where ARexx used a shared memory linked-list for the "port" (as I'd stated, avoiding copying of data), (Open)VMS had "mailboxes" (they would have to copy data -- or at best remap the virtual memory from one process to another) which could serve the same purpose; receiving application creates/owns the named mailbox, sending applications would provide the data packet including a return mailbox link. > >/* A bare string gets sent to the client */ >"Hello!" >/* You can still invoke shell commands, if you actually need to */ >address cmd "do_a_thing" > Yeah, that was the other feature -- anything that could not be parsed as a REXX statement was automatically sent to whatever the current ADDRESS host happened to be. From martin.schoon at gmail.com Fri Apr 14 15:47:35 2023 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 14 Apr 2023 19:47:35 GMT Subject: Problem with Matplotlib example References: <4cef1b3b-30fd-378e-5fe7-7944bf5aec61@mrabarnett.plus.com> Message-ID: Den 2023-04-13 skrev MRAB : > On 2023-04-13 19:41, Martin Sch??n wrote: >> Anyone had success running this example? >> https://tinyurl.com/yhhyc9r >> >> As far as I know I have an up-to-date matplotlib installed. Pip has >> nothing more modern to offer me. >> > All I can say is that it works for me! > > Python 3.10 and 3.11, matplotlib 3.6.1 and then 3.7.1 after updating it. > Thanks are due to both you and Thomas. Your replies put me on the right scent. I soon learned what I should have know since ages: pip reporting there is now newer version of a package does not mean there is *no newer* version. It means there is no newer version for the version of Python I use. In my case I am on Python 3.7. At work, where I am on Python 3.8, this matplotlib example works just fine. /Martin From avi.e.gross at gmail.com Fri Apr 14 16:16:00 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Fri, 14 Apr 2023 16:16:00 -0400 Subject: Weak Type Ability for Python In-Reply-To: References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> <00b801d96e5f$46008d10$d201a730$@gmail.com> <8969c20b-5683-73fc-9c6c-5c06ed881c01@Damon-Family.org> Message-ID: <001101d96f0d$eea6ff40$cbf4fdc0$@gmail.com> Dennis, Before I reply, let me reiterate I am NOT making a concrete suggestion, just having a somewhat abstract discussion. The general topic is a sort of polymorphism I envisioned where a select group of classes/objects that can be seen as different aspects of an elephant can be handled to provide some functionality in a consistent way. We all agree much of the functionality can be done deliberately by individual programmers. The question was whether anyone had done a more general implementation or even saw any reason to do so. Fair enough? So let us assume I have an object, call it obj1, that encapsulates data the old fashioned way. Consider a classical case like an object holding information about a parallelopiped or something like a shoebox. How you store the info can vary, such as recording a height/width/depth, or a series of x,y,z coordinates representing some of the vertices. But no matter how you store the basic info, you can derive many things from them when asked to provide a volume or surface area or whether it will fit within another object of the same kind assuming the sides have no width. Or, you can ask it to return another instance object that has double the width or many other things. There are several ways to provide the functionality, actually quite a few, but one is to make a method for each thing it does such as obj1.get_surface_area(), obj1.get_volume() and obj1.does_it_fit_in(cl2) and of course you can have methods that change the orientation or ask what angles it is oriented at now and whatever else you want. Each such method will return something of a usually deterministic type. Volumes will be a double, for example. But what if you design a small language so you can type obj1.get_by_name("volume") and similar requests, or even a comma separated grouping of requests that returns a list of the answers? It now is not so deterministic-looking to a linter. But normal Python allows and often encourages such polymorphism so is this anything new? What I envisioned is a tad closer to the latter. Not this: a = thisType(3) b = thisType(7) c = 9 #plain integer print(a + b + c) Note the above example is standard. My thoughts are a bit more arcane and focused on convertibility of a single value into multiple forms. Say I have a data type that stores a number representing a temperature. It may have ways to initialize (or change) the temperature so it can be input as degrees centigrade or Fahrenheit or Kelvin or Rankine or even more indirect ways such as 10 degrees Fahrenheit above the freezing point of pure water at a particular atmospheric pressure and so on. What I want to add is a bit like this. Internally many methods may get created that may not be expected to be used except through a designated interface. Call them f1() and f2() ... fn() for now. Also in the class initialization or perhaps in the object dunder init, you create something like a dictionary consisting of key words matched by pointers to the aforementioned functions/methods. This structure will have some name designated by the protocol such as _VIEWS and may be visible to anyone looking at the object. The details can be worked out but this is a simplistic explanation. In this dictionary we may have words like "Celsius", "Fahrenheit" and so on, perhaps even several variants that point to the same functions. If a user wants the temperature in absolute terms, they may call a standard function like "obj1.as_type('Kelvin')" and that function will search the dictionary and get you the results using the appropriate conversion method. You may also support other accessors like 'obj1.supports_type("Fahrenheit451")' that reports as True/False whether the object can handle that output. It merely checks the internal dictionary. You may have another that returns a list of the data types as keys and whatever else is part of the design. You can, of course, have a second set of such directives that instead of returning a temperature as a double, will return a printable text version that includes ? or ?K or ?R or ?F". A second example could be something holding a date with plenty of internal abilities to display it in a wide variety of formats or maybe just holds a day of the week that it will display as a string in any language it handles, such as Sunday being shown as: ???? ???????? Diman?o Vas?rnap Sonntag Dimanche Zondag ??? ?????? And so on. Again, it need not store the text for every language but can call translation software as needed and it can be more than the name of a day of the week. It could have a dictionary containing all the languages it handles as described for another example and access methods. Of course, if called on repeatedly and often for the same languages, it could cache results. My question, again, is not whether this can be done but whether some kind of protocol can be created that is published and suggests the names and so on to use in constructing your own implementation. And, it may be helpful if a module is made available that makes it even simpler to use. I think it is time for me to drop out of this discussion unless I hear something of interest. It is just an idea I have been pondering. -----Original Message----- From: Python-list On Behalf Of Dennis Lee Bieber Sent: Friday, April 14, 2023 12:23 AM To: python-list at python.org Subject: Re: Weak Type Ability for Python On Thu, 13 Apr 2023 20:53:21 -0400, Richard Damon declaimed the following: >On 4/13/23 7:25 PM, avi.e.gross at gmail.com wrote: >> s there any concept in Python of storing information in some way, such as >> text, and implementing various ideas or interfaces so that you can query if >> the contents are willing and able to be viewed in one of many other ways? > >There is nothing that I know of built into Python that does this. > >There is no reason you can't write your own class to implement this. >Something that by "default" looks like a string, but in some contexts >(operated on by certain types) sees if its string could be treated as a >value of some other type, and if so, converts its value to that type and >does the operation. I sure don't want to see the documentation for that... a = thisType(3) b = thisType(7) c = 9 #plain integer print(a + b + c) (Since I presume left to right evaluation of equal level operations) Does this result in 46 ("3" + "7" => "37", int("37") + 9 => 46) or 19 (as int("3") + int("7") => 10, + 9 => 19) Worse... changing order of a/b/c would make completely different results... 82 (b + a + c) 127 (int(a) + c returning thisType(12) + b as strings) and does (c + a) result in returning an integer (a conforming to c); or a string (a coercing c to thisType). -- https://mail.python.org/mailman/listinfo/python-list From hjp-python at hjp.at Sat Apr 15 07:22:24 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 15 Apr 2023 13:22:24 +0200 Subject: Weak Type Ability for Python In-Reply-To: References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> <0sqe3id664268aqif7sttg1r0c1vikof9k@4ax.com> <899fcb5e-016b-1717-de5c-a68ad435cf37@yahoo.co.uk> Message-ID: <20230415112224.mpbvmgstbg4ygr2g@hjp.at> On 2023-04-14 10:19:03 +1000, Chris Angelico wrote: > The entire Presentation Manager and Workplace Shell (broadly > equivalent to a Linux "desktop manager", I think? Kinda?) were object > oriented; you would have a WPDataFile for every, well, data file, but > some of those might be subclasses of WPDataFile. And it was fairly > straight-forward to write your own subclass of WPDataFile, and there > was an API to say "if you would ever create a WPDataFile, instead > create one of my class instead". This brilliant technique allowed > anyone to enhance the desktop in any way, quite impressive especially > for its time. I've yearned for that ever since, in various systems, > although I'm aware that it would make quite a mess of Python if you > could say "class EnhancedInt(int): ..." and then "any time you would > create an int, create an EnhancedInt instead". A bit tricky to > implement. Or alternatively you might be able to add or replace methods on the existing int class. So 5 is still just an int, but now (5 + "x") calls the modified __add__ method which knows how add a string to an int. Might make even more of a mess ;-). 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 Sat Apr 15 07:23:54 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 15 Apr 2023 13:23:54 +0200 Subject: Weak Type Ability for Python In-Reply-To: References: <00a201d96dad$64ef8990$2ece9cb0$@gmail.com> Message-ID: <20230415112354.phmlnzs37nwu2rpt@hjp.at> On 2023-04-13 03:28:37 +0100, MRAB wrote: > On 2023-04-13 03:12, avi.e.gross at gmail.com wrote: > > I suspect the OP is thinking of languages like PERL or JAVA which guess for > > you and make such conversions when it seems to make sense. > > > In the case of Perl, there are distinct operators for addition and string > concatenation, with automatic type conversion (non-numeric strings have a > numeric value of 0, which can hide bugs). You get a warning for that, though. 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 jiehuan233 at outlook.com Sun Apr 16 06:57:18 2023 From: jiehuan233 at outlook.com (Jason Wang) Date: Sun, 16 Apr 2023 18:57:18 +0800 Subject: tksheet - Copy and Paste with headers In-Reply-To: References: Message-ID: ? 2023/4/15 2:33, angela vales ??: > Hello All, > > I found this small group in a google search, so not sure if it is still active but giving it a try nonetheless. > > I have recently created a tkinter app and need the ability to copy and paste data from tksheet table into an Excel file. I do have a button for export, but it will be beneficial to also allow the user to simply copy,paste. > > I have enabled the appropriate bindings but cannot find a solution to also > copy the header information during the copy and paste. > > My table is generated after a query is run. Here is a small snippet. > > df = pd.read_sql_query(query, conn) > results_table.set_sheet_data(df.values.tolist()) > results_table.headers(df.columns.tolist()) > results_table.enable_bindings( > "drag_select", > "select_all", > "column_drag_and_drop", > "row_drag_and_drop", > "column_select", > "row_select", > "arrowkeys", > "right_click_popup_menu", > "copy", > "paste", > "undo" > ) > > best > Angela Vales I am not sure how to solve your problem. The newsgroup may not be able to wait for an answer, so I suggest that you go to Stack Overflow to ask questions after conducting a thorough Google search. Of course, you can also wait for someone who knows the answer to come and answer:D From learn2program at gmail.com Sun Apr 16 09:01:42 2023 From: learn2program at gmail.com (Alan Gauld) Date: Sun, 16 Apr 2023 14:01:42 +0100 Subject: tksheet - Copy and Paste with headers In-Reply-To: References: Message-ID: <39c79652-b424-abd8-c1fc-2f60b27e2aed@yahoo.co.uk> > ? 2023/4/15 2:33, angela vales ??: >> I have recently created a tkinter app and need the ability to copy and > paste data from tksheet table into an Excel file. First thanks for drawing my attention to tksheet. I've long been desiring a decent table widget in tkinter and was on the verge of trying to create one of my own. tksheet looks like it will do all I need. As to copy/paste I couldn't see any explicit mention but it does say the underlying data is in a Tk Canvas so it may be that copy/paste will just work, did you try it? What happened if you paste into a text editor in the first instance? And Excel in the second? If all else fails you can probably write handlers and bind to Ctrl-C and Ctrl-V to do something yourself that mimics cut/paste. -- 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 list1 at tompassin.net Sun Apr 16 09:53:03 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 16 Apr 2023 09:53:03 -0400 Subject: tksheet - Copy and Paste with headers In-Reply-To: <39c79652-b424-abd8-c1fc-2f60b27e2aed@yahoo.co.uk> References: <39c79652-b424-abd8-c1fc-2f60b27e2aed@yahoo.co.uk> Message-ID: <57659803-e20f-ac7a-dd18-9b0ad04208fd@tompassin.net> On 4/16/2023 9:01 AM, Alan Gauld wrote: > >> ? 2023/4/15 2:33, angela vales ??: >>> I have recently created a tkinter app and need the ability to copy and >> paste data from tksheet table into an Excel file. > > First thanks for drawing my attention to tksheet. I've long > been desiring a decent table widget in tkinter and was on the > verge of trying to create one of my own. tksheet looks like > it will do all I need. > > As to copy/paste I couldn't see any explicit mention but > it does say the underlying data is in a Tk Canvas so it may > be that copy/paste will just work, did you try it? What > happened if you paste into a text editor in the first > instance? And Excel in the second? > > If all else fails you can probably write handlers and bind > to Ctrl-C and Ctrl-V to do something yourself that mimics > cut/paste. I have not used tksheet, but in its documentation at https://github.com/ragardner/tksheet/wiki#14-getting-selected-cells, there is the method get_currently_selected() Returns namedtuple of (row, column, type_) e.g. (0, 0, "column") type_ can be "row", "column" or "cell" There are companion methods for rows, columns, etc. That would be a good starting point. From aapost at idontexist.club Sun Apr 16 10:24:34 2023 From: aapost at idontexist.club (aapost) Date: Sun, 16 Apr 2023 10:24:34 -0400 Subject: tksheet - Copy and Paste with headers In-Reply-To: References: Message-ID: On 4/14/23 14:33, angela vales wrote: > I have recently created a tkinter app and need the ability to copy and paste data from tksheet table into an Excel file. I do have a button for export, but it will be beneficial to also allow the user to simply copy,paste. > > I have enabled the appropriate bindings but cannot find a solution to also > copy the header information during the copy and paste. the csv export code runs through a different path than the ctrl_c code, one operating on the sheet level, one on the main table level (I didn't dig in to the depths but my assumptions would be that main table doesn't mathematically consider the headers in the same way). def yield_sheet_rows in _tksheet.py vs def ctrl_c in _tksheet_main_table.py Comparing how the each path functions, without a larger redesign of tksheet, you could create a custom button press combo binding to something other than ctrl-c utilizing the yield_sheet_rows (or - disallow all other ctrl-c functionality in favor of ONLY a csv style everything dump when using ctrl-c): Import these: import csv as csv_module import io This would be your custom binding functionality: rows = self.sheet.yield_sheet_rows(get_header = True, get_index = False) s = io.StringIO() writer = csv_module.writer(s, dialect = csv_module.excel_tab, lineterminator = "\n") for row in rows: writer.writerow(row) self.clipboard_clear() self.clipboard_append(s.getvalue()) It would need something deeper if you wanted to integrate it to ctrl-c and keep the existing ctrl-c functionality From rshepard at appl-ecosys.com Sun Apr 16 16:42:10 2023 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 16 Apr 2023 13:42:10 -0700 (PDT) Subject: Cannot install pkg_resources using pip Message-ID: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> Python3-3.9.10 installed on this Slackware64-14.2 desktop. Trying to run meson to build an application I'm told it's missing pkg_resources, which is part of setuptools. The command fails: # pip install setuptools bash: /usr/bin/pip: /usr/bin/python3.7: bad interpreter: No such file or directory There is no python3.7 here: # ls /usr/bin/python3.7 ls: cannot access '/usr/bin/python3.7': No such file or directory How do I clean this up? TIA, Rich From list1 at tompassin.net Sun Apr 16 17:03:43 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 16 Apr 2023 17:03:43 -0400 Subject: Cannot install pkg_resources using pip In-Reply-To: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> References: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> Message-ID: <87618b70-ef05-b63f-71a2-738c40b138f9@tompassin.net> On 4/16/2023 4:42 PM, Rich Shepard wrote: > Python3-3.9.10 installed on this Slackware64-14.2 desktop. Trying to run > meson to build an application I'm told it's missing pkg_resources, which is > part of setuptools. The command fails: > # pip install setuptools > bash: /usr/bin/pip: /usr/bin/python3.7: bad interpreter: No such file or > directory > > There is no python3.7 here: > # ls /usr/bin/python3.7 > ls: cannot access '/usr/bin/python3.7': No such file or directory > > How do I clean this up? What is there to clean up? If you have Python 3.9 installed, why are you fooling around trying to run Python 3.7? It seems you are not telling us something ... It's better to always run pip with the version of Python that you intend to use. If that is launched when you type "python3", then run pip this way: python3 -m pip If instead you want to use, say, python3.9, then type this: python3.9 -m pip From rshepard at appl-ecosys.com Sun Apr 16 18:27:56 2023 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 16 Apr 2023 15:27:56 -0700 (PDT) Subject: Cannot install pkg_resources using pip In-Reply-To: <99b79b42-a19e-51cb-7618-dab8d971abc1@tompassin.net> References: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> <87618b70-ef05-b63f-71a2-738c40b138f9@tompassin.net> <5d151ae5-3422-198-8164-dec245dfc99e@appl-ecosys.com> <99b79b42-a19e-51cb-7618-dab8d971abc1@tompassin.net> Message-ID: <99628c5c-a034-2076-5d48-2a49b6befec2@appl-ecosys.com> On Sun, 16 Apr 2023, Thomas Passin wrote: > It worked then because your path found a pip script. When there are more > than one Python installations, it can be unclear which one will get run, > depending on how the path got set up after the last version was installed. Thomas, I probably last used pip with a python-3.7 version. > To check your version of Python, run > python3 -V $ python3 -V Python 3.9.10 > Then try to run pip: > python3.9 -m pip $ python3.9 -m pip /usr/bin/python3.9: No module named pip > If pip has not been installed (very possible on Linux), then you will need to > get it. If python3.9 is not the system-upgraded version, then do an internet > search for "linux python install pip". There's a pip website that has an > installer for it. I never remember what it's called, so I always have to > search for it myself. https://www.redhat.com/sysadmin/install-python-pip-linux I'll download the installer from ther. > If it appears that python3.9 *is* the version installed by the system, then > use the system installer to install the right version of pip - as I said > above, the package name can vary across distros. It should have been installed with the upgrade to 3.9.10 > Your message doesn't seem to have been copied to the mailing list. If you > don't mind, it could help other people if you copied it and this reply to > the list. I always respond to the mail list if that's the 'reply to' address. Sometimes I don't check the address used in my reply, assuming it's correct. Thanks, Rich From rshepard at appl-ecosys.com Sun Apr 16 18:34:25 2023 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 16 Apr 2023 15:34:25 -0700 (PDT) Subject: Cannot install pkg_resources using pip In-Reply-To: <99628c5c-a034-2076-5d48-2a49b6befec2@appl-ecosys.com> References: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> <87618b70-ef05-b63f-71a2-738c40b138f9@tompassin.net> <5d151ae5-3422-198-8164-dec245dfc99e@appl-ecosys.com> <99b79b42-a19e-51cb-7618-dab8d971abc1@tompassin.net> <99628c5c-a034-2076-5d48-2a49b6befec2@appl-ecosys.com> Message-ID: <38c9d095-11fa-dec8-b9dc-8abcf375f06e@appl-ecosys.com> On Sun, 16 Apr 2023, Rich Shepard wrote: > I'll download the installer from there. But, I still cannot install the pkg_resources module that meson wants to start the build of pulseaudio-equalizer: # pip install pkg_resources ERROR: Could not find a version that satisfies the requirement pkg_resources (from versions: none) ERROR: No matching distribution found for pkg_resources Rich From khoinguyenn343 at gmail.com Sun Apr 16 16:54:59 2023 From: khoinguyenn343 at gmail.com (Khoinguyen Nguyen) Date: Sun, 16 Apr 2023 16:54:59 -0400 Subject: Fwd: pip is not installed In-Reply-To: References: Message-ID: To whom it may concern, I have tried to reinstall, repair, and run in command prompt, but it seems as though pip won't install. I am using Windows 10 and Python 3.11.3. Are there any other suggestions for troubleshooting? Thank you. From python at mrabarnett.plus.com Sun Apr 16 22:09:36 2023 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 17 Apr 2023 03:09:36 +0100 Subject: Fwd: pip is not installed In-Reply-To: References: Message-ID: On 2023-04-16 21:54, Khoinguyen Nguyen wrote: > To whom it may concern, > I have tried to reinstall, repair, and run in command prompt, but it seems > as though pip won't install. I am using Windows 10 and Python 3.11.3. Are > there any other suggestions for troubleshooting? > Thank you. Have you tried using pip via the Python Launcher? py -m pip That's installed by default by the installer from python.org. From cs at cskk.id.au Sun Apr 16 22:11:06 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 17 Apr 2023 12:11:06 +1000 Subject: Fwd: pip is not installed In-Reply-To: References: Message-ID: On 16Apr2023 16:54, Khoinguyen Nguyen wrote: >I have tried to reinstall, repair, and run in command prompt, but it >seems >as though pip won't install. I am using Windows 10 and Python 3.11.3. Are >there any other suggestions for troubleshooting? Have you tried invoking pip _via_ Python? This is actually the recommended approach because it uses the pip for that specific Python. Example: py -m pip install foo This invokes the "pip" module for thePython invoked by "py" (which I believe is how Python is normally invoked from a Windows command line), to install some package "foo". Cheers, Cameron Simpson From list1 at tompassin.net Sun Apr 16 22:59:16 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 16 Apr 2023 22:59:16 -0400 Subject: Cannot install pkg_resources using pip In-Reply-To: <99628c5c-a034-2076-5d48-2a49b6befec2@appl-ecosys.com> References: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> <87618b70-ef05-b63f-71a2-738c40b138f9@tompassin.net> <5d151ae5-3422-198-8164-dec245dfc99e@appl-ecosys.com> <99b79b42-a19e-51cb-7618-dab8d971abc1@tompassin.net> <99628c5c-a034-2076-5d48-2a49b6befec2@appl-ecosys.com> Message-ID: <2a81722b-40ac-620d-b186-4f17e47e71b2@tompassin.net> On 4/16/2023 6:27 PM, Rich Shepard wrote: > On Sun, 16 Apr 2023, Thomas Passin wrote: [snip] > It should have been installed with the upgrade to 3.9.10 In my experience, on Windows pip is always included but on Linux hardly ever. I have always needed to install the system installer pip package or get it from the pip site, depending, as I wrote earlier, on whether your version of Python was installed by the system or not. [I'm no great Linux expert but I've had to go through this for probably a dozen VMs over the last few years]. From list1 at tompassin.net Sun Apr 16 23:08:56 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 16 Apr 2023 23:08:56 -0400 Subject: Cannot install pkg_resources using pip In-Reply-To: <38c9d095-11fa-dec8-b9dc-8abcf375f06e@appl-ecosys.com> References: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> <87618b70-ef05-b63f-71a2-738c40b138f9@tompassin.net> <5d151ae5-3422-198-8164-dec245dfc99e@appl-ecosys.com> <99b79b42-a19e-51cb-7618-dab8d971abc1@tompassin.net> <99628c5c-a034-2076-5d48-2a49b6befec2@appl-ecosys.com> <38c9d095-11fa-dec8-b9dc-8abcf375f06e@appl-ecosys.com> Message-ID: On 4/16/2023 6:34 PM, Rich Shepard wrote: > On Sun, 16 Apr 2023, Rich Shepard wrote: > >> I'll download the installer from there. > > But, I still cannot install the pkg_resources module that meson wants to > start the build of pulseaudio-equalizer: > # pip install pkg_resources > ERROR: Could not find a version that satisfies the requirement > pkg_resources (from versions: none) > ERROR: No matching distribution found for pkg_resources > > Rich Sorry, Rich, I've never dealt with this so someone else will have to give suggestions. I would try to see if there are any versions available. It could be that meson says it needs version x but only version y > x is available. Pip will quit but meson may very well work with the available version anyway. So I would try to install pkg_resources on its own, and then see if the meson build can succeed. No guarantees, but I've seen this work before. So python3.9 -m pip install --user pkg_resources Or, to see what versions if any are available: python3.9 -m pip install --user pkg_resources== # NO spaces allowed before the "==". There is a pip option to ignore the version specification and just leave the existing package installed as is, and this could help if the full installation wants to downgrade the pgk_resources that you just installed. You can also use the --dry-run option to see what would happen without actually changing anything. From list1 at tompassin.net Mon Apr 17 00:07:13 2023 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 17 Apr 2023 00:07:13 -0400 Subject: Cannot install pkg_resources using pip In-Reply-To: <99628c5c-a034-2076-5d48-2a49b6befec2@appl-ecosys.com> References: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> <87618b70-ef05-b63f-71a2-738c40b138f9@tompassin.net> <5d151ae5-3422-198-8164-dec245dfc99e@appl-ecosys.com> <99b79b42-a19e-51cb-7618-dab8d971abc1@tompassin.net> <99628c5c-a034-2076-5d48-2a49b6befec2@appl-ecosys.com> Message-ID: <91e91f6a-7520-b636-ab3a-de9f72be262b@tompassin.net> On 4/16/2023 6:27 PM, Rich Shepard wrote: >> If pip has not been installed (very possible on Linux), then you will >> need to get it.? If python3.9 is not the system-upgraded version, then >> do an internet search for "linux python install pip". There's a pip >> website that has an installer for it. I never remember what it's >> called, so I always have to search for it myself. > > https://www.redhat.com/sysadmin/install-python-pip-linux > > I'll download the installer from ther. The page I was thinking of is https://pip.pypa.io/en/stable/installation/ I found it by an internet search for "pip installer". It covers several ways to install pip on Linux, MacOS, and Windows. On Linux, use it for Python installations that were *not* installed by the system. Use the package manager if the Python installation or upgrade *was* installed by the system. That Redhat link basically uses the pypa.io instructions. From list1 at tompassin.net Sun Apr 16 23:16:10 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 16 Apr 2023 23:16:10 -0400 Subject: Fwd: pip is not installed In-Reply-To: References: Message-ID: On 4/16/2023 10:09 PM, MRAB wrote: > On 2023-04-16 21:54, Khoinguyen Nguyen wrote: >> To whom it may concern, >> I have tried to reinstall, repair, and run in command prompt, but it >> seems >> as though pip won't install. I am using Windows 10 and Python 3.11.3. Are >> there any other suggestions for troubleshooting? >> Thank you. > > Have you tried using pip via the Python Launcher? > > py -m pip > > That's installed by default by the installer from python.org. To elaborate, Python might have been installed using an installer from python.org, from the Windows store, or in some other way. "py" may only be available for a python.org installer. In general, you would do best to always launch pip with the command pythonx -m pip where "pythonx" means the command that launches the version of python you want to work with. This might be "py", "python3.11", "py -3.11", or something else, so use what you will be using on your system. From rshepard at appl-ecosys.com Mon Apr 17 08:45:51 2023 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 17 Apr 2023 05:45:51 -0700 (PDT) Subject: Cannot install pkg_resources using pip In-Reply-To: References: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> <87618b70-ef05-b63f-71a2-738c40b138f9@tompassin.net> <5d151ae5-3422-198-8164-dec245dfc99e@appl-ecosys.com> <99b79b42-a19e-51cb-7618-dab8d971abc1@tompassin.net> <99628c5c-a034-2076-5d48-2a49b6befec2@appl-ecosys.com> <38c9d095-11fa-dec8-b9dc-8abcf375f06e@appl-ecosys.com> Message-ID: <9f7bd325-8436-29ac-2896-ea35bdd918f6@appl-ecosys.com> On Sun, 16 Apr 2023, Thomas Passin wrote: > Sorry, Rich, I've never dealt with this so someone else will have to give > suggestions. Thomas, This is all new to me, too. > I would try to see if there are any versions available. It could be that > meson says it needs version x but only version y > x is available. Pip > will quit but meson may very well work with the available version anyway. > So I would try to install pkg_resources on its own, and then see if the > meson build can succeed. No guarantees, but I've seen this work before. So > python3.9 -m pip install --user pkg_resources > > Or, to see what versions if any are available: > python3.9 -m pip install --user pkg_resources== > # NO spaces allowed before the "==". Thank you. I'll give this a try. Regards, Rich From FJ100111 at hotmail.com Mon Apr 17 03:36:43 2023 From: FJ100111 at hotmail.com (=?iso-2022-jp?B?GyRCTWUbKEIgGyRCQ2ZNJhsoQg==?=) Date: Mon, 17 Apr 2023 07:36:43 +0000 Subject: pip upgrade error Message-ID: When I using pip list, it tells me there is a new release of pip is available, but I got these error messages when I upgrading pip. I don?t know what happened it is. PS C:\Users\USER> pip --version pip pip 23.0.1 from C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip (python 3.10) PS C:\Users\USER> python.exe -m pip install --upgrade pip Requirement already satisfied: pip in c:\users\user\appdata\roaming\python\python310\site-packages (23.0.1) Collecting pip Using cached pip-23.1-py3-none-any.whl (2.1 MB) Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 23.0.1 Uninstalling pip-23.0.1: Successfully uninstalled pip-23.0.1 Rolling back uninstall of pip Moving to c:\users\user\appdata\roaming\python\python310\scripts\pip.exe from C:\Users\USER\AppData\Local\Temp\pip-uninstall-byh29tpt\pip.exe Moving to c:\users\user\appdata\roaming\python\python310\scripts\pip3.10.exe from C:\Users\USER\AppData\Local\Temp\pip-uninstall-byh29tpt\pip3.10.exe Moving to c:\users\user\appdata\roaming\python\python310\scripts\pip3.exe from C:\Users\USER\AppData\Local\Temp\pip-uninstall-byh29tpt\pip3.exe Moving to c:\users\user\appdata\roaming\python\python310\site-packages\pip-23.0.1.dist-info\ from C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\~ip-23.0.1.dist-info Moving to c:\users\user\appdata\roaming\python\python310\site-packages\pip\ from C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\~ip ERROR: Exception: Traceback (most recent call last): File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_internal\cli\base_command.py", line 160, in exc_logging_wrapper status = run_func(*args) File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_internal\cli\req_command.py", line 247, in wrapper return func(self, options, args) File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_internal\commands\install.py", line 507, in run installed = install_given_reqs( File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_internal\req\__init__.py", line 73, in install_given_reqs requirement.install( File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_internal\req\req_install.py", line 796, in install install_wheel( File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_internal\operations\install\wheel.py", line 729, in install_wheel _install_wheel( File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_internal\operations\install\wheel.py", line 646, in _install_wheel generated_console_scripts = maker.make_multiple(scripts_to_generate) File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\distlib\scripts.py", line 436, in make_multiple filenames.extend(self.make(specification, options)) File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_internal\operations\install\wheel.py", line 427, in make return super().make(specification, options) File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\distlib\scripts.py", line 425, in make self._make_script(entry, filenames, options=options) File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\distlib\scripts.py", line 325, in _make_script self._write_script(scriptnames, shebang, script, filenames, ext) File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\distlib\scripts.py", line 249, in _write_script launcher = self._get_launcher('t') File "C:\Users\USER\AppData\Roaming\Python\Python310\site-packages\pip\_vendor\distlib\scripts.py", line 404, in _get_launcher raise ValueError(msg) ValueError: Unable to find resource t64.exe in package pip._vendor.distlib [notice] A new release of pip is available: 23.0.1 -> 23.1 [notice] To update, run: python.exe -m pip install --upgrade pip From aapost at idontexist.club Mon Apr 17 11:00:20 2023 From: aapost at idontexist.club (aapost) Date: Mon, 17 Apr 2023 11:00:20 -0400 Subject: Cannot install pkg_resources using pip In-Reply-To: References: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> <87618b70-ef05-b63f-71a2-738c40b138f9@tompassin.net> <5d151ae5-3422-198-8164-dec245dfc99e@appl-ecosys.com> <99b79b42-a19e-51cb-7618-dab8d971abc1@tompassin.net> <99628c5c-a034-2076-5d48-2a49b6befec2@appl-ecosys.com> <38c9d095-11fa-dec8-b9dc-8abcf375f06e@appl-ecosys.com> <9f7bd325-8436-29ac-2896-ea35bdd918f6@appl-ecosys.com> Message-ID: On 4/17/23 08:45, Rich Shepard wrote: > On Sun, 16 Apr 2023, Thomas Passin wrote: Slackware isn't as straight forward in it's management as other distros (not standardized anyway). If this is someone elses install I would be cautious in using any advice I am providing, as it would be better for someone with familiarity with how they want the device set up to address the issues (such as if they prefer using some sort of package scheme or if doing everything from source is ok). That being said, if you start from python source (as in overwriting what is currently there and doing a fresh reinstall), you can download Python3.9, then run ./configure make make install after doing that, verify (python may still link to something old, that may be ok in this case, but good to note) python --version python3 --version python3.9 --version pkg_resources is inside of setuptools so you would run python3.9 -m pip install setuptools (might already be there with the reinstall) after that run python3.9 then run import pkg_resources import setuptools to see if you get errors or successful imports if they import successfully, attempt to reinstall meson and ninja against your fresh python install python3.9 -m pip install meson python3.9 -m pip install ninja verify versions with meson -v ninja --version Then follow the instructions of the meson package from there (you mentioned some sort of pulseaudio-equalizer, depending on your desktop environment, you may run in to additional issues depending on how your slackware is setup). From rshepard at appl-ecosys.com Mon Apr 17 13:33:50 2023 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 17 Apr 2023 10:33:50 -0700 (PDT) Subject: Cannot install pkg_resources using pip [RESOLVED] In-Reply-To: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> References: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> Message-ID: <511ec947-de7c-c7a-be66-5e179e5ed857@appl-ecosys.com> On Sun, 16 Apr 2023, Rich Shepard wrote: > How do I clean this up? My thanks for the suggestions and ideas you sent me on this issue. I've resolved it by not trying to build pulseaudio-equalizer. I don't need it because I learned this morning that my Yamaha CM500 headset clearly heard the Zoom audio test tones and voices on a YouTube video. I'm testing the headset on a Zoom call this afternoon with a friend. Assuming it works with the meeting as it did on the Zoom test I'll use it for Zoom and Jitsi meetings and use the Marantz Pro mic and Panasonic headphones for recording web tutorials and podcasts. Regards, Rich From rshepard at appl-ecosys.com Mon Apr 17 14:13:15 2023 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 17 Apr 2023 11:13:15 -0700 (PDT) Subject: Cannot install pkg_resources using pip In-Reply-To: References: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> <87618b70-ef05-b63f-71a2-738c40b138f9@tompassin.net> <5d151ae5-3422-198-8164-dec245dfc99e@appl-ecosys.com> <99b79b42-a19e-51cb-7618-dab8d971abc1@tompassin.net> <99628c5c-a034-2076-5d48-2a49b6befec2@appl-ecosys.com> <38c9d095-11fa-dec8-b9dc-8abcf375f06e@appl-ecosys.com> <9f7bd325-8436-29ac-2896-ea35bdd918f6@appl-ecosys.com> Message-ID: <9aed49f2-e95e-d332-bedb-274160e7bba4@appl-ecosys.com> On Mon, 17 Apr 2023, aapost wrote: > Slackware isn't as straight forward in it's management as other distros > (not standardized anyway). I've used Slackware for 20 years; it's completely rationale and comfortable for me. :-) > That being said, if you start from python source ... If worse came to worse, I'd reinstall the distro package. Thanks, Rich From hjp-python at hjp.at Mon Apr 17 15:24:03 2023 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 17 Apr 2023 21:24:03 +0200 Subject: Cannot install pkg_resources using pip In-Reply-To: <87618b70-ef05-b63f-71a2-738c40b138f9@tompassin.net> References: <702fdd3c-089-f34a-7f-9f971be2d5ba@appl-ecosys.com> <87618b70-ef05-b63f-71a2-738c40b138f9@tompassin.net> Message-ID: <20230417192403.tjstbhqvqsdvdurm@hjp.at> On 2023-04-16 17:03:43 -0400, Thomas Passin wrote: > On 4/16/2023 4:42 PM, Rich Shepard wrote: > > Python3-3.9.10 installed on this Slackware64-14.2 desktop. [...] > > # pip install setuptools > > bash: /usr/bin/pip: /usr/bin/python3.7: bad interpreter: No such file or > > directory > > > > There is no python3.7 here: > > # ls /usr/bin/python3.7 > > ls: cannot access '/usr/bin/python3.7': No such file or directory > > > > How do I clean this up? > > What is there to clean up? There is a version of pip installed for a version of python which isn't installed. That's definitely not useful, so it should be cleaned up. As to how to do that: Find out which package /usr/bin/pip belongs to and deinstall or upgrade this package. How to find that package is a Slackware question, not a Python question. And since Rich wrote that he's been comfortably using Slackware for 20 years, I'll trust that he knows how to do that and just needed a little nudge into the right direction. 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 info at cmcc.it Tue Apr 18 10:51:39 2023 From: info at cmcc.it (info cmcc) Date: Tue, 18 Apr 2023 16:51:39 +0200 Subject: Scientific Software Developer for the Digital Twin of the Ocean | Job position at CMCC Foundation, Italy In-Reply-To: References: Message-ID: *SCIENTIFIC SOFTWARE DEVELOPER FOR THE DIGITAL TWIN OF THE OCEAN* [Job Opening Code: 12443] *Lecce (Italy) - Deadline: 30/04/2023* Our Division of Advanced Scientific Computing (ASC Division) is considering the possibility to hire a talented and proactive Post Degree candidate to support CMCC research activities. The contract will be jointly funded by CMCC and the HPC Training and Research for Earth Sciences (HPC-TRES) program. The job location is CMCC Headquarters in Lecce, Italy. We are looking for a motivated person with the following requirements: - M.Sc. degree in Computer Science or Computer Engineering or equivalent fields; - 2+ years? experience in scientific software development; - Excellent knowledge of Python programming language; - Good knowledge of Python scientific (numpy, scipy, scikit-learn, pandas) and visualization (e.g., matplotlib) libraries; - Good theoretical knowledge of Machine Learning algorithms and techniques for regression and classification tasks; - Good knowledge of at least one Machine/Deep Learning framework (e.g., TensorFlow, Keras, Pytorch); - Good capabilities in writing technical reports and scientific papers as well as documenting code; - Good knowledge of both written and spoken English language. Additional preferred experience: - Experience with HPC systems - Experience in training ML models in distributed environments and corresponding strategies Belonging to legally protected categories (ex L. 68/99) will constitute a preferential condition. *More details and info about HOW TO APPLY:* https://cmccfoundation.applytojob.com/apply/vmml1qbN4W/12443-Scientific-Software-Developer-For-The-Digital-Twin-Of-The-Ocean?source=Our%20Career%20Page%20Widget -- Fondazione CMCCCentro Euro-Mediterraneo sui Cambiamenti Climatici Via Marco Biagi, 5 - 73100 Lecce info at cmcc.it - www.cmcc.it From kevinmwilson1956 at yahoo.com Tue Apr 18 19:18:57 2023 From: kevinmwilson1956 at yahoo.com (Kevin M. Wilson) Date: Tue, 18 Apr 2023 23:18:57 +0000 (UTC) Subject: Pycharm IDE References: <127255282.580618.1681859937764.ref@mail.yahoo.com> Message-ID: <127255282.580618.1681859937764@mail.yahoo.com> Greetings... Kevin here:I need help, as you have guessed!I have this line: The Print Statement... Why complain about a 'comma', or a ')'???def play_game(): number = random.randint(1, LIMIT) print (f'"I am thinking of a number between 1 to {LIMIT}\n")Or is this a setting in the IDE, I need to reassign? Regards, Perplexed "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze."? ? ? Isaiah 43:2 | | Virus-free.www.avg.com | From PythonList at DancesWithMice.info Tue Apr 18 20:02:33 2023 From: PythonList at DancesWithMice.info (dn) Date: Wed, 19 Apr 2023 12:02:33 +1200 Subject: Pycharm IDE In-Reply-To: <127255282.580618.1681859937764@mail.yahoo.com> References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> Message-ID: <61cbbdd9-0b3c-bf38-95ea-f4d521d78e5a@DancesWithMice.info> On 19/04/2023 11.18, Kevin M. Wilson via Python-list wrote: > Greetings... Kevin here:I need help, as you have guessed!I have this line: The Print Statement... Why complain about a 'comma', or a ')'???def play_game(): > number = random.randint(1, LIMIT) > print (f'"I am thinking of a number between 1 to {LIMIT}\n")Or is this a setting in the IDE, I need to reassign? The code is a bit difficult to read (wrapping), but the error message may be an assumption (on Python's part). Should the line be: print( F"I am thinking... ^ no extraneous/unbalanced apostrophe here? -- Regards, =dn From list1 at tompassin.net Tue Apr 18 19:48:12 2023 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 18 Apr 2023 19:48:12 -0400 Subject: Pycharm IDE In-Reply-To: <127255282.580618.1681859937764@mail.yahoo.com> References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> Message-ID: <60c5a5c1-5434-1d8e-8322-a4022d906075@tompassin.net> On 4/18/2023 7:18 PM, Kevin M. Wilson via Python-list wrote: > Greetings... Kevin here:I need help, as you have guessed!I have this line: The Print Statement... Why complain about a 'comma', or a ')'???def play_game(): > number = random.randint(1, LIMIT) > print (f'"I am thinking of a number between 1 to {LIMIT}\n")Or is this a setting in the IDE, I need to reassign? I'm not sure what error you are talking about, but the f-string isn't closed (and doesn't appear to need the double quotes, either, though that is not an error). So - print (f'I am thinking of a number between 1 to {LIMIT}') (print() will add its own newline at the end so you don't need the \n unless you actually want another newline). Next time, please include the actual error message and make sure you include line breaks so things don't run together. > > Regards, Perplexed > "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze." > Isaiah 43:2 > > | | Virus-free.www.avg.com | > From aapost at idontexist.club Tue Apr 18 20:02:49 2023 From: aapost at idontexist.club (aapost) Date: Tue, 18 Apr 2023 20:02:49 -0400 Subject: Pycharm IDE In-Reply-To: References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> Message-ID: On 4/18/23 19:18, Kevin M. Wilson wrote: >Why complain about a 'comma', or a ')'??? > print (f'"I am thinking of a number between 1 to {LIMIT}\n") my version says it expects ' first (to close the fstring) then on a new line below it, it mentions the comma and ) I believe that is just showing you after ' it expects you to end the print with ) as you have or , to add additional arguments to print From kevinmwilson1956 at yahoo.com Wed Apr 19 01:16:00 2023 From: kevinmwilson1956 at yahoo.com (Kevin M. Wilson) Date: Wed, 19 Apr 2023 05:16:00 +0000 (UTC) Subject: Pycharm IDE In-Reply-To: References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> Message-ID: <1155066518.688499.1681881360098@mail.yahoo.com> print (f'"I am thinking of a number between 1 to {LIMIT}\n")I had the impression that the format specifier 'f' was necessary for the print function, but the double quotes are for the string printed to the user, as a prompt!The Pycharm IDE is showing that it expects a single quotation mark or ')'! No error message is displayed. Perplexed "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze."? ? ? Isaiah 43:2 On Tuesday, April 18, 2023 at 06:44:37 PM MDT, aapost wrote: On 4/18/23 19:18, Kevin M. Wilson wrote: >Why complain about a 'comma', or a ')'??? >? ? ? print (f'"I am thinking of a number between 1 to {LIMIT}\n") my version says it expects ' first (to close the fstring) then on a new line below it, it mentions the comma and ) I believe that is just showing you after ' it expects you to end the print with ) as you have or , to add additional arguments to print -- https://mail.python.org/mailman/listinfo/python-list | | Virus-free.www.avg.com | From kevinmwilson1956 at yahoo.com Wed Apr 19 01:27:56 2023 From: kevinmwilson1956 at yahoo.com (Kevin M. Wilson) Date: Wed, 19 Apr 2023 05:27:56 +0000 (UTC) Subject: Pycharm IDE In-Reply-To: <1155066518.688499.1681881360098@mail.yahoo.com> References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> <1155066518.688499.1681881360098@mail.yahoo.com> Message-ID: <1242860619.686995.1681882076134@mail.yahoo.com> Ok, I got rid of the "print (f'"I am thinking of a number between 1 to {LIMIT}\n")"print ("I am thinking of a number between 1 to {LIMIT}\n"), and Pycharm stopped complaining about it... WHY?? Perplexed "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze."? ? ? Isaiah 43:2 On Tuesday, April 18, 2023 at 11:17:52 PM MDT, Kevin M. Wilson via Python-list wrote: print (f'"I am thinking of a number between 1 to {LIMIT}\n")I had the impression that the format specifier 'f' was necessary for the print function, but the double quotes are for the string printed to the user, as a prompt!The Pycharm IDE is showing that it expects a single quotation mark or ')'! No error message is displayed. Perplexed "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze."? ? ? Isaiah 43:2 ? ? On Tuesday, April 18, 2023 at 06:44:37 PM MDT, aapost wrote:? On 4/18/23 19:18, Kevin M. Wilson wrote: >Why complain about a 'comma', or a ')'??? >? ? ? print (f'"I am thinking of a number between 1 to {LIMIT}\n") my version says it expects ' first (to close the fstring) then on a new line below it, it mentions the comma and ) I believe that is just showing you after ' it expects you to end the print with ) as you have or , to add additional arguments to print -- https://mail.python.org/mailman/listinfo/python-list ? |? | Virus-free.www.avg.com | -- https://mail.python.org/mailman/listinfo/python-list | | Virus-free.www.avg.com | From PythonList at DancesWithMice.info Wed Apr 19 03:17:03 2023 From: PythonList at DancesWithMice.info (dn) Date: Wed, 19 Apr 2023 19:17:03 +1200 Subject: Pycharm IDE In-Reply-To: <1242860619.686995.1681882076134@mail.yahoo.com> References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> <1155066518.688499.1681881360098@mail.yahoo.com> <1242860619.686995.1681882076134@mail.yahoo.com> Message-ID: <0e119db8-996d-d545-5435-566ade5433f1@DancesWithMice.info> Kevin, As mentioned in another response, the format of these messages seems very confused. Please copy-paste all of (the pertinent part of) the code, and ensure that the line-endings are in the correct places, tab/indentation looks correct, etc? (this will allow us to copy the same code into our PyCharm software and see what is happening!) There still appears to be both an apostrophe (') and quotation-marks ("). Do you want the user to see one/both? There was mention of this being an input prompt - hence the question-mark. Are you aware that this could be done as part of the input() function? How about creating a string and then printing that, eg prompt = f'"I am thinking of a number between 1 to {LIMIT}" print( prompt ) NB because of the question asked earlier, the above code is NOT syntactically-correct Python! NBB am assuming there's previous code which defines LIMIT On 19/04/2023 17.27, Kevin M. Wilson via Python-list wrote: > Ok, I got rid of the "print (f'"I am thinking of a number between 1 to {LIMIT}\n")"print ("I am thinking of a number between 1 to {LIMIT}\n"), > and Pycharm stopped complaining about it... WHY?? > Perplexed > "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze." > Isaiah 43:2 > > On Tuesday, April 18, 2023 at 11:17:52 PM MDT, Kevin M. Wilson via Python-list wrote: > > print (f'"I am thinking of a number between 1 to {LIMIT}\n")I had the impression that the format specifier 'f' was necessary for the print function, but the double quotes are for the string printed to the user, as a prompt!The Pycharm IDE is showing that it expects a single quotation mark or ')'! No error message is displayed. > Perplexed > "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze." > Isaiah 43:2 > > ? ? On Tuesday, April 18, 2023 at 06:44:37 PM MDT, aapost wrote: > > On 4/18/23 19:18, Kevin M. Wilson wrote: >> Why complain about a 'comma', or a ')'??? >> ? ? ? print (f'"I am thinking of a number between 1 to {LIMIT}\n") > > my version says it expects ' first (to close the fstring) > then on a new line below it, it mentions the comma and ) > I believe that is just showing you after ' it expects you to end the > print with ) as you have > or , to add additional arguments to print -- Regards, =dn From PythonList at DancesWithMice.info Wed Apr 19 05:33:19 2023 From: PythonList at DancesWithMice.info (dn) Date: Wed, 19 Apr 2023 21:33:19 +1200 Subject: Pycharm IDE In-Reply-To: <1057815704.182764.1681895608091@mail.yahoo.com> References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> <1155066518.688499.1681881360098@mail.yahoo.com> <1242860619.686995.1681882076134@mail.yahoo.com> <0e119db8-996d-d545-5435-566ade5433f1@DancesWithMice.info> <1057815704.182764.1681895608091@mail.yahoo.com> Message-ID: On 19/04/2023 21.13, Kevin M. Wilson wrote: > Sorry the code snippet I sent was what is written in PyCharm. LIMIT is > defined and is not causing an error! > PyCharm is flagging the Parentheses at the end. It is not seeing the > Parentheses as the end of the print function. > > def play_game(): > number= random.randint(1, LIMIT) > print (f'"I am thinking of a number between 1 to {LIMIT}\n") > > Observe... Look at the color of the parenthesis, it's green!!! > !!! = WTH Same question! Please explain: why is there a (single) apostrophe? NB some email clients don't notice list communications and ReplyList - you may need to do that manually... -- Regards, =dn From list1 at tompassin.net Wed Apr 19 08:33:21 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 19 Apr 2023 08:33:21 -0400 Subject: Pycharm IDE In-Reply-To: <1242860619.686995.1681882076134@mail.yahoo.com> References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> <1155066518.688499.1681881360098@mail.yahoo.com> <1242860619.686995.1681882076134@mail.yahoo.com> Message-ID: <152fb9fa-ce51-ad2f-c18c-a2052130e00b@tompassin.net> On 4/19/2023 1:27 AM, Kevin M. Wilson via Python-list wrote: > Ok, I got rid of the "print (f'"I am thinking of a number between 1 to {LIMIT}\n")"print ("I am thinking of a number between 1 to {LIMIT}\n"), I think you misunderstand several things at the same time here. 1. These errors originate from syntax errors. They are basically Python errors. It's possible that behind the scenes, PyCharm is running one or another Python program to detect them, but they are errors in your Python code. 2. print() doesn't care whether you give it an f-string or not, because a f-string is a string too. 3. All strings need to be closed with the same kind of quote they started with. If one is not closed, then Python thinks the string is supposed to continue, and - say- the final parenthesis of the print() function looks like it is part of the string. So Python (or PyCharm) notices that the closing parenthesis of the print() expression is missing. 4. in an f-string, the expression in braces is evaluated and replaced by its string value. So if you try to do this print('{LIMIT}') then that will be printed as is with no substitution - because it is not an f-string. So you will see "{LIMIT}" But you thought you were going to see "42" (if LIMIT == 42, that is). OTOH, print(f'{LIMIT}) will substitute the string value of LIMIT before printing the string. Both are legitimate but the first is not what you seem to want. 5. As I posted earlier, you almost certainly do not need to add the "\n". So, some suggestions: - If you are having a problem with some piece of code, try to simplify it down to the smallest bit that shows the problem. - If you are having trouble with f-strings, then think about what you want to achieve and look up information about f-strings with that in mind. - If you are having trouble with the print statement, think what you want it to display and look up information about the print function with that in mind. - If your tool - PyCharm in this case - is producing messages but you don't understand why they are being produced, try to look up information about how and when PyCharm produces error messages Do you see a pattern here? Also note that just because you don't see an error message does not mean that the code is correct. It may be correct from the point of view of Python syntax but that doesn't mean that it will perform correctly nor how you expect. > and Pycharm stopped complaining about it... WHY?? > Perplexed > "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze." > Isaiah 43:2 > > On Tuesday, April 18, 2023 at 11:17:52 PM MDT, Kevin M. Wilson via Python-list wrote: > > print (f'"I am thinking of a number between 1 to {LIMIT}\n")I had the impression that the format specifier 'f' was necessary for the print function, but the double quotes are for the string printed to the user, as a prompt!The Pycharm IDE is showing that it expects a single quotation mark or ')'! No error message is displayed. > Perplexed > "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze." > Isaiah 43:2 > > ? ? On Tuesday, April 18, 2023 at 06:44:37 PM MDT, aapost wrote: > > On 4/18/23 19:18, Kevin M. Wilson wrote: >> Why complain about a 'comma', or a ')'??? >> ? ? ? print (f'"I am thinking of a number between 1 to {LIMIT}\n") > > my version says it expects ' first (to close the fstring) > then on a new line below it, it mentions the comma and ) > I believe that is just showing you after ' it expects you to end the > print with ) as you have > or , to add additional arguments to print From kevinmwilson1956 at yahoo.com Wed Apr 19 05:51:24 2023 From: kevinmwilson1956 at yahoo.com (Kevin M. Wilson) Date: Wed, 19 Apr 2023 09:51:24 +0000 (UTC) Subject: PyCharm's strict PEP and not so strict? References: <2110321349.5908606.1681897884162.ref@mail.yahoo.com> Message-ID: <2110321349.5908606.1681897884162@mail.yahoo.com> Greetings,????? ? ?I'm in a bit of a quandary, I want some strict syntax errors to be flagged, but the use of single quotes vs double quotes! NOT what I need from the 'checker', you dig? As I've recently returned to the IDE, and no longer have the "stones" for bull, how do I set up the kind of "checking" I want? Thank you, Kevin "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze."? ? ? Isaiah 43:2 | | Virus-free.www.avg.com | From learn2program at gmail.com Wed Apr 19 12:25:37 2023 From: learn2program at gmail.com (Alan Gauld) Date: Wed, 19 Apr 2023 17:25:37 +0100 Subject: PyCharm's strict PEP and not so strict? In-Reply-To: <2110321349.5908606.1681897884162@mail.yahoo.com> References: <2110321349.5908606.1681897884162.ref@mail.yahoo.com> <2110321349.5908606.1681897884162@mail.yahoo.com> Message-ID: On 19/04/2023 10:51, Kevin M. Wilson via Python-list wrote: > ?I'm in a bit of a quandary, I want some strict syntax errors to be flagged, OK, You might want to use a "linter" in that case because most tools use the interpreter itself to flag syntax errors. > but the use of single quotes vs double quotes! > NOT what I need from the 'checker', you dig? Not really. What is the problem. Use of single versus double quotes is straightforward - use one or the other and make sure they match(opening and closing) You can nest one type inside the other if you need literal quotes. And of course the same applies to triple quotes except you can include newlines inside those. What kind of problems are you experiencing with quotes? If we have some specific examples we can give specific answers. > "stones" for bull, how do I set up the kind of "checking" I want? That's not a phrase with which I'm familiar but my guess is you need to install a linter tool and then, possibly configure it to flag or hide particular error/warning types to your personal taste. Each tool is different so you will need to read the docs on how to configure it (and how to plumb it into your IDE). Personally I've never felt the need for any stricter error checking than the interpreter provides so I can't offer anything beyond the generic suggestion to use a linter. -- 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 PythonList at DancesWithMice.info Wed Apr 19 13:37:33 2023 From: PythonList at DancesWithMice.info (dn) Date: Thu, 20 Apr 2023 05:37:33 +1200 Subject: PyCharm's strict PEP and not so strict? In-Reply-To: References: <2110321349.5908606.1681897884162.ref@mail.yahoo.com> <2110321349.5908606.1681897884162@mail.yahoo.com> Message-ID: <06af8d39-a128-27e6-eeb8-f9e3f8fde7b6@DancesWithMice.info> On 20/04/2023 04.25, Alan Gauld wrote: > On 19/04/2023 10:51, Kevin M. Wilson via Python-list wrote: >> ?I'm in a bit of a quandary, I want some strict syntax errors to be flagged, > > OK, You might want to use a "linter" in that case because most > tools use the interpreter itself to flag syntax errors. > > >> but the use of single quotes vs double quotes! >> NOT what I need from the 'checker', you dig? > > Not really. What is the problem. Use of single versus double quotes > is straightforward - use one or the other and make sure they > match(opening and closing) You can nest one type inside the > other if you need literal quotes. And of course the same applies > to triple quotes except you can include newlines inside those. > > What kind of problems are you experiencing with quotes? > If we have some specific examples we can give specific answers. > >> "stones" for bull, how do I set up the kind of "checking" I want? > > That's not a phrase with which I'm familiar but my guess > is you need to install a linter tool and then, possibly > configure it to flag or hide particular error/warning types > to your personal taste. Each tool is different so you > will need to read the docs on how to configure it > (and how to plumb it into your IDE). > > Personally I've never felt the need for any stricter error > checking than the interpreter provides so I can't offer > anything beyond the generic suggestion to use a linter. +1 PyCharm enables a range of Python-linters. Some by add-in. Some by "External tools" (https://www.jetbrains.com/help/pycharm/configuring-third-party-tools.html). Once a linter is made-available, some allow one to tune the application or relaxation of certain 'rules', eg whether commas in a comma-separated list are to be followed by a space. Whether any enable the restriction of quotes use is another matter - probably for the reasons @Alan has already covered. PyCharm auto-magically enters both an opening-quote and a closing-quote whenever start typing a string. The 'trick' is not to delete the close whilst editing. After gaining experience, I have a convention of when to use apostrophes and when double-quotes. These old eyes dislike mixing both in a single expression - but sometimes it is the best course to follow. YMMV! -- Regards, =dn From bob1.250211 at outlook.com Wed Apr 19 12:14:25 2023 From: bob1.250211 at outlook.com (charles wiewiora) Date: Wed, 19 Apr 2023 16:14:25 +0000 Subject: Python-pickle error Message-ID: Hello, I am experincing problems with the pickle moducle the folowing code was working before, import pickle number=2 my_pickeld_object=pickle.dumps(number) print("this is my pickled object",{my_pickeld_object},) with open('file.pkl', 'rb') as file: number=pickle.load(file) my_unpickeled_object=pickle.loads(my_pickeld_object) print("this is my unpickeled object",{my_unpickeled_object},) but now i get error Traceback (most recent call last): File "C:\Users\lukwi\Desktop\python\tester2.py", line 5, in with open('file.pkl', 'rb') as file: FileNotFoundError: [Errno 2] No such file or directory: 'file.pkl' im get this problem after this, a .pkl came into my Python script files i though this could be a spare file made from python becauce i was doing this first, import pickle number=2 my_pickeld_object=pickle.dumps(number) print("this is my pickled object",{my_pickeld_object},) with open('file.pkl', 'rb') as file: number=pickle.load(file) so i stupidly deleted the file do you know how to fix this? i reinstalled it but it didn't work this is on widnows and on version 3.11.3 on python thank you From nntp.mbourne at spamgourmet.com Wed Apr 19 16:06:18 2023 From: nntp.mbourne at spamgourmet.com (Mark Bourne) Date: Wed, 19 Apr 2023 21:06:18 +0100 Subject: Pycharm IDE In-Reply-To: References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> <1155066518.688499.1681881360098@mail.yahoo.com> <1242860619.686995.1681882076134@mail.yahoo.com> <152fb9fa-ce51-ad2f-c18c-a2052130e00b@tompassin.net> Message-ID: Thomas Passin wrote: > On 4/19/2023 1:27 AM, Kevin M. Wilson via Python-list wrote: >> Ok, I got rid of the "print (f'"I am thinking of a number between 1 to >> {LIMIT}\n")"print ("I am thinking of a number between 1 to {LIMIT}\n"), > > I think you misunderstand several things at the same time here. > > 1. These errors originate from syntax errors.? They are basically Python > errors.? It's possible that behind the scenes, PyCharm is running one or > another Python program to detect them, but they are errors in your > Python code. > > 2. print() doesn't care whether you give it an f-string or not, because > a f-string is a string too. > > 3. All strings need to be closed with the same kind of quote they > started with.? If one is not closed, then Python thinks the string is > supposed to continue, and - say- the final parenthesis of the print() > function looks like it is part of the string. So Python (or PyCharm) > notices that the closing parenthesis of the print() expression is missing. > > 4. in an f-string, the expression in braces is evaluated and replaced by > its string value.? So if you try to do this > > print('{LIMIT}') > > then that will be printed as is with no? substitution - because it is > not an f-string.? So you will see "{LIMIT}" But you thought you were > going to see "42" (if LIMIT == 42, that is). OTOH, > > print(f'{LIMIT}) ^ I think this one should be: print(f'{LIMIT}') with the closing quote ;o) > will substitute the string value of LIMIT before printing the string. > Both are legitimate but the first is not what you seem to want. > > 5. As I posted earlier, you almost certainly do not need to add the "\n". > > So, some suggestions: > > - If you are having a problem with some piece of code, try to simplify > it down to the smallest bit that shows the problem. > > - If you are having trouble with f-strings, then think about what you > want to achieve and look up information about f-strings with that in mind. > > - If you are having trouble with the print statement, think what you > want it to display and look up information about the print function with > that in mind. > > - If your tool - PyCharm in this case - is producing messages but you > don't understand why they are being produced, try to look up information > about how and when PyCharm produces error messages > > Do you see a pattern here? > > Also note that just because you don't see an error message does not mean > that the code is correct.? It may be correct from the point of view of > Python syntax but that doesn't mean that it will perform correctly nor > how you expect. > >> and Pycharm stopped complaining about it... WHY?? >> Perplexed >> "When you pass through the waters, I will be with you: and when >> you?pass through the rivers, they will not sweep over?you. When?you >> walk?through the fire, you will not be burned: the flames will not set >> you ablaze." >> Isaiah 43:2 >> >> ???? On Tuesday, April 18, 2023 at 11:17:52 PM MDT, Kevin M. Wilson >> via Python-list wrote: >> ? print (f'"I am thinking of a number between 1 to {LIMIT}\n")I had >> the impression that the format specifier 'f' was necessary for the >> print function, but the double quotes are for the string printed to >> the user, as a prompt!The Pycharm IDE is showing that it expects a >> single quotation mark or ')'! No error message is displayed. >> Perplexed >> "When you pass through the waters, I will be with you: and when >> you?pass through the rivers, they will not sweep over?you. When?you >> walk?through the fire, you will not be burned: the flames will not set >> you ablaze." >> Isaiah 43:2 >> >> ?? ? On Tuesday, April 18, 2023 at 06:44:37 PM MDT, aapost >> wrote: >> ? On 4/18/23 19:18, Kevin M. Wilson wrote: >>> Why complain about a 'comma', or a ')'??? >>> ?? ? ? print (f'"I am thinking of a number between 1 to {LIMIT}\n") >> >> my version says it expects ' first (to close the fstring) >> then on a new line below it, it mentions the comma and ) >> I believe that is just showing you after ' it expects you to end the >> print with ) as you have >> or , to add additional arguments to print > From list1 at tompassin.net Wed Apr 19 16:59:51 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 19 Apr 2023 16:59:51 -0400 Subject: Pycharm IDE In-Reply-To: References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> <1155066518.688499.1681881360098@mail.yahoo.com> <1242860619.686995.1681882076134@mail.yahoo.com> <152fb9fa-ce51-ad2f-c18c-a2052130e00b@tompassin.net> Message-ID: <7c7354d4-58fd-38e1-1c34-9587be89de83@tompassin.net> On 4/19/2023 4:06 PM, Mark Bourne wrote: >> >> print(f'{LIMIT}) > > ^ I think this one should be: > > print(f'{LIMIT}') > > with the closing quote ;o) Yup a typo! Where's pylint when I need it? From list1 at tompassin.net Wed Apr 19 17:12:04 2023 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 19 Apr 2023 17:12:04 -0400 Subject: Python-pickle error In-Reply-To: References: Message-ID: On 4/19/2023 12:14 PM, charles wiewiora wrote: > Hello, > I am experincing problems with the pickle moducle > the folowing code was working before, > > import pickle > number=2 > my_pickeld_object=pickle.dumps(number) > print("this is my pickled object",{my_pickeld_object},) > with open('file.pkl', 'rb') as file: > number=pickle.load(file) > my_unpickeled_object=pickle.loads(my_pickeld_object) > print("this is my unpickeled object",{my_unpickeled_object},) > > but now i get error > > Traceback (most recent call last): > File "C:\Users\lukwi\Desktop\python\tester2.py", line 5, in > with open('file.pkl', 'rb') as file: > FileNotFoundError: [Errno 2] No such file or directory: 'file.pkl' That's because you haven't saved anything to a file named "file.pkl". If this code seemed to work in the past, it may have been because there was a file named "file.pkl" left over from some previous experiment. But it's not there now, and even if it were it would not contain your current pickled object. Take a look at .load() and .dump() (instead of .loads() and .dumps(). Maybe they will do what you want a little easier. > im get this problem after this, > a .pkl came into my Python script files > i though this could be a spare file made from python becauce i was doing this first, > > import pickle > number=2 > my_pickeld_object=pickle.dumps(number) > print("this is my pickled object",{my_pickeld_object},) > with open('file.pkl', 'rb') as file: > number=pickle.load(file) > > so i stupidly deleted the file > > do you know how to fix this? > i reinstalled it but it didn't work > this is on widnows and on version 3.11.3 on python > > thank you From PythonList at DancesWithMice.info Wed Apr 19 19:19:43 2023 From: PythonList at DancesWithMice.info (dn) Date: Thu, 20 Apr 2023 11:19:43 +1200 Subject: PyCharm's strict PEP and not so strict? In-Reply-To: <692943468.6227351.1681935070220@mail.yahoo.com> References: <2110321349.5908606.1681897884162.ref@mail.yahoo.com> <2110321349.5908606.1681897884162@mail.yahoo.com> <06af8d39-a128-27e6-eeb8-f9e3f8fde7b6@DancesWithMice.info> <692943468.6227351.1681935070220@mail.yahoo.com> Message-ID: <949d6719-a06b-6dcf-9aa5-6d6497c38060@DancesWithMice.info> NB this reply came only to me (so @Alan will have missed your response to his posting). Have replied on-list (only) - please see earlier comment about email-client behaviors... On 20/04/2023 08.11, Kevin M. Wilson wrote: > *What kind of problems are you experiencing with quotes?* > If we have some specific examples we can give specific answers. > > /I have an issue with the 'Light Blub', if I wanted suggestions I'd turn > on that option... Assuming it's an option!/ The "light bulb" has little to do with "quotes"! This is one of the advantages of utilising a Python-native IDE (cf a more general-purpose alternative, perhaps with some Python add-on). PyCharm attempts to understand the code it is editing, and apply various lessons or experiences to offer intelligent assistance. Thus, the "light bulb" is an icon indicating that PyCharm had spotted one or more "intention actions". These may be faults in the code, or may be anticipating what you're about to do and offering to do it for you. A red light-bulb indicates that there is an error in the Python code. Whereas, the yellow color indicates opportunity, aka "a light-bulb moment". Hah! Yes, there are times when the icon overlays and obstructs the code, and thus irritates. I believe it can be turned-off (but don't recommend such to coders at your level of skill). Please read the manual, specifically that page (https://www.jetbrains.com/help/pycharm/intention-actions.html) - there's even an F-string code-example! In this case, PyCharm undoubtedly was picking-up that the string was opened by a single-quote but never closed. One of the useful options PyCharm suggests in this case, is to presume that the string is longer than will fit on one line, and it will 'break' the string for you/us and ensure that the correct punctuation is placed at the beginning and end of each fragment of the string - something many of us find either slightly confusing or a nuisance of 'boiler-plate'. To see what it has noticed, the alternative actions are to mouse-click on the light-bulb, or to type Alt+Enter. Interestingly, the latter is called "Show Context Actions" (but is still talking about "Intentions". The description reads "Quick-fixes for highlighted errors and warnings, intention actions for improving and optimizing your code." (https://www.jetbrains.com/help/pycharm/mastering-keyboard-shortcuts.html) You may have noticed some indicators/statistics at the top-right of the editing panel. Green ticks/check-marks, and amber/yellow or red caution-triangles. These similarly indicate problems PyCharm has noticed, or wisdom from which you may choose to benefit. These come from a feature called "inspection". There are some controls enabling adjustment of "inspection severity" (https://www.jetbrains.com/help/pycharm/configuring-inspection-severities.html) which may be worth the reading-time. However, and once again, changing any cannot be recommended to someone at an early stage of Python-experience. > *Not really. What is the problem. Use of single versus double quotes?is > straightforward - use one or the other and make sure they?match(opening > and closing) You can nest one type inside the > other if you need literal quotes. And of course the same applies?to > triple quotes except you can include newlines inside those.* > * > * > Not stupid typing... Thanks! I use Double quotes, the light blub > suggestions aren't, in many cases, relevant to my > style of coding, nor of 'english'... I'd like to set my options! Sadly this wouldn't help! If you (can) turn-off such warnings in PyCharm, it will simply delay the inevitable - when the code is executed Python will object to the opening of a single-quote and not finding its matching close. ie the issue is NOT with PyCharm (nor with Python) but ... > *PyCharm enables a range of Python-linters. Some by add-in. Some by > "External tools"* > > I was not 'up' on "linters", Thanks for the heads up! Attempted finding > a "linter" on jetbrains... I take it that finding a 'linter' for Build > #PC-222.4554.11, built on March 15, 2023 > Is a matter of hit and miss... Any suggestions? Try a web-search for "Python linters". Linters, I've know a few... (hum along with the music...) have long been a part of the Python eco-system. They have usually been designed to run from Python or 'the command-line'. Accordingly, many can be added into PyCharm from 'the outside'. The original purpose was possibly to guide/nudge coders into the practices recommended by PEP-008 (https://peps.python.org/pep-0008/). This, as you will read, is not about syntax, but more about coding "style". There are many to choose from. Some are more strict than others. Recommendation: (for the good of your blood-pressure) stay away from "highly opinionated" alternatives, such as Black. Try the ones which offer options to turn-on/-off particular situations (as described earlier). > "stones" for bull, how do I set up the kind of "checking" I want? > > That's not a phrase with which I'm familiar but my guess?is you need to > install a linter tool and then, possibly?configure it to flag or hide > particular error/warning types?to your personal taste. Each tool is > different so you?will need to read the docs on how to configure it?(and > how to plumb it into your IDE). > > Sorry, at 67 I use the idioms of many eras! "Stones", 'balls'... Let's try to dispute another old saw - the one about "old dogs"... Then there's "slowly, slowly, catchee..." (but all of these are probably regarded as 'politically incorrect', and anything disrespectful of others transgresses the Python Code of Conduct, so let's park 'the attitude' right there) @Alan is an accomplished author - even if more familiar with British slang, rather than Spanish 'translations'. This list is blessed by contributions from people from all around the globe. Accordingly, there'll be many who are unable to understand your/my aphorisms and allusions. Hence trying to stay with a more 'international English'. > "When you pass through the waters, I will be with you: and when you?pass > through the rivers, they will not sweep over?you. When?you walk?through > the fire, you will not be burned: the flames will not set you ablaze." > *Isaiah 43:2* > > > On Wednesday, April 19, 2023 at 11:39:36 AM MDT, dn via Python-list > wrote: > > > On 20/04/2023 04.25, Alan Gauld wrote: > > On 19/04/2023 10:51, Kevin M. Wilson via Python-list wrote: > >>? ?I'm in a bit of a quandary, I want some strict syntax errors to be > flagged, > > > > OK, You might want to use a "linter" in that case because most > > tools use the interpreter itself to flag syntax errors. > > > > > >>? but the use of single quotes vs double quotes! > >> NOT what I need from the 'checker', you dig? > > > > Not really. What is the problem. Use of single versus double quotes > > is straightforward - use one or the other and make sure they > > match(opening and closing) You can nest one type inside the > > other if you need literal quotes. And of course the same applies > > to triple quotes except you can include newlines inside those. > > > > What kind of problems are you experiencing with quotes? > > If we have some specific examples we can give specific answers. > > > >> "stones" for bull, how do I set up the kind of "checking" I want? > > > > That's not a phrase with which I'm familiar but my guess > > is you need to install a linter tool and then, possibly > > configure it to flag or hide particular error/warning types > > to your personal taste. Each tool is different so you > > will need to read the docs on how to configure it > > (and how to plumb it into your IDE). > > > > Personally I've never felt the need for any stricter error > > checking than the interpreter provides so I can't offer > > anything beyond the generic suggestion to use a linter. > > > +1 > > > PyCharm enables a range of Python-linters. Some by add-in. Some by > "External tools" > (https://www.jetbrains.com/help/pycharm/configuring-third-party-tools.html). > > Once a linter is made-available, some allow one to tune the application > or relaxation of certain 'rules', eg whether commas in a comma-separated > list are to be followed by a space. > > Whether any enable the restriction of quotes use is another matter - > probably for the reasons @Alan has already covered. > > PyCharm auto-magically enters both an opening-quote and a closing-quote > whenever start typing a string. The 'trick' is not to delete the close > whilst editing. > > After gaining experience, I have a convention of when to use apostrophes > and when double-quotes. These old eyes dislike mixing both in a single > expression - but sometimes it is the best course to follow. > > YMMV! > > -- > Regards, > =dn > -- > https://mail.python.org/mailman/listinfo/python-list > > > > Virus-free.www.avg.com > > <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> -- Regards, =dn From PythonList at DancesWithMice.info Wed Apr 19 19:48:30 2023 From: PythonList at DancesWithMice.info (dn) Date: Thu, 20 Apr 2023 11:48:30 +1200 Subject: Pycharm IDE In-Reply-To: <7c7354d4-58fd-38e1-1c34-9587be89de83@tompassin.net> References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> <1155066518.688499.1681881360098@mail.yahoo.com> <1242860619.686995.1681882076134@mail.yahoo.com> <152fb9fa-ce51-ad2f-c18c-a2052130e00b@tompassin.net> <7c7354d4-58fd-38e1-1c34-9587be89de83@tompassin.net> Message-ID: <55435ecb-8e89-bef5-519b-85e27cc4ddf8@DancesWithMice.info> On 20/04/2023 08.59, Thomas Passin wrote: > On 4/19/2023 4:06 PM, Mark Bourne wrote: >>> >>> print(f'{LIMIT}) >> >> ^ I think this one should be: >> >> print(f'{LIMIT}') >> >> with the closing quote ;o) > > Yup a typo!? Where's pylint when I need it? but (and you designed it this way - right?) an excellent object-lesson for the OP AND great rationale for why linters are so handy! I am bullish on F-strings, but they can stretch the typing fingers and strain the eyes. Remember the days when pythonista used to make deprecating remarks about the superiority of Python's syntax because we didn't have 'all those braces' (and other punctuation-characters) cluttering-up the code??? -- Regards, =dn From list1 at tompassin.net Thu Apr 20 08:52:59 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 20 Apr 2023 08:52:59 -0400 Subject: Pycharm IDE In-Reply-To: <55435ecb-8e89-bef5-519b-85e27cc4ddf8@DancesWithMice.info> References: <127255282.580618.1681859937764.ref@mail.yahoo.com> <127255282.580618.1681859937764@mail.yahoo.com> <1155066518.688499.1681881360098@mail.yahoo.com> <1242860619.686995.1681882076134@mail.yahoo.com> <152fb9fa-ce51-ad2f-c18c-a2052130e00b@tompassin.net> <7c7354d4-58fd-38e1-1c34-9587be89de83@tompassin.net> <55435ecb-8e89-bef5-519b-85e27cc4ddf8@DancesWithMice.info> Message-ID: On 4/19/2023 7:48 PM, dn via Python-list wrote: > On 20/04/2023 08.59, Thomas Passin wrote: >> On 4/19/2023 4:06 PM, Mark Bourne wrote: >>>> >>>> print(f'{LIMIT}) >>> >>> ^ I think this one should be: >>> >>> print(f'{LIMIT}') >>> >>> with the closing quote ;o) >> >> Yup a typo!? Where's pylint when I need it? > > but (and you designed it this way - right?) an excellent object-lesson > for the OP > > AND > > great rationale for why linters are so handy! The Leo editor, which I use, checks the file you are working on for syntax errors and also for undefined variables, missing imports, and the like, when you save it. It gives you a clickable link to the line in question. This is a good compromise because it stays out of your way until you take a break by saving. > I am bullish on F-strings, but they can stretch the typing fingers and > strain the eyes. Remember the days when pythonista used to make > deprecating remarks about the superiority of Python's syntax because we > didn't have 'all those braces' (and other punctuation-characters) > cluttering-up the code??? When you get right down for it, there isn't much difference between 'Here is the result: %s, %s' %(a.b, c) and 'Here is the result: {}, {}'.format(a.b, c) Readability and typeability aren't much different. It's only when we get to f-strings that there's a real change, and the second form started to prepare us for it (yes, I know that the .format() form lets you use your own formatter - probably a real advantage though I never had occasion to use it) From list1 at tompassin.net Thu Apr 20 09:04:36 2023 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 20 Apr 2023 09:04:36 -0400 Subject: PyCharm's strict PEP and not so strict? In-Reply-To: <949d6719-a06b-6dcf-9aa5-6d6497c38060@DancesWithMice.info> References: <2110321349.5908606.1681897884162.ref@mail.yahoo.com> <2110321349.5908606.1681897884162@mail.yahoo.com> <06af8d39-a128-27e6-eeb8-f9e3f8fde7b6@DancesWithMice.info> <692943468.6227351.1681935070220@mail.yahoo.com> <949d6719-a06b-6dcf-9aa5-6d6497c38060@DancesWithMice.info> Message-ID: <2568a5a1-44a8-e817-1218-5b17628ed994@tompassin.net> On 4/19/2023 7:19 PM, dn via Python-list wrote: > >> *PyCharm enables a range of Python-linters. Some by add-in. Some by >> "External tools"* >> >> I was not 'up' on "linters", Thanks for the heads up! Attempted >> finding a "linter" on jetbrains... I take it that finding a 'linter' >> for Build #PC-222.4554.11, built on March 15, 2023 >> Is a matter of hit and miss... Any suggestions? > > Try a web-search for "Python linters". Linters, I've know a few... (hum > along with the music...) have long been a part of the Python eco-system. > They have usually been designed to run from Python or 'the > command-line'. Accordingly, many can be added into PyCharm from 'the > outside'. > > The original purpose was possibly to guide/nudge coders into the > practices recommended by PEP-008 (https://peps.python.org/pep-0008/). > This, as you will read, is not about syntax, but more about coding "style". > > There are many to choose from. Some are more strict than others. > Recommendation: (for the good of your blood-pressure) stay away from > "highly opinionated" alternatives, such as Black. Try the ones which > offer options to turn-on/-off particular situations (as described earlier). Be aware that most of these tools can be configured to be more or less fussy, but it's not going to be so easy for the uninitiated. Unconfigured, you will likely see a stream of messages that aren't helpful but may seem overwhelming. Once you have finally gotten one configured to your satisfaction, you probably will not need to change the configuration again for a long time. You can generally disable specific warnings at a point in the code with special comments. Using pylint, for example, perhaps appropriate in view of the OP's original post: # pylint: disable = consider-using-f-string From mats at wichmann.us Thu Apr 20 12:23:49 2023 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 20 Apr 2023 10:23:49 -0600 Subject: PyCharm's strict PEP and not so strict? In-Reply-To: <949d6719-a06b-6dcf-9aa5-6d6497c38060@DancesWithMice.info> References: <2110321349.5908606.1681897884162.ref@mail.yahoo.com> <2110321349.5908606.1681897884162@mail.yahoo.com> <06af8d39-a128-27e6-eeb8-f9e3f8fde7b6@DancesWithMice.info> <692943468.6227351.1681935070220@mail.yahoo.com> <949d6719-a06b-6dcf-9aa5-6d6497c38060@DancesWithMice.info> Message-ID: <07e77bf8-4de8-b2a2-907a-3deaa480bdd8@wichmann.us> On 4/19/23 17:19, dn via Python-list wrote: > The "light bulb" has little to do with "quotes"! This is one of the > advantages of utilising a Python-native IDE (cf a more general-purpose > alternative, perhaps with some Python add-on). PyCharm attempts to > understand the code it is editing, and apply various lessons or > experiences to offer intelligent assistance. To nitpick a little bit, PyCharm isn't *exactly* Python-native, it's a derivative of the IntelliJ generic IDE platform (written in, sigh, Java) with a *very* evolved Python add-on and packaged in such a way as to make it look as if it weren't an addon at all (but if you lift the covers up you can see the roots) Builtin bits are very configurable, usually, but I haven't found that the Python code inspection (this is the stuff that by default gives you the PEP8-type warnings) is particularly so - be happy to stand corrected on that. However, you can configure an external tool - say, pylint - and if you do, you configure that in the normal way (a .pylintrc rcfile, or a toml config file). If you do this, you can turn off those style checks from the builtin checker. If you want. From l.catoni.99 at gmail.com Thu Apr 20 18:44:38 2023 From: l.catoni.99 at gmail.com (Lorenzo Catoni) Date: Fri, 21 Apr 2023 00:44:38 +0200 Subject: Question regarding unexpected behavior in using __enter__ method Message-ID: Dear Python Mailing List members, I am writing to seek your assistance in understanding an unexpected behavior that I encountered while using the __enter__ method. I have provided a code snippet below to illustrate the problem: ``` >>> class X: ... __enter__ = int ... __exit__ = lambda *_: None ... >>> with X() as x: ... pass ... >>> x 0 ``` As you can see, the __enter__ method does not throw any exceptions and returns the output of "int()" correctly. However, one would normally expect the input parameter "self" to be passed to the function. On the other hand, when I implemented a custom function in place of the __enter__ method, I encountered the following TypeError: ``` >>> def myint(*a, **kw): ... return int(*a, **kw) ... >>> class X: ... __enter__ = myint ... __exit__ = lambda *_: None ... >>> with X() as x: ... pass ... Traceback (most recent call last): File "", line 1, in File "", line 2, in myint TypeError: int() argument must be a string, a bytes-like object or a real number, not 'X' ``` Here, the TypeError occurred because "self" was passed as an input parameter to "myint". Can someone explain why this unexpected behavior occurs only in the latter case? I tested this issue on the following Python versions, and the problem persists on all of them: - Python 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] on linux - Python 3.10.10 (main, Feb 8 2023, 14:50:01) [GCC 9.4.0] on linux - Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)] on win32 I appreciate any input or insights that you might have on this matter. Thank you for your help in advance! Best regards, Lorenzo Catoni From PythonList at DancesWithMice.info Thu Apr 20 22:49:49 2023 From: PythonList at DancesWithMice.info (dn) Date: Fri, 21 Apr 2023 14:49:49 +1200 Subject: Question regarding unexpected behavior in using __enter__ method In-Reply-To: References: Message-ID: <0cf986cc-2bc5-8e70-0ecf-bb32b2aadfb9@DancesWithMice.info> On 21/04/2023 10.44, Lorenzo Catoni wrote: > I am writing to seek your assistance in understanding an unexpected > behavior that I encountered while using the __enter__ method. I have > provided a code snippet below to illustrate the problem: It is expected behavior - just not what WE might have expected! >>>> class X: > ... __enter__ = int > ... __exit__ = lambda *_: None > ... >>>> with X() as x: > ... pass > ... >>>> x > 0 Note that what is happening is the creation of an alias for the int built-in function. The docs say: ? class int(x=0) class int(x, base=10) Return an integer object constructed from a number or string x, or return 0 if no arguments are given. If x defines __int__(), int(x) returns x.__int__(). If x defines __index__(), it returns x.__index__(). If x defines __trunc__(), it returns x.__trunc__(). For floating point numbers, this truncates towards zero. ... ? (https://docs.python.org/3/library/functions.html#int) No argument is given. int() delivers as-promised. Hence, the x == 0 result obtained. > As you can see, the __enter__ method does not throw any exceptions and > returns the output of "int()" correctly. However, one would normally expect > the input parameter "self" to be passed to the function. > > On the other hand, when I implemented a custom function in place of the > __enter__ method, I encountered the following TypeError: > > ``` >>>> def myint(*a, **kw): > ... return int(*a, **kw) > ... >>>> class X: > ... __enter__ = myint > ... __exit__ = lambda *_: None > ... >>>> with X() as x: > ... pass > ... > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in myint > TypeError: int() argument must be a string, a bytes-like object or a real > number, not 'X' > ``` > Here, the TypeError occurred because "self" was passed as an input > parameter to "myint". Can someone explain why this unexpected behavior > occurs only in the latter case? > > I tested this issue on the following Python versions, and the problem > persists on all of them: > - Python 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] on linux > - Python 3.10.10 (main, Feb 8 2023, 14:50:01) [GCC 9.4.0] on linux > - Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 > 64 bit (AMD64)] on win32 > > I appreciate any input or insights that you might have on this matter. (you know this next part!) However, if int() is fed an X-object, which in no way represents a numeric or numeric-able value, then it crashes. After the class definition, try: int( X ) => int 0 Right-y-ho: the evidence. Firstly, what happens when int() is called with no argument? print( "int", int(), ) Note that whereas int and myint are both called with no argument(s), and therefore int() defaults to 0, myint is attempting to use the arguments as part of its return-value - "pass-through". As identified, the first argument (the a-tuple's zero-th element) is going to be x's self - which is NOT numeric, stored in a tuple - which is NOT numeric... Thus, if we "shadow" the built-in int() with a user-function, we can see what is being passed-in def int( *a, **kw, ): print( locals(), ) print( "a", a, type( a ), id( a ), ) print( len( a ), a[ 0 ], type( a[ 0 ], ) ) print( "kw", kw, type( kw ), id( kw ), ) return 42 class X: __enter__ = int __exit__ = lambda *_: None with X() as x: pass print( "After first CM", x, "\n\n") del( int ) def myint(*a, **kw): print( locals(), ) print( "a", a, type( a ), id( a ), ) print( len( a ), a[ 0 ], type( a[ 0 ], ) ) print( "kw", kw, type( kw ), id( kw ), ) return int(*a, **kw) class Y: __enter__ = myint __exit__ = lambda *_: None print( Y, type( Y ), id( Y ), ) with Y() as y: print( y, type( y ), id( y ), ) pass print( y ) => {'a': (<__main__.X object at 0x7f9b6bf13b90>,), 'kw': {}} a (<__main__.X object at 0x7f9b6bf13b90>,) 140305733882528 1 <__main__.X object at 0x7f9b6bf13b90> kw {} 140305734120576 After first CM 42 93904023389520 {'a': (<__main__.Y object at 0x7f9b6bf2c0d0>,), 'kw': {}} a (<__main__.Y object at 0x7f9b6bf2c0d0>,) 140305507712640 1 <__main__.Y object at 0x7f9b6bf2c0d0> kw {} 140305507621376 Traceback (most recent call last): File "/home/dn/Projects/analyzer/lorenzo.py", line 53, in with Y() as y: File "/home/dn/Projects/analyzer/lorenzo.py", line 44, in myint return int(*a, **kw) ^^^^^^^^^^^^^ TypeError: int() argument must be a string, a bytes-like object or a real number, not 'Y' If you remover the del() and leave my play-version of int(), Python can make it work... (the second half of the output) 94557671306576 {'a': (<__main__.Y object at 0x7f950ee2c0d0>,), 'kw': {}} a (<__main__.Y object at 0x7f950ee2c0d0>,) 140278176579200 1 <__main__.Y object at 0x7f950ee2c0d0> kw {} 140278176487936 {'a': (<__main__.Y object at 0x7f950ee2c0d0>,), 'kw': {}} a (<__main__.Y object at 0x7f950ee2c0d0>,) 140278176579152 1 <__main__.Y object at 0x7f950ee2c0d0> kw {} 140278176482368 42 140278410201800 42 So, it rather depends upon what you want returned from the actual myint() function. Web.Refs: https://docs.python.org/3/reference/datamodel.html?highlight=context%20manager#with-statement-context-managers https://docs.python.org/3/reference/compound_stmts.html?highlight=context%20manager#the-with-statement I'm curious though, why not: class X: def __enter__( etc def __exit__( etc with the actual code from myint9) as the suite/body of the __enter__()? (in which case, the r?le of self is 'standard operating procedure' and may be more obvious) -- Regards, =dn From cs at cskk.id.au Thu Apr 20 20:25:46 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 21 Apr 2023 10:25:46 +1000 Subject: Question regarding unexpected behavior in using __enter__ method In-Reply-To: References: Message-ID: On 21Apr2023 00:44, Lorenzo Catoni wrote: >I am writing to seek your assistance in understanding an unexpected >behavior that I encountered while using the __enter__ method. I have >provided a code snippet below to illustrate the problem: > >``` >>>> class X: >... __enter__ = int >... __exit__ = lambda *_: None >... >>>> with X() as x: >... pass >... >>>> x >0 >``` >As you can see, the __enter__ method does not throw any exceptions and >returns the output of "int()" correctly. However, one would normally expect >the input parameter "self" to be passed to the function. My descriptor fu is weak, but I believe this is because `int` is not a plain function but a type. Consider this class definition: class X: x = 1 def y(self): return "y" When you define a class, the body of the class is run in a namespace, and on completion, the namespace is _used_ to construct the class. During that process, the various names are considered. Here we've got 2 names: "x" and "y". "x" refers to an int and is just stored as a class attribute, unchanged. "y" refers to a function, and is promoted to a descriptor of an unbound method. So later: X.x return 1 but X.y returns a unbound method. If we make an instance: objx = X() then obj.x returns 1 (by not fining an "x" on "obj", but finding one on "type(obj)" i.e. the class attribute. By contrast, obj.y returns a bound method, a function already curried with a leading parameter "obj" (which will be "self"). There's no "y" attribute directly on "obj" but there's an unbound method on "type(obj).y", which gets bound by saying "obj.y". The means that what happens to a name when you define the class depends on the typeof the value bound to the name. A plain function gets turned into an unbound instance method, but other things are left alone. When you went: __enter__ = int That's not a plain function and so "obj.__enter__" doesn't turn into a bound method - it it just `int`. Cheers, Cameron Simpson From __peter__ at web.de Fri Apr 21 03:41:07 2023 From: __peter__ at web.de (Peter Otten) Date: Fri, 21 Apr 2023 09:41:07 +0200 Subject: Question regarding unexpected behavior in using __enter__ method In-Reply-To: References: Message-ID: <46d0c9cd-cf53-0535-b42e-3ef063f7b9a6@web.de> On 21/04/2023 00:44, Lorenzo Catoni wrote: > Dear Python Mailing List members, > > I am writing to seek your assistance in understanding an unexpected > behavior that I encountered while using the __enter__ method. I have > provided a code snippet below to illustrate the problem: > > ``` >>>> class X: > ... __enter__ = int > ... __exit__ = lambda *_: None > ... >>>> with X() as x: > ... pass > ... >>>> x > 0 > ``` > As you can see, the __enter__ method does not throw any exceptions and > returns the output of "int()" correctly. However, one would normally expect > the input parameter "self" to be passed to the function. > > On the other hand, when I implemented a custom function in place of the > __enter__ method, I encountered the following TypeError: > > ``` >>>> def myint(*a, **kw): > ... return int(*a, **kw) > ... >>>> class X: > ... __enter__ = myint > ... __exit__ = lambda *_: None > ... >>>> with X() as x: > ... pass > ... > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in myint > TypeError: int() argument must be a string, a bytes-like object or a real > number, not 'X' > ``` > Here, the TypeError occurred because "self" was passed as an input > parameter to "myint". Can someone explain why this unexpected behavior > occurs only in the latter case? Cameron is right, it's the descriptor protocol. Technically inst.attr invokes attr.__get__(...) if it exists: >>> class A: def __get__(self, *args): return args >>> class B: pass >>> class X: a = A() b = B() >>> x = X() >>> x.b <__main__.B object at 0x02C2E388> >>> x.a (<__main__.X object at 0x02C2E280>, ) Python functions support the descriptor protocol >>> hasattr(lambda: None, "__get__") True while builtin functions don't: >>> hasattr(ord, "__get__") False I'm unsure whether to regard int as a class or or function, but as there is no __get__ >>> hasattr(int, "__get__") False it behaves like builtin functions in this case. From l.catoni.99 at gmail.com Fri Apr 21 03:46:00 2023 From: l.catoni.99 at gmail.com (Lorenzo Catoni) Date: Fri, 21 Apr 2023 09:46:00 +0200 Subject: Question regarding unexpected behavior in using __enter__ method In-Reply-To: References: Message-ID: Thankyou for your answer, i think i found the reason for this behavior, is has to do with the function being user defined or not, rather than being a plain function or type, as stated here https://docs.python.org/3/reference/datamodel.html#:~:text=Also%20notice%20that%20this%20transformation%20only%20happens%20for%20user%2Ddefined%20functions%3B%20other%20callable%20objects%20(and%20all%20non%2Dcallable%20objects)%20are%20retrieved%20without%20transformation Regards, Lorenzo Catoni On Fri, 21 Apr 2023 at 07:21, Cameron Simpson wrote: > On 21Apr2023 00:44, Lorenzo Catoni wrote: > >I am writing to seek your assistance in understanding an unexpected > >behavior that I encountered while using the __enter__ method. I have > >provided a code snippet below to illustrate the problem: > > > >``` > >>>> class X: > >... __enter__ = int > >... __exit__ = lambda *_: None > >... > >>>> with X() as x: > >... pass > >... > >>>> x > >0 > >``` > >As you can see, the __enter__ method does not throw any exceptions and > >returns the output of "int()" correctly. However, one would normally > expect > >the input parameter "self" to be passed to the function. > > My descriptor fu is weak, but I believe this is because `int` is not a > plain function but a type. > > Consider this class definition: > > class X: > x = 1 > def y(self): > return "y" > > When you define a class, the body of the class is run in a namespace, > and on completion, the namespace is _used_ to construct the class. > During that process, the various names are considered. Here we've got 2 > names: "x" and "y". > > "x" refers to an int and is just stored as a class attribute, unchanged. > > "y" refers to a function, and is promoted to a descriptor of an unbound > method. > > So later: X.x return 1 but X.y returns a unbound method. If we make an > instance: > > objx = X() > > then obj.x returns 1 (by not fining an "x" on "obj", but finding one on > "type(obj)" i.e. the class attribute. > > By contrast, obj.y returns a bound method, a function already curried > with a leading parameter "obj" (which will be "self"). There's no "y" > attribute directly on "obj" but there's an unbound method on > "type(obj).y", which gets bound by saying "obj.y". > > The means that what happens to a name when you define the class depends > on the typeof the value bound to the name. > > A plain function gets turned into an unbound instance method, but other > things are left alone. > > When you went: > > __enter__ = int > > That's not a plain function and so "obj.__enter__" doesn't turn into a > bound method - it it just `int`. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > From simon+python at bleah.co.uk Fri Apr 21 09:19:28 2023 From: simon+python at bleah.co.uk (Simon Ward) Date: Fri, 21 Apr 2023 14:19:28 +0100 Subject: ipaddress (was: Re: for a 'good python') In-Reply-To: References: Message-ID: <20230421131928.GA16196@bleah.co.uk> On Thu, Apr 13, 2023 at 04:00:59PM +0100, Barry wrote: >Ipaddress was developed outside of the std lib and later added i >recall. I used it prior to it being in the standard library: https://pypi.org/project/ipaddr/ Simon -- A complex system that works is invariably found to have evolved from a simple system that works.?John Gall From Ralf_M at t-online.de Thu Apr 20 17:47:01 2023 From: Ralf_M at t-online.de (Ralf M.) Date: Thu, 20 Apr 2023 23:47:01 +0200 Subject: Incomplete sys.path with embeddable python (Windows)!? Message-ID: Hello, when I run a script with a "normally" installed python, the directory the script resides in is automatically added as first element to sys.path, so that "import my_local_module" finds my_local_module.py in the directory of the script. However, when I run the same script with embeddable python ("Windows embeddable package (64-bit)", download link https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) the script directory is *not* prepended to the path, thus "import my_local_module" gives an ImportError. I couldn't find an option to get the "normal" behaviour. Any ideas how to do that? What I tried so far: * The start-up value for sys.path seems to be defined in python311._pth. It looks that I can add further static paths to it, but I don't know how to make it add the script path (which can be different for different scripts). * Uncommenting "import site" in python311._pth doesn't help. * It seems that I could import something else in python311._pth, but I don't know how something imported from there could find out the path of the script that is about to be started. * I read the (rather short) documentation of the embeddable package and of the site module several times but couldn't recognize a hint as to how to solve the issue. * I can add the following lines to every script: import sys script_path = __file__.rsplit("\\", 1)[0] if script_path not in sys.path: sys.path[0:0] = [script_path] import my_local_modul That works, but it's ugly, executing code between imports is frowned upon, and it needs to be added to every script. Does anybody have a better idea? Any help is appreciated. Ralf M. From mats at wichmann.us Fri Apr 21 11:31:40 2023 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 21 Apr 2023 09:31:40 -0600 Subject: Incomplete sys.path with embeddable python (Windows)!? In-Reply-To: References: Message-ID: <5d93e6e2-9c5c-88d8-8616-f778f79fc4ec@wichmann.us> On 4/20/23 15:47, Ralf M. wrote: > Hello, > > when I run a script with a "normally" installed python, the directory > the script resides in is automatically added as first element to > sys.path, so that "import my_local_module" finds my_local_module.py in > the directory of the script. > > However, when I run the same script with embeddable python ("Windows > embeddable package (64-bit)", download link > https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) > the script directory is *not* prepended to the path, thus "import > my_local_module" gives an ImportError. This is intended behavior - the question comes up from time to time. The embeddable distribution is intended to be part of an application, not a general-purpose Python you can call for just anything. There are a bunch of details here, for example: https://github.com/python/cpython/issues/79022 From list1 at tompassin.net Fri Apr 21 12:07:57 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 21 Apr 2023 12:07:57 -0400 Subject: Incomplete sys.path with embeddable python (Windows)!? In-Reply-To: References: Message-ID: On 4/20/2023 5:47 PM, Ralf M. wrote: > Hello, > > when I run a script with a "normally" installed python, the directory > the script resides in is automatically added as first element to > sys.path, so that "import my_local_module" finds my_local_module.py in > the directory of the script. > > However, when I run the same script with embeddable python ("Windows > embeddable package (64-bit)", download link > https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) > the script directory is *not* prepended to the path, thus "import > my_local_module" gives an ImportError. > > I couldn't find an option to get the "normal" behaviour. Any ideas how > to do that? > > What I tried so far: > > * The start-up value for sys.path seems to be defined in python311._pth. > It looks that I can add further static paths to it, but I don't know how > to make it add the script path (which can be different for different > scripts). > > * Uncommenting "import site" in python311._pth doesn't help. > > * It seems that I could import something else in python311._pth, but I > don't know how something imported from there could find out the path of > the script that is about to be started. > > * I read the (rather short) documentation of the embeddable package and > of the site module several times but couldn't recognize a hint as to how > to solve the issue. > > * I can add the following lines to every script: > ??? import sys > ??? script_path = __file__.rsplit("\\", 1)[0] > ??? if script_path not in sys.path: > ??????? sys.path[0:0] = [script_path] > ??? import my_local_modul > That works, but it's ugly, executing code between imports is frowned > upon, and it needs to be added to every script. > > Does anybody have a better idea? > Any help is appreciated. I haven't worked with embeddable python, but here are some possibilities that came to mind, depending on how your system works - 1. If your script is started from the command line, sys.argv[0] gives the path to the script; You could use os.path.dirname() to get its directory. This will end up the same place as your code fragment, but looks nicer and handles different path separators (e.g., Linux vs Windows); 2. You could write a little module that figures out the script's path and import that first in all your scripts. 3. If you know all the directories that your scripts will be in, you could add them all to a xx.pth file (do a search to make sure where to put .pth files for an embeddable case). Not executing code between imports is a guideline, but guidelines are not laws and you can certainly deviate from them if there is a good reason. My preference would be for 1) if at all possible. Something like this (untested) - import sys import os.path script_dir = os.path.dirname(sys.argv[0]) sys.path.insert(0, script_dir) # Use built-in method to insert Inserting the path entry again in case it's already there is not harmful so there's no need to check. If for some reason sys.argv is not available, just substitute __file__. That still won't be too clunky. From grant.b.edwards at gmail.com Fri Apr 21 16:57:45 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 21 Apr 2023 13:57:45 -0700 (PDT) Subject: Is npyscreen still alive? Message-ID: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> I recently googled across the ncurses application framework npyscreen, and was thinking about giving it a try for a small but real project (something that would be distributed to customers), but I'm a bit concerned that npyscreen no longer "alive". The pypi page says the homepage is http://www.npcole.com/npyscreen/, which then points to a Google Code page at https://code.google.com/archive/p/npyscreen/. That page says the official repo is at https://bitbucket.org/npcole/npyscreen which returns a 404. There seems to be a copy in Github at https://github.com/npcole/npyscreen/commits/master, but the last commit was almost 4 years ago. Maybe it "just works" and is suitable for production? From barry at barrys-emacs.org Fri Apr 21 17:57:33 2023 From: barry at barrys-emacs.org (Barry) Date: Fri, 21 Apr 2023 22:57:33 +0100 Subject: Is npyscreen still alive? In-Reply-To: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> References: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> Message-ID: > On 21 Apr 2023, at 22:00, Grant Edwards wrote: > > ?I recently googled across the ncurses application framework npyscreen, > and was thinking about giving it a try for a small but real project > (something that would be distributed to customers), but I'm a bit > concerned that npyscreen no longer "alive". > > The pypi page says the homepage is http://www.npcole.com/npyscreen/, > which then points to a Google Code page at https://code.google.com/archive/p/npyscreen/. > > That page says the official repo is at https://bitbucket.org/npcole/npyscreen > which returns a 404. > > There seems to be a copy in Github at https://github.com/npcole/npyscreen/commits/master, > but the last commit was almost 4 years ago. > > Maybe it "just works" and is suitable for production? Maybe this, recently lwn.net article, https://textual.textualize.io/ I was planning to check it out. Barry > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From list1 at tompassin.net Fri Apr 21 18:51:14 2023 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 21 Apr 2023 18:51:14 -0400 Subject: Is npyscreen still alive? In-Reply-To: References: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> Message-ID: <0a6c2a83-e44b-45e6-fe5b-e78df8b69828@tompassin.net> On 4/21/2023 5:57 PM, Barry wrote: > > >> On 21 Apr 2023, at 22:00, Grant Edwards wrote: >> >> ?I recently googled across the ncurses application framework npyscreen, >> and was thinking about giving it a try for a small but real project >> (something that would be distributed to customers), but I'm a bit >> concerned that npyscreen no longer "alive". >> >> The pypi page says the homepage is http://www.npcole.com/npyscreen/, >> which then points to a Google Code page at https://code.google.com/archive/p/npyscreen/. >> >> That page says the official repo is at https://bitbucket.org/npcole/npyscreen >> which returns a 404. >> >> There seems to be a copy in Github at https://github.com/npcole/npyscreen/commits/master, >> but the last commit was almost 4 years ago. >> >> Maybe it "just works" and is suitable for production? > > Maybe this, recently lwn.net article, https://textual.textualize.io/ > I was planning to check it out. It's still pip-installable from PyPi. From aapost at idontexist.club Thu Apr 20 21:36:18 2023 From: aapost at idontexist.club (aapost) Date: Thu, 20 Apr 2023 21:36:18 -0400 Subject: Question regarding unexpected behavior in using __enter__ method In-Reply-To: References: Message-ID: On 4/20/23 18:44, Lorenzo Catoni wrote: > Here, the TypeError occurred because "self" was passed as an input Instantiate X and observe it there x2 = X() >>> X.__enter__ >>> X.__exit__ at 0x...> >>> x2.__enter__ >>> x2.__exit__ of <__main__.X object at 0x...>> To receive self the method must be bound. __enter__ = int doesn't bind the int type/class on instantiation, so it never gets self. Your custom function binds and receives self. I am not sure if there is documentation to explain better specifically what makes makes type different and not bindable. From info at cmcc.it Fri Apr 21 05:33:16 2023 From: info at cmcc.it (info cmcc) Date: Fri, 21 Apr 2023 11:33:16 +0200 Subject: Deadline Reminder: April 30, 2023 - Software Developer | Job position at CMCC Foundation, Italy In-Reply-To: References: Message-ID: *Software Developer (Research Associate) code 12428* (Deadline: April 30, 2023) The CMCC Foundation is a scientific research center on climate change and its interactions with the environment, the society, the world of business and policy makers. Our work aims to stimulate sustainable growth, protect the environment, and develop strategies for the adaptation and mitigation of climate change. Our Division of Ocean Predictions and Applications (OPA) is looking for new positions of Software Developers, responsible for (i) supporting modelling developments, implementation, and validation, (ii) porting/recoding/re-engineering/developing numerical procedures in the frame of ocean models, and (iii) deployment of applications and services with virtualization software such as Virtual Machines and Dockers. The job location is CMCC Headquarters in Lecce, Italy. We are looking for motivated persons with the following requirements: - M.Sc. degree (or equivalent working experience) in Computer Science, Engineering, or other scientific disciplines (i.e., physics, mathematics); fluency in English; - knowledge of UNIX/Linux operating systems and script languages (i.e., *nix shell); - good knowledge and skills in programming (i.e., Python and bash scripting); - knowledge of version control systems (i.e., git). Furthermore, it is welcome that you have as much as possible of the following experience: - knowledge of workflow management platforms; - knowledge of Fortran; - HPC architectures and job schedulers (i.e., IBM Spectrum LSF); - experience in managing/manipulating NetCDF data. *More details and info about HOW TO APPLY: https://cmccfoundation.applytojob.com/apply/WkA5Dhltc9/12428-Software-Developer-Research-Associate * -- Fondazione CMCCCentro Euro-Mediterraneo sui Cambiamenti Climatici Via Marco Biagi, 5 - 73100 Lecce info at cmcc.it - www.cmcc.it From info at cmcc.it Fri Apr 21 05:49:36 2023 From: info at cmcc.it (info cmcc) Date: Fri, 21 Apr 2023 11:49:36 +0200 Subject: Junior Research Associate in HPC | Job position at CMCC Foundation, Italy In-Reply-To: References: Message-ID: *Junior Research Associate in HPC* *Deadline: May 15, 2023* *The job location is CMCC Headquarters of Lecce* The CMCC Foundation is a scientific research center on climate change and its interactions with the environment, society, the world of business, and policymakers. Our work aims to stimulate sustainable growth, protect the environment and develop strategies for adapting and mitigating climate change. Our Division of Advanced Scientific Computing (ASC) is looking for a new position of Junior Research Associate in HPC, responsible for *supporting research activities in HPC*. The position has been opened within the project *PNRR HPC SPOKE, CUP Number C83C22000560007.* The job location is CMCC Headquarters in *Lecce, Italy. * We are looking for a motivated person with the following requirements: - *M.Sc. degree in Computer Science or Computer Engineering or equivalent fields;* - *3+ years? experience in scientific software development and parallel programming;* - *Excellent knowledge of C and Fortran programming language;* - Parallel programming with MPI of scientific codes for heterogenous HPC architectures; - OpenACC/OpenMP and GPU programming; - Performance analysis of parallel codes; - *Expert with HPC systems;* - Fluent handling of scripting languages like Bash and Python; - Experience in complex software development and software version control systems (e.g. Git); - Knowledge in numerical methods and numerical schemes; - Knowledge in the application of computational fluid dynamics or weather and climate modelling is an asset; - *Good knowledge of both written and spoken English language.* The project promotes female and youth employment and the reduction of territorial gaps according to art. 47 ?promotion of generational and gender equal opportunities for the awarding of public contracts for the implementation of the National Recovery and Resilience Plan (PNRR)?, of the Italian Law Decree no. 77/2021 converted into law no. 108 of 29 July 2021. *More details and info about HOW TO APPLY: * https://cmccfoundation.applytojob.com/apply/qCBuoQihlI/12447-Junior-Research-Associate-In-HPC *-- * Fondazione CMCC Centro Euro-Mediterraneo sui Cambiamenti Climatici Via Augusto Imperatore, 16 - 73100 Lecce info at cmcc.it - www.cmcc.it From greg.ewing at canterbury.ac.nz Fri Apr 21 21:27:49 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 22 Apr 2023 13:27:49 +1200 Subject: Incomplete sys.path with embeddable python (Windows)!? In-Reply-To: References: <5d93e6e2-9c5c-88d8-8616-f778f79fc4ec@wichmann.us> Message-ID: How are you invoking your script? Presumably you have some code in your embedding application that takes a script path and runs it. Instead of putting the code to update sys.path into every script, the embedding application could do it before running the script. -- Greg From Ralf_M at t-online.de Sat Apr 22 17:35:37 2023 From: Ralf_M at t-online.de (Ralf M.) Date: Sat, 22 Apr 2023 23:35:37 +0200 Subject: Incomplete sys.path with embeddable python (Windows)!? In-Reply-To: <5d93e6e2-9c5c-88d8-8616-f778f79fc4ec@wichmann.us> References: <5d93e6e2-9c5c-88d8-8616-f778f79fc4ec@wichmann.us> Message-ID: Am 21.04.2023 um 17:31 schrieb Mats Wichmann: > On 4/20/23 15:47, Ralf M. wrote: >> Hello, >> >> when I run a script with a "normally" installed python, the directory >> the script resides in is automatically added as first element to >> sys.path, so that "import my_local_module" finds my_local_module.py in >> the directory of the script. >> >> However, when I run the same script with embeddable python ("Windows >> embeddable package (64-bit)", download link >> https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) the script directory is *not* prepended to the path, thus "import my_local_module" gives an ImportError. > > This is intended behavior - the question comes up from time to time. The > embeddable distribution is intended to be part of an application, not a > general-purpose Python you can call for just anything. > > There are a bunch of details here, for example: > > https://github.com/python/cpython/issues/79022 > Thank you for the pointer to the issue. I'll try to remove the ._pth completely (and see whether that breaks anything) and may have a look at the nuget.org package. I can see that for many cases the behaviour is appropriate, but I had hoped that there is a configuration option for the cases where it is not. About my use case: There is a complex application package, consisting of some commercial and some freeware software, tied together with scripts in at least four different scripting languages. Now I intend to add further functionality in a fifth language, Python. The idea is to make the embeddedable package part of the application package and have scripts for the new functions. Several independent functions are to be added, each consisting of a script plus some local modules, and all of them should use the same python embedded into the application package. From Ralf_M at t-online.de Sat Apr 22 17:45:11 2023 From: Ralf_M at t-online.de (Ralf M.) Date: Sat, 22 Apr 2023 23:45:11 +0200 Subject: Incomplete sys.path with embeddable python (Windows)!? In-Reply-To: References: <5d93e6e2-9c5c-88d8-8616-f778f79fc4ec@wichmann.us> Message-ID: Am 22.04.2023 um 03:27 schrieb Greg Ewing via Python-list: > How are you invoking your script? Presumably you have some code > in your embedding application that takes a script path and runs > it. Instead of putting the code to update sys.path into every > script, the embedding application could do it before running > the script. > In principle a good idea, but I don't know how to do that: The script is currently invoked by a .cmd file, but that may change to a shortcut (.lnk). This is what the embeddable package documentation calls "Python Application - simple approach". To update sys.path on start up I would need to do something like C:\path\to\python.exe --add-path C:\s-path C:\s-path\script.py but I couldn't find an option like --add-path. From Ralf_M at t-online.de Sat Apr 22 18:04:16 2023 From: Ralf_M at t-online.de (Ralf M.) Date: Sun, 23 Apr 2023 00:04:16 +0200 Subject: Incomplete sys.path with embeddable python (Windows)!? In-Reply-To: References: Message-ID: <3979254c-95fa-935f-e6a4-4756526f1171@t-online.de> Am 21.04.2023 um 18:07 schrieb Thomas Passin: > On 4/20/2023 5:47 PM, Ralf M. wrote: >> Hello, >> >> when I run a script with a "normally" installed python, the directory >> the script resides in is automatically added as first element to >> sys.path, so that "import my_local_module" finds my_local_module.py in >> the directory of the script. >> >> However, when I run the same script with embeddable python ("Windows >> embeddable package (64-bit)", download link >> https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) the script directory is *not* prepended to the path, thus "import my_local_module" gives an ImportError. >> >> I couldn't find an option to get the "normal" behaviour. Any ideas how >> to do that? >> >> What I tried so far: >> [...] >> * I can add the following lines to every script: >> ???? import sys >> ???? script_path = __file__.rsplit("\\", 1)[0] >> ???? if script_path not in sys.path: >> ???????? sys.path[0:0] = [script_path] >> ???? import my_local_modul >> [...] Thank your for your hints. > I haven't worked with embeddable python, but here are some possibilities > that came to mind, depending on how your system works - > > 1. If your script is started from the command line, sys.argv[0] gives > the path to the script; I didn't think of sys.argv[0] to get at the path; this might be quite useful, I'll try it out next week. > You could use os.path.dirname() to get its > directory.? This will end up the same place as your code fragment, but > looks nicer and handles different path separators (e.g., Linux vs Windows); Yes, but it requires another import and the embedded package is only available for windows anyway, I think. I'll consider the idea, though. > 2. You could write a little module that figures out the script's path > and import that first in all your scripts. > > 3. If you know all the directories that your scripts will be in, you > could add them all to a xx.pth file (do a search to make sure where to > put .pth files for an embeddable case). I thought about that, but for that to work all local modules across all script locations must have unique names, otherwise import might get hold of a module from the wrong directory. Certainly doable for a few scripts, but might become a source of hard to track errors when the number of scripts increases and later maintainers are not aware of the naming restriction. > [...} From list1 at tompassin.net Sat Apr 22 18:17:59 2023 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 22 Apr 2023 18:17:59 -0400 Subject: Incomplete sys.path with embeddable python (Windows)!? In-Reply-To: References: <5d93e6e2-9c5c-88d8-8616-f778f79fc4ec@wichmann.us> Message-ID: <9bc10f4c-890a-4c89-2cd2-e505a715c92e@tompassin.net> On 4/22/2023 5:45 PM, Ralf M. wrote: > Am 22.04.2023 um 03:27 schrieb Greg Ewing via Python-list: >> How are you invoking your script? Presumably you have some code >> in your embedding application that takes a script path and runs >> it. Instead of putting the code to update sys.path into every >> script, the embedding application could do it before running >> the script. >> > In principle a good idea, but I don't know how to do that: > The script is currently invoked by a .cmd file, but that may change to a > shortcut (.lnk). This is what the embeddable package documentation calls > "Python Application - simple approach". > To update sys.path on start up I would need to do something like > ? C:\path\to\python.exe --add-path C:\s-path C:\s-path\script.py > but I couldn't find an option like --add-path. You can get the .cmd file's path and put it into an environmental variable (or as a command line argument). If you haven't encountered that trick of Windows batch file procesing, here it is: %~dp0 (returns the directory a batch file is running from) From greg.ewing at canterbury.ac.nz Sat Apr 22 19:49:03 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 23 Apr 2023 11:49:03 +1200 Subject: Incomplete sys.path with embeddable python (Windows)!? In-Reply-To: References: <3979254c-95fa-935f-e6a4-4756526f1171@t-online.de> Message-ID: On 23/04/23 10:04 am, Ralf M. wrote: > I thought about that, but for that to work all local modules across all > script locations must have unique names, otherwise import might get hold > of a module from the wrong directory. You could put all the local modules belonging to a particular script into a package named after the script, e.g. put the local modules used by foo.py into a package called foolib. -- Greg From mats at wichmann.us Sun Apr 23 12:17:26 2023 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 23 Apr 2023 10:17:26 -0600 Subject: Incomplete sys.path with embeddable python (Windows)!? In-Reply-To: <3979254c-95fa-935f-e6a4-4756526f1171@t-online.de> References: <3979254c-95fa-935f-e6a4-4756526f1171@t-online.de> Message-ID: <2e9b9b87-0707-79c8-bb10-47adb35daf32@wichmann.us> On 4/22/23 16:04, Ralf M. wrote: > Am 21.04.2023 um 18:07 schrieb Thomas Passin: >> On 4/20/2023 5:47 PM, Ralf M. wrote: >>> Hello, >>> >>> when I run a script with a "normally" installed python, the directory >>> the script resides in is automatically added as first element to >>> sys.path, so that "import my_local_module" finds my_local_module.py >>> in the directory of the script. >>> >>> However, when I run the same script with embeddable python ("Windows >>> embeddable package (64-bit)", download link >>> https://www.python.org/ftp/python/3.11.3/python-3.11.3-embed-amd64.zip) the script directory is *not* prepended to the path, thus "import my_local_module" gives an ImportError. >>> >>> I couldn't find an option to get the "normal" behaviour. Any ideas >>> how to do that? >>> >>> What I tried so far: >>> [...] >>> * I can add the following lines to every script: >>> ???? import sys >>> ???? script_path = __file__.rsplit("\\", 1)[0] >>> ???? if script_path not in sys.path: >>> ???????? sys.path[0:0] = [script_path] >>> ???? import my_local_modul >>> [...] Have used this stanza (actually, for the inverse purpose, to remove that script's dir from sys.path, but whatever...): script_dir = os.path.dirname(os.path.realpath(__file__)) you can then insert it: sys.path.insert(0, script_dir) or just add: sys.path = [script_dir] + sys.path assuming you want it at the front... but it doesn't really solve your problem of needing it *everywhere*... From torriem at gmail.com Mon Apr 24 09:37:21 2023 From: torriem at gmail.com (Michael Torrie) Date: Mon, 24 Apr 2023 07:37:21 -0600 Subject: Is npyscreen still alive? In-Reply-To: References: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> Message-ID: <5ad249e5-5c11-a30d-106a-e4a5a21abbf4@gmail.com> On 4/21/23 15:57, Barry wrote: > Maybe this, recently lwn.net article, https://textual.textualize.io/ > I was planning to check it out. Textual definitely looks slick and modern. And with a modern terminal emulator it works quite well and is responsive. I'd definitely consider it for a TUI. But on the Linux console, or on an older terminal, not so much. Textual's really designed for smallish unicode fonts in a windowed environment, not any kind of real, old-school text mode. Just something to keep in mind. 99% of terminal users are using a modern terminal emulator these days, with full color and unicode, which is the target of textual. Curses-based programs don't look great on anything, but they do look consistent on more primitive terminals. From grant.b.edwards at gmail.com Mon Apr 24 10:04:22 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 24 Apr 2023 07:04:22 -0700 (PDT) Subject: Is npyscreen still alive? References: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> <5ad249e5-5c11-a30d-106a-e4a5a21abbf4@gmail.com> Message-ID: <64468c66.050a0220.c3e8f.372e@mx.google.com> On 2023-04-24, Michael Torrie wrote: > On 4/21/23 15:57, Barry wrote: > >> Maybe this, recently lwn.net article, >> https://textual.textualize.io/ I was planning to check it out. > > Textual definitely looks slick and modern. And with a modern > terminal emulator it works quite well and is responsive. I'd > definitely consider it for a TUI. > > But on the Linux console, or on an older terminal, not so much. > Textual's really designed for smallish unicode fonts in a windowed > environment, not any kind of real, old-school text mode. Just > something to keep in mind. 99% of terminal users are using a modern > terminal emulator these days, with full color and unicode, which is > the target of textual. Is putty running on Windows a "modern terminal emulator" in this context? After observing some of the local IT types work, I suspect that will be a common use-case for the app I'm working on. > Curses-based programs don't look great on anything, but they do look > consistent on more primitive terminals. The other big advantage of an ncurses program is that since curses support is in the std library, a curses app is simpler to distribute. Right now, the application is a single .py file you just copy to the destination machine and run. It supports command-line use and a Tk GUI. I can add an ncurses "CUI" without having to either adopt a more complex bundling mechanism that requires it to be "installed" or require that users install dependencies via pip/apt/yum/whatever. -- Grant From nospam at please.ty Sun Apr 23 02:38:36 2023 From: nospam at please.ty (jak) Date: Sun, 23 Apr 2023 08:38:36 +0200 Subject: Incomplete sys.path with embeddable python (Windows)!? In-Reply-To: References: <5d93e6e2-9c5c-88d8-8616-f778f79fc4ec@wichmann.us> Message-ID: Ralf M. ha scritto: > Am 22.04.2023 um 03:27 schrieb Greg Ewing via Python-list: >> How are you invoking your script? Presumably you have some code >> in your embedding application that takes a script path and runs >> it. Instead of putting the code to update sys.path into every >> script, the embedding application could do it before running >> the script. >> > In principle a good idea, but I don't know how to do that: > The script is currently invoked by a .cmd file, but that may change to a > shortcut (.lnk). This is what the embeddable package documentation calls > "Python Application - simple approach". > To update sys.path on start up I would need to do something like > ? C:\path\to\python.exe --add-path C:\s-path C:\s-path\script.py > but I couldn't find an option like --add-path. what about: foo.py: from sys import path print('path:', path) #end foo.py from prompt: $ python -c "import sys;sys.path=['/user/foopath']+sys.path;import foo;foo" output: path: ['/user/foopath', '', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/usr/lib/python3.9/site-packages'] From jamesbtobin at gmail.com Mon Apr 24 05:02:58 2023 From: jamesbtobin at gmail.com (James Tobin) Date: Mon, 24 Apr 2023 10:02:58 +0100 Subject: JOB | Linux Platform Engineer (India and Singapore) Message-ID: Hello, i'm working with an employer that is looking to hire a Linux platform engineer for their office in India and Singapore that has experience in automation and management of platform configuration from both an onprem and cloud perspective. Consequently, I had hoped that some members may like to discuss further; off-list. I can be reached using "JamesBTobin (at) Gmail (dot) Com". Kind regards, James From grant.b.edwards at gmail.com Mon Apr 24 12:26:29 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 24 Apr 2023 09:26:29 -0700 (PDT) Subject: Python curses missing form library? Message-ID: <6446adb5.5e0a0220.6fef5.3633@mx.google.com> Does the Python curses support in the standard library not include support for the curses form library? It seems to include support for the panel library, but I can't find any mention of the form library. I see in the docs that menu support is still missing. :/ -- Grant From grant.b.edwards at gmail.com Mon Apr 24 12:32:37 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 24 Apr 2023 09:32:37 -0700 (PDT) Subject: Is npyscreen still alive? References: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> <5ad249e5-5c11-a30d-106a-e4a5a21abbf4@gmail.com> <64468c66.050a0220.c3e8f.372e@mx.google.com> Message-ID: <6446af25.050a0220.ed912.397a@mx.google.com> On 2023-04-24, Grant Edwards wrote: > The other big advantage of an ncurses program is that since curses > support is in the std library, a curses app is simpler to > distribute. Right now, the application is a single .py file you > just copy to the destination machine and run. It supports > command-line use and a Tk GUI. I can add an ncurses "CUI" without > having to either adopt a more complex bundling mechanism that > requires it to be "installed" or require that users install > dependencies via pip/apt/yum/whatever. However... I just realized that Python's curses support is missing two huge chunks: both menu and form support are not there. I guess that explains why people feel the need to write high-level UI wrappers for Python curses: the high level stuff that curses does support is missing from the Python bindings. Adding a curses UI for my app might not be feasible after all... -- Grant From learn2program at gmail.com Mon Apr 24 14:36:51 2023 From: learn2program at gmail.com (Alan Gauld) Date: Mon, 24 Apr 2023 19:36:51 +0100 Subject: Python curses missing form library? In-Reply-To: <6446adb5.5e0a0220.6fef5.3633@mx.google.com> References: <6446adb5.5e0a0220.6fef5.3633@mx.google.com> Message-ID: <97e5f793-7348-7c62-f928-61b54fd3886f@yahoo.co.uk> On 24/04/2023 17:26, Grant Edwards wrote: > Does the Python curses support in the standard library not include > support for the curses form library? It seems to include support for > the panel library, but I can't find any mention of the form library. I don't believe so. If you are building terminal based form-type apps the best bet seems to be urwid. I haven't used it in anger but the beginner docs I saw looked promising. -- 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 mats at wichmann.us Mon Apr 24 14:39:49 2023 From: mats at wichmann.us (Mats Wichmann) Date: Mon, 24 Apr 2023 12:39:49 -0600 Subject: Is npyscreen still alive? In-Reply-To: <6446af25.050a0220.ed912.397a@mx.google.com> References: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> <5ad249e5-5c11-a30d-106a-e4a5a21abbf4@gmail.com> <64468c66.050a0220.c3e8f.372e@mx.google.com> <6446af25.050a0220.ed912.397a@mx.google.com> Message-ID: On 4/24/23 10:32, Grant Edwards wrote: > On 2023-04-24, Grant Edwards wrote: > >> The other big advantage of an ncurses program is that since curses >> support is in the std library, a curses app is simpler to >> distribute. Right now, the application is a single .py file you >> just copy to the destination machine and run. It supports >> command-line use and a Tk GUI. I can add an ncurses "CUI" without >> having to either adopt a more complex bundling mechanism that >> requires it to be "installed" or require that users install >> dependencies via pip/apt/yum/whatever. > > However... I just realized that Python's curses support is missing two > huge chunks: both menu and form support are not there. I guess that > explains why people feel the need to write high-level UI wrappers for > Python curses: the high level stuff that curses does support is > missing from the Python bindings. > > Adding a curses UI for my app might not be feasible after all... > > -- > Grant > I guess it's also worth mentioning that Python curses doesn't work out of the box on Windows - because the actual curses library isn't commonly present on Windows. It's not hard to get hold of builds (check PyPI) but that means it's no longer "standard". From grant.b.edwards at gmail.com Mon Apr 24 14:55:34 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 24 Apr 2023 11:55:34 -0700 (PDT) Subject: Python curses missing form library? References: <6446adb5.5e0a0220.6fef5.3633@mx.google.com> <97e5f793-7348-7c62-f928-61b54fd3886f@yahoo.co.uk> Message-ID: <6446d0a6.050a0220.f74f6.3aeb@mx.google.com> On 2023-04-24, Alan Gauld wrote: > On 24/04/2023 17:26, Grant Edwards wrote: >> Does the Python curses support in the standard library not include >> support for the curses form library? It seems to include support for >> the panel library, but I can't find any mention of the form library. > > I don't believe so. If you are building terminal based form-type > apps the best bet seems to be urwid. I haven't used it in anger > but the beginner docs I saw looked promising. urwid does indeed look nice, but it would require doing the whole bundling and installing thing. I was hoping to avoid that by sticking with stdlib and curses. -- Grant From grant.b.edwards at gmail.com Mon Apr 24 14:59:54 2023 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 24 Apr 2023 11:59:54 -0700 (PDT) Subject: Is npyscreen still alive? References: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> <5ad249e5-5c11-a30d-106a-e4a5a21abbf4@gmail.com> <64468c66.050a0220.c3e8f.372e@mx.google.com> <6446af25.050a0220.ed912.397a@mx.google.com> Message-ID: <6446d1aa.920a0220.3a115.3c0d@mx.google.com> On 2023-04-24, Mats Wichmann wrote: > On 4/24/23 10:32, Grant Edwards wrote: > >> However... I just realized that Python's curses support is missing two >> huge chunks: both menu and form support are not there. I guess that >> explains why people feel the need to write high-level UI wrappers for >> Python curses: the high level stuff that curses does support is >> missing from the Python bindings. >> >> Adding a curses UI for my app might not be feasible after all... > > I guess it's also worth mentioning that Python curses doesn't work out > of the box on Windows - because the actual curses library isn't commonly > present on Windows. It's not hard to get hold of builds (check PyPI) but > that means it's no longer "standard". That's a good point. I neglected to mention that the use case for curses UI app is to run on headless Linux servers. It needs to work when run on a Linux by a user logged in via Putty on Windows, but I have no need to execute the application in curses-mode on Windows. -- Grant From torriem at gmail.com Mon Apr 24 15:17:03 2023 From: torriem at gmail.com (Michael Torrie) Date: Mon, 24 Apr 2023 13:17:03 -0600 Subject: Is npyscreen still alive? In-Reply-To: <64468c66.050a0220.c3e8f.372e@mx.google.com> References: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> <5ad249e5-5c11-a30d-106a-e4a5a21abbf4@gmail.com> <64468c66.050a0220.c3e8f.372e@mx.google.com> Message-ID: <678d716f-557d-2f05-c5e7-451797a9a35a@gmail.com> On 4/24/23 08:04, Grant Edwards wrote: > Is putty running on Windows a "modern terminal emulator" in this > context? After observing some of the local IT types work, I suspect > that will be a common use-case for the app I'm working on. Yes, Putty qualifies as a "modern terminal emulator." It supports UTF-8 and unicode fonts. And the mouse events work as well. The only catch is the default font is courier new which seems to not have some of the line drawing characters in it. But if I change to something like Cascadia Code it looks very good. From info at tundraware.com Mon Apr 24 19:10:56 2023 From: info at tundraware.com (Tim Daneliuk) Date: Mon, 24 Apr 2023 18:10:56 -0500 Subject: Is npyscreen still alive? In-Reply-To: References: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> <5ad249e5-5c11-a30d-106a-e4a5a21abbf4@gmail.com> <64468c66.050a0220.c3e8f.372e@mx.google.com> Message-ID: <0tejhj-9uq2.ln1@oceanview.tundraware.com> On 4/24/23 09:14, Stefan Ram wrote: > Grant Edwards writes: >> The other big advantage of an ncurses program is that since curses >> support is in the std library, a curses app is simpler to distribute. > > IIRC curses is not in the standard library /on Windows/. I miss > a platform independent (well, at least for Linux, Mac, and > Windows) package with curses features in the standard library. > > That's correct (or was, last time I looked). For this reason, I resorted to using tkinter for the twander file browser. While it works, the code needs a complete rethink and to be written to be Python3 compatible. Perhaps when/if that happens, something like Textual need serious consideration. tkinter works, but is showing its age. So a fresher look without all the burden of X and or requiring a browser, while also giving you that option is appealing. From info at tundraware.com Mon Apr 24 19:13:08 2023 From: info at tundraware.com (Tim Daneliuk) Date: Mon, 24 Apr 2023 18:13:08 -0500 Subject: Is npyscreen still alive? In-Reply-To: References: <6442f8c9.050a0220.3ed35.17c6@mx.google.com> <5ad249e5-5c11-a30d-106a-e4a5a21abbf4@gmail.com> <64468c66.050a0220.c3e8f.372e@mx.google.com> <6446af25.050a0220.ed912.397a@mx.google.com> Message-ID: <8f7af4f4-6843-8449-cd6a-fd1c0d294646@tundraware.com> On 4/24/23 11:32, Grant Edwards wrote: > On 2023-04-24, Grant Edwards wrote: > >> The other big advantage of an ncurses program is that since curses >> support is in the std library, a curses app is simpler to >> distribute. Right now, the application is a single .py file you >> just copy to the destination machine and run. It supports >> command-line use and a Tk GUI. I can add an ncurses "CUI" without >> having to either adopt a more complex bundling mechanism that >> requires it to be "installed" or require that users install >> dependencies via pip/apt/yum/whatever. > > However... I just realized that Python's curses support is missing two > huge chunks: both menu and form support are not there. I guess that > explains why people feel the need to write high-level UI wrappers for > Python curses: the high level stuff that curses does support is > missing from the Python bindings. > > Adding a curses UI for my app might not be feasible after all... > > -- > Grant > That's because the Gods Of Ancient Internets knew that all you ever really need is VT220 escape sequences ... unless you are one of the heathens that still program in HLLAPI on 327x machinery .... (I kid, I kid, NO one needs that pain ...) From rob.cliffe at btinternet.com Sat Apr 22 09:56:02 2023 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Sat, 22 Apr 2023 14:56:02 +0100 Subject: Question regarding unexpected behavior in using __enter__ method In-Reply-To: References: Message-ID: <70c4ee88-a9c5-a7d9-7404-aae558ccbda7@btinternet.com> This puzzled me at first, but I think others have nailed it.? It is not to do with the 'with' statement, but with the way functions are defined. When a class is instantiated, as in x=X(): ??? the instance object gets (at least in effect), as attributes, copies of functions defined *in the class* (using def or lambda) but they become "bound methods", i.e. bound to the instance.? Whenever they are called, they will be called with the instance as the first argument, aka self: ??? class X(object): ??? ??? def func(*args, **kargs): pass ??? x = X() ??? y = () x.func and y.func are two *different" functions.? When x.func is called, x is added as the first argument.? When y.func is called. y is added as the first argument. ???? boundFunc = y.func ??? boundFunc() # Adds y as first argument. Indeed, these functions have an attribute called __self__ whose value is ... you guessed it ... the object they are bound to When a function is defined outside of a class, it remains a simple function, not bound to any object.? It does not have a __self__ attribute.? Neither does a built-in type such as 'int'. Nor for that matter does the class function X.func: ??? X.func() # Called with no arguments Best wishes Rob Cliffe On 20/04/2023 23:44, Lorenzo Catoni wrote: > Dear Python Mailing List members, > > I am writing to seek your assistance in understanding an unexpected > behavior that I encountered while using the __enter__ method. I have > provided a code snippet below to illustrate the problem: > > ``` >>>> class X: > ... __enter__ = int > ... __exit__ = lambda *_: None > ... >>>> with X() as x: > ... pass > ... >>>> x > 0 > ``` > As you can see, the __enter__ method does not throw any exceptions and > returns the output of "int()" correctly. However, one would normally expect > the input parameter "self" to be passed to the function. > > On the other hand, when I implemented a custom function in place of the > __enter__ method, I encountered the following TypeError: > > ``` >>>> def myint(*a, **kw): > ... return int(*a, **kw) > ... >>>> class X: > ... __enter__ = myint > ... __exit__ = lambda *_: None > ... >>>> with X() as x: > ... pass > ... > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in myint > TypeError: int() argument must be a string, a bytes-like object or a real > number, not 'X' > ``` > Here, the TypeError occurred because "self" was passed as an input > parameter to "myint". Can someone explain why this unexpected behavior > occurs only in the latter case? > > I tested this issue on the following Python versions, and the problem > persists on all of them: > - Python 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] on linux > - Python 3.10.10 (main, Feb 8 2023, 14:50:01) [GCC 9.4.0] on linux > - Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 > 64 bit (AMD64)] on win32 > > I appreciate any input or insights that you might have on this matter. > > Thank you for your help in advance! > > Best regards, > Lorenzo Catoni From avi.e.gross at gmail.com Tue Apr 25 23:47:06 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Tue, 25 Apr 2023 23:47:06 -0400 Subject: Question regarding unexpected behavior in using __enter__ method In-Reply-To: <70c4ee88-a9c5-a7d9-7404-aae558ccbda7@btinternet.com> References: <70c4ee88-a9c5-a7d9-7404-aae558ccbda7@btinternet.com> Message-ID: <008f01d977f1$c56eb1d0$504c1570$@gmail.com> I think you got that right, Rob. A method created in a class is normally expected to care about the class in the sense that it often wants to access internal aspects and is given a "this" or "self" or whatever name you choose as a first argument. As noted, it is sometimes possible to create a function attached not to an object but to the class itself as in, I think, the math class that is not normally instantiated as an object but lets you use things like math.pi and math.cos() and so on. A comment on dunder methods in python is that they have a sort of purpose albeit you can hijack some to do other things. The protocol for WITH is a bit slippery as __enter__() and __exit__ are expected to do some abstract things that loosely are intended to set up something at the start in a way that will be (guaranteed) to be done if the exit routine is called when done. This can be about opening a file, or network connection and later closing it, or setting up some data structure and freeing the memory at the end, but it could be ANYTHING you feel like. For example, it can turn logging of some kind on and off and also compress the log file at the end. Or it could set up changes to the object that are there for the duration of the WITH and then reset the changes back at the end. An imaginary example might be to start caching what some methods are doing or replace a method by another, then empty the cache at the end or put back the redirected one. And if what you want done at the beginning or end is outside the object being worked on, fine. Consider wrapping your function call in a simple function that calls the one you want after ignoring or removing the first argument. There are decorators that can do things like that. So if you want int() or some existing plain non-member function, define an f() whose body calls int() with all arguments passed along other than the first. I just wrote and tested a trivial example where for some reason you just want to call sum() either with an iterable argument or with a second unnamed or named argument that specified a start you can add to. If this is written as a class method, it would have a first argument of "self" to ignore so I simulate that here: def plusone(first, *rest, **named): return(sum(*rest, **named)) If you call this as below with valid arguments, it sort of swallows the first argument and passes the rest along: >>> plusone("ignore", []) 0 >>> plusone("ignore", [1,2,3]) 6 >>> plusone("ignore", [1,2,3], 100) 106 >>> plusone("ignore", range(7), start=100) 121 Yes, anything like this adds overhead. It does add flexibility and allows you to hijack the WITH protocol to do other things perhaps never anticipated but that may make sense, such as changing a companion object rather than the current one. But you need to live within some rules to do things and that means knowing there will be a first argument. Avi -----Original Message----- From: Python-list On Behalf Of Rob Cliffe via Python-list Sent: Saturday, April 22, 2023 9:56 AM To: Lorenzo Catoni ; python-list at python.org Subject: Re: Question regarding unexpected behavior in using __enter__ method This puzzled me at first, but I think others have nailed it. It is not to do with the 'with' statement, but with the way functions are defined. When a class is instantiated, as in x=X(): the instance object gets (at least in effect), as attributes, copies of functions defined *in the class* (using def or lambda) but they become "bound methods", i.e. bound to the instance. Whenever they are called, they will be called with the instance as the first argument, aka self: class X(object): def func(*args, **kargs): pass x = X() y = () x.func and y.func are two *different" functions. When x.func is called, x is added as the first argument. When y.func is called. y is added as the first argument. boundFunc = y.func boundFunc() # Adds y as first argument. Indeed, these functions have an attribute called __self__ whose value is ... you guessed it ... the object they are bound to When a function is defined outside of a class, it remains a simple function, not bound to any object. It does not have a __self__ attribute. Neither does a built-in type such as 'int'. Nor for that matter does the class function X.func: X.func() # Called with no arguments Best wishes Rob Cliffe On 20/04/2023 23:44, Lorenzo Catoni wrote: > Dear Python Mailing List members, > > I am writing to seek your assistance in understanding an unexpected > behavior that I encountered while using the __enter__ method. I have > provided a code snippet below to illustrate the problem: > > ``` >>>> class X: > ... __enter__ = int > ... __exit__ = lambda *_: None > ... >>>> with X() as x: > ... pass > ... >>>> x > 0 > ``` > As you can see, the __enter__ method does not throw any exceptions and > returns the output of "int()" correctly. However, one would normally expect > the input parameter "self" to be passed to the function. > > On the other hand, when I implemented a custom function in place of the > __enter__ method, I encountered the following TypeError: > > ``` >>>> def myint(*a, **kw): > ... return int(*a, **kw) > ... >>>> class X: > ... __enter__ = myint > ... __exit__ = lambda *_: None > ... >>>> with X() as x: > ... pass > ... > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in myint > TypeError: int() argument must be a string, a bytes-like object or a real > number, not 'X' > ``` > Here, the TypeError occurred because "self" was passed as an input > parameter to "myint". Can someone explain why this unexpected behavior > occurs only in the latter case? > > I tested this issue on the following Python versions, and the problem > persists on all of them: > - Python 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] on linux > - Python 3.10.10 (main, Feb 8 2023, 14:50:01) [GCC 9.4.0] on linux > - Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 > 64 bit (AMD64)] on win32 > > I appreciate any input or insights that you might have on this matter. > > Thank you for your help in advance! > > Best regards, > Lorenzo Catoni -- https://mail.python.org/mailman/listinfo/python-list From nntp.mbourne at spamgourmet.com Wed Apr 26 15:41:50 2023 From: nntp.mbourne at spamgourmet.com (Mark Bourne) Date: Wed, 26 Apr 2023 20:41:50 +0100 Subject: Question regarding unexpected behavior in using __enter__ method In-Reply-To: References: Message-ID: Lorenzo Catoni wrote: > Dear Python Mailing List members, > > I am writing to seek your assistance in understanding an unexpected > behavior that I encountered while using the __enter__ method. I have > provided a code snippet below to illustrate the problem: > > ``` >>>> class X: > ... __enter__ = int > ... __exit__ = lambda *_: None > ... >>>> with X() as x: > ... pass > ... >>>> x > 0 > ``` > As you can see, the __enter__ method does not throw any exceptions and > returns the output of "int()" correctly. However, one would normally expect > the input parameter "self" to be passed to the function. > > On the other hand, when I implemented a custom function in place of the > __enter__ method, I encountered the following TypeError: > > ``` >>>> def myint(*a, **kw): > ... return int(*a, **kw) > ... >>>> class X: > ... __enter__ = myint > ... __exit__ = lambda *_: None > ... >>>> with X() as x: > ... pass > ... > Traceback (most recent call last): > File "", line 1, in > File "", line 2, in myint > TypeError: int() argument must be a string, a bytes-like object or a real > number, not 'X' > ``` > Here, the TypeError occurred because "self" was passed as an input > parameter to "myint". Can someone explain why this unexpected behavior > occurs only in the latter case? > > I tested this issue on the following Python versions, and the problem > persists on all of them: > - Python 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] on linux > - Python 3.10.10 (main, Feb 8 2023, 14:50:01) [GCC 9.4.0] on linux > - Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep 5 2022, 14:08:36) [MSC v.1933 > 64 bit (AMD64)] on win32 > > I appreciate any input or insights that you might have on this matter. > > Thank you for your help in advance! Aside from other explanations and suggestions, the following definition of X also works: class X: __enter__ = staticmethod(myint) __exit__ = lambda *_: None Wrapping `myint` in a call to `staticmethod` is the same as using `@staticmethod` as a decorator on a method within the class, so the `self` parameter doesn't get passed. Equivalent to: class X: @staticmethod def __enter__(*a, **kw): return int(*a, **kw) __exit__ = lambda *_: None Which in turn is just a neater way of doing: class X: def __enter__(*a, **kw): return int(*a, **kw) __enter__ = staticmethod(__enter__) __exit__ = lambda *_: None Those equivalents are a bit pointless, since no arguments will be passed into `__enter__` anyway in normal usage, but perhaps make it a bit clearer that the second example behaves as would be expected for a method of X (where the instance is passed as the first argument), and that it's the first example (with `__enter__ = int`) that should be a bit more surprising. (I'm not sure there's much practical use for the original `__enter__ = int` either, but presumably that's just used as a cut-down demonstration). -- Mark. From fungus at amongus.com Wed Apr 26 20:31:10 2023 From: fungus at amongus.com (Retrograde) Date: Wed, 26 Apr 2023 20:31:10 -0400 Subject: replacement for nntplib on Python3 Message-ID: <20230426203110.fb1a0de75df0296488b16381@amongus.com> I used to use a script that relied on nntplib, which is currently still available in Python3 but scheduled for deprecation in the near future. What would be a suitable replacement? -- Retrograde From skip.montanaro at gmail.com Wed Apr 26 21:56:09 2023 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 26 Apr 2023 20:56:09 -0500 Subject: replacement for nntplib on Python3 In-Reply-To: <20230426203110.fb1a0de75df0296488b16381@amongus.com> References: <20230426203110.fb1a0de75df0296488b16381@amongus.com> Message-ID: You could create a git repo with just nntplib and generate a package on PyPI, then use that when running a version of Python which lacks nntplib. Skip On Wed, Apr 26, 2023, 8:42 PM Retrograde wrote: > I used to use a script that relied on nntplib, which is currently still > available in Python3 but scheduled for deprecation in the near future. > What would be a suitable replacement? > > -- > Retrograde > -- > https://mail.python.org/mailman/listinfo/python-list > From pozzugno at gmail.com Fri Apr 28 06:31:36 2023 From: pozzugno at gmail.com (pozz) Date: Fri, 28 Apr 2023 12:31:36 +0200 Subject: Multithreading? How? Message-ID: I need to develop a Python application that is a sort of gateway between to networks: a "serial bus" network (think of a serial port or a USB connection) and a MQTT connection (in my case, it's AWS IoT service). On the bus, a proprietary protocol is implemented. From the bus, the app knows the status of the system (think of a simple ON/OFF status). The user can retrieve the status of the system through MQTT: it sends a message to read/status MQTT topic and receive back a message with the current status on read/status/reply MQTT topic. Of course, they are just examples. On the contrary, when the app detects a status change reported from the serial bus (think of a transition from ON to OFF), it sends a MQTT message. I'm thinking to split the application in three classes: Bus, App and IoT. Bus and IoT are also threads. The thread of Bus manages the serial protocol, while the thread of IoT manages MQTT connection with the broker (the server). However I don't know if it could be a good architecture. Suppone Bus thread receives a new status from the system. In the context of ThreadBus, the object Bus could call a method of App object: app.set_status(new_status_from_the_bus) In the App I have: class App(): .. def set_status(new_status): # Could be called from ThreadBus if new_status != self.new_status: self.new_status = new_status # Do some actions on status change def get_status(): # Could be called from ThreadIoT return self.status Of course, IoT object needs to know the current status of the system when a message is received from MQTT. So ThreadIoT could call app.get_status(). I think this architecture has some problems with race conditions or threads synchronization. What happens if IoT calls get_status() exactly when set_status() called by ThreadBus is executing? If status is a big data structure, set_status() could be interrupted by get_status() that could get a completely corrupted status, because it was only partly updated by set_status(). I know I can use locks or semaphores in get_status() and set_status(), but I don't know if this is a good approach. Consider that the system is complex, it isn't composed by a simple single status. It has many many parameters that are collected from the serial bus. Should I use a lock for every [get|set]_status(), [get|set]_dimensions(), [get|set]_battery_level(), [get|set]_mains_present(), and so on? Another possibility is to use a Queue for Bus and a Queue for IoT. So the set_status(new_status) called from Bus object will be transformed in a put in the queue: app_queue.put({"type": "new_status", "data": ...}) However how could be transformed the get_status() from IoT? How the return value (the current status) is real retrieved? class IoT(): .. def status_request_from_MQTT(): app_queue.put({"type": "get_status"}) # How to get the status to return? return current_status Should the app put the status on the same queue and should IoT waits for a new message in the Queue? def status_request_from_MQTT(): app_queue.put({"type": "get_status"}) try: current_status = app_queue.get(timeout=10) except Empty: # What to do? return current_status Again another approach is to avoid multi-threading at all and create a single "main loop" function that waits at the same time for incoming events on the serial bus and MQTT (how?). I don't know if this could be done in my case, because I'm using awscrt Python module and it works through callbacks that I think is called from another thread. Any suggestions on this architecture? From cl at isbd.net Fri Apr 28 11:55:41 2023 From: cl at isbd.net (Chris Green) Date: Fri, 28 Apr 2023 16:55:41 +0100 Subject: How to 'ignore' an error in Python? Message-ID: I'm sure I'm missing something obvious here but I can't see an elegant way to do this. I want to create a directory, but if it exists it's not an error and the code should just continue. So, I have:- for dirname in listofdirs: try: os.mkdir(dirname) except FileExistsError: # so what can I do here that says 'carry on regardless' except: # handle any other error, which is really an error # I want code here to execute whether or not dirname exists Do I really have to use a finally: block? It feels rather clumsy. I suppose I could test if the directory exists before the os.mkdir() but again that feels a bit clumsy somehow. I suppose also I could use os.mkdirs() with exist_ok=True but again that feels vaguely wrong somehow. -- Chris Green ? From mats at wichmann.us Fri Apr 28 12:39:36 2023 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 28 Apr 2023 10:39:36 -0600 Subject: How to 'ignore' an error in Python? In-Reply-To: References: Message-ID: <606727f8-70a5-e8a6-c664-f539d9f82567@wichmann.us> On 4/28/23 09:55, Chris Green wrote: > I'm sure I'm missing something obvious here but I can't see an elegant > way to do this. I want to create a directory, but if it exists it's > not an error and the code should just continue. > > So, I have:- > > for dirname in listofdirs: > try: > os.mkdir(dirname) > except FileExistsError: > # so what can I do here that says 'carry on regardless' > except: > # handle any other error, which is really an error > > # I want code here to execute whether or not dirname exists > > > Do I really have to use a finally: block? It feels rather clumsy. For this specific case, you can use os.makedirs: os.makedirs(dirname, exist_ok=True) The mkdir in pathlib also takes the exist_ok flag As to the way you asked the question, you can use "pass" or the ellipses for the "# so what can I do here" From python at mrabarnett.plus.com Fri Apr 28 13:05:23 2023 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 28 Apr 2023 18:05:23 +0100 Subject: How to 'ignore' an error in Python? In-Reply-To: References: Message-ID: <02181fec-dcd3-abdf-d1dd-648e6c74c78e@mrabarnett.plus.com> On 2023-04-28 16:55, Chris Green wrote: > I'm sure I'm missing something obvious here but I can't see an elegant > way to do this. I want to create a directory, but if it exists it's > not an error and the code should just continue. > > So, I have:- > > for dirname in listofdirs: > try: > os.mkdir(dirname) > except FileExistsError: > # so what can I do here that says 'carry on regardless' > except: > # handle any other error, which is really an error > > # I want code here to execute whether or not dirname exists > > > Do I really have to use a finally: block? It feels rather clumsy. > > I suppose I could test if the directory exists before the os.mkdir() > but again that feels a bit clumsy somehow. > > I suppose also I could use os.mkdirs() with exist_ok=True but again > that feels vaguely wrong somehow. > I'd do this: from contextlib import suppress for dirname in listofdirs: with suppress(FileExistsError): os.mkdir(dirname) From mats at wichmann.us Fri Apr 28 13:40:53 2023 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 28 Apr 2023 11:40:53 -0600 Subject: How to 'ignore' an error in Python? In-Reply-To: <02181fec-dcd3-abdf-d1dd-648e6c74c78e@mrabarnett.plus.com> References: <02181fec-dcd3-abdf-d1dd-648e6c74c78e@mrabarnett.plus.com> Message-ID: On 4/28/23 11:05, MRAB wrote: > On 2023-04-28 16:55, Chris Green wrote: >> I'm sure I'm missing something obvious here but I can't see an elegant >> way to do this.? I want to create a directory, but if it exists it's >> not an error and the code should just continue. >> >> So, I have:- >> >> ???? for dirname in listofdirs: >> ???????? try: >> ???????????? os.mkdir(dirname) >> ???????? except FileExistsError: >> ???????????? # so what can I do here that says 'carry on regardless' >> ???????? except: >> ???????????? # handle any other error, which is really an error > I'd do this: > > ??? from contextlib import suppress > > ??? for dirname in listofdirs: > ??????? with suppress(FileExistsError): > ??????????? os.mkdir(dirname) I'm fond of that approach too, though you can't use if it you really wanted to do the except: # handle any other error, which is really an error If you're okay letting Python just raise whatever other error it found, then great! From cs at cskk.id.au Fri Apr 28 21:36:07 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 29 Apr 2023 11:36:07 +1000 Subject: How to 'ignore' an error in Python? In-Reply-To: References: Message-ID: On 28Apr2023 16:55, Chris Green wrote: > for dirname in listofdirs: > try: > os.mkdir(dirname) > except FileExistsError: > # so what can I do here that says 'carry on regardless' > except: > # handle any other error, which is really an error > > # I want code here to execute whether or not dirname exists > >Do I really have to use a finally: block? It feels rather clumsy. You don't. Provided the "handle any other error" part reraises or does a break/continue, so as to skip the bottom of the loop body. ok = true for dirname in listofdirs: try: os.mkdir(dirname) except FileExistsError: pass except Exception as e: warning("mkdir(%r): %s", dirname, e) ok = False continue rest of the loop body ... if not ok: ... not all directories made ... 2 notes on the above: - catching Exception, not a bare except (which catches a rather broader suit of things) - reporting the other exception Cheers, Cameron Simpson From cs at cskk.id.au Fri Apr 28 21:32:52 2023 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 29 Apr 2023 11:32:52 +1000 Subject: How to 'ignore' an error in Python? In-Reply-To: <606727f8-70a5-e8a6-c664-f539d9f82567@wichmann.us> References: <606727f8-70a5-e8a6-c664-f539d9f82567@wichmann.us> Message-ID: On 28Apr2023 10:39, Mats Wichmann wrote: >For this specific case, you can use os.makedirs: >os.makedirs(dirname, exist_ok=True) I'm not a great fan of makedirs because it will make all the missing components, not just the final one. So as an example, if you've got a NAS mounted backup area at eg: /mnt/nas/backups/the-thing/backups-subdir and your config file has this mistyped as: /mn/nas/backups/the-thing/backups-subdir and makedirs is used, then it will make the backup area on eg the root drive where there's no room. (I'm looking at you, Docker, grr). There are plenty of similar situations. Because of this I usually am prepared to make a missing final component with mkdir(), but not a potentially deep path with makedirs(). Cheers, Cameron Simpson From kushal at locationd.net Sat Apr 29 00:18:45 2023 From: kushal at locationd.net (Kushal Kumaran) Date: Fri, 28 Apr 2023 21:18:45 -0700 Subject: How to 'ignore' an error in Python? In-Reply-To: (Chris Green's message of "Fri, 28 Apr 2023 16:55:41 +0100") References: Message-ID: <874joznwwq.fsf@copper.locationd.net> On Fri, Apr 28 2023 at 04:55:41 PM, Chris Green wrote: > I'm sure I'm missing something obvious here but I can't see an elegant > way to do this. I want to create a directory, but if it exists it's > not an error and the code should just continue. > > So, I have:- > > for dirname in listofdirs: > try: > os.mkdir(dirname) > except FileExistsError: > # so what can I do here that says 'carry on regardless' > except: > # handle any other error, which is really an error > > # I want code here to execute whether or not dirname exists > > > Do I really have to use a finally: block? It feels rather clumsy. > > I suppose I could test if the directory exists before the os.mkdir() > but again that feels a bit clumsy somehow. > > I suppose also I could use os.mkdirs() with exist_ok=True but again > that feels vaguely wrong somehow. > Why does exist_ok=True feel wrong to you? This is exactly what it is there for. -- regards, kushal From rosuav at gmail.com Sat Apr 29 00:33:48 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Apr 2023 14:33:48 +1000 Subject: How to 'ignore' an error in Python? In-Reply-To: <874joznwwq.fsf@copper.locationd.net> References: <874joznwwq.fsf@copper.locationd.net> Message-ID: On Sat, 29 Apr 2023 at 14:27, Kushal Kumaran wrote: > > On Fri, Apr 28 2023 at 04:55:41 PM, Chris Green wrote: > > I'm sure I'm missing something obvious here but I can't see an elegant > > way to do this. I want to create a directory, but if it exists it's > > not an error and the code should just continue. > > > > So, I have:- > > > > for dirname in listofdirs: > > try: > > os.mkdir(dirname) > > except FileExistsError: > > # so what can I do here that says 'carry on regardless' > > except: > > # handle any other error, which is really an error > > > > # I want code here to execute whether or not dirname exists > > > > > > Do I really have to use a finally: block? It feels rather clumsy. > > > > I suppose I could test if the directory exists before the os.mkdir() > > but again that feels a bit clumsy somehow. > > > > I suppose also I could use os.mkdirs() with exist_ok=True but again > > that feels vaguely wrong somehow. > > > > Why does exist_ok=True feel wrong to you? This is exactly what it is > there for. > Using mkdirs when you only want to make one is inviting problems of being subtly wrong, where it creates too many levels of directory. Personally, I would just do: try: os.mkdir(dirname) except FileExistsError: pass and not try to handle anything else at all. ChrisA From avi.e.gross at gmail.com Sat Apr 29 13:41:41 2023 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 29 Apr 2023 13:41:41 -0400 Subject: How to 'ignore' an error in Python? In-Reply-To: <874joznwwq.fsf@copper.locationd.net> References: <874joznwwq.fsf@copper.locationd.net> Message-ID: <006301d97ac1$dbc30c10$93492430$@gmail.com> I get a tad suspicious when someone keeps telling us every offered solution does not feel right. Perhaps they are not using the right programming language as clearly they are not willing to work with it as it is not as it should be. After all the back and forth, there are several choices including accepting whatever method is least annoying to them, or rolling their own. Create a function with a name like do_it_my_way_or_the_highway() that uses any acceptable method but completely hides the implementation details from your code. One way might be to get the source code and copy it under your own name and modify it so the default is to do what you want. It can even be as simple as a small wrapper that forwards to the original function with a keyword set by default. After all, this does seem to be a bit like what you are asking for. A way to call your functionality that does it the way you insist it should have been designed, never mind that many others are happy with it as it is and use the techniques mentioned at other times. But I do have sympathy. I have seen lots of simple-minded code that seems to cleanly and elegantly solve a problem as long as all the ducks are just-so. Then someone points out that the code may break if it is called with some other type than expected or if it tries to divide by zero or if something else changes a variable between the time you looked at it and the time you update it and so on. Next thing you know, your code grows (even exponentially) to try to handle all these conditions and includes lots of nested IF statements and all kinds of TRY statements and slows down and is hard to read or even think about. And to make it worse, people ask for your formerly simple function to become a Swiss army knife that accepts oodles of keyword arguments that alter various aspects of the behavior! So, yes, it can feel wrong. But so what? Sometimes you can find ways to reduce the complexity and sometimes you simply create a few accessory functions you can use that tame the complexity a bit. But almost any complex program in any language can require a loss of simplicity. -----Original Message----- From: Python-list On Behalf Of Kushal Kumaran Sent: Saturday, April 29, 2023 12:19 AM To: python-list at python.org Subject: Re: How to 'ignore' an error in Python? On Fri, Apr 28 2023 at 04:55:41 PM, Chris Green wrote: > I'm sure I'm missing something obvious here but I can't see an elegant > way to do this. I want to create a directory, but if it exists it's > not an error and the code should just continue. > > So, I have:- > > for dirname in listofdirs: > try: > os.mkdir(dirname) > except FileExistsError: > # so what can I do here that says 'carry on regardless' > except: > # handle any other error, which is really an error > > # I want code here to execute whether or not dirname exists > > > Do I really have to use a finally: block? It feels rather clumsy. > > I suppose I could test if the directory exists before the os.mkdir() > but again that feels a bit clumsy somehow. > > I suppose also I could use os.mkdirs() with exist_ok=True but again > that feels vaguely wrong somehow. > Why does exist_ok=True feel wrong to you? This is exactly what it is there for. -- regards, kushal -- https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Sat Apr 29 21:04:54 2023 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 30 Apr 2023 13:04:54 +1200 Subject: How to 'ignore' an error in Python? In-Reply-To: References: <874joznwwq.fsf@copper.locationd.net> Message-ID: On 30/04/23 2:43 am, jak wrote: > Maybe I expressed myself badly but I didn't mean to propose alternatives > to the EAFP way but just to evaluate the possibility that it is not a > folder. If it's not a folder, you'll find out when the next thing you try to do to it fails. You could check for it earlier, but there's still the possibility of a race condition -- someone could delete the folder and replace it with a file in the meantime. Or just delete it and not replace it with anything. So you need to be prepared to deal with failures at any point. -- Greg From cl at isbd.net Sat Apr 29 03:32:25 2023 From: cl at isbd.net (Chris Green) Date: Sat, 29 Apr 2023 08:32:25 +0100 Subject: How to 'ignore' an error in Python? References: <874joznwwq.fsf@copper.locationd.net> Message-ID: <9ptuhj-nnhn.ln1@esprimo.zbmc.eu> Kushal Kumaran wrote: > On Fri, Apr 28 2023 at 04:55:41 PM, Chris Green wrote: > > I'm sure I'm missing something obvious here but I can't see an elegant > > way to do this. I want to create a directory, but if it exists it's > > not an error and the code should just continue. > > > > So, I have:- > > > > for dirname in listofdirs: > > try: > > os.mkdir(dirname) > > except FileExistsError: > > # so what can I do here that says 'carry on regardless' > > except: > > # handle any other error, which is really an error > > > > # I want code here to execute whether or not dirname exists > > > > > > Do I really have to use a finally: block? It feels rather clumsy. > > > > I suppose I could test if the directory exists before the os.mkdir() > > but again that feels a bit clumsy somehow. > > > > I suppose also I could use os.mkdirs() with exist_ok=True but again > > that feels vaguely wrong somehow. > > > > Why does exist_ok=True feel wrong to you? This is exactly what it is > there for. > It was rather using os.mekedirs() to create a single directory that seemed wrong. If os.mkdir() had exist_ok=True than that would have been the obvious way to do it. -- Chris Green ? From cl at isbd.net Sat Apr 29 03:34:41 2023 From: cl at isbd.net (Chris Green) Date: Sat, 29 Apr 2023 08:34:41 +0100 Subject: How to 'ignore' an error in Python? References: <874joznwwq.fsf@copper.locationd.net> Message-ID: Chris Angelico wrote: > On Sat, 29 Apr 2023 at 14:27, Kushal Kumaran wrote: > > > > On Fri, Apr 28 2023 at 04:55:41 PM, Chris Green wrote: > > > I'm sure I'm missing something obvious here but I can't see an elegant > > > way to do this. I want to create a directory, but if it exists it's > > > not an error and the code should just continue. > > > > > > So, I have:- > > > > > > for dirname in listofdirs: > > > try: > > > os.mkdir(dirname) > > > except FileExistsError: > > > # so what can I do here that says 'carry on regardless' > > > except: > > > # handle any other error, which is really an error > > > > > > # I want code here to execute whether or not dirname exists > > > > > > > > > Do I really have to use a finally: block? It feels rather clumsy. > > > > > > I suppose I could test if the directory exists before the os.mkdir() > > > but again that feels a bit clumsy somehow. > > > > > > I suppose also I could use os.mkdirs() with exist_ok=True but again > > > that feels vaguely wrong somehow. > > > > > > > Why does exist_ok=True feel wrong to you? This is exactly what it is > > there for. > > > > Using mkdirs when you only want to make one is inviting problems of > being subtly wrong, where it creates too many levels of directory. > Personally, I would just do: > > try: os.mkdir(dirname) > except FileExistsError: pass > > and not try to handle anything else at all. > Yes, OP here, that seems to me to be the 'right' way to do it. Basically I hadn't realised the effect of pass in a try block and that's why I asked the question originally. -- Chris Green ? From nospam at please.ty Sat Apr 29 09:24:42 2023 From: nospam at please.ty (jak) Date: Sat, 29 Apr 2023 15:24:42 +0200 Subject: How to 'ignore' an error in Python? In-Reply-To: References: <874joznwwq.fsf@copper.locationd.net> Message-ID: Chris Angelico ha scritto: > Using mkdirs when you only want to make one is inviting problems of > being subtly wrong, where it creates too many levels of directory. > Personally, I would just do: Maybe I only say this because it has happened to me too many times but before ignoring the error in the 'except' branch, I would make sure that if the name exists it is a folder and not a file. From nospam at please.ty Sat Apr 29 10:43:38 2023 From: nospam at please.ty (jak) Date: Sat, 29 Apr 2023 16:43:38 +0200 Subject: How to 'ignore' an error in Python? In-Reply-To: References: <874joznwwq.fsf@copper.locationd.net> Message-ID: Stefan Ram ha scritto: > jak writes: >> Maybe I only say this because it has happened to me too many times but >> before ignoring the error in the 'except' branch, I would make sure that >> if the name exists it is a folder and not a file. > > If the name exists and it is a file's name, this will be detected > by "mkdir( exist_ok=True )", and an object will be raised. Such > an object, indeed, usually should /not/ be ignored by the caller. > But there is no reason to deviate from the EAFP path. > > Maybe I expressed myself badly but I didn't mean to propose alternatives to the EAFP way but just to evaluate the possibility that it is not a folder. From rosuav at gmail.com Sat Apr 29 22:04:30 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Apr 2023 12:04:30 +1000 Subject: How to 'ignore' an error in Python? In-Reply-To: References: <874joznwwq.fsf@copper.locationd.net> Message-ID: On Sun, 30 Apr 2023 at 11:58, Chris Green wrote: > > Chris Angelico wrote: > > On Sat, 29 Apr 2023 at 14:27, Kushal Kumaran wrote: > > > > > > On Fri, Apr 28 2023 at 04:55:41 PM, Chris Green wrote: > > > > I'm sure I'm missing something obvious here but I can't see an elegant > > > > way to do this. I want to create a directory, but if it exists it's > > > > not an error and the code should just continue. > > > > > > > > So, I have:- > > > > > > > > for dirname in listofdirs: > > > > try: > > > > os.mkdir(dirname) > > > > except FileExistsError: > > > > # so what can I do here that says 'carry on regardless' > > > > except: > > > > # handle any other error, which is really an error > > > > > > > > # I want code here to execute whether or not dirname exists > > > > > > > > > > > > Do I really have to use a finally: block? It feels rather clumsy. > > > > > > > > I suppose I could test if the directory exists before the os.mkdir() > > > > but again that feels a bit clumsy somehow. > > > > > > > > I suppose also I could use os.mkdirs() with exist_ok=True but again > > > > that feels vaguely wrong somehow. > > > > > > > > > > Why does exist_ok=True feel wrong to you? This is exactly what it is > > > there for. > > > > > > > Using mkdirs when you only want to make one is inviting problems of > > being subtly wrong, where it creates too many levels of directory. > > Personally, I would just do: > > > > try: os.mkdir(dirname) > > except FileExistsError: pass > > > > and not try to handle anything else at all. > > > Yes, OP here, that seems to me to be the 'right' way to do it. > Basically I hadn't realised the effect of pass in a try block and > that's why I asked the question originally. > There's two points to note here. "pass" doesn't do anything whatsoever; it's only there to prevent the syntactic problem of having nothing in that block. This will also suppress the error: try: os.mkdir(dirname) except FileExistsError: dummy = "ignore" The second thing is that, as soon as you have an "except" clause that matches the error, that's it - it stops there. The error is considered handled at that point. If that's NOT what you want, you have a few options. Firstly, you can simply not have a matching except clause. That's why we like to be as precise as possible with our catching; every other type of problem will be left uncaught. Secondly, you can use "try/finally" to add code that happens as the exception flies by, but doesn't catch it (it also happens at the end of the block for other reasons). And thirdly, you can reraise the exception: try: os.mkdir(dirname) except FileExistsError: print("Hey, that one already exists!") raise That's going to keep the exception going just as if it hadn't been caught, but with the additional handling. But if you don't do any of those things, the exception is deemed to be handled, and it goes no further. ChrisA From rosuav at gmail.com Sat Apr 29 22:05:49 2023 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Apr 2023 12:05:49 +1000 Subject: How to 'ignore' an error in Python? In-Reply-To: References: <874joznwwq.fsf@copper.locationd.net> Message-ID: On Sun, 30 Apr 2023 at 12:02, jak wrote: > > Chris Angelico ha scritto: > > Using mkdirs when you only want to make one is inviting problems of > > being subtly wrong, where it creates too many levels of directory. > > Personally, I would just do: > > > Maybe I only say this because it has happened to me too many times but > before ignoring the error in the 'except' branch, I would make sure that > if the name exists it is a folder and not a file. > That's a fair consideration, although the other way to handle that is to allow other operations to fail later (if someone creates a file called "logs" and then you try to create "logs/2023-04-30.txt", you get an error at that point). I have also known situations where this is a deliberate way to suppress something (like a cache or log directory). ChrisA From psam1304 at gmail.com Sat Apr 29 23:28:59 2023 From: psam1304 at gmail.com (Phu Sam) Date: Sat, 29 Apr 2023 20:28:59 -0700 Subject: How to 'ignore' an error in Python? In-Reply-To: References: <874joznwwq.fsf@copper.locationd.net> Message-ID: Unsubscribe On Sat, Apr 29, 2023 at 7:05 PM Chris Angelico wrote: > On Sun, 30 Apr 2023 at 11:58, Chris Green wrote: > > > > Chris Angelico wrote: > > > On Sat, 29 Apr 2023 at 14:27, Kushal Kumaran > wrote: > > > > > > > > On Fri, Apr 28 2023 at 04:55:41 PM, Chris Green wrote: > > > > > I'm sure I'm missing something obvious here but I can't see an > elegant > > > > > way to do this. I want to create a directory, but if it exists > it's > > > > > not an error and the code should just continue. > > > > > > > > > > So, I have:- > > > > > > > > > > for dirname in listofdirs: > > > > > try: > > > > > os.mkdir(dirname) > > > > > except FileExistsError: > > > > > # so what can I do here that says 'carry on regardless' > > > > > except: > > > > > # handle any other error, which is really an error > > > > > > > > > > # I want code here to execute whether or not dirname exists > > > > > > > > > > > > > > > Do I really have to use a finally: block? It feels rather clumsy. > > > > > > > > > > I suppose I could test if the directory exists before the > os.mkdir() > > > > > but again that feels a bit clumsy somehow. > > > > > > > > > > I suppose also I could use os.mkdirs() with exist_ok=True but again > > > > > that feels vaguely wrong somehow. > > > > > > > > > > > > > Why does exist_ok=True feel wrong to you? This is exactly what it is > > > > there for. > > > > > > > > > > Using mkdirs when you only want to make one is inviting problems of > > > being subtly wrong, where it creates too many levels of directory. > > > Personally, I would just do: > > > > > > try: os.mkdir(dirname) > > > except FileExistsError: pass > > > > > > and not try to handle anything else at all. > > > > > Yes, OP here, that seems to me to be the 'right' way to do it. > > Basically I hadn't realised the effect of pass in a try block and > > that's why I asked the question originally. > > > > There's two points to note here. "pass" doesn't do anything > whatsoever; it's only there to prevent the syntactic problem of having > nothing in that block. This will also suppress the error: > > try: > os.mkdir(dirname) > except FileExistsError: > dummy = "ignore" > > The second thing is that, as soon as you have an "except" clause that > matches the error, that's it - it stops there. The error is considered > handled at that point. If that's NOT what you want, you have a few > options. Firstly, you can simply not have a matching except clause. > That's why we like to be as precise as possible with our catching; > every other type of problem will be left uncaught. Secondly, you can > use "try/finally" to add code that happens as the exception flies by, > but doesn't catch it (it also happens at the end of the block for > other reasons). And thirdly, you can reraise the exception: > > try: > os.mkdir(dirname) > except FileExistsError: > print("Hey, that one already exists!") > raise > > That's going to keep the exception going just as if it hadn't been > caught, but with the additional handling. > > But if you don't do any of those things, the exception is deemed to be > handled, and it goes no further. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From specially at processed.almost.meat Sun Apr 30 11:40:21 2023 From: specially at processed.almost.meat (Roy Hann) Date: Sun, 30 Apr 2023 15:40:21 -0000 (UTC) Subject: Using loguru in a library Message-ID: Is there anyone using loguru (loguru 0.5.3 in my case) successfully in a library? In my __init__.py in mylib I do logger.disable('mylib') which definitely works. I don't get any more logging. I "pip install ." the library, then in mytest.py I do import mylib logger.enable('mylib') expecting that it would report any log messages above level DEBUG, just as it does when I don't disable logging. Unfortunately it doesn't have any effect; it doesn't report any logging from mylib. I have verified that __name__ is visible in the library and is 'mylib'. I would also have expected that logger.enable(None) would turn all the logging on everywhere but it seems not. I have probably misunderstood how logger.enable() is supposed to be used. Can anyone share a brief example? Roy