From nospam at dfs.com Fri Dec 2 10:19:45 2022 From: nospam at dfs.com (DFS) Date: Fri, 2 Dec 2022 10:19:45 -0500 Subject: Python is maybe the most widely used language, but clp gets 0 posts some days? Message-ID: Usenet is dead. Long live Usenet. From arequipeno at gmail.com Fri Dec 2 15:00:21 2022 From: arequipeno at gmail.com (Ian Pilcher) Date: Fri, 2 Dec 2022 14:00:21 -0600 Subject: Calling pselect/ppoll/epoll_pwait Message-ID: Does Python provide any way to call the "p" variants of the I/O multiplexing functions? Looking at the documentation of the select[1] and selectors[2] modules, it appears that they expose only the "non-p" variants. [1] https://docs.python.org/3/library/select.html [2] https://docs.python.org/3/library/selectors.html -- ======================================================================== Google Where SkyNet meets Idiocracy ======================================================================== From barry at barrys-emacs.org Fri Dec 2 19:00:34 2022 From: barry at barrys-emacs.org (Barry) Date: Sat, 3 Dec 2022 00:00:34 +0000 Subject: Calling pselect/ppoll/epoll_pwait In-Reply-To: References: Message-ID: <427E6CAE-1E77-42BD-924F-F221CBFCB6AC@barrys-emacs.org> > On 2 Dec 2022, at 20:03, Ian Pilcher wrote: > > ?Does Python provide any way to call the "p" variants of the I/O > multiplexing functions? > > Looking at the documentation of the select[1] and selectors[2] modules, > it appears that they expose only the "non-p" variants. > > [1] https://docs.python.org/3/library/select.html > [2] https://docs.python.org/3/library/selectors.html Can you use signalfd and select/poll/epoll? Barry > > -- > ======================================================================== > Google Where SkyNet meets Idiocracy > ======================================================================== > -- > https://mail.python.org/mailman/listinfo/python-list > From gweatherby at uchc.edu Sat Dec 3 08:12:57 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Sat, 3 Dec 2022 13:12:57 +0000 Subject: Calling pselect/ppoll/epoll_pwait In-Reply-To: <427E6CAE-1E77-42BD-924F-F221CBFCB6AC@barrys-emacs.org> References: <427E6CAE-1E77-42BD-924F-F221CBFCB6AC@barrys-emacs.org> Message-ID: Signalfd and select could probably be made to work if one codes around the race conditions pselect is provided to avoid. I?m not sure if using the GIL (for CPython) is sufficient or if a dedicated concurrency control (e.g. lock, mutex, semaphore) is necessary. An alternative is to call the C library function via a wrapper. I had need to use setfsuid on a project a couple of years ago and found this example: https://gist.github.com/atdt/ebafa299e843a767139b From: Python-list on behalf of Barry Date: Friday, December 2, 2022 at 7:02 PM To: Ian Pilcher Cc: python-list at python.org Subject: Re: Calling pselect/ppoll/epoll_pwait *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > On 2 Dec 2022, at 20:03, Ian Pilcher wrote: > > ?Does Python provide any way to call the "p" variants of the I/O > multiplexing functions? > > Looking at the documentation of the select[1] and selectors[2] modules, > it appears that they expose only the "non-p" variants. > > [1] https://urldefense.com/v3/__https://docs.python.org/3/library/select.html__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_OD5qBjeA$ > [2] https://urldefense.com/v3/__https://docs.python.org/3/library/selectors.html__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_MwNjgO8A$ Can you use signalfd and select/poll/epoll? Barry > > -- > ======================================================================== > Google Where SkyNet meets Idiocracy > ======================================================================== > -- > https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_PhasKBfg$ > -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_PhasKBfg$ From barry at barrys-emacs.org Sun Dec 4 04:55:24 2022 From: barry at barrys-emacs.org (Barry) Date: Sun, 4 Dec 2022 09:55:24 +0000 Subject: Calling pselect/ppoll/epoll_pwait In-Reply-To: References: Message-ID: <1735D724-0AEF-4FE9-8C92-86FA5041DDDC@barrys-emacs.org> On 3 Dec 2022, at 13:13, Weatherby,Gerard wrote: ? Signalfd and select could probably be made to work if one codes around the race conditions pselect is provided to avoid. I?m not sure if using the GIL (for CPython) is sufficient or if a dedicated concurrency control (e.g. lock, mutex, semaphore) is necessary. An alternative is to call the C library function via a wrapper. I had need to use setfsuid on a project a couple of years ago and found this example: [1]https://gist.github.com/atdt/ebafa299e843a767139b ? I read this on SO when researching your question. Search for epoll and signal. (I would post the link but ipad turns the link into an image?) I assume that the lack of pepoll means you can use epoll and signalfd without race conditions. The trick seems to be setting the signal to ignore. Barry ? From: Python-list on behalf of Barry Date: Friday, December 2, 2022 at 7:02 PM To: Ian Pilcher Cc: python-list at python.org Subject: Re: Calling pselect/ppoll/epoll_pwait *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > On 2 Dec 2022, at 20:03, Ian Pilcher wrote: > > ?Does Python provide any way to call the "p" variants of the I/O > multiplexing functions? > > Looking at the documentation of the select[1] and selectors[2] modules, > it appears that they expose only the "non-p" variants. > > [1] [2]https://urldefense.com/v3/__https://docs.python.org/3/library/select.html__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_OD5qBjeA$ > [2] [3]https://urldefense.com/v3/__https://docs.python.org/3/library/selectors.html__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_MwNjgO8A$ Can you use signalfd and select/poll/epoll? Barry > > -- > ======================================================================== > Google????????????????????????????????????? Where SkyNet meets Idiocracy > ======================================================================== > -- > [4]https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_PhasKBfg$ > -- [5]https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_PhasKBfg$ References Visible links 1. https://gist.github.com/atdt/ebafa299e843a767139b 2. https://urldefense.com/v3/__https:/docs.python.org/3/library/select.html__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_OD5qBjeA$ 3. https://urldefense.com/v3/__https:/docs.python.org/3/library/selectors.html__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_MwNjgO8A$ 4. https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_PhasKBfg$ 5. https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hClFFo4XdiwQAhHxDbHA5zFr490Of9uheHSf84V9cREMHyw1kX-baG5HzXWMt-hFLP30q6DpSUb2G_PhasKBfg$ From biglee12672 at gmail.com Fri Dec 2 17:38:03 2022 From: biglee12672 at gmail.com (biglee12672 at gmail.com) Date: Fri, 2 Dec 2022 14:38:03 -0800 Subject: unable to resolve readline issues Message-ID: <002b01d9069e$bd78f2c0$386ad840$@gmail.com> Dear Sir: For whatever reason I have lost functionality of using Python 3.11. While opening Python (standalone or from CMD prompt) as usual this AM the following message appeared. Did read that it is not compatible with Windows but I can't get it to work as I don't know what module will load. Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. Failed calling sys.__interactivehook__ Traceback (most recent call last): File "", line 445, in register_readline File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\re adline.py", line 34, in rl = Readline() ^^^^^^^^^^ File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\py readline\rlmain.py", line 422, in __init__ BaseReadline.__init__(self) File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\py readline\rlmain.py", line 62, in __init__ mode.init_editing_mode(None) File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\py readline\modes\emacs.py", line 633, in init_editing_mode self._bind_key('space', self.self_insert) File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\py readline\modes\basemode.py", line 162, in _bind_key if not callable(func): ^^^^^^^^^^^^^^ File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\py readline\py3k_compat.py", line 8, in callable return isinstance(x, collections.Callable)rer ^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'collections' has no attribute 'Callable' >From this point on Python became unusable as I uninstalled rebooted then reinstalled to find I have the same issues as stated. Finally uninstalled Python as it doesn't perform as usual especially trying to understand the use of pyreadline, gnureadline and or just readline. If you can help great. Regards, Leon Pearlman From eryksun at gmail.com Sun Dec 4 15:08:36 2022 From: eryksun at gmail.com (Eryk Sun) Date: Sun, 4 Dec 2022 14:08:36 -0600 Subject: unable to resolve readline issues In-Reply-To: <002b01d9069e$bd78f2c0$386ad840$@gmail.com> References: <002b01d9069e$bd78f2c0$386ad840$@gmail.com> Message-ID: On 12/2/22, biglee12672 at gmail.com wrote: > > From this point on Python became unusable as I uninstalled rebooted then > reinstalled to find I have the same issues as stated. Finally uninstalled > Python as it doesn't perform as usual especially trying to understand the > use of pyreadline, gnureadline and or just readline. When Python runs interactively, it implicitly tries to import the readline module. On POSIX, Python has a builtin readline module that usually uses the GNU Readline library. On Windows, Python does not include a readline module. Instead, if standard I/O is a console, the high-level WinAPI ReadConsoleW() function is used, which implements its own line editor and command-line history. It's not as general, flexible, or capable as the readline interface, so a third-party pyreadline package was implemented for Windows. However, as far as I know, pyreadline is no longer actively developed. Thus it has out-of-date code, which may be broken in newer releases of Python, such as isinstance(x, collections.Callable). Your choice is to either patch pyreadline to fix the bug or uninstall it. From python at mrabarnett.plus.com Sun Dec 4 15:18:28 2022 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 4 Dec 2022 20:18:28 +0000 Subject: unable to resolve readline issues In-Reply-To: <002b01d9069e$bd78f2c0$386ad840$@gmail.com> References: <002b01d9069e$bd78f2c0$386ad840$@gmail.com> Message-ID: <7e85d380-6703-47a4-2d9d-be7511eb0f90@mrabarnett.plus.com> On 2022-12-02 22:38, biglee12672 at gmail.com wrote: > Dear Sir: > > For whatever reason I have lost functionality of using Python 3.11. While > opening Python (standalone or from CMD prompt) as usual this AM the > following message appeared. Did read that it is not compatible with > Windows but I can't get it to work as I don't know what module will load. > > Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. > Failed calling sys.__interactivehook__ > Traceback (most recent call last): > File "", line 445, in register_readline > File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\readline.py", line 34, in > rl = Readline() > ^^^^^^^^^^ > File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyreadline\rlmain.py", line 422, in __init__ > BaseReadline.__init__(self) > File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyreadline\rlmain.py", line 62, in __init__ > mode.init_editing_mode(None) > File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyreadline\modes\emacs.py", line 633, in init_editing_mode > self._bind_key('space', self.self_insert) > File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyreadline\modes\basemode.py", line 162, in _bind_key > if not callable(func): > ^^^^^^^^^^^^^^ > File "C:\Users\bigle\AppData\Local\Programs\Python\Python311\Lib\site-packages\pyreadline\py3k_compat.py", line 8, in callable > return isinstance(x, collections.Callable)rer > ^^^^^^^^^^^^^^^^^^^^ > AttributeError: module 'collections' has no attribute 'Callable' > > From this point on Python became unusable as I uninstalled rebooted then > reinstalled to find I have the same issues as stated. Finally uninstalled > Python as it doesn't perform as usual especially trying to understand the > use of pyreadline, gnureadline and or just readline. > > If you can help great. > > Regards, > Leon Pearlman > Looking at PyPI, it appears that it was last supported on Python 3.5. I'd suggest that after uninstalling Python, you delete the Python folder if it's still there (because of any installed 3rd-party modules) before re-installing. From salmodovar at ligumu.com Sun Dec 4 18:36:19 2022 From: salmodovar at ligumu.com (=?UTF-8?Q?Sabrina_Almod=c3=b3var?=) Date: Sun, 4 Dec 2022 20:36:19 -0300 Subject: unable to resolve readline issues References: <002b01d9069e$bd78f2c0$386ad840$@gmail.com> Message-ID: On 04/12/2022 17:08, Eryk Sun wrote: > On 12/2/22, biglee12672 at gmail.com wrote: >> >> From this point on Python became unusable as I uninstalled rebooted then >> reinstalled to find I have the same issues as stated. Finally uninstalled >> Python as it doesn't perform as usual especially trying to understand the >> use of pyreadline, gnureadline and or just readline. > > When Python runs interactively, it implicitly tries to import the > readline module. On POSIX, Python has a builtin readline module that > usually uses the GNU Readline library. > > On Windows, Python does not include a readline module. Instead, if > standard I/O is a console, the high-level WinAPI ReadConsoleW() > function is used, which implements its own line editor and > command-line history. It's not as general, flexible, or capable as the > readline interface, so a third-party pyreadline package was > implemented for Windows. However, as far as I know, pyreadline is no > longer actively developed. Thus it has out-of-date code, which may be > broken in newer releases of Python, such as isinstance(x, > collections.Callable). > > Your choice is to either patch pyreadline to fix the bug or uninstall it. (*) How to patch it Open the file Lib/site-packages/pyreadline/py3k_compat.py and locate the procedure def callable(x): return isinstance(x, collections.Callable) Change it to def callable(x): return isinstance(x, collections.abc.Callable) You're done. From mats at wichmann.us Mon Dec 5 10:25:44 2022 From: mats at wichmann.us (Mats Wichmann) Date: Mon, 5 Dec 2022 08:25:44 -0700 Subject: unable to resolve readline issues In-Reply-To: References: <002b01d9069e$bd78f2c0$386ad840$@gmail.com> Message-ID: On 12/4/22 13:08, Eryk Sun wrote: > On 12/2/22, biglee12672 at gmail.com wrote: >> >> From this point on Python became unusable as I uninstalled rebooted then >> reinstalled to find I have the same issues as stated. Finally uninstalled >> Python as it doesn't perform as usual especially trying to understand the >> use of pyreadline, gnureadline and or just readline. > > When Python runs interactively, it implicitly tries to import the > readline module. On POSIX, Python has a builtin readline module that > usually uses the GNU Readline library. > > On Windows, Python does not include a readline module. Instead, if > standard I/O is a console, the high-level WinAPI ReadConsoleW() > function is used, which implements its own line editor and > command-line history. It's not as general, flexible, or capable as the > readline interface, so a third-party pyreadline package was > implemented for Windows. However, as far as I know, pyreadline is no > longer actively developed. Thus it has out-of-date code, which may be > broken in newer releases of Python, such as isinstance(x, > collections.Callable). > > Your choice is to either patch pyreadline to fix the bug or uninstall it. there is a pyreadline3 I tried it for a particular case and didn't have a whole lot of luck with it, so YMMV, but somebody has done the porting work to keep it more current. From salmodovar at ligumu.com Mon Dec 5 20:37:39 2022 From: salmodovar at ligumu.com (=?UTF-8?Q?Sabrina_Almod=c3=b3var?=) Date: Mon, 5 Dec 2022 22:37:39 -0300 Subject: on the python paradox Message-ID: The Python Paradox Paul Graham August 2004 In a recent talk [1] I said something that upset a lot of people: that you could get smarter programmers to work on a Python project than you could to work on a Java project. I didn't mean by this that Java programmers are dumb. I meant that Python programmers are smart. It's a lot of work to learn a new programming language. And people don't learn Python because it will get them a job; they learn it because they genuinely like to program and aren't satisfied with the languages they already know. Which makes them exactly the kind of programmers companies should want to hire. Hence what, for lack of a better name, I'll call the Python paradox: if a company chooses to write its software in a comparatively esoteric language, they'll be able to hire better programmers, because they'll attract only those who cared enough to learn it. And for programmers the paradox is even more pronounced: the language to learn, if you want to get a good job, is a language that people don't learn merely to get a job. Only a few companies have been smart enough to realize this so far. But there is a kind of selection going on here too: they're exactly the companies programmers would most like to work for. Google, for example. When they advertise Java programming jobs, they also want Python experience. A friend of mine who knows nearly all the widely used languages uses Python for most of his projects. He says the main reason is that he likes the way source code looks. That may seem a frivolous reason to choose one language over another. But it is not so frivolous as it sounds: when you program, you spend more time reading code than writing it. You push blobs of source code around the way a sculptor does blobs of clay. So a language that makes source code ugly is maddening to an exacting programmer, as clay full of lumps would be to a sculptor. At the mention of ugly source code, people will of course think of Perl. But the superficial ugliness of Perl is not the sort I mean. Real ugliness is not harsh-looking syntax, but having to build programs out of the wrong concepts. Perl may look like a cartoon character swearing, but there are cases where it surpasses Python conceptually. So far, anyway. Both languages are of course moving targets. But they share, along with Ruby (and Icon, and Joy, and J, and Lisp, and Smalltalk) the fact that they're created by, and used by, people who really care about programming. And those tend to be the ones who do it well. (*) Footnotes [1] Audio of the talk, also attached to this post http://origin.conversationsnetwork.org/Paul%20Graham%20-%20Great%20Hackers.mp3 From gabriele1NOSPAM at hotmail.com Tue Dec 6 05:07:55 2022 From: gabriele1NOSPAM at hotmail.com (^Bart) Date: Tue, 6 Dec 2022 11:07:55 +0100 Subject: FTP without username and password Message-ID: Hi Guys, usually I use this code on my Debian Bullseye: # python3 -m pyftpdlib -i 192.168.0.71 -p 21 -d /home/my_user/ftp It works, it's simply easy and perfect but... a device in my lan needs a ftp folder without username and password! I tried to search on internet how to set the code above to be available without username and password but... I didn't understand how to fix it :\ Obviously I could use a workaround like Samba or another machine where I have a Vsftp server but... I'd like to fix Python! ;) Regards. ^Bart From jon+usenet at unequivocal.eu Tue Dec 6 10:48:07 2022 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 6 Dec 2022 15:48:07 -0000 (UTC) Subject: FTP without username and password References: Message-ID: On 2022-12-06, ^Bart wrote: > Hi Guys, > > usually I use this code on my Debian Bullseye: > > # python3 -m pyftpdlib -i 192.168.0.71 -p 21 -d /home/my_user/ftp > > It works, it's simply easy and perfect but... a device in my lan needs a > ftp folder without username and password! > > I tried to search on internet how to set the code above to be available > without username and password but... I didn't understand how to fix it :\ The code above already does make the directory available without a username and password. Do you mean you need the directory to be *writable* without a username and password? If so try the '-w' option. From rosuav at gmail.com Tue Dec 6 10:55:53 2022 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 Dec 2022 02:55:53 +1100 Subject: FTP without username and password In-Reply-To: References: Message-ID: On Wed, 7 Dec 2022 at 02:51, ^Bart wrote: > > Hi Guys, > > usually I use this code on my Debian Bullseye: > > # python3 -m pyftpdlib -i 192.168.0.71 -p 21 -d /home/my_user/ftp > > It works, it's simply easy and perfect but... a device in my lan needs a > ftp folder without username and password! > > I tried to search on internet how to set the code above to be available > without username and password but... I didn't understand how to fix it :\ > > Obviously I could use a workaround like Samba or another machine where I > have a Vsftp server but... I'd like to fix Python! ;) > I assume it HAS to be FTP, otherwise you'd set up something much more secure like ssh (or scp or sshfs, which are built on it), done with an authorized key rather than a password. In general, "anonymous FTP" is done technically with a username and password. Can you look at how the device tries to connect, and then make that username (probably "anonymous") and that password (could be anything, traditionally was an email address) valid for fetching? ChrisA From gabriele1NOSPAM at hotmail.com Tue Dec 6 14:42:42 2022 From: gabriele1NOSPAM at hotmail.com (^Bart) Date: Tue, 6 Dec 2022 20:42:42 +0100 Subject: FTP without username and password References: Message-ID: > In general, "anonymous FTP" is done technically with a username and > password. Can you look at how the device tries to connect, and then > make that username (probably "anonymous") and that password (could be > anything, traditionally was an email address) valid for fetching? Thanks for your reply, I needed a TFTP to upload a no brand firmware in a Wildix antenna, I solved with a free software of SolarWinds, there's something also for Linux! I tried the written Python code but it needs to insert a username and password so it's a different service than TFTP but maybe there's also a code to do it in Python! ;) > ChrisA Regards. ^Bart From gabriele1NOSPAM at hotmail.com Tue Dec 6 14:44:44 2022 From: gabriele1NOSPAM at hotmail.com (^Bart) Date: Tue, 6 Dec 2022 20:44:44 +0100 Subject: FTP without username and password References: Message-ID: > The code above already does make the directory available without a > username and password. Do you mean you need the directory to be > *writable* without a username and password? If so try the '-w' option. Thanks for your reply, I solved by TFTP SolarWind free tool, like what I wrote in another post I needed it to upload a no brand firmware in a Wildix antenna. Regards. ^Bart From grant.b.edwards at gmail.com Tue Dec 6 15:11:34 2022 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 06 Dec 2022 12:11:34 -0800 (PST) Subject: FTP without username and password References: Message-ID: <638fa1f6.050a0220.9a168.c10c@mx.google.com> On 2022-12-06, ^Bart wrote: >> In general, "anonymous FTP" is done technically with a username and >> password. Can you look at how the device tries to connect, and then >> make that username (probably "anonymous") and that password (could be >> anything, traditionally was an email address) valid for fetching? > > Thanks for your reply, I needed a TFTP to upload a no brand firmware in > a Wildix antenna, I solved with a free software of SolarWinds, there's > something also for Linux! > > I tried the written Python code but it needs to insert a username and > password so it's a different service than TFTP but maybe there's also a > code to do it in Python! ;) The Python code you showed was implementing an FTP server. That's a completely different protocol from TFTP. There are TFTP implementations for Pythong. This one works well: https://github.com/msoulier/tftpy -- Grant From ramvikrams243 at gmail.com Tue Dec 6 15:24:24 2022 From: ramvikrams243 at gmail.com (ramvikram singh) Date: Wed, 7 Dec 2022 01:54:24 +0530 Subject: Contributing to cpython Message-ID: Greetings, I learnt python this year and visiting the python issue tab for the last two months, but there is a problem which I am facing I understand the issue after reading the few times but I can't think about how to modify the code as per the issue. Could you please help me with this? From barry at barrys-emacs.org Tue Dec 6 16:45:08 2022 From: barry at barrys-emacs.org (Barry) Date: Tue, 6 Dec 2022 21:45:08 +0000 Subject: Contributing to cpython In-Reply-To: References: Message-ID: <2C2BCA10-D3F2-40A8-984E-0D84BDF6FB0A@barrys-emacs.org> > On 6 Dec 2022, at 20:55, ramvikram singh wrote: > > ?Greetings, > I learnt python this year and visiting the python issue tab for the last > two months, but there is a problem which I am facing I understand the issue > after reading the few times but I can't think about how to modify the code > as per the issue. Could you please help me with this? no one can help as you have not explained what the issue is. Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From lukasz at langa.pl Tue Dec 6 18:01:39 2022 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Wed, 7 Dec 2022 00:01:39 +0100 Subject: [RELEASE] Python 3.11.1, 3.10.9, 3.9.16, 3.8.16, 3.7.16, and 3.12.0 alpha 3 are now available Message-ID: <820CB8BD-49D6-469B-8DC0-0D7B2B5C984D@langa.pl> Greetings! We bring you a slew of releases this fine Saint Nicholas / Sinterklaas day. Six simultaneous releases has got to be some record. There?s one more record we broke this time, you?ll see below. In any case, updating is recommended due to security content: 3.7 - 3.12: gh-98739 : Updated bundled libexpat to 2.5.0 to fix CVE-2022-43680 (heap use-after-free). 3.7 - 3.12: gh-98433 : The IDNA codec decoder used on DNS hostnames by socket or asyncio related name resolution functions no longer involves a quadratic algorithm to fix CVE-2022-45061 . This prevents a potential CPU denial of service if an out-of-spec excessive length hostname involving bidirectional characters were decoded. Some protocols such as urllib http 3xx redirects potentially allow for an attacker to supply such a name. 3.7 - 3.12: gh-100001 : python -m http.server no longer allows terminal control characters sent within a garbage request to be printed to the stderr server log. 3.8 - 3.12: gh-87604 : Avoid publishing list of active per-interpreter audit hooks via the gc module. 3.9 - 3.10 (already released in 3.11+ before): gh-97514 : On Linux the multiprocessing module returns to using filesystem backed unix domain sockets for communication with the forkserver process instead of the Linux abstract socket namespace. Only code that chooses to use the ?forkserver? start method is affected. This prevents Linux CVE-2022-42919 (potential privilege escalation) as abstract sockets have no permissions and could allow any user on the system in the same network namespace (often the whole system) to inject code into the multiprocessing forkserver process. This was a potential privilege escalation. Filesystem based socket permissions restrict this to the forkserver process user as was the default in Python 3.8 and earlier. 3.7 - 3.10: gh-98517 : Port XKCP?s fix for the buffer overflows in SHA-3 to fix CVE-2022-37454 . 3.7 - 3.9 (already released in 3.10+ before): gh-68966 : The deprecated mailcap module now refuses to inject unsafe text (filenames, MIME types, parameters) into shell commands to address CVE-2015-20107 . Instead of using such text, it will warn and act as if a match was not found (or for test commands, as if the test failed). Python 3.12.0 alpha 3 Get it here, read the change log, sing a GPT-3-generated Sinterklaas song: https://www.python.org/downloads/release/python-3120a3/ 216 new commits since 3.12.0 alpha 2 last month. Python 3.11.1 Get it here, see the change log, read the recipe for quark soup: https://www.python.org/downloads/release/python-3111/ A whopping 495 new commits since 3.11.0. This is a massive increase of changes comparing to 3.10 at the same stage in the release cycle: there were ?only? 339 commits between 3.10.0 and 3.10.1. Python 3.10.9 Get it here, read the change log, see circular patterns: https://www.python.org/downloads/release/python-3109/ 165 new commits. Python 3.9.16 Get it here, read the change log, consider upgrading to a newer version: https://www.python.org/downloads/release/python-3916/ Security-only release with no binaries. 10 commits. Python 3.8.16 Get it here, see the change log, definitely upgrade to a newer version: https://www.python.org/downloads/release/python-3816/ Security-only release with no binaries. 9 commits. Python 3.7.16 Get it here, read the change log, check PEP 537 to confirm EOL is coming to this version in June 2023: https://www.python.org/downloads/release/python-3716/ Security-only release with no binaries. 8 commits. 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/ Your friendly release team, Ned Deily @nad Steve Dower @steve.dower Pablo Galindo Salgado @pablogsal ?ukasz Langa @ambv Thomas Wouters @thomas -------------- 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 list1 at tompassin.net Tue Dec 6 17:05:19 2022 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 6 Dec 2022 17:05:19 -0500 Subject: Contributing to cpython In-Reply-To: References: Message-ID: <146d844c-f650-8e99-695f-4376fe96cd62@tompassin.net> On 12/6/2022 3:24 PM, ramvikram singh wrote: > Greetings, > I learnt python this year and visiting the python issue tab for the last > two months, but there is a problem which I am facing I understand the issue > after reading the few times but I can't think about how to modify the code > as per the issue. Could you please help me with this? There is a page about contributing work on code to Python at https://devguide.python.org It starts out: "This guide is a comprehensive resource for contributing to Python ? for both new and experienced contributors." You should study this guide carefully. If you don't know how to use git, clone a repo, work with git branches, what a pull request is, and so forth, you need to get some basic familiarity with working with those tools and concepts. You should be able to file new issues on GitHub and contribute to their discussion thread. If you want to actually contribute code, you should be able to build Python yourself, as covered in the guide. After that, you should remember that while help is welcome, the Python code base has a long history and a change that seems obvious to you may not work because of other constraints on that part of the codebase. I once suggested a change in a particular function for finding executable files so that it would look in some other locations too. I learnt that this function was intended for internal use by distutils, and that it needed its quirks to work properly in its intended use. No one wanted to take a chance on changing it. I'm not saying you cannot or should not try to contribute useful changes. I'm only saying that you need to get prepared - do your homework - first, and to not be discouraged if your first efforts are not accepted. From jfong at ms4.hinet.net Tue Dec 6 21:23:07 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Tue, 6 Dec 2022 18:23:07 -0800 (PST) Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? Message-ID: s0 = r'\x0a' At this moment it was done by def to1byte(matchobj): ....return chr(int('0x' + matchobj.group(1), 16)) s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) But, is it that difficult on doing this simple thing? --Jach From wlfraed at ix.netcom.com Tue Dec 6 21:32:20 2022 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Tue, 06 Dec 2022 21:32:20 -0500 Subject: FTP without username and password References: Message-ID: On Tue, 6 Dec 2022 20:42:42 +0100, ^Bart declaimed the following: > >I tried the written Python code but it needs to insert a username and >password so it's a different service than TFTP but maybe there's also a >code to do it in Python! ;) > It's a whole different protocol. TFTP is simplified to the point it will fit on embedded devices which don't need security (the assumption being that one has the embedded device physically present, FTP assumes distributed networks). https://wiki.python.org/moin/tftp -- Wulfraed Dennis Lee Bieber AF6VN wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ From python at mrabarnett.plus.com Tue Dec 6 22:01:12 2022 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 7 Dec 2022 03:01:12 +0000 Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: Message-ID: On 2022-12-07 02:23, Jach Feng wrote: > s0 = r'\x0a' > At this moment it was done by > > def to1byte(matchobj): > ....return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > But, is it that difficult on doing this simple thing? > You could try this: >>> s0 = r'\x0a' >>> ast.literal_eval('"%s"' % s0) '\n' From ramvikrams243 at gmail.com Tue Dec 6 23:18:21 2022 From: ramvikrams243 at gmail.com (ramvikram singh) Date: Wed, 7 Dec 2022 09:48:21 +0530 Subject: Contributing to cpython In-Reply-To: References: Message-ID: the issue is that after reading the issue I am not able to think how to modify the code, this is where I am stuck On Wed, Dec 7, 2022 at 1:54 AM ramvikram singh wrote: > Greetings, > I learnt python this year and visiting the python issue tab for the last > two months, but there is a problem which I am facing I understand the issue > after reading the few times but I can't think about how to modify the code > as per the issue. Could you please help me with this? > From jfong at ms4.hinet.net Tue Dec 6 22:37:54 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Tue, 6 Dec 2022 19:37:54 -0800 (PST) Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: Message-ID: <64271aaf-3896-43b2-8998-30d245fb98fen@googlegroups.com> MRAB ? 2022?12?7? ?????11:04:43 [UTC+8] ?????? > On 2022-12-07 02:23, Jach Feng wrote: > > s0 = r'\x0a' > > At this moment it was done by > > > > def to1byte(matchobj): > > ....return chr(int('0x' + matchobj.group(1), 16)) > > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > > > But, is it that difficult on doing this simple thing? > > > You could try this: > > >>> s0 = r'\x0a' > >>> ast.literal_eval('"%s"' % s0) > '\n' Not work in my system:-( Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> s0 = r'\x0a' >>> import ast >>> ast.literal_eval("%s" % s0) Traceback (most recent call last): File "", line 1, in File "C:\Users\Jach\AppData\Local\Programs\Python\Python38-32\lib\ast.py", line 59, in literal_eval node_or_string = parse(node_or_string, mode='eval') File "C:\Users\Jach\AppData\Local\Programs\Python\Python38-32\lib\ast.py", line 47, in parse return compile(source, filename, mode, flags, File "", line 1 \x0a ^ SyntaxError: unexpected character after line continuation character From list1 at tompassin.net Tue Dec 6 22:55:52 2022 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 6 Dec 2022 22:55:52 -0500 Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: Message-ID: <776e63a0-2bf3-1dd0-87a5-61f587ce0732@tompassin.net> On 12/6/2022 9:23 PM, Jach Feng wrote: > s0 = r'\x0a' > At this moment it was done by > > def to1byte(matchobj): > ....return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > But, is it that difficult on doing this simple thing? > > --Jach I'm not totally clear on what you are trying to do here. But: s1 = r'\xdd' # s1[2:] = 'dd' n1 = int(s1[2:], 16) # = 221 decimal or 0xdd in hex # So chr(n1) == '?' # True # and '\xdd' == '?' # True So the conversion you want seems to be chr(int(s1[2:], 16)). Of course, this will only work if the input string is exactly four characters long, and the first two characters are r'\x', and the remaining two characters are going to be a hex string representation of a number small enough to fit into a byte. If you know for sure that will be the case, then the conversion above seems to be about as simple as it could be. If those conditions may not always be met, then you need to work out exactly what strings you may need to convert, and what they should be converted to. From list1 at tompassin.net Wed Dec 7 00:12:13 2022 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 7 Dec 2022 00:12:13 -0500 Subject: Contributing to cpython In-Reply-To: References: Message-ID: On 12/6/2022 11:18 PM, ramvikram singh wrote: > the issue is that after reading the issue I am not able to think how to > modify the code, this is where I am stuck > > On Wed, Dec 7, 2022 at 1:54 AM ramvikram singh > wrote: > >> Greetings, >> I learnt python this year and visiting the python issue tab for the last >> two months, but there is a problem which I am facing I understand the issue >> after reading the few times but I can't think about how to modify the code >> as per the issue. Could you please help me with this? >> No one can help you because you have said nothing about the issue. It is as if I were to write "I am having a problem with my car. Can you help me?". And before you can think about modifying the code, you need to understand what the issue is, why it is happening, how that could be changed, and why that would be a safe kind of change to make. After that, you would be prepared to think about details of the code. And that thinking would need to include ways in which you could verify that you can make the problem occur and how you can test to make sure that it is fixed after changes to the code. From roel at roelschroeven.net Wed Dec 7 03:42:18 2022 From: roel at roelschroeven.net (Roel Schroeven) Date: Wed, 7 Dec 2022 09:42:18 +0100 Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: <64271aaf-3896-43b2-8998-30d245fb98fen@googlegroups.com> References: <64271aaf-3896-43b2-8998-30d245fb98fen@googlegroups.com> Message-ID: Op 7/12/2022 om 4:37 schreef Jach Feng: > MRAB ? 2022?12?7? ?????11:04:43 [UTC+8] ?????? > > On 2022-12-07 02:23, Jach Feng wrote: > > > s0 = r'\x0a' > > > At this moment it was done by > > > > > > def to1byte(matchobj): > > > ....return chr(int('0x' + matchobj.group(1), 16)) > > > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > > > > > But, is it that difficult on doing this simple thing? > > > > > You could try this: > > > > >>> s0 = r'\x0a' > > >>> ast.literal_eval('"%s"' % s0) > > '\n' > Not work in my system:-( > > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> s0 = r'\x0a' > >>> import ast > >>> ast.literal_eval("%s" % s0) > Traceback (most recent call last): > File "", line 1, in > File "C:\Users\Jach\AppData\Local\Programs\Python\Python38-32\lib\ast.py", line 59, in literal_eval > node_or_string = parse(node_or_string, mode='eval') > File "C:\Users\Jach\AppData\Local\Programs\Python\Python38-32\lib\ast.py", line 47, in parse > return compile(source, filename, mode, flags, > File "", line 1 > \x0a > ^ > SyntaxError: unexpected character after line continuation character You missed a pair of quotes. They are easily overlooked but very important. The point is to wrap your string in another pair of quotes so it becomes a valid Python string literal in a Python string which can then be passed to ast.literal_eval(). Works for me: In [7]: s0 = r'\x0a' In [8]: import ast In [9]: ast.literal_eval('"%s"' % s0) Out[9]: '\n' -- "Experience is that marvelous thing that enables you to recognize a mistake when you make it again." -- Franklin P. Jones From david at lowryduda.com Wed Dec 7 11:05:53 2022 From: david at lowryduda.com (David Lowry-Duda) Date: Wed, 7 Dec 2022 11:05:53 -0500 Subject: Nonuniform PRNG? Message-ID: Inspired by the recent thread about pseudorandom number generators on python-ideas (where I also mistakenly first wrote this message), I began to wonder: suppose that I had a pseudorandom number generator that attempted to generate a nonuniform distribution. Suppose for instance that it was to generate a 0 bit 2/3 of the time, and a 1 bit 1/3 of the time. How would one go about testing this PRNG against an idealized (similarly biased) PRNG? - DLD From david at lowryduda.com Wed Dec 7 10:58:09 2022 From: david at lowryduda.com (David Lowry-Duda) Date: Wed, 7 Dec 2022 10:58:09 -0500 Subject: on the python paradox In-Reply-To: References: Message-ID: On Mon, Dec 05, 2022 at 10:37:39PM -0300, Sabrina Almod?var wrote: > The Python Paradox > Paul Graham > August 2004 > > [SNIP] > > Hence what, for lack of a better name, I'll call the Python paradox: > if a company chooses to write its software in a comparatively esoteric > language, they'll be able to hire better programmers, because they'll > attract only those who cared enough to learn it. And for programmers > the paradox is even more pronounced: the language to learn, if you > want to get a good job, is a language that people don't learn merely > to get a job. > > [SNIP] I wonder what the appropriately esoteric language is today? We can sort of think of go/rust as esoteric versions of C/C++. But what would be the esoteric python? Perhaps Julia? I don't know of any large software projects happening in julia world that aren't essentially scientific computing libraries (but this is because *I* work mostly with scientific computing libraries and sometimes live under a rock). - DLD From jacob.kruger.work at gmail.com Wed Dec 7 04:16:59 2022 From: jacob.kruger.work at gmail.com (jacob kruger) Date: Wed, 7 Dec 2022 11:16:59 +0200 Subject: Initial introduction Message-ID: <71f1c437-2f5c-55be-3d7c-3d706aa724d2@gmail.com> Hi there I might shortly be posting about a specific issue with imaplib/poplib, but, thought would first introduce myself. I am 100% blind, but, among other forms of assistive technology software, I use windows PC's with the NVDA screenreader, which itself is written in python, but, besides that, i generally work with either VS code or other programmer-specific text editors when it comes to python coding, etc., and, while have been a web application developer for over 25 years, working with different programming/scripting languages and platforms, I am more-or-less a full-time python developer nowadays, and, when it comes to web development in this context, I work with either flask or django, but anyway. Regards -- Jacob Kruger +2782 413 4791 "Resistance is futile...but, acceptance is versatile..." From jfong at ms4.hinet.net Wed Dec 7 02:40:12 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Tue, 6 Dec 2022 23:40:12 -0800 (PST) Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: <776e63a0-2bf3-1dd0-87a5-61f587ce0732@tompassin.net> Message-ID: <722b829f-977d-4dc7-ab66-693c3593f771n@googlegroups.com> Thomas Passin ? 2022?12?7? ?????12:51:32 [UTC+8] ?????? > On 12/6/2022 9:23 PM, Jach Feng wrote: > > s0 = r'\x0a' > > At this moment it was done by > > > > def to1byte(matchobj): > > ....return chr(int('0x' + matchobj.group(1), 16)) > > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > > > But, is it that difficult on doing this simple thing? > > > > --Jach > I'm not totally clear on what you are trying to do here. But: > > s1 = r'\xdd' # s1[2:] = 'dd' > n1 = int(s1[2:], 16) # = 221 decimal or 0xdd in hex > # So > chr(n1) == '?' # True > # and > '\xdd' == '?' # True > > So the conversion you want seems to be chr(int(s1[2:], 16)). > > Of course, this will only work if the input string is exactly four > characters long, and the first two characters are r'\x', and the > remaining two characters are going to be a hex string representation of > a number small enough to fit into a byte. > > If you know for sure that will be the case, then the conversion above > seems to be about as simple as it could be. If those conditions may not > always be met, then you need to work out exactly what strings you may > need to convert, and what they should be converted to. Thank you for reminding that the '0x'+ in the to1byte() definition is redundant:-) Just not sure if there is a better way than using chr(int(...)) to do it. Yes, for this specific case, slice is much simpler than re.sub(). From io at io.it Wed Dec 7 07:28:20 2022 From: io at io.it (^Bart) Date: Wed, 7 Dec 2022 13:28:20 +0100 Subject: FTP without username and password References: <638fa1f6.050a0220.9a168.c10c@mx.google.com> Message-ID: > The Python code you showed was implementing an FTP server. That's a > completely different protocol from TFTP. There are TFTP > implementations for Pythong. This one works well: https://github.com/msoulier/tftpy I didn't know the difference of FTP and TFTP so... I thought TFTP was just a FTP without username and password! LOL! ;) I'm sorry for my "bad post" and thanks to show me the Python implementation! :) > -- > Grant Regards. ^Bart From io at io.it Wed Dec 7 07:30:14 2022 From: io at io.it (^Bart) Date: Wed, 7 Dec 2022 13:30:14 +0100 Subject: FTP without username and password References: Message-ID: > It's a whole different protocol. TFTP is simplified to the point it > will fit on embedded devices which don't need security (the assumption > being that one has the embedded device physically present, FTP assumes > distributed networks). > > https://wiki.python.org/moin/tftp I never used TFTP so, like what I wrote in another post, I thought it was just a FTP without username and password... Thanks to show me the "Python way" to use TFTP! :) Have a nice day! ^Bart From salmodovar at ligumu.com Wed Dec 7 12:34:47 2022 From: salmodovar at ligumu.com (=?UTF-8?Q?Sabrina_Almod=c3=b3var?=) Date: Wed, 7 Dec 2022 14:34:47 -0300 Subject: Nonuniform PRNG? References: Message-ID: On 07/12/2022 13:05, David Lowry-Duda wrote: > Inspired by the recent thread about pseudorandom number generators on > python-ideas (where I also mistakenly first wrote this message), I began > to wonder: suppose that I had a pseudorandom number generator that > attempted to generate a nonuniform distribution. Suppose for instance > that it was to generate a 0 bit 2/3 of the time, and a 1 bit 1/3 of the > time. > > How would one go about testing this PRNG against an idealized (similarly > biased) PRNG? I believe things go like this. If you have a uniform PRNG, you test it against the state-of-the-art in statistical tests then build from it your nonuniform one. Now you have a nonuniform one that's tested. But you want things the other way around. Having a nonuniform one to start, you build a uniform one from the nonuniform one and then test it against the state-of-the-art in statistical tests. I believe you might be wondering how to build one from the other, but I'll let you check that. By the way, there's no such thing as an idealized PRNG. All PRNG fail all statistical tests. The question is when. A bad PRNG fails quickly and obviously. A good one requires large samples or a nontrivial test. From gweatherby at uchc.edu Wed Dec 7 12:55:20 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Wed, 7 Dec 2022 17:55:20 +0000 Subject: on the python paradox In-Reply-To: References: Message-ID: I use asyncio in a couple of places. Haven?t quite grokked it yet, though. From: Python-list on behalf of Stefan Ram Date: Wednesday, December 7, 2022 at 12:28 PM To: python-list at python.org Subject: Re: on the python paradox *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** David Lowry-Duda writes: >I wonder what the appropriately esoteric language is today? How many Python programmers grog metaclasses or asyncio? So, I'd say: The two streams have converged. Python is the esoteric mainstream language. -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!mvBtuPjNnWaXWGLt8aXlimysNpjtW4fP_ls5-vLPv8qWMyafvYcP6sgo0jcV7ngjmV1E3F0zJ5ipXlbjkBF8_l8$ From grant.b.edwards at gmail.com Wed Dec 7 14:10:32 2022 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 07 Dec 2022 11:10:32 -0800 (PST) Subject: FTP without username and password References: Message-ID: <6390e528.020a0220.669f3.f166@mx.google.com> On 2022-12-07, Dennis Lee Bieber wrote: > It's a whole different protocol. TFTP is simplified to the point it > will fit on embedded devices which don't need security (the > assumption being that one has the embedded device physically > present, FTP assumes distributed networks). One of the big differences is that FTP uses a pair of TCP connections (a control connection and a data connection) while TFTP uses UDP. UDP is far, far simpler to implement than TCP. Things like bootloaders for embedded systems often support UDP but don't implement TCP at all. -- Grant From salmodovar at ligumu.com Wed Dec 7 13:28:47 2022 From: salmodovar at ligumu.com (=?UTF-8?Q?Sabrina_Almod=c3=b3var?=) Date: Wed, 7 Dec 2022 15:28:47 -0300 Subject: Nonuniform PRNG? References: Message-ID: On 07/12/2022 14:04, Stefan Ram wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: >> So, in this case, careful code reviews might be better than >> tests. For example, assuming, random.intrange( 0, 2 ) works >> as advertised, we can be pretty sure that >> 0 if random.randint( 0, 2 ) else 1 >> fulfills the requirement. > > In practice, tests should still be done. When such a function > returns the same result a hundred times, it does make sense > to become suspicious and investigate it. Whatever it does a hundred times is not enough. Code review is definitely not enough. The design of PRNGs should be good in theory --- designed with good mathematical foundations --- and in practice by passing all tests in the best-designed batteries. As far as I know, the state-of-the-art in statistical tests against PRNGs is the TestU01 library, available at http://simul.iro.umontreal.ca/testu01/tu01.html From salmodovar at ligumu.com Wed Dec 7 13:33:00 2022 From: salmodovar at ligumu.com (=?UTF-8?Q?Sabrina_Almod=c3=b3var?=) Date: Wed, 7 Dec 2022 15:33:00 -0300 Subject: Nonuniform PRNG? References: Message-ID: On 07/12/2022 13:45, Stefan Ram wrote: [...] > |One of the oldest interpretations is the /limit frequency/ > |interpretation. If the conditioning event /C/ can lead > |to either A or "not A", and if in /n/ repetitions of such > |a situation the event A occurs /m/ times, then it is asserted > |that P(A|C) = lim n-->oo (m/n). This provides not only > |an interpretation of probability, but also a definition > |of probability in terms of a numerical frequency ratio. > |Hence the axioms of abstract probability theory can > |be derived as theorems of the frequency theory. > | > |In spite of its superficial appeal, the limit frequency > |interpretation has been widely discarded, primarily because > |there is no assurance that the above limit really exists for > |the actual sequences of events to which one wishes to apply > |probability theory. > | > "Quantum Mechanics" (1998) - Leslie E. Ballentine That's pretty interesting. Indeed, we really must discard this frequency interpretation, even though it is what's in my mind when I think of estimating the probability of a certain event, which I think would be called the empirical distribution of probability? From __peter__ at web.de Wed Dec 7 16:12:27 2022 From: __peter__ at web.de (Peter Otten) Date: Wed, 7 Dec 2022 22:12:27 +0100 Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: Message-ID: <725a6a70-be22-d11a-e0cf-6a29ef2adeeb@web.de> On 07/12/2022 03:23, Jach Feng wrote: > s0 = r'\x0a' > At this moment it was done by > > def to1byte(matchobj): > ....return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > But, is it that difficult on doing this simple thing? >>> import codecs >>> codecs.decode(r"\x68\x65\x6c\x6c\x6f\x0a", "unicode-escape") 'hello\n' From barry at barrys-emacs.org Wed Dec 7 16:45:11 2022 From: barry at barrys-emacs.org (Barry) Date: Wed, 7 Dec 2022 21:45:11 +0000 Subject: FTP without username and password Message-ID: ? > On 7 Dec 2022, at 16:49, ^Bart wrote: > > ? >> It's a whole different protocol. TFTP is simplified to the point it >> will fit on embedded devices which don't need security (the assumption >> being that one has the embedded device physically present, FTP assumes >> distributed networks). >> https://wiki.python.org/moin/tftp > > I never used TFTP so, like what I wrote in another post, I thought it was just a FTP without username and password... > > Thanks to show me the "Python way" to use TFTP! :) > > Have a nice day! > ^Bart TFTP server and client tools are standard on linux systems. Barry > > -- > https://mail.python.org/mailman/listinfo/python-list From david at lowryduda.com Wed Dec 7 17:37:10 2022 From: david at lowryduda.com (David Lowry-Duda) Date: Wed, 7 Dec 2022 17:37:10 -0500 Subject: Nonuniform PRNG? In-Reply-To: References: Message-ID: On Wed, Dec 07, 2022 at 03:28:47PM -0300, Sabrina Almod?var wrote: >As far as I know, the state-of-the-art in statistical tests against >PRNGs is the TestU01 library, available at > > http://simul.iro.umontreal.ca/testu01/tu01.html I'm familiar with this type of test. But as far as I can tell and have seen, these tests only tst against *uniform* PRNGs. I am not aware of any written tests against nonuniform PRNGs. I suspect it would be possible to mirror a lot of the ideas. For example, one common PRNG statistical test is to make many of matrices of various sizes and to study the ranks of these matrices. Presumably one could do a similar statistical analysis against what would be expected for any particular probability distribution. Running a candidate PRNG through this test will produce some sort of distribution, after all. But it would be much nicer if work on statistical tests against nonuniform PRNGs had already been done somewhere. -- David Lowry-Duda From caliche-81 at hotmail.com Wed Dec 7 17:04:56 2022 From: caliche-81 at hotmail.com (=?UTF-8?Q?Carlos_Berm=c3=badez?=) Date: Wed, 7 Dec 2022 17:04:56 -0500 Subject: FTP without username and password References: Message-ID: El 6/12/2022 a las 9:32 p.?m., Dennis Lee Bieber escribi?: > On Tue, 6 Dec 2022 20:42:42 +0100, ^Bart > declaimed the following: > >> >> I tried the written Python code but it needs to insert a username and >> password so it's a different service than TFTP but maybe there's also a >> code to do it in Python! ;) >> > > It's a whole different protocol. TFTP is simplified to the point it > will fit on embedded devices which don't need security (the assumption > being that one has the embedded device physically present, FTP assumes > distributed networks). > > https://wiki.python.org/moin/tftp > > TFTP is used usually to manage updates and boot workstations without bootable disks using a NIC with a preloaded ROM. From Richard at Damon-Family.org Wed Dec 7 20:30:49 2022 From: Richard at Damon-Family.org (Richard Damon) Date: Wed, 7 Dec 2022 17:30:49 -0800 Subject: Nonuniform PRNG? In-Reply-To: References: Message-ID: On 12/7/22 2:37 PM, David Lowry-Duda wrote: > On Wed, Dec 07, 2022 at 03:28:47PM -0300, Sabrina Almod?var wrote: >> As far as I know, the state-of-the-art in statistical tests against >> PRNGs is the TestU01 library, available at >> >> ?http://simul.iro.umontreal.ca/testu01/tu01.html > > I'm familiar with this type of test. But as far as I can tell and have > seen, these tests only tst against *uniform* PRNGs. I am not aware of > any written tests against nonuniform PRNGs. > > I suspect it would be possible to mirror a lot of the ideas. For > example, one common PRNG statistical test is to make many of matrices > of various sizes and to study the ranks of these matrices. Presumably > one could do a similar statistical analysis against what would be > expected for any particular probability distribution. Running a > candidate PRNG through this test will produce some sort of > distribution, after all. > > But it would be much nicer if work on statistical tests against > nonuniform PRNGs had already been done somewhere. > The big problem is there are MANY variations of nonuniform random numbers, and all the variations lead to different statistics to test against. Most of the test can probably apply, but the new test criteria would need to be computed based on computing the exected results and expected variation in that result, largely based on various cross correlations of the numbers. -- Richard Damon From jfong at ms4.hinet.net Wed Dec 7 20:16:09 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Wed, 7 Dec 2022 17:16:09 -0800 (PST) Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: <64271aaf-3896-43b2-8998-30d245fb98fen@googlegroups.com> Message-ID: Roel Schroeven ? 2022?12?7? ?????4:42:48 [UTC+8] ?????? > Op 7/12/2022 om 4:37 schreef Jach Feng: > > MRAB ? 2022?12?7? ?????11:04:43 [UTC+8] ?????? > > > On 2022-12-07 02:23, Jach Feng wrote: > > > > s0 = r'\x0a' > > > > At this moment it was done by > > > > > > > > def to1byte(matchobj): > > > > ....return chr(int('0x' + matchobj.group(1), 16)) > > > > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > > > > > > > But, is it that difficult on doing this simple thing? > > > > > > > You could try this: > > > > > > >>> s0 = r'\x0a' > > > >>> ast.literal_eval('"%s"' % s0) > > > '\n' > > Not work in my system:-( > > > > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit (Intel)] on win32 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> s0 = r'\x0a' > > >>> import ast > > >>> ast.literal_eval("%s" % s0) > > Traceback (most recent call last): > > File "", line 1, in > > File "C:\Users\Jach\AppData\Local\Programs\Python\Python38-32\lib\ast.py", line 59, in literal_eval > > node_or_string = parse(node_or_string, mode='eval') > > File "C:\Users\Jach\AppData\Local\Programs\Python\Python38-32\lib\ast.py", line 47, in parse > > return compile(source, filename, mode, flags, > > File "", line 1 > > \x0a > > ^ > > SyntaxError: unexpected character after line continuation character > You missed a pair of quotes. They are easily overlooked but very > important. The point is to wrap your string in another pair of quotes so > it becomes a valid Python string literal in a Python string which can > then be passed to ast.literal_eval(). Works for me: > > In [7]: s0 = r'\x0a' > > In [8]: import ast > > In [9]: ast.literal_eval('"%s"' % s0) > Out[9]: '\n' > > -- > "Experience is that marvelous thing that enables you to recognize a > mistake when you make it again." > -- Franklin P. Jones Thank you for notifying me. I did notice those ''' in MRAB's post, but didn't figure out what it is at that time:-( From jfong at ms4.hinet.net Wed Dec 7 20:17:22 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Wed, 7 Dec 2022 17:17:22 -0800 (PST) Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: <725a6a70-be22-d11a-e0cf-6a29ef2adeeb@web.de> Message-ID: Peter Otten ? 2022?12?8? ?????5:17:59 [UTC+8] ?????? > On 07/12/2022 03:23, Jach Feng wrote: > > s0 = r'\x0a' > > At this moment it was done by > > > > def to1byte(matchobj): > > ....return chr(int('0x' + matchobj.group(1), 16)) > > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > > > But, is it that difficult on doing this simple thing? > >>> import codecs > >>> codecs.decode(r"\x68\x65\x6c\x6c\x6f\x0a", "unicode-escape") > 'hello\n' Thank you. What I really want to handle is to any r'\xdd'. The r'\x0a' is for example. Sorry, didn't describe it clearly:-) From rbeaudoin at acm.org Wed Dec 7 21:50:37 2022 From: rbeaudoin at acm.org (Robert E. Beaudoin) Date: Wed, 7 Dec 2022 21:50:37 -0500 Subject: Nonuniform PRNG? References: Message-ID: <20221207215037.4d345dee@euclid> One thing you could do is to apply von Neumann de-biasing to convert a string of output bits from your biased PRNG to an unbiased string, and test the de-biased output. If such tests pass I don't know that you can be satisfied thaty your biased PRNG is close to a theorieical biased random bit stream, but if they fail that should indicate a problem. Robert E. Beaudoin On Wed, 7 Dec 2022 11:05:53 -0500 David Lowry-Duda wrote: > Inspired by the recent thread about pseudorandom number generators on > python-ideas (where I also mistakenly first wrote this message), I > began to wonder: suppose that I had a pseudorandom number generator > that attempted to generate a nonuniform distribution. Suppose for > instance that it was to generate a 0 bit 2/3 of the time, and a 1 bit > 1/3 of the time. > > How would one go about testing this PRNG against an idealized > (similarly biased) PRNG? > > - DLD From robin at reportlab.com Thu Dec 8 07:52:25 2022 From: robin at reportlab.com (Robin Becker) Date: Thu, 8 Dec 2022 12:52:25 +0000 Subject: C extension custom types in abi3 module Message-ID: <3c066a7e-cbbc-67ea-a880-53fb27d453b4@everest.reportlab.co.uk> I am trying to split off reportlab C extensions to simplify installations and make use of more advanced packages. A simple extension is easily converted to being an abi3 module. However, another has a custom type which uses the old style mechanisms here https://docs.python.org/3.7/extending/newtypes_tutorial.html#the-basics I made a simple setup based on this abi3 example modified to allow switching between abi3 and normal build https://github.com/joerick/python-abi3-package-sample I made a tiny change to the code example in the newtypes tutorial page the code is here https://github.com/MrBitBucket/custom-type In a python 3.7 - 3.12a3 environment I find I can build the wheel OK with ABI3_WHEEL=0 pip wheel -w dist . but I get lots of compile errors if I switch to an abi3 build with ABI3_WHEEL=1 pip wheel -w dist . looking at the errors > src/_custom.c:10:1: error: variable ?CustomType? has initializer but incomplete type > 10 | static PyTypeObject CustomType = { > | ^~~~~~ > In file included from /home/robin/LOCAL/3.7.16/include/python3.7m/Python.h:90, > from src/_custom.c:2: > /home/robin/LOCAL/3.7.16/include/python3.7m/object.h:90:5: error: extra brace group at end of initializer > 90 | { PyObject_HEAD_INIT(type) size }, > | ^ > src/_custom.c:11:9: note: in expansion of macro ?PyVarObject_HEAD_INIT? > 11 | PyVarObject_HEAD_INIT(NULL, 0) it looks like I have to use a different mechanism to setup custom types in the abi3 world. I looked in Modules/xxlimited_35.c, but that seems much more complex and provides for a type which supports GC. Are there any ABI3 examples using the old style strategy? -- Robin Becker From gweatherby at uchc.edu Thu Dec 8 08:23:42 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Thu, 8 Dec 2022 13:23:42 +0000 Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: <725a6a70-be22-d11a-e0cf-6a29ef2adeeb@web.de> Message-ID: I?m not understanding the task. The sample code given is converting the input r?\x0a? to a newline, it appears. import re def exam(z): print(f"examine {type(z)} {z}") for c in z: print(f"{ord(c)} {c}") s0 = r'\x0a' def to1byte(matchobj): return chr(int('0x' + matchobj.group(1), 16)) s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) exam(s0) exam(s1) --- examine \x0a 92 \ 120 x 48 0 97 a examine 10 From: Python-list on behalf of Jach Feng Date: Wednesday, December 7, 2022 at 9:27 PM To: python-list at python.org Subject: Re: How to convert a raw string r'xdd' to 'xdd' more gracefully? *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Peter Otten ? 2022?12?8? ?????5:17:59 [UTC+8] ?????? > On 07/12/2022 03:23, Jach Feng wrote: > > s0 = r'\x0a' > > At this moment it was done by > > > > def to1byte(matchobj): > > ....return chr(int('0x' + matchobj.group(1), 16)) > > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > > > But, is it that difficult on doing this simple thing? > >>> import codecs > >>> codecs.decode(r"\x68\x65\x6c\x6c\x6f\x0a", "unicode-escape") > 'hello\n' Thank you. What I really want to handle is to any r'\xdd'. The r'\x0a' is for example. Sorry, didn't describe it clearly:-) -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!kUnextA7_cF7EoP_4hGzC5Jq2wRvn8nwLwT8wmeNkgVjK_n6VG19fxb-4SwmDMwepWe8_bGaH9Y2LlkSvFRz$ From list1 at tompassin.net Thu Dec 8 09:12:19 2022 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 8 Dec 2022 09:12:19 -0500 Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: <725a6a70-be22-d11a-e0cf-6a29ef2adeeb@web.de> Message-ID: The original post started out with r'\x0a' but then talked about '\xdd'. I assumed that there was a pattern here, a raw string containing "\x" and two more characters, and made a suggestion for converting any string with that pattern. But the OP was very unclear what the task really was, so here we all are, making a variety of guesses. On 12/8/2022 8:23 AM, Weatherby,Gerard wrote: > I?m not understanding the task. The sample code given is converting the input r?\x0a? to a newline, it appears. > > > import re > > > def exam(z): > print(f"examine {type(z)} {z}") > for c in z: > print(f"{ord(c)} {c}") > > s0 = r'\x0a' > > def to1byte(matchobj): > return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > exam(s0) > exam(s1) > > --- > examine \x0a > 92 \ > 120 x > 48 0 > 97 a > examine > > 10 > > From: Python-list on behalf of Jach Feng > Date: Wednesday, December 7, 2022 at 9:27 PM > To: python-list at python.org > Subject: Re: How to convert a raw string r'xdd' to 'xdd' more gracefully? > *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > > Peter Otten ? 2022?12?8? ?????5:17:59 [UTC+8] ?????? >> On 07/12/2022 03:23, Jach Feng wrote: >>> s0 = r'\x0a' >>> At this moment it was done by >>> >>> def to1byte(matchobj): >>> ....return chr(int('0x' + matchobj.group(1), 16)) >>> s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) >>> >>> But, is it that difficult on doing this simple thing? >>>>> import codecs >>>>> codecs.decode(r"\x68\x65\x6c\x6c\x6f\x0a", "unicode-escape") >> 'hello\n' > Thank you. What I really want to handle is to any r'\xdd'. The r'\x0a' is for example. Sorry, didn't describe it clearly:-) > -- > https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!kUnextA7_cF7EoP_4hGzC5Jq2wRvn8nwLwT8wmeNkgVjK_n6VG19fxb-4SwmDMwepWe8_bGaH9Y2LlkSvFRz$ From robin at reportlab.com Thu Dec 8 10:35:55 2022 From: robin at reportlab.com (Robin Becker) Date: Thu, 8 Dec 2022 15:35:55 +0000 Subject: C extension custom types in abi3 module In-Reply-To: <3c066a7e-cbbc-67ea-a880-53fb27d453b4@everest.reportlab.co.uk> References: <3c066a7e-cbbc-67ea-a880-53fb27d453b4@everest.reportlab.co.uk> Message-ID: <8c0d3da6-cd0c-aa95-fc4d-c4f10aba9585@everest.reportlab.co.uk> On 08/12/2022 12:52, Robin Becker wrote: > I am trying to split off reportlab C extensions to simplify installations and make use of more advanced packages. > > A simple extension is easily converted to being an abi3 module. However, another has a custom type which uses the old > style mechanisms here ............ > > it looks like I have to use a different mechanism to setup custom types in the abi3 world. > In the docs I see this "Also, since PyTypeObject is only part of the Limited API as an opaque struct, any extension modules using static types must be compiled for a specific Python minor version." So it seems I must switch to using a heap allocated type or keep compiling in the old way. > I looked in Modules/xxlimited_35.c, but that seems much more complex and provides for a type which supports GC. > > Are there any ABI3 examples using the old style strategy? > -- > Robin Becker -- Robin Becker From __peter__ at web.de Thu Dec 8 11:20:27 2022 From: __peter__ at web.de (Peter Otten) Date: Thu, 8 Dec 2022 17:20:27 +0100 Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: <725a6a70-be22-d11a-e0cf-6a29ef2adeeb@web.de> Message-ID: On 08/12/2022 02:17, Jach Feng wrote: > Peter Otten ? 2022?12?8? ?????5:17:59 [UTC+8] ?????? >> On 07/12/2022 03:23, Jach Feng wrote: >>> s0 = r'\x0a' >>> At this moment it was done by >>> >>> def to1byte(matchobj): >>> ....return chr(int('0x' + matchobj.group(1), 16)) >>> s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) >>> >>> But, is it that difficult on doing this simple thing? >>>>> import codecs >>>>> codecs.decode(r"\x68\x65\x6c\x6c\x6f\x0a", "unicode-escape") >> 'hello\n' > Thank you. What I really want to handle is to any r'\xdd'. The r'\x0a' is for example. Sorry, didn't describe it clearly:-) Hm, codecs.decode() does work for arbitrary escapes. It will produce the same result for r"\xdd"-type raw strings where d is in the range 0...F. It will also convert other escapes like >>> codecs.decode(r"\t", "unicode-escape") '\t' >>> codecs.decode(r"\u5728", "unicode-escape") '?' From jfong at ms4.hinet.net Thu Dec 8 03:56:42 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Thu, 8 Dec 2022 00:56:42 -0800 (PST) Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: Message-ID: Jach Feng ? 2022?12?7? ?????10:23:20 [UTC+8] ?????? > s0 = r'\x0a' > At this moment it was done by > > def to1byte(matchobj): > ....return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > But, is it that difficult on doing this simple thing? > > --Jach I find another answer on the web. >>> s0 = r'\x0a' >>> s0.encode('Latin-1').decode('unicode-escape') '\n' From aarnav.bos at code.berlin Thu Dec 8 12:52:29 2022 From: aarnav.bos at code.berlin (Aarnav Mahavir Bos) Date: Thu, 8 Dec 2022 18:52:29 +0100 Subject: Panoptisch - A way to understand your project's dependencies and find malicious packages Message-ID: Hello all, I would like to share Panoptisch, a FOSS(Free and Open Source Software) tool I've been working on. We all may have encountered the issue of not having a clear dependency tree or not being sure of the modules our dependencies and sub-dependencies are using. Some of us may have also heard of supply chain attacks, where open source projects are hijacked to distribute malicious code masquerading as the original package. This can happen deep down in the dependency chain. Panoptisch was born out of the need to accurately verify the modules used in my project. It recursively scans a Python module or file to find modules used and exports a report in JSON which can be parsed for analysis. For example, should your yaml parser, or it's sub-dependencies import socket/os? should your markdown renderer or it's sub-dependencies import sys/importlib? *Probably not.* Panoptisch is in early stages, has known limitations and is looking for help! I would love feedback, contributions, and most important of all, rigorous testing! I would also love to help you integrate this tool in your workflow to write more secure software. Link: https://github.com/R9295/panoptisch Short Demo: https://www.youtube.com/watch?v=bDJWl_odXx0 Thanks and Regards, aarnav From ilicjelena3105 at gmail.com Thu Dec 8 15:12:47 2022 From: ilicjelena3105 at gmail.com (=?UTF-8?B?SmVsZW5hIElsacSH?=) Date: Thu, 8 Dec 2022 12:12:47 -0800 (PST) Subject: MinecraftEdu Message-ID: <60a744d6-4994-41c3-a3bc-635cc7d665c3n@googlegroups.com> Hello, I'm new to MinecraftEDU programming with Python. I'm wondering if anyone can recommend how to get started with creating lessons and how to get started programming in MinecraftEDU? From cs at cskk.id.au Thu Dec 8 16:26:12 2022 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 9 Dec 2022 08:26:12 +1100 Subject: MinecraftEdu In-Reply-To: <60a744d6-4994-41c3-a3bc-635cc7d665c3n@googlegroups.com> References: <60a744d6-4994-41c3-a3bc-635cc7d665c3n@googlegroups.com> Message-ID: On 08Dec2022 12:12, Jelena Ili? wrote: >I'm new to MinecraftEDU programming with Python. I'm wondering if >anyone can recommend how to get started with creating lessons and how >to get started programming in MinecraftEDU? Had you started here? https://education.minecraft.net/en-us/resources/computer-science-subject-kit/python-101 That's just from a web search, I've not used it. Cheers, Cameron Simpson From jfong at ms4.hinet.net Thu Dec 8 21:05:02 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Thu, 8 Dec 2022 18:05:02 -0800 (PST) Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: Message-ID: Jach Feng ? 2022?12?7? ?????10:23:20 [UTC+8] ?????? > s0 = r'\x0a' > At this moment it was done by > > def to1byte(matchobj): > ....return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > But, is it that difficult on doing this simple thing? > > --Jach The whold story is, I had a script which accepts an argparse's positional argument. I like this argument may have control character embedded in when required. So I make a post "How to enter escape character in a positional string argument from the command line? on DEC05. But there is no response. I assume that there is no way of doing it and I have to convert it later after I get the whole string from the command line. I made this convertion using the chr(int(...)) method but not satisfied with. That why this post came out. At this moment the conversion is done almost the same as Peter's codecs.decode() method but without the need of importing codecs module:-) def to1byte(matchobj): ....return matchobj.group(0).encode().decode("unicode-escape") From axy at declassed.art Thu Dec 8 22:49:58 2022 From: axy at declassed.art (Axy) Date: Fri, 9 Dec 2022 03:49:58 +0000 Subject: Panoptisch - A way to understand your project's dependencies and find malicious packages In-Reply-To: References: Message-ID: <146e747f-bb2b-29e6-b8df-93698495c46a@declassed.art> On 08/12/2022 17:52, Aarnav Mahavir Bos wrote: > Hello all, > > I would like to share Panoptisch, a FOSS(Free and Open Source Software) > tool I've been working on. Hi there, I added your project to my watch list, keep on your work. A couple of points: First, I glanced at the code and in the very first file I opened, https://github.com/R9295/panoptisch/blob/master/panoptisch/__init__.py, I see main(). I usually place such a code in __main__.py Second, in addition to AST analysis it would be nice to implement a sandbox with import hooks. Axy. From gweatherby at uchc.edu Fri Dec 9 08:29:06 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Fri, 9 Dec 2022 13:29:06 +0000 Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: Message-ID: That?s actually more of a shell question than a Python question. How you pass certain control characters is going to depend on the shell, operating system, and possibly the keyboard you?re using. (e.g. https://www.alt-codes.net). Here?s a sample program. The dashes are to help show the boundaries of the string #!/usr/bin/env python3 import argparse import logging parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('data') args = parser.parse_args() print(f'Input\n: -{args.data}- length {len(args.data)}') for c in args.data: print(f'{ord(c)} ',end='') print() Using bash on Linux: ./cl.py '^M ' Input - - length 3 13 32 10 From: Python-list on behalf of Jach Feng Date: Thursday, December 8, 2022 at 9:31 PM To: python-list at python.org Subject: Re: How to convert a raw string r'xdd' to 'xdd' more gracefully? *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Jach Feng ? 2022?12?7? ?????10:23:20 [UTC+8] ?????? > s0 = r'\x0a' > At this moment it was done by > > def to1byte(matchobj): > ....return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > But, is it that difficult on doing this simple thing? > > --Jach The whold story is, I had a script which accepts an argparse's positional argument. I like this argument may have control character embedded in when required. So I make a post "How to enter escape character in a positional string argument from the command line? on DEC05. But there is no response. I assume that there is no way of doing it and I have to convert it later after I get the whole string from the command line. I made this convertion using the chr(int(...)) method but not satisfied with. That why this post came out. At this moment the conversion is done almost the same as Peter's codecs.decode() method but without the need of importing codecs module:-) def to1byte(matchobj): ....return matchobj.group(0).encode().decode("unicode-escape") -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hcg9ULzmtVUzMJ87Emlfsf6PGAfC-MEzUs3QQNVzWwK4aWDEtePG34hRX0ZFVvWcqZXRcM67JkkIg-l-K9vB$ From dankolis at gmail.com Fri Dec 9 10:38:57 2022 From: dankolis at gmail.com (Dan Kolis) Date: Fri, 9 Dec 2022 07:38:57 -0800 (PST) Subject: Panoptisch - A way to understand your project's dependencies and find malicious packages In-Reply-To: References: <146e747f-bb2b-29e6-b8df-93698495c46a@declassed.art> Message-ID: <8903c97c-26a0-486b-a1b8-f4330659f2a3n@googlegroups.com> I think it needs a built in viewer or at least a human readable output, or nobody will go through the trouble to use it. Other that that, maybe a pretty good idea, sure From kermit at polaris.net Fri Dec 9 12:13:16 2022 From: kermit at polaris.net (kermit at polaris.net) Date: Fri, 9 Dec 2022 12:13:16 -0500 (EST) Subject: New computer, new Python In-Reply-To: References: Message-ID: <1670605996.031430820@webmail.emailsrvr.com> Hello. I've downloaded the new Python to my new Computer, and the new Python mystifies me. Instead of an editor, it looks like a Dos executable program. How can I write my own Python Functions and subroutines in the new Python? It is version 3.11 (64 bit). Kermit -----Original Message----- From: python-list-request at python.org Sent: Friday, December 9, 2022 12:00pm To: python-list at python.org Subject: Python-list Digest, Vol 231, Issue 9 Send Python-list mailing list submissions to python-list at python.org To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/python-list or, via email, send a message with subject or body 'help' to python-list-request at python.org You can reach the person managing the list at python-list-owner at python.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Python-list digest..." Today's Topics: 1. Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully? (Jach Feng) 2. Re: Nonuniform PRNG? (Stefan Ram) 3. Panoptisch - A way to understand your project's dependencies and find malicious packages (Aarnav Mahavir Bos) 4. MinecraftEdu (Jelena Ili?) 5. Re: MinecraftEdu (Cameron Simpson) 6. Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully? (Jach Feng) 7. Re: Panoptisch - A way to understand your project's dependencies and find malicious packages (Axy) 8. Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully? (Weatherby,Gerard) 9. Re: Panoptisch - A way to understand your project's dependencies and find malicious packages (Dan Kolis) ---------------------------------------------------------------------- Message: 1 Date: Thu, 8 Dec 2022 00:56:42 -0800 (PST) From: Jach Feng To: python-list at python.org Subject: Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully? Message-ID: Content-Type: text/plain; charset="UTF-8" Jach Feng ? 2022?12?7? ?????10:23:20 [UTC+8] ?????? > s0 = r'\x0a' > At this moment it was done by > > def to1byte(matchobj): > ....return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > But, is it that difficult on doing this simple thing? > > --Jach I find another answer on the web. >>> s0 = r'\x0a' >>> s0.encode('Latin-1').decode('unicode-escape') '\n' ------------------------------ Message: 2 Date: 8 Dec 2022 12:17:22 GMT From: ram at zedat.fu-berlin.de (Stefan Ram) To: python-list at python.org Subject: Re: Nonuniform PRNG? Message-ID: Content-Type: text/plain; charset=UTF-8 "Robert E. Beaudoin" writes: >One thing you could do is to apply von Neumann de-biasing to convert a >string of output bits from your biased PRNG to an unbiased string, and >test the de-biased output. Some non-uniform generators are based on uniform generators whose output then is warped by the application of some function. If one has access to the underlying uniform generator used, one can test this with the algorithms for uniform generators. ------------------------------ Message: 3 Date: Thu, 8 Dec 2022 18:52:29 +0100 From: Aarnav Mahavir Bos To: python-list at python.org Subject: Panoptisch - A way to understand your project's dependencies and find malicious packages Message-ID: Content-Type: text/plain; charset="UTF-8" Hello all, I would like to share Panoptisch, a FOSS(Free and Open Source Software) tool I've been working on. We all may have encountered the issue of not having a clear dependency tree or not being sure of the modules our dependencies and sub-dependencies are using. Some of us may have also heard of supply chain attacks, where open source projects are hijacked to distribute malicious code masquerading as the original package. This can happen deep down in the dependency chain. Panoptisch was born out of the need to accurately verify the modules used in my project. It recursively scans a Python module or file to find modules used and exports a report in JSON which can be parsed for analysis. For example, should your yaml parser, or it's sub-dependencies import socket/os? should your markdown renderer or it's sub-dependencies import sys/importlib? *Probably not.* Panoptisch is in early stages, has known limitations and is looking for help! I would love feedback, contributions, and most important of all, rigorous testing! I would also love to help you integrate this tool in your workflow to write more secure software. Link: https://github.com/R9295/panoptisch Short Demo: https://www.youtube.com/watch?v=bDJWl_odXx0 Thanks and Regards, aarnav ------------------------------ Message: 4 Date: Thu, 8 Dec 2022 12:12:47 -0800 (PST) From: Jelena Ili? To: python-list at python.org Subject: MinecraftEdu Message-ID: <60a744d6-4994-41c3-a3bc-635cc7d665c3n at googlegroups.com> Content-Type: text/plain; charset="UTF-8" Hello, I'm new to MinecraftEDU programming with Python. I'm wondering if anyone can recommend how to get started with creating lessons and how to get started programming in MinecraftEDU? ------------------------------ Message: 5 Date: Fri, 9 Dec 2022 08:26:12 +1100 From: Cameron Simpson To: Jelena Ili? Cc: python-list at python.org Subject: Re: MinecraftEdu Message-ID: Content-Type: text/plain; charset=utf-8; format=flowed On 08Dec2022 12:12, Jelena Ili? wrote: >I'm new to MinecraftEDU programming with Python. I'm wondering if >anyone can recommend how to get started with creating lessons and how >to get started programming in MinecraftEDU? Had you started here? https://education.minecraft.net/en-us/resources/computer-science-subject-kit/python-101 That's just from a web search, I've not used it. Cheers, Cameron Simpson ------------------------------ Message: 6 Date: Thu, 8 Dec 2022 18:05:02 -0800 (PST) From: Jach Feng To: python-list at python.org Subject: Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully? Message-ID: Content-Type: text/plain; charset="UTF-8" Jach Feng ? 2022?12?7? ?????10:23:20 [UTC+8] ?????? > s0 = r'\x0a' > At this moment it was done by > > def to1byte(matchobj): > ....return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > But, is it that difficult on doing this simple thing? > > --Jach The whold story is, I had a script which accepts an argparse's positional argument. I like this argument may have control character embedded in when required. So I make a post "How to enter escape character in a positional string argument from the command line? on DEC05. But there is no response. I assume that there is no way of doing it and I have to convert it later after I get the whole string from the command line. I made this convertion using the chr(int(...)) method but not satisfied with. That why this post came out. At this moment the conversion is done almost the same as Peter's codecs.decode() method but without the need of importing codecs module:-) def to1byte(matchobj): ....return matchobj.group(0).encode().decode("unicode-escape") ------------------------------ Message: 7 Date: Fri, 9 Dec 2022 03:49:58 +0000 From: Axy To: python-list at python.org Subject: Re: Panoptisch - A way to understand your project's dependencies and find malicious packages Message-ID: <146e747f-bb2b-29e6-b8df-93698495c46a at declassed.art> Content-Type: text/plain; charset=UTF-8; format=flowed On 08/12/2022 17:52, Aarnav Mahavir Bos wrote: > Hello all, > > I would like to share Panoptisch, a FOSS(Free and Open Source Software) > tool I've been working on. Hi there, I added your project to my watch list, keep on your work. A couple of points: First, I glanced at the code and in the very first file I opened, https://github.com/R9295/panoptisch/blob/master/panoptisch/__init__.py, I see main(). I usually place such a code in __main__.py Second, in addition to AST analysis it would be nice to implement a sandbox with import hooks. Axy. ------------------------------ Message: 8 Date: Fri, 9 Dec 2022 13:29:06 +0000 From: "Weatherby,Gerard" To: Jach Feng , "python-list at python.org" Subject: Re: How to convert a raw string r'\xdd' to '\xdd' more gracefully? Message-ID: Content-Type: text/plain; charset="iso-2022-jp" That?s actually more of a shell question than a Python question. How you pass certain control characters is going to depend on the shell, operating system, and possibly the keyboard you?re using. (e.g. https://www.alt-codes.net). Here?s a sample program. The dashes are to help show the boundaries of the string #!/usr/bin/env python3 import argparse import logging parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('data') args = parser.parse_args() print(f'Input\n: -{args.data}- length {len(args.data)}') for c in args.data: print(f'{ord(c)} ',end='') print() Using bash on Linux: ./cl.py '^M ' Input - - length 3 13 32 10 From: Python-list on behalf of Jach Feng Date: Thursday, December 8, 2022 at 9:31 PM To: python-list at python.org Subject: Re: How to convert a raw string r'xdd' to 'xdd' more gracefully? *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Jach Feng ? 2022?12?7? ?????10:23:20 [UTC+8] ?????? > s0 = r'\x0a' > At this moment it was done by > > def to1byte(matchobj): > ....return chr(int('0x' + matchobj.group(1), 16)) > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > But, is it that difficult on doing this simple thing? > > --Jach The whold story is, I had a script which accepts an argparse's positional argument. I like this argument may have control character embedded in when required. So I make a post "How to enter escape character in a positional string argument from the command line? on DEC05. But there is no response. I assume that there is no way of doing it and I have to convert it later after I get the whole string from the command line. I made this convertion using the chr(int(...)) method but not satisfied with. That why this post came out. At this moment the conversion is done almost the same as Peter's codecs.decode() method but without the need of importing codecs module:-) def to1byte(matchobj): ....return matchobj.group(0).encode().decode("unicode-escape") -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hcg9ULzmtVUzMJ87Emlfsf6PGAfC-MEzUs3QQNVzWwK4aWDEtePG34hRX0ZFVvWcqZXRcM67JkkIg-l-K9vB$ ------------------------------ Message: 9 Date: Fri, 9 Dec 2022 07:38:57 -0800 (PST) From: Dan Kolis To: python-list at python.org Subject: Re: Panoptisch - A way to understand your project's dependencies and find malicious packages Message-ID: <8903c97c-26a0-486b-a1b8-f4330659f2a3n at googlegroups.com> Content-Type: text/plain; charset="UTF-8" I think it needs a built in viewer or at least a human readable output, or nobody will go through the trouble to use it. Other that that, maybe a pretty good idea, sure ------------------------------ Subject: Digest Footer -- https://mail.python.org/mailman/listinfo/python-list ------------------------------ End of Python-list Digest, Vol 231, Issue 9 ******************************************* From PythonList at DancesWithMice.info Fri Dec 9 15:30:55 2022 From: PythonList at DancesWithMice.info (dn) Date: Sat, 10 Dec 2022 09:30:55 +1300 Subject: New computer, new Python In-Reply-To: <1670605996.031430820@webmail.emailsrvr.com> References: <1670605996.031430820@webmail.emailsrvr.com> Message-ID: On 10/12/2022 06.13, kermit at polaris.net wrote: > > > Hello. I've downloaded the new Python to my new Computer, and the new Python mystifies me. > > Instead of an editor, it looks like a Dos executable program. > > How can I write my own Python Functions and subroutines in the new Python? > > It is version 3.11 (64 bit). Have you invested time in the documentation? https://docs.python.org/3/using/windows.html -- Regards, =dn From nospam at dfs.com Fri Dec 9 15:36:44 2022 From: nospam at dfs.com (DFS) Date: Fri, 9 Dec 2022 15:36:44 -0500 Subject: New computer, new Python In-Reply-To: References: <1670605996.031430820@webmail.emailsrvr.com> Message-ID: On 12/9/2022 12:13 PM, kermit at polaris.net wrote: > > > Hello. I've downloaded the new Python to my new Computer, and the new Python mystifies me. > > Instead of an editor, it looks like a Dos executable program. python.exe is a Windows executable. > How can I write my own Python Functions and subroutines in the new Python? Open a text editor and write your own functions and subs. Save the file as prog.py. From the command line (not from inside the Python shell), type: $ python prog.py > It is version 3.11 (64 bit). The latest and greatest. Significantly sped up vs 3.10. From gweatherby at uchc.edu Fri Dec 9 17:03:19 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Fri, 9 Dec 2022 22:03:19 +0000 Subject: New computer, new Python In-Reply-To: References: <1670605996.031430820@webmail.emailsrvr.com> Message-ID: Python in an IDE is much easier in the long run. We use PyCharm ? there?s a free version: https://www.jetbrains.com/pycharm/download/#section=windows From: Python-list on behalf of DFS Date: Friday, December 9, 2022 at 4:36 PM To: python-list at python.org Subject: Re: New computer, new Python *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On 12/9/2022 12:13 PM, kermit at polaris.net wrote: > > > Hello. I've downloaded the new Python to my new Computer, and the new Python mystifies me. > > Instead of an editor, it looks like a Dos executable program. python.exe is a Windows executable. > How can I write my own Python Functions and subroutines in the new Python? Open a text editor and write your own functions and subs. Save the file as prog.py. From the command line (not from inside the Python shell), type: $ python prog.py > It is version 3.11 (64 bit). The latest and greatest. Significantly sped up vs 3.10. -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!ncQETnsgLM_I29jKwV8WUZPhvn7g3Q5jBnkT_S0CmOf0KCORpl5xSLtMM8ZtE8gMsORNxCKhq01pCww$ From bowman at montana.com Fri Dec 9 16:56:34 2022 From: bowman at montana.com (rbowman) Date: 9 Dec 2022 21:56:34 GMT Subject: New computer, new Python References: <1670605996.031430820@webmail.emailsrvr.com> Message-ID: On Fri, 9 Dec 2022 12:13:16 -0500 (EST), kermit at polaris.net wrote: > How can I write my own Python Functions and subroutines in the new > Python? Personally, I would go with VS Code: https://learn.microsoft.com/en-us/training/modules/python-install-vscode/ It supports virtual environments nicely: https://code.visualstudio.com/docs/python/environments From mats at wichmann.us Fri Dec 9 17:38:59 2022 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 9 Dec 2022 15:38:59 -0700 Subject: New computer, new Python In-Reply-To: References: <1670605996.031430820@webmail.emailsrvr.com> Message-ID: On 12/9/22 14:56, rbowman wrote: > On Fri, 9 Dec 2022 12:13:16 -0500 (EST), kermit at polaris.net wrote: > >> How can I write my own Python Functions and subroutines in the new >> Python? > > Personally, I would go with VS Code: > > https://learn.microsoft.com/en-us/training/modules/python-install-vscode/ > > It supports virtual environments nicely: > > https://code.visualstudio.com/docs/python/environments Possibly in some previous setup, IDLE was the thing you opened. IDLE *is* an IDE - maybe not the fanciest one available, but it's written in Python and comes with the Python distribution. I don't disagree with the two fine editors/IESs suggested previously (I use both of them, in slightly different circumstances), but IDLE works well too. Try telling windows to find and open idle and see if that's more what you are expecting? From list1 at tompassin.net Fri Dec 9 17:36:10 2022 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 9 Dec 2022 17:36:10 -0500 Subject: New computer, new Python In-Reply-To: <1670605996.031430820@webmail.emailsrvr.com> References: <1670605996.031430820@webmail.emailsrvr.com> Message-ID: It sounds like on your old computer, you used some kind of program to write python code and perhaps to run it too. It would help if you could say what that program was. Python itself - the actual program called "python.exe" on Windows - runs a Python interpreter inside a Windows console window. That's what you see when you run "python". You probably would like to run the same editor as you used on the old computer, but unless you can say what that program was, we can't help you. The best we can do is to suggest various alternative programs and editors, as several people have already done. On 12/9/2022 12:13 PM, kermit at polaris.net wrote: > > > Hello. I've downloaded the new Python to my new Computer, and the new Python mystifies me. > > Instead of an editor, it looks like a Dos executable program. > > How can I write my own Python Functions and subroutines in the new Python? > > It is version 3.11 (64 bit). > > Kermit > > > > > -----Original Message----- > From: python-list-request at python.org > Sent: Friday, December 9, 2022 12:00pm > To: python-list at python.org > Subject: Python-list Digest, Vol 231, Issue 9 > > > > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > > Today's Topics: > > 1. Re: How to convert a raw string r'\xdd' to '\xdd' more > gracefully? (Jach Feng) > 2. Re: Nonuniform PRNG? (Stefan Ram) > 3. Panoptisch - A way to understand your project's dependencies > and find malicious packages (Aarnav Mahavir Bos) > 4. MinecraftEdu (Jelena Ili?) > 5. Re: MinecraftEdu (Cameron Simpson) > 6. Re: How to convert a raw string r'\xdd' to '\xdd' more > gracefully? (Jach Feng) > 7. Re: Panoptisch - A way to understand your project's > dependencies and find malicious packages (Axy) > 8. Re: How to convert a raw string r'\xdd' to '\xdd' more > gracefully? (Weatherby,Gerard) > 9. Re: Panoptisch - A way to understand your project's > dependencies and find malicious packages (Dan Kolis) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Thu, 8 Dec 2022 00:56:42 -0800 (PST) > From: Jach Feng > To: python-list at python.org > Subject: Re: How to convert a raw string r'\xdd' to '\xdd' more > gracefully? > Message-ID: > Content-Type: text/plain; charset="UTF-8" > > Jach Feng ? 2022?12?7? ?????10:23:20 [UTC+8] ?????? >> s0 = r'\x0a' >> At this moment it was done by >> >> def to1byte(matchobj): >> ....return chr(int('0x' + matchobj.group(1), 16)) >> s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) >> >> But, is it that difficult on doing this simple thing? >> >> --Jach > I find another answer on the web. > >>>> s0 = r'\x0a' >>>> s0.encode('Latin-1').decode('unicode-escape') > '\n' > > > ------------------------------ > > Message: 2 > Date: 8 Dec 2022 12:17:22 GMT > From: ram at zedat.fu-berlin.de (Stefan Ram) > To: python-list at python.org > Subject: Re: Nonuniform PRNG? > Message-ID: > Content-Type: text/plain; charset=UTF-8 > > "Robert E. Beaudoin" writes: >> One thing you could do is to apply von Neumann de-biasing to convert a >> string of output bits from your biased PRNG to an unbiased string, and >> test the de-biased output. > > Some non-uniform generators are based on uniform generators > whose output then is warped by the application of some function. > > If one has access to the underlying uniform generator used, > one can test this with the algorithms for uniform generators. > > > > > ------------------------------ > > Message: 3 > Date: Thu, 8 Dec 2022 18:52:29 +0100 > From: Aarnav Mahavir Bos > To: python-list at python.org > Subject: Panoptisch - A way to understand your project's dependencies > and find malicious packages > Message-ID: > > Content-Type: text/plain; charset="UTF-8" > > Hello all, > > I would like to share Panoptisch, a FOSS(Free and Open Source Software) > tool I've been working on. > > We all may have encountered the issue of not having a clear dependency tree > or not being sure of the modules our dependencies and sub-dependencies are > using. > > Some of us may have also heard of supply chain attacks, where open source > projects are hijacked to distribute malicious code masquerading as the > original package. This can happen deep down in the dependency chain. > > Panoptisch was born out of the need to accurately verify the modules used > in my project. > It recursively scans a Python module or file to find modules used and > exports a report in JSON which can be parsed for analysis. > > For example, should your yaml parser, or it's sub-dependencies import > socket/os? should your markdown renderer or it's sub-dependencies import > sys/importlib? *Probably not.* > > Panoptisch is in early stages, has known limitations and is looking for > help! I would love feedback, contributions, and most important of all, > rigorous testing! > > I would also love to help you integrate this tool in your workflow to write > more secure software. > > Link: https://github.com/R9295/panoptisch > Short Demo: https://www.youtube.com/watch?v=bDJWl_odXx0 > > Thanks and Regards, > aarnav > > > ------------------------------ > > Message: 4 > Date: Thu, 8 Dec 2022 12:12:47 -0800 (PST) > From: Jelena Ili? > To: python-list at python.org > Subject: MinecraftEdu > Message-ID: <60a744d6-4994-41c3-a3bc-635cc7d665c3n at googlegroups.com> > Content-Type: text/plain; charset="UTF-8" > > Hello, > I'm new to MinecraftEDU programming with Python. I'm wondering if anyone can recommend how to get started with creating lessons and how to get started programming in MinecraftEDU? > > > ------------------------------ > > Message: 5 > Date: Fri, 9 Dec 2022 08:26:12 +1100 > From: Cameron Simpson > To: Jelena Ili? > Cc: python-list at python.org > Subject: Re: MinecraftEdu > Message-ID: > Content-Type: text/plain; charset=utf-8; format=flowed > > On 08Dec2022 12:12, Jelena Ili? wrote: >> I'm new to MinecraftEDU programming with Python. I'm wondering if >> anyone can recommend how to get started with creating lessons and how >> to get started programming in MinecraftEDU? > > Had you started here? > https://education.minecraft.net/en-us/resources/computer-science-subject-kit/python-101 > > That's just from a web search, I've not used it. > > Cheers, > Cameron Simpson > > > ------------------------------ > > Message: 6 > Date: Thu, 8 Dec 2022 18:05:02 -0800 (PST) > From: Jach Feng > To: python-list at python.org > Subject: Re: How to convert a raw string r'\xdd' to '\xdd' more > gracefully? > Message-ID: > Content-Type: text/plain; charset="UTF-8" > > Jach Feng ? 2022?12?7? ?????10:23:20 [UTC+8] ?????? >> s0 = r'\x0a' >> At this moment it was done by >> >> def to1byte(matchobj): >> ....return chr(int('0x' + matchobj.group(1), 16)) >> s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) >> >> But, is it that difficult on doing this simple thing? >> >> --Jach > The whold story is, > > I had a script which accepts an argparse's positional argument. I like this argument may have control character embedded in when required. So I make a post "How to enter escape character in a positional string argument from the command line? on DEC05. But there is no response. I assume that there is no way of doing it and I have to convert it later after I get the whole string from the command line. > > I made this convertion using the chr(int(...)) method but not satisfied with. That why this post came out. > > At this moment the conversion is done almost the same as Peter's codecs.decode() method but without the need of importing codecs module:-) > > def to1byte(matchobj): > ....return matchobj.group(0).encode().decode("unicode-escape") > > > ------------------------------ > > Message: 7 > Date: Fri, 9 Dec 2022 03:49:58 +0000 > From: Axy > To: python-list at python.org > Subject: Re: Panoptisch - A way to understand your project's > dependencies and find malicious packages > Message-ID: <146e747f-bb2b-29e6-b8df-93698495c46a at declassed.art> > Content-Type: text/plain; charset=UTF-8; format=flowed > > On 08/12/2022 17:52, Aarnav Mahavir Bos wrote: >> Hello all, >> >> I would like to share Panoptisch, a FOSS(Free and Open Source Software) >> tool I've been working on. > > Hi there, > > I added your project to my watch list, keep on your work. > > A couple of points: > > First, I glanced at the code and in the very first file I opened, > https://github.com/R9295/panoptisch/blob/master/panoptisch/__init__.py, > I see main(). I usually place such a code in __main__.py > > Second, in addition to AST analysis it would be nice to implement a > sandbox with import hooks. > > Axy. > > > > ------------------------------ > > Message: 8 > Date: Fri, 9 Dec 2022 13:29:06 +0000 > From: "Weatherby,Gerard" > To: Jach Feng , "python-list at python.org" > > Subject: Re: How to convert a raw string r'\xdd' to '\xdd' more > gracefully? > Message-ID: > > > Content-Type: text/plain; charset="iso-2022-jp" > > That?s actually more of a shell question than a Python question. How you pass certain control characters is going to depend on the shell, operating system, and possibly the keyboard you?re using. (e.g. https://www.alt-codes.net). > > Here?s a sample program. The dashes are to help show the boundaries of the string > > #!/usr/bin/env python3 > import argparse > import logging > > > parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) > parser.add_argument('data') > args = parser.parse_args() > print(f'Input\n: -{args.data}- length {len(args.data)}') > for c in args.data: > print(f'{ord(c)} ',end='') > print() > > > Using bash on Linux: > > ./cl.py '^M > ' > Input > - > - length 3 > 13 32 10 > > > From: Python-list on behalf of Jach Feng > Date: Thursday, December 8, 2022 at 9:31 PM > To: python-list at python.org > Subject: Re: How to convert a raw string r'xdd' to 'xdd' more gracefully? > *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > > Jach Feng ? 2022?12?7? ?????10:23:20 [UTC+8] ?????? >> s0 = r'\x0a' >> At this moment it was done by >> >> def to1byte(matchobj): >> ....return chr(int('0x' + matchobj.group(1), 16)) >> s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) >> >> But, is it that difficult on doing this simple thing? >> >> --Jach > The whold story is, > > I had a script which accepts an argparse's positional argument. I like this argument may have control character embedded in when required. So I make a post "How to enter escape character in a positional string argument from the command line? on DEC05. But there is no response. I assume that there is no way of doing it and I have to convert it later after I get the whole string from the command line. > > I made this convertion using the chr(int(...)) method but not satisfied with. That why this post came out. > > At this moment the conversion is done almost the same as Peter's codecs.decode() method but without the need of importing codecs module:-) > > def to1byte(matchobj): > ....return matchobj.group(0).encode().decode("unicode-escape") > -- > https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hcg9ULzmtVUzMJ87Emlfsf6PGAfC-MEzUs3QQNVzWwK4aWDEtePG34hRX0ZFVvWcqZXRcM67JkkIg-l-K9vB$ > > > ------------------------------ > > Message: 9 > Date: Fri, 9 Dec 2022 07:38:57 -0800 (PST) > From: Dan Kolis > To: python-list at python.org > Subject: Re: Panoptisch - A way to understand your project's > dependencies and find malicious packages > Message-ID: <8903c97c-26a0-486b-a1b8-f4330659f2a3n at googlegroups.com> > Content-Type: text/plain; charset="UTF-8" > > I think it needs a built in viewer or at least a human readable output, or nobody will go through the trouble to use it. > > Other that that, maybe a pretty good idea, sure > > > > ------------------------------ > > Subject: Digest Footer > From jfong at ms4.hinet.net Fri Dec 9 21:06:54 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Fri, 9 Dec 2022 18:06:54 -0800 (PST) Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: Message-ID: <1b7bc8dd-06cd-4f2a-897f-76fd6f0f7ec9n@googlegroups.com> Weatherby,Gerard ? 2022?12?9? ?????9:36:18 [UTC+8] ?????? > That?s actually more of a shell question than a Python question. How you pass certain control characters is going to depend on the shell, operating system, and possibly the keyboard you?re using. (e.g. https://www.alt-codes.net). > > Here?s a sample program. The dashes are to help show the boundaries of the string > > #!/usr/bin/env python3 > import argparse > import logging > > > parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) > parser.add_argument('data') > args = parser.parse_args() > print(f'Input\n: -{args.data}- length {len(args.data)}') > for c in args.data: > print(f'{ord(c)} ',end='') > print() > > > Using bash on Linux: > > ./cl.py '^M > ' > Input > - > - length 3 > 13 32 10 > From: Python-list on behalf of Jach Feng > Date: Thursday, December 8, 2022 at 9:31 PM > To: pytho... at python.org > Subject: Re: How to convert a raw string r'xdd' to 'xdd' more gracefully? > *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > Jach Feng ? 2022?12?7? ?????10:23:20 [UTC+8] ?????? > > s0 = r'\x0a' > > At this moment it was done by > > > > def to1byte(matchobj): > > ....return chr(int('0x' + matchobj.group(1), 16)) > > s1 = re.sub(r'\\x([0-9a-fA-F]{2})', to1byte, s0) > > > > But, is it that difficult on doing this simple thing? > > > > --Jach > The whold story is, > > I had a script which accepts an argparse's positional argument. I like this argument may have control character embedded in when required. So I make a post "How to enter escape character in a positional string argument from the command line? on DEC05. But there is no response. I assume that there is no way of doing it and I have to convert it later after I get the whole string from the command line. > > I made this convertion using the chr(int(...)) method but not satisfied with. That why this post came out. > > At this moment the conversion is done almost the same as Peter's codecs.decode() method but without the need of importing codecs module:-) > > def to1byte(matchobj): > ....return matchobj.group(0).encode().decode("unicode-escape") > -- > https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hcg9ULzmtVUzMJ87Emlfsf6PGAfC-MEzUs3QQNVzWwK4aWDEtePG34hRX0ZFVvWcqZXRcM67JkkIg-l-K9vB$ > That?s actually more of a shell question than a Python question. How you pass certain control characters is going to depend on the shell, operating system, and possibly the keyboard you?re using. (e.g. https://www.alt-codes.net). You are right, that's why I found later that it's easier to enter it using a preferred pattern. But there is a case, as moi mentioned in his previous post, will cause failure when a Windows path in the form of \xdd just happen in the string:-( From jfong at ms4.hinet.net Fri Dec 9 21:12:41 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Fri, 9 Dec 2022 18:12:41 -0800 (PST) Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: References: Message-ID: <6d435f5a-f8ab-4f65-acdb-7996eff9fc25n@googlegroups.com> moi ? 2022?12?9? ?????11:41:20 [UTC+8] ?????? > PS C:\humour> py38 sysargwithliteral.py a\x0ab\x09c\x0a\x80uro\x0ax\x08z cp1252 > a > b c > ?uro > z > > PS C:\humour> $a = py38 sysargwithliteral.py a\x0ab\x09c\x0a\x80uro\x0ax\x08z cp1252 > > PS C:\humour> licp($a) > a U+0061 > b U+0062 > U+0009 > c U+0063 > ? U+20AC > u U+0075 > r U+0072 > o U+006F > x U+0078 > U+0008 > z U+007A > > PS C:\humour> > > PS C:\humour> py38 sysargwithliteral.py a\u000ab\u0009c\u000a\u20acuro\u000ax\u0008z\u000aend\U0001f60a unicode > a > b c > ?uro > z > end? > > PS C:\humour> > > PS C:\humour> py38 sysargwithliteral.py a\x0ab\x09c\x0a\x80uro\x0ax\x08z cp1252 | py38 -c "import sys; s = sys.stdin.read(); print(s.rstrip())" > a > b c > ?uro > z > > PS C:\humour> > Note: In a terminal "\t" is correct. Where is the sysargwithliteral.py? From axy at declassed.art Sat Dec 10 01:36:01 2022 From: axy at declassed.art (Axy) Date: Sat, 10 Dec 2022 06:36:01 +0000 Subject: Announcing Clabate 0.5.0: minimalistic class-based templates for Python Message-ID: Hi there, although it's quite old my side project, it has reached the point where I don't want to add anything more. It's a simple template system based on standard string formatting. You declare your template strings as class attributes and they are formatted in the right order. For dynamic content you can use class properties, and inline invocations, such as 'hello, {my_db:get_name({person_id!r})}' https://github.com/declassed-art/clabate Axy From h.goebel at crazy-compilers.com Sat Dec 10 12:17:13 2022 From: h.goebel at crazy-compilers.com (Hartmut Goebel) Date: Sat, 10 Dec 2022 18:17:13 +0100 Subject: ANN: pdfdecrypt 1.0 Message-ID: <00201355-03de-1f6d-95a6-93f65ad94fdd@crazy-compilers.com> I'm pleased to announce pdfdecrypt 1.0, a command line tool to remove passwords from PDF documents.? It will read the encrypted document, ask for the password and write the decrypted document without touching any internal structure. :Licence:??? GNU Affero General Public License v3 or later (AGPLv3+) :Homepage:?? https://pdfdecrypt.readthedocs.io/ :Repository: https://gitlab.com/pdftools/pdfdecrypt/ Download --------------- :Quick Installation: ??? pip install -U pdfdecrypt Relevant Changes since last release --------------------------------------- * Initial release -- Regards Hartmut Goebel | Hartmut Goebel | h.goebel at crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible | From martinp.dipaola at gmail.com Sun Dec 11 08:57:36 2022 From: martinp.dipaola at gmail.com (Martin Di Paola) Date: Sun, 11 Dec 2022 10:57:36 -0300 Subject: on the python paradox In-Reply-To: References: Message-ID: <20221211135736.i2s2j3wndzxlrxxf@gmail.com> >On Mon, Dec 05, 2022 at 10:37:39PM -0300, Sabrina Almod?var wrote: >> The Python Paradox >> Paul Graham >> August 2004 >> >>[SNIP] >> >>Hence what, for lack of a better name, I'll call the Python paradox: >>if a company chooses to write its software in a comparatively >>esoteric language, they'll be able to hire better programmers, >>because they'll attract only those who cared enough to learn it. And >>for programmers the paradox is even more pronounced: the language to >>learn, if you want to get a good job, is a language that people >>don't learn merely to get a job. >> >>[SNIP] I don't think that an esoteric language leads to better programmers. I know really good people that work mostly in assembly which by today standard would be considered "esoteric". They are really good at their field but they write shitty code in higher languages as python. That same goes for the other direction: I saw Ruby programmers writing C code and trust me, it didn't result in good quality code. I would be more inclined to think that a good programmer is not the one that knows an esoteric language but the one that can jump from one programming paradigm to another. And when I say "jump" I mean that he/she can understand the problem to solve, find the best tech stack to solve it and do it in an efficient manner using that tech stack correctly. It is in the "using that tech stack correctly" where some programmers that "think" they know languages A, B and C get it wrong. Just writing code that "compiles" and "it does not immediately crash" is not enough to say that "you are using the tech stack correctly". On Wed, Dec 07, 2022 at 10:58:09AM -0500, David Lowry-Duda wrote: >On Mon, Dec 05, 2022 at 10:37:39PM -0300, Sabrina Almod?var wrote: >> The Python Paradox >> Paul Graham >> August 2004 >> >>[SNIP] >> >>Hence what, for lack of a better name, I'll call the Python paradox: >>if a company chooses to write its software in a comparatively >>esoteric language, they'll be able to hire better programmers, >>because they'll attract only those who cared enough to learn it. And >>for programmers the paradox is even more pronounced: the language to >>learn, if you want to get a good job, is a language that people >>don't learn merely to get a job. >> >>[SNIP] > >I wonder what the appropriately esoteric language is today? > >We can sort of think of go/rust as esoteric versions of C/C++. But >what would be the esoteric python? > >Perhaps Julia? I don't know of any large software projects happening >in julia world that aren't essentially scientific computing libraries >(but this is because *I* work mostly with scientific computing >libraries and sometimes live under a rock). > >- DLD >-- >https://mail.python.org/mailman/listinfo/python-list From cl at isbd.net Sun Dec 11 05:09:59 2022 From: cl at isbd.net (Chris Green) Date: Sun, 11 Dec 2022 10:09:59 +0000 Subject: Does one have to use curses to read single characters from keyboard? Message-ID: Is the only way to read single characters from the keyboard to use curses.cbreak() or curses.raw()? If so how do I then read characters, it's not at all obvious from the curses documentation as that seems to think I'm using a GUI in some shape or form. All I actually want to do is get 'Y' or 'N' answers to questions on the command line. Searching for ways to do this produces what seem to me rather clumsy ways of doing it. -- Chris Green ? From nospam at dfs.com Sun Dec 11 07:37:56 2022 From: nospam at dfs.com (DFS) Date: Sun, 11 Dec 2022 07:37:56 -0500 Subject: Does one have to use curses to read single characters from keyboard? In-Reply-To: References: Message-ID: On 12/11/2022 5:09 AM, Chris Green wrote: > Is the only way to read single characters from the keyboard to use > curses.cbreak() or curses.raw()? If so how do I then read characters, > it's not at all obvious from the curses documentation as that seems to > think I'm using a GUI in some shape or form. > > All I actually want to do is get 'Y' or 'N' answers to questions on > the command line. > > Searching for ways to do this produces what seem to me rather clumsy > ways of doing it. resp = 'x' while resp.lower() not in 'yn': resp = input("Did you say Y or did you say N?: ") From cl at isbd.net Sun Dec 11 08:59:27 2022 From: cl at isbd.net (Chris Green) Date: Sun, 11 Dec 2022 13:59:27 +0000 Subject: Does one have to use curses to read single characters from keyboard? References: Message-ID: Stefan Ram wrote: > Chris Green writes: > >Is the only way to read single characters from the keyboard to use > >curses.cbreak() or curses.raw()? If so how do I then read characters, > > It seems that you want to detect keypresses and not read > characters from a line-buffered console with editing > features. > > Curses is not portable IIRC. A more portable means would > be to use tkinter with the "bind" function to bind keys. > > >All I actually want to do is get 'Y' or 'N' answers to questions on > >the command line. > > answer = input( 'Format drive C: (Y/N)?' ) > ... and therein lies the fundamental problem, you have to type Y or N followed by Return. See my own follow-up though. -- Chris Green ? From oscar.j.benjamin at gmail.com Sun Dec 11 12:19:53 2022 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 11 Dec 2022 17:19:53 +0000 Subject: Does one have to use curses to read single characters from keyboard? In-Reply-To: References: Message-ID: On Sun, 11 Dec 2022 at 15:55, Chris Green wrote: > > Is the only way to read single characters from the keyboard to use > curses.cbreak() or curses.raw()? If so how do I then read characters, > it's not at all obvious from the curses documentation as that seems to > think I'm using a GUI in some shape or form. > > All I actually want to do is get 'Y' or 'N' answers to questions on > the command line. > > Searching for ways to do this produces what seem to me rather clumsy > ways of doing it. What you are asking for is known as getch. On Windows Python's msvcrt module provides precisely this function. There are ways to do it on non-Windows platforms but nothing as simple as the getch function is in the stdlib. Some modules and recipes are available which I guess it what you've already seen: https://pypi.org/project/getch/ https://github.com/joeyespo/py-getch https://stackoverflow.com/questions/510357/how-to-read-a-single-character-from-the-user This seems to be the most well maintained option: https://pypi.org/project/readchar/ I've often thought that getch was a good candidate for the stdlib. There are plenty of recipes around but it would ideally just be available as a cross platform function. Using curses would have been overkill in any of my use cases where I really just wanted getch to make a more efficient interface for a terminal program having some limited interactivity. Actually slightly more than getch is readchar's readkey which also works for pressing non-character keys. There were times in the past where I might have used that if I'd known about it. -- Oscar From menyland at gmail.com Sun Dec 11 12:34:25 2022 From: menyland at gmail.com (Chris Nyland) Date: Sun, 11 Dec 2022 12:34:25 -0500 Subject: Does one have to use curses to read single characters from keyboard? In-Reply-To: References: Message-ID: You should try the input function. I use it all the time. It does require the user to hit enter but that is pretty typical of that kind of interface. So I would write a loop like while True: answer = input("Please answer the question (y/n):") if answer == 'y': break Chris On Sun, Dec 11, 2022 at 11:03 AM Stefan Ram wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: > >import tkinter > > This two-liner allows to answer with just one keypress ([Y]/[N]) here. > > import tkinter.messagebox > tkinter.messagebox.askyesno( "Question", "Format harddisk?" ) > > > -- > https://mail.python.org/mailman/listinfo/python-list > From antoon.pardon at vub.be Sun Dec 11 13:00:36 2022 From: antoon.pardon at vub.be (Antoon Pardon) Date: Sun, 11 Dec 2022 19:00:36 +0100 Subject: Does one have to use curses to read single characters from keyboard? In-Reply-To: References: Message-ID: <2103ade1-0f0d-9036-f625-011f25516c72@vub.be> Op 11/12/2022 om 12:32 schreef Stefan Ram: > ram at zedat.fu-berlin.de (Stefan Ram) writes: >> Curses is not portable IIRC. A more portable means would >> be to use tkinter with the "bind" function to bind keys. > import tkinter > > text = tkinter.Text() > text.pack() > text.bind\ > ( "", > lambda event: > text.insert > ( tkinter.END, "Y\nFormatting drive C:\n...\n" )or "break" ) > text.insert( tkinter.END, "Format drive C:?\n" ) > text.focus() > > tkinter.mainloop() > > Not allowing users to edit their keypresses before confirming > them with [Return]. What could possibly go wrong? Nothing that can't go wrong otherwise. It is my experience that when a [Return] is needed, people just type in a two key combination. They don't type one key, then check, then type [Return]. So in practice the same things go wrong, either way. -- Antoon Pardon. From salmodovar at ligumu.com Sun Dec 11 13:22:11 2022 From: salmodovar at ligumu.com (=?UTF-8?Q?Sabrina_Almod=c3=b3var?=) Date: Sun, 11 Dec 2022 15:22:11 -0300 Subject: on the python paradox References: <20221211135736.i2s2j3wndzxlrxxf@gmail.com> Message-ID: On 11/12/2022 10:57, Martin Di Paola wrote: >> On Mon, Dec 05, 2022 at 10:37:39PM -0300, Sabrina Almod?var wrote: >>> ??????????????????????? The Python Paradox >>> ?????????????????????????? Paul Graham >>> ?????????????????????????? August 2004 >>> >>> [SNIP] >>> >>> Hence what, for lack of a better name, I'll call the Python paradox: >>> if a company chooses to write its software in a comparatively >>> esoteric language, they'll be able to hire better programmers, >>> because they'll attract only those who cared enough to learn it. And >>> for programmers the paradox is even more pronounced: the language to >>> learn, if you want to get a good job, is a language that people don't >>> learn merely to get a job. >>> >>> [SNIP] > > I don't think that an esoteric language leads to better programmers. When you say this, I interpret it as a theorem, A implies B, but surely nobody would be so foolish to claim such thing, so perhaps you can review your reading or writing. > I know really good people that work mostly in assembly which by today > standard would be considered "esoteric". So, I wouldn't consider assembly esoteric, but I certainly would not try to define esoteric. > They are really good at their field but they write shitty code in higher > languages as python. I bet. If all they know is assembly, then they master very few linguistic abstractions. > That same goes for the other direction: I saw Ruby programmers writing C > code and trust me, it didn't result in good quality code. A Ruby person who doesn't know C must also know very little about machines and operating systems, so that is bound to failure in C. > I would be more inclined to think that a good programmer is not the one > that knows an esoteric language but the one that can jump from one > programming paradigm to another. That makes a lot of sense. Such person knows so many ways of expression, which most likely implies mastery of linguistic abstractions and expression. > And when I say "jump" I mean that he/she can understand the problem to > solve, find the best tech stack to solve it and do it in an efficient > manner using that tech stack correctly. Got ya. > It is in the "using that tech stack correctly" where some programmers > that "think" they know languages A, B and C get it wrong. I agree with that too. > Just writing code that "compiles" and "it does not immediately crash" is > not enough to say that "you are using the tech stack correctly". So true. Good thoughts. From cl at isbd.net Sun Dec 11 13:50:51 2022 From: cl at isbd.net (Chris Green) Date: Sun, 11 Dec 2022 18:50:51 +0000 Subject: Does one have to use curses to read single characters from keyboard? References: <2103ade1-0f0d-9036-f625-011f25516c72@vub.be> Message-ID: My solution in the end was copied from one I found that was much simpler and straightforward than most. I meant to post this earlier but it got lost somewhere:- import sys, termios, tty # # # Read a single character from teminal, specifically for 'Y/N' # fdInput = sys.stdin.fileno() termAttr = termios.tcgetattr(0) # # # Get a single character, setcbreak rather than setraw meands CTRL/C etc. still work # def getch(): sys.stdout.flush() tty.setcbreak(fdInput) ch = sys.stdin.buffer.raw.read(1).decode(sys.stdin.encoding) termios.tcsetattr(fdInput, termios.TCSAFLUSH, termAttr) sys.stdout.write(ch) return ch # # # Get a y or n answer, ignore other characters # def getyn(): ch = 'x' while ch != 'y' and ch != 'n': ch = getch().lower() return ch So getyn() reads a y or an n, ignores anything else and doesn't wait for a return key. Keyboard input operation is restored to normal after doing this. Using tty.setcbreak() rather than tty.setraw() means that CTRL/C etc. still work if things go really wrong. -- Chris Green ? From arj.python at gmail.com Sun Dec 11 15:43:05 2022 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Mon, 12 Dec 2022 00:43:05 +0400 Subject: on the python paradox In-Reply-To: References: Message-ID: I choose Python and still stick with it as default as I choose Python because of its design beauty. Typing does not mean mandatory braces. There can be an indentation-based language that is strongly typed. Python is beautiful in itself. Beautiful to look at. Source code should be easy for the average human to relate to and connect with easily. Being more alien-ware-like does not magically increase performance. Our taste and quality bar should be high after so much time has passed. I don't see a language as beautiful as it is front-end wise. "And people don't learn Python because it will get them a job; they learn it because they genuinely like to program and aren't satisfied with the languages they already know." Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius From PythonList at DancesWithMice.info Sun Dec 11 16:07:37 2022 From: PythonList at DancesWithMice.info (dn) Date: Mon, 12 Dec 2022 10:07:37 +1300 Subject: Does one have to use curses to read single characters from keyboard? In-Reply-To: References: Message-ID: On 11/12/2022 23.09, Chris Green wrote: > Is the only way to read single characters from the keyboard to use > curses.cbreak() or curses.raw()? If so how do I then read characters, > it's not at all obvious from the curses documentation as that seems to > think I'm using a GUI in some shape or form. > > All I actually want to do is get 'Y' or 'N' answers to questions on > the command line. > > Searching for ways to do this produces what seem to me rather clumsy > ways of doing it. You may like to re-ask this question over on the Python-Tutor list. The ListAdmin over there (literally) wrote the book on Python+curses... Did such research include the keyboard module? https://pypi.org/project/keyboard/ This project includes an (Enter-free) "hot-key" feature which firstly detects the specific key or key-combination, and then calls an action if/when True. (amongst other functionality) Quick read tutorial: https://www.thepythoncode.com/article/control-keyboard-python Disclaimer: have had it on my 'radar', but never actually employed. (if you have considered, will be interested to hear conclusions...) -- Regards, =dn From barry at barrys-emacs.org Sun Dec 11 17:22:45 2022 From: barry at barrys-emacs.org (Barry Scott) Date: Sun, 11 Dec 2022 22:22:45 +0000 Subject: Does one have to use curses to read single characters from keyboard? In-Reply-To: References: <2103ade1-0f0d-9036-f625-011f25516c72@vub.be> Message-ID: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> > On 11 Dec 2022, at 18:50, Chris Green wrote: > > My solution in the end was copied from one I found that was much > simpler and straightforward than most. I meant to post this earlier > but it got lost somewhere:- > > import sys, termios, tty > # > # > # Read a single character from teminal, specifically for 'Y/N' > # > fdInput = sys.stdin.fileno() > termAttr = termios.tcgetattr(0) > # > # > # Get a single character, setcbreak rather than setraw meands CTRL/C > etc. still work > # > def getch(): > sys.stdout.flush() > tty.setcbreak(fdInput) > ch = sys.stdin.buffer.raw.read(1).decode(sys.stdin.encoding) Will not work for uncode code points above 255. This is what happened when I typed ? key: :>>> a.getch() Traceback (most recent call last): File "", line 1, in File "/private/var/folders/ll/08dwwqkx6v9bcd15sh06x14w0000gn/T/a.py", line 15, in getch ch = sys.stdin.buffer.raw.read(1).decode(sys.stdin.encoding) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 0: unexpected end of data You would need to have a loop that collected all the utf-8 bytes of a single code point. You can to look at the first byte of know if the utf-8 is 1, 2, 3 or 4 bytes for a code point. Barry > termios.tcsetattr(fdInput, termios.TCSAFLUSH, termAttr) > sys.stdout.write(ch) > return ch > # > # > # Get a y or n answer, ignore other characters > # > def getyn(): > ch = 'x' > while ch != 'y' and ch != 'n': > ch = getch().lower() > return ch > > So getyn() reads a y or an n, ignores anything else and doesn't wait > for a return key. Keyboard input operation is restored to normal > after doing this. Using tty.setcbreak() rather than tty.setraw() means > that CTRL/C etc. still work if things go really wrong. > > > -- > Chris Green > ? > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sun Dec 11 17:32:49 2022 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 Dec 2022 09:32:49 +1100 Subject: Does one have to use curses to read single characters from keyboard? In-Reply-To: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> References: <2103ade1-0f0d-9036-f625-011f25516c72@vub.be> <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> Message-ID: On Mon, 12 Dec 2022 at 09:24, Barry Scott wrote: > You would need to have a loop that collected all the utf-8 bytes of a single code point. > You can to look at the first byte of know if the utf-8 is 1, 2, 3 or 4 bytes for a code point. And cope with escape sequences too - if you press an arrow key, for instance, you'll get a multi-character string to signal that. This is why it's probably easier to let someone else do the work. ChrisA From cs at cskk.id.au Sun Dec 11 17:54:11 2022 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 12 Dec 2022 09:54:11 +1100 Subject: Does one have to use curses to read single characters from keyboard? In-Reply-To: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> Message-ID: On 11Dec2022 22:22, Barry Scott wrote: >> # Get a single character, setcbreak rather than setraw meands >> CTRL/C >> etc. still work >> # >> def getch(): >> sys.stdout.flush() >> tty.setcbreak(fdInput) >> ch = sys.stdin.buffer.raw.read(1).decode(sys.stdin.encoding) > >Will not work for uncode code points above 255. Aye. But one could write a little loop to collect bytes until a complete character was received. A little experiment: >>> try: bytes((0xf0,)).decode('utf8') ... except UnicodeDecodeError as e: ... e2=e ... >>> e2 UnicodeDecodeError('utf-8', b'\xf0', 0, 1, 'unexpected end of data') >>> e2.reason 'unexpected end of data' Keep collecting while you get `UnicodeDecodeError`s with a `.reason` of 'unexpected end of data'. Can be encoding agnostic (obviously you need to _choose_ an encoding, it is needn't be utf-8). (For the OP: `UnicodeDecodeError` doesn't necessarily mean you're decoding Unicode data, you're decoding _into_ a Python string which is a Unicode string.) Cheers, Cameron Simpson From Gronicus at SGA.Ninja Mon Dec 12 01:01:43 2022 From: Gronicus at SGA.Ninja (Steve GS) Date: Mon, 12 Dec 2022 01:01:43 -0500 Subject: Subtracting dates to get hours and minutes In-Reply-To: References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> Message-ID: <003901d90def$36620a80$a3261f80$@SGA.Ninja> How do I subtract two time/dates and calculate the hours and minutes between? Steve From miked at dewhirst.com.au Mon Dec 12 03:13:02 2022 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Mon, 12 Dec 2022 19:13:02 +1100 Subject: Subtracting dates to get hours and minutes In-Reply-To: <003901d90def$36620a80$a3261f80$@SGA.Ninja> Message-ID: <4NVvlL0707znVFL@mail.python.org> I have seen vast conversations on this topic but if everything is in the same time-zone and daylight saving switchovers are not involved it is relatively straightforward.Check the timedelta docs. Or convert datetimes to ordinals and subtract then convert the result to whatever units please you.M--(Unsigned mail from my phone) -------- Original message --------From: Steve GS Date: 12/12/22 17:34 (GMT+10:00) To: python-list at python.org Subject: Subtracting dates to get hours and minutes How do I subtract two time/dates and calculate the hours and minutesbetween?Steve-- https://mail.python.org/mailman/listinfo/python-list From cl at isbd.net Sun Dec 11 16:13:19 2022 From: cl at isbd.net (Chris Green) Date: Sun, 11 Dec 2022 21:13:19 +0000 Subject: Does one have to use curses to read single characters from keyboard? References: <2103ade1-0f0d-9036-f625-011f25516c72@vub.be> Message-ID: Stefan Ram wrote: > Chris Green writes: > >import sys, termios, tty > > There might be some versions of Python and the Microsoft? > Windows operating system where "termios" is not available. > Ah, I did originally say that this was a Unix/Linux only solution but that was in my first response that got lost somewhere. -- Chris Green ? From marc at marcsnet.com Mon Dec 12 01:40:21 2022 From: marc at marcsnet.com (Marc Lucke) Date: Mon, 12 Dec 2022 17:40:21 +1100 Subject: Subtracting dates to get hours and minutes In-Reply-To: <003901d90def$36620a80$a3261f80$@SGA.Ninja> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> Message-ID: my approach would be to convert your two date/times to seconds from epoch - e.g. https://www.geeksforgeeks.org/convert-python-datetime-to-epoch/ - then subtract the number, divide the resultant by 3600 (hours) & get the modulus for minutes.? There's probably a standard function - it should be /very/ easy to do. - Marc On 12/12/2022 5:01 pm, Steve GS wrote: > How do I subtract two time/dates and calculate the hours and minutes > between? > Steve > From jfong at ms4.hinet.net Mon Dec 12 06:03:48 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Mon, 12 Dec 2022 03:03:48 -0800 (PST) Subject: How to convert a raw string r'\xdd' to '\xdd' more gracefully? In-Reply-To: <2e9969b0-7a81-46bc-995c-23c033eb6683n@googlegroups.com> References: <6d435f5a-f8ab-4f65-acdb-7996eff9fc25n@googlegroups.com> <8cf595cb-3e5b-4de2-9d3a-79ac44065cebn@googlegroups.com> <2e9969b0-7a81-46bc-995c-23c033eb6683n@googlegroups.com> Message-ID: moi ? 2022?12?12? ?????5:38:50 [UTC+8] ?????? > >>> ast.literal_eval("r'\x7a'") == ast.literal_eval("r'z'") > True > >>> ast.literal_eval("r'\xe0'") == ast.literal_eval("r'?'") > True > >>> ast.literal_eval("r'\x9c'") == ast.literal_eval("r'?'") > False > > --------- > > > >>> print(codecs.decode(r'z', 'unicode-escape')) > z > >>> print(codecs.decode(r'g\hz', 'unicode-escape')) > g\hz > >>> print(codecs.decode(r'g\az', 'unicode-escape')) > g\u0007z > >>> print(codecs.decode(r'g\nz', 'unicode-escape')) > g > z > >>> > print(codecs.decode(r'abc?', 'unicode-escape')) > abc?? > >>> I have a different result:-) >>> print(codecs.decode(r'g\hz', 'unicode-escape')) :1: DeprecationWarning: invalid escape sequence '\h' g\hz >>> print(codecs.decode(r'g\az', 'unicode-escape')) gz # with a companioning bell From cl at isbd.net Mon Dec 12 06:12:12 2022 From: cl at isbd.net (Chris Green) Date: Mon, 12 Dec 2022 11:12:12 +0000 Subject: Does one have to use curses to read single characters from keyboard? References: <2103ade1-0f0d-9036-f625-011f25516c72@vub.be> <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> Message-ID: Barry Scott wrote: > > > > On 11 Dec 2022, at 18:50, Chris Green wrote: > > > > My solution in the end was copied from one I found that was much > > simpler and straightforward than most. I meant to post this earlier > > but it got lost somewhere:- > > > > import sys, termios, tty > > # > > # > > # Read a single character from teminal, specifically for 'Y/N' > > # > > fdInput = sys.stdin.fileno() > > termAttr = termios.tcgetattr(0) > > # > > # > > # Get a single character, setcbreak rather than setraw meands CTRL/C > > etc. still work > > # > > def getch(): > > sys.stdout.flush() > > tty.setcbreak(fdInput) > > ch = sys.stdin.buffer.raw.read(1).decode(sys.stdin.encoding) > > Will not work for uncode code points above 255. > > This is what happened when I typed ? key: > > :>>> a.getch() > Traceback (most recent call last): > File "", line 1, in > File "/private/var/folders/ll/08dwwqkx6v9bcd15sh06x14w0000gn/T/a.py", line 15, in getch > ch = sys.stdin.buffer.raw.read(1).decode(sys.stdin.encoding) > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 0: unexpected end of data > Since it's just for me to use the above doesn't worry me! :-) I'd have to try quite hard to enter a multi-byte character from my keyboard so it's very unlikely to happen by mistake. -- Chris Green ? From learn2program at gmail.com Mon Dec 12 12:45:21 2022 From: learn2program at gmail.com (Alan Gauld) Date: Mon, 12 Dec 2022 17:45:21 +0000 Subject: Does one have to use curses to read single characters from keyboard? In-Reply-To: References: Message-ID: On 11/12/2022 21:07, dn wrote: > On 11/12/2022 23.09, Chris Green wrote: >> Is the only way to read single characters from the keyboard to use >> curses.cbreak() or curses.raw()? If so how do I then read characters, >> it's not at all obvious from the curses documentation as that seems to >> think I'm using a GUI in some shape or form. >> >> All I actually want to do is get 'Y' or 'N' answers to questions on >> the command line. >> >> Searching for ways to do this produces what seem to me rather clumsy >> ways of doing it. > > You may like to re-ask this question over on the Python-Tutor list. The > ListAdmin over there (literally) wrote the book on Python+curses... > > > Did such research include the keyboard module? > https://pypi.org/project/keyboard/ > > This project includes an (Enter-free) "hot-key" feature which firstly > detects the specific key or key-combination, and then calls an action > if/when True. > (amongst other functionality) > > Quick read tutorial: > https://www.thepythoncode.com/article/control-keyboard-python > > Disclaimer: have had it on my 'radar', but never actually employed. > (if you have considered, will be interested to hear conclusions...) -- 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 gweatherby at uchc.edu Mon Dec 12 12:49:32 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Mon, 12 Dec 2022 17:49:32 +0000 Subject: Subtracting dates to get hours and minutes In-Reply-To: References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> Message-ID: The difference between two datetime objects is a timedelta object. https://docs.python.org/3/library/datetime.html#timedelta-objects . It has a total_seconds() method. This is a simple task, unless one of the datetimes has a time zone specified and the other doesn?t. From: Python-list on behalf of Marc Lucke Date: Monday, December 12, 2022 at 11:37 AM To: python-list at python.org Subject: Re: Subtracting dates to get hours and minutes *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** my approach would be to convert your two date/times to seconds from epoch - e.g. https://urldefense.com/v3/__https://www.geeksforgeeks.org/convert-python-datetime-to-epoch/__;!!Cn_UX_p3!hBXQeMkZ3QYS6BI0yTHsADseWTXcDXOhKFkg35NnRMicvYQvwLo9c_ihSaTrG60LywsKQm6UNd7mAAYr$ - then subtract the number, divide the resultant by 3600 (hours) & get the modulus for minutes. There's probably a standard function - it should be /very/ easy to do. - Marc On 12/12/2022 5:01 pm, Steve GS wrote: > How do I subtract two time/dates and calculate the hours and minutes > between? > Steve > -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hBXQeMkZ3QYS6BI0yTHsADseWTXcDXOhKFkg35NnRMicvYQvwLo9c_ihSaTrG60LywsKQm6UNSbh5q0S$ From grant.b.edwards at gmail.com Mon Dec 12 13:47:13 2022 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 12 Dec 2022 10:47:13 -0800 (PST) Subject: Does one have to use curses to read single characters from keyboard? References: Message-ID: <63977731.920a0220.558eb.4863@mx.google.com> On 2022-12-11, Chris Green wrote: > Is the only way to read single characters from the keyboard to use > curses.cbreak() or curses.raw()? No. > If so how do I then read characters, Use a termios.tcsetattr() to put fd 0 into raw mode and then use os.read(). Recent versions of Python include a "tty" module that has conveniece functions to handle that: -- Grant From parejkoj at gmail.com Mon Dec 12 19:41:53 2022 From: parejkoj at gmail.com (John K. Parejko) Date: Mon, 12 Dec 2022 16:41:53 -0800 Subject: sqlite3 double quote behavior Message-ID: <8156D69B-3E35-4A75-98B5-9C3DD36AF78E@gmail.com> Asking here before I file an improvement request issue on the python GitHub: sqlite has a known misfeature with double-quoted strings, whereby they will be interpreted as string literals if they don?t match a valid identifier [1]. The note in the sqlite docs describe a way to disable this misfeature at compile time or by calling an `sqlite3_db_config` C-function, but I don?t see any way to do that in the python sqlite library [2]. Am I missing a way to manage this setting, or is it not available within python? This would be very useful to enable, so that python?s sqlite library will treat queries more like standard sql, instead of this particular version of MySQL. I was just burned by this, where some tests I?d written against an sqlite database did not fail in the way that they ?should? have, because of this double-quoted string issue. It doesn?t look like `sqlite3_db_config` is used within the python sqlite3 codebase at all, so this might not be a trivial change? I only see two references to it in the cpython github. Thank you in advance for any suggestions, John 1: https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted 2: https://docs.python.org/3/library/sqlite3.html From lal at solute.de Tue Dec 13 03:02:49 2022 From: lal at solute.de (Lars Liedtke) Date: Tue, 13 Dec 2022 09:02:49 +0100 Subject: sqlite3 double quote behavior In-Reply-To: <8156D69B-3E35-4A75-98B5-9C3DD36AF78E@gmail.com> References: <8156D69B-3E35-4A75-98B5-9C3DD36AF78E@gmail.com> Message-ID: <2da757b3-52b9-65b1-bc2d-73c55d3f5787@solute.de> Hey, this might be not the answer you are searching for at all, and it is only a mitigation. But as far as I know, sqlalchemy (and other ORMs) do that for you. I am mention sqlalchemy, because it has got a query builder as well. So you don't have to change your DB-Layer to full ORM, but you could let it build the queries for you. Of course, I know that this would mean a dependency and additional complexity. I just could not leave it unmentioned ;-) Cheers Lars 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.12.22 um 01:41 schrieb John K. Parejko: Asking here before I file an improvement request issue on the python GitHub: sqlite has a known misfeature with double-quoted strings, whereby they will be interpreted as string literals if they don?t match a valid identifier [1]. The note in the sqlite docs describe a way to disable this misfeature at compile time or by calling an `sqlite3_db_config` C-function, but I don?t see any way to do that in the python sqlite library [2]. Am I missing a way to manage this setting, or is it not available within python? This would be very useful to enable, so that python?s sqlite library will treat queries more like standard sql, instead of this particular version of MySQL. I was just burned by this, where some tests I?d written against an sqlite database did not fail in the way that they ?should? have, because of this double-quoted string issue. It doesn?t look like `sqlite3_db_config` is used within the python sqlite3 codebase at all, so this might not be a trivial change? I only see two references to it in the cpython github. Thank you in advance for any suggestions, John 1: https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted 2: https://docs.python.org/3/library/sqlite3.html From learn2program at gmail.com Tue Dec 13 03:46:48 2022 From: learn2program at gmail.com (Alan Gauld) Date: Tue, 13 Dec 2022 08:46:48 +0000 Subject: Does one have to use curses to read single characters from keyboard? In-Reply-To: References: Message-ID: On 12/12/2022 17:45, Alan Gauld wrote: Absolutely nothing apparently! But in practce I did pen some esponses to Davids post. However this list seems to strip out what I've written, its happened a few times now. Not every time but enough that I rarely post here. But I'll try once more... > On 11/12/2022 21:07, dn wrote: >> On 11/12/2022 23.09, Chris Green wrote: >>> Is the only way to read single characters from the keyboard to use >>> curses.cbreak() or curses.raw()? >> You may like to re-ask this question over on the Python-Tutor list. The >> ListAdmin over there (literally) wrote the book on Python+curses... Thanks for the plug David, but... While my book is, I think, the only one specifically for curses with Python, it's hardly a definitive tome on the subject, rather a beginner's tutorial. An expanded HowTo if you like.. >> Did such research include the keyboard module? >> https://pypi.org/project/keyboard/ There are several such modules, including a good one by Fred Lundh. They are cross platform and probably the best solution for the OP if he doesn't mind using a third party module. I think Fred's was called terminal? But its been a while I normally just use curses for anything terminal related. -- 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 roel at roelschroeven.net Tue Dec 13 03:51:07 2022 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 13 Dec 2022 09:51:07 +0100 Subject: sqlite3 double quote behavior In-Reply-To: <8156D69B-3E35-4A75-98B5-9C3DD36AF78E@gmail.com> References: <8156D69B-3E35-4A75-98B5-9C3DD36AF78E@gmail.com> Message-ID: Op 13/12/2022 om 1:41 schreef John K. Parejko: > Asking here before I file an improvement request issue on the python GitHub: > > sqlite has a known misfeature with double-quoted strings, whereby they will be interpreted as string literals if they don?t match a valid identifier [1]. The note in the sqlite docs describe a way to disable this misfeature at compile time or by calling an `sqlite3_db_config` C-function, but I don?t see any way to do that in the python sqlite library [2]. > > Am I missing a way to manage this setting, or is it not available within python? This would be very useful to enable, so that python?s sqlite library will treat queries more like standard sql, instead of this particular version of MySQL. I was just burned by this, where some tests I?d written against an sqlite database did not fail in the way that they ?should? have, because of this double-quoted string issue. > > It doesn?t look like `sqlite3_db_config` is used within the python sqlite3 codebase at all, so this might not be a trivial change? I only see two references to it in the cpython github. > Like Lars Liedtke this is not an exact answer to your question, but you can side-step the issue by using parametrized queries, i.e. instead of ??? cur.execute('SELECT name, location FROM persons WHERE name = "John Doe"') do ??? cur.execute('SELECT name, location FROM persons WHERE name = ?', ('John Doe',)) -- "Life ain't no fairy tale Just give me another ale And I'll drink to Rock 'n Roll" -- Barkeep (The Scabs) From rosuav at gmail.com Tue Dec 13 04:09:58 2022 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Dec 2022 20:09:58 +1100 Subject: sqlite3 double quote behavior In-Reply-To: References: <8156D69B-3E35-4A75-98B5-9C3DD36AF78E@gmail.com> Message-ID: On Tue, 13 Dec 2022 at 19:52, Roel Schroeven wrote: > Like Lars Liedtke this is not an exact answer to your question, but you > can side-step the issue by using parametrized queries, i.e. instead of > > cur.execute('SELECT name, location FROM persons WHERE name = "John > Doe"') > > do > > cur.execute('SELECT name, location FROM persons WHERE name = ?', > ('John Doe',)) > That's the wrong behaviour though. According to the SQL standard, the second query should be equivalent to this: cur.execute("SELECT name, location FROM persons WHERE name = 'John Doe'") What the OP wanted was like your first query, and proper DBMSes like PostgreSQL will handle it accordingly. The question is how to get SQLite3 to also do so. I don't use SQLite3 much so I'm not really one to judge, but maybe it would be worth exposing the sqlite3_db_config() function to Python? Yes, it would be more than a trivial change, but it should be reasonably straight-forward. In order to be useful, it would probably also need an associated IntEnum for all those lovely opaque numbers that define the verbs. ChrisA From list1 at tompassin.net Tue Dec 13 08:23:13 2022 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 13 Dec 2022 08:23:13 -0500 Subject: sqlite3 double quote behavior In-Reply-To: References: <8156D69B-3E35-4A75-98B5-9C3DD36AF78E@gmail.com> Message-ID: <52fe72f2-f3b5-e962-9609-89eadf7f389b@tompassin.net> On 12/13/2022 4:09 AM, Chris Angelico wrote: > On Tue, 13 Dec 2022 at 19:52, Roel Schroeven wrote: >> Like Lars Liedtke this is not an exact answer to your question, but you >> can side-step the issue by using parametrized queries, i.e. instead of >> >> cur.execute('SELECT name, location FROM persons WHERE name = "John >> Doe"') >> >> do >> >> cur.execute('SELECT name, location FROM persons WHERE name = ?', >> ('John Doe',)) >> > > That's the wrong behaviour though. According to the SQL standard, the > second query should be equivalent to this: > > cur.execute("SELECT name, location FROM persons WHERE name = 'John Doe'") > > What the OP wanted was like your first query, and proper DBMSes like > PostgreSQL will handle it accordingly. The question is how to get > SQLite3 to also do so. From reading the SQLite3 documentation on this issue (not from personal experience), in fact the second form is actually what one wants, even if SQLite3 will usually handle the first form correctly. The rule is "Use single quotes for string values and double quotes for database names such as schema, table and column names; for backwards compatibility SQLite will accept double quotes for string values, but you may get a surprise if the string value looks like a database name." > I don't use SQLite3 much so I'm not really one to judge, but maybe it > would be worth exposing the sqlite3_db_config() function to Python? > Yes, it would be more than a trivial change, but it should be > reasonably straight-forward. In order to be useful, it would probably > also need an associated IntEnum for all those lovely opaque numbers > that define the verbs. > > ChrisA From rosuav at gmail.com Tue Dec 13 09:00:21 2022 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Dec 2022 01:00:21 +1100 Subject: sqlite3 double quote behavior In-Reply-To: <52fe72f2-f3b5-e962-9609-89eadf7f389b@tompassin.net> References: <8156D69B-3E35-4A75-98B5-9C3DD36AF78E@gmail.com> <52fe72f2-f3b5-e962-9609-89eadf7f389b@tompassin.net> Message-ID: On Wed, 14 Dec 2022 at 00:30, Thomas Passin wrote: > > On 12/13/2022 4:09 AM, Chris Angelico wrote: > > On Tue, 13 Dec 2022 at 19:52, Roel Schroeven wrote: > >> Like Lars Liedtke this is not an exact answer to your question, but you > >> can side-step the issue by using parametrized queries, i.e. instead of > >> > >> cur.execute('SELECT name, location FROM persons WHERE name = "John > >> Doe"') > >> > >> do > >> > >> cur.execute('SELECT name, location FROM persons WHERE name = ?', > >> ('John Doe',)) > >> > > > > That's the wrong behaviour though. According to the SQL standard, the > > second query should be equivalent to this: > > > > cur.execute("SELECT name, location FROM persons WHERE name = 'John Doe'") > > > > What the OP wanted was like your first query, and proper DBMSes like > > PostgreSQL will handle it accordingly. The question is how to get > > SQLite3 to also do so. > > From reading the SQLite3 documentation on this issue (not from personal > experience), in fact the second form is actually what one wants, even if > SQLite3 will usually handle the first form correctly. No, the two have distinct semantics. BOTH are valid, they just mean different things. ChrisA From roel at roelschroeven.net Tue Dec 13 09:15:36 2022 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 13 Dec 2022 15:15:36 +0100 Subject: sqlite3 double quote behavior In-Reply-To: <52fe72f2-f3b5-e962-9609-89eadf7f389b@tompassin.net> References: <8156D69B-3E35-4A75-98B5-9C3DD36AF78E@gmail.com> <52fe72f2-f3b5-e962-9609-89eadf7f389b@tompassin.net> Message-ID: <86352d40-99ee-9deb-d3c8-557dfd9ccac1@roelschroeven.net> Op 13/12/2022 om 14:23 schreef Thomas Passin: > On 12/13/2022 4:09 AM, Chris Angelico wrote: >> On Tue, 13 Dec 2022 at 19:52, Roel Schroeven >> wrote: >>> Like Lars Liedtke this is not an exact answer to your question, but you >>> can side-step the issue by using parametrized queries, i.e. instead of >>> >>> ????? cur.execute('SELECT name, location FROM persons WHERE name = >>> "John >>> Doe"') >>> >>> do >>> >>> ????? cur.execute('SELECT name, location FROM persons WHERE name = ?', >>> ('John Doe',)) >>> >> >> That's the wrong behaviour though. According to the SQL standard, the >> second query should be equivalent to this: >> >> cur.execute("SELECT name, location FROM persons WHERE name = 'John >> Doe'") >> >> What the OP wanted was like your first query, and proper DBMSes like >> PostgreSQL will handle it accordingly. The question is how to get >> SQLite3 to also do so. > > From reading the SQLite3 documentation on this issue (not from > personal experience), in fact the second form is actually what one > wants, even if SQLite3 will usually handle the first form correctly.? > The rule is "Use single quotes for string values and double quotes for > database names such as schema, table and column names; for backwards > compatibility SQLite will accept double quotes for string values, but > you may get a surprise if the string value looks like a database name." What I missed at first is the case where you really want to use an identifier, not a string. Then you use double quotes, and would like to get an error ("unknown identifier" or something like that) in case of a typo, instead of the database engine silently presuming your wrongly-spelled identifier is a string. That case can't be solved with parametrized queries, and does really require the ability to enable more strict behavior. +1 to expose the sqlite3_db_config() function, or maybe just a special case for this specific option. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones From roel at roelschroeven.net Tue Dec 13 09:19:16 2022 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 13 Dec 2022 15:19:16 +0100 Subject: sqlite3 double quote behavior In-Reply-To: <86352d40-99ee-9deb-d3c8-557dfd9ccac1@roelschroeven.net> References: <8156D69B-3E35-4A75-98B5-9C3DD36AF78E@gmail.com> <52fe72f2-f3b5-e962-9609-89eadf7f389b@tompassin.net> <86352d40-99ee-9deb-d3c8-557dfd9ccac1@roelschroeven.net> Message-ID: Op 13/12/2022 om 15:15 schreef Roel Schroeven: > > +1 to expose the sqlite3_db_config() function, or maybe just a special > case for this specific option. > Actually I'm surprised SQLite doesn't have a PRAGMA command to customize this behavior. That would make it possible to customize from any client. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones From michael.stemper at gmail.com Tue Dec 13 09:46:29 2022 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Tue, 13 Dec 2022 08:46:29 -0600 Subject: Top level of a recursive function Message-ID: It's easy enough -- in fact necessary -- to handle the bottom level of a function differently than the levels above it. What about the case where you want to handle something differently in the top level than in lower levels? Is there any way to tell from within a function that it wasn't invoked by itself? I've come up with a hack to support different processing, by use of an extra argument, as shown in this simplified example: def fred(cf,toplevel=True): x = cf[0] if len(cf)>1: if toplevel: return x + fred(cf[1:],False) else: return "(" + x + fred(cf[1:],False) + ")" else: if toplevel: return x else: return "(" + x + ")" Aside from being ugly, this lets the caller diddle with "toplevel", which shouldn't really be externally modifiable. Are there better ways to do this? -- Michael F. Stemper I refuse to believe that a corporation is a person until Texas executes one. From Joseph.Schachner at Teledyne.com Tue Dec 13 12:19:07 2022 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph (US)) Date: Tue, 13 Dec 2022 17:19:07 +0000 Subject: Top level of a recursive function In-Reply-To: References: Message-ID: Reducing repetitiveness has made this code harder to read. I had to think about what it is doing. It might be slightly faster, but in my opinion it is not worth it. --- Joseph S. Teledyne Confidential; Commercially Sensitive Business Data -----Original Message----- From: Stefan Ram Sent: Tuesday, December 13, 2022 10:25 AM To: python-list at python.org Subject: Re: Top level of a recursive function Supersedes: ram at zedat.fu-berlin.de (Stefan Ram) writes: >def rest( s ): > return "(" + s[ 0 ] +( rest( s[1:] ) if len( s )> 1 else '' )+ ')' >def nest( s ): > return( s[ 0 ] if s else '' )+( rest( s[1:] )if len( s )> 1 else '' ) Below, I have tried to reduce repetitiveness a bit. (PS: Now, one "if" remains; less ifs are not possible in the case of controlled recursion.) def rest( s ): return '(' + nest( s )+ ')' def nest( s ): return s[ :1 ]+( rest( s[ 1: ])if s[ 1: ]else '' ) fred = nest From rosuav at gmail.com Tue Dec 13 12:36:46 2022 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Dec 2022 04:36:46 +1100 Subject: Top level of a recursive function In-Reply-To: References: Message-ID: On Wed, 14 Dec 2022 at 03:35, Michael F. Stemper wrote: > > It's easy enough -- in fact necessary -- to handle the bottom > level of a function differently than the levels above it. What > about the case where you want to handle something differently > in the top level than in lower levels? Is there any way to tell > from within a function that it wasn't invoked by itself? > Why does it have to be the same function? def _sort_recursive(stuff, keys, start, end): """imagine a nice implementation of some sorting algorithm here""" def sort(stuff, key=None): if key: keys = [key(x) for x in stuff] else: keys = stuff return _sort_recursive(stuff, 0, len(stuff)) With purely recursive functions (where every call to the function truly could have been a top-level call - a lot of mathematical functions work out this way), it makes sense to call the externally-callable function recursively; but for anything more messy, it's usually easiest to make the recursive part internal, and then have a top-level function that calls into the recursive one. ChrisA From mats at wichmann.us Tue Dec 13 12:57:59 2022 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 13 Dec 2022 10:57:59 -0700 Subject: Top level of a recursive function In-Reply-To: References: Message-ID: <56717951-1d27-1ea7-75aa-e607e90476ce@wichmann.us> On 12/13/22 10:36, Chris Angelico wrote: > On Wed, 14 Dec 2022 at 03:35, Michael F. Stemper > wrote: >> >> It's easy enough -- in fact necessary -- to handle the bottom >> level of a function differently than the levels above it. What >> about the case where you want to handle something differently >> in the top level than in lower levels? Is there any way to tell >> from within a function that it wasn't invoked by itself? >> > > Why does it have to be the same function? > > def _sort_recursive(stuff, keys, start, end): > """imagine a nice implementation of some sorting algorithm here""" > > def sort(stuff, key=None): > if key: > keys = [key(x) for x in stuff] > else: > keys = stuff > return _sort_recursive(stuff, 0, len(stuff)) if some support for this position is needed, this is roughly how the stdlib glob() function is implemented. From rosuav at gmail.com Tue Dec 13 13:06:04 2022 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Dec 2022 05:06:04 +1100 Subject: Top level of a recursive function In-Reply-To: <56717951-1d27-1ea7-75aa-e607e90476ce@wichmann.us> References: <56717951-1d27-1ea7-75aa-e607e90476ce@wichmann.us> Message-ID: On Wed, 14 Dec 2022 at 05:01, Mats Wichmann wrote: > > On 12/13/22 10:36, Chris Angelico wrote: > > On Wed, 14 Dec 2022 at 03:35, Michael F. Stemper > > wrote: > >> > >> It's easy enough -- in fact necessary -- to handle the bottom > >> level of a function differently than the levels above it. What > >> about the case where you want to handle something differently > >> in the top level than in lower levels? Is there any way to tell > >> from within a function that it wasn't invoked by itself? > >> > > > > Why does it have to be the same function? > > > > def _sort_recursive(stuff, keys, start, end): > > """imagine a nice implementation of some sorting algorithm here""" > > > > def sort(stuff, key=None): > > if key: > > keys = [key(x) for x in stuff] > > else: > > keys = stuff > > return _sort_recursive(stuff, 0, len(stuff)) > > if some support for this position is needed, this is roughly how the > stdlib glob() function is implemented. > Yeah, lots of things are done that way. You'll find a variety of naming conventions around different languages and libraries, including "_low_FUNCTIONNAME" or "_internal_FUNCTIONNAME" etc. It's definitely easier than trying to mess with tracking toplevel status. ChrisA From arequipeno at gmail.com Tue Dec 13 13:50:34 2022 From: arequipeno at gmail.com (Ian Pilcher) Date: Tue, 13 Dec 2022 12:50:34 -0600 Subject: Calling pselect/ppoll/epoll_pwait In-Reply-To: References: Message-ID: <6e304a4e-39fe-1b68-478f-495c46ba0338@gmail.com> On 12/2/22 14:00, Ian Pilcher wrote: > Does Python provide any way to call the "p" variants of the I/O > multiplexing functions? Just to close this out ... As others suggested, there's no easy way to call the "p" variants of the I/O multiplexing functions, but this can be worked around by "mapping" signals to file descriptors. There are a few ways to accomplish this. 1. Use a Linux signalfd. There's at least one library out there that provides signalfd support to Python. 2. Use signal.set_wakeup_fd()[1]. I didn't really explore this, as it appears that there isn't any way to filter the signals that will be reported. 3. Roll your own. This turned out to be really simple for my use case, which is simply to set an exit flag and wake my program up if it receives SIGINT or SIGTERM. _sel = selectors.DefaultSelector() _exit_flag = False _sig_pipe_r, _sig_pipe_w = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC) def _sig_handler(signum, frame): global _exit_flag _exit_flag = True os.write(_sig_pipe_w, b'\x00') _sel.register(_sig_pipe_r, selectors.EVENT_READ) # register other file descriptors of interest signal.signal(signal.SIGINT, _sig_handler) signal.signal(signal.SIGTERM, _sig_handler) while not _exit_flag: ready = _sel.select() # handle other file descriptors [1] https://docs.python.org/3/library/signal.html#signal.set_wakeup_fd -- ======================================================================== Google Where SkyNet meets Idiocracy ======================================================================== From roel at roelschroeven.net Tue Dec 13 13:58:35 2022 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 13 Dec 2022 19:58:35 +0100 Subject: sqlite3 double quote behavior In-Reply-To: References: Message-ID: <49fa4d80-7a40-5425-be63-07c08cab2b58@roelschroeven.net> Stefan Ram schreef op 13/12/2022 om 8:42: > "John K. Parejko" writes: > >I was just burned by this, where some tests I?d written > >against an sqlite database did not fail in the way that they > >?should? have, because of this double-quoted string issue. > > In standard SQL, double quotes denote identifiers that are > allowed to contain special characters. Or that are equal SQL keywords, which can be a reason to double-quote them. SQL engines sometimes add new keywords; explicitly marking string literals as string literals prevents future conflicts and confusion. Perhaps it's a better idea to use [identifier] or `identifier` instead though (I just learned about those on https://sqlite.org/lang_keywords.html). Both are not standard SQL ([] is used in MS Access and SQL Server, `` is used in MySQL) but both work in SQLite. That should prevent any ambiguity and confusion, if it doesn't bother you too much that it's not standard SQL. -- "I love science, and it pains me to think that to so many are terrified of the subject or feel that choosing science means you cannot also choose compassion, or the arts, or be awed by nature. Science is not meant to cure us of mystery, but to reinvent and reinvigorate it." -- Robert Sapolsky From rosuav at gmail.com Tue Dec 13 14:01:43 2022 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Dec 2022 06:01:43 +1100 Subject: sqlite3 double quote behavior In-Reply-To: <49fa4d80-7a40-5425-be63-07c08cab2b58@roelschroeven.net> References: <49fa4d80-7a40-5425-be63-07c08cab2b58@roelschroeven.net> Message-ID: On Wed, 14 Dec 2022 at 06:00, Roel Schroeven wrote: > > Stefan Ram schreef op 13/12/2022 om 8:42: > > "John K. Parejko" writes: > > >I was just burned by this, where some tests I?d written > > >against an sqlite database did not fail in the way that they > > >?should? have, because of this double-quoted string issue. > > > > In standard SQL, double quotes denote identifiers that are > > allowed to contain special characters. > Or that are equal SQL keywords, which can be a reason to double-quote > them. SQL engines sometimes add new keywords; explicitly marking string > literals as string literals prevents future conflicts and confusion. > > Perhaps it's a better idea to use [identifier] or `identifier` instead > though (I just learned about those on > https://sqlite.org/lang_keywords.html). Both are not standard SQL ([] is > used in MS Access and SQL Server, `` is used in MySQL) but both work in > SQLite. That should prevent any ambiguity and confusion, if it doesn't > bother you too much that it's not standard SQL. > Why not just use "identifier" which is standard SQL? ChrisA From michael.stemper at gmail.com Tue Dec 13 15:28:26 2022 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Tue, 13 Dec 2022 14:28:26 -0600 Subject: Top level of a recursive function In-Reply-To: References: Message-ID: On 13/12/2022 09.03, Stefan Ram wrote: > "Michael F. Stemper" writes: >> def fred(cf,toplevel=True): >> x = cf[0] >> if len(cf)>1: >> if toplevel: >> return x + fred(cf[1:],False) >> else: >> return "(" + x + fred(cf[1:],False) + ")" >> else: >> if toplevel: >> return x >> else: >> return "(" + x + ")" > > def rest( s ): > return "(" + s[ 0 ] +( rest( s[1:] ) if len( s )> 1 else '' )+ ')' > > def nest( s ): > return( s[ 0 ] if s else '' )+( rest( s[1:] )if len( s )> 1 else '' ) Hey, that's slick! And if I define rest within nest, it's not going to be externally accessible. Thanks -- Michael F. Stemper No animals were harmed in the composition of this message. From roel at roelschroeven.net Tue Dec 13 16:18:16 2022 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 13 Dec 2022 22:18:16 +0100 Subject: sqlite3 double quote behavior In-Reply-To: References: <49fa4d80-7a40-5425-be63-07c08cab2b58@roelschroeven.net> Message-ID: <0c4ce444-4235-2091-67f9-6dc92d5fac73@roelschroeven.net> Chris Angelico schreef op 13/12/2022 om 20:01: > On Wed, 14 Dec 2022 at 06:00, Roel Schroeven wrote: > > > > Stefan Ram schreef op 13/12/2022 om 8:42: > > > "John K. Parejko" writes: > > > >I was just burned by this, where some tests I?d written > > > >against an sqlite database did not fail in the way that they > > > >?should? have, because of this double-quoted string issue. > > > > > > In standard SQL, double quotes denote identifiers that are > > > allowed to contain special characters. > > Or that are equal SQL keywords, which can be a reason to double-quote > > them. SQL engines sometimes add new keywords; explicitly marking string > > literals as string literals prevents future conflicts and confusion. > > > > Perhaps it's a better idea to use [identifier] or `identifier` instead > > though (I just learned about those on > > https://sqlite.org/lang_keywords.html). Both are not standard SQL ([] is > > used in MS Access and SQL Server, `` is used in MySQL) but both work in > > SQLite. That should prevent any ambiguity and confusion, if it doesn't > > bother you too much that it's not standard SQL. > > > > Why not just use "identifier" which is standard SQL? If you accidentally type [identifire] or `identifire`, SQLite will produce an unknown identifier error, alerting you immediately to your typo. If you accidentally type "identifire", SQLite will silently treat it as a string literal instead of an identifier, causing more difficult to diagnose problems. -- "In the old days, writers used to sit in front of a typewriter and stare out of the window. Nowadays, because of the marvels of convergent technology, the thing you type on and the window you stare out of are now the same thing.? -- Douglas Adams From roel at roelschroeven.net Tue Dec 13 16:36:24 2022 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 13 Dec 2022 22:36:24 +0100 Subject: sqlite3 double quote behavior In-Reply-To: <0c4ce444-4235-2091-67f9-6dc92d5fac73@roelschroeven.net> References: <49fa4d80-7a40-5425-be63-07c08cab2b58@roelschroeven.net> <0c4ce444-4235-2091-67f9-6dc92d5fac73@roelschroeven.net> Message-ID: <407f0447-edf1-46e5-6c52-b8634876c684@roelschroeven.net> Roel Schroeven schreef op 13/12/2022 om 22:18: > Chris Angelico schreef op 13/12/2022 om 20:01: > > > Perhaps it's a better idea to use [identifier] or `identifier` instead > > > though (I just learned about those on > > > https://sqlite.org/lang_keywords.html). Both are not standard SQL ([] is > > > used in MS Access and SQL Server, `` is used in MySQL) but both work in > > > SQLite. That should prevent any ambiguity and confusion, if it doesn't > > > bother you too much that it's not standard SQL. > > > > > > > Why not just use "identifier" which is standard SQL? > > If you accidentally type [identifire] or `identifire`, SQLite will > produce an unknown identifier error, alerting you immediately to your typo. > If you accidentally type "identifire", SQLite will silently treat it as > a string literal instead of an identifier, causing more difficult to > diagnose problems. Example: -- Preparation: sqlite> create table foo ("columna" text, "columnb" text); sqlite> insert into foo values ("xyzzy", "xyzzy"); -- Variant with "": sqlite> select count(*) from foo where "columna" = "colummb"; 0 Not at all at first sight clear why there seem to be no matching rows, if you even notice straightaway that the result is not correct. -- Variant with []: sqlite> select count(*) from foo where [columna] = [colummb]; Error: no such column: colummb Immediately clear that there is a problem, and what the problem is. -- "In the old days, writers used to sit in front of a typewriter and stare out of the window. Nowadays, because of the marvels of convergent technology, the thing you type on and the window you stare out of are now the same thing.? -- Douglas Adams From roel at roelschroeven.net Tue Dec 13 16:44:37 2022 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 13 Dec 2022 22:44:37 +0100 Subject: sqlite3 double quote behavior In-Reply-To: <407f0447-edf1-46e5-6c52-b8634876c684@roelschroeven.net> References: <49fa4d80-7a40-5425-be63-07c08cab2b58@roelschroeven.net> <0c4ce444-4235-2091-67f9-6dc92d5fac73@roelschroeven.net> <407f0447-edf1-46e5-6c52-b8634876c684@roelschroeven.net> Message-ID: <9ff67425-065b-5c19-43fe-f3690fff446a@roelschroeven.net> Roel Schroeven schreef op 13/12/2022 om 22:36: > sqlite> insert into foo values ("xyzzy", "xyzzy"); SQLite accepts it like that, but I really should have used single quotes there instead of double quotes. It's a bad habit from using MySQL for too long I guess. -- "In the old days, writers used to sit in front of a typewriter and stare out of the window. Nowadays, because of the marvels of convergent technology, the thing you type on and the window you stare out of are now the same thing.? -- Douglas Adams From rosuav at gmail.com Tue Dec 13 16:58:12 2022 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 14 Dec 2022 08:58:12 +1100 Subject: sqlite3 double quote behavior In-Reply-To: <0c4ce444-4235-2091-67f9-6dc92d5fac73@roelschroeven.net> References: <49fa4d80-7a40-5425-be63-07c08cab2b58@roelschroeven.net> <0c4ce444-4235-2091-67f9-6dc92d5fac73@roelschroeven.net> Message-ID: On Wed, 14 Dec 2022 at 08:19, Roel Schroeven wrote: > > Chris Angelico schreef op 13/12/2022 om 20:01: > > On Wed, 14 Dec 2022 at 06:00, Roel Schroeven wrote: > > > > > > Stefan Ram schreef op 13/12/2022 om 8:42: > > > > "John K. Parejko" writes: > > > > >I was just burned by this, where some tests I?d written > > > > >against an sqlite database did not fail in the way that they > > > > >?should? have, because of this double-quoted string issue. > > > > > > > > In standard SQL, double quotes denote identifiers that are > > > > allowed to contain special characters. > > > Or that are equal SQL keywords, which can be a reason to double-quote > > > them. SQL engines sometimes add new keywords; explicitly marking string > > > literals as string literals prevents future conflicts and confusion. > > > > > > Perhaps it's a better idea to use [identifier] or `identifier` instead > > > though (I just learned about those on > > > https://sqlite.org/lang_keywords.html). Both are not standard SQL ([] is > > > used in MS Access and SQL Server, `` is used in MySQL) but both work in > > > SQLite. That should prevent any ambiguity and confusion, if it doesn't > > > bother you too much that it's not standard SQL. > > > > > > > Why not just use "identifier" which is standard SQL? > > If you accidentally type [identifire] or `identifire`, SQLite will > produce an unknown identifier error, alerting you immediately to your typo. > If you accidentally type "identifire", SQLite will silently treat it as > a string literal instead of an identifier, causing more difficult to > diagnose problems. > Okay, so..... exactly the same as if you use standard double quotes, but change the configuration option. So the options are: make everything worse for everyone by exacerbating the problem of non-standard identifier quoting, or get this API so SQLite can be configured, like the OP actually asked for. Yeah. Let's not do the wrong thing. ChrisA From roel at roelschroeven.net Tue Dec 13 18:34:18 2022 From: roel at roelschroeven.net (Roel Schroeven) Date: Wed, 14 Dec 2022 00:34:18 +0100 Subject: sqlite3 double quote behavior In-Reply-To: References: <49fa4d80-7a40-5425-be63-07c08cab2b58@roelschroeven.net> <0c4ce444-4235-2091-67f9-6dc92d5fac73@roelschroeven.net> Message-ID: <291f4801-055a-3f11-e6f0-5881f28ceb15@roelschroeven.net> Chris Angelico schreef op 13/12/2022 om 22:58: > Okay, so..... exactly the same as if you use standard double quotes, > but change the configuration option. So the options are: make > everything worse for everyone by exacerbating the problem of > non-standard identifier quoting, or get this API so SQLite can be > configured, like the OP actually asked for. > I'm not advocating for one above the other, I think they complement each other. Having the option to change SQLite's behavior is clearly the better solution if/when that happens (and is released and available in our development environments), but that doesn't mean there's no value in having a workaround here and now. -- "Most quotes are misattributed" -- Einstein From Gronicus at SGA.Ninja Tue Dec 13 22:43:35 2022 From: Gronicus at SGA.Ninja (Gronicus at SGA.Ninja) Date: Tue, 13 Dec 2022 22:43:35 -0500 Subject: Subtracting dates to get hours and minutes In-Reply-To: References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> Message-ID: <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> As is, Test A works. Comment out Test A and uncomment Test B it fails. In Test B, I move the data into a variable resulting with the report: "TypeError: an integer is required (got type tuple) How do I fix this? #----------------------------------------------------------------------------- import datetime #================================================= # Test A Hard coded Date/Time Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30) # ================================================= # Test B Date/Time data as a variable #Startt = (2022, 12, 13, 5, 3, 30) #Stopp = (2022, 12, 12, 21, 15, 30) #Startt = datetime.datetime(Startt) #Stopp = datetime.datetime(Stopp) # ================================================= c = Startt - Stopp minutes = c.total_seconds() / 60 minutes = c.seconds / 60 hours = 0 while (minutes > 59): minutes = minutes - 60 hours += 1 minutes = round(minutes) print() print (" Hours = <" + str(hours) + ">") print (" Minutes = <" + str(minutes) + ">") # ----------------------------------------------------------------------------- From list1 at tompassin.net Tue Dec 13 23:19:58 2022 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 13 Dec 2022 23:19:58 -0500 Subject: Subtracting dates to get hours and minutes In-Reply-To: <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> Message-ID: <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> Your problem is that datetime.datetime does not accept a tuple as an argument. It expects an integer value for the first argument, but you supplied a tuple. In Python, you can use a sequence (e.g., tuple or list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So: Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) st1 = (2022, 12, 13, 5, 3, 30) dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1) dts1 == Startt # True On 12/13/2022 10:43 PM, Gronicus at SGA.Ninja wrote: > As is, Test A works. > Comment out Test A and uncomment Test B it fails. > In Test B, I move the data into a variable resulting with the report: > "TypeError: an integer is required (got type tuple) > > How do I fix this? > > #----------------------------------------------------------------------------- > import datetime > #================================================= > # Test A Hard coded Date/Time > Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) > Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30) > > # ================================================= > # Test B Date/Time data as a variable > #Startt = (2022, 12, 13, 5, 3, 30) > #Stopp = (2022, 12, 12, 21, 15, 30) > > #Startt = datetime.datetime(Startt) > #Stopp = datetime.datetime(Stopp) > > # ================================================= > c = Startt - Stopp > minutes = c.total_seconds() / 60 > minutes = c.seconds / 60 > hours = 0 > > while (minutes > 59): > minutes = minutes - 60 > hours += 1 > minutes = round(minutes) > print() > print (" Hours = <" + str(hours) + ">") > print (" Minutes = <" + str(minutes) + ">") > > # ----------------------------------------------------------------------------- > From Gronicus at SGA.Ninja Wed Dec 14 00:55:49 2022 From: Gronicus at SGA.Ninja (Gronicus at SGA.Ninja) Date: Wed, 14 Dec 2022 00:55:49 -0500 Subject: Subtracting dates to get hours and minutes In-Reply-To: <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> Message-ID: <016d01d90f80$b7e1a830$27a4f890$@SGA.Ninja> I realized it had something to do with tupilation The simple fix is to add the * into the original code. Startt = datetime.datetime(*Startt) I am not sure what "dts1 == Startt # True" does.... Thank you..... -----Original Message----- From: Python-list On Behalf Of Thomas Passin Sent: Tuesday, December 13, 2022 11:20 PM To: python-list at python.org Subject: Re: Subtracting dates to get hours and minutes Your problem is that datetime.datetime does not accept a tuple as an argument. It expects an integer value for the first argument, but you supplied a tuple. In Python, you can use a sequence (e.g., tuple or list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So: Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) st1 = (2022, 12, 13, 5, 3, 30) dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1) dts1 == Startt # True On 12/13/2022 10:43 PM, Gronicus at SGA.Ninja wrote: > As is, Test A works. > Comment out Test A and uncomment Test B it fails. > In Test B, I move the data into a variable resulting with the report: > "TypeError: an integer is required (got type tuple) > > How do I fix this? > > #--------------------------------------------------------------------- > -------- > import datetime > #================================================= > # Test A Hard coded Date/Time > Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = > datetime.datetime(2022, 12, 12, 21, 15, 30) > > # ================================================= > # Test B Date/Time data as a variable > #Startt = (2022, 12, 13, 5, 3, 30) > #Stopp = (2022, 12, 12, 21, 15, 30) > > #Startt = datetime.datetime(Startt) > #Stopp = datetime.datetime(Stopp) > > # ================================================= > c = Startt - Stopp > minutes = c.total_seconds() / 60 > minutes = c.seconds / 60 > hours = 0 > > while (minutes > 59): > minutes = minutes - 60 > hours += 1 > minutes = round(minutes) > print() > print (" Hours = <" + str(hours) + ">") > print (" Minutes = <" + str(minutes) + ">") > > # > ---------------------------------------------------------------------- > ------- > -- https://mail.python.org/mailman/listinfo/python-list From Cecil at decebal.nl Wed Dec 14 03:55:34 2022 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 14 Dec 2022 09:55:34 +0100 Subject: How to get the needed version of a dependency Message-ID: <875yee1i0p.fsf@munus.decebal.nl> If I want to know the dependencies for requests I use: pip show requests And one of the lines I get is: Requires: certifi, charset-normalizer, idna, urllib3 But I want (in this case) to know with version of charset-normalizer requests needs. How do I get that? -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From nospam at dfs.com Wed Dec 14 08:38:54 2022 From: nospam at dfs.com (DFS) Date: Wed, 14 Dec 2022 08:38:54 -0500 Subject: How to get the needed version of a dependency In-Reply-To: <875yee1i0p.fsf@munus.decebal.nl> References: <875yee1i0p.fsf@munus.decebal.nl> Message-ID: On 12/14/2022 3:55 AM, Cecil Westerhof wrote: > If I want to know the dependencies for requests I use: > pip show requests > > And one of the lines I get is: > Requires: certifi, charset-normalizer, idna, urllib3 > > But I want (in this case) to know with version of charset-normalizer > requests needs. > How do I get that? Check the METADATA file in the *dist-info package files usually found in Lib\site-packages. ie \Python\3.11.0\Lib\site-packages\pandas-1.5.2.dist-info Look for config lines beginning with 'Requires': Requires-Python: >=3.8 Requires-Dist: python-dateutil (>=2.8.1) $ pip list will show you which version of the package you have installed, so you can search for the matching .dist-info file From list1 at tompassin.net Wed Dec 14 09:30:54 2022 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 14 Dec 2022 09:30:54 -0500 Subject: Subtracting dates to get hours and minutes In-Reply-To: <016d01d90f80$b7e1a830$27a4f890$@SGA.Ninja> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> <016d01d90f80$b7e1a830$27a4f890$@SGA.Ninja> Message-ID: <81edaf57-f286-d8c3-9035-c5144dc570e6@tompassin.net> On 12/14/2022 12:55 AM, Gronicus at SGA.Ninja wrote: > I realized it had something to do with tupilation > The simple fix is to add the * into the original code. > Startt = datetime.datetime(*Startt) > > I am not sure what "dts1 == Startt # True" does.... It demonstrates that the version with the "*" gives the same result as the first expression. That line is not needed by any code, it's just there to show you that the proposed expression gives the desired result. > Thank you..... > > > -----Original Message----- > From: Python-list On > Behalf Of Thomas Passin > Sent: Tuesday, December 13, 2022 11:20 PM > To: python-list at python.org > Subject: Re: Subtracting dates to get hours and minutes > > Your problem is that datetime.datetime does not accept a tuple as an > argument. It expects an integer value for the first argument, but you > supplied a tuple. In Python, you can use a sequence (e.g., tuple or > list) the way you want by prefixing it with an asterisk. This causes the > sequence of items to be treated as individual arguments. So: > > Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) > st1 = (2022, 12, 13, 5, 3, 30) > dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1) > dts1 == Startt # True > > On 12/13/2022 10:43 PM, Gronicus at SGA.Ninja wrote: >> As is, Test A works. >> Comment out Test A and uncomment Test B it fails. >> In Test B, I move the data into a variable resulting with the report: >> "TypeError: an integer is required (got type tuple) >> >> How do I fix this? >> >> #--------------------------------------------------------------------- >> -------- >> import datetime >> #================================================= >> # Test A Hard coded Date/Time >> Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = >> datetime.datetime(2022, 12, 12, 21, 15, 30) >> >> # ================================================= >> # Test B Date/Time data as a variable >> #Startt = (2022, 12, 13, 5, 3, 30) >> #Stopp = (2022, 12, 12, 21, 15, 30) >> >> #Startt = datetime.datetime(Startt) >> #Stopp = datetime.datetime(Stopp) >> >> # ================================================= >> c = Startt - Stopp >> minutes = c.total_seconds() / 60 >> minutes = c.seconds / 60 >> hours = 0 >> >> while (minutes > 59): >> minutes = minutes - 60 >> hours += 1 >> minutes = round(minutes) >> print() >> print (" Hours = <" + str(hours) + ">") >> print (" Minutes = <" + str(minutes) + ">") >> >> # >> ---------------------------------------------------------------------- >> ------- >> > > -- > https://mail.python.org/mailman/listinfo/python-list > From songbird at anthive.com Wed Dec 14 13:50:14 2022 From: songbird at anthive.com (songbird) Date: Wed, 14 Dec 2022 13:50:14 -0500 Subject: Keeping a list of records with named fields that can be updated Message-ID: <6gip6j-698.ln1@anthive.com> I'm relatively new to python but not new to programming in general. The program domain is accounting and keeping track of stock trades and other related information (dates, cash accounts, interest, dividends, transfers of funds, etc.) Assume that all data is CSV format. There are multiple files. Assume there is a coherent starting point and that all data is in order. Assume each line contains a description. The description determines what the line is. The number of fields in the line does not change within the data file but it may happen that later lines in other files may be different other than the fact that they all must contain a description. All descriptions are deterministic (none are recursive or referencing things from the future). All things referenced in the description which do not already exist are added to a list (or perhaps more than one in a few cases) and may contain some basic information (the date, how many and for how much, or a total amount or a fee or ...) If the field of the line isn't a number it is either a symbol or a description. A default action is simply to keep most parts of the line and to adjust any totals of a previously seen description that matches by whatever amounts are on the line. The key is the description. I've already written one program based upon the files I already have which works but what happens is that new descriptions are added (new accounts, new stocks, etc.) and I don't want to have to write new code manually every time a description changes. I started using named tuples (it works for reading in the files and accessing the fields) but I cannot update those so I need to use something else to give me the list of unique descriptions and fields that I need to update. I've not gotten beyond that yet as I'm still learning. Suggestions? Thanks! :) songbird From transreductionist at gmail.com Wed Dec 14 13:53:10 2022 From: transreductionist at gmail.com (Aaron P) Date: Wed, 14 Dec 2022 10:53:10 -0800 (PST) Subject: Single line if statement with a continue Message-ID: I occasionally run across something like: for idx, thing in enumerate(things): if idx == 103: continue do_something_with(thing) It seems more succinct and cleaner to use: if idx == 103: continue. Of course this would be considered an anti-pattern, and Flake8 will complain. Any opinions, or feedback on the matter. From Cecil at decebal.nl Wed Dec 14 16:05:26 2022 From: Cecil at decebal.nl (Cecil Westerhof) Date: Wed, 14 Dec 2022 22:05:26 +0100 Subject: How to get the needed version of a dependency References: <875yee1i0p.fsf@munus.decebal.nl> Message-ID: <87tu1xzofd.fsf@munus.decebal.nl> DFS writes: > On 12/14/2022 3:55 AM, Cecil Westerhof wrote: >> If I want to know the dependencies for requests I use: >> pip show requests >> And one of the lines I get is: >> Requires: certifi, charset-normalizer, idna, urllib3 >> But I want (in this case) to know with version of charset-normalizer >> requests needs. >> How do I get that? > > Check the METADATA file in the *dist-info package files usually found in > Lib\site-packages. > > ie \Python\3.11.0\Lib\site-packages\pandas-1.5.2.dist-info > > Look for config lines beginning with 'Requires': > > Requires-Python: >=3.8 > Requires-Dist: python-dateutil (>=2.8.1) > > $ pip list will show you which version of the package you have > installed, so you can search for the matching .dist-info file Works. In /usr/local/lib/python3.9/dist-packages/requests-2.28.1.dist-info/METADATA I see: Requires-Dist: charset-normalizer (<3,>=2) That already keeps charset-normalizer two months from being updated. Maybe I should contact Kenneth Reitz. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From list1 at tompassin.net Wed Dec 14 22:54:04 2022 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 14 Dec 2022 22:54:04 -0500 Subject: Keeping a list of records with named fields that can be updated In-Reply-To: <6gip6j-698.ln1@anthive.com> References: <6gip6j-698.ln1@anthive.com> Message-ID: <49bbb11a-a33d-b883-b3e4-7418840dbb99@tompassin.net> Dictionaries and sets are your friends here. On 12/14/2022 1:50 PM, songbird wrote: > > I'm relatively new to python but not new to programming in general. > > The program domain is accounting and keeping track of stock trades and other related information (dates, cash accounts, interest, dividends, transfers of funds, etc.) > > Assume that all data is CSV format. There are multiple files. > > Assume there is a coherent starting point and that all data is in order. > > Assume each line contains a description. The description determines what the line is. The number of fields in the line does not change within the data file but it may happen that later lines in other files may be different other than the fact that they all must contain a description. > > All descriptions are deterministic (none are recursive or referencing things from the future). All things referenced in the description which do not already exist are added to a list (or perhaps more than one in a few cases) and may contain some basic information (the date, how many and for how much, or a total amount or a fee or ...) If the field of the line isn't a number it is either a symbol or a description. > > A default action is simply to keep most parts of the line and to adjust any totals of a previously seen description that matches by whatever amounts are on the line. The key is the description. > > I've already written one program based upon the files I already have which works but what happens is that new descriptions are added (new accounts, new stocks, etc.) and I don't want to have to write new code manually every time a description changes. > > I started using named tuples (it works for reading in the files and accessing the fields) but I cannot update those so I need to use something else to give me the list of unique descriptions and fields that I need to update. I've not gotten beyond that yet as I'm still learning. > > Suggestions? > > Thanks! :) > > > songbird From rosuav at gmail.com Wed Dec 14 23:35:28 2022 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Dec 2022 15:35:28 +1100 Subject: Single line if statement with a continue In-Reply-To: References: Message-ID: On Thu, 15 Dec 2022 at 14:41, Aaron P wrote: > > I occasionally run across something like: > > for idx, thing in enumerate(things): > if idx == 103: > continue > do_something_with(thing) > > It seems more succinct and cleaner to use: > > if idx == 103: continue. > > Of course this would be considered an anti-pattern, and Flake8 will complain. > > Any opinions, or feedback on the matter. Nothing at all wrong with writing that on a single line. If you have issues with Flake8 not accepting your choices, reconfigure Flake8 :) ChrisA From PythonList at DancesWithMice.info Thu Dec 15 00:24:15 2022 From: PythonList at DancesWithMice.info (dn) Date: Thu, 15 Dec 2022 18:24:15 +1300 Subject: Single line if statement with a continue In-Reply-To: References: Message-ID: On 15/12/2022 07.53, Aaron P wrote: > I occasionally run across something like: > > for idx, thing in enumerate(things): > if idx == 103: > continue > do_something_with(thing) > > It seems more succinct and cleaner to use: > > if idx == 103: continue. > > Of course this would be considered an anti-pattern, and Flake8 will complain. > > Any opinions, or feedback on the matter. These aged-eyes prefer the second line and indentation. However, another alternative (given simplicity of example): for ... if idx != 103: do_something ... Which could, in-turn, be boiled-down to a 'one-liner'. -- Regards, =dn From list1 at tompassin.net Thu Dec 15 00:06:43 2022 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 15 Dec 2022 00:06:43 -0500 Subject: Single line if statement with a continue In-Reply-To: References: Message-ID: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> PEP-8, which is Guido's style guide and generally good to follow, does not completely discourage single-line usage like the example. It's not clear to me how Chris's example fits into the guidelines. PEP-8: "While sometimes it?s okay to put an if/for/while with a small body on the same line, never do this for multi-clause statements. ... # Wrong: if foo == 'blah': do_blah_thing() for x in lst: total += x while t < 10: t = delay() " If the one-liner were not in a multi-statement block, it would be all right with PEP-8. OTOH, there is nothing that says one has to fully comply with PEP-8. I personally tend to use if test: return even inside larger blocks. If one is working with other someone else's project and there is a style guide, it's important to follow that guide because the other people involved will find it easier to read and understand your code. If you are working on your own project, PEP-8 is always a good starting point, and flake8 and pylint will be happier. That's worth something. On 12/14/2022 11:35 PM, Chris Angelico wrote: > On Thu, 15 Dec 2022 at 14:41, Aaron P wrote: >> >> I occasionally run across something like: >> >> for idx, thing in enumerate(things): >> if idx == 103: >> continue >> do_something_with(thing) >> >> It seems more succinct and cleaner to use: >> >> if idx == 103: continue. >> >> Of course this would be considered an anti-pattern, and Flake8 will complain. >> >> Any opinions, or feedback on the matter. > > Nothing at all wrong with writing that on a single line. If you have > issues with Flake8 not accepting your choices, reconfigure Flake8 :) > > ChrisA From rosuav at gmail.com Thu Dec 15 01:56:08 2022 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 15 Dec 2022 17:56:08 +1100 Subject: Single line if statement with a continue In-Reply-To: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> References: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> Message-ID: On Thu, 15 Dec 2022 at 16:29, Thomas Passin wrote: > > PEP-8, which is Guido's style guide and generally good to follow, does > not completely discourage single-line usage like the example. It's not > clear to me how Chris's example fits into the guidelines. > > PEP-8: > "While sometimes it?s okay to put an if/for/while with a small body on > the same line, never do this for multi-clause statements. > ... > # Wrong: > if foo == 'blah': do_blah_thing() > for x in lst: total += x > while t < 10: t = delay() > " > > If the one-liner were not in a multi-statement block, it would be all > right with PEP-8. Not sure what your point is about it being "in" a multi-statement block - PEP 8 has nothing to say about that. What it's saying is that you shouldn't do this: if foo == 'blah': one(); two(); three() And I agree; if you're putting more than one statement after your 'if', it's generally clearest to have it on multiple lines. But a simple "continue" or "break" statement works just fine on the same line as the if. ChrisA From avi.e.gross at gmail.com Thu Dec 15 01:58:11 2022 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 15 Dec 2022 01:58:11 -0500 Subject: Single line if statement with a continue In-Reply-To: References: Message-ID: <005401d91052$98eb2410$cac16c30$@gmail.com> Unless someone is counting lines of code for some purpose, like number of error found per thousand lines of code, many short one-liners strike me as more readable and especially if followed by a blank line so it is a bit obvious. Consider a similar issue in many languages that use curly braces and where they can be skipped in a one liner like "if (condition) statement" rather than the style some use on multiple lines like: If (condition) { Statement } Or even: If (condition) { Statement } Of course, once you have additional parts following like an "else" that contains multiple statements, it seems more symmetric to do both parts the same style. And in commented code, a one-liner may get long and harder to read as in If (condition) statement # long comment Note the above are not python and the absence of a colon is intentional. No one language is being discussed and some have their own vagaries and variants such as not knowing if your code is done if you change lines in ambiguous situations. And note some languages support methods like the ?: operator or the inline if/else python allows as in this: min = 5 low = 12 x = low if low >= 12 else min x 12 low = 3 x = low if low >= 12 else min result 12 Clearly that is a one-liner that almost has to be a one liner as there is no obvious easy way to wrap it into multiple lines. I mean the following works, albeit darned if I know if any of it should be indented or who wants to read it this way: x = low \ if \ low >= 12 \ else \ min x 5 As many have discussed, it is a matter of taste and people should be flexible enough to program in whatever style others want to see when that applies such as working in a group project or fixing someone else's code. -----Original Message----- From: Python-list On Behalf Of dn Sent: Thursday, December 15, 2022 12:24 AM To: python-list at python.org Subject: Re: Single line if statement with a continue On 15/12/2022 07.53, Aaron P wrote: > I occasionally run across something like: > > for idx, thing in enumerate(things): > if idx == 103: > continue > do_something_with(thing) > > It seems more succinct and cleaner to use: > > if idx == 103: continue. > > Of course this would be considered an anti-pattern, and Flake8 will complain. > > Any opinions, or feedback on the matter. These aged-eyes prefer the second line and indentation. However, another alternative (given simplicity of example): for ... if idx != 103: do_something ... Which could, in-turn, be boiled-down to a 'one-liner'. -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Thu Dec 15 03:39:54 2022 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Dec 2022 09:39:54 +0100 Subject: Top level of a recursive function In-Reply-To: References: Message-ID: <1d28e5ea-4877-adc0-f945-c6c79a532cc1@web.de> On 13/12/2022 15:46, Michael F. Stemper wrote: > It's easy enough -- in fact necessary -- to handle the bottom > level of a function differently than the levels above it. What > about the case where you want to handle something differently > in the top level than in lower levels? Is there any way to tell > from within a function that it wasn't invoked by itself? > > I've come up with a hack to support different processing, by > use of an extra argument, as shown in this simplified example: > > def fred(cf,toplevel=True): > ? x = cf[0] > ? if len(cf)>1: > ??? if toplevel: > ????? return x + fred(cf[1:],False) > ??? else: > ????? return "(" + x + fred(cf[1:],False) + ")" > ? else: > ??? if toplevel: > ????? return x > ??? else: > ????? return "(" + x + ")" > > Aside from being ugly, this lets the caller diddle with "toplevel", > which shouldn't really be externally modifiable. > > Are there better ways to do this? For adepts of functional programming the above is a "fold right" operation, first hit for "foldr in python": https://burgaud.com/foldl-foldr-python With that >>> from functools import reduce >>> def foldr(func, items): return reduce(lambda x, y: func(y, x), items[::-1]) your problem reduces ;) to >>> foldr("{0}({1})".format, [1,2,3,4]) '1(2(3(4)))' From __peter__ at web.de Thu Dec 15 04:21:14 2022 From: __peter__ at web.de (Peter Otten) Date: Thu, 15 Dec 2022 10:21:14 +0100 Subject: Keeping a list of records with named fields that can be updated In-Reply-To: <6gip6j-698.ln1@anthive.com> References: <6gip6j-698.ln1@anthive.com> Message-ID: <9158537c-f561-e666-f60c-34d50f61d7b7@web.de> On 14/12/2022 19:50, songbird wrote: > > I'm relatively new to python but not new to programming in general. > > The program domain is accounting and keeping track of stock trades and other related information (dates, cash accounts, interest, dividends, transfers of funds, etc.) > > Assume that all data is CSV format. There are multiple files. > > Assume there is a coherent starting point and that all data is in order. > > Assume each line contains a description. The description determines what the line is. The number of fields in the line does not change within the data file but it may happen that later lines in other files may be different other than the fact that they all must contain a description. > > All descriptions are deterministic (none are recursive or referencing things from the future). All things referenced in the description which do not already exist are added to a list (or perhaps more than one in a few cases) and may contain some basic information (the date, how many and for how much, or a total amount or a fee or ...) If the field of the line isn't a number it is either a symbol or a description. > > A default action is simply to keep most parts of the line and to adjust any totals of a previously seen description that matches by whatever amounts are on the line. The key is the description. > > I've already written one program based upon the files I already have which works but what happens is that new descriptions are added (new accounts, new stocks, etc.) and I don't want to have to write new code manually every time a description changes. > > I started using named tuples (it works for reading in the files and accessing the fields) but I cannot update those so I need to use something else to give me the list of unique descriptions and fields that I need to update. I've not gotten beyond that yet as I'm still learning. > > Suggestions? > > Thanks! :) While I think what you need is a database instead of the collection of csv files the way to alter namedtuples is to create a new one: >>> from collections import namedtuple >>> Row = namedtuple("Row", "foo bar baz") >>> row = Row(1, 2, 3) >>> row._replace(bar=42) Row(foo=1, bar=42, baz=3) An alternative would be dataclasses where basic usage is just as easy: >>> from dataclasses import make_dataclass >>> Row = make_dataclass("Row", "foo bar baz".split()) >>> row = Row(1, 2, 3) >>> row Row(foo=1, bar=2, baz=3) >>> row.bar = 42 >>> row Row(foo=1, bar=42, baz=3) From gweatherby at uchc.edu Thu Dec 15 08:00:15 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Thu, 15 Dec 2022 13:00:15 +0000 Subject: Keeping a list of records with named fields that can be updated In-Reply-To: <6gip6j-698.ln1@anthive.com> References: <6gip6j-698.ln1@anthive.com> Message-ID: I have a lot of NamedTuples in my codebase, and I now add new ones never. They were a good option prior to Python 3.7 but dataclasses are much easier to work with and are almost a drop-in substitute. A combination of a default dictionary and a dataclass might meet your needs: import collections from dataclasses import dataclass @dataclass class AccountingEntry: description: str # other fields ledger = collections.defaultdict(list) for ae in get_accounting_entries(): ledger[ae.description] = ae From: Python-list on behalf of songbird Date: Wednesday, December 14, 2022 at 10:38 PM To: python-list at python.org Subject: Keeping a list of records with named fields that can be updated *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** I'm relatively new to python but not new to programming in general. The program domain is accounting and keeping track of stock trades and other related information (dates, cash accounts, interest, dividends, transfers of funds, etc.) Assume that all data is CSV format. There are multiple files. Assume there is a coherent starting point and that all data is in order. Assume each line contains a description. The description determines what the line is. The number of fields in the line does not change within the data file but it may happen that later lines in other files may be different other than the fact that they all must contain a description. All descriptions are deterministic (none are recursive or referencing things from the future). All things referenced in the description which do not already exist are added to a list (or perhaps more than one in a few cases) and may contain some basic information (the date, how many and for how much, or a total amount or a fee or ...) If the field of the line isn't a number it is either a symbol or a description. A default action is simply to keep most parts of the line and to adjust any totals of a previously seen description that matches by whatever amounts are on the line. The key is the description. I've already written one program based upon the files I already have which works but what happens is that new descriptions are added (new accounts, new stocks, etc.) and I don't want to have to write new code manually every time a description changes. I started using named tuples (it works for reading in the files and accessing the fields) but I cannot update those so I need to use something else to give me the list of unique descriptions and fields that I need to update. I've not gotten beyond that yet as I'm still learning. Suggestions? Thanks! :) songbird -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!ndkoYjlClLoELvhzTpXFZEtJ70fXjdFllo-ce0fJ4f0AdRLQXvryO11ZSJ16tf-Ke-pko3kmBxW1cesvrQAQUQ$ From Gronicus at SGA.Ninja Thu Dec 15 13:14:43 2022 From: Gronicus at SGA.Ninja (Gronicus at SGA.Ninja) Date: Thu, 15 Dec 2022 13:14:43 -0500 Subject: Subtracting dates to get hours and minutes In-Reply-To: <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> Message-ID: <00c701d910b1$1b6a56f0$523f04d0$@SGA.Ninja> So far so good , I can now use a variable in datetime.datetime but it only works if I hard-code the time/date information. Now I want to have the code read from a file but I get: TypeError: function takes at most 9 arguments (26 given) I figure that the structure in the file is incorrect. What should it be? The entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to use it I get the error. The program is a bit more sophisticated now but here is the update with a sample of the SPECIFICATIONS.txt file: ===================================================================== # This program compares two Timedate values, subtracts the two and # converts the difference to seconds and hours. # # %A Monday # %a Mon # %B January # %b Jan # %d 05 day # %m month as 01 # %Y 2020 # %y 20 # %H 24 # %I 12 # %M 30 min # %S Seconds import time import datetime from time import gmtime, strftime ##define strftime as time/date right now # ====================================================== def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7 ItemValue = "--" with open("SPECIFICATIONS.txt" , 'r') as infile: for lineEQN in infile: # loop to find each line in the file for that dose if ((lineEQN[4:7]== GetThisOne)): ItemValue = lineEQN[30:60].strip() # Just the Data return(ItemValue) """ SPECIFICATIONS.txt IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ## IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ## """ # ====================== Main() ====================================== print() Startt = "404" Stopp = "404" Answer = "Y" Answer = input("Run test A? (" + Answer + ")" ) if Answer == "Y" or Answer == "y" or Answer == "": print() print(" Running Test A:") # Year Mth Day Hour Min Sec Startt = 2018, 12, 4, 10, 7, 00 Stopp = 2022, 12, 12, 1, 15, 30 NowTime = 2022, 12, 14, 21, 15, 30 else: print(" Running Test B:") Startt = GetSpecByItem("HRG") Stopp = GetSpecByItem("HRB") NowTime = strftime("(%Y, %m, %d, %H, %M, %S)") print() print("55 NowTime = " + str(NowTime)) print("56 Startt = " + str(Startt)) print("57 Stopp = " + str(Stopp)) print() NowTime = datetime.datetime(*NowTime) Startt = datetime.datetime(*Startt) Stopp = datetime.datetime(*Stopp) #Start == Startt # True" #print("Startt test = " + Start) # ================================================= print() c = NowTime - Stopp minutes = c.total_seconds() / 60 minutes = c.seconds / 60 hours = 0 while (minutes > 59): minutes = minutes - 60 hours += 1 minutes = round(minutes) print ("77 Hours = <" + str(hours) + ">") print ("78 Minutes = <" + str(minutes) + ">") if hours > 7: print(" Time to inject Humulin R u500.") pause = input("Pause") # ====================================================== -----Original Message----- From: Python-list On Behalf Of Thomas Passin Sent: Tuesday, December 13, 2022 11:20 PM To: python-list at python.org Subject: Re: Subtracting dates to get hours and minutes Your problem is that datetime.datetime does not accept a tuple as an argument. It expects an integer value for the first argument, but you supplied a tuple. In Python, you can use a sequence (e.g., tuple or list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So: Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) st1 = (2022, 12, 13, 5, 3, 30) dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1) dts1 == Startt # True On 12/13/2022 10:43 PM, Gronicus at SGA.Ninja wrote: > As is, Test A works. > Comment out Test A and uncomment Test B it fails. > In Test B, I move the data into a variable resulting with the report: > "TypeError: an integer is required (got type tuple) > > How do I fix this? > > #--------------------------------------------------------------------- > -------- > import datetime > #================================================= > # Test A Hard coded Date/Time > Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = > datetime.datetime(2022, 12, 12, 21, 15, 30) > > # ================================================= > # Test B Date/Time data as a variable > #Startt = (2022, 12, 13, 5, 3, 30) > #Stopp = (2022, 12, 12, 21, 15, 30) > > #Startt = datetime.datetime(Startt) > #Stopp = datetime.datetime(Stopp) > > # ================================================= > c = Startt - Stopp > minutes = c.total_seconds() / 60 > minutes = c.seconds / 60 > hours = 0 > > while (minutes > 59): > minutes = minutes - 60 > hours += 1 > minutes = round(minutes) > print() > print (" Hours = <" + str(hours) + ">") > print (" Minutes = <" + str(minutes) + ">") > > # > ---------------------------------------------------------------------- > ------- > -- https://mail.python.org/mailman/listinfo/python-list From cl at isbd.net Thu Dec 15 03:58:26 2022 From: cl at isbd.net (Chris Green) Date: Thu, 15 Dec 2022 08:58:26 +0000 Subject: Single line if statement with a continue References: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> Message-ID: Thomas Passin wrote: > I personally tend to use > > if test: return > > even inside larger blocks. I always try to avoid multiple returns from functions/methods, as soon as things get complex it's all to easy to miss clean-up etc. "No multiple returns" is often found in programming guidelines. -- Chris Green ? From Cecil at decebal.nl Thu Dec 15 08:09:54 2022 From: Cecil at decebal.nl (Cecil Westerhof) Date: Thu, 15 Dec 2022 14:09:54 +0100 Subject: Single line if statement with a continue References: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> Message-ID: <87edt0zucd.fsf@munus.decebal.nl> ram at zedat.fu-berlin.de (Stefan Ram) writes: >>"No multiple returns" is often found in programming guidelines. > > I religiously followed that when I did more C programming > than today. Then, I read an article about how the result > pattern makes functions measurably slower. (It should not > with an optimizing compiler, but it did due to those > measurements. Can't find that article now, though.) That makes me think about the quote from Edsger W. Dijkstra about the go to statement: Please do not fall into the trap of believing that I am terribly dogmatic about the go to statement. I have the uncomfortable feeling that others are making a religion out of it, as if the conceptual problems of programming could be solved by a simple trick, by a simple form of coding discipline! -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof From songbird at anthive.com Thu Dec 15 08:41:57 2022 From: songbird at anthive.com (songbird) Date: Thu, 15 Dec 2022 08:41:57 -0500 Subject: Keeping a list of records with named fields that can be updated References: <6gip6j-698.ln1@anthive.com> <9158537c-f561-e666-f60c-34d50f61d7b7@web.de> Message-ID: <5qkr6j-dk2.ln1@anthive.com> Peter Otten wrote: > > While I think what you need is a database instead of the collection of > csv files the way to alter namedtuples is to create a new one: the files are coming from the web site that stores the accounts. i already have manually created files from many years ago with some of the same information but to go back and reformat all of those would be a lot of work. it is much easier to just take the files as supplied and process them if i can do that instead. i do know database stuff well enough but this is fairly simple math and i'd like to avoid creating yet another copy in yet another format to have to deal with. > >>> from collections import namedtuple > >>> Row = namedtuple("Row", "foo bar baz") > >>> row = Row(1, 2, 3) > >>> row._replace(bar=42) > Row(foo=1, bar=42, baz=3) > > An alternative would be dataclasses where basic usage is just as easy: > > >>> from dataclasses import make_dataclass > >>> Row = make_dataclass("Row", "foo bar baz".split()) > >>> row = Row(1, 2, 3) > >>> row > Row(foo=1, bar=2, baz=3) > >>> row.bar = 42 > >>> row > Row(foo=1, bar=42, baz=3) thanks, i'll give these a try. :) songbird From avi.e.gross at gmail.com Thu Dec 15 14:05:32 2022 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 15 Dec 2022 14:05:32 -0500 Subject: Single line if statement with a continue In-Reply-To: References: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> Message-ID: <055e01d910b8$349de450$9dd9acf0$@gmail.com> Multiple returns is not always a problem as it depends on the nature of a task whether it has complex enough cases. I have seen code that instead sets Boolean variables when it is ready to return and everything else keeps checking the variables to skip further processing so the program then slides down to a single return statement. If done properly, it boils down to the same result if VERY carefully done but with lots of sometimes complex IF statements that may be not be updated well if the logic changes a bit. In such cases, I vastly prefer clean and unambiguous returns from the function right at the point where the decision is made, UNLESS the exit is not always clean as there may be cleanup or finalization of some kind required that is best done at a single point. If efficiency is an issue, then clearly a rapid exit may beat one where processing continues for a while and also often beats a method that involves creating and calling multiple smaller functions with lots of overhead. Having said all that, of course, if you can find a fairly simple algorithm that only returns from one place, use it instead of a convoluted one. The issue is not necessarily that multiple return points are bad, but that they are often a symptom of sloppy planning. But for some problems, they fit well and simplify things. -----Original Message----- From: Python-list On Behalf Of Stefan Ram Sent: Thursday, December 15, 2022 7:42 AM To: python-list at python.org Subject: Re: Single line if statement with a continue Chris Green writes: >I always try to avoid multiple returns from functions/methods, as soon >as things get complex it's all to easy to miss clean-up etc. This "complexity" could also mean that the function has become too large. In such a case, one could say that the /size/ of the function is the actual cause of problems and not multiple returns. |Fools ignore complexity. Pragmatists suffer it. Some can avoid it. |Geniuses remove it. Alan Perlis (1922/1990) Within a small function, multiple returns are rarely a problem. When a function is large, one can apply well-known refactors. For an example, look at the code in the first post of the thread Python script not letting go of files Date: Tue, 29 Nov 2022 12:52:15 +0000 and then at my reply of 29 Nov 2022 14:44:39 GMT. >"No multiple returns" is often found in programming guidelines. I religiously followed that when I did more C programming than today. Then, I read an article about how the result pattern makes functions measurably slower. (It should not with an optimizing compiler, but it did due to those measurements. Can't find that article now, though.) "Result pattern" I call writing, if a: result = 123 else: result = 456 return result , instead of, if a: return 123 else return 456 . -- https://mail.python.org/mailman/listinfo/python-list From parejkoj at gmail.com Thu Dec 15 14:18:55 2022 From: parejkoj at gmail.com (John K. Parejko) Date: Thu, 15 Dec 2022 11:18:55 -0800 Subject: sqlite3 double quote behavior In-Reply-To: References: <49fa4d80-7a40-5425-be63-07c08cab2b58@roelschroeven.net> <0c4ce444-4235-2091-67f9-6dc92d5fac73@roelschroeven.net> Message-ID: <9ED49723-3E93-41F5-8CDA-4CA322F6B105@gmail.com> Thanks for the discussion. I?m aware that SQLite has several different options for identifier quoting, but they?re not cross-compatible with other SQL, whereas double quotes are (modulo this strange SQLite behavior). Is anyone here familiar with the python sqlite3 implementation? I wonder how hard it would be to raise up the `sqlite3_db_config` generically, or have a specific function to set just the DQS_DDL and DQS_DML settings? It looks like everything interesting is in `Modules/_sqlite/module.c`, but I?m not familiar with the cpython internals. John > On 13Dec 2022, at 13:58, Chris Angelico wrote: > > On Wed, 14 Dec 2022 at 08:19, Roel Schroeven wrote: >> >> Chris Angelico schreef op 13/12/2022 om 20:01: >>> On Wed, 14 Dec 2022 at 06:00, Roel Schroeven wrote: >>>> >>>> Stefan Ram schreef op 13/12/2022 om 8:42: >>>>> "John K. Parejko" writes: >>>>>> I was just burned by this, where some tests I?d written >>>>>> against an sqlite database did not fail in the way that they >>>>>> ?should? have, because of this double-quoted string issue. >>>>> >>>>> In standard SQL, double quotes denote identifiers that are >>>>> allowed to contain special characters. >>>> Or that are equal SQL keywords, which can be a reason to double-quote >>>> them. SQL engines sometimes add new keywords; explicitly marking string >>>> literals as string literals prevents future conflicts and confusion. >>>> >>>> Perhaps it's a better idea to use [identifier] or `identifier` instead >>>> though (I just learned about those on >>>> https://sqlite.org/lang_keywords.html). Both are not standard SQL ([] is >>>> used in MS Access and SQL Server, `` is used in MySQL) but both work in >>>> SQLite. That should prevent any ambiguity and confusion, if it doesn't >>>> bother you too much that it's not standard SQL. >>>> >>> >>> Why not just use "identifier" which is standard SQL? >> >> If you accidentally type [identifire] or `identifire`, SQLite will >> produce an unknown identifier error, alerting you immediately to your typo. >> If you accidentally type "identifire", SQLite will silently treat it as >> a string literal instead of an identifier, causing more difficult to >> diagnose problems. >> > > Okay, so..... exactly the same as if you use standard double quotes, > but change the configuration option. So the options are: make > everything worse for everyone by exacerbating the problem of > non-standard identifier quoting, or get this API so SQLite can be > configured, like the OP actually asked for. > > Yeah. Let's not do the wrong thing. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From gweatherby at uchc.edu Thu Dec 15 14:22:59 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Thu, 15 Dec 2022 19:22:59 +0000 Subject: Single line if statement with a continue In-Reply-To: <055e01d910b8$349de450$9dd9acf0$@gmail.com> References: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> <055e01d910b8$349de450$9dd9acf0$@gmail.com> Message-ID: I once saw a C function full of GOTOs which jumped to the return state at the bottom of the functions because the programmer had learned that ?multiple returns are a bad idea.? I totally agree multiple returns causing confusion is a symptom of poor design, not a cause. Required cleanup is easily handled by the try / finally construct. From: Python-list on behalf of avi.e.gross at gmail.com Date: Thursday, December 15, 2022 at 2:07 PM To: python-list at python.org Subject: RE: Single line if statement with a continue *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Multiple returns is not always a problem as it depends on the nature of a task whether it has complex enough cases. I have seen code that instead sets Boolean variables when it is ready to return and everything else keeps checking the variables to skip further processing so the program then slides down to a single return statement. If done properly, it boils down to the same result if VERY carefully done but with lots of sometimes complex IF statements that may be not be updated well if the logic changes a bit. In such cases, I vastly prefer clean and unambiguous returns from the function right at the point where the decision is made, UNLESS the exit is not always clean as there may be cleanup or finalization of some kind required that is best done at a single point. If efficiency is an issue, then clearly a rapid exit may beat one where processing continues for a while and also often beats a method that involves creating and calling multiple smaller functions with lots of overhead. Having said all that, of course, if you can find a fairly simple algorithm that only returns from one place, use it instead of a convoluted one. The issue is not necessarily that multiple return points are bad, but that they are often a symptom of sloppy planning. But for some problems, they fit well and simplify things. -----Original Message----- From: Python-list On Behalf Of Stefan Ram Sent: Thursday, December 15, 2022 7:42 AM To: python-list at python.org Subject: Re: Single line if statement with a continue Chris Green writes: >I always try to avoid multiple returns from functions/methods, as soon >as things get complex it's all to easy to miss clean-up etc. This "complexity" could also mean that the function has become too large. In such a case, one could say that the /size/ of the function is the actual cause of problems and not multiple returns. |Fools ignore complexity. Pragmatists suffer it. Some can avoid it. |Geniuses remove it. Alan Perlis (1922/1990) Within a small function, multiple returns are rarely a problem. When a function is large, one can apply well-known refactors. For an example, look at the code in the first post of the thread Python script not letting go of files Date: Tue, 29 Nov 2022 12:52:15 +0000 and then at my reply of 29 Nov 2022 14:44:39 GMT. >"No multiple returns" is often found in programming guidelines. I religiously followed that when I did more C programming than today. Then, I read an article about how the result pattern makes functions measurably slower. (It should not with an optimizing compiler, but it did due to those measurements. Can't find that article now, though.) "Result pattern" I call writing, if a: result = 123 else: result = 456 return result , instead of, if a: return 123 else return 456 . -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!lVeLOl91qPUjowC1ch_u353upn8X-V4rsReaNberWpIXBlBP6CYcDgr_aaMb0ZHoYX4YWO8id1biCn6sW7V6vJM$ -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!lVeLOl91qPUjowC1ch_u353upn8X-V4rsReaNberWpIXBlBP6CYcDgr_aaMb0ZHoYX4YWO8id1biCn6sW7V6vJM$ From python at mrabarnett.plus.com Thu Dec 15 14:27:46 2022 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 15 Dec 2022 19:27:46 +0000 Subject: Subtracting dates to get hours and minutes In-Reply-To: <00c701d910b1$1b6a56f0$523f04d0$@SGA.Ninja> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> <00c701d910b1$1b6a56f0$523f04d0$@SGA.Ninja> Message-ID: On 2022-12-15 18:14, Gronicus at SGA.Ninja wrote: > So far so good , I can now use a variable in datetime.datetime but it only > works if I hard-code the time/date information. Now I want to have the code > read from a file but I get: TypeError: function takes at most 9 arguments > (26 given) > > I figure that the structure in the file is incorrect. What should it be? The > entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to > use it I get the error. > > The program is a bit more sophisticated now but here is the update with a > sample of the SPECIFICATIONS.txt file: > ===================================================================== > > # This program compares two Timedate values, subtracts the two and > # converts the difference to seconds and hours. > # > > # %A Monday # %a Mon # %B January # %b Jan > # %d 05 day # %m month as 01 # %Y 2020 # %y 20 > # %H 24 # %I 12 # %M 30 min # %S Seconds > > import time > import datetime > from time import gmtime, strftime ##define strftime as time/date right now > # ====================================================== > > def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7 > ItemValue = "--" > > with open("SPECIFICATIONS.txt" , 'r') as infile: > for lineEQN in infile: # loop to find each line in the file for that > dose > if ((lineEQN[4:7]== GetThisOne)): You don't need the parentheses, and certainly 2 pairs of them! > ItemValue = lineEQN[30:60].strip() # Just the Data > return(ItemValue) You're returning a _string_. I suggest using 'literal_eval' from the 'ast' module to convert the string safely into a tuple. However, if the 'for' loop fails to match a line, the function will return "--", which won't be of any use later on unless you check for it specifically and, say, report an error to the user. > > """ > SPECIFICATIONS.txt > > IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ## > IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ## > """ > # ====================== Main() ====================================== > print() > Startt = "404" > Stopp = "404" > > Answer = "Y" > Answer = input("Run test A? (" + Answer + ")" ) > > if Answer == "Y" or Answer == "y" or Answer == "": > print() > print(" Running Test A:") > # Year Mth Day Hour Min Sec > Startt = 2018, 12, 4, 10, 7, 00 > Stopp = 2022, 12, 12, 1, 15, 30 > NowTime = 2022, 12, 14, 21, 15, 30 'Startt' and 'Stopp' here are tuples. > else: > print(" Running Test B:") > Startt = GetSpecByItem("HRG") > Stopp = GetSpecByItem("HRB") 'Startt' and 'Stopp' here are _strings_. > NowTime = strftime("(%Y, %m, %d, %H, %M, %S)") > > print() > print("55 NowTime = " + str(NowTime)) > print("56 Startt = " + str(Startt)) > print("57 Stopp = " + str(Stopp)) > print() > > NowTime = datetime.datetime(*NowTime) > Startt = datetime.datetime(*Startt) > Stopp = datetime.datetime(*Stopp) > These will work if 'Startt' and 'Stopp' are tuples, but not if they're strings. In the latter case, you're effectively passing multiple single-characters strings into 'datetime'. > #Start == Startt # True" > #print("Startt test = " + Start) > # ================================================= > print() > c = NowTime - Stopp > minutes = c.total_seconds() / 60 > minutes = c.seconds / 60 > hours = 0 > > while (minutes > 59): > minutes = minutes - 60 > hours += 1 > minutes = round(minutes) > print ("77 Hours = <" + str(hours) + ">") > print ("78 Minutes = <" + str(minutes) + ">") > if hours > 7: > print(" Time to inject Humulin R u500.") > > pause = input("Pause") > # ====================================================== > > -----Original Message----- > From: Python-list On > Behalf Of Thomas Passin > Sent: Tuesday, December 13, 2022 11:20 PM > To: python-list at python.org > Subject: Re: Subtracting dates to get hours and minutes > > Your problem is that datetime.datetime does not accept a tuple as an > argument. It expects an integer value for the first argument, but you > supplied a tuple. In Python, you can use a sequence (e.g., tuple or > list) the way you want by prefixing it with an asterisk. This causes the > sequence of items to be treated as individual arguments. So: > > Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) > st1 = (2022, 12, 13, 5, 3, 30) > dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1) > dts1 == Startt # True > > On 12/13/2022 10:43 PM, Gronicus at SGA.Ninja wrote: >> As is, Test A works. >> Comment out Test A and uncomment Test B it fails. >> In Test B, I move the data into a variable resulting with the report: >> "TypeError: an integer is required (got type tuple) >> >> How do I fix this? >> >> #--------------------------------------------------------------------- >> -------- >> import datetime >> #================================================= >> # Test A Hard coded Date/Time >> Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = >> datetime.datetime(2022, 12, 12, 21, 15, 30) >> >> # ================================================= >> # Test B Date/Time data as a variable >> #Startt = (2022, 12, 13, 5, 3, 30) >> #Stopp = (2022, 12, 12, 21, 15, 30) >> >> #Startt = datetime.datetime(Startt) >> #Stopp = datetime.datetime(Stopp) >> >> # ================================================= >> c = Startt - Stopp >> minutes = c.total_seconds() / 60 >> minutes = c.seconds / 60 >> hours = 0 >> >> while (minutes > 59): >> minutes = minutes - 60 >> hours += 1 >> minutes = round(minutes) >> print() >> print (" Hours = <" + str(hours) + ">") >> print (" Minutes = <" + str(minutes) + ">") >> >> # >> ---------------------------------------------------------------------- >> ------- >> > > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Thu Dec 15 14:34:28 2022 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 15 Dec 2022 19:34:28 +0000 Subject: Single line if statement with a continue In-Reply-To: <055e01d910b8$349de450$9dd9acf0$@gmail.com> References: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> <055e01d910b8$349de450$9dd9acf0$@gmail.com> Message-ID: On 2022-12-15 19:05, avi.e.gross at gmail.com wrote: > Multiple returns is not always a problem as it depends on the nature of a > task whether it has complex enough cases. > > I have seen code that instead sets Boolean variables when it is ready to > return and everything else keeps checking the variables to skip further > processing so the program then slides down to a single return statement. If > done properly, it boils down to the same result if VERY carefully done but > with lots of sometimes complex IF statements that may be not be updated well > if the logic changes a bit. > > In such cases, I vastly prefer clean and unambiguous returns from the > function right at the point where the decision is made, UNLESS the exit is > not always clean as there may be cleanup or finalization of some kind > required that is best done at a single point. > A problem with having a single return is that it can lead to excessive indentation: if test_1: ... if test_2: ... if test_3: ... return With multiple returns, however: if not test_1: return ... if not test_2: return ... if not test_3: return ... return > If efficiency is an issue, then clearly a rapid exit may beat one where > processing continues for a while and also often beats a method that involves > creating and calling multiple smaller functions with lots of overhead. > > Having said all that, of course, if you can find a fairly simple algorithm > that only returns from one place, use it instead of a convoluted one. The > issue is not necessarily that multiple return points are bad, but that they > are often a symptom of sloppy planning. But for some problems, they fit well > and simplify things. > > -----Original Message----- > From: Python-list On > Behalf Of Stefan Ram > Sent: Thursday, December 15, 2022 7:42 AM > To: python-list at python.org > Subject: Re: Single line if statement with a continue > > Chris Green writes: >>I always try to avoid multiple returns from functions/methods, as soon >>as things get complex it's all to easy to miss clean-up etc. > > This "complexity" could also mean that the function has > become too large. In such a case, one could say that the > /size/ of the function is the actual cause of problems > and not multiple returns. > > |Fools ignore complexity. Pragmatists suffer it. Some can avoid it. > |Geniuses remove it. > Alan Perlis (1922/1990) > > Within a small function, multiple returns are rarely > a problem. > > When a function is large, one can apply well-known > refactors. For an example, look at the code in the > first post of the thread > > Python script not letting go of files > Date: Tue, 29 Nov 2022 12:52:15 +0000 > > and then at my reply of > > 29 Nov 2022 14:44:39 GMT. > >>"No multiple returns" is often found in programming guidelines. > > I religiously followed that when I did more C programming > than today. Then, I read an article about how the result > pattern makes functions measurably slower. (It should not > with an optimizing compiler, but it did due to those > measurements. Can't find that article now, though.) > > "Result pattern" I call writing, > > if a: > result = 123 > else: > result = 456 > return result > > , instead of, > > if a: > return 123 > else > return 456 > > . > > > -- > https://mail.python.org/mailman/listinfo/python-list > From list1 at tompassin.net Thu Dec 15 13:56:05 2022 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 15 Dec 2022 13:56:05 -0500 Subject: Subtracting dates to get hours and minutes In-Reply-To: <00c701d910b1$1b6a56f0$523f04d0$@SGA.Ninja> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> <00c701d910b1$1b6a56f0$523f04d0$@SGA.Ninja> Message-ID: It's hard to be sure from what you have offered, but I suspect that you are taking the string "(2022, 12, 13, 5, 3, 30)" from the file and using it as is. When you feed that in as a starred argument, the string gets treated as a sequence where each item is a character in the string. Your example contains 26 characters, which matches the error message, so that's probably what is going on. You need to convert the string into the correct integers, because is the datetime function expects to get integers, not strings. It isn't going to work with a string that looks like a tuple when it is printed. Here is one way you could do this. From the input file, extract the string. Call it dstr. Then you have to get rid of the parentheses and separate out each item so you can convert it into an integer. So: items = dstr[1:-2].split(',') # This creates a list of strings. # print(items) --> ['2022', ' 12', ' 13', ' 5', ' 3', ' 3'] # Create a tuple of integers from the string items seq = (int(n) for n in items) # or make it a list instead: seq = [int(n) for n in items] # And here is the datetime object you wanted d1 = datetime.datetime(*seq) On 12/15/2022 1:14 PM, Gronicus at SGA.Ninja wrote: > So far so good , I can now use a variable in datetime.datetime but it only > works if I hard-code the time/date information. Now I want to have the code > read from a file but I get: TypeError: function takes at most 9 arguments > (26 given) > > I figure that the structure in the file is incorrect. What should it be? The > entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to > use it I get the error. > > The program is a bit more sophisticated now but here is the update with a > sample of the SPECIFICATIONS.txt file: > ===================================================================== > > # This program compares two Timedate values, subtracts the two and > # converts the difference to seconds and hours. > # > > # %A Monday # %a Mon # %B January # %b Jan > # %d 05 day # %m month as 01 # %Y 2020 # %y 20 > # %H 24 # %I 12 # %M 30 min # %S Seconds > > import time > import datetime > from time import gmtime, strftime ##define strftime as time/date right now > # ====================================================== > > def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7 > ItemValue = "--" > > with open("SPECIFICATIONS.txt" , 'r') as infile: > for lineEQN in infile: # loop to find each line in the file for that > dose > if ((lineEQN[4:7]== GetThisOne)): > ItemValue = lineEQN[30:60].strip() # Just the Data > return(ItemValue) > > """ > SPECIFICATIONS.txt > > IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ## > IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ## > """ > # ====================== Main() ====================================== > print() > Startt = "404" > Stopp = "404" > > Answer = "Y" > Answer = input("Run test A? (" + Answer + ")" ) > > if Answer == "Y" or Answer == "y" or Answer == "": > print() > print(" Running Test A:") > # Year Mth Day Hour Min Sec > Startt = 2018, 12, 4, 10, 7, 00 > Stopp = 2022, 12, 12, 1, 15, 30 > NowTime = 2022, 12, 14, 21, 15, 30 > else: > print(" Running Test B:") > Startt = GetSpecByItem("HRG") > Stopp = GetSpecByItem("HRB") > NowTime = strftime("(%Y, %m, %d, %H, %M, %S)") > > print() > print("55 NowTime = " + str(NowTime)) > print("56 Startt = " + str(Startt)) > print("57 Stopp = " + str(Stopp)) > print() > > NowTime = datetime.datetime(*NowTime) > Startt = datetime.datetime(*Startt) > Stopp = datetime.datetime(*Stopp) > > #Start == Startt # True" > #print("Startt test = " + Start) > # ================================================= > print() > c = NowTime - Stopp > minutes = c.total_seconds() / 60 > minutes = c.seconds / 60 > hours = 0 > > while (minutes > 59): > minutes = minutes - 60 > hours += 1 > minutes = round(minutes) > print ("77 Hours = <" + str(hours) + ">") > print ("78 Minutes = <" + str(minutes) + ">") > if hours > 7: > print(" Time to inject Humulin R u500.") > > pause = input("Pause") > # ====================================================== > > > -----Original Message----- > From: Python-list On > Behalf Of Thomas Passin > Sent: Tuesday, December 13, 2022 11:20 PM > To: python-list at python.org > Subject: Re: Subtracting dates to get hours and minutes > > Your problem is that datetime.datetime does not accept a tuple as an > argument. It expects an integer value for the first argument, but you > supplied a tuple. In Python, you can use a sequence (e.g., tuple or > list) the way you want by prefixing it with an asterisk. This causes the > sequence of items to be treated as individual arguments. So: > > Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) > st1 = (2022, 12, 13, 5, 3, 30) > dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1) > dts1 == Startt # True > > On 12/13/2022 10:43 PM, Gronicus at SGA.Ninja wrote: >> As is, Test A works. >> Comment out Test A and uncomment Test B it fails. >> In Test B, I move the data into a variable resulting with the report: >> "TypeError: an integer is required (got type tuple) >> >> How do I fix this? >> >> #--------------------------------------------------------------------- >> -------- >> import datetime >> #================================================= >> # Test A Hard coded Date/Time >> Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = >> datetime.datetime(2022, 12, 12, 21, 15, 30) >> >> # ================================================= >> # Test B Date/Time data as a variable >> #Startt = (2022, 12, 13, 5, 3, 30) >> #Stopp = (2022, 12, 12, 21, 15, 30) >> >> #Startt = datetime.datetime(Startt) >> #Stopp = datetime.datetime(Stopp) >> >> # ================================================= >> c = Startt - Stopp >> minutes = c.total_seconds() / 60 >> minutes = c.seconds / 60 >> hours = 0 >> >> while (minutes > 59): >> minutes = minutes - 60 >> hours += 1 >> minutes = round(minutes) >> print() >> print (" Hours = <" + str(hours) + ">") >> print (" Minutes = <" + str(minutes) + ">") >> >> # >> ---------------------------------------------------------------------- >> ------- >> > > -- > https://mail.python.org/mailman/listinfo/python-list > From list1 at tompassin.net Thu Dec 15 15:13:52 2022 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 15 Dec 2022 15:13:52 -0500 Subject: sqlite3 double quote behavior In-Reply-To: <9ED49723-3E93-41F5-8CDA-4CA322F6B105@gmail.com> References: <49fa4d80-7a40-5425-be63-07c08cab2b58@roelschroeven.net> <0c4ce444-4235-2091-67f9-6dc92d5fac73@roelschroeven.net> <9ED49723-3E93-41F5-8CDA-4CA322F6B105@gmail.com> Message-ID: <3253d206-34b5-554c-661c-af2ee2c2e8e0@tompassin.net> There is a Python adapter for SQLITE called "APSW". It has a config() function. I looked in the codebase and it defines the two configuration constants needed to turn off the double quote behavior (see https://sqlite.org/quirks.html). These constants are SQLITE_DBCONFIG_DQS_DDL and SQLITE_DBCONFIG_DQS_DML. This makes me think that the double-quote behavior can be turned off by Python code, though I haven't tried it. From the APSW docs (see https://rogerbinns.github.io/apsw/tips.html#about-python-apsw-and-sqlite-versions): "APSW wraps the SQLite C API. That means when SQLite adds new constant or API, then so does APSW. You can think of APSW as the Python expression of SQLite?s C API. You can lookup SQLite APIs to find which APSW functions and attributes call them." On 12/15/2022 2:18 PM, John K. Parejko wrote: > Thanks for the discussion. I?m aware that SQLite has several different options for identifier quoting, but they?re not cross-compatible with other SQL, whereas double quotes are (modulo this strange SQLite behavior). > > Is anyone here familiar with the python sqlite3 implementation? I wonder how hard it would be to raise up the `sqlite3_db_config` generically, or have a specific function to set just the DQS_DDL and DQS_DML settings? It looks like everything interesting is in `Modules/_sqlite/module.c`, but I?m not familiar with the cpython internals. > > John > >> On 13Dec 2022, at 13:58, Chris Angelico wrote: >> >> On Wed, 14 Dec 2022 at 08:19, Roel Schroeven wrote: >>> >>> Chris Angelico schreef op 13/12/2022 om 20:01: >>>> On Wed, 14 Dec 2022 at 06:00, Roel Schroeven wrote: >>>>> >>>>> Stefan Ram schreef op 13/12/2022 om 8:42: >>>>>> "John K. Parejko" writes: >>>>>>> I was just burned by this, where some tests I?d written >>>>>>> against an sqlite database did not fail in the way that they >>>>>>> ?should? have, because of this double-quoted string issue. >>>>>> >>>>>> In standard SQL, double quotes denote identifiers that are >>>>>> allowed to contain special characters. >>>>> Or that are equal SQL keywords, which can be a reason to double-quote >>>>> them. SQL engines sometimes add new keywords; explicitly marking string >>>>> literals as string literals prevents future conflicts and confusion. >>>>> >>>>> Perhaps it's a better idea to use [identifier] or `identifier` instead >>>>> though (I just learned about those on >>>>> https://sqlite.org/lang_keywords.html). Both are not standard SQL ([] is >>>>> used in MS Access and SQL Server, `` is used in MySQL) but both work in >>>>> SQLite. That should prevent any ambiguity and confusion, if it doesn't >>>>> bother you too much that it's not standard SQL. >>>>> >>>> >>>> Why not just use "identifier" which is standard SQL? >>> >>> If you accidentally type [identifire] or `identifire`, SQLite will >>> produce an unknown identifier error, alerting you immediately to your typo. >>> If you accidentally type "identifire", SQLite will silently treat it as >>> a string literal instead of an identifier, causing more difficult to >>> diagnose problems. >>> >> >> Okay, so..... exactly the same as if you use standard double quotes, >> but change the configuration option. So the options are: make >> everything worse for everyone by exacerbating the problem of >> non-standard identifier quoting, or get this API so SQLite can be >> configured, like the OP actually asked for. >> >> Yeah. Let's not do the wrong thing. >> >> ChrisA >> -- >> https://mail.python.org/mailman/listinfo/python-list > From list1 at tompassin.net Thu Dec 15 14:56:03 2022 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 15 Dec 2022 14:56:03 -0500 Subject: Single line if statement with a continue In-Reply-To: References: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> Message-ID: On 12/15/2022 3:58 AM, Chris Green wrote: > Thomas Passin wrote: >> I personally tend to use >> >> if test: return >> >> even inside larger blocks. > > I always try to avoid multiple returns from functions/methods, as soon > as things get complex it's all to easy to miss clean-up etc. > > "No multiple returns" is often found in programming guidelines. Yes, or alternatively, "If any branch uses a return, they all should." From grant.b.edwards at gmail.com Thu Dec 15 16:34:54 2022 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 15 Dec 2022 13:34:54 -0800 (PST) Subject: Single line if statement with a continue References: <1ad0365c-486c-1305-4e65-6b1bcf035b0a@tompassin.net> <055e01d910b8$349de450$9dd9acf0$@gmail.com> Message-ID: <639b92fe.050a0220.26f48.0575@mx.google.com> On 2022-12-15, MRAB wrote: > A problem with having a single return is that it can lead to excessive > indentation: > > if test_1: > ... > > if test_2: > ... > > if test_3: > ... > > return I sometimes have to work on code like that with bocks nested 8-10 levels deep spread out over hundreds of lines. The first thing I do is convert it to something like the code below. Check for error conditions up front and exit accordingly. When working in C, a "goto error" or "goto done" instead of "return" can provide a "single return" if that's deemed important. > > With multiple returns, however: > > if not test_1: > return > > ... > > if not test_2: > return > > ... > > if not test_3: > return > > ... > > return From Gronicus at SGA.Ninja Thu Dec 15 17:00:11 2022 From: Gronicus at SGA.Ninja (Gronicus at SGA.Ninja) Date: Thu, 15 Dec 2022 17:00:11 -0500 Subject: Subtracting dates to get hours and minutes In-Reply-To: <252f3f64.8d86.185171c7cb3.Webtop.120@btinternet.com> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> <00c701d910b1$1b6a56f0$523f04d0$@SGA.Ninja> <252f3f64.8d86.185171c7cb3.Webtop.120@btinternet.com> Message-ID: <00e201d910d0$9b083a70$d118af50$@SGA.Ninja> Yes, it works like a charm. On the tupility of it all. Special thanks for the explanation too?.. Now that the code no longer produces the errors, I see that the year and month not included in the calculation? How do I fix this? From: anthony.flury Sent: Thursday, December 15, 2022 1:47 PM To: Gronicus at SGA.Ninja Subject: RE: Subtracting dates to get hours and minutes What is likely happening is that when you read the data from the file you are not reading a tuple, you are reading a 26 charcter string. You have to convert that string into a tuple - the easiest way will be somthing like this : timet = tuple(int(x.strip()) for x in timestring[1:-1].split(',')) where timestring is the data you get from the file The [1:-1] removes the () from the data The .split(",") method creates a temporary list from the remaining string breaking the string where there are commas The x.strip() removes spaces from each item in the temporary list. Note that the * unpack operator doesn't just unpack tuples, it works on an iterable, so when you read the data from the file currently, and then use * on it, it will pass 26 separate characters to the function. ------ Original Message ------ From: Gronicus at SGA.Ninja To: "'Thomas Passin'" >; python-list at python.org Sent: Thursday, 15 Dec, 22 At 18:14 Subject: RE: Subtracting dates to get hours and minutes So far so good , I can now use a variable in datetime.datetime but it only works if I hard-code the time/date information. Now I want to have the code read from a file but I get: TypeError: function takes at most 9 arguments (26 given) I figure that the structure in the file is incorrect. What should it be? The entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to use it I get the error. The program is a bit more sophisticated now but here is the update with a sample of the SPECIFICATIONS.txt file: ===================================================================== # This program compares two Timedate values, subtracts the two and # converts the difference to seconds and hours. # # %A Monday # %a Mon # %B January # %b Jan # %d 05 day # %m month as 01 # %Y 2020 # %y 20 # %H 24 # %I 12 # %M 30 min # %S Seconds import time import datetime from time import gmtime, strftime ##define strftime as time/date right now # ====================================================== def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7 ItemValue = "--" with open("SPECIFICATIONS.txt" , 'r') as infile: for lineEQN in infile: # loop to find each line in the file for that dose if ((lineEQN[4:7]== GetThisOne)): ItemValue = lineEQN[30:60].strip() # Just the Data return(ItemValue) """ SPECIFICATIONS.txt IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ## IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ## """ # ====================== Main() ====================================== print() Startt = "404" Stopp = "404" Answer = "Y" Answer = input("Run test A? (" + Answer + ")" ) if Answer == "Y" or Answer == "y" or Answer == "": print() print(" Running Test A:") # Year Mth Day Hour Min Sec Startt = 2018, 12, 4, 10, 7, 00 Stopp = 2022, 12, 12, 1, 15, 30 NowTime = 2022, 12, 14, 21, 15, 30 else: print(" Running Test B:") Startt = GetSpecByItem("HRG") Stopp = GetSpecByItem("HRB") NowTime = strftime("(%Y, %m, %d, %H, %M, %S)") print() print("55 NowTime = " + str(NowTime)) print("56 Startt = " + str(Startt)) print("57 Stopp = " + str(Stopp)) print() NowTime = datetime.datetime(*NowTime) Startt = datetime.datetime(*Startt) Stopp = datetime.datetime(*Stopp) #Start == Startt # True" #print("Startt test = " + Start) # ================================================= print() c = NowTime - Stopp minutes = c.total_seconds() / 60 minutes = c.seconds / 60 hours = 0 while (minutes > 59): minutes = minutes - 60 hours += 1 minutes = round(minutes) print ("77 Hours = <" + str(hours) + ">") print ("78 Minutes = <" + str(minutes) + ">") if hours > 7: print(" Time to inject Humulin R u500.") pause = input("Pause") # ====================================================== -----Original Message----- From: Python-list > On Behalf Of Thomas Passin Sent: Tuesday, December 13, 2022 11:20 PM To: python-list at python.org Subject: Re: Subtracting dates to get hours and minutes Your problem is that datetime.datetime does not accept a tuple as an argument. It expects an integer value for the first argument, but you supplied a tuple. In Python, you can use a sequence (e.g., tuple or list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So: Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) st1 = (2022, 12, 13, 5, 3, 30) dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1) dts1 == Startt # True On 12/13/2022 10:43 PM, Gronicus at SGA.Ninja wrote: As is, Test A works. Comment out Test A and uncomment Test B it fails. In Test B, I move the data into a variable resulting with the report: "TypeError: an integer is required (got type tuple) How do I fix this? #--------------------------------------------------------------------- -------- import datetime #================================================= # Test A Hard coded Date/Time Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30) # ================================================= # Test B Date/Time data as a variable #Startt = (2022, 12, 13, 5, 3, 30) #Stopp = (2022, 12, 12, 21, 15, 30) #Startt = datetime.datetime(Startt) #Stopp = datetime.datetime(Stopp) # ================================================= c = Startt - Stopp minutes = c.total_seconds() / 60 minutes = c.seconds / 60 hours = 0 while (minutes > 59): minutes = minutes - 60 hours += 1 minutes = round(minutes) print() print (" Hours = <" + str(hours) + ">") print (" Minutes = <" + str(minutes) + ">") # ---------------------------------------------------------------------- ------- -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list From gweatherby at uchc.edu Thu Dec 15 17:22:44 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Thu, 15 Dec 2022 22:22:44 +0000 Subject: Subtracting dates to get hours and minutes In-Reply-To: <00e201d910d0$9b083a70$d118af50$@SGA.Ninja> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> <00c701d910b1$1b6a56f0$523f04d0$@SGA.Ninja> <252f3f64.8d86.185171c7cb3.Webtop.120@btinternet.com> <00e201d910d0$9b083a70$d118af50$@SGA.Ninja> Message-ID: Not sure what you mean: x = datetime.datetime(year=2018,month=12,day=4,hour=10) y = datetime.datetime(year=2022,month=12,day=13,hour=5) print(x -y) -1470 days, 5:00:00 If you want to display years, (x-y).days /365 From: Python-list on behalf of Gronicus at SGA.Ninja Date: Thursday, December 15, 2022 at 5:02 PM To: 'anthony.flury' , python-list at python.org Subject: RE: Subtracting dates to get hours and minutes *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Yes, it works like a charm. On the tupility of it all. Special thanks for the explanation too?.. Now that the code no longer produces the errors, I see that the year and month not included in the calculation? How do I fix this? From: anthony.flury Sent: Thursday, December 15, 2022 1:47 PM To: Gronicus at SGA.Ninja Subject: RE: Subtracting dates to get hours and minutes What is likely happening is that when you read the data from the file you are not reading a tuple, you are reading a 26 charcter string. You have to convert that string into a tuple - the easiest way will be somthing like this : timet = tuple(int(x.strip()) for x in timestring[1:-1].split(',')) where timestring is the data you get from the file The [1:-1] removes the () from the data The .split(",") method creates a temporary list from the remaining string breaking the string where there are commas The x.strip() removes spaces from each item in the temporary list. Note that the * unpack operator doesn't just unpack tuples, it works on an iterable, so when you read the data from the file currently, and then use * on it, it will pass 26 separate characters to the function. ------ Original Message ------ From: Gronicus at SGA.Ninja To: "'Thomas Passin'" >; python-list at python.org Sent: Thursday, 15 Dec, 22 At 18:14 Subject: RE: Subtracting dates to get hours and minutes So far so good , I can now use a variable in datetime.datetime but it only works if I hard-code the time/date information. Now I want to have the code read from a file but I get: TypeError: function takes at most 9 arguments (26 given) I figure that the structure in the file is incorrect. What should it be? The entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to use it I get the error. The program is a bit more sophisticated now but here is the update with a sample of the SPECIFICATIONS.txt file: ===================================================================== # This program compares two Timedate values, subtracts the two and # converts the difference to seconds and hours. # # %A Monday # %a Mon # %B January # %b Jan # %d 05 day # %m month as 01 # %Y 2020 # %y 20 # %H 24 # %I 12 # %M 30 min # %S Seconds import time import datetime from time import gmtime, strftime ##define strftime as time/date right now # ====================================================== def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7 ItemValue = "--" with open("SPECIFICATIONS.txt" , 'r') as infile: for lineEQN in infile: # loop to find each line in the file for that dose if ((lineEQN[4:7]== GetThisOne)): ItemValue = lineEQN[30:60].strip() # Just the Data return(ItemValue) """ SPECIFICATIONS.txt IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ## IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ## """ # ====================== Main() ====================================== print() Startt = "404" Stopp = "404" Answer = "Y" Answer = input("Run test A? (" + Answer + ")" ) if Answer == "Y" or Answer == "y" or Answer == "": print() print(" Running Test A:") # Year Mth Day Hour Min Sec Startt = 2018, 12, 4, 10, 7, 00 Stopp = 2022, 12, 12, 1, 15, 30 NowTime = 2022, 12, 14, 21, 15, 30 else: print(" Running Test B:") Startt = GetSpecByItem("HRG") Stopp = GetSpecByItem("HRB") NowTime = strftime("(%Y, %m, %d, %H, %M, %S)") print() print("55 NowTime = " + str(NowTime)) print("56 Startt = " + str(Startt)) print("57 Stopp = " + str(Stopp)) print() NowTime = datetime.datetime(*NowTime) Startt = datetime.datetime(*Startt) Stopp = datetime.datetime(*Stopp) #Start == Startt # True" #print("Startt test = " + Start) # ================================================= print() c = NowTime - Stopp minutes = c.total_seconds() / 60 minutes = c.seconds / 60 hours = 0 while (minutes > 59): minutes = minutes - 60 hours += 1 minutes = round(minutes) print ("77 Hours = <" + str(hours) + ">") print ("78 Minutes = <" + str(minutes) + ">") if hours > 7: print(" Time to inject Humulin R u500.") pause = input("Pause") # ====================================================== -----Original Message----- From: Python-list > On Behalf Of Thomas Passin Sent: Tuesday, December 13, 2022 11:20 PM To: python-list at python.org Subject: Re: Subtracting dates to get hours and minutes Your problem is that datetime.datetime does not accept a tuple as an argument. It expects an integer value for the first argument, but you supplied a tuple. In Python, you can use a sequence (e.g., tuple or list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So: Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) st1 = (2022, 12, 13, 5, 3, 30) dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1) dts1 == Startt # True On 12/13/2022 10:43 PM, Gronicus at SGA.Ninja wrote: As is, Test A works. Comment out Test A and uncomment Test B it fails. In Test B, I move the data into a variable resulting with the report: "TypeError: an integer is required (got type tuple) How do I fix this? #--------------------------------------------------------------------- -------- import datetime #================================================= # Test A Hard coded Date/Time Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30) # ================================================= # Test B Date/Time data as a variable #Startt = (2022, 12, 13, 5, 3, 30) #Stopp = (2022, 12, 12, 21, 15, 30) #Startt = datetime.datetime(Startt) #Stopp = datetime.datetime(Stopp) # ================================================= c = Startt - Stopp minutes = c.total_seconds() / 60 minutes = c.seconds / 60 hours = 0 while (minutes > 59): minutes = minutes - 60 hours += 1 minutes = round(minutes) print() print (" Hours = <" + str(hours) + ">") print (" Minutes = <" + str(minutes) + ">") # ---------------------------------------------------------------------- ------- -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!g11w53LvI3sz4DsypU-K7satSGvJqZDO1QO9M6Q6Tl3HmndPRIRrkNdzq4_ZJbTiq68dzN535TH75Ks0junwPQ$ -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!g11w53LvI3sz4DsypU-K7satSGvJqZDO1QO9M6Q6Tl3HmndPRIRrkNdzq4_ZJbTiq68dzN535TH75Ks0junwPQ$ -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!g11w53LvI3sz4DsypU-K7satSGvJqZDO1QO9M6Q6Tl3HmndPRIRrkNdzq4_ZJbTiq68dzN535TH75Ks0junwPQ$ From Gronicus at SGA.Ninja Thu Dec 15 17:49:23 2022 From: Gronicus at SGA.Ninja (Gronicus at SGA.Ninja) Date: Thu, 15 Dec 2022 17:49:23 -0500 Subject: Subtracting dates to get hours and minutes In-Reply-To: <252f3f64.8d86.185171c7cb3.Webtop.120@btinternet.com> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> <00c701d910b1$1b6a56f0$523f04d0$@SGA.Ninja> <252f3f64.8d86.185171c7cb3.Webtop.120@btinternet.com> Message-ID: <00ec01d910d7$7a9023a0$6fb06ae0$@SGA.Ninja> Yes, it works like a charm. On the tupility of it all. Special thanks for the explanation too?.. (Originally asked but I found the errors. All is working) Now that the code no longer produces the errors, I see that the year and month not included in the calculation? How do I fix this? From: anthony.flury Sent: Thursday, December 15, 2022 1:47 PM To: Gronicus at SGA.Ninja Subject: RE: Subtracting dates to get hours and minutes What is likely happening is that when you read the data from the file you are not reading a tuple, you are reading a 26 charcter string. You have to convert that string into a tuple - the easiest way will be somthing like this : timet = tuple(int(x.strip()) for x in timestring[1:-1].split(',')) where timestring is the data you get from the file The [1:-1] removes the () from the data The .split(",") method creates a temporary list from the remaining string breaking the string where there are commas The x.strip() removes spaces from each item in the temporary list. Note that the * unpack operator doesn't just unpack tuples, it works on an iterable, so when you read the data from the file currently, and then use * on it, it will pass 26 separate characters to the function. ------ Original Message ------ From: Gronicus at SGA.Ninja To: "'Thomas Passin'" >; python-list at python.org Sent: Thursday, 15 Dec, 22 At 18:14 Subject: RE: Subtracting dates to get hours and minutes So far so good , I can now use a variable in datetime.datetime but it only works if I hard-code the time/date information. Now I want to have the code read from a file but I get: TypeError: function takes at most 9 arguments (26 given) I figure that the structure in the file is incorrect. What should it be? The entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to use it I get the error. The program is a bit more sophisticated now but here is the update with a sample of the SPECIFICATIONS.txt file: ===================================================================== # This program compares two Timedate values, subtracts the two and # converts the difference to seconds and hours. # # %A Monday # %a Mon # %B January # %b Jan # %d 05 day # %m month as 01 # %Y 2020 # %y 20 # %H 24 # %I 12 # %M 30 min # %S Seconds import time import datetime from time import gmtime, strftime ##define strftime as time/date right now # ====================================================== def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7 ItemValue = "--" with open("SPECIFICATIONS.txt" , 'r') as infile: for lineEQN in infile: # loop to find each line in the file for that dose if ((lineEQN[4:7]== GetThisOne)): ItemValue = lineEQN[30:60].strip() # Just the Data return(ItemValue) """ SPECIFICATIONS.txt IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ## IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ## """ # ====================== Main() ====================================== print() Startt = "404" Stopp = "404" Answer = "Y" Answer = input("Run test A? (" + Answer + ")" ) if Answer == "Y" or Answer == "y" or Answer == "": print() print(" Running Test A:") # Year Mth Day Hour Min Sec Startt = 2018, 12, 4, 10, 7, 00 Stopp = 2022, 12, 12, 1, 15, 30 NowTime = 2022, 12, 14, 21, 15, 30 else: print(" Running Test B:") Startt = GetSpecByItem("HRG") Stopp = GetSpecByItem("HRB") NowTime = strftime("(%Y, %m, %d, %H, %M, %S)") print() print("55 NowTime = " + str(NowTime)) print("56 Startt = " + str(Startt)) print("57 Stopp = " + str(Stopp)) print() NowTime = datetime.datetime(*NowTime) Startt = datetime.datetime(*Startt) Stopp = datetime.datetime(*Stopp) #Start == Startt # True" #print("Startt test = " + Start) # ================================================= print() c = NowTime - Stopp minutes = c.total_seconds() / 60 minutes = c.seconds / 60 hours = 0 while (minutes > 59): minutes = minutes - 60 hours += 1 minutes = round(minutes) print ("77 Hours = <" + str(hours) + ">") print ("78 Minutes = <" + str(minutes) + ">") if hours > 7: print(" Time to inject Humulin R u500.") pause = input("Pause") # ====================================================== -----Original Message----- From: Python-list > On Behalf Of Thomas Passin Sent: Tuesday, December 13, 2022 11:20 PM To: python-list at python.org Subject: Re: Subtracting dates to get hours and minutes Your problem is that datetime.datetime does not accept a tuple as an argument. It expects an integer value for the first argument, but you supplied a tuple. In Python, you can use a sequence (e.g., tuple or list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So: Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) st1 = (2022, 12, 13, 5, 3, 30) dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1) dts1 == Startt # True On 12/13/2022 10:43 PM, Gronicus at SGA.Ninja wrote: As is, Test A works. Comment out Test A and uncomment Test B it fails. In Test B, I move the data into a variable resulting with the report: "TypeError: an integer is required (got type tuple) How do I fix this? #--------------------------------------------------------------------- -------- import datetime #================================================= # Test A Hard coded Date/Time Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30) # ================================================= # Test B Date/Time data as a variable #Startt = (2022, 12, 13, 5, 3, 30) #Stopp = (2022, 12, 12, 21, 15, 30) #Startt = datetime.datetime(Startt) #Stopp = datetime.datetime(Stopp) # ================================================= c = Startt - Stopp minutes = c.total_seconds() / 60 minutes = c.seconds / 60 hours = 0 while (minutes > 59): minutes = minutes - 60 hours += 1 minutes = round(minutes) print() print (" Hours = <" + str(hours) + ">") print (" Minutes = <" + str(minutes) + ">") # ---------------------------------------------------------------------- ------- -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Thu Dec 15 17:35:26 2022 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 15 Dec 2022 17:35:26 -0500 Subject: Subtracting dates to get hours and minutes In-Reply-To: References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> <00c701d910b1$1b6a56f0$523f04d0$@SGA.Ninja> Message-ID: <3d0dae98-1e5d-f185-74b7-d24b8e4fa8df@tompassin.net> Oops, "items = dstr[1:-2].split(',')" should have read "items = dstr[1:-1].split(',')". On 12/15/2022 1:56 PM, Thomas Passin wrote: > It's hard to be sure from what you have offered, but I suspect that you > are taking the string "(2022, 12, 13,? 5,? 3, 30)" from the file and > using it as is.? When you feed that in as a starred argument, the string > gets treated as a sequence where each item is a character in the string. > ?Your example contains 26 characters, which matches the error message, > so that's probably what is going on. > > You need to convert the string into the correct integers, because is the > datetime function expects to get integers, not strings.? It isn't going > to work with a string that looks like a tuple when it is printed. > > Here is one way you could do this.? From the input file, extract the > string. Call it dstr.? Then you have to get rid of the parentheses and > separate out each item so you can convert it into an integer.? So: > > items = dstr[1:-2].split(',')? # This creates a list of strings. > # print(items) --> ['2022', ' 12', ' 13', '? 5', '? 3', ' 3'] > > # Create a tuple of integers from the string items > seq = (int(n) for n in items) > # or make it a list instead: seq = [int(n) for n in items] > > # And here is the datetime object you wanted > d1 = datetime.datetime(*seq) > > > On 12/15/2022 1:14 PM, Gronicus at SGA.Ninja wrote: >> So far so good , I can now use a variable in datetime.datetime but it >> only >> works if I hard-code the time/date information. Now I want to have the >> code >> read from a file but I get: TypeError: function takes at most 9 arguments >> (26 given) >> >> I figure that the structure in the file is incorrect. What should it >> be? The >> entry in the file is (2022, 12, 13,? 5,? 3, 30) but when my program >> tries to >> use it I get the error. >> >> The program is a bit more sophisticated now but here is the update with a >> sample of the SPECIFICATIONS.txt file: >> ===================================================================== >> >> # This program compares two Timedate values, subtracts the two and >> # converts the difference to seconds and hours. >> # >> >> #? %A Monday??? #? %a Mon?????????? #? %B January?? #? %b Jan >> #? %d 05 day??? #? %m month as 01?? #? %Y 2020????? #? %y 20 >> #? %H 24??????? #? %I 12??????????? #? %M 30 min??? #? %S Seconds >> >> import time >> import datetime >> from time import gmtime, strftime ##define strftime as time/date right >> now >> # ====================================================== >> >> def GetSpecByItem(GetThisOne):? #get line by item in column 4 - 7 >> ???? ItemValue = "--" >> ???? with open("SPECIFICATIONS.txt" , 'r') as infile: >> ????? for lineEQN in infile: # loop to find each line in the file for >> that >> dose >> ???????? if ((lineEQN[4:7]== GetThisOne)): >> ??????????? ItemValue = lineEQN[30:60].strip()?? # Just the Data >> ???? return(ItemValue) >> >> """ >> SPECIFICATIONS.txt >> >> IYf HRB Humalog R Date?????????? (2018, 12, 4, 10,? 7, 00)?????????? ## >> IYf HRG Humulin R Date?????????? (2022, 12, 13,? 5,? 3, 30)????????? ## >> """ >> # ====================== Main() ====================================== >> print() >> Startt = "404" >> Stopp? = "404" >> >> Answer = "Y" >> Answer = input("Run test A? (" + Answer + ")" ) >> >> if Answer == "Y" or Answer == "y" or Answer == "": >> ??? print() >> ??? print("???? Running Test A:") >> #?????????? Year? Mth Day Hour Min Sec >> ??? Startt? =?? 2018, 12, 4, 10,? 7, 00 >> ??? Stopp?? =?? 2022, 12, 12, 1, 15, 30 >> ??? NowTime =?? 2022, 12, 14, 21, 15, 30 >> else: >> ??? print("???? Running Test B:") >> ??? Startt = GetSpecByItem("HRG") >> ??? Stopp =? GetSpecByItem("HRB") >> ??? NowTime = strftime("(%Y, %m, %d, %H, %M, %S)") >> print() >> print("55??? NowTime = " + str(NowTime)) >> print("56???? Startt = " + str(Startt)) >> print("57????? Stopp = " + str(Stopp)) >> print() >> >> NowTime =? datetime.datetime(*NowTime) >> Startt =?? datetime.datetime(*Startt) >> Stopp =??? datetime.datetime(*Stopp) >> >> #Start == Startt? # True" >> #print("Startt test = " + Start) >> # ================================================= >> print() >> c = NowTime - Stopp >> minutes = c.total_seconds() / 60 >> minutes = c.seconds / 60 >> hours = 0 >> >> while (minutes > 59): >> ???????? minutes = minutes - 60 >> ???????? hours += 1 >> minutes = round(minutes) >> print ("77 Hours =???? <" + str(hours) + ">") >> print ("78 Minutes =?? <" + str(minutes) + ">") >> if hours > 7: >> ???? print(" Time to inject Humulin R u500.") >> >> pause = input("Pause") >> # ====================================================== >> >> >> -----Original Message----- >> From: Python-list On >> Behalf Of Thomas Passin >> Sent: Tuesday, December 13, 2022 11:20 PM >> To: python-list at python.org >> Subject: Re: Subtracting dates to get hours and minutes >> >> Your problem is that datetime.datetime does not accept a tuple as an >> argument.? It expects an integer value for the first argument, but you >> supplied a tuple.? In Python, you can use a sequence (e.g., tuple or >> list) the way you want by prefixing it with an asterisk.? This causes the >> sequence of items to be treated as individual arguments. So: >> >> Startt = datetime.datetime(2022, 12, 13,? 5,? 3, 30) >> st1 = (2022, 12, 13,? 5,? 3, 30) >> dts1 = datetime.datetime(*st1)? # NOT datetime.datetime(st1) >> dts1 == Startt? # True >> >> On 12/13/2022 10:43 PM, Gronicus at SGA.Ninja wrote: >>> ?? As is, Test A works. >>> ?? Comment out Test A and uncomment Test B it fails. >>> ?? In Test B, I move the data into a variable resulting with the report: >>> ????????????? "TypeError: an integer is required (got type tuple) >>> >>> How do I fix this? >>> >>> #--------------------------------------------------------------------- >>> -------- >>> import datetime >>> #================================================= >>> #???????? Test A?? Hard coded Date/Time >>> Startt = datetime.datetime(2022, 12, 13,? 5,? 3, 30) Stopp = >>> datetime.datetime(2022, 12, 12, 21, 15, 30) >>> >>> # ================================================= >>> #???????? Test B?? Date/Time data as a variable >>> #Startt = (2022, 12, 13,? 5,? 3, 30) >>> #Stopp =? (2022, 12, 12, 21, 15, 30) >>> >>> #Startt = datetime.datetime(Startt) >>> #Stopp =? datetime.datetime(Stopp) >>> >>> # ================================================= >>> c = Startt - Stopp >>> minutes = c.total_seconds() / 60 >>> minutes = c.seconds / 60 >>> hours = 0 >>> >>> while (minutes > 59): >>> ????????? minutes = minutes - 60 >>> ????????? hours += 1 >>> minutes = round(minutes) >>> print() >>> print ("?????? Hours =? <" + str(hours) + ">") >>> print ("???? Minutes =? <" + str(minutes) + ">") >>> >>> # >>> ---------------------------------------------------------------------- >>> ------- >>> >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From python at mrabarnett.plus.com Thu Dec 15 23:34:06 2022 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 16 Dec 2022 04:34:06 +0000 Subject: Subtracting dates to get hours and minutes In-Reply-To: <00ec01d910d7$7a9023a0$6fb06ae0$@SGA.Ninja> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> <00c701d910b1$1b6a56f0$523f04d0$@SGA.Ninja> <252f3f64.8d86.185171c7cb3.Webtop.120@btinternet.com> <00ec01d910d7$7a9023a0$6fb06ae0$@SGA.Ninja> Message-ID: <7420959b-1f58-5caa-ba7a-37dcbd676df4@mrabarnett.plus.com> On 2022-12-15 22:49, Gronicus at SGA.Ninja wrote: > Yes, it works like a charm. On the tupility of it all. > Special thanks for the explanation too?.. > > > > (Originally asked but I found the errors. All is working) > > Now that the code no longer produces the errors, I see that the year and month not included in the calculation? How do I fix this? > > How long is a month? How many months are there until January 1? On December 25, many months will there be until January 1? And how many years are there until January 1? [snip] From list1 at tompassin.net Fri Dec 16 00:25:22 2022 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 16 Dec 2022 00:25:22 -0500 Subject: Subtracting dates to get hours and minutes In-Reply-To: <7420959b-1f58-5caa-ba7a-37dcbd676df4@mrabarnett.plus.com> References: <64B09923-9660-4E02-A5BA-E1F2FC453DAE@barrys-emacs.org> <003901d90def$36620a80$a3261f80$@SGA.Ninja> <016201d90f6e$3eae74a0$bc0b5de0$@SGA.Ninja> <503d15f0-18bb-409b-e911-e1c2de2ac90b@tompassin.net> <00c701d910b1$1b6a56f0$523f04d0$@SGA.Ninja> <252f3f64.8d86.185171c7cb3.Webtop.120@btinternet.com> <00ec01d910d7$7a9023a0$6fb06ae0$@SGA.Ninja> <7420959b-1f58-5caa-ba7a-37dcbd676df4@mrabarnett.plus.com> Message-ID: On 12/15/2022 11:34 PM, MRAB wrote: > On 2022-12-15 22:49, Gronicus at SGA.Ninja wrote: >> Yes, it works like a charm. On the tupility of it all. >> Special thanks for the explanation too?.. >> >> >> (Originally asked but I found the errors. All is working) >> >> Now that the code no longer produces the errors, I see that the year >> and month not included in the calculation? How do I fix this? First you should read about the function you are using. In this case, it is at https://docs.python.org/3.10/library/datetime.html I found this page using an internet search for "python datetime.datetime". All Python functions, classes, and methods will normally be found in the documentation for the standard library, as this one is. You should also look at datetime.timedelta, as various people have posted here. Try to understand what is being described. Then try to make simple examples that will show if you can get what you want, or if not, what more information you need. Look through the rest of the documentation of (in this case) the datetime module and see if any of the other functionality looks like it will produce what you want. It is important to understand clearly what your input data is like, and what results you need to achieve. If you are not clear, or do not express yourself clearly, it will be hard and frustrating for others on the list to assist you. For example, you wrote "I see that the year and month not included in the calculation". I don't know what you mean. You already include the month in the tuple that you feed to datetime.datetime(). That is, in the input string you showed, "(2022, 12, 13, 5, 3, 30)", it seems that "2022" represents a year, "12" represents a month, "13" represents a day of the month, and so forth. So I don't understand how year and month not included. I see that you do think that something is not coming out right, but you need to be more precise about what you mean so that others can understand too. To succeed at programming, you need to be very precise about attending to details because the computer cannot know what you have in your mind. To succeed at getting help, you have to be precise and accurate about what you want to achieve and what is not coming out right, and describe those things simply and clearly to other people. In other words, please help us to help you. From kaiserarnhart at gmail.com Fri Dec 16 11:07:21 2022 From: kaiserarnhart at gmail.com (Kaiser Arnhart) Date: Fri, 16 Dec 2022 10:07:21 -0600 Subject: Download Not Working In-Reply-To: References: Message-ID: <09FE50A0-578D-4DF3-BF5E-66B787ED5D4F@gmail.com> > Good afternoon, > > I am unable to open Python 3 after downloading. For context, I uninstalled it due to not checking the "Add to Path" box and then I reinstalled after checking that box and now none of the downloads will open and run Python 3. Please help. > > Thanks, Kaiser Arnhart Baylor University Ashton Woods - Project Manager > On Dec 16, 2022, at 9:14 AM, Kaiser Arnhart wrote: > > ? > Good afternoon, > > I am unable to open Python 3 after downloading. For context, I uninstalled it due to not checking the "Add to Path" box and then I reinstalled after checking that box and now none of the downloads will open and run Python 3. Please help. > > Thanks, > > -- > Kaiser Arnhart > Baylor University > Ashton Woods - Project Manager > > From PythonList at DancesWithMice.info Fri Dec 16 11:40:50 2022 From: PythonList at DancesWithMice.info (dn) Date: Sat, 17 Dec 2022 05:40:50 +1300 Subject: Download Not Working In-Reply-To: <09FE50A0-578D-4DF3-BF5E-66B787ED5D4F@gmail.com> References: <09FE50A0-578D-4DF3-BF5E-66B787ED5D4F@gmail.com> Message-ID: On 17/12/2022 05.07, Kaiser Arnhart wrote: >> Good afternoon, >> >> I am unable to open Python 3 after downloading. For context, I uninstalled it due to not checking the "Add to Path" box and then I reinstalled after checking that box and now none of the downloads will open and run Python 3. Please help. >> >> Thanks, > > > Kaiser Arnhart > Baylor University > Ashton Woods - Project Manager > >> On Dec 16, 2022, at 9:14 AM, Kaiser Arnhart wrote: >> >> ? >> Good afternoon, >> >> I am unable to open Python 3 after downloading. For context, I uninstalled it due to not checking the "Add to Path" box and then I reinstalled after checking that box and now none of the downloads will open and run Python 3. Please help. >> >> Thanks, >> >> -- >> Kaiser Arnhart >> Baylor University >> Ashton Woods - Project Manager Please be advised that there are many download sources, and several operating systems which will run Python. Please provide more precise information, including what is visible in the Download folder "after downloading", and which command(s) are being used to "open and run Python 3". Assuming MS-Windows, please review the documentation at: https://docs.python.org/3/using/windows.html (or navigate from there to appropriate advice) -- Regards, =dn From list1 at tompassin.net Fri Dec 16 11:45:43 2022 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 16 Dec 2022 11:45:43 -0500 Subject: Download Not Working In-Reply-To: <09FE50A0-578D-4DF3-BF5E-66B787ED5D4F@gmail.com> References: <09FE50A0-578D-4DF3-BF5E-66B787ED5D4F@gmail.com> Message-ID: <52a16756-4e87-ce35-b22a-01b3e43f58d8@tompassin.net> Please be more informative! Is this on Windows? Did Python 3 run as you expected, before you uninstalled it? Exactly how did you try to launch Python? Exactly what did you observe when it appeared not to run? Did you try any other ways to run it? What version of Python are you talking about? Did you install it for you only or for all users? What did you expect to see when you tried to run it? On 12/16/2022 11:07 AM, Kaiser Arnhart wrote: >> Good afternoon, >> >> I am unable to open Python 3 after downloading. For context, I uninstalled it due to not checking the "Add to Path" box and then I reinstalled after checking that box and now none of the downloads will open and run Python 3. Please help. >> >> Thanks, > > > Kaiser Arnhart > Baylor University > Ashton Woods - Project Manager > >> On Dec 16, 2022, at 9:14 AM, Kaiser Arnhart wrote: >> >> ? >> Good afternoon, >> >> I am unable to open Python 3 after downloading. For context, I uninstalled it due to not checking the "Add to Path" box and then I reinstalled after checking that box and now none of the downloads will open and run Python 3. Please help. >> >> Thanks, >> >> -- >> Kaiser Arnhart >> Baylor University >> Ashton Woods - Project Manager >> >> From mats at wichmann.us Fri Dec 16 14:45:03 2022 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 16 Dec 2022 12:45:03 -0700 Subject: Download Not Working In-Reply-To: <09FE50A0-578D-4DF3-BF5E-66B787ED5D4F@gmail.com> References: <09FE50A0-578D-4DF3-BF5E-66B787ED5D4F@gmail.com> Message-ID: <30b4be5c-63d1-bfa5-5aa7-8cb837ec3275@wichmann.us> On 12/16/22 09:07, Kaiser Arnhart wrote: >> Good afternoon, >> >> I am unable to open Python 3 after downloading. For context, I uninstalled it due to not checking the "Add to Path" box Others have already asked for more details. On the above, though, note that you can fix many aspects of the install on Windows without uninstalling. Open the Apps & Features applet. Click on Python. Click on Modify. follow the steps from there... the path thin is on the Advanced Options page. From romimarcov at gmail.com Fri Dec 16 21:20:56 2022 From: romimarcov at gmail.com (Romina Marcovecchio) Date: Fri, 16 Dec 2022 18:20:56 -0800 (PST) Subject: Cannot import gdal in jupyter notebook In-Reply-To: References: Message-ID: <88188f08-c00e-48d5-a550-8716bd11a7f2n@googlegroups.com> El mi?rcoles, 12 de octubre de 2022 a las 10:18:23 UTC-3, Abdul Haseeb Azizi escribi?: > On Wednesday, October 12, 2022 at 9:51:22 AM UTC+2, Abdul Haseeb Azizi wrote: > > On Tuesday, October 11, 2022 at 10:29:34 PM UTC+2, MRAB wrote: > > > On 2022-10-11 20:38, Thomas Passin wrote: > > > > On Windows, when I tried to install gdal using pip, it needed to compile > > > > part of it. I'm not set up with the Microsoft compiler and header > > > > files, so that failed. If you are on Windows, you will need to look for > > > > a binary wheel to install, or install and configure the compiler and > > > > header files. > > > > > > > The PyPI page at https://pypi.org/project/GDAL/ has this: > > > > > > """ > > > Conda > > > GDAL can be quite complex to build and install, particularly on Windows > > > and MacOS. Pre built binaries are provided for the conda system: > > > > > > https://docs.conda.io/en/latest/ > > > > > > By the conda-forge project: > > > > > > https://conda-forge.org/ > > > """ > > > > > > > On 10/11/2022 11:53 AM, Abdul Haseeb Azizi wrote: > > > >> Hi everyone, > > > >> I am new to python and I am trying to utilize this code "from osgeo import gdal". I installed python 3.10 and also I installed anaconda3 to solve this matter but I could not succeed. When I run that code I get the following error. > > > >> --------------------------------------------------------------------------- > > > >> ModuleNotFoundError Traceback (most recent call last) > > > >> Cell In [1], line 1 > > > >> ----> 1 from osgeo import gdal > > > >> > > > >> ModuleNotFoundError: No module named 'osgeo' > > > >> > > > >> I also tried to create anaconda environment and enter the following codes: > > > >> conda crate --name pygdal > > > >> conda activate pygdal > > > >> conda install -c conda-forge gdal > > > >> > > > >> I don't what is the problem. Any help is appreciated to solve this matter. > > > >> Looking forward to hear from you. > > > >> > > > >> with regards > > > >> Abdul > > > > > > Thanks a lot for your recommendations. > > As I mentioned before I installed conda and also created conda environment using the following codes: > > Step 1: Create conda environment > > > > conda create --name venv > > > > After creating the virtual environment, by default it will install some of the packages. > > Step 2: Installation of gdal > > conda install -c conda-forge gdal > > Step 3: Installation of ipykernel > > > > conda install -c anaconda ipykernel > > > > Step 4: Add ipykernel and run jupyternotebook > > > > python -m ipykernel install --user --name=venv > > jupyter notebook > > > > > > still I get the following error: > > > > %pip install gdal > > > > Requirement already satisfied: gdal in c:\users\abdul\anaconda3\lib\site-packages (3.4.1) > > Note: you may need to restart the kernel to use updated packages. > > > > from osgeo import gdal > > > > > > --------------------------------------------------------------------------- > > ImportError Traceback (most recent call last) > > File ~\anaconda3\lib\site-packages\osgeo\__init__.py:29, in swig_import_helper() > > 28 try: > > ---> 29 return importlib.import_module(mname) > > 30 except ImportError: > > > > File ~\anaconda3\lib\importlib\__init__.py:127, in import_module(name, package) > > 126 level += 1 > > --> 127 return _bootstrap._gcd_import(name[level:], package, level) > > > > File :1030, in _gcd_import(name, package, level) > > > > File :1007, in _find_and_load(name, import_) > > > > File :986, in _find_and_load_unlocked(name, import_) > > > > File :666, in _load_unlocked(spec) > > > > File :565, in module_from_spec(spec) > > > > File :1173, in create_module(self, spec) > > > > File :228, in _call_with_frames_removed(f, *args, **kwds) > > > > ImportError: DLL load failed while importing _gdal: The specified module could not be found. > > > > During handling of the above exception, another exception occurred: > > > > ImportError Traceback (most recent call last) > > Input In [1], in () > > ----> 1 from osgeo import gdal > > File ~\anaconda3\lib\site-packages\osgeo\__init__.py:45, in > > 41 raise ImportError(traceback_string + '\n' + msg) > > 42 return importlib.import_module('_gdal') > > ---> 45 _gdal = swig_import_helper() > > 46 del swig_import_helper > > 48 __version__ = _gdal.__version__ = _gdal.VersionInfo("RELEASE_NAME") > > > > File ~\anaconda3\lib\site-packages\osgeo\__init__.py:41, in swig_import_helper() > > 39 import traceback > > 40 traceback_string = ''.join(traceback.format_exception(*sys.exc_info())) > > ---> 41 raise ImportError(traceback_string + '\n' + msg) > > 42 return importlib.import_module('_gdal') > > > > ImportError: Traceback (most recent call last): > > File "C:\Users\abdul\anaconda3\lib\site-packages\osgeo\__init__.py", line 29, in swig_import_helper > > return importlib.import_module(mname) > > File "C:\Users\abdul\anaconda3\lib\importlib\__init__.py", line 127, in import_module > > return _bootstrap._gcd_import(name[level:], package, level) > > File "", line 1030, in _gcd_import > > File "", line 1007, in _find_and_load > > File "", line 986, in _find_and_load_unlocked > > File "", line 666, in _load_unlocked > > File "", line 565, in module_from_spec > > File "", line 1173, in create_module > > File "", line 228, in _call_with_frames_removed > > ImportError: DLL load failed while importing _gdal: The specified module could not be found. > > > > On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH. > > If gdalXXX.dll is in the PATH, then set the USE_PATH_FOR_GDAL_PYTHON=YES environment variable > > to feed the PATH into os.add_dll_directory(). > > > > I hope you could look at the errors and guide me to solve this problem. > > > > with regards > > Abdul > Hi all, > I followed the instructions given in the following link and I could install gdal and it works perfectly now. > In case this might be of use for anyone of you. > https://www.quora.com/How-do-I-install-gdal-in-PyCharm > > thanks Hola, no he podido solucionar el problema gdal: ImportError Traceback (most recent call last) Cell In[4], line 1 ----> 1 import rasterio File ~\anaconda3\envs\myenv1\lib\site-packages\rasterio\__init__.py:9 6 from logging import NullHandler 7 from pathlib import Path ----> 9 from rasterio._base import gdal_version 10 from rasterio.drivers import driver_from_extension, is_blacklisted 11 from rasterio.dtypes import ( 12 bool_, 13 ubyte, (...) 25 check_dtype, 26 ) ImportError: DLL load failed while importing _base: No se puede encontrar el m?dulo especificado. From email at paulstgeorge.com Sat Dec 17 06:51:17 2022 From: email at paulstgeorge.com (Paul St George) Date: Sat, 17 Dec 2022 12:51:17 +0100 Subject: String to Float, without introducing errors Message-ID: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> I have a large/long array of numbers in an external file. The numbers look like this: -64550.727 -64511.489 -64393.637 -64196.763 -63920.2 -63563.037 -63124.156 -62602.254 -61995.895 -61303.548 -60523.651 -59654.66 ... When I bring the numbers into my code, they are Strings. To use the numbers in my code, I want to change the Strings to Float type because the code will not work with Strings but I do not want to change the numbers in any other way. So, I want my Strings (above) to be these numbers. -64550.727 -64511.489 -64393.637 -64196.763 -63920.2 -63563.037 -63124.156 -62602.254 -61995.895 -61303.548 -60523.651 -59654.66 ... Please help! From gweatherby at uchc.edu Sat Dec 17 06:59:59 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Sat, 17 Dec 2022 11:59:59 +0000 Subject: String to Float, without introducing errors In-Reply-To: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> Message-ID: https://docs.python.org/3/library/decimal.html Get Outlook for iOS ________________________________ From: Python-list on behalf of Paul St George Sent: Saturday, December 17, 2022 6:51:17 AM To: python-list at python.org Subject: String to Float, without introducing errors *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** I have a large/long array of numbers in an external file. The numbers look like this: -64550.727 -64511.489 -64393.637 -64196.763 -63920.2 -63563.037 -63124.156 -62602.254 -61995.895 -61303.548 -60523.651 -59654.66 ... When I bring the numbers into my code, they are Strings. To use the numbers in my code, I want to change the Strings to Float type because the code will not work with Strings but I do not want to change the numbers in any other way. So, I want my Strings (above) to be these numbers. -64550.727 -64511.489 -64393.637 -64196.763 -63920.2 -63563.037 -63124.156 -62602.254 -61995.895 -61303.548 -60523.651 -59654.66 ... Please help! -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!guE_zPsjxMW4k6nHIdOqZbrt8SdjUC9GELXgSHatARIr2PrAYr6tXCmixkZGNocjsf9SKLduQFjZjM7tOeaQ$ From learn2program at gmail.com Sat Dec 17 07:11:37 2022 From: learn2program at gmail.com (Alan Gauld) Date: Sat, 17 Dec 2022 12:11:37 +0000 Subject: String to Float, without introducing errors In-Reply-To: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> Message-ID: <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> On 17/12/2022 11:51, Paul St George wrote: > I have a large/long array of numbers in an external file. The numbers look like this: > > -64550.727 > -64511.489 > -64393.637 > -64196.763 > -63920.2 > When I bring the numbers into my code, they are Strings. To use the > numbers in my code, I want to change the Strings to Float type > because the code will not work with Strings but I do not want > to change the numbers in any other way. That may be impossible. Float type is not exact and the conversion will be the closest binary representation of your decimal number. It will be very close but it may be slightly different when you print it, for example. (You can usually deal with that by using string formatting features.) Another option is to use the decimal numeric type. That has other compromises associated with it but, if retaining absolute decimal accuracy is your primary goal, it might suit you better. -- 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 hjp-python at hjp.at Sat Dec 17 07:39:56 2022 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 17 Dec 2022 13:39:56 +0100 Subject: String to Float, without introducing errors In-Reply-To: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> Message-ID: <20221217123956.epbpwrhrywl2u3ko@hjp.at> On 2022-12-17 12:51:17 +0100, Paul St George wrote: > I have a large/long array of numbers in an external file. The numbers > look like this: > > -64550.727 > -64511.489 > -64393.637 [...] > > When I bring the numbers into my code, they are Strings. To use the > numbers in my code, I want to change the Strings to Float type because > the code will not work with Strings but I do not want to change the > numbers in any other way. >>> s = "-64550.727" >>> f = float(s) >>> f -64550.727 >>> type(f) (Contrary to the other people posting in this thread I don't think float is the wrong type for the job. It might be, but you haven't given enough details to tell whether the inevitable rounding error matters or not. In my experience in almost all cases where people think it matters it really doesn't.) 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 Sat Dec 17 09:15:58 2022 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 17 Dec 2022 09:15:58 -0500 Subject: String to Float, without introducing errors In-Reply-To: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> Message-ID: You have strings, and you want to end up with numbers. The numbers are not integers. Other responders have gone directly to whether you should use float or decimal as the conversion, but that is a secondary matter. If you have integers, convert with integer = int(number_string) If you don't have integers, convert with number = float(number_string) If the number is not an integer and you need to be extremely precise with the fractional part - for example, if you need to keep exact track of exact amounts of money - you can use decimal instead of float. But in this example it seems unlikely that you need that. The thing to be aware of that hasn't been mentioned so far is that the conversion might cause an exception if there is something wrong with one of the number strings. If you don't handle it, your program will quit running when it hits the error. That might not matter to you. If it matters, you can handle the exception in the program, but first you will need to decide what to do about such an error: should that number be omitted, should it be replaced with a placeholder, should it be replaced with float("NaN"), or what else? In your case here, I'd suggest not handling the error until you get the basics of your program working. Then if you need to, figure out how you want to handle exceptions. On 12/17/2022 6:51 AM, Paul St George wrote: > I have a large/long array of numbers in an external file. The numbers look like this: > > -64550.727 > -64511.489 > -64393.637 > -64196.763 > -63920.2 > -63563.037 > -63124.156 > -62602.254 > -61995.895 > -61303.548 > -60523.651 > -59654.66 > ... > > When I bring the numbers into my code, they are Strings. To use the numbers in my code, I want to change the Strings to Float type because the code will not work with Strings but I do not want to change the numbers in any other way. > > So, I want my Strings (above) to be these numbers. > > -64550.727 > -64511.489 > -64393.637 > -64196.763 > -63920.2 > -63563.037 > -63124.156 > -62602.254 > -61995.895 > -61303.548 > -60523.651 > -59654.66 > ... > > Please help! > > > > > > > > > > From mats at wichmann.us Sat Dec 17 13:41:32 2022 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 17 Dec 2022 11:41:32 -0700 Subject: String to Float, without introducing errors In-Reply-To: References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> Message-ID: <13bbe0c7-3fb1-6474-51fd-99cfb9fd0e88@wichmann.us> On 12/17/22 07:15, Thomas Passin wrote: > You have strings, and you want to end up with numbers.? The numbers are > not integers.? Other responders have gone directly to whether you should > use float or decimal as the conversion, but that is a secondary matter. > > If you have integers, convert with > > integer = int(number_string) >> -64550.727 they pretty clearly aren't integers: >> -64511.489 >> -64393.637 >> -64196.763 >> -63920.2 >> -63563.037 >> -63124.156 >> -62602.254 >> -61995.895 >> -61303.548 >> -60523.651 >> -59654.66 From list1 at tompassin.net Sat Dec 17 14:09:45 2022 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 17 Dec 2022 14:09:45 -0500 Subject: String to Float, without introducing errors In-Reply-To: <13bbe0c7-3fb1-6474-51fd-99cfb9fd0e88@wichmann.us> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <13bbe0c7-3fb1-6474-51fd-99cfb9fd0e88@wichmann.us> Message-ID: <9ca24bea-e012-e772-c70e-5eddc9180606@tompassin.net> On 12/17/2022 1:41 PM, Mats Wichmann wrote: > On 12/17/22 07:15, Thomas Passin wrote: >> You have strings, and you want to end up with numbers.? The numbers >> are not integers.? Other responders have gone directly to whether you >> should use float or decimal as the conversion, but that is a secondary >> matter. >> >> If you have integers, convert with >> >> integer = int(number_string) >>> -64550.727 > > they pretty clearly aren't integers: Of course they aren't. That's why I gave the line with float() too. It's useful to see that there is a basic pattern here: Given a string, expect to need to convert it to what you actually want, int, float, decimal, whatever. >>> -64511.489 >>> -64393.637 >>> -64196.763 >>> -63920.2 >>> -63563.037 >>> -63124.156 >>> -62602.254 >>> -61995.895 >>> -61303.548 >>> -60523.651 >>> -59654.66 From rob.cliffe at btinternet.com Thu Dec 15 08:30:39 2022 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Thu, 15 Dec 2022 13:30:39 +0000 Subject: Single line if statement with a continue In-Reply-To: References: Message-ID: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com> On 15/12/2022 04:35, Chris Angelico wrote: > On Thu, 15 Dec 2022 at 14:41, Aaron P wrote: >> I occasionally run across something like: >> >> for idx, thing in enumerate(things): >> if idx == 103: >> continue >> do_something_with(thing) >> >> It seems more succinct and cleaner to use: >> >> if idx == 103: continue. >> >> >> Nothing at all wrong with writing that on a single line. If you have >> issues with Flake8 not accepting your choices, reconfigure Flake8 :) >> >> ChrisA I'm so glad that Chris and others say this.? It (i.e. if plus break/continue/return on a single line) is something I have quite often done in my own code, albeit with a feeling of guilt that I was breaking a Python taboo.? Now I will do it with a clear conscience. ? Best wishes Rob Cliffe From rob.cliffe at btinternet.com Wed Dec 14 14:17:50 2022 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Wed, 14 Dec 2022 19:17:50 +0000 Subject: Top level of a recursive function In-Reply-To: References: Message-ID: On 14/12/2022 13:49, Stefan Ram wrote: > I also found an example similar to what was discussed here > in pypy's library file "...\Lib\_tkinter\__init__.py": > > |def _flatten(item): > | def _flatten1(output, item, depth): > | if depth > 1000: > | raise ValueError("nesting too deep in _flatten") > | if not isinstance(item, (list, tuple)): > | raise TypeError("argument must be sequence") > | # copy items to output tuple > | for o in item: > | if isinstance(o, (list, tuple)): > | _flatten1(output, o, depth + 1) > | elif o is not None: > | output.append(o) > | > | result = [] > | _flatten1(result, item, 0) > | return tuple(result) > > . > > This presumably results in an (avoidable) run-time overhead from constructing _flatten1 every time _flatten is called (and having it garbage-collected later). Best wishes Rob Cliffe From sjeik_appie at hotmail.com Sat Dec 17 14:45:18 2022 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Sat, 17 Dec 2022 20:45:18 +0100 Subject: Keeping a list of records with named fields that can be updated In-Reply-To: <9158537c-f561-e666-f60c-34d50f61d7b7@web.de> Message-ID: On Dec 15, 2022 10:21, Peter Otten <__peter__ at web.de> wrote: >>> from collections import namedtuple >>> Row = namedtuple("Row", "foo bar baz") >>> row = Row(1, 2, 3) >>> row._replace(bar=42) Row(foo=1, bar=42, baz=3) ==== Ahh, I always thought these are undocumented methods, but: "In addition to the methods inherited from tuples, named tuples support three additional methods and two attributes. To prevent conflicts with field names, the method and attribute names start with an underscore." https://docs.python.org/3/library/collections.html#collections.somenamedtuple._make From abdullahnafees23 at gmail.com Sat Dec 17 14:22:42 2022 From: abdullahnafees23 at gmail.com (Abdullah Nafees) Date: Sun, 18 Dec 2022 00:22:42 +0500 Subject: Single line if statement with a continue In-Reply-To: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com> References: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com> Message-ID: Just wanted to say that a silent reader like me learnt more about PEP-8 solely from this thread than my mentor at work or any other course I have taken earlier this year. Thank you so much. On Sun, 18 Dec 2022, 00:16 Rob Cliffe via Python-list, < python-list at python.org> wrote: > > > On 15/12/2022 04:35, Chris Angelico wrote: > > On Thu, 15 Dec 2022 at 14:41, Aaron P > wrote: > >> I occasionally run across something like: > >> > >> for idx, thing in enumerate(things): > >> if idx == 103: > >> continue > >> do_something_with(thing) > >> > >> It seems more succinct and cleaner to use: > >> > >> if idx == 103: continue. > >> > >> > >> Nothing at all wrong with writing that on a single line. If you have > >> issues with Flake8 not accepting your choices, reconfigure Flake8 :) > >> > >> ChrisA > I'm so glad that Chris and others say this. It (i.e. if plus > break/continue/return on a single line) is something I have quite often > done in my own code, albeit with a feeling of guilt that I was breaking > a Python taboo. Now I will do it with a clear conscience. ? > Best wishes > Rob Cliffe > -- > https://mail.python.org/mailman/listinfo/python-list > From email at paulstgeorge.com Sat Dec 17 15:45:06 2022 From: email at paulstgeorge.com (Paul St George) Date: Sat, 17 Dec 2022 21:45:06 +0100 Subject: String to Float, without introducing errors In-Reply-To: <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> Message-ID: <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> Thanks to all! It was the rounding rounding error that I needed to avoid (as Peter J. Holzer suggested). The use of decimal solved it and just in time. I was about to truncate the number, get each of the characters from the string mantissa, and then do something like this: 64550.727 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001) Now I do not need to! > On 17 Dec 2022, at 13:11, Alan Gauld wrote: > > On 17/12/2022 11:51, Paul St George wrote: >> I have a large/long array of numbers in an external file. The numbers look like this: >> >> -64550.727 >> -64511.489 >> -64393.637 >> -64196.763 >> -63920.2 > >> When I bring the numbers into my code, they are Strings. To use the >> numbers in my code, I want to change the Strings to Float type >> because the code will not work with Strings but I do not want >> to change the numbers in any other way. > > That may be impossible. Float type is not exact and the conversion > will be the closest binary representation of your decimal number. > It will be very close but it may be slightly different when you > print it, for example. (You can usually deal with that by using > string formatting features.) > > Another option is to use the decimal numeric type. That has other > compromises associated with it but, if retaining absolute decimal > accuracy is your primary goal, it might suit you better. > > > -- > 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 Sat Dec 17 15:49:05 2022 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Dec 2022 07:49:05 +1100 Subject: String to Float, without introducing errors In-Reply-To: <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> Message-ID: On Sun, 18 Dec 2022 at 07:46, Paul St George wrote: > > Thanks to all! > It was the rounding rounding error that I needed to avoid (as Peter J. Holzer suggested). The use of decimal solved it and just in time. I was about to truncate the number, get each of the characters from the string mantissa, and then do something like this: > > 64550.727 > > 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001) > > Now I do not need to! It sounds like fixed-point arithmetic might be a better fit for what you're doing. ChrisA From grant.b.edwards at gmail.com Sat Dec 17 16:21:34 2022 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 17 Dec 2022 13:21:34 -0800 (PST) Subject: String to Float, without introducing errors References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> Message-ID: <639e32de.020a0220.7add7.2f5b@mx.google.com> On 2022-12-17, Chris Angelico wrote: >> It was the rounding rounding error that I needed to avoid (as Peter >> J. Holzer suggested). The use of decimal solved it and just in >> time. I was about to truncate the number, get each of the >> characters from the string mantissa, and then do something like >> this: >> >> 64550.727 >> >> 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001) >> >> Now I do not need to! > > It sounds like fixed-point arithmetic might be a better fit for what > you're doing. Yes, fixed point (or decimal) is a better fit for what he's doing. but I suspect that floating point would be a better fit for the problem he's trying to solve. -- Grant From rosuav at gmail.com Sat Dec 17 16:27:21 2022 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Dec 2022 08:27:21 +1100 Subject: String to Float, without introducing errors In-Reply-To: <639e32de.020a0220.7add7.2f5b@mx.google.com> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> <639e32de.020a0220.7add7.2f5b@mx.google.com> Message-ID: On Sun, 18 Dec 2022 at 08:22, Grant Edwards wrote: > > On 2022-12-17, Chris Angelico wrote: > > >> It was the rounding rounding error that I needed to avoid (as Peter > >> J. Holzer suggested). The use of decimal solved it and just in > >> time. I was about to truncate the number, get each of the > >> characters from the string mantissa, and then do something like > >> this: > >> > >> 64550.727 > >> > >> 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001) > >> > >> Now I do not need to! > > > > It sounds like fixed-point arithmetic might be a better fit for what > > you're doing. > > Yes, fixed point (or decimal) is a better fit for what he's doing. but > I suspect that floating point would be a better fit for the problem > he's trying to solve. > Hard to judge, given how little info we have on the actual problem. Could go either way. ChrisA From hjp-python at hjp.at Sat Dec 17 16:45:12 2022 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 17 Dec 2022 22:45:12 +0100 Subject: String to Float, without introducing errors In-Reply-To: <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> Message-ID: <20221217214512.wlm2htukxisij6v5@hjp.at> On 2022-12-17 21:45:06 +0100, Paul St George wrote: > It was the rounding rounding error that I needed to avoid (as Peter J. > Holzer suggested). The use of decimal solved it and just in time. I > was about to truncate the number, get each of the characters from the > string mantissa, and then do something like this: > > 64550.727 > > 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001) That wouldn't have helped. In fact it would have made matters worse because instead of a single rounding operation you now have nine! 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 Sat Dec 17 16:54:05 2022 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 17 Dec 2022 16:54:05 -0500 Subject: String to Float, without introducing errors In-Reply-To: <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> Message-ID: <71d697b7-9f95-6136-a1ad-308093e5ef23@tompassin.net> On 12/17/2022 3:45 PM, Paul St George wrote: > Thanks to all! > It was the rounding rounding error that I needed to avoid (as Peter J. Holzer suggested). The use of decimal solved it and just in time. I was about to truncate the number, get each of the characters from the string mantissa, and then do something like this: > > 64550.727 > > 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001) > > Now I do not need to! And that approach would not have helped you, because each of those calculations would be done as floating point, and you wouldn't have gotten any more precision (and maybe less) than simply doing float('64550.727'). Here is a small but interesting discussion thread about float vs Decimal: https://stackoverflow.com/questions/32053647/comparing-python-decimals-created-from-float-and-string Would you mind telling us why that degree of precision (that is, decimal vs float) matters for your problem? >> On 17 Dec 2022, at 13:11, Alan Gauld wrote: >> >> On 17/12/2022 11:51, Paul St George wrote: >>> I have a large/long array of numbers in an external file. The numbers look like this: >>> >>> -64550.727 >>> -64511.489 >>> -64393.637 >>> -64196.763 >>> -63920.2 >> >>> When I bring the numbers into my code, they are Strings. To use the >>> numbers in my code, I want to change the Strings to Float type >>> because the code will not work with Strings but I do not want >>> to change the numbers in any other way. >> >> That may be impossible. Float type is not exact and the conversion >> will be the closest binary representation of your decimal number. >> It will be very close but it may be slightly different when you >> print it, for example. (You can usually deal with that by using >> string formatting features.) >> >> Another option is to use the decimal numeric type. That has other >> compromises associated with it but, if retaining absolute decimal >> accuracy is your primary goal, it might suit you better. >> >> >> -- >> 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 Sat Dec 17 16:54:55 2022 From: PythonList at DancesWithMice.info (dn) Date: Sun, 18 Dec 2022 10:54:55 +1300 Subject: String to Float, without introducing errors In-Reply-To: <20221217123956.epbpwrhrywl2u3ko@hjp.at> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <20221217123956.epbpwrhrywl2u3ko@hjp.at> Message-ID: On 18/12/2022 01.39, Peter J. Holzer wrote: > On 2022-12-17 12:51:17 +0100, Paul St George wrote: >> I have a large/long array of numbers in an external file. The numbers >> look like this: >> >> -64550.727 >> -64511.489 >> -64393.637 > [...] >> >> When I bring the numbers into my code, they are Strings. To use the >> numbers in my code, I want to change the Strings to Float type because >> the code will not work with Strings but I do not want to change the >> numbers in any other way. > >>>> s = "-64550.727" >>>> f = float(s) >>>> f > -64550.727 >>>> type(f) > > > (Contrary to the other people posting in this thread I don't think float > is the wrong type for the job. It might be, but you haven't given enough > details to tell whether the inevitable rounding error matters or not. In > my experience in almost all cases where people think it matters it > really doesn't.) Agreed: (ultimately) insufficient information-provided. (but that probably doesn't matter either - as the OP seems to have come to a decision) Agreed: probably doesn't matter. 'The world' agrees with both, having decided that Numerical Analysis is no-longer a necessary ComSc study. In the ?good, old, days Numerical Analysis included contemplation of the difficulties and differences between "precision" and "accuracy". Thus, the highly accurate calculation of less-than precise numbers - or was it precise values subject to less than accurate computation? (rhetorical!) Sort of like giving highly-accurate answers to a less-than precise (complete) question, by presuming can ignore the latter. -- Regards, =dn From PythonList at DancesWithMice.info Sat Dec 17 16:59:14 2022 From: PythonList at DancesWithMice.info (dn) Date: Sun, 18 Dec 2022 10:59:14 +1300 Subject: Single line if statement with a continue In-Reply-To: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com> References: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com> Message-ID: <9db24918-e924-3c0a-9a84-d513c6efd51d@DancesWithMice.info> On 16/12/2022 02.30, Rob Cliffe via Python-list wrote: > On 15/12/2022 04:35, Chris Angelico wrote: >> On Thu, 15 Dec 2022 at 14:41, Aaron P >> wrote: >>> I occasionally run across something like: >>> >>> for idx, thing in enumerate(things): >>> ???? if idx == 103: >>> ???????? continue >>> ???? do_something_with(thing) >>> >>> It seems more succinct and cleaner to use: >>> >>> if idx == 103: continue. >>> >>> >>> Nothing at all wrong with writing that on a single line. If you have >>> issues with Flake8 not accepting your choices, reconfigure Flake8 :) >>> >>> ChrisA > I'm so glad that Chris and others say this.? It (i.e. if plus > break/continue/return on a single line) is something I have quite often > done in my own code, albeit with a feeling of guilt that I was breaking > a Python taboo.? Now I will do it with a clear conscience. ? Anxiety doesn't help anyone - least of all you. Remember another Python mantra: "we're all adults here"! (also (compulsory interjection) PEP-008 is not a set of rules for all Python code - see PEP-008) -- Regards, =dn From annelmoeti at gmail.com Sat Dec 17 17:45:21 2022 From: annelmoeti at gmail.com (Anne) Date: Sun, 18 Dec 2022 00:45:21 +0200 Subject: Subject: problem activating python In-Reply-To: <818D04E1-24EB-4C55-A5E6-AB2C7C46B8CB@hxcore.ol> References: <818D04E1-24EB-4C55-A5E6-AB2C7C46B8CB@hxcore.ol> Message-ID: I tried several times to install and use python for youtube views with Tor using Youtube tutorials but I keep getting error after error. Please help me. regards Dimpho ? ? ? ? From rosuav at gmail.com Sat Dec 17 17:58:05 2022 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Dec 2022 09:58:05 +1100 Subject: String to Float, without introducing errors In-Reply-To: References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> <639e32de.020a0220.7add7.2f5b@mx.google.com> Message-ID: On Sun, 18 Dec 2022 at 09:46, Stefan Ram wrote: > > Grant Edwards writes: > >Yes, fixed point (or decimal) is a better fit for what he's doing. but > >I suspect that floating point would be a better fit for the problem > >he's trying to solve. > > I'd like to predict that within the next ten posts in this > thread someone will mention "What Every Computer Scientist > Should Know About Floating-Point Arithmetic". > > |>>> 0.1 + 0.2 - 0.3 > |5.551115123125783e-17 > Looks like someone just did. ChrisA From avi.e.gross at gmail.com Sat Dec 17 18:05:46 2022 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 17 Dec 2022 18:05:46 -0500 Subject: String to Float, without introducing errors In-Reply-To: <13bbe0c7-3fb1-6474-51fd-99cfb9fd0e88@wichmann.us> References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <13bbe0c7-3fb1-6474-51fd-99cfb9fd0e88@wichmann.us> Message-ID: <005c01d9126c$191b2e80$4b518b80$@gmail.com> As often seems to happen, someone asks something that may not be fully clear and others chime in and extend the question. Was the original question how to read in a ingle column of numbers from a file that are all numeric and NOT integers and be able to use them? If so, the answer was quite trivial using the conversion function of your choice. Handling errors or what to do with something like a blank or NA are nice ideas if asked about. My answer would be to ask if this was an assignment where they are EXPECTED to do things a certain way to master a concept, or part of a serious attempt to get things done. For the latter case, it may make plenty of sense considering a single column of text as just a special case for the kind of multi-column files often read in from formatted data files and use some functionality from add-on modules like numpy or pandas that also allow you to deal with many other concerns. Note such utilities also often make a decent guess on what data type a column should be turned into and it is possible they may occasionally decide based on the data that the contents all HAPPEN to be integer or there is at least one that makes it choose character. So any such use may well require the subsequent use of functions that check the dtype and, if needed, do an explicit conversion to what you really really really want. -----Original Message----- From: Python-list On Behalf Of Mats Wichmann Sent: Saturday, December 17, 2022 1:42 PM To: python-list at python.org Subject: Re: String to Float, without introducing errors On 12/17/22 07:15, Thomas Passin wrote: > You have strings, and you want to end up with numbers. The numbers > are not integers. Other responders have gone directly to whether you > should use float or decimal as the conversion, but that is a secondary matter. > > If you have integers, convert with > > integer = int(number_string) >> -64550.727 they pretty clearly aren't integers: >> -64511.489 >> -64393.637 >> -64196.763 >> -63920.2 >> -63563.037 >> -63124.156 >> -62602.254 >> -61995.895 >> -61303.548 >> -60523.651 >> -59654.66 -- https://mail.python.org/mailman/listinfo/python-list From mats at wichmann.us Sat Dec 17 18:38:35 2022 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 17 Dec 2022 16:38:35 -0700 Subject: Subject: problem activating python In-Reply-To: References: <818D04E1-24EB-4C55-A5E6-AB2C7C46B8CB@hxcore.ol> Message-ID: <91cc6767-e54c-51e9-7208-c560cebdddae@wichmann.us> On 12/17/22 15:45, Anne wrote: > I tried several times to install and use python for youtube views with Tor > using Youtube tutorials but I keep getting error after error. Please help > me. > regards Dimpho Folks around here tend to be pretty helpful. But only if you describe the problem in a way they can help with. It's not clear what you're trying to do, and "I keep getting error after error" doesn't give anyone any information to work with. From avi.e.gross at gmail.com Sat Dec 17 18:57:47 2022 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 17 Dec 2022 18:57:47 -0500 Subject: Single line if statement with a continue In-Reply-To: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com> References: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com> Message-ID: <006801d91273$5cfffe80$16fffb80$@gmail.com> I happen to be of two schools here. Is something sort of taboo when using something like a computer language to write a program? What if another language tells you to do it a different way or sort of the opposite? Is it based on the details of the language and implementation or the prejudices of the one trying to make rules? If a compiler or interpreter HAPPILY (as happy as machines/code get) compiles or interprets your code without errors every time you use it a certain way, then it is not wrong to use it. Of course if it subject to change or already deprecated, ... If people around you complain they do not like it, then the word "taboo" does apply but you can feel free to re-educate them or move on. This reminds me too much of people who are taught some grammar such as some part of a sentence requiring a "noun-phrase" and later it explains that a non-phrase can be EITHER a noun accompanied by an assortment of other words that together form a phrase, or just a "noun" or just a "pronoun" or just a "nothing but an implied pronoun". So which is it? The answer is all of them are legal, at least within bounds. A sentence like "Come over here" is an implied "You come over here" and works best if earlier sentences have laid some context on what is being talked about so the "you" is obvious or will be explained later but perhaps should be discouraged in other circumstances. So back to computer languages. Many languages using grouping with something like "{...}" often do not care where you break your lines albeit some get touchy about an else statement placed improperly. It is perfectly legal to write: If (condition) { first; second; third } The grammar basically states that a "statement" or similar name can be a simple statement or a compound statement and anywhere one can go, within reason, so can the other. Python has a twist here in that they discourage or outlaw some such things as they use mainly indentation rather than braces. This makes it hard to use multiple lines when the first line is way at the end as the others do not line up. It becomes all or ONE. I mean it allows a simple expression on the same line after the colon and then terminates the construct so a future indented line is seen as an indentation error. An experiment shows the following attempt to line up a second line way over below the first also fails: if 5 > 3: a = a * 3 b = b * 3 In a constant width font my second line is indented so "b is just below "a" and it fails because the interpreter does not measure the beginning column of the first line as being where the " a = a * 3" starts but at the "if" and that makes reasonable sense. I could imagine another design but since it is not what is done, the multi-line version MUST be done only on subsequent lines indented properly and identically. So it is not really right or wrong to do one-liners. It is legal and often more readable. But if you ever want to extend your lines to be multi-line, it probably is best to use the multi-line approach regularly. Still, using many editors, you will rapidly notice something is wrong when adding a line of code and seeing it is indented under the "if". Is anyone really thrilled to read code in other languages that span so many lines: If (condition) { var1 = 0 } else { var1 = 1 } It is a great way to get your line-of-code count up but the many briefer versions can be easier to read in one glance up to and including a bit murkier ones like var1 = (condition) ? 0 : 1 My view is that simple things that fit easily on a screen, and also held all at once in my mind, should be written fairly concisely. I do admit how much I can hold at once varies based on how well I can concentrate at that moment and have met people whose short-term memory for many things is larger or smaller than mine. But generally people can handle simple constructs like we are discussing. Complicated things and ones that might need changes later should be written very cautiously and in detail including judicious use of comments around and within the code OR consider re-planning it into a less complicated form that calls on other fairly simple functions that can each be decently understood based on naming and usage. If you have a complicated calculation that eventually assigns values to a1, a2, a3, a4 then a language like Python makes a One liner easy as in: If (condition): a1, a2, a3, a4 = func(args) But now that four or more lines have been collapsed into one, maybe something like this works too and maybe is a tad more readable with parentheses: If (condition): (a1, a2, a3, a4) = func(args) I am not suggesting using something silly like this though: if(1): (a, b, c, d) = (min(1,2), (1+2)/2, (1*2*2*3)/4, max(1,2)) That is so way beyond a one liner that it is best seen as multiple lines. It may be legal but is best used to obfuscate! The problem with some RULES is that not only are they not real rules but sometimes have exceptions where they get in the way of getting things done. - Avi -----Original Message----- From: Python-list On Behalf Of Rob Cliffe via Python-list Sent: Thursday, December 15, 2022 8:31 AM To: python-list at python.org Subject: Re: Single line if statement with a continue On 15/12/2022 04:35, Chris Angelico wrote: > On Thu, 15 Dec 2022 at 14:41, Aaron P wrote: >> I occasionally run across something like: >> >> for idx, thing in enumerate(things): >> if idx == 103: >> continue >> do_something_with(thing) >> >> It seems more succinct and cleaner to use: >> >> if idx == 103: continue. >> >> >> Nothing at all wrong with writing that on a single line. If you have >> issues with Flake8 not accepting your choices, reconfigure Flake8 :) >> >> ChrisA I'm so glad that Chris and others say this. It (i.e. if plus break/continue/return on a single line) is something I have quite often done in my own code, albeit with a feeling of guilt that I was breaking a Python taboo. Now I will do it with a clear conscience. ? Best wishes Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Sat Dec 17 19:50:42 2022 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 17 Dec 2022 19:50:42 -0500 Subject: Single line if statement with a continue In-Reply-To: <006801d91273$5cfffe80$16fffb80$@gmail.com> References: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com> <006801d91273$5cfffe80$16fffb80$@gmail.com> Message-ID: <1bd05dac-6689-98a8-6d47-4df6925eba55@tompassin.net> >if 5 > 3: a = a * 3 > b = b * 3 That would be a fairly weird construction, neither one thing nor another. But still, if you really want it that way, this is legal Python: a = 2; b = 10 if 5 > 3: a = a * 3;\ b = b * 3 print(a, b) # 6 30 On 12/17/2022 6:57 PM, avi.e.gross at gmail.com wrote: > I happen to be of two schools here. > > Is something sort of taboo when using something like a computer language to write a program? What if another language tells you to do it a different way or sort of the opposite? Is it based on the details of the language and implementation or the prejudices of the one trying to make rules? > > If a compiler or interpreter HAPPILY (as happy as machines/code get) compiles or interprets your code without errors every time you use it a certain way, then it is not wrong to use it. Of course if it subject to change or already deprecated, ... That's not the point of using some consistent style. IMO, source code should be clear, compact, and easy for someone else to understand. That someone might be you six months from now. These objectives do not always align. Consistency helps reduce mental effort by using constructions and formatting in a familiar way - basically, using a familiar programming idiom. Compactness can help clarity, unless the code is too terse which can become a hindrance. But too much verbosity can get in the way of grasping the essential processing. Personal taste and familiarity also factor into assessing clarity and compactness. It's always a balancing act. Style guides can help by providing good basic idioms. There's no law** that says you *have* to follow them exactly all the time. But it's helpful when you can. If your own style guide i is similar to one used widely, so much the better. **Except at some organizations > If people around you complain they do not like it, then the word "taboo" does apply but you can feel free to re-educate them or move on. > > This reminds me too much of people who are taught some grammar such as some part of a sentence requiring a "noun-phrase" and later it explains that a non-phrase can be EITHER a noun accompanied by an assortment of other words that together form a phrase, or just a "noun" or just a "pronoun" or just a "nothing but an implied pronoun". > > So which is it? The answer is all of them are legal, at least within bounds. A sentence like "Come over here" is an implied "You come over here" and works best if earlier sentences have laid some context on what is being talked about so the "you" is obvious or will be explained later but perhaps should be discouraged in other circumstances. > > So back to computer languages. Many languages using grouping with something like "{...}" often do not care where you break your lines albeit some get touchy about an else statement placed improperly. It is perfectly legal to write: > > If (condition) { first; second; third } > > The grammar basically states that a "statement" or similar name can be a simple statement or a compound statement and anywhere one can go, within reason, so can the other. > > Python has a twist here in that they discourage or outlaw some such things as they use mainly indentation rather than braces. This makes it hard to use multiple lines when the first line is way at the end as the others do not line up. It becomes all or ONE. I mean it allows a simple expression on the same line after the colon and then terminates the construct so a future indented line is seen as an indentation error. An experiment shows the following attempt to line up a second line way over below the first also fails: > > if 5 > 3: a = a * 3 > b = b * 3 > > In a constant width font my second line is indented so "b is just below "a" and it fails because the interpreter does not measure the beginning column of the first line as being where the " a = a * 3" starts but at the "if" and that makes reasonable sense. I could imagine another design but since it is not what is done, the multi-line version MUST be done only on subsequent lines indented properly and identically. > > So it is not really right or wrong to do one-liners. It is legal and often more readable. But if you ever want to extend your lines to be multi-line, it probably is best to use the multi-line approach regularly. > > Still, using many editors, you will rapidly notice something is wrong when adding a line of code and seeing it is indented under the "if". > > Is anyone really thrilled to read code in other languages that span so many lines: > > If (condition) > { > var1 = 0 > } > else > { > var1 = 1 > } > > It is a great way to get your line-of-code count up but the many briefer versions can be easier to read in one glance up to and including a bit murkier ones like > > var1 = (condition) ? 0 : 1 > > My view is that simple things that fit easily on a screen, and also held all at once in my mind, should be written fairly concisely. I do admit how much I can hold at once varies based on how well I can concentrate at that moment and have met people whose short-term memory for many things is larger or smaller than mine. But generally people can handle simple constructs like we are discussing. > > Complicated things and ones that might need changes later should be written very cautiously and in detail including judicious use of comments around and within the code OR consider re-planning it into a less complicated form that calls on other fairly simple functions that can each be decently understood based on naming and usage. > > If you have a complicated calculation that eventually assigns values to a1, a2, a3, a4 then a language like Python makes a > One liner easy as in: > > If (condition): > a1, a2, a3, a4 = func(args) > > But now that four or more lines have been collapsed into one, maybe something like this works too and maybe is a tad more readable with parentheses: > > If (condition): (a1, a2, a3, a4) = func(args) > > > I am not suggesting using something silly like this though: > > if(1): (a, b, c, d) = (min(1,2), (1+2)/2, (1*2*2*3)/4, max(1,2)) > > That is so way beyond a one liner that it is best seen as multiple lines. It may be legal but is best used to obfuscate! > > The problem with some RULES is that not only are they not real rules but sometimes have exceptions where they get in the way of getting things done. > > - Avi > > -----Original Message----- > From: Python-list On Behalf Of Rob Cliffe via Python-list > Sent: Thursday, December 15, 2022 8:31 AM > To: python-list at python.org > Subject: Re: Single line if statement with a continue > > > > On 15/12/2022 04:35, Chris Angelico wrote: >> On Thu, 15 Dec 2022 at 14:41, Aaron P wrote: >>> I occasionally run across something like: >>> >>> for idx, thing in enumerate(things): >>> if idx == 103: >>> continue >>> do_something_with(thing) >>> >>> It seems more succinct and cleaner to use: >>> >>> if idx == 103: continue. >>> >>> >>> Nothing at all wrong with writing that on a single line. If you have >>> issues with Flake8 not accepting your choices, reconfigure Flake8 :) >>> >>> ChrisA > I'm so glad that Chris and others say this. It (i.e. if plus break/continue/return on a single line) is something I have quite often done in my own code, albeit with a feeling of guilt that I was breaking a Python taboo. Now I will do it with a clear conscience. ? > Best wishes > Rob Cliffe > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sat Dec 17 19:59:44 2022 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Dec 2022 11:59:44 +1100 Subject: Single line if statement with a continue In-Reply-To: <006801d91273$5cfffe80$16fffb80$@gmail.com> References: <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com> <006801d91273$5cfffe80$16fffb80$@gmail.com> Message-ID: On Sun, 18 Dec 2022 at 10:59, wrote: > > If a compiler or interpreter HAPPILY (as happy as machines/code get) compiles or interprets your code without errors every time you use it a certain way, then it is not wrong to use it. Of course if it subject to change or already deprecated, ... > Source code is, first and foremost, for programmers to read. You're confusing it with binary executables. ChrisA From torriem at gmail.com Sat Dec 17 20:41:46 2022 From: torriem at gmail.com (Michael Torrie) Date: Sat, 17 Dec 2022 18:41:46 -0700 Subject: Subject: problem activating python In-Reply-To: References: <818D04E1-24EB-4C55-A5E6-AB2C7C46B8CB@hxcore.ol> Message-ID: <27d418c6-49e9-4df8-8b9a-b54326f0c0bb@gmail.com> On 12/17/22 15:45, Anne wrote: > I tried several times to install and use python for youtube views with Tor > using Youtube tutorials but I keep getting error after error. Please help > me. > regards Dimpho Given the lack of any information in your post, I can only assume you're trying to get Python installed on Windows. Please read this page and post here if you have any questions: https://docs.python.org/3/using/windows.html From jimdaniellewis at gmail.com Sun Dec 18 06:50:10 2022 From: jimdaniellewis at gmail.com (Jim Lewis) Date: Sun, 18 Dec 2022 06:50:10 -0500 Subject: Fwd: Installation hell In-Reply-To: References: Message-ID: I'm an occasional user of Python and have a degree in computer science. Almost every freaking time I use Python, I go through PSH (Python Setup Hell). Sometimes a wrong version is installed. Sometimes it's a path issue. Or exe naming confusion: python, python3, phthon311, etc. Or library compatibility issues - took an hour to find out that pygame does not work with the current version of python. Then the kludgy PIP app and using a DOS box under Windows with command prompts which is ridiculous. God only knows how many novice users of the language (or even intermediate users) were lost in the setup process. Why not clean the infrastructure up and make a modern environment or IDE or something better than it is now. Or at least good error messages that explain exactly what to do. Even getting this email to the list took numerous steps. -- A frustrated user From c.buhtz at posteo.jp Sun Dec 18 10:38:57 2022 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Sun, 18 Dec 2022 15:38:57 +0000 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment Message-ID: <4NZn7V1JFkz6tpJ@submission01.posteo.de> Hello, when I install a package on a GNU/Linux system via "sudo python3 -m pip install -e ." that defines entry points in its pyproject.toml the entry point starter scripts are located in /usr/locale/bin. That folder is in PATH for "regular" root users and by "sudo su" roots users. But I need to start that entry points via "pkexec". But in the environment started by "pkexec" the PATH does not contain /usr/local/bin. So what can I do? I don't need a hack or workaround but an "elegant" solution. From email at paulstgeorge.com Sun Dec 18 14:00:37 2022 From: email at paulstgeorge.com (Paul St George) Date: Sun, 18 Dec 2022 20:00:37 +0100 Subject: String to Float, without introducing errors Message-ID: So I am working on a physics paper with a colleague. We have a theory about Newtons Cradle. We answer the question why when you lift and drop balls 1 and 2, balls 4 and 5 rise up. I could say more, but ... (if you are interested please write to me). We want to illustrate the paper with animations. The theory includes distortion of the balls and this distortion is very very small. So, I am sent data with locations and dimensions to 13 decimal places. Something strange is happening with the animations: the balls are not moving smoothly. I do not know (yet) where the problem lies so it is difficult to provide a clear narrative. Because there is a problem, I am investigating in all areas. This brings me to the question I asked here. I am not expecting six decimal places or three decimal places to be as accurate as thirteen decimal places, but I would like to be in control of or fully aware of what goes on under the bonnet. Here is a picture: https://paulstgeorge.com/newton/cyclography.html? Thanks, Paul >> On 17 Dec 2022, at 16:54:05 EST 2022, Thomas Passin wrote: On 12/17/2022 3:45 PM, Paul St George wrote: > Thanks to all! > It was the rounding rounding error that I needed to avoid (as Peter J. Holzer suggested). The use of decimal solved it and just in time. I was about to truncate the number, get each of the characters from the string mantissa, and then do something like this: > > 64550.727 > > 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001) > > Now I do not need to! And that approach would not have helped you, because each of those calculations would be done as floating point, and you wouldn't have gotten any more precision (and maybe less) than simply doing float('64550.727'). Here is a small but interesting discussion thread about float vs Decimal: https://stackoverflow.com/questions/32053647/comparing-python-decimals-created-from-float-and-string Would you mind telling us why that degree of precision (that is, decimal vs float) matters for your problem? >> On 17 Dec 2022, at 13:11, Alan Gauld > wrote: >> >> On 17/12/2022 11:51, Paul St George wrote: >>> I have a large/long array of numbers in an external file. The numbers look like this: >>> >>> -64550.727 >>> -64511.489 >>> -64393.637 >>> -64196.763 >>> -63920.2 >> >>> When I bring the numbers into my code, they are Strings. To use the >>> numbers in my code, I want to change the Strings to Float type >>> because the code will not work with Strings but I do not want >>> to change the numbers in any other way. >> >> That may be impossible. Float type is not exact and the conversion >> will be the closest binary representation of your decimal number. >> It will be very close but it may be slightly different when you >> print it, for example. (You can usually deal with that by using >> string formatting features.) >> >> Another option is to use the decimal numeric type. That has other >> compromises associated with it but, if retaining absolute decimal >> accuracy is your primary goal, it might suit you better. >> >> >> -- >> 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 gweatherby at uchc.edu Sun Dec 18 13:45:39 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Sun, 18 Dec 2022 18:45:39 +0000 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: <4NZn7V1JFkz6tpJ@submission01.posteo.de> References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> Message-ID: "sudo python3 -m pip install -e ." You?ve already started down a problematic road. I recommend installing root level Python packages through your system package manager. (apt for debian, or whatever RedHat is using now). If a package you need isn?t available from the system level virtual environments are your friend. I?ve never used pkexec. Generally, just use sudo. There?s an -E flag to preserve the environment. We generally write bash wrappers that set whatever environment we need. From: Python-list on behalf of c.buhtz at posteo.jp Date: Sunday, December 18, 2022 at 12:56 PM To: Python-list at python.org Subject: pip/setuptools: Entry points not visible from pkexec-root-environment *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Hello, when I install a package on a GNU/Linux system via "sudo python3 -m pip install -e ." From mats at wichmann.us Sun Dec 18 14:04:14 2022 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 18 Dec 2022 12:04:14 -0700 Subject: Fwd: Installation hell In-Reply-To: References: Message-ID: <3d790e8f-9ade-d000-c0e6-4a12c27f6eee@wichmann.us> On 12/18/22 04:50, Jim Lewis wrote: > I'm an occasional user of Python and have a degree in computer science. > Almost every freaking time I use Python, I go through PSH (Python Setup > Hell). Sometimes a wrong version is installed. Sometimes it's a path issue. > Or exe naming confusion: python, python3, phthon311, etc. Or library > compatibility issues - took an hour to find out that pygame does not work > with the current version of python. It's usually best to wait a bit after a new Python releases, until the myriad packages developed externally which depend on the binary ABI catch up. *Some* carefully follow the beta release cycle and are ready on or close to day 1, some feel like they have enough other work to do and are not. Can understand both viewpoints. You can check - search for something that's important to you on pypi.org and see if binary wheels are available. e.g. https://pypi.org/project/pygame/#files New Python releases are only once a year, so this shouldn't be too huge a burden, Python 3.10 works just fine in the meantime. > Then the kludgy PIP app and using a DOS > box under Windows with command prompts which is ridiculous. Why? Python is a command-line tool to process a language, Similar to many other languages - Go, for example. Or a C/C++ compiler. *Or* you can choose to use someone's wrapping of that process inside an Integrated Development Environment. There are tons that support Python and let you run your code from within the editor environment without having to go open a cmd.exe or powershell box. Most of those are external, but the comes-with-Python IDLE works well, too. > God only knows > how many novice users of the language (or even intermediate users) were > lost in the setup process. Why not clean the infrastructure up and make a > modern environment or IDE or something better than it is now. Or at least > good error messages that explain exactly what to do. Even getting this > email to the list took numerous steps. > > -- A frustrated user From axy at declassed.art Sun Dec 18 14:08:36 2022 From: axy at declassed.art (Axy) Date: Sun, 18 Dec 2022 19:08:36 +0000 Subject: Fun with python string formatting Message-ID: <7d8373d0-b0d0-da45-7316-537a99dc399f@declassed.art> Hi all, what do you see looking at format string syntax https://docs.python.org/3/library/string.html#formatstrings ? In particular, at something like this: {h[1].red.jumbo-header:Hello, World!} Yes, this is syntactically correct statement and if we tweak Formatter methods, we can generate such an output:

Hello, World!

Someone might need a booze to catch sight of arguments and css classes in the source statement, okay: let it be Aligote markup. Although I haven't implemented HTML rendering yet (my actual needs were reST and Markdown), this does generate plain text and Markdown now. However, I'm discouraged at the moment. Without nested markup the implementation is very small and nice. With more or less complex formatting, such as nested lists, there's a need to analyse upper level statements and to enforce some rules. Also, there's a pain with indentation, but that's mainly because I was too lazy and based my implementation on previous work instead of writing a better one from scratch. There are some undefined points such as how to render paragraphs. Use strict {p:text} directive or just split literal text by doubly newlines. Can't decide whether to cut down all the complexity and revert recursion level to 2 or proceed with rich markup. Anyway, below is the rendered specification in plain text. Here's the source code https://github.com/declassed-art/clabate/blob/main/clabate/extras/aligote.py and the specification https://github.com/declassed-art/clabate/blob/main/clabate/examples/aligote_spec.py If this looks funny and you have any crazy ideas what can be added to or changed in the specification, let me know. Axy. Aligote markup specification ============================ Headings -------- {h1:heading} ============ {h2:heading} ------------ {h3:heading} ------------ {h4:heading} ------------ {h5:heading} ------------ {h6:heading} ------------ Styles ------ {b:bold text} {i:italic text} {b:bold and {i:italic} text} {i:italic and {b:bold} text} {u:underline text} {s:strike-through text} {sub:subscript text} {sup:superscript text} Links ----- {link[optional text]:URL} Examples: {link:http://declassed.art} {link[Declassed Art]:http://declassed.art} Rendered as: http://declassed.art Declassed Art (http://declassed.art) Lists ----- Unordered lists --------------- {ul: ??? {li:item one, can be markup} ??? {li:item two ??????? can be multi-line} ??? {li:etc} } Rendered as: * item one, can be {b:markup} * item two ? can be multi-line * etc Ordered lists ------------- {ol: ??? {li:item one} ??? {li:item two} ??? {li:etc} } Rendered as: 1. item one 2. item two 3. etc Nested lists ------------ {ul: ??? {li:item one} ??? {li:item two} ??? {ol: ??????? {li:item one, ??????????? multi-line} ??????? {li:item two} ??? } ??? {li:etc} } Rendered as: * item one * item two ??? 1. item one, ?????? multi-line ??? 2. item two * etc Optional arguments ------------------ XXX Markdown does not support arbitrary numbering, does it? {ol: ??? {li[3]:item 3} ??? {li[5]:item 5 ??????? {ol: ??????????? {li:ordinal is rendered as 5.1} ??????????? {li[3]:ordinal is rendered as 5.3} ??????????? {li[5][5]:ordinal is rendered as 5.5} ??????????? {li: ordinal is rendered as 5.6} ??????? } ??? } } Rendered as: 3. item 3 5. item 5 ?? 5.1. ordinal is rendered as 5.1 ?? 5.3. ordinal is rendered as 5.3 ?? 5.5. ordinal is rendered as 5.5 ?? 5.6. ordinal is rendered as 5.6 Optional argument for unordered list is the bullet character. Default is `*`: {ul: ??? {li:item 1} ??? {li[+]:item 2} ??? {li[-]:item 3} } Rendered as: * item 1 + item 2 - item 3 Quirks ------ {ol: ??? {li:item one} ??? Basically, lists may contain any literal text. ??? In terms of python formatting this is not an error, ??? but that's not good for rendering. ??? {li:item two} } Rendered as: 1. item one Basically, lists may contain any literal text. In terms of python formatting this is not an error, but that's not good for rendering. 2. item two Syntax highlighting ------------------- {python: ??? print('Hello, world!') } Rendered as: ??? print('Hello, world!') From c.buhtz at posteo.jp Sun Dec 18 14:23:24 2022 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Sun, 18 Dec 2022 19:23:24 +0000 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> Message-ID: Dear Gerard, thank you for your reply. Am 18.12.2022 19:45 schrieb Weatherby,Gerard: > "sudo python3 -m pip > install -e ." > > You?ve already started down a problematic road. I recommend installing > root level Python packages through your system package manager. (apt > for debian, or whatever RedHat is using now). I'm totally with you at this point. It is clear for me that distro maintainers sometimes using different mechanics. But I'm the upstream maintainer and before handing offer a release to the distro that thing need to run without a distro. And that is pip. I also know a quit old project using "make" for that. This question is independent from distros. > I?ve never used pkexec. Generally, just use sudo. They are two very different things. There is a strict reason why I need to use pkexec here. From rosuav at gmail.com Sun Dec 18 14:25:31 2022 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Dec 2022 06:25:31 +1100 Subject: Fwd: Installation hell In-Reply-To: <3d790e8f-9ade-d000-c0e6-4a12c27f6eee@wichmann.us> References: <3d790e8f-9ade-d000-c0e6-4a12c27f6eee@wichmann.us> Message-ID: On Mon, 19 Dec 2022 at 06:10, Mats Wichmann wrote: > Why? Python is a command-line tool to process a language, Similar to > many other languages - Go, for example. Or a C/C++ compiler. *Or* you > can choose to use someone's wrapping of that process inside an > Integrated Development Environment. There are tons that support Python > and let you run your code from within the editor environment without > having to go open a cmd.exe or powershell box. Most of those are > external, but the comes-with-Python IDLE works well, too. I wouldn't bother responding to these sorts of people. They have already decided that it's impossible to find any sort of decent IDE for Python (despite pretty much every editor out there having Python support), are deathly afraid of command lines, and yet feel the need to join a mailing list to tell us all that. You won't convince them of anything. ChrisA From rosuav at gmail.com Sun Dec 18 14:27:26 2022 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Dec 2022 06:27:26 +1100 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: <4NZn7V1JFkz6tpJ@submission01.posteo.de> References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> Message-ID: On Mon, 19 Dec 2022 at 04:56, wrote: > > Hello, > > when I install a package on a GNU/Linux system via "sudo python3 -m pip > install -e ." that defines entry points in its pyproject.toml the entry > point starter scripts are located in /usr/locale/bin. > > That folder is in PATH for "regular" root users and by "sudo su" roots > users. > > But I need to start that entry points via "pkexec". > But in the environment started by "pkexec" the PATH does not contain > /usr/local/bin. > > So what can I do? > > I don't need a hack or workaround but an "elegant" solution. Does it have to be in path? Can't you say /usr/local/bin/entrypointname? Not sure what constitutes an elegant solution here. ChrisA From list1 at tompassin.net Sun Dec 18 14:55:50 2022 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 18 Dec 2022 14:55:50 -0500 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> Message-ID: Pip is fine for most packages, as it looks like you know. Some distros put some packages in unusual places, and those are the ones that either are not or should not be installed via pip. Which ones varies from distro to distro. (I just include this information here for others who haven't discovered it yet). You asked for something that's not a hack, but here's a hack anyway :). Worth reading for the caveats - https://stackoverflow.com/questions/50783033/execute-pkexec-command-on-a-different-path I think the most natural way is to launch it with a script that adds your desired path to the pkexec environment. What I don't know is if that script needs elevated permissions itself, but you probably already know about that. On 12/18/2022 2:23 PM, c.buhtz at posteo.jp wrote: > Dear Gerard, > thank you for your reply. > > Am 18.12.2022 19:45 schrieb Weatherby,Gerard: >> "sudo python3 -m pip >> install -e ." >> >> You?ve already started down a problematic road. I recommend installing >> root level Python packages through your system package manager. (apt >> for debian, or whatever RedHat is using now). > > I'm totally with you at this point. > > It is clear for me that distro maintainers sometimes using different > mechanics. > But I'm the upstream maintainer and before handing offer a release to > the distro that thing need to run without a distro. And that is pip. I > also know a quit old project using "make" for that. > > This question is independent from distros. > >> I?ve never used pkexec. Generally, just use sudo. > > They are two very different things. There is a strict reason why I need > to use pkexec here. > From list1 at tompassin.net Sun Dec 18 15:06:35 2022 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 18 Dec 2022 15:06:35 -0500 Subject: String to Float, without introducing errors In-Reply-To: References: Message-ID: <1de4633b-b6c4-14af-7463-8a57527cf0be@tompassin.net> Thanks for filling us in! I wouldn't think the animations themselves would need such precision, though perhaps the calculations of the forces and motions do. One way to check might be to perturb the initial conditions a bit and see if the changes in the motions seem to be correspondingly small. That might help you work out if the problem is with the physics solution or the animation. It would be easy to get some numerical instability in the calculations, for example if you are inverting matrices. On 12/18/2022 2:00 PM, Paul St George wrote: > So I am working on a physics paper with a colleague. We have a theory about Newtons Cradle. We answer the question why when you lift and drop balls 1 and 2, balls 4 and 5 rise up. I could say more, but ... (if you are interested please write to me). > > We want to illustrate the paper with animations. The theory includes distortion of the balls and this distortion is very very small. So, I am sent data with locations and dimensions to 13 decimal places. Something strange is happening with the animations: the balls are not moving smoothly. I do not know (yet) where the problem lies so it is difficult to provide a clear narrative. > > Because there is a problem, I am investigating in all areas. This brings me to the question I asked here. I am not expecting six decimal places or three decimal places to be as accurate as thirteen decimal places, but I would like to be in control of or fully aware of what goes on under the bonnet. > > Here is a picture: > https://paulstgeorge.com/newton/cyclography.html? > Thanks, > Paul > > > > >>> On 17 Dec 2022, at 16:54:05 EST 2022, Thomas Passin wrote: > On 12/17/2022 3:45 PM, Paul St George wrote: >> Thanks to all! >> It was the rounding rounding error that I needed to avoid (as Peter J. Holzer suggested). The use of decimal solved it and just in time. I was about to truncate the number, get each of the characters from the string mantissa, and then do something like this: >> >> 64550.727 >> >> 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001) >> >> Now I do not need to! > > And that approach would not have helped you, because each of those > calculations would be done as floating point, and you wouldn't have > gotten any more precision (and maybe less) than simply doing > float('64550.727'). > > Here is a small but interesting discussion thread about float vs Decimal: > > https://stackoverflow.com/questions/32053647/comparing-python-decimals-created-from-float-and-string > > Would you mind telling us why that degree of precision (that is, decimal > vs float) matters for your problem? > > >>> On 17 Dec 2022, at 13:11, Alan Gauld > wrote: >>> >>> On 17/12/2022 11:51, Paul St George wrote: >>>> I have a large/long array of numbers in an external file. The numbers look like this: >>>> >>>> -64550.727 >>>> -64511.489 >>>> -64393.637 >>>> -64196.763 >>>> -63920.2 >>> >>>> When I bring the numbers into my code, they are Strings. To use the >>>> numbers in my code, I want to change the Strings to Float type >>>> because the code will not work with Strings but I do not want >>>> to change the numbers in any other way. >>> >>> That may be impossible. Float type is not exact and the conversion >>> will be the closest binary representation of your decimal number. >>> It will be very close but it may be slightly different when you >>> print it, for example. (You can usually deal with that by using >>> string formatting features.) >>> >>> Another option is to use the decimal numeric type. That has other >>> compromises associated with it but, if retaining absolute decimal >>> accuracy is your primary goal, it might suit you better. >>> >>> >>> -- >>> 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 wlfraed at ix.netcom.com Sun Dec 18 11:07:18 2022 From: wlfraed at ix.netcom.com (Dennis Lee Bieber) Date: Sun, 18 Dec 2022 11:07:18 -0500 Subject: Single line if statement with a continue References: Message-ID: On Wed, 14 Dec 2022 10:53:10 -0800 (PST), Aaron P declaimed the following: Late response here, and the concept may have been covered in skimmed-over posts.. >I occasionally run across something like: > >for idx, thing in enumerate(things): > if idx == 103: > continue > do_something_with(thing) > For this example, I'd probably reverse the condition. if idx != 103: do_something_with(thing) and hence completely drop the "continue" -- after all, if idx is 103, the if statement falls through, and the end of the loop acts as an implicit "continue" OTOH: if the "if/continue" is buried in four or five layers of conditionals, it could be cleaner than trying to configure the conditionals to have a chained exit. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ From songbird at anthive.com Sun Dec 18 10:44:18 2022 From: songbird at anthive.com (songbird) Date: Sun, 18 Dec 2022 10:44:18 -0500 Subject: Keeping a list of records with named fields that can be updated References: <6gip6j-698.ln1@anthive.com> <9158537c-f561-e666-f60c-34d50f61d7b7@web.de> Message-ID: Peter Otten wrote: ... > While I think what you need is a database instead of the collection of > csv files the way to alter namedtuples is to create a new one: > > >>> from collections import namedtuple > >>> Row = namedtuple("Row", "foo bar baz") > >>> row = Row(1, 2, 3) > >>> row._replace(bar=42) > Row(foo=1, bar=42, baz=3) namedtuple is easier to use as that will use the csv and csvreader and create the records without me having to do any conversion or direct handling myself. it's all automagically done. my initial version works, but i'd like it to be a bit more elegant and handle descriptions it hasn't seen before in a more robust manner. > An alternative would be dataclasses where basic usage is just as easy: > > >>> from dataclasses import make_dataclass > >>> Row = make_dataclass("Row", "foo bar baz".split()) > >>> row = Row(1, 2, 3) > >>> row > Row(foo=1, bar=2, baz=3) > >>> row.bar = 42 > >>> row > Row(foo=1, bar=42, baz=3) i do like that i can directly reference each field in a dataclass and not have to specify a _replace for each change. is there an easy way to convert from namedtuple to dataclass? i can see there is a _asdict converter, but don't really like how that turns out as then i have to do a bunch of: rec['fieldname'] = blah rec.fieldname is much easier to understand. songbird From bowman at montana.com Sun Dec 18 12:19:56 2022 From: bowman at montana.com (rbowman) Date: 18 Dec 2022 17:19:56 GMT Subject: String to Float, without introducing errors References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> <639e32de.020a0220.7add7.2f5b@mx.google.com> Message-ID: On Sun, 18 Dec 2022 11:14:28 -0500, Dennis Lee Bieber wrote: > .. And maybe lament the days when a 3-digit result was acceptable in > math class -- being the typical capability in reading a standard (10" > scale) slide rule. Arguably more thought was given to what those three digits meant in the real world. For example, is calculating a latitude to 6 decimal places meaningful when the data was gathered by a GPS receiver with 5m accuracy? From email at paulstgeorge.com Sun Dec 18 12:35:47 2022 From: email at paulstgeorge.com (Paul St George) Date: Sun, 18 Dec 2022 18:35:47 +0100 Subject: String to Float, without introducing errors Message-ID: <414BA74A-525D-4923-A435-47DB61F78979@paulstgeorge.com> So I am working on a physics paper with a colleague. We have a theory about Newtons Cradle. We answer the question why when you lift and drop balls 1 and 2, balls 4 and 5 rise up. I could say more, but ... (if you are interested please write to me). We want to illustrate the paper with animations. The theory includes distortion of the balls and this distortion is very very small. So, I am sent data with locations and dimensions to 13 decimal places. Something strange is happening with the animations: the balls are not moving smoothly. I do not know (yet) where the problem lies so it is difficult to provide a clear narrative. Because there is a problem, I am investigating in all areas. This brings me to the question I asked here. I am not expecting six decimal places or three decimal places to be as accurate as thirteen decimal places, but I would like to be in control of or fully aware of what goes on under the bonnet. ? >> On 17 Dec 2022, at 16:54:05 EST 2022, Thomas Passin wrote: On 12/17/2022 3:45 PM, Paul St George wrote: > Thanks to all! > It was the rounding rounding error that I needed to avoid (as Peter J. Holzer suggested). The use of decimal solved it and just in time. I was about to truncate the number, get each of the characters from the string mantissa, and then do something like this: > > 64550.727 > > 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001) > > Now I do not need to! And that approach would not have helped you, because each of those calculations would be done as floating point, and you wouldn't have gotten any more precision (and maybe less) than simply doing float('64550.727'). Here is a small but interesting discussion thread about float vs Decimal: https://stackoverflow.com/questions/32053647/comparing-python-decimals-created-from-float-and-string Would you mind telling us why that degree of precision (that is, decimal vs float) matters for your problem? >> On 17 Dec 2022, at 13:11, Alan Gauld > wrote: >> >> On 17/12/2022 11:51, Paul St George wrote: >>> I have a large/long array of numbers in an external file. The numbers look like this: >>> >>> -64550.727 >>> -64511.489 >>> -64393.637 >>> -64196.763 >>> -63920.2 >> >>> When I bring the numbers into my code, they are Strings. To use the >>> numbers in my code, I want to change the Strings to Float type >>> because the code will not work with Strings but I do not want >>> to change the numbers in any other way. >> >> That may be impossible. Float type is not exact and the conversion >> will be the closest binary representation of your decimal number. >> It will be very close but it may be slightly different when you >> print it, for example. (You can usually deal with that by using >> string formatting features.) >> >> Another option is to use the decimal numeric type. That has other >> compromises associated with it but, if retaining absolute decimal >> accuracy is your primary goal, it might suit you better. >> >> >> -- >> 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 c.buhtz at posteo.jp Sun Dec 18 16:07:38 2022 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Sun, 18 Dec 2022 21:07:38 +0000 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> Message-ID: Dear Chris, thank you for your reply. Am 18.12.2022 20:27 schrieb Chris Angelico: > Does it have to be in path? Can't you say > /usr/local/bin/entrypointname? Not sure what constitutes an elegant > solution here. I asked that myself. My current solution do determine the full path of the entrypoint via "which entrypoint". I also think this is to my current knowledge the best solution. From barry at barrys-emacs.org Sun Dec 18 16:33:22 2022 From: barry at barrys-emacs.org (Barry) Date: Sun, 18 Dec 2022 21:33:22 +0000 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: <4NZn7V1JFkz6tpJ@submission01.posteo.de> References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> Message-ID: <53296433-ED16-42C4-8F97-4408A8D6061E@barrys-emacs.org> > On 18 Dec 2022, at 17:57, c.buhtz at posteo.jp wrote: > > ?Hello, > > when I install a package on a GNU/Linux system via "sudo python3 -m pip > install -e ." that defines entry points in its pyproject.toml the entry > point starter scripts are located in /usr/locale/bin. > > That folder is in PATH for "regular" root users and by "sudo su" roots > users. > > But I need to start that entry points via "pkexec". > But in the environment started by "pkexec" the PATH does not contain > /usr/local/bin. > > So what can I do? Why are asking on this list and discuss.python.org? Lots of people on this list are also on discuss.python.org. Barry > > I don't need a hack or workaround but an "elegant" solution. > -- > https://mail.python.org/mailman/listinfo/python-list > From mats at wichmann.us Sun Dec 18 16:37:07 2022 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 18 Dec 2022 14:37:07 -0700 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> Message-ID: On 12/18/22 14:07, c.buhtz at posteo.jp wrote: > Dear Chris, > > thank you for your reply. > > Am 18.12.2022 20:27 schrieb Chris Angelico: >> Does it have to be in path? Can't you say >> /usr/local/bin/entrypointname? Not sure what constitutes an elegant >> solution here. > > I asked that myself. My current solution do determine the full path of > the entrypoint via "which entrypoint". > I also think this is to my current knowledge the best solution. the which command uses your PATH, so I'm not sure you're buying anything new there.... From PythonList at DancesWithMice.info Sun Dec 18 16:45:34 2022 From: PythonList at DancesWithMice.info (dn) Date: Mon, 19 Dec 2022 10:45:34 +1300 Subject: String to Float, without introducing errors In-Reply-To: References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> <639e32de.020a0220.7add7.2f5b@mx.google.com> Message-ID: On 18/12/2022 10.55, Stefan Ram wrote: > Grant Edwards writes: >> Yes, fixed point (or decimal) is a better fit for what he's doing. but >> I suspect that floating point would be a better fit for the problem >> he's trying to solve. > > I'd like to predict that within the next ten posts in this > thread someone will mention "What Every Computer Scientist > Should Know About Floating-Point Arithmetic". Thank you for doing-so. More specific: https://docs.python.org/3/tutorial/floatingpoint.html Perhaps in the rush to 'answer', the joke is on 'us' - that we might first need to more carefully-understand the OP's use-case, requirements, and constraints? The joke sours when remembering that this 'mystery' generates frequent questions 'here' (and on other Python fora) - not as many as 'why don't I see a pretty-GUI when I fire-up Python on MS-Windows?' but it is a more sophisticated realisation and deserves a detailed response (such as the thought-provoking illustration-code appearing today). Is it a consequence of Python lowering 'the barrier to entry'? Good thing? Bad thing? (we first started noticing this sort of issue in our (non-Python) MOOCs, several pre-COVID years ago: when we first started, the trainee was typically recent post-grad; whereas today we enrol folk with a much wider range of ages and backgrounds. It is likely that more dev.work has gone into 'the bottom end', than into new/higher sophistications - even given IT's rate-of-change!) -- -- Regards, =dn From cs at cskk.id.au Sun Dec 18 16:53:56 2022 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 19 Dec 2022 08:53:56 +1100 Subject: String to Float, without introducing errors In-Reply-To: <414BA74A-525D-4923-A435-47DB61F78979@paulstgeorge.com> References: <414BA74A-525D-4923-A435-47DB61F78979@paulstgeorge.com> Message-ID: On 18Dec2022 18:35, Paul St George wrote: >So I am working on a physics paper with a colleague. We have a theory about Newtons Cradle. We answer the question why when you lift and drop balls 1 and 2, balls 4 and 5 rise up. I could say more, but ... (if you are interested please write to me). > >We want to illustrate the paper with animations. The theory includes distortion of the balls and this distortion is very very small. So, I am sent data with locations and dimensions to 13 decimal places. Something strange is happening with the animations: the balls are not moving smoothly. I do not know (yet) where the problem lies so it is difficult to provide a clear narrative. > >Because there is a problem, I am investigating in all areas. This brings me to the question I asked here. I am not expecting six decimal places or three decimal places to be as accurate as thirteen decimal places, but I would like to be in control of or fully aware of what goes on under the bonnet. First the short take: your machine pobably is quite precise, and float is far more performant that the other numeric types available. Your source data seem to have more round off than the rounding in a float. Under the bonnet: A Python float is effectively a base-2 value in scientific notation. Internally it has a base-2 mantissa and base-2 exponent. This page: https://docs.python.org/3/library/stdtypes.html#typesnumeric says that CPython's float uses C's "double" floating point type (you are almost certainly using the CPython implementation) and thus you're using the machine's floating point implemenetation. I believe that almost all modern CPUs implement IEEE 754 floating point: https://en.wikipedia.org/wiki/IEEE_754 Because they're base 2, various values in other bases will not be precisely representable as a float. For example, 1/3 (which you will know is _also_ not representable precisely as a base-10 value such as 0.333). You can get specifics of your Python's floating point from `sys.float_Info`, i.e: from sys import float_info The look at float_info.epsilon etc. Details: https://docs.python.org/3/library/sys.html#sys.float_info Here's my machine: Python 3.10.6 (main, Aug 11 2022, 13:47:18) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from sys import float_info >>> float_info sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1) Values of note: mant_dig=53 (53 base-2 bits), dig=15 (15 decimal digits of precision). You might want to look at sys.float_repr_style here: https://docs.python.org/3/library/sys.html#sys.float_repr_style which affects how Python writes floats out. In particular this text: If the string has value 'short' then for a finite float x, repr(x) aims to produce a short string with the property that float(repr(x)) == x. This is the usual behaviour in Python 3.1 and later. Again, on my machine: >>> 64550.727 64550.727 >>> 64550.728 64550.728 >>> 64550.72701 64550.72701 >>> 64550.7270101 64550.7270101 >>> 64550.727010101 64550.727010101 >>> 64550.72701010101 64550.72701010101 >>> 64550.7270101010101 64550.72701010101 >>> 64550.727010101010101 64550.72701010101 >>> 64550.72701010101010101 64550.72701010101 >>> On 17 Dec 2022, at 16:54:05 EST 2022, Thomas Passin wrote: >On 12/17/2022 3:45 PM, Paul St George wrote: >> Thanks to all! >> It was the rounding rounding error that I needed to avoid (as Peter J. Holzer suggested). The use of decimal solved it and just in time. I was about to truncate the number, get each of the characters from the string mantissa, and then do something like this: >> >> 64550.727 >> >> 64550 + (7 * 0.1) + (2 * 0.01) + (7 * 0.001) >> >> Now I do not need to! Good, because if you do that using floats it will be less precise than float(64550.727). (Which I see Alan has already stated.) Your source file contains strings like "64550.727". They look to already be less than 13 digits of precision as written i.e. some round off already took place when that file was written. Do you know the precision of the source data? I suspect that rather than chasing a "perfect" representation of your source data, which is already rounded off, you: - see if the source values can be obtained more precisely - figure out which operations in your simulation contribute to the motion roughness you see I'm no expert on floating point coding for precision, but I believe that trying to work with values "close together" in magnitude is important because values of different scales inherently convert one of them to the other scale (i.e. similar sized exponent part) with corresponding loss of precision in the mantissa part. That may require you to form your calcutations carefully. See if you can locate a source for the jerkiness (by printing intermediate results) and then maybe rephrase that step? Cheers, Cameron Simpson From rosuav at gmail.com Sun Dec 18 17:25:17 2022 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Dec 2022 09:25:17 +1100 Subject: String to Float, without introducing errors In-Reply-To: References: <1de4633b-b6c4-14af-7463-8a57527cf0be@tompassin.net> Message-ID: On Mon, 19 Dec 2022 at 07:57, Stefan Ram wrote: > G = Decimal( 6.6743015E-11 ) > r = Decimal( 6.371E6 ) > M = Decimal( 5.9722E24 ) What's the point of using Decimal if you start with nothing more than float accuracy? ChrisA From guinness.tony at gmail.com Sun Dec 18 16:27:52 2022 From: guinness.tony at gmail.com (Tony Oliver) Date: Sun, 18 Dec 2022 13:27:52 -0800 (PST) Subject: Single line if statement with a continue In-Reply-To: References: <006801d91273$5cfffe80$16fffb80$@gmail.com> <4f21e136-dbec-3aed-60e2-c3908bebce71@btinternet.com> Message-ID: On Saturday, 17 December 2022 at 23:58:11 UTC, avi.e... at gmail.com wrote: > Is something sort of taboo when using something like a computer language to write a program? With what else would you write a program? From greg.ewing at canterbury.ac.nz Sun Dec 18 16:35:39 2022 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 19 Dec 2022 10:35:39 +1300 Subject: String to Float, without introducing errors In-Reply-To: References: <414BA74A-525D-4923-A435-47DB61F78979@paulstgeorge.com> Message-ID: <95fed732-8a8f-eb55-8e82-3061fd2d8359@canterbury.ac.nz> On 19/12/22 6:35 am, Paul St George wrote: > So I am working on a physics paper with a colleague. We have a theory about Newtons Cradle. > > We want to illustrate the paper with animations. > > Because there is a problem, I am investigating in all areas. ... I would like to be in control of or fully aware of what goes on under the bonnet. When you convert a string to a float, you're already getting the closest possible value in binary floating point. For things like physics simulations, you need to design your algorithms so that they're tolerant of small inaccuracies in the representation of your numbers. If those are causing you problems, it sounds like there is some kind of numerical instability in your algorithm that needs to be addressed. It's also possible that there is just a bug somewhere in your code, and the problem really has nothing to do with floating point inaccuracies. If you can post some code we might be able to help you further. -- Greg From cs at cskk.id.au Sun Dec 18 19:41:13 2022 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 19 Dec 2022 11:41:13 +1100 Subject: String to Float, without introducing errors In-Reply-To: References: Message-ID: On 19Dec2022 08:53, Cameron Simpson wrote: >I'm no expert on floating point coding for precision, but I believe >that trying to work with values "close together" in magnitude is >important because values of different scales inherently convert one of >them to the other scale (i.e. similar sized exponent part) with >corresponding loss of precision in the mantissa part. That may require >you to form your calcutations carefully. This depends on the operation. With addition/subtraction you'd see this directly. With multiplication etc it isn't really the case. But there are both more and less effective ways to arrange your floating point math in terms of preserving what precision you have. Cheers, Cameron Simpson From c.buhtz at posteo.jp Mon Dec 19 01:29:10 2022 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Mon, 19 Dec 2022 06:29:10 +0000 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> Message-ID: <8dab758ebb1071c7854bf4e714d76450@posteo.de> Am 18.12.2022 22:37 schrieb Mats Wichmann: > the which command uses your PATH, so I'm not sure you're buying > anything new there.... I'm using which before entering pkexec. ;) I'll show a demonstrator project later. From c.buhtz at posteo.jp Mon Dec 19 01:36:49 2022 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Mon, 19 Dec 2022 06:36:49 +0000 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: <53296433-ED16-42C4-8F97-4408A8D6061E@barrys-emacs.org> References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> <53296433-ED16-42C4-8F97-4408A8D6061E@barrys-emacs.org> Message-ID: Dear Barry, thanks for reply and asking back. Am 18.12.2022 22:33 schrieb Barry: > Why are asking on this list and discuss.python.org? To be exact I'm asking in the "Packaging" section of "discuss.python.org". To my knowledge that section is the official channel of "pypa/pip" project pointed to from there own README.md [1]. To be complete. I also asked in in context of "pypa/setuptools" [2] and on the debian-python mailing list. Not all questions are exactly the same but touching the same meta topic. "pypa/setuptools" themselfs pointed me to the fact that they are not responsible for generating the entry-point-scripts but "pypa/pip" is. No matter both have "pypa/" in their names they seem technically different. This has reasons but is very confusing for "developers from the outside" like me. There are also alternative build-tools other then "setuptools". That is why I asked on that python-list here, too. The later was in the hope to maybe be pointed to alternative solutions away from setuptools and/or pip. My apologize. When I decide for a solution I will point you to a demonstrator repository illustrating that solution. [1] -- [2] -- From rosuav at gmail.com Mon Dec 19 01:40:52 2022 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Dec 2022 17:40:52 +1100 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: <8dab758ebb1071c7854bf4e714d76450@posteo.de> References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> <8dab758ebb1071c7854bf4e714d76450@posteo.de> Message-ID: On Mon, 19 Dec 2022 at 17:30, wrote: > > Am 18.12.2022 22:37 schrieb Mats Wichmann: > > the which command uses your PATH, so I'm not sure you're buying > > anything new there.... > > I'm using which before entering pkexec. ;) > > I'll show a demonstrator project later. Hmm, then I'm not sure what you're *losing* here. The problem, as I understand it, is that the scripts are getting installed into /usr/local/bin (which is on PATH at the time they're installed), but pkexec has a restricted PATH. So if you use which before pkexec'ing, wouldn't you find the scripts, and then be able to run them without regard to PATH? ChrisA From c.buhtz at posteo.jp Mon Dec 19 03:36:34 2022 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Mon, 19 Dec 2022 08:36:34 +0000 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> <8dab758ebb1071c7854bf4e714d76450@posteo.de> Message-ID: Dear Chris, thanks for asking back and my apologize for being to broad in my way of asking (in a foreign language). Am 19.12.2022 07:40 schrieb Chris Angelico: > Hmm, then I'm not sure what you're *losing* here. The problem, as I > understand it, is that the scripts are getting installed into > /usr/local/bin (which is on PATH at the time they're installed), but > pkexec has a restricted PATH. So if you use which before pkexec'ing, > wouldn't you find the scripts, and then be able to run them without > regard to PATH? Absolut correct. This works. The question is if this is a "good" or "elegant" way from the viewpoint of different communities/projects (e.g. Python, setuptools, pip, other build-systems, distros, something I forgot). I assume that I'm not the first person with such a use case. So there could be solutions out there. Maybe they are standardized solutions out there; e.g. a magic feature of setuptools or pip I haven't noticed yet. From rosuav at gmail.com Mon Dec 19 06:17:26 2022 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 19 Dec 2022 22:17:26 +1100 Subject: pip/setuptools: Entry points not visible from pkexec-root-environment In-Reply-To: References: <4NZn7V1JFkz6tpJ@submission01.posteo.de> <8dab758ebb1071c7854bf4e714d76450@posteo.de> Message-ID: On Mon, 19 Dec 2022 at 19:38, wrote: > > Dear Chris, > thanks for asking back and my apologize for being to broad in my way of > asking (in a foreign language). > > Am 19.12.2022 07:40 schrieb Chris Angelico: > > Hmm, then I'm not sure what you're *losing* here. The problem, as I > > understand it, is that the scripts are getting installed into > > /usr/local/bin (which is on PATH at the time they're installed), but > > pkexec has a restricted PATH. So if you use which before pkexec'ing, > > wouldn't you find the scripts, and then be able to run them without > > regard to PATH? > > Absolut correct. This works. > > The question is if this is a "good" or "elegant" way from the viewpoint > of different communities/projects (e.g. Python, setuptools, pip, other > build-systems, distros, something I forgot). > Ah! Then, my response is: Yes, it is definitely a good/elegant solution. I've often created scripts that install into somewhere (eg systemd, cron, ifupdown) by using 'which' to figure something out, and then posting the full path into the corresponding file. It's a convenient way to ensure that the exact same program would be used. Notably, "which python3" will ensure that you run on the currently-active Python interpreter; this includes virtual environments. Very convenient. ChrisA From hjp-python at hjp.at Mon Dec 19 07:01:41 2022 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 19 Dec 2022 13:01:41 +0100 Subject: Single line if statement with a continue In-Reply-To: References: Message-ID: <20221219120141.4geegs2aq4or37b3@hjp.at> On 2022-12-18 16:49:27 +0000, Stefan Ram wrote: > Dennis Lee Bieber writes: > >>for idx, thing in enumerate(things): > >> if idx == 103: > >> continue > >> do_something_with(thing) > >> > > For this example, I'd probably reverse the condition. > > if idx != 103: > > do_something_with(thing) > > The first four lines of the quotation above cannot be a > complete program as "do_something_with" is not defined > therein, so they must be part of a larger program. > If, in this larger program, something still follows > "do_something_with(thing)" in the loop, the new program > after the transformation might not show the same behavior. ?do_something_with(thing)? is obviously not intended to be a single function call but as a shorthand for ?one or more lines of code which do something with `thing`?. So there is nothing after it because it is included in it. That said, the "fail and bail" technique is often more readable than putting the main incode inside of an if - especially if that code is long and/or it is guarded by multiple conditions. 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 Mon Dec 19 09:10:52 2022 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 19 Dec 2022 15:10:52 +0100 Subject: String to Float, without introducing errors In-Reply-To: References: <1de4633b-b6c4-14af-7463-8a57527cf0be@tompassin.net> Message-ID: <20221219141052.frflz6y2n6md7uvj@hjp.at> On 2022-12-19 09:25:17 +1100, Chris Angelico wrote: > On Mon, 19 Dec 2022 at 07:57, Stefan Ram wrote: > > G = Decimal( 6.6743015E-11 ) > > r = Decimal( 6.371E6 ) > > M = Decimal( 5.9722E24 ) > > What's the point of using Decimal if you start with nothing more than > float accuracy? Right. He also interpreted the notation "6.67430(15)E-11" wrong. The digits in parentheses represent the uncertainty in the same number of last digits. So "6.67430(15)E-11" means "something between 6.67430E-11 - 0.00015E-11 and 6.67430E-11 + 0.00015E-11". The r value has only a precision of 1 km and I'm not sure how accurate the mass is. Let's just assume (for the sake of the argument) that these are actually accurate in all given digits. So G is between 6.67415E-11 and 6.67445E-11, r is between 6.3705E6 and 6.3715E6 and M is between 5.97215E24 and 5.97225E24. If we compute the time for those deviations you will find that the differences are many orders of magnitude greater than the effect you wanted to show. And that still ignores the fact that a vacuum won't be perfect (and collisions with a few stray atoms might have a similarly tiny effect), that gravity isn't constant while the weight falls (it's getting closer to the center of the earth and it's moving past other masses on its way) that Newton's law is only an approximation, etc. So while the effect is (almost certainly) real, the numbers are garbage. I think there's a basic numeracy problem here. This is unfortunately all too common, even among scientists. The OP apparently rounded their numbers to 8 significant digits (thereby introducing an error of about 1E-8) and then insisted that the additional error of 1E-15 introduced by the decimal to float conversion was unacceptable, showing IMHO a fundamental misunderstanding of the numbers they are working with. 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 gweatherby at uchc.edu Mon Dec 19 09:59:20 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Mon, 19 Dec 2022 14:59:20 +0000 Subject: Installation hell In-Reply-To: References: Message-ID: Personally, I don?t use Windows and avoid it like the plague. Python is easy to install on Linux and Mac. I?d start here: https://learn.microsoft.com/en-us/visualstudio/python/overview-of-python-tools-for-visual-studio?view=vs-2022 From: Python-list on behalf of Jim Lewis Date: Sunday, December 18, 2022 at 12:56 PM To: Python-list at python.org Subject: Fwd: Installation hell *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** I'm an occasional user of Python and have a degree in computer science. Almost every freaking time I use Python, I go through PSH (Python Setup Hell). Sometimes a wrong version is installed. Sometimes it's a path issue. Or exe naming confusion: python, python3, phthon311, etc. Or library compatibility issues - took an hour to find out that pygame does not work with the current version of python. Then the kludgy PIP app and using a DOS box under Windows with command prompts which is ridiculous. God only knows how many novice users of the language (or even intermediate users) were lost in the setup process. Why not clean the infrastructure up and make a modern environment or IDE or something better than it is now. Or at least good error messages that explain exactly what to do. Even getting this email to the list took numerous steps. -- A frustrated user -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!gdOs-oC1JZcmvMXy1G4irRpzHCUmF565UXVdCjzSWNGZKpmZ04I_llDX4WUeob3asBCjLe6TIthAAhmwFgbph9u1m9A$ From list1 at tompassin.net Mon Dec 19 10:02:46 2022 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 19 Dec 2022 10:02:46 -0500 Subject: String to Float, without introducing errors In-Reply-To: <20221219141052.frflz6y2n6md7uvj@hjp.at> References: <1de4633b-b6c4-14af-7463-8a57527cf0be@tompassin.net> <20221219141052.frflz6y2n6md7uvj@hjp.at> Message-ID: On 12/19/2022 9:10 AM, Peter J. Holzer wrote: > On 2022-12-19 09:25:17 +1100, Chris Angelico wrote: >> On Mon, 19 Dec 2022 at 07:57, Stefan Ram wrote: >>> G = Decimal( 6.6743015E-11 ) >>> r = Decimal( 6.371E6 ) >>> M = Decimal( 5.9722E24 ) >> >> What's the point of using Decimal if you start with nothing more than >> float accuracy? > > Right. He also interpreted the notation "6.67430(15)E-11" wrong. The > digits in parentheses represent the uncertainty in the same number of > last digits. So "6.67430(15)E-11" means "something between 6.67430E-11 - > 0.00015E-11 and 6.67430E-11 + 0.00015E-11". The r value has only a > precision of 1 km and I'm not sure how accurate the mass is. Let's just > assume (for the sake of the argument) that these are actually accurate in > all given digits. > > So G is between 6.67415E-11 and 6.67445E-11, r is between 6.3705E6 and > 6.3715E6 and M is between 5.97215E24 and 5.97225E24. If we compute the > time for those deviations you will find that the differences are many > orders of magnitude greater than the effect you wanted to show. And that > still ignores the fact that a vacuum won't be perfect (and collisions > with a few stray atoms might have a similarly tiny effect), that gravity > isn't constant while the weight falls (it's getting closer to the center > of the earth and it's moving past other masses on its way) that Newton's > law is only an approximation, etc. So while the effect is (almost > certainly) real, the numbers are garbage. > > I think there's a basic numeracy problem here. This is unfortunately all > too common, even among scientists. The OP apparently rounded their > numbers to 8 significant digits (thereby introducing an error of about > 1E-8) and then insisted that the additional error of 1E-15 introduced by > the decimal to float conversion was unacceptable, showing IMHO a > fundamental misunderstanding of the numbers they are working with. > > hp In a way, this example shows both things - the potential value of using Decimal numbers, and a degree of innumeracy. It also misses a chance to illustrate how to approach a problem in the simplest and most informative way. Here's what I mean - We can imagine that the input numbers really are exact, with the remaining digits filled in with zeros. Then it might really be the case that - if you wanted to do this computation with precision and could assume all those other effects could be neglected - using Decimals would be a good thing to do. So OK, let's say that's demonstrated. No need to nit-pick it further. As a physics problem, though, you would generally be interested in two kinds of things: 1. Could there be such an effect, and if so would it be large enough to be interesting, whether in theory or in practice? 2. Can there be any feasible way to demonstrate the proposed effect by measurements? The first thing one should do is to find a way to estimate the magnitude of the effect so it can be compared with some of those other phenomena (non-constant gravity, etc) to see if it's worth doing a full computation at all, or even spending any more time on the matter. There is likely to be a way to make such an estimate without needing to resort to extremely high precision - you would only need to get within perhaps an order of magnitude. Your real task, then, is to find that way. For example, you would probably be able to estimate the precision needed without actually doing the calculation. That in itself might turn out to enough. From python at mrabarnett.plus.com Mon Dec 19 10:14:14 2022 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 19 Dec 2022 15:14:14 +0000 Subject: String to Float, without introducing errors In-Reply-To: <20221219141052.frflz6y2n6md7uvj@hjp.at> References: <1de4633b-b6c4-14af-7463-8a57527cf0be@tompassin.net> <20221219141052.frflz6y2n6md7uvj@hjp.at> Message-ID: On 2022-12-19 14:10, Peter J. Holzer wrote: > On 2022-12-19 09:25:17 +1100, Chris Angelico wrote: >> On Mon, 19 Dec 2022 at 07:57, Stefan Ram wrote: >> > G = Decimal( 6.6743015E-11 ) >> > r = Decimal( 6.371E6 ) >> > M = Decimal( 5.9722E24 ) >> >> What's the point of using Decimal if you start with nothing more than >> float accuracy? > > Right. He also interpreted the notation "6.67430(15)E-11" wrong. The > digits in parentheses represent the uncertainty in the same number of > last digits. So "6.67430(15)E-11" means "something between 6.67430E-11 - > 0.00015E-11 and 6.67430E-11 + 0.00015E-11". The r value has only a > precision of 1 km and I'm not sure how accurate the mass is. Let's just > assume (for the sake of the argument) that these are actually accurate in > all given digits. > > So G is between 6.67415E-11 and 6.67445E-11, r is between 6.3705E6 and > 6.3715E6 and M is between 5.97215E24 and 5.97225E24. If we compute the > time for those deviations you will find that the differences are many > orders of magnitude greater than the effect you wanted to show. And that > still ignores the fact that a vacuum won't be perfect (and collisions > with a few stray atoms might have a similarly tiny effect), that gravity > isn't constant while the weight falls (it's getting closer to the center > of the earth and it's moving past other masses on its way) that Newton's > law is only an approximation, etc. So while the effect is (almost > certainly) real, the numbers are garbage. > > I think there's a basic numeracy problem here. This is unfortunately all > too common, even among scientists. The OP apparently rounded their > numbers to 8 significant digits (thereby introducing an error of about > 1E-8) and then insisted that the additional error of 1E-15 introduced by > the decimal to float conversion was unacceptable, showing IMHO a > fundamental misunderstanding of the numbers they are working with. > To be fair, I don't think I've never seen that notation either! I've only ever seen the form 6.67430E-11 ? 0.00015E-11, which is much clearer. From list1 at tompassin.net Mon Dec 19 10:55:52 2022 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 19 Dec 2022 10:55:52 -0500 Subject: Installation hell In-Reply-To: References: Message-ID: <37be6b3c-fb22-83ad-16d1-25ed8ade3e76@tompassin.net> On 12/19/2022 9:59 AM, Weatherby,Gerard wrote: > Personally, I don?t use Windows and avoid it like the plague. Python is easy to install on Linux and Mac. That's not been my experience. Windows installers for Python have worked well for me over many generations of Python releases. It's Linux where I've found difficulties. For example, if your distro's Python install didn't include tkinter (or even pip), how do you get it? It's different for different Linux distros. I generally have to use internet searches to find out. For another example, when you use pip to install a package, it sometimes suggests that you install a newer version of pip itself. Should you do that? On Linux, probably not, because the distro will have modified pip so it puts things in distro-specific places. Yet there is no newer version of pip available through the distro's package manager. Will anything bad happen if you don't update pip? Who knows? I have a Linux VM that has several versions of Python3 on it. Python3.8 came installed with the distro, but for some programs I need Python 3.9+. If I forget which versions I have, how can I find out? People say to use which, but that doesn't work - it only reports "python3". This does work, but it's not all that easy to remember (the grep "site" part is just to filter out uninformative result lines): ~$ find 2>/dev/null ~ -name python -type d |grep "site" /home/tom/.local/lib/python3.9/site-packages/PyQt5/Qt5/qsci/api/python /home/tom/.local/lib/python3.8/site-packages/pandas/_libs/src/ujson/python /home/tom/.local/lib/python3.10/site-packages/PyQt5/Qt5/qsci/api/python Not that this task is much easier to remember on Windows, but it's not harder. One way: the "py" launcher will tell you: py --list -V:3.10 * Python 3.10 (64-bit) -V:3.9 Python 3.9 (64-bit) -V:3.7 Python 3.7 (64-bit) -V:2.7 This is not Linux-bashing, but there's no need for Windows-bashing either. > I?d start here: https://learn.microsoft.com/en-us/visualstudio/python/overview-of-python-tools-for-visual-studio?view=vs-2022 > > From: Python-list on behalf of Jim Lewis > Date: Sunday, December 18, 2022 at 12:56 PM > To: Python-list at python.org > Subject: Fwd: Installation hell > *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > > I'm an occasional user of Python and have a degree in computer science. > Almost every freaking time I use Python, I go through PSH (Python Setup > Hell). Sometimes a wrong version is installed. Sometimes it's a path issue. > Or exe naming confusion: python, python3, phthon311, etc. Or library > compatibility issues - took an hour to find out that pygame does not work > with the current version of python. Then the kludgy PIP app and using a DOS > box under Windows with command prompts which is ridiculous. God only knows > how many novice users of the language (or even intermediate users) were > lost in the setup process. Why not clean the infrastructure up and make a > modern environment or IDE or something better than it is now. Or at least > good error messages that explain exactly what to do. Even getting this > email to the list took numerous steps. > > -- A frustrated user > -- > https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!gdOs-oC1JZcmvMXy1G4irRpzHCUmF565UXVdCjzSWNGZKpmZ04I_llDX4WUeob3asBCjLe6TIthAAhmwFgbph9u1m9A$ From hjp-python at hjp.at Mon Dec 19 11:23:38 2022 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 19 Dec 2022 17:23:38 +0100 Subject: String to Float, without introducing errors In-Reply-To: References: <1de4633b-b6c4-14af-7463-8a57527cf0be@tompassin.net> <20221219141052.frflz6y2n6md7uvj@hjp.at> Message-ID: <20221219162338.u5aheuwh6vpjnjca@hjp.at> On 2022-12-19 15:14:14 +0000, MRAB wrote: > On 2022-12-19 14:10, Peter J. Holzer wrote: > > He also interpreted the notation "6.67430(15)E-11" wrong. The > > digits in parentheses represent the uncertainty in the same number of > > last digits. So "6.67430(15)E-11" means "something between 6.67430E-11 - > > 0.00015E-11 and 6.67430E-11 + 0.00015E-11". [...] > To be fair, I don't think I've never seen that notation either! I've probably seen it first on Wikipedia, quite a few years ago. Since then I've also encountered in in physical and astronomical papers (I'm neither a physicist nor an astronomomer but I occasionally read the original papers if what I read in the "mainstream media"[1] or hear on youtube seems suspect). > I've only ever seen the form 6.67430E-11 ? 0.00015E-11, which is much > clearer. Yeah, it's definitely not the pinnacle of inuitiveness. I freely admit that I looked it up before posting just to make sure that I wasn't confused about its meaning. Another problem (but it shares that with the ? notation) is that it's not clear what that number actually represents. Is it one sigma or two? Or something else? Is the distribution even symmetric? hp [1] I'm not quite happy with that term. -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From rosuav at gmail.com Mon Dec 19 11:36:55 2022 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Dec 2022 03:36:55 +1100 Subject: Installation hell In-Reply-To: <37be6b3c-fb22-83ad-16d1-25ed8ade3e76@tompassin.net> References: <37be6b3c-fb22-83ad-16d1-25ed8ade3e76@tompassin.net> Message-ID: On Tue, 20 Dec 2022 at 03:05, Thomas Passin wrote: > > That's not been my experience. Windows installers for Python have > worked well for me over many generations of Python releases. It's Linux > where I've found difficulties. For example, if your distro's Python > install didn't include tkinter (or even pip), how do you get it? It's > different for different Linux distros. I generally have to use internet > searches to find out. If you want to use your distro's Python and add more stuff to it globally, then yes, it depends on your distro. This is not really a surprise. > For another example, when you use pip to install a package, it sometimes > suggests that you install a newer version of pip itself. Should you do > that? On Linux, probably not, because the distro will have modified pip > so it puts things in distro-specific places. Yet there is no newer > version of pip available through the distro's package manager. Will > anything bad happen if you don't update pip? Who knows? Virtual environments work the same way regardless of distro, including allowing you to install an upgraded pip. As long as your distro provides the venv package (on Debian, that's in python3-venv), you can just: $ python3 -m venv env $ source env/bin/activate $ pip install -U pip $ pip install -r requirements.txt $ pip install some-package-name $ etc etc etc etc etc This is also a recommended way to do things on Windows, so you don't even need to do things differently. > I have a Linux VM that has several versions of Python3 on it. Python3.8 > came installed with the distro, but for some programs I need Python > 3.9+. If I forget which versions I have, how can I find out? People > say to use which, but that doesn't work - it only reports "python3". > This does work, but it's not all that easy to remember (the grep "site" > part is just to filter out uninformative result lines): Use what your shell already offers you! If you have multiple Pythons installed, type "python3" and hit tab twice. You should get a list of options. The exact shell you're using will affect how they're shown, but I'm pretty sure most shells (at least, the ones designed to be interactive - /bin/dash might not) will give you some facility like this. rosuav at sikorsky:~$ python3 python3 python3.5-dbg-config python3.8-config python3.10 python3.5dm python3.8m python3.10-config python3.5dm-config python3.8m-config python3.11 python3.5m python3.9 python3.11-config python3.5m-config python3.9-config python3.12 python3.6 python3.9d python3.12-config python3.6-config python3.9-dbg python3.4 python3.6m python3.9-dbg-config python3.4-config python3.6m-config python3.9d-config python3.4m python3.7 python3-config python3.4m-config python3.7-config python3d python3.5 python3.7m python3-dbg python3.5-config python3.7m-config python3-dbg-config python3.5-dbg python3.8 python3d-config rosuav at sikorsky:~$ python3 Yes, this is a bit noisy in that it has the -config and -dbg-config tools listed as well, but you can easily see all the variants that are installed. > ~$ find 2>/dev/null ~ -name python -type d |grep "site" > /home/tom/.local/lib/python3.9/site-packages/PyQt5/Qt5/qsci/api/python > /home/tom/.local/lib/python3.8/site-packages/pandas/_libs/src/ujson/python > /home/tom/.local/lib/python3.10/site-packages/PyQt5/Qt5/qsci/api/python Ugh, that's a horribly inefficient way to do it. All you need to do is search $PATH. If tab completion isn't suitable, you could probably use "whereis python3", though it's probably a bit noisy. > Not that this task is much easier to remember on Windows, but it's not > harder. One way: the "py" launcher will tell you: > > py --list > -V:3.10 * Python 3.10 (64-bit) > -V:3.9 Python 3.9 (64-bit) > -V:3.7 Python 3.7 (64-bit) > -V:2.7 > > This is not Linux-bashing, but there's no need for Windows-bashing either. There's no need for Linux-bashing when Linux isn't the problem. :) And Windows wasn't the OP's problem. Nor was Python. The OP moaned about a lack of IDEs, when pretty much every IDE and text editor out there has Python support. We're not here to bash anything. Well, except maybe the popular Unix shell. I'll /bin/bash that every day of the week... ahem. Anyhow. We're here to share tips and help everyone be more productive. ChrisA From hjp-python at hjp.at Mon Dec 19 11:54:51 2022 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 19 Dec 2022 17:54:51 +0100 Subject: Installation hell In-Reply-To: <37be6b3c-fb22-83ad-16d1-25ed8ade3e76@tompassin.net> References: <37be6b3c-fb22-83ad-16d1-25ed8ade3e76@tompassin.net> Message-ID: <20221219165451.eezmne5revu6clrf@hjp.at> On 2022-12-19 10:55:52 -0500, Thomas Passin wrote: > On 12/19/2022 9:59 AM, Weatherby,Gerard wrote: > > Personally, I don?t use Windows and avoid it like the plague. > > Python is easy to install on Linux and Mac. > > That's not been my experience. Windows installers for Python have worked > well for me over many generations of Python releases. I haven't had any problem either despite being only an occasional Windows user. It is however, quite noticable that almost everyone who asks a question about their Python installation on this list is using Windows. I don't think this is just because there are more Windows users than Linux or Mac Users. > It's Linux where I've found difficulties. For example, if your > distro's Python install didn't include tkinter (or even pip), how do > you get it? It's different for different Linux distros. Yes, but most Linux users don't use a dozen different distributions. And if you've used one for a while you generaLLy know their general naming conventions. So just guessing (with a little help from your shell's expansion mechanism) the name will take you a long way. So as a long-time Debian and Ubuntu user I just know that a Python package foo will be packaged as python3-foo while a Perl package of the same name would be packaged as libfoo-perl. Not exactly consistent, but you get used to it. On RedHat (which I've also used for a long time) the naming conventions are a bit different but also easy to find out. > For another example, when you use pip to install a package, it sometimes > suggests that you install a newer version of pip itself. Should you do that? > On Linux, probably not, because the distro will have modified pip so it puts > things in distro-specific places. Yet there is no newer version of pip > available through the distro's package manager. Will anything bad happen if > you don't update pip? Who knows? If I use pip on Linux I almost always install into a virtual environment (rule 1: Don't mess with the package manager). So year, I can install a new version of pip into that virtual environment without affecting anything else. > I have a Linux VM that has several versions of Python3 on it. Python3.8 > came installed with the distro, but for some programs I need Python 3.9+. > If I forget which versions I have, how can I find out? I type python and then ctrl-D. The shell will then show me all commands starting with "python" in my path (your shell may have a different key combination for that, maybe tab-tab). > People say to use which, but that doesn't work - it only reports > "python3". More specifically it will report *where* the exact command you named is installed. So "which python3" might report /usr/bin/python3 or /usr/local/bin/python3 or maybe /opt/python3.9.2/bin/python3 but it will never report the presence of any executable not named "python3" and even if you have several it will only give you one of them. > ~$ find 2>/dev/null ~ -name python -type d |grep "site" > /home/tom/.local/lib/python3.9/site-packages/PyQt5/Qt5/qsci/api/python > /home/tom/.local/lib/python3.8/site-packages/pandas/_libs/src/ujson/python > /home/tom/.local/lib/python3.10/site-packages/PyQt5/Qt5/qsci/api/python > > Not that this task is much easier to remember on Windows, but it's not > harder. One way: the "py" launcher will tell you: > > py --list > -V:3.10 * Python 3.10 (64-bit) > -V:3.9 Python 3.9 (64-bit) > -V:3.7 Python 3.7 (64-bit) > -V:2.7 But that works only for Python. Shell expansion works for any command. If you use Linux, learn how to use your shell (and maybe learn different shells - I personally prefer zsh, but I can also use bash, ksh, tcsh and if necessary even sh). 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 Mon Dec 19 12:06:38 2022 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 19 Dec 2022 12:06:38 -0500 Subject: Installation hell In-Reply-To: References: <37be6b3c-fb22-83ad-16d1-25ed8ade3e76@tompassin.net> Message-ID: <4dec30dc-6598-d9c7-444f-ddbac2565ebd@tompassin.net> On 12/19/2022 11:36 AM, Chris Angelico wrote: > On Tue, 20 Dec 2022 at 03:05, Thomas Passin wrote: >> >> That's not been my experience. Windows installers for Python have >> worked well for me over many generations of Python releases. It's Linux >> where I've found difficulties. For example, if your distro's Python >> install didn't include tkinter (or even pip), how do you get it? It's >> different for different Linux distros. I generally have to use internet >> searches to find out. > > If you want to use your distro's Python and add more stuff to it > globally, then yes, it depends on your distro. This is not really a > surprise. > >> For another example, when you use pip to install a package, it sometimes >> suggests that you install a newer version of pip itself. Should you do >> that? On Linux, probably not, because the distro will have modified pip >> so it puts things in distro-specific places. Yet there is no newer >> version of pip available through the distro's package manager. Will >> anything bad happen if you don't update pip? Who knows? > > Virtual environments work the same way regardless of distro, including > allowing you to install an upgraded pip. I have always disliked working with venvs and avoid it whenever possible. But I suppose that's just me. > As long as your distro > provides the venv package (on Debian, that's in python3-venv), you can > just: > > $ python3 -m venv env > $ source env/bin/activate > $ pip install -U pip > $ pip install -r requirements.txt > $ pip install some-package-name > $ etc etc etc etc etc > > This is also a recommended way to do things on Windows, so you don't > even need to do things differently. > >> I have a Linux VM that has several versions of Python3 on it. Python3.8 >> came installed with the distro, but for some programs I need Python >> 3.9+. If I forget which versions I have, how can I find out? People >> say to use which, but that doesn't work - it only reports "python3". >> This does work, but it's not all that easy to remember (the grep "site" >> part is just to filter out uninformative result lines): > > Use what your shell already offers you! If you have multiple Pythons > installed, type "python3" and hit tab twice. You should get a list of > options. The exact shell you're using will affect how they're shown, > but I'm pretty sure most shells (at least, the ones designed to be > interactive - /bin/dash might not) will give you some facility like > this. Ah, that's nice. Though it didn't report python3.10 on the VM I mentioned earlier. > > rosuav at sikorsky:~$ python3 > python3 python3.5-dbg-config python3.8-config > python3.10 python3.5dm python3.8m > python3.10-config python3.5dm-config python3.8m-config > python3.11 python3.5m python3.9 > python3.11-config python3.5m-config python3.9-config > python3.12 python3.6 python3.9d > python3.12-config python3.6-config python3.9-dbg > python3.4 python3.6m python3.9-dbg-config > python3.4-config python3.6m-config python3.9d-config > python3.4m python3.7 python3-config > python3.4m-config python3.7-config python3d > python3.5 python3.7m python3-dbg > python3.5-config python3.7m-config python3-dbg-config > python3.5-dbg python3.8 python3d-config > rosuav at sikorsky:~$ python3 > > Yes, this is a bit noisy in that it has the -config and -dbg-config > tools listed as well, but you can easily see all the variants that are > installed. > >> ~$ find 2>/dev/null ~ -name python -type d |grep "site" >> /home/tom/.local/lib/python3.9/site-packages/PyQt5/Qt5/qsci/api/python >> /home/tom/.local/lib/python3.8/site-packages/pandas/_libs/src/ujson/python >> /home/tom/.local/lib/python3.10/site-packages/PyQt5/Qt5/qsci/api/python > > Ugh, that's a horribly inefficient way to do it. All you need to do is > search $PATH. If tab completion isn't suitable, you could probably use > "whereis python3", though it's probably a bit noisy. Sure is! >> Not that this task is much easier to remember on Windows, but it's not >> harder. One way: the "py" launcher will tell you: >> >> py --list >> -V:3.10 * Python 3.10 (64-bit) >> -V:3.9 Python 3.9 (64-bit) >> -V:3.7 Python 3.7 (64-bit) >> -V:2.7 >> >> This is not Linux-bashing, but there's no need for Windows-bashing either. > > There's no need for Linux-bashing when Linux isn't the problem. :) > > And Windows wasn't the OP's problem. Nor was Python. The OP moaned > about a lack of IDEs, when pretty much every IDE and text editor out > there has Python support. Yes, the OP's rant didn't make much sense to me, especially since it didn't line up with my experience at all. > We're not here to bash anything. Well, except maybe the popular Unix > shell. I'll /bin/bash that every day of the week... ahem. Anyhow. > We're here to share tips and help everyone be more productive. > > ChrisA From rosuav at gmail.com Mon Dec 19 12:15:07 2022 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Dec 2022 04:15:07 +1100 Subject: Installation hell In-Reply-To: <20221219165451.eezmne5revu6clrf@hjp.at> References: <37be6b3c-fb22-83ad-16d1-25ed8ade3e76@tompassin.net> <20221219165451.eezmne5revu6clrf@hjp.at> Message-ID: On Tue, 20 Dec 2022 at 03:56, Peter J. Holzer wrote: > > It is however, quite noticable that almost everyone who asks a question > about their Python installation on this list is using Windows. I don't > think this is just because there are more Windows users than Linux or > Mac Users. Yes. I think there are a few reasons for that. One is that there are many many lazy people in the world, and those people are likely to (a) use the OS that came with their computers - usually Windows or Mac OS; and (b) ask a question on a mailing list rather than spend some extra minutes figuring things out with some web searches. An unrelated cause might be a large number of student and/or novice programmers, who simply don't have the groundwork knowledge to figure these things out; and, again, they'll be using whatever OS their systems come with. Why don't we see more Mac questions, then? No idea, and I'm not a Mac person so I can't judge, but I would guess it's just a matter of numbers - Windows outnumbers Mac OS (not counting iOS, which people don't tend to be installing Python on) by a fairly significant factor. > > I have a Linux VM that has several versions of Python3 on it. Python3.8 > > came installed with the distro, but for some programs I need Python 3.9+. > > If I forget which versions I have, how can I find out? > > I type python and then ctrl-D. The shell will then show me all commands > starting with "python" in my path (your shell may have a different key > combination for that, maybe tab-tab). Ah, interesting. When I mentioned tab-tab I was aware that there are others, but I'm not familiar with Ctrl-D. Normally that means "send the command as it is", so I assume your shell is set up to take an unfinished command and tab-complete it. Which shell is that? (Also - what happens if you Ctrl-D in the middle of a line? Does that work?) > But that works only for Python. Shell expansion works for any command. > If you use Linux, learn how to use your shell (and maybe learn different > shells - I personally prefer zsh, but I can also use bash, ksh, tcsh and > if necessary even sh). I agree, although I wouldn't recommend trying to get too much out of sh as an interactive shell. It's best aimed at low-overhead script running, and configured accordingly. Though it's sometimes good to have some familiarity with a low-powered shell and the most basic of input methods, just in case you're ever thrust into a situation where a hard drive has crashed, /bin/bash is corrupted, you don't have convenient access to external boot media, and you just want to get the network interface up so you can do some basic fixes or data recovery... (Never been in precisely that situation, but I have had other key programs unavailable for various reasons, and it's handy to know alternatives!) ChrisA From rosuav at gmail.com Mon Dec 19 12:24:46 2022 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Dec 2022 04:24:46 +1100 Subject: Installation hell In-Reply-To: <4dec30dc-6598-d9c7-444f-ddbac2565ebd@tompassin.net> References: <37be6b3c-fb22-83ad-16d1-25ed8ade3e76@tompassin.net> <4dec30dc-6598-d9c7-444f-ddbac2565ebd@tompassin.net> Message-ID: On Tue, 20 Dec 2022 at 04:14, Thomas Passin wrote: > > On 12/19/2022 11:36 AM, Chris Angelico wrote: > > On Tue, 20 Dec 2022 at 03:05, Thomas Passin wrote: > >> > >> That's not been my experience. Windows installers for Python have > >> worked well for me over many generations of Python releases. It's Linux > >> where I've found difficulties. For example, if your distro's Python > >> install didn't include tkinter (or even pip), how do you get it? It's > >> different for different Linux distros. I generally have to use internet > >> searches to find out. > > > > If you want to use your distro's Python and add more stuff to it > > globally, then yes, it depends on your distro. This is not really a > > surprise. > > > >> For another example, when you use pip to install a package, it sometimes > >> suggests that you install a newer version of pip itself. Should you do > >> that? On Linux, probably not, because the distro will have modified pip > >> so it puts things in distro-specific places. Yet there is no newer > >> version of pip available through the distro's package manager. Will > >> anything bad happen if you don't update pip? Who knows? > > > > Virtual environments work the same way regardless of distro, including > > allowing you to install an upgraded pip. > > I have always disliked working with venvs and avoid it whenever > possible. But I suppose that's just me. > That's fine. You don't HAVE to use venvs - and in fact, I only use them for a relatively small number of projects (eg those that get deployed to Heroku - make a venv, match Python version to Heroku's offering, and install packages into it, for maximum consistency). There are a few ways to manage things: 1) Always use your package manager. Don't use pip at all. 2) Install pip from your package manager, but then do user installations (~/.local). 3) Install venv from your package manager, use virtual environments everywhere. 4) Build Python from source, parallel to your system Python. 5) Some combination of the above. As you saw from my tab-tab demo, I have a LOT of Pythons installed, many of them alphas and betas. Right now, my 'python3' command is 3.12, but /usr/bin/python3 is the system Python (3.9.2) and has packages managed by apt/dpkg. So when a system-installed script tries to run, it finds the Python and packages that were curated by the Debian folks; but if I, at the command line, type "python3 somescript.py", I get a newer Python with packages managed by pip. Sometimes I'll install those with "sudo python3 -m pip install X", but mostly without sudo, and they land in ~/.local. (Installing as root is useful when I need other users to be able to run the script - it's a pain to try to install something into the correct low-privilege user.) You have options. There's nothing wrong with picking and choosing according to what's convenient for you. ChrisA From rtm443x at googlemail.com Mon Dec 19 12:28:48 2022 From: rtm443x at googlemail.com (j) Date: Mon, 19 Dec 2022 17:28:48 +0000 Subject: Fwd: Installation hell In-Reply-To: References: Message-ID: I agree. Wasted too much time on last few installs. It got to the point I downloaded python-embedded, unzipped it and set the path manually for my work (needed it as part of a compiler). It ain't good enough. And I like python. jan On 18/12/2022 11:50, Jim Lewis wrote: > I'm an occasional user of Python and have a degree in computer science. > Almost every freaking time I use Python, I go through PSH (Python Setup > Hell). Sometimes a wrong version is installed. Sometimes it's a path issue. > Or exe naming confusion: python, python3, phthon311, etc. Or library > compatibility issues - took an hour to find out that pygame does not work > with the current version of python. Then the kludgy PIP app and using a DOS > box under Windows with command prompts which is ridiculous. God only knows > how many novice users of the language (or even intermediate users) were > lost in the setup process. Why not clean the infrastructure up and make a > modern environment or IDE or something better than it is now. Or at least > good error messages that explain exactly what to do. Even getting this > email to the list took numerous steps. > > -- A frustrated user From list1 at tompassin.net Mon Dec 19 12:55:32 2022 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 19 Dec 2022 12:55:32 -0500 Subject: Fwd: Installation hell In-Reply-To: References: Message-ID: On 12/19/2022 12:28 PM, j via Python-list wrote: > I agree. Wasted too much time on last few installs. > > It got to the point I downloaded python-embedded, unzipped it and set > the path manually for my work (needed it as part of a compiler). I don't set those paths. If you have several different versions installed, who knows which one the path will find first? Probably not the one you want. Without paths to the script files, I need to set them temporarily, navigate to to the right directory first, or create a dedicated batch file, but at least I get the right ones that way. I don't find it to be a problem. > It ain't good enough. And I like python. > > jan > > On 18/12/2022 11:50, Jim Lewis wrote: >> I'm an occasional user of Python and have a degree in computer science. >> Almost every freaking time I use Python, I go through PSH (Python Setup >> Hell). Sometimes a wrong version is installed. Sometimes it's a path >> issue. >> Or exe naming confusion: python, python3, phthon311, etc. Or library >> compatibility issues - took an hour to find out that pygame does not work >> with the current version of python. Then the kludgy PIP app and using >> a DOS >> box under Windows with command prompts which is ridiculous. God only >> knows >> how many novice users of the language (or even intermediate users) were >> lost in the setup process. Why not clean the infrastructure up and make a >> modern environment or IDE or something better than it is now. Or at least >> good error messages that explain exactly what to do. Even getting this >> email to the list took numerous steps. >> >> -- A frustrated user From __peter__ at web.de Mon Dec 19 12:42:43 2022 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Dec 2022 18:42:43 +0100 Subject: Keeping a list of records with named fields that can be updated In-Reply-To: References: <9158537c-f561-e666-f60c-34d50f61d7b7@web.de> Message-ID: <1b77a861-8855-f327-1c44-35af4e12879e@web.de> On 17/12/2022 20:45, Albert-Jan Roskam wrote: > On Dec 15, 2022 10:21, Peter Otten <__peter__ at web.de> wrote: > > >>> from collections import namedtuple > >>> Row = namedtuple("Row", "foo bar baz") > >>> row = Row(1, 2, 3) > >>> row._replace(bar=42) > Row(foo=1, bar=42, baz=3) > > ==== > Ahh, I always thought these are undocumented methods, but: "In addition to > the methods inherited from tuples, named tuples support three additional > methods and two attributes. To prevent conflicts with field names, the > method and attribute names start with an underscore." > https://docs.python.org/3/library/collections.html#collections.somenamedtuple._make I've read somewhere that Raymond Hettinger regrets the naming and now would favour a trailing underscore to avoid name conflicts. From hjp-python at hjp.at Mon Dec 19 13:14:47 2022 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 19 Dec 2022 19:14:47 +0100 Subject: Installation hell In-Reply-To: References: <37be6b3c-fb22-83ad-16d1-25ed8ade3e76@tompassin.net> <20221219165451.eezmne5revu6clrf@hjp.at> Message-ID: <20221219181447.i3v5cu5r245h6j2o@hjp.at> On 2022-12-20 04:15:07 +1100, Chris Angelico wrote: > On Tue, 20 Dec 2022 at 03:56, Peter J. Holzer wrote: > > It is however, quite noticable that almost everyone who asks a question > > about their Python installation on this list is using Windows. I don't > > think this is just because there are more Windows users than Linux or > > Mac Users. > > Yes. I think there are a few reasons for that. One is that there are > many many lazy people in the world, and those people are likely to (a) > use the OS that came with their computers - usually Windows or Mac OS; Yeah. But also on Linux you never have to set up Python. It's just there, ready for use (a few years ago, when Python2 way still the default, you might have had to "apt install python3"[1] but that's it). So the lazy Linux users never run into these problems. > > > I have a Linux VM that has several versions of Python3 on it. Python3.8 > > > came installed with the distro, but for some programs I need Python 3.9+. > > > If I forget which versions I have, how can I find out? > > > > I type python and then ctrl-D. The shell will then show me all commands > > starting with "python" in my path (your shell may have a different key > > combination for that, maybe tab-tab). > > Ah, interesting. When I mentioned tab-tab I was aware that there are > others, but I'm not familiar with Ctrl-D. Normally that means "send > the command as it is", It means that only in cooked mode. Since an interactive shell has to switch the terminal into cbreak or even raw mode anyway, it can mean whatever the the shell wants it to mean. > so I assume your shell is set up to take an unfinished command and > tab-complete it. Which shell is that? zsh (with vi keybindings, although I think ctrl-D works the same with emacs keybindings). > (Also - what happens if you Ctrl-D in the middle of a line? Does that work?) Yes. For example if I type "ls foo", dann move the cursor back after "ls" and type " --co^D", I get: % ls --co foo --color -- control use of color --context -- print any security context of each file If I then type tab, it cycles through the options. If I select --color= and type ^D again, I get % ls --color= foo always auto never Etc. Debian/Ubuntu contains a ton of predefined expansions for zsh. Many of them are very context specific and invoke other commands to figure out the actual options (I guess that it actually invokes ls --help to find the options of help, and for psql it definitely checks which users or databases a local postgres installation has to provide you with sensible options at the appropriate position in the command line. There's also remote filename expansion for scp and rsync, etc.) > > But that works only for Python. Shell expansion works for any command. > > If you use Linux, learn how to use your shell (and maybe learn different > > shells - I personally prefer zsh, but I can also use bash, ksh, tcsh and > > if necessary even sh). > > I agree, although I wouldn't recommend trying to get too much out of > sh as an interactive shell. Yeah. If I happen to login to an account which has /bin/sh as the login shell I'll invoke a different shell if I have to type more than 3 or 4 commands (and there is an alernative installed on the machine, which these days is usually the case). But when I started to use Unix, the Bourne shell was all there was. If you were lucky, there might have been a csh, too, but that didn't use cursor keys either. At least it had a history and you could use ! escapes to access it (I still use those in zsh and bash). hp [1] Or use yum or zypper or whatever, or your GUI package manager if that's your thing. -- _ | 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 salmodovar at ligumu.com Sat Dec 17 19:40:34 2022 From: salmodovar at ligumu.com (=?UTF-8?Q?Sabrina_Almod=c3=b3var?=) Date: Sat, 17 Dec 2022 21:40:34 -0300 Subject: String to Float, without introducing errors References: <5BF45E45-9112-4680-9692-15AE936A56A3@paulstgeorge.com> <512a2101-ea59-29aa-753a-eafe0655fc32@yahoo.co.uk> <2C24114F-7CA3-4AE0-B76F-988B33517F93@paulstgeorge.com> <639e32de.020a0220.7add7.2f5b@mx.google.com> Message-ID: On 17/12/2022 18:55, Stefan Ram wrote: > Grant Edwards writes: >> Yes, fixed point (or decimal) is a better fit for what he's doing. but >> I suspect that floating point would be a better fit for the problem >> he's trying to solve. > > I'd like to predict that within the next ten posts in this > thread someone will mention "What Every Computer Scientist > Should Know About Floating-Point Arithmetic". Lol! Speaking of which, let us guide ourselves by https://floating-point-gui.de/basic/ and learn that calculations such as ``0.1 + 0.4 work correctly.'' That's the Internet. You learn a thing on a Tuesday, and on a Wednesday you're a teacher. That's why we need peer review. From greg.ewing at canterbury.ac.nz Sun Dec 18 19:10:16 2022 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 19 Dec 2022 13:10:16 +1300 Subject: String to Float, without introducing errors In-Reply-To: References: <1de4633b-b6c4-14af-7463-8a57527cf0be@tompassin.net> Message-ID: On 19/12/22 9:24 am, Stefan Ram wrote: > So what's the time until a mass of one gram > arrives at the ground versus a mass of ten grams? I think > one needs "Decimal" to calculate this! Or you can be smarter about how you calculate it. Differentiating t with respect to m gives dt/dm = -0.5 * sqrt(2 * s * r**2 / (G * (M + m)**3)) which, since m is much smaller than M, is approximately -0.5 * sqrt(2 * s * r**2 / (G * M**3)) So >>> G = 6.6743015E-11 >>> r = 6.371E6 >>> M = 5.9722E24 >>> dtdm = -0.5 * sqrt(2*s*(r**2) / (G * M**3)) >>> dtdm * (1/1000 - 10/1000) 3.4004053539917275e-28 which agrees with your Decimal calculation to 3 digits, and should be as precise as the input numbers (about 4 digits in this case). This is a good example of why it's important to choose an appropriate numerical algorithm! -- Greg From michael.stemper at gmail.com Mon Dec 19 12:29:24 2022 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Mon, 19 Dec 2022 11:29:24 -0600 Subject: String to Float, without introducing errors In-Reply-To: References: <1de4633b-b6c4-14af-7463-8a57527cf0be@tompassin.net> <20221219141052.frflz6y2n6md7uvj@hjp.at> Message-ID: On 19/12/2022 09.14, MRAB wrote: > On 2022-12-19 14:10, Peter J. Holzer wrote: >> On 2022-12-19 09:25:17 +1100, Chris Angelico wrote: >>> On Mon, 19 Dec 2022 at 07:57, Stefan Ram wrote: >>> > G = Decimal( 6.6743015E-11 ) >>> > r = Decimal( 6.371E6 ) >>> > M = Decimal( 5.9722E24 ) >>> >>> What's the point of using Decimal if you start with nothing more than >>> float accuracy? >> >> Right. He also interpreted the notation "6.67430(15)E-11" wrong. The >> digits in parentheses represent the uncertainty in the same number of >> last digits. So "6.67430(15)E-11" means "something between 6.67430E-11 - >> 0.00015E-11 and 6.67430E-11 + 0.00015E-11". The r value has only a >> precision of 1 km and I'm not sure how accurate the mass is. Let's just >> assume (for the sake of the argument) that these are actually accurate in >> all given digits. ntal misunderstanding of the numbers they are working with. >> > To be fair, I don't think I've never seen that notation either! I've only ever seen the form 6.67430E-11 ? 0.00015E-11, which is much clearer. See, for instance: In particular, the "concise form". For more detail, see: -- Michael F. Stemper Isaiah 58:6-7 From __peter__ at web.de Mon Dec 19 13:29:20 2022 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Dec 2022 19:29:20 +0100 Subject: Keeping a list of records with named fields that can be updated In-Reply-To: References: <6gip6j-698.ln1@anthive.com> <9158537c-f561-e666-f60c-34d50f61d7b7@web.de> Message-ID: <2ede4582-0bd9-fec3-421d-24239e2eb144@web.de> On 18/12/2022 16:44, songbird wrote: > Peter Otten wrote: > ... >> While I think what you need is a database instead of the collection of >> csv files the way to alter namedtuples is to create a new one: >> >>>>> from collections import namedtuple >>>>> Row = namedtuple("Row", "foo bar baz") >>>>> row = Row(1, 2, 3) >>>>> row._replace(bar=42) >> Row(foo=1, bar=42, baz=3) > > namedtuple is easier to use as that will use the csv and > csvreader and create the records without me having to do any > conversion or direct handling myself. it's all automagically > done. my initial version works, but i'd like it to be a bit > more elegant and handle descriptions it hasn't seen before > in a more robust manner. > > >> An alternative would be dataclasses where basic usage is just as easy: >> >>>>> from dataclasses import make_dataclass >>>>> Row = make_dataclass("Row", "foo bar baz".split()) >>>>> row = Row(1, 2, 3) >>>>> row >> Row(foo=1, bar=2, baz=3) >>>>> row.bar = 42 >>>>> row >> Row(foo=1, bar=42, baz=3) > > i do like that i can directly reference each field in a > dataclass and not have to specify a _replace for each change. > > is there an easy way to convert from namedtuple to dataclass? > i can see there is a _asdict converter, but don't really like > how that turns out as then i have to do a bunch of: > rec['fieldname'] = blah > > rec.fieldname is much easier to understand. I recommend that you use a dataclass /instead/ of a namedtuple, not both. However, for a dataclass with the same fields in the same order as in your namedtuple the conversion is trivial: Create compatible namedtuple and dataclass types: >>> NTRow = namedtuple("NTRow", ["alpha", "beta", "gamma"]) >>> DCRow = make_dataclass("DCRow", NTRow._fields) Build the namedtuple: >>> ntrow = NTRow(1, "two", 3.0) >>> ntrow NTRow(alpha=1, beta='two', gamma=3.0) Convert to dataclass: >>> dcrow = DCRow(*ntrow) >>> dcrow DCRow(alpha=1, beta='two', gamma=3.0) From nospam at dfs.com Mon Dec 19 13:57:41 2022 From: nospam at dfs.com (DFS) Date: Mon, 19 Dec 2022 13:57:41 -0500 Subject: Fwd: Installation hell In-Reply-To: References: Message-ID: On 12/18/2022 6:50 AM, Jim Lewis wrote: > I'm an occasional user of Python and have a degree in computer science. > Almost every freaking time I use Python, I go through PSH (Python Setup > Hell). Sometimes a wrong version is installed. Sometimes it's a path issue. > Or exe naming confusion: python, python3, phthon311, etc. Or library > compatibility issues - took an hour to find out that pygame does not work > with the current version of python. Then the kludgy PIP app and using a DOS > box under Windows with command prompts which is ridiculous. God only knows > how many novice users of the language (or even intermediate users) were > lost in the setup process. Why not clean the infrastructure up and make a > modern environment or IDE or something better than it is now. Or at least > good error messages that explain exactly what to do. Even getting this > email to the list took numerous steps. > > -- A frustrated user Issues installing python and sending an email? Ask for a refund on your compsci degree. From angel.gutierrez.rodriguez at gmail.com Mon Dec 19 13:58:11 2022 From: angel.gutierrez.rodriguez at gmail.com (=?UTF-8?B?w4FuZ2VsIEdS?=) Date: Mon, 19 Dec 2022 19:58:11 +0100 Subject: String to Float, without introducing errors References: <1de4633b-b6c4-14af-7463-8a57527cf0be@tompassin.net> <20221219141052.frflz6y2n6md7uvj@hjp.at> Message-ID: On 2022-12-19 16:14, MRAB wrote: > To be fair, I don't think I've never seen that notation either! I've > only ever seen the form 6.67430E-11 ? 0.00015E-11, which is much clearer. We use it regularly in our experimental data: 6.3(4), 15.002(10). Things would become complex using exponential forms for errors, specially when starting to play with exponents: 6.67430E-11 ? 1.5E-15. -- ?ngel GR From songbird at anthive.com Mon Dec 19 14:22:34 2022 From: songbird at anthive.com (songbird) Date: Mon, 19 Dec 2022 14:22:34 -0500 Subject: Keeping a list of records with named fields that can be updated References: <6gip6j-698.ln1@anthive.com> <9158537c-f561-e666-f60c-34d50f61d7b7@web.de> <2ede4582-0bd9-fec3-421d-24239e2eb144@web.de> Message-ID: Peter Otten wrote: ... > I recommend that you use a dataclass /instead/ of a namedtuple, not > both. However, for a dataclass with the same fields in the same order as > in your namedtuple the conversion is trivial: > > Create compatible namedtuple and dataclass types: > > >>> NTRow = namedtuple("NTRow", ["alpha", "beta", "gamma"]) > >>> DCRow = make_dataclass("DCRow", NTRow._fields) > > Build the namedtuple: > > >>> ntrow = NTRow(1, "two", 3.0) > >>> ntrow > NTRow(alpha=1, beta='two', gamma=3.0) > > Convert to dataclass: > > >>> dcrow = DCRow(*ntrow) > >>> dcrow > DCRow(alpha=1, beta='two', gamma=3.0) thanks, once i get the data in from the file i only have to reference it, but for the rest of the code i can use the dataclass instead and that will be easier to read than dicts. :) your help is appreciated. :) songbird From jschwar at sbcglobal.net Mon Dec 19 15:34:42 2022 From: jschwar at sbcglobal.net (Jim Schwartz) Date: Mon, 19 Dec 2022 14:34:42 -0600 Subject: Fwd: Installation hell In-Reply-To: References: Message-ID: <003a01d913e9$53feb750$fbfc25f0$@sbcglobal.net> This type of response is not called for. I thought this list was designed to help people. That's not what this person was doing. Everyone has different experience levels and backgrounds. Help them learn. Don't berate them. Here's what was said: Issues installing python and sending an email? Ask for a refund on your compsci degree. -----Original Message----- From: Python-list On Behalf Of DFS Sent: Monday, December 19, 2022 12:58 PM To: python-list at python.org Subject: Re: Fwd: Installation hell On 12/18/2022 6:50 AM, Jim Lewis wrote: > I'm an occasional user of Python and have a degree in computer science. > Almost every freaking time I use Python, I go through PSH (Python > Setup Hell). Sometimes a wrong version is installed. Sometimes it's a path issue. > Or exe naming confusion: python, python3, phthon311, etc. Or library > compatibility issues - took an hour to find out that pygame does not > work with the current version of python. Then the kludgy PIP app and > using a DOS box under Windows with command prompts which is > ridiculous. God only knows how many novice users of the language (or > even intermediate users) were lost in the setup process. Why not clean > the infrastructure up and make a modern environment or IDE or > something better than it is now. Or at least good error messages that > explain exactly what to do. Even getting this email to the list took numerous steps. > > -- A frustrated user Issues installing python and sending an email? Ask for a refund on your compsci degree. -- https://mail.python.org/mailman/listinfo/python-list From rtm443x at googlemail.com Mon Dec 19 15:34:54 2022 From: rtm443x at googlemail.com (j) Date: Mon, 19 Dec 2022 20:34:54 +0000 Subject: Fwd: Installation hell In-Reply-To: References: Message-ID: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> I was unclear. I use the full path to the folder with the unzipped python-embedded. I shouldn't have said 'set'. I have complained on here before about broken installs but got indifference. An installer should install stuff correctly (leaving a working environment). If it won't then give clear instructions on how to install manually then let us do it. A broken installer is like a road that just runs out. Dismissals about 'lazy people' (for example) aren't helpful if you are trying to get some actual work done. jan On 19/12/2022 17:55, Thomas Passin wrote: > On 12/19/2022 12:28 PM, j via Python-list wrote: >> I agree. Wasted too much time on last few installs. >> >> It got to the point I downloaded python-embedded, unzipped it and set >> the path manually for my work (needed it as part of a compiler). > > I don't set those paths.? If you have several different versions > installed, who knows which one the path will find first?? Probably not > the one you want.? Without paths to the script files, I need to set > them temporarily, navigate to to the right directory first, or create > a dedicated batch file, but at least I get the right ones that way. > > I don't find it to be a problem. > >> It ain't good enough. And I like python. >> >> jan >> >> On 18/12/2022 11:50, Jim Lewis wrote: >>> I'm an occasional user of Python and have a degree in computer science. >>> Almost every freaking time I use Python, I go through PSH (Python Setup >>> Hell). Sometimes a wrong version is installed. Sometimes it's a path >>> issue. >>> Or exe naming confusion: python, python3, phthon311, etc. Or library >>> compatibility issues - took an hour to find out that pygame does not >>> work >>> with the current version of python. Then the kludgy PIP app and >>> using a DOS >>> box under Windows with command prompts which is ridiculous. God only >>> knows >>> how many novice users of the language (or even intermediate users) were >>> lost in the setup process. Why not clean the infrastructure up and >>> make a >>> modern environment or IDE or something better than it is now. Or at >>> least >>> good error messages that explain exactly what to do. Even getting this >>> email to the list took numerous steps. >>> >>> -- A frustrated user > From mats at wichmann.us Mon Dec 19 15:47:42 2022 From: mats at wichmann.us (Mats Wichmann) Date: Mon, 19 Dec 2022 13:47:42 -0700 Subject: Fwd: Installation hell In-Reply-To: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> References: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> Message-ID: <10644030-2c9e-8be2-e42d-a80c445f062e@wichmann.us> On 12/19/22 13:34, j via Python-list wrote: > I was unclear. I use the full path to the folder with the unzipped > python-embedded. I shouldn't have said 'set'. > > I have complained on here before about broken installs but got > indifference. An installer should install stuff correctly (leaving a > working environment). If it won't then give clear instructions on how to > install manually then let us do it. A broken installer is like a road > that just runs out. > > Dismissals about 'lazy people' (for example) aren't helpful if you are > trying to get some actual work done. > > jan I don't think there was an intent to be dismissive, just to point out that this list, and the tutor list, and other places *do* get questions from people who haven't tried very much, and don't tell their readers what they've tried, jrather ust go "it's broken, please fix it for me". You can call that lazy or not (I personally would not throw out that term); it does happen. The Python installer has a few specific people working on it, most of us here aren't in a position to make changes to it - complaining here can get sympathy, or not, but probably not action. It does seem to work out for a lot of people, so it's always a bit of a surprise when it doesn't. I'd say you ought to file an issue on it if it's broken for you - not to say you haven't tried that already. From gweatherby at uchc.edu Mon Dec 19 15:51:10 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Mon, 19 Dec 2022 20:51:10 +0000 Subject: Installation hell In-Reply-To: <37be6b3c-fb22-83ad-16d1-25ed8ade3e76@tompassin.net> References: <37be6b3c-fb22-83ad-16d1-25ed8ade3e76@tompassin.net> Message-ID: I was suggesting a possible resource while making it clear I am not Windows savvy. My avoidance of Windows has nothing to do with Python, so there is no need to discuss it here. If I don?t care which Python I?m using, I?ll type python3. If I want3.9, python3.9. python3 -V tells me the default on that system. (It varies across our servers). If a Python package isn?t available in the mainline Ubuntu repository (python3-whatever), I?m creating a virtual environment. It just saves trouble in the long run. I have this in ~/bin to create an environment. I?m slowly moving projects to the pyproject.toml because pip is complaining about the setup.py installs. #!/bin/bash VERS=3.8 #default version VENV=venv #default environment name if [ $# -gt 0 ]; then VERS=$1 fi if [ $# -gt 1 ]; then VENV=$2 fi PYTHON=python$VERS echo $PYTHON $PYTHON -m venv $VENV ./$VENV/bin/pip install -U pip ipython if [ -e requirements.txt ]; then ./$VENV/bin/pip install -r requirements.txt fi if [ -e setup.py ]; then ./$VENV/bin/python setup.py install fi if [ -e pyproject.toml ]; then ./$VENV/bin/pip install -e . fi From: Python-list on behalf of Thomas Passin Date: Monday, December 19, 2022 at 11:05 AM To: python-list at python.org Subject: Re: Installation hell *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** On 12/19/2022 9:59 AM, Weatherby,Gerard wrote: > Personally, I don?t use Windows and avoid it like the plague. Python is easy to install on Linux and Mac. That's not been my experience. Windows installers for Python have worked well for me over many generations of Python releases. It's Linux where I've found difficulties. For example, if your distro's Python install didn't include tkinter (or even pip), how do you get it? It's different for different Linux distros. I generally have to use internet searches to find out. For another example, when you use pip to install a package, it sometimes suggests that you install a newer version of pip itself. Should you do that? On Linux, probably not, because the distro will have modified pip so it puts things in distro-specific places. Yet there is no newer version of pip available through the distro's package manager. Will anything bad happen if you don't update pip? Who knows? I have a Linux VM that has several versions of Python3 on it. Python3.8 came installed with the distro, but for some programs I need Python 3.9+. If I forget which versions I have, how can I find out? People say to use which, but that doesn't work - it only reports "python3". This does work, but it's not all that easy to remember (the grep "site" part is just to filter out uninformative result lines): ~$ find 2>/dev/null ~ -name python -type d |grep "site" /home/tom/.local/lib/python3.9/site-packages/PyQt5/Qt5/qsci/api/python /home/tom/.local/lib/python3.8/site-packages/pandas/_libs/src/ujson/python /home/tom/.local/lib/python3.10/site-packages/PyQt5/Qt5/qsci/api/python Not that this task is much easier to remember on Windows, but it's not harder. One way: the "py" launcher will tell you: py --list -V:3.10 * Python 3.10 (64-bit) -V:3.9 Python 3.9 (64-bit) -V:3.7 Python 3.7 (64-bit) -V:2.7 This is not Linux-bashing, but there's no need for Windows-bashing either. > I?d start here: https://learn.microsoft.com/en-us/visualstudio/python/overview-of-python-tools-for-visual-studio?view=vs-2022 > > From: Python-list on behalf of Jim Lewis > Date: Sunday, December 18, 2022 at 12:56 PM > To: Python-list at python.org > Subject: Fwd: Installation hell > *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** > > I'm an occasional user of Python and have a degree in computer science. > Almost every freaking time I use Python, I go through PSH (Python Setup > Hell). Sometimes a wrong version is installed. Sometimes it's a path issue. > Or exe naming confusion: python, python3, phthon311, etc. Or library > compatibility issues - took an hour to find out that pygame does not work > with the current version of python. Then the kludgy PIP app and using a DOS > box under Windows with command prompts which is ridiculous. God only knows > how many novice users of the language (or even intermediate users) were > lost in the setup process. Why not clean the infrastructure up and make a > modern environment or IDE or something better than it is now. Or at least > good error messages that explain exactly what to do. Even getting this > email to the list took numerous steps. > > -- A frustrated user > -- > https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!gdOs-oC1JZcmvMXy1G4irRpzHCUmF565UXVdCjzSWNGZKpmZ04I_llDX4WUeob3asBCjLe6TIthAAhmwFgbph9u1m9A$ -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!jE6AjIj87dxZUxuKQ6JNejqfM89fMIn9dCawvy3MAsC1Y9K1LVekL9Vxn1dNntu2VNPzdvehOKAEpOjyhEQ$ From nntp.mbourne at spamgourmet.com Mon Dec 19 15:48:49 2022 From: nntp.mbourne at spamgourmet.com (Mark Bourne) Date: Mon, 19 Dec 2022 20:48:49 +0000 Subject: How to enter escape character in a positional string argument from the command line? References: <6b7f0c6d-f745-4745-aa5f-2012ec8ed906n@googlegroups.com> Message-ID: Jach Feng wrote: > I have a script using the argparse module. I want to enter the string "step\x0A" as one of its positional arguments. I expect this string has a length of 5, but it gives 8. Obviously the escape character didn't function correctly. How to do it? That depends on the command-line shell you're calling your script from. In bash, you can include a newline in a quoted string: ./your_script 'step ' (the closing quote is on the next line) Or if you want to do it on a single line (or use other escape sequences), you can use e.g.: ./your_script $'step\x0a' (dollar sign before a single-quoted string which contains escape sequences) -- Mark. From eryksun at gmail.com Mon Dec 19 16:47:30 2022 From: eryksun at gmail.com (Eryk Sun) Date: Mon, 19 Dec 2022 15:47:30 -0600 Subject: Installation hell In-Reply-To: References: Message-ID: On 12/18/22, Jim Lewis wrote: > > Sometimes it's a path issue. For whatever reason, Python installations on Windows lack versioned executable names (except for the Microsoft Store distribution). Thus adding multiple installations to PATH doesn't help unless "python.exe" is manually linked or copied to versioned names, e.g. "python3.11.exe" -> "python.exe" and "python3.exe" -> "python.exe". In this case, the first installation in PATH is the default for running "python" and "python3". Using the "py.exe" launcher is the more general and preferred solution. It allows running any registered Python installation. It's also the installed handler for the ".py" file type, and it supports Unix-style shebangs. > Or exe naming confusion: python, python3, phthon311, etc. I don't understand what's supposedly confusing here. Here are some commands to help discover what "py" or "python" commands and installations are available. * CMD: where py*.exe * PowerShell: get-command py*.exe * Python launcher: py --list-paths > Or library compatibility issues - took an hour to find out that > pygame does not work with the current version of python. It should be a trivial task to discover that wheel packages for pygame aren't currently available for Python 3.11. It is not unreasonable to expect Python developers to familiarize themselves with pip and PyPI. If you search a bit deeper, you'll find a site with unofficial Windows builds of many packages, including pygame for Python 3.11: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame Otherwise, while building some packages from source can be quite involved and difficult, I'd expect anyone with a degree in computer science to be able to build pygame if necessary. They even provide a simple guide: https://www.pygame.org/wiki/CompileWindows > Then the kludgy PIP app and using a DOS box under Windows with > command prompts which is ridiculous. How is pip "kludgy" (i.e. sloppy, hasty, shoddy, or inelegant)? How is using a command-line interface "ridiculous"? Many programmers and system administrators actually prefer using command-line interfaces and text user interfaces (TUI) for many if not most development and administration tasks. It's a matter of opinion. --- Nerdy operating system discussion... > using a DOS box under Windows The term "DOS box" refers to a virtual machine running 16-bit MS-DOS in virtual 8086 (v86) mode under Windows 3.1 or Windows 9x, with the MS-DOS keyboard and display drivers hooked to redirect I/O to a desktop window. There is no "DOS box" in Windows NT systems. Windows client systems switched to NT starting with Windows XP. Thus the term "DOS box" is about two decades out of date. Also, "DOS" is not synonymous with a command-line interface shell (e.g. the 16-bit MS-DOS shell, "COMMAND.COM"). A "Disk Operating System" is one that supports disk drives and filesystems, which includes most operating systems from the late 1960s onward (e.g. DOS/360 from 1966). There were several DOS systems for personal computers in the 1980s, such as Apple ProDOS, Atari DOS, Tandy TRSDOS, Commodore DOS, and Microsoft MS-DOS. A DOS system can use a graphical shell, such as running Windows 1.0 (1985) on MS-DOS. The "python.exe" executable is a Windows application that's flagged to require a console session. If it doesn't inherit a console session, then the system allocates one automatically. However, any Windows application can allocate, attach to, and detach from a console session via AllocConsole(), AttachConsole(), and FreeConsole(). Prior to Windows 7, each console session in the current NT session is hosted on threads in the subsystem process for Windows, "csrss.exe". Starting with Windows 7, console sessions are hosted by instances of "conhost.exe". The console host also implements a builtin terminal window for command-line interface (CLI) and text user interface (TUI) applications. (A console session can be allocated without a terminal window if a console application is spawned with the creation flag CREATE_NO_WINDOW.) Prior to Windows 10, the connection between a console session and its terminal is hardwired in the console host. This makes it difficult to implement an alternate terminal, though some alternate terminals have managed to do so in creative ways (e.g. ConEmu). Starting with Windows 10, alternate terminals can use an open source implementation of the console host, named "openconsole.exe". The most important example is Microsoft's "Windows Terminal". Starting with Windows 11, an alternate terminal can also register as the default terminal for console applications. For example, if Windows Terminal is set as the default terminal, then running "python.exe" from Explorer opens a new tab in Terminal. From list1 at tompassin.net Mon Dec 19 16:54:18 2022 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 19 Dec 2022 16:54:18 -0500 Subject: Fwd: Installation hell In-Reply-To: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> References: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> Message-ID: <9a5c8d2c-7be3-d9c0-0e22-b16fdcbc955f@tompassin.net> On 12/19/2022 3:34 PM, j wrote: > I was unclear. I use the full path to the folder with the unzipped > python-embedded. I shouldn't have said 'set'. > > I have complained on here before about broken installs but got > indifference. An installer should install stuff correctly (leaving a > working environment). If it won't then give clear instructions on how to > install manually then let us do it. A broken installer is like a road > that just runs out. Yes, I've had a few of those, just not with Python so far. One problem with a list like this is that if other people don't have the problem or can't make it happen, then they don't have any suggestions based on personal experience. So they can't be helpful. In this issue, I'm in that category. In that situation, we (the list-people, I mean) need good information to have a chance of being helpful. But I've observed that many requestors for help like this - especially installation issues - don't provide any useful particulars. That makes it seem like they don't understand what they are doing, and folks would like them to do their homework and think about what it would take for other people to have a chance of helping. Would you try to cook a meal, and then say "I followed the recipe and it didn't work, please help"? It's impossible. But I've seen this kind of question over and over on this list. I did once have a Python installation problem. The installed Python executable worked, but later I ran into some permissions problem. I had installed for "everyone", so it installed into Program Files, and apparently somewhere along the way I had done something odd to the permissions for that directory. I was never sure what. I uninstalled, and since then I have always installed new versions for just one user (me). Never a problem since. I'm sorry to say that I have never tried an embedded install, and I don't know what's different about one. Maybe I'll try one now, just to know. > Dismissals about 'lazy people' (for example) aren't helpful if you are > trying to get some actual work done. Yes, that's true. Lack of clear information isn't helpful, either. Well this is getting too long, and not directly helping with any of your problems. I hope it may be informative for others who want to ask for help. To be able to help someone, I have to understand just what they were trying to do, what they did, what happened that caused them to think their efforts failed, and what error messages the system emitted. That may not be enough either, but it's a required starting point. Without this kind of information, people who want to help feel frustrated. > jan > > > On 19/12/2022 17:55, Thomas Passin wrote: >> On 12/19/2022 12:28 PM, j via Python-list wrote: >>> I agree. Wasted too much time on last few installs. >>> >>> It got to the point I downloaded python-embedded, unzipped it and set >>> the path manually for my work (needed it as part of a compiler). >> >> I don't set those paths.? If you have several different versions >> installed, who knows which one the path will find first?? Probably not >> the one you want.? Without paths to the script files, I need to set >> them temporarily, navigate to to the right directory first, or create >> a dedicated batch file, but at least I get the right ones that way. >> >> I don't find it to be a problem. >> >>> It ain't good enough. And I like python. >>> >>> jan >>> >>> On 18/12/2022 11:50, Jim Lewis wrote: >>>> I'm an occasional user of Python and have a degree in computer science. >>>> Almost every freaking time I use Python, I go through PSH (Python Setup >>>> Hell). Sometimes a wrong version is installed. Sometimes it's a path >>>> issue. >>>> Or exe naming confusion: python, python3, phthon311, etc. Or library >>>> compatibility issues - took an hour to find out that pygame does not >>>> work >>>> with the current version of python. Then the kludgy PIP app and >>>> using a DOS >>>> box under Windows with command prompts which is ridiculous. God only >>>> knows >>>> how many novice users of the language (or even intermediate users) were >>>> lost in the setup process. Why not clean the infrastructure up and >>>> make a >>>> modern environment or IDE or something better than it is now. Or at >>>> least >>>> good error messages that explain exactly what to do. Even getting this >>>> email to the list took numerous steps. >>>> >>>> -- A frustrated user >> From list1 at tompassin.net Mon Dec 19 17:01:28 2022 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 19 Dec 2022 17:01:28 -0500 Subject: Fwd: Installation hell In-Reply-To: <9a5c8d2c-7be3-d9c0-0e22-b16fdcbc955f@tompassin.net> References: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> <9a5c8d2c-7be3-d9c0-0e22-b16fdcbc955f@tompassin.net> Message-ID: <657c8d6c-fac2-9973-fdce-7b1515aa0a23@tompassin.net> On 12/19/2022 4:54 PM, Thomas Passin wrote: > On 12/19/2022 3:34 PM, j wrote: >> I was unclear. I use the full path to the folder with the unzipped >> python-embedded. I shouldn't have said 'set'. >> >> I have complained on here before about broken installs but got >> indifference. An installer should install stuff correctly (leaving a >> working environment). If it won't then give clear instructions on how >> to install manually then let us do it. A broken installer is like a >> road that just runs out. > > Yes, I've had a few of those, just not with Python so far.? One problem > with a list like this is that if other people don't have the problem or > can't make it happen, then they don't have any suggestions based on > personal experience.? So they can't be helpful.? In this issue, I'm in > that category. > > In that situation, we (the list-people, I mean) need good information to > have a chance of being helpful.? But I've observed that many requestors > for help like this - especially installation issues - don't provide any > useful particulars.? That makes it seem like they don't understand what > they are doing, and folks would like them to do their homework and think > about what it would take for other people to have a chance of helping. > > Would you try to cook a meal, and then say "I followed the recipe and it > didn't work, please help"?? It's impossible.? But I've seen this kind of > question over and over on this list. > > I did once have a Python installation problem.? The installed Python > executable worked, but later I ran into some permissions problem.? I had > installed for "everyone", so it installed into Program Files, and > apparently somewhere along the way I had done something odd to the > permissions for that directory.? I was never sure what.? I uninstalled, > and since then I have always installed new versions for just one user > (me). Never a problem since. > > I'm sorry to say that I have never tried an embedded install, and I > don't know what's different about one.? Maybe I'll try one now, just to > know. FWIW, I once set up a Python installation so that it could run from a USB stick (Windows only). My launcher was a batch file that contained the following: @echo off setlocal : Find effective drive for this file. set ed=%~d0 path %ed%\python37\Scripts;%ed%\python37;%PATH% set PYTHONUSERBASE=%ed%\user\python set HOME=%ed%\user\python call python %* endlocal I suppose anyone trying to use an embedded version of Python would have to set up some environmental variables in a similar way. Note that I used the "user" directory on the USB stick as a home directory for the installation. From rosuav at gmail.com Mon Dec 19 17:16:24 2022 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Dec 2022 09:16:24 +1100 Subject: Fwd: Installation hell In-Reply-To: <657c8d6c-fac2-9973-fdce-7b1515aa0a23@tompassin.net> References: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> <9a5c8d2c-7be3-d9c0-0e22-b16fdcbc955f@tompassin.net> <657c8d6c-fac2-9973-fdce-7b1515aa0a23@tompassin.net> Message-ID: On Tue, 20 Dec 2022 at 09:12, Thomas Passin wrote: > FWIW, I once set up a Python installation so that it could run from a > USB stick (Windows only). My launcher was a batch file that contained > the following: > > @echo off > setlocal > : Find effective drive for this file. > set ed=%~d0 > path %ed%\python37\Scripts;%ed%\python37;%PATH% > set PYTHONUSERBASE=%ed%\user\python > set HOME=%ed%\user\python > call python %* > endlocal > So much easier to do on a Unix-like system, where you don't need to concern yourself with "effective drive" and can simply use relative paths. I know we're not here to bash Windows, but... drive letters really need to just die already. ChrisA From mats at wichmann.us Mon Dec 19 17:28:12 2022 From: mats at wichmann.us (Mats Wichmann) Date: Mon, 19 Dec 2022 15:28:12 -0700 Subject: Installation hell In-Reply-To: References: Message-ID: <19527ace-b516-cdb3-8715-0a38aafaaa3a@wichmann.us> On 12/19/22 14:47, Eryk Sun wrote: > If you search a bit deeper, you'll find a site with unofficial Windows > builds of many packages, including pygame for Python 3.11: > > https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame Semi-OT: that's been a superb resource, but apparently it's no longer maintained - internet scuttlebutt suggests the project which let it exist has lost funding. The link above is a mirror, marked "Archived", and I can't see there's been any addition since July 1. (sadly... I happen to need an lxml build for experimenting with 3.12 alphas, and that's an absolute bear to build for WIndows - I've never cracked it) From list1 at tompassin.net Mon Dec 19 17:53:16 2022 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 19 Dec 2022 17:53:16 -0500 Subject: Fwd: Installation hell In-Reply-To: References: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> <9a5c8d2c-7be3-d9c0-0e22-b16fdcbc955f@tompassin.net> <657c8d6c-fac2-9973-fdce-7b1515aa0a23@tompassin.net> Message-ID: <7f169067-a750-1ee2-d341-1089f746b81c@tompassin.net> On 12/19/2022 5:16 PM, Chris Angelico wrote: > On Tue, 20 Dec 2022 at 09:12, Thomas Passin wrote: >> FWIW, I once set up a Python installation so that it could run from a >> USB stick (Windows only). My launcher was a batch file that contained >> the following: >> >> @echo off >> setlocal >> : Find effective drive for this file. >> set ed=%~d0 >> path %ed%\python37\Scripts;%ed%\python37;%PATH% >> set PYTHONUSERBASE=%ed%\user\python >> set HOME=%ed%\user\python >> call python %* >> endlocal >> > > So much easier to do on a Unix-like system, where you don't need to > concern yourself with "effective drive" and can simply use relative > paths. I know we're not here to bash Windows, but... drive letters > really need to just die already. Considering that this was for a removable drive, the launcher needed to know its own location, which might change from one instance to another. If you look at the code above, you won't find an obvious drive letter. You would need to do the equivalent on Linux. The Windows drive letter is just not relevant here. (and I thought we weren't going keep on bashing non-preferred operating systems). From grant.b.edwards at gmail.com Mon Dec 19 18:01:40 2022 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 19 Dec 2022 15:01:40 -0800 (PST) Subject: Fwd: Installation hell References: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> <9a5c8d2c-7be3-d9c0-0e22-b16fdcbc955f@tompassin.net> <657c8d6c-fac2-9973-fdce-7b1515aa0a23@tompassin.net> Message-ID: <63a0ed54.050a0220.9ee4e.5a12@mx.google.com> On 2022-12-19, Chris Angelico wrote: > So much easier to do on a Unix-like system, where you don't need to > concern yourself with "effective drive" and can simply use relative > paths. I know we're not here to bash Windows, but... drive letters > really need to just die already. They needed to "die already" 40 years ago. I was a Unix user before MS-DOS came out, and I was rather stunned by the whole drive letter thing. It seemed like such a giant step backwards. I figured that once hard drives became common, drive letters would die. Nope, they're still failing strong! -- Grant From rosuav at gmail.com Mon Dec 19 18:20:57 2022 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Dec 2022 10:20:57 +1100 Subject: Fwd: Installation hell In-Reply-To: <7f169067-a750-1ee2-d341-1089f746b81c@tompassin.net> References: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> <9a5c8d2c-7be3-d9c0-0e22-b16fdcbc955f@tompassin.net> <657c8d6c-fac2-9973-fdce-7b1515aa0a23@tompassin.net> <7f169067-a750-1ee2-d341-1089f746b81c@tompassin.net> Message-ID: On Tue, 20 Dec 2022 at 10:01, Thomas Passin wrote: > > On 12/19/2022 5:16 PM, Chris Angelico wrote: > > On Tue, 20 Dec 2022 at 09:12, Thomas Passin wrote: > >> FWIW, I once set up a Python installation so that it could run from a > >> USB stick (Windows only). My launcher was a batch file that contained > >> the following: > >> > >> @echo off > >> setlocal > >> : Find effective drive for this file. > >> set ed=%~d0 > >> path %ed%\python37\Scripts;%ed%\python37;%PATH% > >> set PYTHONUSERBASE=%ed%\user\python > >> set HOME=%ed%\user\python > >> call python %* > >> endlocal > >> > > > > So much easier to do on a Unix-like system, where you don't need to > > concern yourself with "effective drive" and can simply use relative > > paths. I know we're not here to bash Windows, but... drive letters > > really need to just die already. > > Considering that this was for a removable drive, the launcher needed to > know its own location, which might change from one instance to another. > If you look at the code above, you won't find an obvious drive letter. > You would need to do the equivalent on Linux. The Windows drive letter > is just not relevant here. The only thing that's relevant is the *path*. Everything can be made relative to a single directory. On Unix-like systems, any relative path can be made absolute with reference to a single directory - most commonly the current working directory, of which there is precisely one. On Windows, there is the current working directory, plus twenty-six ADDITIONAL reference directories, plus a current drive (I'm not certain whether "current working directory" is the same as "current drive + current directory on that drive", so maybe there's one fewer than this). If you create a Python virtual environment without symlinks (eg "python3 -m venv env --copies"), you can run Python scripts using that environment simply by invoking the corresponding Python interpreter, regardless of the actual path. Trivially easy, because it's simply relative paths. On Tue, 20 Dec 2022 at 10:03, Grant Edwards wrote: > > On 2022-12-19, Chris Angelico wrote: > > > So much easier to do on a Unix-like system, where you don't need to > > concern yourself with "effective drive" and can simply use relative > > paths. I know we're not here to bash Windows, but... drive letters > > really need to just die already. > > They needed to "die already" 40 years ago. I was a Unix user before > MS-DOS came out, and I was rather stunned by the whole drive letter > thing. It seemed like such a giant step backwards. I figured that once > hard drives became common, drive letters would die. Nope, they're > still failing strong! They feel like part of an old style of concrete identifiers, like working with direct memory addresses (as opposed to virtual memory pages), until you realise that even MS-DOS had a special hack that let a single physical drive behave as both A: and B: with system-provided prompts "please insert disk for drive A/B" when needed. And with the SUBST and JOIN commands, you could - again, even in MS-DOS - mount directories as drives or drives as directories. (I don't remember what happened if you tried to use both at once to have a directory appear in a different location - the equivalent of a bind mount. Might have worked.) People could have destroyed drive letters by just always turning them into directories, and then comfortably moving to a Unix-like mount system, but since that didn't happen, generations of Windows users have grown up with the expectation that drive letters are a thing. And that leads to myriad problems. Until Steve Dower got involved with the Python installers, there were periodic issues resulting from certain combinations of (a) installing Python somewhere other than the C: drive, (b) using pip from somewhere other than the C: drive to install packages, and (c) attempting to use those packages from somewhere other than C:. I don't remember exactly what the solutions were (I want to say that "use explicit paths" was part of it, but this was a while ago and my memory of other people's problems isn't the greatest), but it was often a mess. Chrsia From miked at dewhirst.com.au Mon Dec 19 20:28:25 2022 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Tue, 20 Dec 2022 12:28:25 +1100 Subject: OT: ~gohlke [Was: Installation hell] In-Reply-To: <19527ace-b516-cdb3-8715-0a38aafaaa3a@wichmann.us> References: <19527ace-b516-cdb3-8715-0a38aafaaa3a@wichmann.us> Message-ID: On 20/12/2022 9:28 am, Mats Wichmann wrote: > On 12/19/22 14:47, Eryk Sun wrote: > >> If you search a bit deeper, you'll find a site with unofficial Windows >> builds of many packages, including pygame for Python 3.11: >> >> https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame > Semi-OT: that's been a superb resource, but apparently it's no longer > maintained - internet scuttlebutt suggests the project which let it > exist has lost funding.? The link above is a mirror, marked > "Archived", and I can't see there's been any addition since July 1. > (sadly... I happen to need an lxml build for experimenting with 3.12 > alphas, and that's an absolute bear to build for WIndows - I've never > cracked it) That is dreadful news! Windows as a dev platform is dead without it. That is serious. Back on topic - Installation hell I use Windows for historic reasons related to needing to support 99% of my customers/dependents who also use it. I'm the only one who also uses Linux - but only non-GUI Linux. Windows works for me as a dev platform because there are so many talented Python people out there who make it work. It would be impossible otherwise. I would be forced to to learn two GUIs if I had to develop on Linux. I'm here to tell you that dev and production on different OSs works without a hitch! For me. Whoever wrote the installation docs for Windows did a great job. All the bases and options are covered. Absolutely no-one could complain that any pertinent detail has been omitted. Some marketing research is indicated. The OP who started this thread could define themself in exquisite detail so that installation infrastructure including documentation can be developed to suit that market exemplar. I think there are several separate markets. Eg., for someone like me ... locked into Windows (but not Microsoft otherwise) and needing to target Linux web servers. That would allow a branching of the installation docs to home in, say, on virtual envs and multiple Python installations in the root of drive C: (well away from "Program files") and so on. If the OP says they are an educated computer scientist they could become a hero and write up a tightly focused set of docs (extracted from the comprehensive canonical docs) which assume their particular "market", for want of a better term. The PSF might recognise the effort and be able to promote such a high interest from Windows Python devs into funding for Chris Gohlke. Cheers Mike -- Signed email is an absolute defence against phishing. This email has been signed with my private key. If you import my public key you can automatically decrypt my signature and be sure it came from me. Just ask and I'll send it to you. Your email software can handle signing. -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 495 bytes Desc: OpenPGP digital signature URL: From jfong at ms4.hinet.net Mon Dec 19 21:24:49 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Mon, 19 Dec 2022 18:24:49 -0800 (PST) Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: References: <6b7f0c6d-f745-4745-aa5f-2012ec8ed906n@googlegroups.com> Message-ID: Mark Bourne ? 2022?12?20? ?????4:49:13 [UTC+8] ?????? > Jach Feng wrote: > > I have a script using the argparse module. I want to enter the string "step\x0A" as one of its positional arguments. I expect this string has a length of 5, but it gives 8. Obviously the escape character didn't function correctly. How to do it? > That depends on the command-line shell you're calling your script from. > > In bash, you can include a newline in a quoted string: > ./your_script 'step > ' > (the closing quote is on the next line) > > Or if you want to do it on a single line (or use other escape > sequences), you can use e.g.: > ./your_script $'step\x0a' > (dollar sign before a single-quoted string which contains escape sequences) > > -- > Mark. That's really good for Linux user! How about Windows? From list1 at tompassin.net Mon Dec 19 22:36:10 2022 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 19 Dec 2022 22:36:10 -0500 Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: References: <6b7f0c6d-f745-4745-aa5f-2012ec8ed906n@googlegroups.com> Message-ID: On 12/19/2022 9:24 PM, Jach Feng wrote: > Mark Bourne ? 2022?12?20? ?????4:49:13 [UTC+8] ?????? >> Jach Feng wrote: >>> I have a script using the argparse module. I want to enter the string "step\x0A" as one of its positional arguments. I expect this string has a length of 5, but it gives 8. Obviously the escape character didn't function correctly. How to do it? >> That depends on the command-line shell you're calling your script from. >> >> In bash, you can include a newline in a quoted string: >> ./your_script 'step >> ' >> (the closing quote is on the next line) >> >> Or if you want to do it on a single line (or use other escape >> sequences), you can use e.g.: >> ./your_script $'step\x0a' >> (dollar sign before a single-quoted string which contains escape sequences) >> >> -- >> Mark. > That's really good for Linux user! How about Windows? One way is to process the argument after it gets into Python rather than before. How hard that will be depends on how general you need the argument to be. For your actual example, the argument comes into Python as if it were arg1 = r"step\x0A" # or "step\\x0a" You can see if there is an "\\x": pos = arg1.find('\\x') # 4 Replace or use a regex to replace it: arg1_fixed = arg1.replace('\\x0A', '\n') Naturally, if "\\x0A" is only a special case and other combinations are possible, you will need to figure out what you need and do some more complicated processing. From eryksun at gmail.com Mon Dec 19 23:35:27 2022 From: eryksun at gmail.com (Eryk Sun) Date: Mon, 19 Dec 2022 22:35:27 -0600 Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: References: <6b7f0c6d-f745-4745-aa5f-2012ec8ed906n@googlegroups.com> Message-ID: On 12/19/22, Jach Feng wrote: > > That's really good for Linux user! How about Windows? In CMD, typing the "^" escape character at the end of a line ignores the newline and prompts for "more" input. If you press enter again, you'll get another "more" prompt in which you can write the rest of the command line. Command-line arguments are separated by spaces, so you have to start the next line with a space if you want it to be a new argument. Also, "^" is a literal character when it's in a double-quoted string, which requires careful use of quotes. For example: C:\>py -c "import sys; print(sys.orig_argv[3:])" spam^ More? More? eggs^ More? More? " and spam" ['spam\n', 'eggs\n and spam'] The above is easier in PowerShell, which supports entering multiline strings without having to escape the newline. The second-level prompt is ">> ". For example: > py -c "import sys; print(sys.orig_argv[3:])" spam" >> " eggs" >> and spam" ['spam\n', 'eggs\n and spam'] From eryksun at gmail.com Tue Dec 20 08:11:00 2022 From: eryksun at gmail.com (Eryk Sun) Date: Tue, 20 Dec 2022 07:11:00 -0600 Subject: Fwd: Installation hell In-Reply-To: References: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> <9a5c8d2c-7be3-d9c0-0e22-b16fdcbc955f@tompassin.net> <657c8d6c-fac2-9973-fdce-7b1515aa0a23@tompassin.net> Message-ID: On 12/19/22, Chris Angelico wrote: > On Tue, 20 Dec 2022 at 09:12, Thomas Passin wrote: > >> @echo off >> setlocal >> : Find effective drive for this file. >> set ed=%~d0 >> path %ed%\python37\Scripts;%ed%\python37;%PATH% For reference, in case not everyone on the list knows what "%~d0" means, the CMD shell supports extracting the drive (d), path (p), name (n), and extension (x) components of a path name that's stored in a parameter such as "%0". The full path (f) is resolved beforehand. For example: C:\Temp>set var=spam\eggs.py C:\Temp>for %c in (%var%) do @echo drive: "%~dc" drive: "C:" C:\Temp>for %c in (%var%) do @echo path: "%~pc" path: "\Temp\spam\" C:\Temp>for %c in (%var%) do @echo name: "%~nc" name: "eggs" C:\Temp>for %c in (%var%) do @echo extension: "%~xc" extension: ".py" C:\Temp>for %c in (%var%) do @echo full path: "%~dpnxc" full path: "C:\Temp\spam\eggs.py" C:\Temp>for %c in (%var%) do @echo full path: "%~fc" full path: "C:\Temp\spam\eggs.py" > So much easier to do on a Unix-like system, where you don't need to > concern yourself with "effective drive" and can simply use relative > paths. A relative path in the PATH environment variable would depend on the current working directory. Surely the added paths need to be absolute. However, Thomas didn't have to reference the drive explicitly. The expression "%~dp0" is the fully-qualified directory of the executing batch script, and an absolute path can reference its ancestor directories using ".." components. > I know we're not here to bash Windows, but... drive letters > really need to just die already. I don't foresee drive-letter names getting phased out of Windows. And Windows itself is unlikely to get phased out as long as Microsoft continues to profit from it, as it has for the past 37 years. The drive concept is deeply ingrained in the design of NT, the Windows API, shells, and applications. While assigning drive names "A:", "B:", and "D:" to "Z:" can be avoided, the system volume, i.e. drive "C:", still has to be accessed in the normal way, or using another one of its persistent names, such as r"\\?\BootPartition". The latter still uses the filesystem mount point on the root path of the device (e.g. "\\\\?\\BootPartition\\"), which you probably take issue with. That's a deeply ingrained aspect of Windows. Even mount points set on filesystem directories are actually bind mount points that ultimately resolve to the root path on the volume device (e.g. "\\Device\\HarddiskVolume4\\"). This differs from how regular mount points work on Unix, for which a path like "/dev/sda1/etc" is gibberish. Below I've outlined the underlying details of how logical drives (e.g. "C:"), UNC shares (e.g. r"\\server\share"), other device names, and filesystem mount points are implemented on NT. --- NT Device Names In contrast to Unix, NT is organized around an object namespace, not a root filesystem. Instances of many object types can be named. Some named object types also support a parse routine for paths in the namespace of an object (e.g. the configuration manager's registry "Key" type and the I/O manager's "Device" type). The object manager uses two object types to define the object namespace: Directory and Symbolic Link. Directory objects form the hierarchical tree. At the base of the tree is the anonymous root directory object (i.e. "\\"). A directory is implemented as a hashmap of named objects. A directory can be set as the shadow of another directory, creating a union directory for name lookups. Unless otherwise stated, the following discussion uses "directory" and "symlink" to refer to a directory object and a symbolic-link object, respectively -- not to a filesystem directory or filesystem symlink. A canonical NT device name (e.g. "C:", "PIPE", "UNC") is implemented in the object namespace as a symlink that targets the path of a real device object. The real device is typically in the r"\Device" directory. A canonical device name might be a persistent name for an enumerated device (e.g. "C:" -> r"\Device\HarddiskVolume2"). In some cases the real device name is persistent, but it's different from the canonical name (e.g. "PIPE" -> r"\Device\NamedPipe", or "UNC" -> r"\Device\Mup"). The symlink that implements a canonical device name is created either in the r"\Global??" directory or in a directory that's used for local device names in a given logon session (e.g. r"\Sessions\0\DosDevices\"). The global device directory generally contains system devices. Mapped drives and substitute drives typically use a local device directory, so users don't have to worry about conflicting drive assignments in these cases. The global device directory is the shadow of each local device directory, forming a union for name lookups. If the same device name is defined in both the local and global directories, the local device name takes precedence. However, each local device directory also contains a symlink named "Global" to explicitly reference the global device directory. In NT 5.1+, the object path r"\??" is implemented as a virtual directory. It always references the local device directory of the current thread's logon session. For example, r"\??\Z:" is probably a mapped drive in the current logon session, while r"\??\C:" is the global "C:" drive, which can be written more explicitly as r"\??\Global\C:". The target of a symlink can be any path, including a directory in a filesystem. The latter is the case for mapped drives (e.g. "Z:" -> r"\Device\Mup\server\share") and substitute drives (e.g. "W:" -> r"\??\C:\Windows"). Note that drive names that target a filesystem directory instead of a device are peculiar. API functions generally special case mapped drives, which target a path on r"\Device\Mup". Substitute drives, on the other hand, may cause some API functions to misbehave, such as GetVolumePathNameW(). The Windows API reserves two UNC path prefixes that translate to the "\\??\\" virtual directory path in NT. The prefix "\\\\?\\" (backslashes only) begins a path that opens literally, and the prefix "\\\\.\\" (any mix of forward slashes and backslashes) begins a path that opens normalized. The normalization of a path replaces forward slashes with backlashes, collapses repeated slashes, resolves "." and ".." components, and strips trailing spaces and dots. For example, "//./C:/spam/foo/..///eggs. . ." opens normalized as the NT path r"\??\C:\spam\eggs", while r"\\?\C:\spam\eggs. . ." opens literally as the NT path r"\??\C:\spam\eggs. . .". Literal paths have to be used carefully, else one might create filenames such as "eggs. . ." that can't be accessed normally. Finally, the global device directory contains a symlink named "GlobalRoot" that targets the root directory in the object namespace. It's not particularly useful in the NT API, which can directly access the root directory. The Windows API, however, requires defining a new device via DefineDosDeviceW(), if not for the "GlobalRoot" symlink. For example, the NT path r"\Device\ConDrv\Output" can be opened in the Windows API as r"\\?\GlobalRoot\Device\ConDrv\Output". --- NT Mount Points The primary mount point for a filesystem is usually the root path of the device that contains the filesystem (e.g. "\\??\\PIPE\\"). For a volume device, it's called a volume mount point (e.g. "\\??\\C:\\"). This is automatic by default. As soon as a volume device comes online, an existing filesystem on the device gets recognized and mounted on the root path of the device. A common exception is the r"\??\UNC" device, which virtually mounts UNC shares such as r"\??\UNC\server\share". A UNC share is the root directory of a redirected filesystem or virtual filesystem. When a new share path is encountered, the "UNC" device (really r"\Device\Mup") sends it simultaneously to a prioritized list of providers in order to determine which providers handle it, if any. A bind mount point (i.e. a filesystem junction) can be set on an empty filesystem directory. The target must be a path on a local volume device. This is basically like the result of the JOIN command in MS-DOS, except it's generalized to allow grafting a subtree instead of an entire volume, and the joined volume isn't required to have a logical drive name. A junction can also be used instead of a substitute drive (e.g. a drive created by subst.exe), either of which makes working with a long base path more convenient. A junction that targets the root path of a volume name can be registered with the mount-point manager as the volume's canonical mount point. A volume name is based on the volume's persistent GUID. For example, the target path will look like "\\??\\Volume{12345678-1234-1234-1234-123456781234}\\". UNC paths can't be mounted on a filesystem directory. However, a filesystem symlink can target a UNC path. This can be used in place of a mapped drive. That said, the canonical mount point for a UNC share is always of the form r"\??\UNC\server\share". It's never a mapped drive, and it's definitely never a filesystem symlink. From list1 at tompassin.net Tue Dec 20 08:59:56 2022 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 20 Dec 2022 08:59:56 -0500 Subject: Fwd: Installation hell In-Reply-To: References: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> <9a5c8d2c-7be3-d9c0-0e22-b16fdcbc955f@tompassin.net> <657c8d6c-fac2-9973-fdce-7b1515aa0a23@tompassin.net> Message-ID: On 12/20/2022 8:11 AM, Eryk Sun wrote: [snipped] >> I know we're not here to bash Windows, but... drive letters >> really need to just die already. > I don't foresee drive-letter names getting phased out of Windows. And > Windows itself is unlikely to get phased out as long as Microsoft > continues to profit from it, as it has for the past 37 years. Microsoft won't get rid of them for backwards compatibility reasons, aside from the sheer difficulty of changing all that code. The company has always been very industrious about keeping backwards compatibility for Windows. I have compiled Delphi Windows GUI code from 2003 and even earlier that still runs, as one example. From edmondo.giovannozzi at gmail.com Tue Dec 20 04:51:53 2022 From: edmondo.giovannozzi at gmail.com (Edmondo Giovannozzi) Date: Tue, 20 Dec 2022 01:51:53 -0800 (PST) Subject: Fwd: Installation hell In-Reply-To: References: <8a0665e8-c968-ade1-4530-657bca739fde@gmail.com> <9a5c8d2c-7be3-d9c0-0e22-b16fdcbc955f@tompassin.net> <657c8d6c-fac2-9973-fdce-7b1515aa0a23@tompassin.net> <7f169067-a750-1ee2-d341-1089f746b81c@tompassin.net> Message-ID: <50880739-c06c-434f-aa6f-b1f6ee3a9267n@googlegroups.com> Personally I use winpython: https://winpython.github.io/ That have all the scientific packages already available. It can run without being installed and uses spyder as an IDE (for small projects it's ok). And, I can import pygame (even though I have not tested if everything works) in python 3.11. As I'm using it for science projects I find it perfect. From marce at dziban.net Tue Dec 20 16:09:37 2022 From: marce at dziban.net (Marce Coll) Date: Tue, 20 Dec 2022 22:09:37 +0100 Subject: ContextVars in async context Message-ID: <7eadba8f-bf67-4086-b0d3-b85119b43623@app.fastmail.com> Hi python people, hope this is the correct place to ask this! For a transactional async decorator I'm building I am using contextvars in order to know when a transaction is open in my current context. My understanding is that if given the following call stack A |- B | |- C |- D |- E If you set a context var at A with value 1, and then override it at B with value 2, then A, D and E will see value 1 and B and C will se value 2. Very similar (although a bit more manual) than dynamic scopes in common lisp. Now, back to the transactional decorator, from the little documentation there is about this I would imagine that something like this: @asynccontextmanager async def transactional( endpoint: _base.Endpoint, isolation_level: IsolationLevel = IsolationLevel.READ_COMMITTED, ): session = TRANSACTION_VAR.get() if not session: async with endpoint.session() as session, session.begin(): tok = TRANSACTION_VAR.set(session) try: await session.execute(text(f"SET TRANSACTION ISOLATION LEVEL {isolation_level.value}")) yield session finally: TRANSACTION_VAR.reset(tok) else: yield session should work automatically, and with some preliminary tests it seems it works, but, I don't understand why I need the manual reset. I thought just setting the variable would change it downstream the callstack and reset it when leaving the current context, as seen in the asyncio example in the documentation https://docs.python.org/3/library/contextvars.html#asyncio-support Now the final question, while the current setup works, when trying to use this as a context manager inside an async generator and then wrapping that with like `asyncio.wait_for`. To illustrate this: -- async def gen(): with transactional(): ... yield data g = gen() asyncio.wait_for(g.__anext__(), 1) # ValueError: was created in a different Context -- As far as I understand, that moves the awaitable into a new task and when trying to reset tok, it complains that tok was created in a different context. This is unfortunate as sometimes you want to be able to add a timeout using wait_for, particularly in tests. Is there anything I could do to my code to make it more reliable and robust when working with contextvars in an async context? Sorry for the wall of text, hope it's understandable Thanks in advance, -- Marce Coll marce at dziban.net From ethan at stoneleaf.us Tue Dec 20 16:23:51 2022 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 20 Dec 2022 13:23:51 -0800 Subject: Friendly Reminder Message-ID: <9f12edcf-2f0f-d125-d36c-d42a91db4c6a@stoneleaf.us> Greetings, all! I know our stress levels can be higher than normal around the holidays, but let's please be patient with each other. Both conversations and debates will be smoother if we assume other posters are asking/debating in good faith (at least, until proven otherwise). Happy Pythoning, and happy holidays! -- ~Ethan~ Moderator From jfong at ms4.hinet.net Tue Dec 20 22:10:46 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Tue, 20 Dec 2022 19:10:46 -0800 (PST) Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: References: <6b7f0c6d-f745-4745-aa5f-2012ec8ed906n@googlegroups.com> Message-ID: Thomas Passin ? 2022?12?20? ?????11:36:41 [UTC+8] ?????? > On 12/19/2022 9:24 PM, Jach Feng wrote: > > Mark Bourne ? 2022?12?20? ?????4:49:13 [UTC+8] ?????? > >> Jach Feng wrote: > >>> I have a script using the argparse module. I want to enter the string "step\x0A" as one of its positional arguments. I expect this string has a length of 5, but it gives 8. Obviously the escape character didn't function correctly. How to do it? > >> That depends on the command-line shell you're calling your script from. > >> > >> In bash, you can include a newline in a quoted string: > >> ./your_script 'step > >> ' > >> (the closing quote is on the next line) > >> > >> Or if you want to do it on a single line (or use other escape > >> sequences), you can use e.g.: > >> ./your_script $'step\x0a' > >> (dollar sign before a single-quoted string which contains escape sequences) > >> > >> -- > >> Mark. > > That's really good for Linux user! How about Windows? > One way is to process the argument after it gets into Python rather than > before. How hard that will be depends on how general you need the > argument to be. For your actual example, the argument comes into Python > as if it were > > arg1 = r"step\x0A" # or "step\\x0a" > > You can see if there is an "\\x": > > pos = arg1.find('\\x') # 4 > > Replace or use a regex to replace it: > > arg1_fixed = arg1.replace('\\x0A', '\n') > > Naturally, if "\\x0A" is only a special case and other combinations are > possible, you will need to figure out what you need and do some more > complicated processing. That's what I am taking this path under Windows now, the ultimate solution before Windows has shell similar to bash:-) From jfong at ms4.hinet.net Tue Dec 20 22:19:05 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Tue, 20 Dec 2022 19:19:05 -0800 (PST) Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: References: <6b7f0c6d-f745-4745-aa5f-2012ec8ed906n@googlegroups.com> Message-ID: ery... at gmail.com ? 2022?12?20? ?????12:35:52 [UTC+8] ?????? > On 12/19/22, Jach Feng wrote: > > > > That's really good for Linux user! How about Windows? > In CMD, typing the "^" escape character at the end of a line ignores > the newline and prompts for "more" input. If you press enter again, > you'll get another "more" prompt in which you can write the rest of > the command line. Command-line arguments are separated by spaces, so > you have to start the next line with a space if you want it to be a > new argument. Also, "^" is a literal character when it's in a > double-quoted string, which requires careful use of quotes. For > example: > > C:\>py -c "import sys; print(sys.orig_argv[3:])" spam^ > More? > More? eggs^ > More? > More? " and spam" > ['spam\n', 'eggs\n and spam'] > > The above is easier in PowerShell, which supports entering multiline > strings without having to escape the newline. The second-level prompt > is ">> ". For example: > > > py -c "import sys; print(sys.orig_argv[3:])" spam" > >> " eggs" > >> and spam" > ['spam\n', 'eggs\n and spam'] Thanks for the information. No idea Windows CMD can take such a trick to enter "\n" :-) From rosuav at gmail.com Wed Dec 21 00:01:25 2022 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 21 Dec 2022 16:01:25 +1100 Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: References: <6b7f0c6d-f745-4745-aa5f-2012ec8ed906n@googlegroups.com> Message-ID: On Wed, 21 Dec 2022 at 15:28, Jach Feng wrote: > That's what I am taking this path under Windows now, the ultimate solution before Windows has shell similar to bash:-) Technically, Windows DOES have a shell similar to bash. It's called bash. :) The trouble is, most people use cmd.exe instead. ChrisA From sjeik_appie at hotmail.com Wed Dec 21 07:15:58 2022 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Wed, 21 Dec 2022 13:15:58 +0100 Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: Message-ID: On Dec 21, 2022 06:01, Chris Angelico wrote: On Wed, 21 Dec 2022 at 15:28, Jach Feng wrote: > That's what I am taking this path under Windows now, the ultimate solution before Windows has shell similar to bash:-) Technically, Windows DOES have a shell similar to bash. It's called bash. :) The trouble is, most people use cmd.exe instead. ===== I use Git Bash quite a lot:?https://gitforwindows.org/ Is that the one you're referring to? From lal at solute.de Wed Dec 21 07:50:02 2022 From: lal at solute.de (Lars Liedtke) Date: Wed, 21 Dec 2022 13:50:02 +0100 Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: References: Message-ID: <9889d5d4-3a41-4b7c-f709-b1810a09880e@solute.de> Or you could have "native" bash ($SHELL) with WSL. But I assume not everyone is using it. Cheers Lars 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 21.12.22 um 13:15 schrieb Albert-Jan Roskam: On Dec 21, 2022 06:01, Chris Angelico wrote: On Wed, 21 Dec 2022 at 15:28, Jach Feng wrote: > That's what I am taking this path under Windows now, the ultimate solution before Windows has shell similar to bash:-) Technically, Windows DOES have a shell similar to bash. It's called bash. :) The trouble is, most people use cmd.exe instead. ===== I use Git Bash quite a lot: https://gitforwindows.org/ Is that the one you're referring to? From rosuav at gmail.com Wed Dec 21 09:29:01 2022 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Dec 2022 01:29:01 +1100 Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: References: Message-ID: On Wed, 21 Dec 2022 at 23:16, Albert-Jan Roskam wrote: > > > > On Dec 21, 2022 06:01, Chris Angelico wrote: > > On Wed, 21 Dec 2022 at 15:28, Jach Feng wrote: > > That's what I am taking this path under Windows now, the ultimate solution before Windows has shell similar to bash:-) > > Technically, Windows DOES have a shell similar to bash. It's called > bash. :) The trouble is, most people use cmd.exe instead. > > > ===== > > I use Git Bash quite a lot: https://gitforwindows.org/ > > Is that the one you're referring to? > Yeah, that's probably the easiest way to get hold of it. ChrisA From jfong at ms4.hinet.net Wed Dec 21 00:40:13 2022 From: jfong at ms4.hinet.net (Jach Feng) Date: Tue, 20 Dec 2022 21:40:13 -0800 (PST) Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: References: <6b7f0c6d-f745-4745-aa5f-2012ec8ed906n@googlegroups.com> Message-ID: <9e965167-3e8c-418c-bafa-598d4e1de99cn@googlegroups.com> Chris Angelico ? 2022?12?21? ?????1:02:01 [UTC+8] ?????? > On Wed, 21 Dec 2022 at 15:28, Jach Feng wrote: > > That's what I am taking this path under Windows now, the ultimate solution before Windows has shell similar to bash:-) > Technically, Windows DOES have a shell similar to bash. It's called > bash. :) The trouble is, most people use cmd.exe instead. > > ChrisA Really? Where? I can't find it in my Windows 8.1 From rosuav at gmail.com Wed Dec 21 11:12:50 2022 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Dec 2022 03:12:50 +1100 Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: <9e965167-3e8c-418c-bafa-598d4e1de99cn@googlegroups.com> References: <6b7f0c6d-f745-4745-aa5f-2012ec8ed906n@googlegroups.com> <9e965167-3e8c-418c-bafa-598d4e1de99cn@googlegroups.com> Message-ID: On Thu, 22 Dec 2022 at 03:11, Jach Feng wrote: > > Chris Angelico ? 2022?12?21? ?????1:02:01 [UTC+8] ?????? > > On Wed, 21 Dec 2022 at 15:28, Jach Feng wrote: > > > That's what I am taking this path under Windows now, the ultimate solution before Windows has shell similar to bash:-) > > Technically, Windows DOES have a shell similar to bash. It's called > > bash. :) The trouble is, most people use cmd.exe instead. > > > > ChrisA > Really? Where? I can't find it in my Windows 8.1 Ah, I didn't mean "ships with"; bash for Windows is very much available, but you'd have to go fetch it. Try the Windows app store first, and if not, a quick web search will find it. Or install Git for Windows, which comes with bash. ChrisA From rosuav at gmail.com Wed Dec 21 11:19:18 2022 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Dec 2022 03:19:18 +1100 Subject: How to enter escape character in a positional string argument from the command line? In-Reply-To: References: <9889d5d4-3a41-4b7c-f709-b1810a09880e@solute.de> Message-ID: On Thu, 22 Dec 2022 at 03:11, Stefan Ram wrote: > > Lars Liedtke writes: > >Or you could have "native" bash ($SHELL) with WSL. > > In this newsgroup, it would actually be obvious to use Python. Less obvious than you might think - partly because bash is just so dang good that it's really really hard to outdo it :) Sure, bash has a lot of weird and wonky edge cases, but it's an incredibly practical shell to use. > When commands are typed manually, this might be a bit verbose, > though. I mean > > os.chdir( r'C:\EXAMPLE' ) > > versus > > CD C:\EXAMPLE Exactly. What's good for a programming language is often not good for a shell. > class PythonShell( cmd.Cmd ): > > intro = 'Welcome to the Python shell. Type help or ? to list commands.\n' > prompt = '(Python) ' > file = None > > def do_cd( self, arg ): > 'change directory: CD C:\EXAMPLE' > os.chdir( *parse( arg )) > > def do_bye( self, arg ): > 'Exit: BYE' > print( 'Thank you for using the Python Shell!' ) > return True Sure, you can always create your own shell. But I think you'll find that, as you start expanding on this, you'll end up leaning more towards "implementing bash-like and/or cmd-like semantics in Python" rather than "creating a Python shell". Shells, in general, try to execute programs as easily and conveniently as possible. Programming languages try to stay inside themselves and do things, with subprocess spawning being a much less important task. Fun challenge: see how much you can do in bash without ever forking to another program. And by "fun", I mean extremely difficult, and by "challenge" I really mean "something you might have to do when your system is utterly hosed and all you have available is one root shell". It's amazing how far you can go when your hard drive has crashed and you desperately need to get one crucial login key that you thought you had saved elsewhere but hadn't. ChrisA From gheskett at shentel.net Wed Dec 21 11:55:54 2022 From: gheskett at shentel.net (gene heskett) Date: Wed, 21 Dec 2022 11:55:54 -0500 Subject: How to enter escape character in a positional string argumentfrom the command line? In-Reply-To: References: <9889d5d4-3a41-4b7c-f709-b1810a09880e@solute.de> Message-ID: <1d7e4fd3-2cdb-e1df-ed18-d2d79b727dc4@shentel.net> On 12/21/22 11:22, Chris Angelico wrote: > On Thu, 22 Dec 2022 at 03:11, Stefan Ram wrote: >> >> Lars Liedtke writes: >>> Or you could have "native" bash ($SHELL) with WSL. >> >> In this newsgroup, it would actually be obvious to use Python. > > Less obvious than you might think - partly because bash is just so > dang good that it's really really hard to outdo it :) Sure, bash has a > lot of weird and wonky edge cases, but it's an incredibly practical > shell to use. > When you make a statement like that, Chris, you should also note that every single one of those "wonky edge cases" is documented down to the last dotted i. Bash's docs will kill a good sized pulp tree, needing around a ream of paper to print on a duplex printer. I know, I did it around a decade ago. If you like to write scripts, having a dead tree copy of the docs at your elbow in incredibly useful. That huge man page does not cover it like the printed docs do. >> When commands are typed manually, this might be a bit verbose, >> though. I mean >> >> os.chdir( r'C:\EXAMPLE' ) >> >> versus >> >> CD C:\EXAMPLE > > Exactly. What's good for a programming language is often not good for a shell. > >> class PythonShell( cmd.Cmd ): >> >> intro = 'Welcome to the Python shell. Type help or ? to list commands.\n' >> prompt = '(Python) ' >> file = None >> >> def do_cd( self, arg ): >> 'change directory: CD C:\EXAMPLE' >> os.chdir( *parse( arg )) >> >> def do_bye( self, arg ): >> 'Exit: BYE' >> print( 'Thank you for using the Python Shell!' ) >> return True > > Sure, you can always create your own shell. But I think you'll find > that, as you start expanding on this, you'll end up leaning more > towards "implementing bash-like and/or cmd-like semantics in Python" > rather than "creating a Python shell". Shells, in general, try to > execute programs as easily and conveniently as possible. Programming > languages try to stay inside themselves and do things, with subprocess > spawning being a much less important task. > > Fun challenge: see how much you can do in bash without ever forking to > another program. And by "fun", I mean extremely difficult, and by > "challenge" I really mean "something you might have to do when your > system is utterly hosed and all you have available is one root shell". > > It's amazing how far you can go when your hard drive has crashed and > you desperately need to get one crucial login key that you thought you > had saved elsewhere but hadn't. > > ChrisA 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 rosuav at gmail.com Wed Dec 21 12:00:44 2022 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Dec 2022 04:00:44 +1100 Subject: How to enter escape character in a positional string argumentfrom the command line? In-Reply-To: <1d7e4fd3-2cdb-e1df-ed18-d2d79b727dc4@shentel.net> References: <9889d5d4-3a41-4b7c-f709-b1810a09880e@solute.de> <1d7e4fd3-2cdb-e1df-ed18-d2d79b727dc4@shentel.net> Message-ID: On Thu, 22 Dec 2022 at 03:58, gene heskett wrote: > > On 12/21/22 11:22, Chris Angelico wrote: > > On Thu, 22 Dec 2022 at 03:11, Stefan Ram wrote: > >> > >> Lars Liedtke writes: > >>> Or you could have "native" bash ($SHELL) with WSL. > >> > >> In this newsgroup, it would actually be obvious to use Python. > > > > Less obvious than you might think - partly because bash is just so > > dang good that it's really really hard to outdo it :) Sure, bash has a > > lot of weird and wonky edge cases, but it's an incredibly practical > > shell to use. > > > When you make a statement like that, Chris, you should also note that > every single one of those "wonky edge cases" is documented down to the > last dotted i. Bash's docs will kill a good sized pulp tree, needing > around a ream of paper to print on a duplex printer. I know, I did it > around a decade ago. If you like to write scripts, having a dead tree > copy of the docs at your elbow in incredibly useful. That huge man page > does not cover it like the printed docs do. > Oh yes, absolutely true. Its wonkiness is dependable and consistent; but it is definitely quirky (look at all the different ways to embed arguments into things, and the ways that $*, $@, "$*, and "$@" behave when put into variables). Not usually a problem, but it does sometimes leave you thinking "wow, wouldn't it be easier to just use something like Python?". And in the complicated cases, yeah, it can be. But in the simple cases? Bash rocks. ChrisA From rosuav at gmail.com Wed Dec 21 12:16:47 2022 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 22 Dec 2022 04:16:47 +1100 Subject: How to enter escape character in a positional string argumentfrom the command line? In-Reply-To: <775B6DA0-165A-484F-99F2-D9A3255A649F@barrys-emacs.org> References: <775B6DA0-165A-484F-99F2-D9A3255A649F@barrys-emacs.org> Message-ID: On Thu, 22 Dec 2022 at 04:12, Barry wrote: > I see bash scripts that are 1000?s of line of code at work and its a maintenance nightmare. > > Knowing when to make the move from ?handy bash script? to ?this is a production application? and needs to be python is what I see people miss. > > After a certain point in complexity the python code wins on maintenance. > Personally i set a low bar to move from bash to python. Agreed 100%. However, how many commands do you type a day at the bash prompt? *Every one of those* is a simple case that doesn't need Python. That's what makes bash such a great shell. You can type simple, convenient commands, and they *just work*. Need something a bit more complicated? You can do that too. Want to automate a short sequence of commands? Don't have to translate them into another system (like Python subprocess calls), just copy/paste them into a shell script. Yes, there absolutely is a point beyond which it's better to translate everything. But the vast number of commands executed every day? Most of them are fine with bash. And that's why Python will never replace bash as a shell. ChrisA From barry at barrys-emacs.org Wed Dec 21 12:12:47 2022 From: barry at barrys-emacs.org (Barry) Date: Wed, 21 Dec 2022 17:12:47 +0000 Subject: How to enter escape character in a positional string argumentfrom the command line? In-Reply-To: References: Message-ID: <775B6DA0-165A-484F-99F2-D9A3255A649F@barrys-emacs.org> > On 21 Dec 2022, at 17:06, Chris Angelico wrote: > > ?On Thu, 22 Dec 2022 at 03:58, gene heskett wrote: >> >>> On 12/21/22 11:22, Chris Angelico wrote: >>> On Thu, 22 Dec 2022 at 03:11, Stefan Ram wrote: >>>> >>>> Lars Liedtke writes: >>>>> Or you could have "native" bash ($SHELL) with WSL. >>>> >>>> In this newsgroup, it would actually be obvious to use Python. >>> >>> Less obvious than you might think - partly because bash is just so >>> dang good that it's really really hard to outdo it :) Sure, bash has a >>> lot of weird and wonky edge cases, but it's an incredibly practical >>> shell to use. >>> >> When you make a statement like that, Chris, you should also note that >> every single one of those "wonky edge cases" is documented down to the >> last dotted i. Bash's docs will kill a good sized pulp tree, needing >> around a ream of paper to print on a duplex printer. I know, I did it >> around a decade ago. If you like to write scripts, having a dead tree >> copy of the docs at your elbow in incredibly useful. That huge man page >> does not cover it like the printed docs do. >> > > Oh yes, absolutely true. Its wonkiness is dependable and consistent; > but it is definitely quirky (look at all the different ways to embed > arguments into things, and the ways that $*, $@, "$*, and "$@" behave > when put into variables). Not usually a problem, but it does sometimes > leave you thinking "wow, wouldn't it be easier to just use something > like Python?". And in the complicated cases, yeah, it can be. But in > the simple cases? Bash rocks. I see bash scripts that are 1000?s of line of code at work and its a maintenance nightmare. Knowing when to make the move from ?handy bash script? to ?this is a production application? and needs to be python is what I see people miss. After a certain point in complexity the python code wins on maintenance. Personally i set a low bar to move from bash to python. Barry > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From dieter at handshake.de Wed Dec 21 12:16:14 2022 From: dieter at handshake.de (Dieter Maurer) Date: Wed, 21 Dec 2022 18:16:14 +0100 Subject: ContextVars in async context In-Reply-To: <7eadba8f-bf67-4086-b0d3-b85119b43623@app.fastmail.com> References: <7eadba8f-bf67-4086-b0d3-b85119b43623@app.fastmail.com> Message-ID: <25507.16222.156662.41602@ixdm.fritz.box> Marce Coll wrote at 2022-12-20 22:09 +0100: >Hi python people, hope this is the correct place to ask this! > >For a transactional async decorator I'm building I am using contextvars in order to know when a transaction is open in my current context. > >My understanding is that if given the following call stack > >A >|- B >| |- C >|- D > |- E > >If you set a context var at A with value 1, and then override it at B with value 2, then A, D and E will see value 1 and B and C will se value 2. Very similar (although a bit more manual) than dynamic scopes in common lisp. This is not the way I understand context variables. In my view (--> PEP 0567), the context is the coroutine not the call stack. This means: all calls in the same coroutine share the same context variables. In your example, if `B` overrides the context variable, then all later calls in this coroutine will see the overridden value. From pegloff at gmail.com Wed Dec 21 16:32:28 2022 From: pegloff at gmail.com (Patrick EGLOFF) Date: Wed, 21 Dec 2022 22:32:28 +0100 Subject: pygame.midi input/output not working Message-ID: HI, Some time ago I wrote a small software using pygame.midi It worked just fine with Win10/ python 3.9 / SDL 2.0.14 / pygame 2.0.1 I had to change my computer and now I installed Win10 / Python 3.11.1 / SDL 2.0.18 / pygame 2.1.2 The following instructions don't work anymore, making the IDE stop execution : my_input = pygame.midi.Input(MidiDeviceIn) midi_out = pygame.midi.Output(MidiDeviceOut) Does someone have a suggestion? Thanks, -- Patrick Egloff email : pegloff at gmail.com Web page : http://www.egloff.eu From list1 at tompassin.net Wed Dec 21 17:23:47 2022 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 21 Dec 2022 17:23:47 -0500 Subject: pygame.midi input/output not working In-Reply-To: References: Message-ID: <1ded41e3-3551-fed8-f836-ee8c60aea5af@tompassin.net> On 12/21/2022 4:32 PM, Patrick EGLOFF wrote: > HI, > Some time ago I wrote a small software using pygame.midi > It worked just fine with Win10/ python 3.9 / SDL 2.0.14 / pygame 2.0.1 > > I had to change my computer and now I installed Win10 / Python 3.11.1 / SDL > 2.0.18 / pygame 2.1.2 > > The following instructions don't work anymore, making the IDE stop > execution : > > my_input = pygame.midi.Input(MidiDeviceIn) > midi_out = pygame.midi.Output(MidiDeviceOut) > > Does someone have a suggestion? The pygame web site says this: "Pygame still does not run on Python 3.11" Also from the same page: "Make sure you install python with the "Add python to PATH" option selected. This means that python, and pip will work for you from the command line." See https://www.pygame.org/wiki/GettingStarted#Pygame%20Installation So what to do until pygame runs in Python 3.11? I'd install an earlier version of Python. You can have several versions on your machine at the same time. Remember, you have to install all the required packages with each version of Python - they don't use each other's code or libraries. From pegloff at gmail.com Thu Dec 22 00:33:07 2022 From: pegloff at gmail.com (Patrick EGLOFF) Date: Thu, 22 Dec 2022 06:33:07 +0100 Subject: Fwd: pygame.midi input/output not working In-Reply-To: References: <1ded41e3-3551-fed8-f836-ee8c60aea5af@tompassin.net> Message-ID: Hi Thomas, Thanks for the answer AND solution ! That was it... shame on me, I didn't notice this warning. I uninstalled 3.11.1 and installed 3.10.9, and my software is back to live ! Now I have to figure out another problem. I will make another post about this serial weird behavior. Thanks for making my day ! Patrick Le mer. 21 d?c. 2022 ? 23:27, Thomas Passin a ?crit : > On 12/21/2022 4:32 PM, Patrick EGLOFF wrote: > > HI, > > Some time ago I wrote a small software using pygame.midi > > It worked just fine with Win10/ python 3.9 / SDL 2.0.14 / pygame 2.0.1 > > > > I had to change my computer and now I installed Win10 / Python 3.11.1 / > SDL > > 2.0.18 / pygame 2.1.2 > > > > The following instructions don't work anymore, making the IDE stop > > execution : > > > > my_input = pygame.midi.Input(MidiDeviceIn) > > midi_out = pygame.midi.Output(MidiDeviceOut) > > > > Does someone have a suggestion? > > The pygame web site says this: > > "Pygame still does not run on Python 3.11" > > Also from the same page: > > "Make sure you install python with the "Add python to PATH" option > selected. This means that python, and pip will work for you from the > command line." > > See https://www.pygame.org/wiki/GettingStarted#Pygame%20Installation > > So what to do until pygame runs in Python 3.11? I'd install an earlier > version of Python. You can have several versions on your machine at the > same time. Remember, you have to install all the required packages with > each version of Python - they don't use each other's code or libraries. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Patrick Egloff email : pegloff at gmail.com Web page : http://www.egloff.eu -- Patrick Egloff email : pegloff at gmail.com Web page : http://www.egloff.eu From hjp-python at hjp.at Thu Dec 22 05:04:22 2022 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 22 Dec 2022 11:04:22 +0100 Subject: pygame.midi input/output not working In-Reply-To: <1ded41e3-3551-fed8-f836-ee8c60aea5af@tompassin.net> References: <1ded41e3-3551-fed8-f836-ee8c60aea5af@tompassin.net> Message-ID: <20221222100422.bsbyubmjw3y7gn6c@hjp.at> On 2022-12-21 17:23:47 -0500, Thomas Passin wrote: > The pygame web site says this: > > "Pygame still does not run on Python 3.11" This doesn't sound like "we haven't got around to preparing packages yet" and more like "there's a serious incompatibility we haven't solved yet". Does anybody know what the issue is? 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 gweatherby at uchc.edu Thu Dec 22 08:08:55 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Thu, 22 Dec 2022 13:08:55 +0000 Subject: pygame.midi input/output not working In-Reply-To: <20221222100422.bsbyubmjw3y7gn6c@hjp.at> References: <1ded41e3-3551-fed8-f836-ee8c60aea5af@tompassin.net> <20221222100422.bsbyubmjw3y7gn6c@hjp.at> Message-ID: https://github.com/pygame/pygame/issues/3522 From: Python-list on behalf of Peter J. Holzer Date: Thursday, December 22, 2022 at 5:06 AM To: python-list at python.org Subject: Re: pygame.midi input/output not working On 2022-12-21 17:23:47 -0500, Thomas Passin wrote: > The pygame web site says this: > > "Pygame still does not run on Python 3.11" This doesn't sound like "we haven't got around to preparing packages yet" and more like "there's a serious incompatibility we haven't solved yet". Does anybody know what the issue is? hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" From list1 at tompassin.net Thu Dec 22 08:45:11 2022 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 22 Dec 2022 08:45:11 -0500 Subject: pygame.midi input/output not working In-Reply-To: <20221222100422.bsbyubmjw3y7gn6c@hjp.at> References: <1ded41e3-3551-fed8-f836-ee8c60aea5af@tompassin.net> <20221222100422.bsbyubmjw3y7gn6c@hjp.at> Message-ID: <0e418681-6ebd-f385-a122-10947cd39c4b@tompassin.net> This issue thread on Github says that everyone is waiting on the packaging maintainer, but nothing from him for some time. On 12/22/2022 5:04 AM, Peter J. Holzer wrote: > On 2022-12-21 17:23:47 -0500, Thomas Passin wrote: >> The pygame web site says this: >> >> "Pygame still does not run on Python 3.11" > > This doesn't sound like "we haven't got around to preparing packages > yet" and more like "there's a serious incompatibility we haven't solved > yet". > > Does anybody know what the issue is? > > hp > > From pegloff at gmail.com Thu Dec 22 06:01:44 2022 From: pegloff at gmail.com (Patrick EGLOFF) Date: Thu, 22 Dec 2022 12:01:44 +0100 Subject: Pyserial problem Message-ID: Hi all, I use Python 3.10.9 and Pyserial 3.5 on a Win10 machine. I'm sending datas via an USB port to a device that accept commands in the form of : cmd; The device receives and reacts to the commands sent, and it should reply with an ACK of the same kind. But looking with a COM port sniffer, nothing is sent back. I checked that everything is working with PUTTY and even MINITERM, and everything is just fine, the device is responding correctly. I have set the flow control to different values, as well as setting the RTS and DTR high or low with no change. Normally, the device works without any flow control, and CTS + DTR high. I checked with MINITERM, that the flow control and control lines have the same state. I'm a bit surprised and stucked. Can someone help ? Thanks, -- Patrick Egloff email : pegloff at gmail.com Web page : http://www.egloff.eu From hongyi.zhao at gmail.com Thu Dec 22 08:35:04 2022 From: hongyi.zhao at gmail.com (hongy...@gmail.com) Date: Thu, 22 Dec 2022 05:35:04 -0800 (PST) Subject: =?UTF-8?Q?Extract_the_=E2=80=9CMatrix_form=E2=80=9D_dataset_from_BCS_websi?= =?UTF-8?Q?te=2E?= Message-ID: <2c0b55d0-202a-47ed-ae4f-697a1342bf34n@googlegroups.com> I want to extract / scrape the ?Matrix form? dataset from the BCS website [1], a.k.a., the data appeared in the 3rd column. I tried with the following python code snippet, but still failed to figure out the trick: import requests from bs4 import BeautifulSoup import re proxies = { 'http': 'socks5h://127.0.0.1:18888', 'https': 'socks5h://127.0.0.1:18888' } requests.packages.urllib3.disable_warnings() r = requests.get('https://www.cryst.ehu.es/cgi-bin/plane/programs/nph-plane_getgen?gnum=17&type=plane', proxies=proxies, verify=False) soup = BeautifulSoup(r.content, features="lxml") table = soup.find('table') id = table.find_all('id') My python environment is as follows: werner at X10DAi:~$ pyenv shell datasci (datasci) werner at X10DAi:~$ python --version Python 3.11.1 Any tips will be appreciated. [1] https://www.cryst.ehu.es/cgi-bin/plane/programs/nph-plane_getgen?gnum=17&type=plane Regards, Zhao From phd at phdru.name Thu Dec 22 11:41:38 2022 From: phd at phdru.name (Oleg Broytman) Date: Thu, 22 Dec 2022 19:41:38 +0300 Subject: SQLObject 3.10.1 Message-ID: Hello! I'm pleased to announce version 3.10.1, the first minor feature release of branch 3.10 of SQLObject. What's new in SQLObject ======================= Minor features -------------- * Use ``module_loader.exec_module(module_loader.create_module())`` instead of ``module_loader.load_module()`` when available. Drivers ------- * Added ``mysql-connector-python``. Tests ----- * Run tests with Python 3.11. CI -- * Ubuntu >= 22 and ``setup-python`` dropped Pythons < 3.7. Use ``conda`` via ``s-weigand/setup-conda`` instead of ``setup-python`` to install older Pythons on Linux. For a more complete list, please see the news: http://sqlobject.org/News.html What is SQLObject ================= SQLObject is a free and open-source (LGPL) Python object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL/MariaDB (with a number of DB API drivers: ``MySQLdb``, ``mysqlclient``, ``mysql-connector``, ``PyMySQL``, ``mariadb``), PostgreSQL (``psycopg2``, ``PyGreSQL``, partially ``pg8000`` and ``py-postgresql``), SQLite (builtin ``sqlite``, ``pysqlite``, partially ``supersqlite``); connections to other backends - Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB) - are less debugged). Python 2.7 or 3.4+ is required. Where is SQLObject ================== Site: http://sqlobject.org Download: https://pypi.org/project/SQLObject/3.10.1 News and changes: http://sqlobject.org/News.html StackOverflow: https://stackoverflow.com/questions/tagged/sqlobject Mailing lists: https://sourceforge.net/p/sqlobject/mailman/ Development: http://sqlobject.org/devel/ Developer Guide: http://sqlobject.org/DeveloperGuide.html Example ======= Install:: $ pip install sqlobject Create a simple class that wraps a table:: >>> from sqlobject import * >>> >>> sqlhub.processConnection = connectionForURI('sqlite:/:memory:') >>> >>> class Person(SQLObject): ... fname = StringCol() ... mi = StringCol(length=1, default=None) ... lname = StringCol() ... >>> Person.createTable() Use the object:: >>> p = Person(fname="John", lname="Doe") >>> p >>> p.fname 'John' >>> p.mi = 'Q' >>> p2 = Person.get(1) >>> p2 >>> p is p2 True Queries:: >>> p3 = Person.selectBy(lname="Doe")[0] >>> p3 >>> pc = Person.select(Person.q.lname=="Doe").count() >>> pc 1 Oleg. -- Oleg Broytman https://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From list1 at tompassin.net Thu Dec 22 12:34:05 2022 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 22 Dec 2022 12:34:05 -0500 Subject: =?UTF-8?Q?Re=3a_Extract_the_=e2=80=9cMatrix_form=e2=80=9d_dataset_f?= =?UTF-8?Q?rom_BCS_website=2e?= In-Reply-To: <2c0b55d0-202a-47ed-ae4f-697a1342bf34n@googlegroups.com> References: <2c0b55d0-202a-47ed-ae4f-697a1342bf34n@googlegroups.com> Message-ID: <39dfb3d6-0e51-e94a-539d-ef114d380e2d@tompassin.net> On 12/22/2022 8:35 AM, hongy... at gmail.com wrote: > I want to extract / scrape the ?Matrix form? dataset from the BCS website [1], a.k.a., the data appeared in the 3rd column. > > I tried with the following python code snippet, but still failed to figure out the trick: Tell what you observed, and what you expected. For example, does the data get downloaded? Do you get error messages, and if so what are they? Does the id variable contain anything at all? Etc. > import requests > from bs4 import BeautifulSoup > import re > > proxies = { > 'http': 'socks5h://127.0.0.1:18888', > 'https': 'socks5h://127.0.0.1:18888' > } > > requests.packages.urllib3.disable_warnings() > r = requests.get('https://www.cryst.ehu.es/cgi-bin/plane/programs/nph-plane_getgen?gnum=17&type=plane', proxies=proxies, verify=False) > soup = BeautifulSoup(r.content, features="lxml") > > table = soup.find('table') > id = table.find_all('id') > > My python environment is as follows: > > werner at X10DAi:~$ pyenv shell datasci > (datasci) werner at X10DAi:~$ python --version > Python 3.11.1 > > Any tips will be appreciated. > > [1] https://www.cryst.ehu.es/cgi-bin/plane/programs/nph-plane_getgen?gnum=17&type=plane > > Regards, > Zhao From barry at barrys-emacs.org Thu Dec 22 12:37:25 2022 From: barry at barrys-emacs.org (Barry) Date: Thu, 22 Dec 2022 17:37:25 +0000 Subject: Pyserial problem In-Reply-To: References: Message-ID: > On 22 Dec 2022, at 17:09, Patrick EGLOFF wrote: > > ?Hi all, > > I use Python 3.10.9 and Pyserial 3.5 on a Win10 machine. > > I'm sending datas via an USB port to a device that accept commands in the > form of : cmd; > The device receives and reacts to the commands sent, and it should reply > with an ACK of the same kind. > > But looking with a COM port sniffer, nothing is sent back. > > I checked that everything is working with PUTTY and even MINITERM, and > everything is just fine, the device is responding correctly. > > I have set the flow control to different values, as well as setting the RTS > and DTR high or low with no change. > Normally, the device works without any flow control, and CTS + DTR high. > > I checked with MINITERM, that the flow control and control lines have the > same state. > > I'm a bit surprised and stucked. > Can someone help ? Please post tour code that you are using to talk to the device. Barry > Thanks, > -- > Patrick Egloff > email : pegloff at gmail.com > Web page : http://www.egloff.eu > -- > https://mail.python.org/mailman/listinfo/python-list > From phd at phdru.name Sun Dec 25 11:18:22 2022 From: phd at phdru.name (Oleg Broytman) Date: Sun, 25 Dec 2022 19:18:22 +0300 Subject: CheetahTemplate 3.3.1 Message-ID: Hello! I'm pleased to announce version 3.3.1, the 1st bugfix release of branch 3.3 of CheetahTemplate3. What's new in CheetahTemplate3 ============================== Bug fixes: - Fixed ``ImportHooks`` under PyPy3. Tests: - Run tests with PyPy3. CI: - Use ``conda`` to install older Pythons Ubuntu >= 22 and ``setup-python`` dropped Pythons < 3.7. Use ``s-weigand/setup-conda`` instead of ``setup-python``. What is CheetahTemplate3 ======================== Cheetah3 is a free and open source (MIT) Python template engine. It's a fork of the original CheetahTemplate library. Python 2.7 or 3.4+ is required. Where is CheetahTemplate3 ========================= Site: https://cheetahtemplate.org/ Download: https://pypi.org/project/CT3/3.3.1 News and changes: https://cheetahtemplate.org/news.html StackOverflow: https://stackoverflow.com/questions/tagged/cheetah Mailing lists: https://sourceforge.net/p/cheetahtemplate/mailman/ Development: https://github.com/CheetahTemplate3 Developer Guide: https://cheetahtemplate.org/dev_guide/ Example ======= Install:: $ pip install CT3 # (or even "ct3") Below is a simple example of some Cheetah code, as you can see it's practically Python. You can import, inherit and define methods just like in a regular Python module, since that's what your Cheetah templates are compiled to :) :: #from Cheetah.Template import Template #extends Template #set $people = [{'name' : 'Tom', 'mood' : 'Happy'}, {'name' : 'Dick', 'mood' : 'Sad'}, {'name' : 'Harry', 'mood' : 'Hairy'}] How are you feeling?
    #for $person in $people
  • $person['name'] is $person['mood']
  • #end for
Oleg. -- Oleg Broytman https://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From antoon.pardon at vub.be Tue Dec 27 05:27:29 2022 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 27 Dec 2022 11:27:29 +0100 Subject: How make your module substitute a python stdlib module. Message-ID: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> OK, I am writing an alternative for the threading module. What I would like to know is how I can get some library modules call my alternative instead of the threading module. For instance there is the logging module, it can log the thread name. So I would like to know how I can get the logging module to call the function from my module to get the current_thread, instead of it calling "current_thread" from the threading module. -- Antoon Pardon From rosuav at gmail.com Tue Dec 27 05:37:29 2022 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 Dec 2022 21:37:29 +1100 Subject: How make your module substitute a python stdlib module. In-Reply-To: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> Message-ID: On Tue, 27 Dec 2022 at 21:29, Antoon Pardon wrote: > > OK, I am writing an alternative for the threading module. What I would > like to know is how I can get some library modules call my alternative > instead of the threading module. > > For instance there is the logging module, it can log the thread name. So > I would like to know how I can get the logging module to call the > function from my module to get the current_thread, instead of it calling > "current_thread" from the threading module. Easy: make sure your module is called "threading.py" and is earlier in the path than the standard library. In fact, it's so easy that people do it unintentionally all the time... Generally, the current directory (or the script directory) is the first entry in sys.path, so that's a good place to put it. ChrisA From antoon.pardon at vub.be Tue Dec 27 06:12:16 2022 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 27 Dec 2022 12:12:16 +0100 Subject: How make your module substitute a python stdlib module. In-Reply-To: References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> Message-ID: <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> Op 27/12/2022 om 11:37 schreef Chris Angelico: > On Tue, 27 Dec 2022 at 21:29, Antoon Pardon wrote: >> OK, I am writing an alternative for the threading module. What I would >> like to know is how I can get some library modules call my alternative >> instead of the threading module. >> >> For instance there is the logging module, it can log the thread name. So >> I would like to know how I can get the logging module to call the >> function from my module to get the current_thread, instead of it calling >> "current_thread" from the threading module. > Easy: make sure your module is called "threading.py" and is earlier in > the path than the standard library. In fact, it's so easy that people > do it unintentionally all the time... Generally, the current directory > (or the script directory) is the first entry in sys.path, so that's a > good place to put it. Well I had hope for a somewhat more selective solution. The intention is to have a number of modules collected in a package where this module is one of and the package is available via the "installed" search path. So the programmer should just be able to choose to write his code with either: ??? from threading import Thread or ??? from QYZlib.threaders import Thread -- Antoon Pardon From rosuav at gmail.com Tue Dec 27 06:28:32 2022 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 Dec 2022 22:28:32 +1100 Subject: How make your module substitute a python stdlib module. In-Reply-To: <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> Message-ID: On Tue, 27 Dec 2022 at 22:13, Antoon Pardon wrote: > > > > Op 27/12/2022 om 11:37 schreef Chris Angelico: > > On Tue, 27 Dec 2022 at 21:29, Antoon Pardon wrote: > >> OK, I am writing an alternative for the threading module. What I would > >> like to know is how I can get some library modules call my alternative > >> instead of the threading module. > >> > >> For instance there is the logging module, it can log the thread name. So > >> I would like to know how I can get the logging module to call the > >> function from my module to get the current_thread, instead of it calling > >> "current_thread" from the threading module. > > Easy: make sure your module is called "threading.py" and is earlier in > > the path than the standard library. In fact, it's so easy that people > > do it unintentionally all the time... Generally, the current directory > > (or the script directory) is the first entry in sys.path, so that's a > > good place to put it. > > Well I had hope for a somewhat more selective solution. The intention is > to have a number of modules collected in a package where this module is > one of and the package is available via the "installed" search path. > > So the programmer should just be able to choose to write his code with > either: > > from threading import Thread > > or > > from QYZlib.threaders import Thread > How do you intend to distinguish one from the other? How should the logging module know which threading module to use? ChrisA From antoon.pardon at vub.be Tue Dec 27 07:04:53 2022 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 27 Dec 2022 13:04:53 +0100 Subject: How make your module substitute a python stdlib module. In-Reply-To: References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> Message-ID: <20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be> Op 27/12/2022 om 12:28 schreef Chris Angelico: > On Tue, 27 Dec 2022 at 22:13, Antoon Pardon wrote: >> >> >> Op 27/12/2022 om 11:37 schreef Chris Angelico: >>> On Tue, 27 Dec 2022 at 21:29, Antoon Pardon wrote: >>>> OK, I am writing an alternative for the threading module. What I would >>>> like to know is how I can get some library modules call my alternative >>>> instead of the threading module. >>>> >>>> For instance there is the logging module, it can log the thread name. So >>>> I would like to know how I can get the logging module to call the >>>> function from my module to get the current_thread, instead of it calling >>>> "current_thread" from the threading module. >>> Easy: make sure your module is called "threading.py" and is earlier in >>> the path than the standard library. In fact, it's so easy that people >>> do it unintentionally all the time... Generally, the current directory >>> (or the script directory) is the first entry in sys.path, so that's a >>> good place to put it. >> Well I had hope for a somewhat more selective solution. The intention is >> to have a number of modules collected in a package where this module is >> one of and the package is available via the "installed" search path. >> >> So the programmer should just be able to choose to write his code with >> either: >> >> from threading import Thread >> >> or >> >> from QYZlib.threaders import Thread >> > How do you intend to distinguish one from the other? How should the > logging module know which threading module to use? That is my question! How can I get the logging module to use my module.I was hoping the logging module would allow some kind of dependency injection, so you can tell it what threading module to use. An other option might be to manipulate sys.modules. -- Antoon Pardon From rosuav at gmail.com Tue Dec 27 07:09:37 2022 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 Dec 2022 23:09:37 +1100 Subject: How make your module substitute a python stdlib module. In-Reply-To: <20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be> References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> <20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be> Message-ID: On Tue, 27 Dec 2022 at 23:06, Antoon Pardon wrote: > > How do you intend to distinguish one from the other? How should the > > logging module know which threading module to use? > > That is my question! How can I get the logging module to use my module.I was hoping the logging module would allow some kind of dependency > injection, so you can tell it what threading module to use. An other > option might be to manipulate sys.modules. -- Antoon Pardon But presumably you want OTHER modules to continue using the vanilla threading module? This is likely to end up somewhat hacky. Yes, you can manipulate sys.modules, but there's only one threading module at a time, so you need a way to distinguish between modules that should use the changed one and modules that shouldn't. TBH this is starting to sound like something where you want unittest-type facilities, actually. ChrisA From antoon.pardon at vub.be Tue Dec 27 07:26:37 2022 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 27 Dec 2022 13:26:37 +0100 Subject: How make your module substitute a python stdlib module. In-Reply-To: References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> <20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be> Message-ID: Op 27/12/2022 om 13:09 schreef Chris Angelico: > On Tue, 27 Dec 2022 at 23:06, Antoon Pardon wrote: >>> How do you intend to distinguish one from the other? How should the >>> logging module know which threading module to use? >> That is my question! How can I get the logging module to use my module.I was hoping the logging module would allow some kind of dependency >> injection, so you can tell it what threading module to use. An other >> option might be to manipulate sys.modules. -- Antoon Pardon > But presumably you want OTHER modules to continue using the vanilla > threading module? This is likely to end up somewhat hacky. Yes, you > can manipulate sys.modules, but there's only one threading module at a > time, so you need a way to distinguish between modules that should use > the changed one and modules that shouldn't. But don't these caveats also apply with your original answer of having a local threading.py file? At the moment I am happy with a solution that once the programmer has imported from QYZlib.threaders that module will used as the threading module. -- Antoon Pardon. From rosuav at gmail.com Tue Dec 27 07:46:09 2022 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 Dec 2022 23:46:09 +1100 Subject: How make your module substitute a python stdlib module. In-Reply-To: References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> <20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be> Message-ID: On Tue, 27 Dec 2022 at 23:28, Antoon Pardon wrote: > > > > Op 27/12/2022 om 13:09 schreef Chris Angelico: > > On Tue, 27 Dec 2022 at 23:06, Antoon Pardon wrote: > >>> How do you intend to distinguish one from the other? How should the > >>> logging module know which threading module to use? > >> That is my question! How can I get the logging module to use my module.I was hoping the logging module would allow some kind of dependency > >> injection, so you can tell it what threading module to use. An other > >> option might be to manipulate sys.modules. -- Antoon Pardon > > But presumably you want OTHER modules to continue using the vanilla > > threading module? This is likely to end up somewhat hacky. Yes, you > > can manipulate sys.modules, but there's only one threading module at a > > time, so you need a way to distinguish between modules that should use > > the changed one and modules that shouldn't. > > But don't these caveats also apply with your original answer of having a > local threading.py file? > > At the moment I am happy with a solution that once the programmer has > imported from QYZlib.threaders that module will used as the threading > module. > Oh! If that's all you need, then yes, a simple patch of sys.modules will work. You'll have to make sure you get your module imported before anything else pulls up the vanilla one, though. Otherwise, your only option is to keep the existing module object and monkeypatch it with whatever changes you need. But a simple "sys.modules['threading'] = QYZlib.threaders" will work. Of course, how *well* this works depends also on how well that module manages to masquerade as the threading module, but I'm sure you've figured that part out :) ChrisA From antoon.pardon at vub.be Tue Dec 27 08:25:00 2022 From: antoon.pardon at vub.be (Antoon Pardon) Date: Tue, 27 Dec 2022 14:25:00 +0100 Subject: How make your module substitute a python stdlib module. In-Reply-To: References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> <20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be> Message-ID: <302d8b3c-86b2-ebb7-84ff-8d290b30af35@vub.be> Op 27/12/2022 om 13:46 schreef Chris Angelico: > On Tue, 27 Dec 2022 at 23:28, Antoon Pardon wrote: >> At the moment I am happy with a solution that once the programmer has >> imported from QYZlib.threaders that module will used as the threading >> module. >> > Oh! If that's all you need, then yes, a simple patch of sys.modules > will work. You'll have to make sure you get your module imported > before anything else pulls up the vanilla one, though. Otherwise, your > only option is to keep the existing module object and monkeypatch it > with whatever changes you need. > > But a simple "sys.modules['threading'] = QYZlib.threaders" will work. > Of course, how *well* this works depends also on how well that module > manages to masquerade as the threading module, but I'm sure you've > figured that part out :) Well it is what will work for the moment. Thanks for the confirmation this will indeed work. -- Antoon Pardon. From nntp.mbourne at spamgourmet.com Tue Dec 27 08:37:08 2022 From: nntp.mbourne at spamgourmet.com (Mark Bourne) Date: Tue, 27 Dec 2022 13:37:08 +0000 Subject: How make your module substitute a python stdlib module. References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> Message-ID: Antoon Pardon wrote: > > > Op 27/12/2022 om 11:37 schreef Chris Angelico: >> On Tue, 27 Dec 2022 at 21:29, Antoon Pardon wrote: >>> OK, I am writing an alternative for the threading module. What I would >>> like to know is how I can get some library modules call my alternative >>> instead of the threading module. >>> >>> For instance there is the logging module, it can log the thread name. So >>> I would like to know how I can get the logging module to call the >>> function from my module to get the current_thread, instead of it calling >>> "current_thread" from the threading module. >> Easy: make sure your module is called "threading.py" and is earlier in >> the path than the standard library. In fact, it's so easy that people >> do it unintentionally all the time... Generally, the current directory >> (or the script directory) is the first entry in sys.path, so that's a >> good place to put it. > > Well I had hope for a somewhat more selective solution. The intention is > to have a number of modules collected in a package where this module is > one of and the package is available via the "installed" search path. > > So the programmer should just be able to choose to write his code with > either: > > ??? from threading import Thread > > or > > ??? from QYZlib.threaders import Thread In that case, it sounds like you don't want to always replace the logging module's behaviour, since code might use the standard threading module. You might also need to consider that a mix of both the standard threading module and yours might be used (particularly if using other libraries which create their own threads using the standard module). It might be better for your module to provide a custom `logging.Filter` subclass, which replaces the `thread` and `threadName` attributes of the `LogRecord` with your threading module's idea of the thread ID. Then applications using your threading module would configure the `logging` module to use your filter, while code using the standard threading module can continue as normal. Despite the name, logging filters can also modify log records, not just filter whether or not they're logged. It might even be desirable to leave the original `thread` and `threadName` attributes unchanged and add new attributes to the `LogRecord` for your module's idea of threads (e.g. `myThread` and `myThreadName`). I think using `%(myThread)d` and `%(myThreadName)s` in the log format string would use those attributes, without needing a custom formatter. That would allow both thread IDs to be logged, in case a mix of standard threads and your threads is used. -- Mark. From dieter at handshake.de Tue Dec 27 13:46:38 2022 From: dieter at handshake.de (Dieter Maurer) Date: Tue, 27 Dec 2022 19:46:38 +0100 Subject: How make your module substitute a python stdlib module. In-Reply-To: <302d8b3c-86b2-ebb7-84ff-8d290b30af35@vub.be> References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> <20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be> <302d8b3c-86b2-ebb7-84ff-8d290b30af35@vub.be> Message-ID: <25515.15758.806652.162959@ixdm.fritz.box> Antoon Pardon wrote at 2022-12-27 14:25 +0100: > ... >> But a simple "sys.modules['threading'] = QYZlib.threaders" will work. >> Of course, how *well* this works depends also on how well that module >> manages to masquerade as the threading module, but I'm sure you've >> figured that part out :) > >Well it is what will work for the moment. Thanks for the confirmation >this will indeed work. If you need to change a module in minor ways (e.g. only provide a custom `thread_ident` function), you can use a technique called "monkey patching" (which is patching at runtime). You can usually assign new values to module variables. Thus, you yould try `threading.thread_ident = `. This would affect most uses of the function -- which may not be a good idea. Alternatively, you could monkey patch the `logging` module. Look at its code and find out whether it accesses the function directly or indirectly via `threading`. In the first case, you would monkey patch the function, in the second the `threading` variable. You could also use `dm.reuse` (a package maintained on PyPI) to override the method using the function. This way, your change would be even more localized. From list1 at tompassin.net Tue Dec 27 10:49:45 2022 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 27 Dec 2022 10:49:45 -0500 Subject: How make your module substitute a python stdlib module. In-Reply-To: <302d8b3c-86b2-ebb7-84ff-8d290b30af35@vub.be> References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> <20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be> <302d8b3c-86b2-ebb7-84ff-8d290b30af35@vub.be> Message-ID: On 12/27/2022 8:25 AM, Antoon Pardon wrote: > > > Op 27/12/2022 om 13:46 schreef Chris Angelico: >> On Tue, 27 Dec 2022 at 23:28, Antoon Pardon? wrote: >>> At the moment I am happy with a solution that once the programmer has >>> imported from QYZlib.threaders that module will used as the threading >>> module. >>> >> Oh! If that's all you need, then yes, a simple patch of sys.modules >> will work. You'll have to make sure you get your module imported >> before anything else pulls up the vanilla one, though. Otherwise, your >> only option is to keep the existing module object and monkeypatch it >> with whatever changes you need. >> >> But a simple "sys.modules['threading'] = QYZlib.threaders" will work. >> Of course, how *well* this works depends also on how well that module >> manages to masquerade as the threading module, but I'm sure you've >> figured that part out :) > > Well it is what will work for the moment. Thanks for the confirmation > this will indeed work. What you **should not** do is to make other modules use your code when they think they are using the standard library. Raymond Chen in The Old New Thing blog often writes about users who want to do a basically similar thing. He always asks "What if some other program wants to do the same thing?" One case was when a developer wanted his program's icon to force itself to be at the top position in the Windows task bar. "What if another program tried this too?" The two would keep trying to displace each other at the top position. If you set the PYTHONPATH environmental variable, you can put any directory you like to be at the start of the module search path after the current directory. Perhaps this would be enough for your use case? From antoon.pardon at vub.be Wed Dec 28 05:39:08 2022 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 28 Dec 2022 11:39:08 +0100 Subject: How make your module substitute a python stdlib module. In-Reply-To: References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> <20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be> <302d8b3c-86b2-ebb7-84ff-8d290b30af35@vub.be> Message-ID: Op 27/12/2022 om 16:49 schreef Thomas Passin: > On 12/27/2022 8:25 AM, Antoon Pardon wrote: >> >> >> Op 27/12/2022 om 13:46 schreef Chris Angelico: >>> On Tue, 27 Dec 2022 at 23:28, Antoon Pardon? >>> wrote: >>>> At the moment I am happy with a solution that once the programmer has >>>> imported from QYZlib.threaders that module will used as the threading >>>> module. >>>> >>> Oh! If that's all you need, then yes, a simple patch of sys.modules >>> will work. You'll have to make sure you get your module imported >>> before anything else pulls up the vanilla one, though. Otherwise, your >>> only option is to keep the existing module object and monkeypatch it >>> with whatever changes you need. >>> >>> But a simple "sys.modules['threading'] = QYZlib.threaders" will work. >>> Of course, how *well* this works depends also on how well that module >>> manages to masquerade as the threading module, but I'm sure you've >>> figured that part out :) >> >> Well it is what will work for the moment. Thanks for the confirmation >> this will indeed work. > > > What you **should not** do is to make other modules use your code when > they think they are using the standard library. Raymond Chen in The > Old New Thing blog often writes about users who want to do a basically > similar thing. He always asks "What if some other program wants to do > the same thing?"? One case was when a developer wanted his program's > icon to force itself to be at the top position in the Windows task > bar. "What if another program tried this too?"? The two would keep > trying to displace each other at the top position. > > If you set the PYTHONPATH environmental variable, you can put any > directory you like to be at the start of the module search path after > the current directory.? Perhaps this would be enough for your use case? But if I put a threading.py file in that directory, it would make other modules use my code when they "think" they are using the standard library. The problem is that the logging module uses threading, but doesn't allow you to specify which threading module to use. So if you want to use an alternative, you either have to do things like this, or copy the logging packages into your project and adapt it to use your alternative. From list1 at tompassin.net Wed Dec 28 10:55:51 2022 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 28 Dec 2022 10:55:51 -0500 Subject: How make your module substitute a python stdlib module. In-Reply-To: References: <9ac8fb4f-b998-e7cd-6499-e3427e42e420@vub.be> <909b8fd7-de13-1945-63a5-f71d286a78a4@vub.be> <20a11b92-c2c9-e06f-07e9-44a42391ee3f@vub.be> <302d8b3c-86b2-ebb7-84ff-8d290b30af35@vub.be> Message-ID: <46619686-a011-f7e9-b7d5-b8b9790fb7b0@tompassin.net> On 12/28/2022 5:39 AM, Antoon Pardon wrote: > Op 27/12/2022 om 16:49 schreef Thomas Passin: >> On 12/27/2022 8:25 AM, Antoon Pardon wrote: >>> >>> >>> Op 27/12/2022 om 13:46 schreef Chris Angelico: >>>> On Tue, 27 Dec 2022 at 23:28, Antoon Pardon >>>> wrote: >>>>> At the moment I am happy with a solution that once the programmer has >>>>> imported from QYZlib.threaders that module will used as the threading >>>>> module. >>>>> >>>> Oh! If that's all you need, then yes, a simple patch of sys.modules >>>> will work. You'll have to make sure you get your module imported >>>> before anything else pulls up the vanilla one, though. Otherwise, your >>>> only option is to keep the existing module object and monkeypatch it >>>> with whatever changes you need. >>>> >>>> But a simple "sys.modules['threading'] = QYZlib.threaders" will work. >>>> Of course, how *well* this works depends also on how well that module >>>> manages to masquerade as the threading module, but I'm sure you've >>>> figured that part out :) >>> >>> Well it is what will work for the moment. Thanks for the confirmation >>> this will indeed work. >> >> >> What you **should not** do is to make other modules use your code when >> they think they are using the standard library. Raymond Chen in The >> Old New Thing blog often writes about users who want to do a basically >> similar thing. He always asks "What if some other program wants to do >> the same thing?"? One case was when a developer wanted his program's >> icon to force itself to be at the top position in the Windows task >> bar. "What if another program tried this too?"? The two would keep >> trying to displace each other at the top position. >> >> If you set the PYTHONPATH environmental variable, you can put any >> directory you like to be at the start of the module search path after >> the current directory.? Perhaps this would be enough for your use case? > > But if I put a threading.py file in that directory, it would make other > modules use my code when they "think" they are using the standard library. > > The problem is that the logging module uses threading, but doesn't allow > you to specify which threading module to use. So if you want to use an > alternative, you either have to do things like this, or copy the logging > packages into your project and adapt it to use your alternative. In that case, I think your best bet would be to write wrappers for the threading classes or functions you want to use. Your wrappers would import from the threading module and could then produce the behavior you want. From alexander.richert at noaa.gov Wed Dec 28 13:42:29 2022 From: alexander.richert at noaa.gov (Alexander Richert - NOAA Affiliate) Date: Wed, 28 Dec 2022 10:42:29 -0800 Subject: Possible re bug when using ".*" Message-ID: In a couple recent versions of Python (including 3.8 and 3.10), the following code: import re print(re.sub(".*", "replacement", "pattern")) yields the output "replacementreplacement". This behavior does not occur in 3.6. Which behavior is the desired one? Perhaps relatedly, I noticed that even in 3.6, the code print(re.findall(".*","pattern")) yields ['pattern',''] which is not what I was expecting. Thanks, Alex Richert -- Alexander Richert, PhD *RedLine Performance Systems* From roel at roelschroeven.net Wed Dec 28 13:59:09 2022 From: roel at roelschroeven.net (Roel Schroeven) Date: Wed, 28 Dec 2022 19:59:09 +0100 Subject: Possible re bug when using ".*" In-Reply-To: References: Message-ID: <2be03a38-87af-a064-1c67-69ba627f7c4f@roelschroeven.net> Alexander Richert - NOAA Affiliate via Python-list schreef op 28/12/2022 om 19:42: > In a couple recent versions of Python (including 3.8 and 3.10), the > following code: > import re > print(re.sub(".*", "replacement", "pattern")) > yields the output "replacementreplacement". > > This behavior does not occur in 3.6. > > Which behavior is the desired one? Perhaps relatedly, I noticed that even > in 3.6, the code > print(re.findall(".*","pattern")) > yields ['pattern',''] which is not what I was expecting. The documentation for re.sub() and re.findall() has these notes: "Changed in version 3.7: Empty matches for the pattern are replaced when adjacent to a previous non-empty match." and "Changed in version 3.7: Non-empty matches can now start just after a previous empty match." That's probably describes the behavior you're seeing. ".*" first matches "pattern", which is a non-empty match; then it matches the empty string at the end, which is an empty match but is replaced because it is adjacent to a non-empty match. Seems somewhat counter-intuitive to me, but AFAICS it's the intended behavior. -- "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." -- Douglas Adams From roel at roelschroeven.net Wed Dec 28 14:03:04 2022 From: roel at roelschroeven.net (Roel Schroeven) Date: Wed, 28 Dec 2022 20:03:04 +0100 Subject: Possible re bug when using ".*" In-Reply-To: <2be03a38-87af-a064-1c67-69ba627f7c4f@roelschroeven.net> References: <2be03a38-87af-a064-1c67-69ba627f7c4f@roelschroeven.net> Message-ID: Roel Schroeven schreef op 28/12/2022 om 19:59: > Alexander Richert - NOAA Affiliate via Python-list schreef op > 28/12/2022 om 19:42: >> In a couple recent versions of Python (including 3.8 and 3.10), the >> following code: >> import re >> print(re.sub(".*", "replacement", "pattern")) >> yields the output "replacementreplacement". >> >> This behavior does not occur in 3.6. >> >> Which behavior is the desired one? Perhaps relatedly, I noticed that even >> in 3.6, the code >> print(re.findall(".*","pattern")) >> yields ['pattern',''] which is not what I was expecting. > The documentation for re.sub() and re.findall() has these notes: > "Changed in version 3.7: Empty matches for the pattern are replaced > when adjacent to a previous non-empty match." and "Changed in version > 3.7: Non-empty matches can now start just after a previous empty match." > That's probably describes the behavior you're seeing. ".*" first > matches "pattern", which is a non-empty match; then it matches the > empty string at the end, which is an empty match but is replaced > because it is adjacent to a non-empty match. > > Seems somewhat counter-intuitive to me, but AFAICS it's the intended > behavior. For what it's worth, there's some discussion about this in this Github issue: https://github.com/python/cpython/issues/76489 -- "Je ne suis pas d?accord avec ce que vous dites, mais je me battrai jusqu?? la mort pour que vous ayez le droit de le dire." -- Attribu? ? Voltaire "I disapprove of what you say, but I will defend to the death your right to say it." -- Attributed to Voltaire "Ik ben het niet eens met wat je zegt, maar ik zal je recht om het te zeggen tot de dood toe verdedigen" -- Toegeschreven aan Voltaire From python at mrabarnett.plus.com Wed Dec 28 14:07:06 2022 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 28 Dec 2022 19:07:06 +0000 Subject: Possible re bug when using ".*" In-Reply-To: References: Message-ID: <014c86f6-d181-ec5c-3908-88dabd52a966@mrabarnett.plus.com> On 2022-12-28 18:42, Alexander Richert - NOAA Affiliate via Python-list wrote: > In a couple recent versions of Python (including 3.8 and 3.10), the > following code: > import re > print(re.sub(".*", "replacement", "pattern")) > yields the output "replacementreplacement". > > This behavior does not occur in 3.6. > > Which behavior is the desired one? Perhaps relatedly, I noticed that even > in 3.6, the code > print(re.findall(".*","pattern")) > yields ['pattern',''] which is not what I was expecting. > It's not a bug, it's a change in behaviour to bring it more into line with other regex implementations in other languages. From ethan at stoneleaf.us Wed Dec 28 15:37:20 2022 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 28 Dec 2022 12:37:20 -0800 Subject: Possible re bug when using ".*" In-Reply-To: <014c86f6-d181-ec5c-3908-88dabd52a966@mrabarnett.plus.com> References: <014c86f6-d181-ec5c-3908-88dabd52a966@mrabarnett.plus.com> Message-ID: On 12/28/22 11:07, MRAB wrote: > On 2022-12-28 18:42, Alexander Richert - NOAA Affiliate via Python-list wrote: >> ? In a couple recent versions of Python (including 3.8 and 3.10), the >> following code: >> import re >> print(re.sub(".*", "replacement", "pattern")) >> yields the output "replacementreplacement". >> >> This behavior does not occur in 3.6. >> >> Which behavior is the desired one? Perhaps relatedly, I noticed that even >> in 3.6, the code >> print(re.findall(".*","pattern")) >> yields ['pattern',''] which is not what I was expecting. >> > It's not a bug, it's a change in behaviour to bring it more into line with other regex implementations in other languages. The new behavior makes no sense to me, but better to be consistent with the other regex engines than not -- I still get thrown off by vim's regex. -- ~Ethan~ From barry at barrys-emacs.org Thu Dec 29 08:17:34 2022 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 29 Dec 2022 13:17:34 +0000 Subject: Possible re bug In-Reply-To: References: Message-ID: <07801d28-76c1-a8dc-1c5c-c74d5fff2a84@barrys-emacs.org> Please please fix you email client so that your replies stay with the emails you are replying to. Barry On 28/12/2022 19:09, Stefan Ram wrote: > Alexander Richert writes: > |print(re.findall(".*","pattern")) > |yields ['pattern',''] which is not what I was expecting. > > The asterisk is "greedy", so I agree that it should consume > /everything/ including all the empty strings at the end. > To work around this, one can use '^.*' (no smiley intended). > > From supersellerninja at gmail.com Fri Dec 30 02:55:36 2022 From: supersellerninja at gmail.com (Mor yosef) Date: Fri, 30 Dec 2022 09:55:36 +0200 Subject: help Message-ID: Hello guys, i install python 3.11.1, and i have google chrome so i download the Webdriver Chrome and i just add it on my c:// driver and when i add some script on my desktop i try to run it from the terminal and all the time i receive this error message : maybe you guys can help me with this one? when i add some random code the terminal like "python -m webbrowser https://www.google.com" it's just works (it's open the website in new tab) Regards Mor yosef From boblatest at yahoo.com Fri Dec 30 08:48:01 2022 From: boblatest at yahoo.com (Robert Latest) Date: 30 Dec 2022 13:48:01 GMT Subject: Why can't the pointer in a PyCapsule be NULL? Message-ID: Hi all, the question is in the subject. I'd like the pointer to be able to be NULL because that would make my code slightly cleaner. No big deal though. From boblatest at yahoo.com Fri Dec 30 12:59:10 2022 From: boblatest at yahoo.com (Robert Latest) Date: 30 Dec 2022 17:59:10 GMT Subject: Why can't the pointer in a PyCapsule be NULL? References: Message-ID: Stefan Ram wrote: > Robert Latest writes: >>the question is in the subject. I'd like the pointer to be able to be NULL >>because that would make my code slightly cleaner. No big deal though. > > In Usenet, it is considered good style to have all relevant > content in the body. Makes sense. > . On a superficial level, the answer is: "Because > PyCapsule_GetPointer uses NULL to indicate failure." Makes sense, too. Thanks. From arequipeno at gmail.com Fri Dec 30 16:41:19 2022 From: arequipeno at gmail.com (Ian Pilcher) Date: Fri, 30 Dec 2022 15:41:19 -0600 Subject: set.add() doesn't replace equal element Message-ID: I just discovered this behavior, which is problematic for my particular use. Is there a different set API (or operator) that can be used to add an element to a set, and replace any equal element? If not, am I correct that I should call set.discard() before calling set.add() to achieve the behavior that I want? -- ======================================================================== Google Where SkyNet meets Idiocracy ======================================================================== From pbryan at anode.ca Fri Dec 30 16:47:59 2022 From: pbryan at anode.ca (Paul Bryan) Date: Fri, 30 Dec 2022 13:47:59 -0800 Subject: set.add() doesn't replace equal element In-Reply-To: References: Message-ID: What kind of elements are being added to the set? Can you show reproducible sample code? On Fri, Dec 30 2022 at 03:41:19 PM -0600, Ian Pilcher wrote: > I just discovered this behavior, which is problematic for my > particular > use. Is there a different set API (or operator) that can be used to > add an element to a set, and replace any equal element? > > If not, am I correct that I should call set.discard() before calling > set.add() to achieve the behavior that I want? > > -- > ======================================================================== > Google Where SkyNet meets > Idiocracy > ======================================================================== > -- > From rosuav at gmail.com Fri Dec 30 16:58:20 2022 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Dec 2022 08:58:20 +1100 Subject: set.add() doesn't replace equal element In-Reply-To: References: Message-ID: On Sat, 31 Dec 2022 at 08:42, Ian Pilcher wrote: > > I just discovered this behavior, which is problematic for my particular > use. Is there a different set API (or operator) that can be used to > add an element to a set, and replace any equal element? > > If not, am I correct that I should call set.discard() before calling > set.add() to achieve the behavior that I want? > Use a dictionary. Initially, map everything to itself. You can then replace things with the new keys: >>> stuff = {} >>> stuff[1] = 1 >>> stuff[4] = 4 >>> stuff[True] = True >>> stuff[2] = 2 >>> stuff[4.0] = 4.0 >>> stuff {1: True, 4: 4.0, 2: 2} To see what's in your set, look at the dictionary's values. They will replace any equal elements, leaving the keys unchanged. ChrisA From avi.e.gross at gmail.com Fri Dec 30 17:03:54 2022 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Fri, 30 Dec 2022 17:03:54 -0500 Subject: set.add() doesn't replace equal element In-Reply-To: References: Message-ID: <002b01d91c9a$9be04d90$d3a0e8b0$@gmail.com> Ian, Do you have some examples of things you can put in a set that you consider equal but want to store in the set INSTEAD of any current element? What follows is some thoughts on some methods you could build yourself. Others re possible and someone else may present you with a module that does what you want. In principle, if you had a function that produced a canonical version of an argument as a sort of FIRST choice, you might still have to do some serious work. Assuming alpha, beta and gamma are all what you define as equal, such as if you consider the value of a string like "32.00" to be equal to "32.000000000" or even to "64/2", then you can get ALL elements of the set and call your function on it and compare it to the function applied to your new proposed set addition. So f(alpha)and f(beta) and f(gamma) would by definition return the same result, albeit that might be an integer like 32, or a string of "32.0" or whatever you need. Now are you sure the set has no "duplicates" already per your algorithm? If you are, your algorithm would need to loop on all keys and if a key matches using f() and the newer version is not otherwise identical, remove the old and insert the new. You can break out of the loop at that point BUT if there is no uniqueness guarantee, you need to process all keys every time. A possible improvement would be to consider various mixed approaches. You could use a dictionary where the keys are f(whatever) and the values are the current "whatever" as one example. The "set" then would be the values of the dictionary when you need that view, and the dictionary as a whole when you want to add or delete. If you needed operations like union and intersect, it may take more work. And, of course, you can maintain two sets. The other set would contain only f(whatever) while the first would contain the "whatever"s. What you are describing may have been implemented with a concept like partitions. An example might be the partitioning of numbers modulo N so that numbers are considered "equal" if they leave the same remainder when divided by N. Rather than use a set directly, this could be better done by creating an object that manages internal data structures so asking it to add a new number results in it calculating the remainder, seeing if it is in use, and replacing it with the latest if needed. Avi -----Original Message----- From: Python-list On Behalf Of Ian Pilcher Sent: Friday, December 30, 2022 4:41 PM To: python-list at python.org Subject: set.add() doesn't replace equal element I just discovered this behavior, which is problematic for my particular use. Is there a different set API (or operator) that can be used to add an element to a set, and replace any equal element? If not, am I correct that I should call set.discard() before calling set.add() to achieve the behavior that I want? -- ======================================================================== Google Where SkyNet meets Idiocracy ======================================================================== -- https://mail.python.org/mailman/listinfo/python-list From cgrace.chris at gmail.com Fri Dec 30 17:13:48 2022 From: cgrace.chris at gmail.com (Chris Grace) Date: Fri, 30 Dec 2022 17:13:48 -0500 Subject: help In-Reply-To: References: Message-ID: Hello, The mailing list strips all images. We cannot see the error you posted. I'd recommend posting it in text form. What is the script you are running? What do you expect your script to do? On Fri, Dec 30, 2022, 3:14 PM Mor yosef wrote: > Hello guys, > i install python 3.11.1, and i have google chrome so i download the > Webdriver Chrome > and i just add it on my c:// driver and when i add some script on my > desktop i try to run it from the terminal and all the time i receive this > error message : maybe you guys can help me with this one? > when i add some random code the terminal like "python -m webbrowser > https://www.google.com" it's just works (it's open the website in new tab) > Regards > Mor yosef > -- > https://mail.python.org/mailman/listinfo/python-list > From arequipeno at gmail.com Fri Dec 30 17:27:56 2022 From: arequipeno at gmail.com (Ian Pilcher) Date: Fri, 30 Dec 2022 16:27:56 -0600 Subject: set.add() doesn't replace equal element In-Reply-To: References: Message-ID: On 12/30/22 15:47, Paul Bryan wrote: > What kind of elements are being added to the set? Can you show > reproducible sample code? The objects in question are DHCP leases. I consider them "equal" if the lease address (or IPv6 prefix) is equal, even if the timestamps have changed. That code is not small, but it's easy to demonstrate the behavior. >>> import datetime >>> class Foo(object): ... def __init__(self, index): ... self.index = index ... self.timestamp = datetime.datetime.now() ... def __eq__(self, other): ... return type(other) is Foo and other.index == self.index ... def __hash__(self): ... return hash(self.index) ... def __repr__(self): ... return f'Foo({self.index}) created at {str(self.timestamp)}' ... >>> f1 = Foo(1) >>> s = { f1 } >>> s {Foo(1) created at 2022-12-30 16:24:12.352908} >>> f2 = Foo(1) >>> f2 Foo(1) created at 2022-12-30 16:24:35.489208 >>> s.add(f2) >>> s {Foo(1) created at 2022-12-30 16:24:12.352908} -- ======================================================================== Google Where SkyNet meets Idiocracy ======================================================================== From rosuav at gmail.com Fri Dec 30 17:46:45 2022 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 31 Dec 2022 09:46:45 +1100 Subject: set.add() doesn't replace equal element In-Reply-To: References: Message-ID: On Sat, 31 Dec 2022 at 09:29, Ian Pilcher wrote: > > On 12/30/22 15:47, Paul Bryan wrote: > > What kind of elements are being added to the set? Can you show > > reproducible sample code? > > The objects in question are DHCP leases. I consider them "equal" if > the lease address (or IPv6 prefix) is equal, even if the timestamps have > changed. That code is not small, but it's easy to demonstrate the > behavior. Seems the more logical approach would be to use a dictionary mapping the lease address/prefix to the timestamp? The part that contributes to the equality check is the key, and everything else is the value. ChrisA From pbryan at anode.ca Fri Dec 30 18:00:15 2022 From: pbryan at anode.ca (Paul Bryan) Date: Fri, 30 Dec 2022 15:00:15 -0800 Subject: set.add() doesn't replace equal element In-Reply-To: References: Message-ID: It seems to me like you have to ideas of what "equal" means. You want to update a "non-equal/equal" value in the set (because of a different time stamp). If you truly considered them equal, the time stamp would be irrelevant and updating the value in the set would be unnecessary. I would: a) /not/ consider two different leases with two different time stamps to be equal, and b) as already mentioned, store them in another data structure like a dictionary. Not knowing the specifics of the DHCP object structure, if a DHCP lease object has some immutable key or other durable immutable attribute, I would be inclined to make that the dictionary key, and store the DHCP object as the value. On Fri, Dec 30 2022 at 04:27:56 PM -0600, Ian Pilcher wrote: > On 12/30/22 15:47, Paul Bryan wrote: >> What kind of elements are being added to the set? Can you show >> reproducible sample code? > > The objects in question are DHCP leases. I consider them "equal" if > the lease address (or IPv6 prefix) is equal, even if the timestamps > have > changed. That code is not small, but it's easy to demonstrate the > behavior. > > >>> import datetime > >>> class Foo(object): > ... def __init__(self, index): > ... self.index = index > ... self.timestamp = datetime.datetime.now() > ... def __eq__(self, other): > ... return type(other) is Foo and other.index == self.index > ... def __hash__(self): > ... return hash(self.index) > ... def __repr__(self): > ... return f'Foo({self.index}) created at > {str(self.timestamp)}' > ... > >>> f1 = Foo(1) > >>> s = { f1 } > >>> s > {Foo(1) created at 2022-12-30 16:24:12.352908} > >>> f2 = Foo(1) > >>> f2 > Foo(1) created at 2022-12-30 16:24:35.489208 > >>> s.add(f2) > >>> s > {Foo(1) created at 2022-12-30 16:24:12.352908} > > -- > ======================================================================== > Google Where SkyNet meets > Idiocracy > ======================================================================== > From goranikac65 at gmail.com Sat Dec 31 00:45:40 2022 From: goranikac65 at gmail.com (Goran Ikac) Date: Sat, 31 Dec 2022 06:45:40 +0100 Subject: NoneType List Message-ID: Happy New Year, everybody! I'm new in the Python List, new in Python world, and new in coding. A few days (weeks?) ago, I faced a problem trying to write a program for an exercise. I asked for help and nobody answered. In the meantime, I found a part of the solution, but a part still remains a mystery for me. Please run this small snippet, and help. Thanks a = [1, 2] print() print("a ==", a) print("type(a) is", type(a)) b = a.append(3) print("\nb =", "a.append(3)") print("b ==", b) print("type(b) is", type(b)) c = ['1', '2'] print("\nc ==", c) print("type(c) is", type(c)) d = c.append('3') print("\nd =", "c.append('3')") print("d ==", d) print("type(d) is", type(d)) """ I mean: why b = a.append(something) is the None type, and how to make a new list that contains all the items from a and some new items? I wasn't able to solve it in a few hours :( Now I know: """ crta = '=' print('\n', 4 * ' ', crta * (len('The solution:')), sep='') print(3 * ' ', 'The solution:') print(4 * ' ', crta * (len('The solution:')), sep='') print('\nThe solution is the slice, an element of Python syntax that allows') print('to make a brand new copy of a list, or parts of a list.') print('The slice actually copies the list\'s contents, not the list\'s name:') print() a = [1, 2] print("a ==", a) print("type(a) is", type(a)) b = a[:] print("\nb = a[:]") print("b ==", b) b.append(3) print("\nb =", "b.append(3)") print("b ==", b) print("type(b) is", type(b)) print("\na ==", a) print('But I still don't know why "b = a.append(something)" is the None type.') print('Is there anybody out there?!') From PythonList at DancesWithMice.info Sat Dec 31 03:58:05 2022 From: PythonList at DancesWithMice.info (dn) Date: Sat, 31 Dec 2022 21:58:05 +1300 Subject: NoneType List In-Reply-To: References: Message-ID: On 31/12/2022 18.45, Goran Ikac wrote: > Happy New Year, everybody! > I'm new in the Python List, new in Python world, and new in coding. > A few days (weeks?) ago, I faced a problem trying to write a program for an > exercise. I asked for help and nobody answered. > In the meantime, I found a part of the solution, but a part still remains a > mystery for me. Please run this small snippet, and help. > Thanks > > a = [1, 2] > print() > > print("a ==", a) > print("type(a) is", type(a)) > > b = a.append(3) > > print("b ==", b) > print("type(b) is", type(b)) Please review https://docs.python.org/3/tutorial/datastructures.html It is not immediately obvious to people who are not used to object-oriented programming. As observed, "a" is a list. The list contains a pair of numeric-values. The append is a "method". Methods are functions which belong to classes (let's say). Accordingly, the operation is performed on that class, ie the appending is to the "a" list. This can be proven by adding to the above: print( "\na (appended) =", a ) [1, 2, 3] As far as the expression on the right-hand side of (the equals sign) there is no output-value, hence b == None. For comparison, try: b = a + [ 4 ] and understand why the answer is different, and thus why the first 'problem' behavior works the way it does... print( 'Happy new year!' ) PS are you aware of the Python-Tutor Discussion List? It may be more suited to assisting your learning intentions... -- Regards, =dn From learn2program at gmail.com Sat Dec 31 04:09:04 2022 From: learn2program at gmail.com (Alan Gauld) Date: Sat, 31 Dec 2022 09:09:04 +0000 Subject: NoneType List In-Reply-To: References: Message-ID: On 31/12/2022 05:45, Goran Ikac wrote: > b = a.append(3) > I mean: why b = a.append(something) is the None type, and how to make a new > list that contains all the items from a and some new items? append() like many other collection methods in Python works in place and returns None. But the action has succeeded and 3 will have been appended to list 'a'. So, to create a new list that contains all the old items you could do: newlist = [] # an empty list for item in oldlist: newlist.append(item) This is so common Python has a shorthand form to do this: newlist = [item for item in oldlist] called a list comprehension. And there is an even shorter way using something called slicing: newlist = oldlist[:] # copy oldlist to new. However, as an ex-Smalltalk programmer, I do wish that Python returned self from these methods rather than None so that we could chain them. But sadly it doesn't. -- 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 chris_roysmith at internode.on.net Sat Dec 31 02:09:07 2022 From: chris_roysmith at internode.on.net (Chris Roy-Smith) Date: Sat, 31 Dec 2022 18:09:07 +1100 Subject: NoneType List In-Reply-To: References: Message-ID: <143a64ee-8c85-3f34-1d95-44e93f705c25@internode.on.net> On 31/12/22 16:45, Goran Ikac wrote: > Happy New Year, everybody! > I'm new in the Python List, new in Python world, and new in coding. > A few days (weeks?) ago, I faced a problem trying to write a program for an > exercise. I asked for help and nobody answered. > In the meantime, I found a part of the solution, but a part still remains a > mystery for me. Please run this small snippet, and help. > Thanks > > a = [1, 2] > print() > > print("a ==", a) > print("type(a) is", type(a)) > > b = a.append(3) append is not used that way, append is a method, not a function. have a look at https://www.w3schools.com/python/ref_list_append.asp. regards, Chris > print("\nb =", "a.append(3)") > print("b ==", b) > print("type(b) is", type(b)) > > c = ['1', '2'] > print("\nc ==", c) > print("type(c) is", type(c)) > > d = c.append('3') > print("\nd =", "c.append('3')") > print("d ==", d) > print("type(d) is", type(d)) > > """ > I mean: why b = a.append(something) is the None type, and how to make a new > list > that contains all the items from a and some new items? > I wasn't able to solve it in a few hours :( > Now I know: > """ > > crta = '=' > print('\n', 4 * ' ', crta * (len('The solution:')), sep='') > print(3 * ' ', 'The solution:') > print(4 * ' ', crta * (len('The solution:')), sep='') > print('\nThe solution is the slice, an element of Python syntax that > allows') > print('to make a brand new copy of a list, or parts of a list.') > print('The slice actually copies the list\'s contents, not the list\'s > name:') > > print() > a = [1, 2] > print("a ==", a) > print("type(a) is", type(a)) > > b = a[:] > print("\nb = a[:]") > print("b ==", b) > b.append(3) > print("\nb =", "b.append(3)") > print("b ==", b) > print("type(b) is", type(b)) > print("\na ==", a) > > print('But I still don't know why "b = a.append(something)" is the None > type.') > print('Is there anybody out there?!') From gweatherby at uchc.edu Sat Dec 31 10:33:31 2022 From: gweatherby at uchc.edu (Weatherby,Gerard) Date: Sat, 31 Dec 2022 15:33:31 +0000 Subject: NoneType List In-Reply-To: References: Message-ID: Just use the addition operator: a = [1,2] a = a + [3,4] a is now [1, 2, 3, 4] From: Python-list on behalf of Goran Ikac Date: Saturday, December 31, 2022 at 1:53 AM To: python-list at python.org Subject: NoneType List *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. *** Happy New Year, everybody! I'm new in the Python List, new in Python world, and new in coding. A few days (weeks?) ago, I faced a problem trying to write a program for an exercise. I asked for help and nobody answered. In the meantime, I found a part of the solution, but a part still remains a mystery for me. Please run this small snippet, and help. Thanks a = [1, 2] print() print("a ==", a) print("type(a) is", type(a)) b = a.append(3) print("\nb =", "a.append(3)") print("b ==", b) print("type(b) is", type(b)) c = ['1', '2'] print("\nc ==", c) print("type(c) is", type(c)) d = c.append('3') print("\nd =", "c.append('3')") print("d ==", d) print("type(d) is", type(d)) """ I mean: why b = a.append(something) is the None type, and how to make a new list that contains all the items from a and some new items? I wasn't able to solve it in a few hours :( Now I know: """ crta = '=' print('\n', 4 * ' ', crta * (len('The solution:')), sep='') print(3 * ' ', 'The solution:') print(4 * ' ', crta * (len('The solution:')), sep='') print('\nThe solution is the slice, an element of Python syntax that allows') print('to make a brand new copy of a list, or parts of a list.') print('The slice actually copies the list\'s contents, not the list\'s name:') print() a = [1, 2] print("a ==", a) print("type(a) is", type(a)) b = a[:] print("\nb = a[:]") print("b ==", b) b.append(3) print("\nb =", "b.append(3)") print("b ==", b) print("type(b) is", type(b)) print("\na ==", a) print('But I still don't know why "b = a.append(something)" is the None type.') print('Is there anybody out there?!') -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!mv_VSTDWgnB7T16IHcBh7TaT3whji-SsPeUtaBmHdSsIJknJZ16qeALOSjCkjCmqheE1pJ-47P_mwAauV-0TjQo$ From list1 at tompassin.net Sat Dec 31 10:50:13 2022 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 31 Dec 2022 10:50:13 -0500 Subject: NoneType List Message-ID: <8f6d265a-c484-b566-2e13-c1c791b20ebf@tompassin.net> Happy New Year, everybody! I'm new in the Python List, new in Python world, and new in coding. A few days (weeks?) ago, I faced a problem trying to write a program for an exercise. I asked for help and nobody answered. In the meantime, I found a part of the solution, but a part still remains a mystery for me. Please run this small snippet, and help. Thanks a = [1, 2] print() print("a ==", a) print("type(a) is", type(a)) b = a.append(3) print("\nb =", "a.append(3)") print("b ==", b) print("type(b) is", type(b)) c = ['1', '2'] print("\nc ==", c) print("type(c) is", type(c)) d = c.append('3') print("\nd =", "c.append('3')") print("d ==", d) print("type(d) is", type(d)) """ I mean: why b = a.append(something) is the None type, and how to make a new list that contains all the items from a and some new items? I wasn't able to solve it in a few hours :( Now I know: """ crta = '=' print('\n', 4 * ' ', crta * (len('The solution:')), sep='') print(3 * ' ', 'The solution:') print(4 * ' ', crta * (len('The solution:')), sep='') print('\nThe solution is the slice, an element of Python syntax that allows') print('to make a brand new copy of a list, or parts of a list.') print('The slice actually copies the list\'s contents, not the list\'s name:') print() a = [1, 2] print("a ==", a) print("type(a) is", type(a)) b = a[:] print("\nb = a[:]") print("b ==", b) b.append(3) print("\nb =", "b.append(3)") print("b ==", b) print("type(b) is", type(b)) print("\na ==", a) print('But I still don't know why "b = a.append(something)" is the None type.') print('Is there anybody out there?!') -- https://mail.python.org/mailman/listinfo/python-list From arequipeno at gmail.com Sat Dec 31 11:41:32 2022 From: arequipeno at gmail.com (Ian Pilcher) Date: Sat, 31 Dec 2022 10:41:32 -0600 Subject: set.add() doesn't replace equal element In-Reply-To: References: Message-ID: <07e467b1-630d-51d9-f811-257ea21f02d1@gmail.com> On 12/30/22 17:00, Paul Bryan wrote: > It seems to me like you have to ideas of what "equal" means. You want to > update a "non-equal/equal" value in the set (because of a different time > stamp). If you truly considered them equal, the time stamp would be > irrelevant and updating the value in the set would be unnecessary. > > I would: > > a) /not/ consider two different leases with two different time stamps to > be equal, and > b) as already mentioned, store them in another data structure like a > dictionary. > > Not knowing the specifics of the DHCP object structure, if a DHCP lease > object has some immutable key or other durable immutable attribute, I > would be inclined to make that the dictionary key, and store the DHCP > object as the value. I have come to the conclusion that you are correct. Thanks! -- ======================================================================== Google Where SkyNet meets Idiocracy ======================================================================== From list1 at tompassin.net Sat Dec 31 12:07:25 2022 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 31 Dec 2022 12:07:25 -0500 Subject: NoneType List In-Reply-To: <8f6d265a-c484-b566-2e13-c1c791b20ebf@tompassin.net> References: <8f6d265a-c484-b566-2e13-c1c791b20ebf@tompassin.net> Message-ID: <3eb7480c-88f7-72cf-af66-c0072928bf3f@tompassin.net> Oops, my reply got lost somehow. Here it is: Everyone's answer to date has been too complicated. What is going on is that list.append() changes the list in place. It returns nothing. If you want to append an item and then assign the result to a new list, you have to do just that: l1.append(item) # If we want a *copy* of the appended list: l2 = l1[:] # Changes to l2 will not change l1 # If we want another name for the appended list: l2 = l1 # Changes to l2 will change l1 since they are the same object list.sort() also operates in place. There is a function sorted() that returns the sorted list (without changing the original list). The same thing is true of set.add(). The set is changed in place, and nothing is returned. On 12/31/2022 10:50 AM, Thomas Passin wrote: > Happy New Year, everybody! > I'm new in the Python List, new in Python world, and new in coding. > A few days (weeks?) ago, I faced a problem trying to write a program for an > exercise. I asked for help and nobody answered. > In the meantime, I found a part of the solution, but a part still remains a > mystery for me. Please run this small snippet, and help. > Thanks > > a = [1, 2] > print() > > print("a ==", a) > print("type(a) is", type(a)) > > b = a.append(3) > print("\nb =", "a.append(3)") > print("b ==", b) > print("type(b) is", type(b)) > > c = ['1', '2'] > print("\nc ==", c) > print("type(c) is", type(c)) > > d = c.append('3') > print("\nd =", "c.append('3')") > print("d ==", d) > print("type(d) is", type(d)) > > """ > I mean: why b = a.append(something) is the None type, and how to make a new > list > that contains all the items from a and some new items? > I wasn't able to solve it in a few hours :( > Now I know: > """ > > crta = '=' > print('\n', 4 * ' ', crta * (len('The solution:')), sep='') > print(3 * ' ', 'The solution:') > print(4 * ' ', crta * (len('The solution:')), sep='') > print('\nThe solution is the slice, an element of Python syntax that > allows') > print('to make a brand new copy of a list, or parts of a list.') > print('The slice actually copies the list\'s contents, not the list\'s > name:') > > print() > a = [1, 2] > print("a ==", a) > print("type(a) is", type(a)) > > b = a[:] > print("\nb = a[:]") > print("b ==", b) > b.append(3) > print("\nb =", "b.append(3)") > print("b ==", b) > print("type(b) is", type(b)) > print("\na ==", a) > > print('But I still don't know why "b = a.append(something)" is the None > type.') > print('Is there anybody out there?!') From python at mrabarnett.plus.com Sat Dec 31 12:37:39 2022 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 31 Dec 2022 17:37:39 +0000 Subject: NoneType List In-Reply-To: References: Message-ID: <2321d9bc-5eb3-c1b9-0425-020b54dd39e8@mrabarnett.plus.com> On 2022-12-31 05:45, Goran Ikac wrote: > Happy New Year, everybody! > I'm new in the Python List, new in Python world, and new in coding. > A few days (weeks?) ago, I faced a problem trying to write a program for an > exercise. I asked for help and nobody answered. > In the meantime, I found a part of the solution, but a part still remains a > mystery for me. Please run this small snippet, and help. > Thanks > > a = [1, 2] > print() > > print("a ==", a) > print("type(a) is", type(a)) > > b = a.append(3) > print("\nb =", "a.append(3)") > print("b ==", b) > print("type(b) is", type(b)) > > c = ['1', '2'] > print("\nc ==", c) > print("type(c) is", type(c)) > > d = c.append('3') > print("\nd =", "c.append('3')") > print("d ==", d) > print("type(d) is", type(d)) > > """ > I mean: why b = a.append(something) is the None type, and how to make a new > list > that contains all the items from a and some new items? > I wasn't able to solve it in a few hours :( > Now I know: > """ > > crta = '=' > print('\n', 4 * ' ', crta * (len('The solution:')), sep='') > print(3 * ' ', 'The solution:') > print(4 * ' ', crta * (len('The solution:')), sep='') > print('\nThe solution is the slice, an element of Python syntax that > allows') > print('to make a brand new copy of a list, or parts of a list.') > print('The slice actually copies the list\'s contents, not the list\'s > name:') > > print() > a = [1, 2] > print("a ==", a) > print("type(a) is", type(a)) > > b = a[:] > print("\nb = a[:]") > print("b ==", b) > b.append(3) > print("\nb =", "b.append(3)") > print("b ==", b) > print("type(b) is", type(b)) > print("\na ==", a) > > print('But I still don't know why "b = a.append(something)" is the None > type.') > print('Is there anybody out there?!') Methods that modify in-place usually return None. "a.append(something)" modifies (appends to) the list 'a' and returns None. If you want to a new line with something at the end try "b = a + [something]". From PythonList at DancesWithMice.info Sat Dec 31 15:58:35 2022 From: PythonList at DancesWithMice.info (dn) Date: Sun, 1 Jan 2023 09:58:35 +1300 Subject: NoneType List In-Reply-To: References: Message-ID: <2b238dce-3e9f-9bee-27a0-d163cb6c7cef@DancesWithMice.info> On 31/12/2022 18.45, Goran Ikac wrote: ... > A few days (weeks?) ago, I faced a problem trying to write a program for an > exercise. I asked for help and nobody answered. Looking back over the last six months of List-Archives, your name does not appear against a single post. This may explain why "nobody answered". However, ten hours after the above/first message, you posted again. This time as "Thomas Passin". That was followed an hour-or-so later, with a reply-to-self saying: "Everyone's answer to date has been too complicated", and then basically repeating the information previously-provided by a number of contributors. It then goes on to talk about copying, sorting, adding, and even sets. Much of which you had earlier said: "I know". Was there a further question in there? Which part of which answer did you find "too complicated"? Did you try the experiments suggested, and read the references-provided? Please ask a further question detailing what you have understood, and what is still mystifying. Folk here endeavor to be helpful (see also, earlier reference to the Python-Tutor list). When asking a question here, please try to reduce the problem to its simplest form, so that you're not asking volunteers to read multiple-screens of irrelevant code. It will help to ask one question at a time, or to carefully separate multiple questions. Yes, this can be difficult when one is learning. That said, we all started somewhere and are happy to help you to become a valued colleague! -- Regards, =dn From avi.e.gross at gmail.com Sat Dec 31 17:36:59 2022 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 31 Dec 2022 17:36:59 -0500 Subject: NoneType List In-Reply-To: <2b238dce-3e9f-9bee-27a0-d163cb6c7cef@DancesWithMice.info> References: <2b238dce-3e9f-9bee-27a0-d163cb6c7cef@DancesWithMice.info> Message-ID: <006501d91d68$6538dd10$2faa9730$@gmail.com> It depends on what people consider too complicated. I find it a tad complicated when someone posts using two different ID, and then wonders ... The question related to taking a list and extending it and using the result in an assignment statement. There were several inter-related questions people responded to. One was asking why something did not work as expected. Several answers pointed out it was because it was not designed the way expected and reading the manual page or other reference material would help explain that you need to use code the way it was intended and not as you wish it. Other aspects of similar code that do what you expect were shown and you could pick any you liked. A second question some were answering is various ways to get the functionality wanted. Some were simple enough like using "+" and others did seem complex as they showed many variations on copying an object or how to make a subclass that effectively substitutes a method that returns the internally changed object. And, of course, we had the philosophical question of why the feature was designed to not return anything (well, NULL) rather than return the changed object. Returning nothing is arguably slightly more efficient in the many cases where the return value is simply ignored and thus tossed. But as mentioned, it would be nice for some purposes, including chaining, to be able to write something like result = lst.add_ret("item").sort_ret() As mentioned, this can still be easily done using something like: result = sorted(lst + "item") -----Original Message----- From: Python-list On Behalf Of dn Sent: Saturday, December 31, 2022 3:59 PM To: python-list at python.org Subject: Re: NoneType List On 31/12/2022 18.45, Goran Ikac wrote: ... > A few days (weeks?) ago, I faced a problem trying to write a program > for an exercise. I asked for help and nobody answered. Looking back over the last six months of List-Archives, your name does not appear against a single post. This may explain why "nobody answered". However, ten hours after the above/first message, you posted again. This time as "Thomas Passin". That was followed an hour-or-so later, with a reply-to-self saying: "Everyone's answer to date has been too complicated", and then basically repeating the information previously-provided by a number of contributors. It then goes on to talk about copying, sorting, adding, and even sets. Much of which you had earlier said: "I know". Was there a further question in there? Which part of which answer did you find "too complicated"? Did you try the experiments suggested, and read the references-provided? Please ask a further question detailing what you have understood, and what is still mystifying. Folk here endeavor to be helpful (see also, earlier reference to the Python-Tutor list). When asking a question here, please try to reduce the problem to its simplest form, so that you're not asking volunteers to read multiple-screens of irrelevant code. It will help to ask one question at a time, or to carefully separate multiple questions. Yes, this can be difficult when one is learning. That said, we all started somewhere and are happy to help you to become a valued colleague! -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Sat Dec 31 18:32:04 2022 From: list1 at tompassin.net (Thomas Passin) Date: Sat, 31 Dec 2022 18:32:04 -0500 Subject: NoneType List In-Reply-To: <2b238dce-3e9f-9bee-27a0-d163cb6c7cef@DancesWithMice.info> References: <2b238dce-3e9f-9bee-27a0-d163cb6c7cef@DancesWithMice.info> Message-ID: <11625e0f-8975-b929-a2ca-e14ed74a19b0@tompassin.net> On 12/31/2022 3:58 PM, dn wrote: > On 31/12/2022 18.45, Goran Ikac wrote: > ... >> A few days (weeks?) ago, I faced a problem trying to write a program >> for an >> exercise. I asked for help and nobody answered. > > Looking back over the last six months of List-Archives, your name does > not appear against a single post. This may explain why "nobody answered". > > However, ten hours after the above/first message, you posted again. This > time as "Thomas Passin". That message was probably a mistaken one from me. I had composed a reply but through some mental glitch had to re-do it. I managed to send it with the only quoted thread but not the reply I had wanted to include. So I added my reply and sent it again. It was probably confusing, and I'm sorry about that. > That was followed an hour-or-so later, with a > reply-to-self saying: "Everyone's answer to date has been too > complicated", and then basically repeating the information > previously-provided by a number of contributors. > > It then goes on to talk about copying, sorting, adding, and even sets. > Much of which you had earlier said: "I know". Was there a further > question in there? > > Which part of which answer did you find "too complicated"? > > Did you try the experiments suggested, and read the references-provided? > > Please ask a further question detailing what you have understood, and > what is still mystifying. Folk here endeavor to be helpful (see also, > earlier reference to the Python-Tutor list). > > When asking a question here, please try to reduce the problem to its > simplest form, so that you're not asking volunteers to read > multiple-screens of irrelevant code. It will help to ask one question at > a time, or to carefully separate multiple questions. > > Yes, this can be difficult when one is learning. That said, we all > started somewhere and are happy to help you to become a valued colleague! > From greg.ewing at canterbury.ac.nz Sat Dec 31 19:21:05 2022 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 1 Jan 2023 13:21:05 +1300 Subject: NoneType List In-Reply-To: References: <2b238dce-3e9f-9bee-27a0-d163cb6c7cef@DancesWithMice.info> <006501d91d68$6538dd10$2faa9730$@gmail.com> Message-ID: On 1/01/23 11:36 am, avi.e.gross at gmail.com wrote: > And, of course, we had the philosophical question of why the feature was > designed to not return anything ... rather than return the changed > object. My understanding is that Guido designed it that way to keep a clear separation between mutating and non-mutating methods, and to help catch mistakes resulting from mixing them up. -- Greg From avi.e.gross at gmail.com Sat Dec 31 22:17:56 2022 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 31 Dec 2022 22:17:56 -0500 Subject: NoneType List In-Reply-To: References: <2b238dce-3e9f-9bee-27a0-d163cb6c7cef@DancesWithMice.info> <006501d91d68$6538dd10$2faa9730$@gmail.com> Message-ID: <00e601d91d8f$a4e59b20$eeb0d160$@gmail.com> Agreed, there are lots of pro/con arguments and the feature is what it is historically and not trivial to change. Inline changes to an object make sense to just be done "silently" and if there are errors, they propagate the usual way. As Guido was a major influence at that time, one view was seen as more important and prevailed. Had a language like that been created today, I wonder if some designs might have looked a bit different so that some functions could be called with optional arguments that specified what the user wanted returned. In particular, besides a function where you add a value returning nothing/None, there may be room for other choices and any choice hard-wired in would eleicit complaints from others. lst.add("Value") could also return one of several other things such as a pointer to the upgraded object but also of a pointer to the object as it looked before the change (not a serious proposal) or a True/False value specifying if the change was able to be completed (such as running out of memory, or the addition not being something you can put in the object) or even return what was added or how many objects are now in the object at the top level, or how many times the method was called so far! I suspect, at the expense of some overhead, you could just add an argument to many kinds of methods or even functions such as returning='option' that guides what you want returned, with the default often being what Guido and others currently have set. Python already allows functions to return anything they feel like, so this probably would not break many things. Of course there are other paths in that direction, such as setting an attribute of the list/object first that affects how things get returned but that seems more cumbersome and makes all kinds of errors more likely. Still, that is a path often used by some Python modules where objects are created and then tweaked to behave in various ways when later methods are invoked. But is any of it needed? The current system generally works fine and we have seen many ways to get other results without tampering with the current implementation. This may be yet another example of people who come to python with pre-existing bias, such as insisting it work like another language they have used, or wanting the computer to do what they MEANT rather than what they explicitly or implicitly programmed! -----Original Message----- From: Python-list On Behalf Of Greg Ewing Sent: Saturday, December 31, 2022 7:21 PM To: python-list at python.org Subject: Re: NoneType List On 1/01/23 11:36 am, avi.e.gross at gmail.com wrote: > And, of course, we had the philosophical question of why the feature > was designed to not return anything ... rather than return the changed > object. My understanding is that Guido designed it that way to keep a clear separation between mutating and non-mutating methods, and to help catch mistakes resulting from mixing them up. -- Greg -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sat Dec 31 22:23:13 2022 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jan 2023 14:23:13 +1100 Subject: NoneType List In-Reply-To: <00e601d91d8f$a4e59b20$eeb0d160$@gmail.com> References: <2b238dce-3e9f-9bee-27a0-d163cb6c7cef@DancesWithMice.info> <006501d91d68$6538dd10$2faa9730$@gmail.com> <00e601d91d8f$a4e59b20$eeb0d160$@gmail.com> Message-ID: On Sun, 1 Jan 2023 at 14:19, wrote: > Had a language like that been created today, I wonder if some designs might > have looked a bit different so that some functions could be called with > optional arguments that specified what the user wanted returned. Frankly, I doubt it. While you can argue "returning self is more useful" vs "returning None is more clear if you get it wrong", having options does NOT improve things, and just makes everything more complicated, slower, harder to comprehend, and generally worse to work with. A language should have some sort of consistent behaviour and stick to it. If that's not possible, an object type should at least have that. ChrisA From avi.e.gross at gmail.com Sat Dec 31 23:16:10 2022 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Sat, 31 Dec 2022 23:16:10 -0500 Subject: NoneType List In-Reply-To: References: <2b238dce-3e9f-9bee-27a0-d163cb6c7cef@DancesWithMice.info> <006501d91d68$6538dd10$2faa9730$@gmail.com> <00e601d91d8f$a4e59b20$eeb0d160$@gmail.com> Message-ID: <00fd01d91d97$c78994d0$569cbe70$@gmail.com> Chris, There is much to say about consistent behavior as compared to flexibility and convenience. I have seen other languages provide functions for example, where the result can vary and often cause confusion. R had a function that would sometimes notice the result could be simplified and return that. Guess what? It caused lots of problems and an option was added that said it should NOT simplify and always return the same kind of thing. Consider what happens if a calculation that returned a matrix would decide that is there was only one columns, it would return a vector/array/whatever as a one-dimensional result and if the calculation produced a 1 by 1 matrix, it would simply return a scalar value! But it may be a feature you want in some cases, albeit rarely when the results of the function are fed into something that is not expecting it. Various forms of polymorphism can be helpful but can also be very confusing. Some solutions are what I have described in earlier messages and some languages blur distinctions. Again, in R, there may not be a scalar as all you have is a vector of length one. But matrices even of 1-D are not vectors and I have had to interconvert between them to make some code run. I am not making comparisons in the sense that nothing other languages choose to do is binding on what Python should do. Still, I think it is wrong to suggest that it does not often do partially ambiguous things from some perspective. Many functions will take a variety of arguments and return something reasonable but different each time. As a dumb example, what does a simple function like max() return if fed just integers, just floating point or a combination of both? It seems to return whatever type the maximum indicates. But it also accepts characters and sorts them appropriately returning type 'str' and probably accepts and returns all kinds of objects if you specify a key function. Is that so much different than we are discussing in that there isn't any absolute consistency and things can go various ways in terms of return value? Heck, I can even make max() return None! -----Original Message----- From: Python-list On Behalf Of Chris Angelico Sent: Saturday, December 31, 2022 10:23 PM To: python-list at python.org Subject: Re: NoneType List On Sun, 1 Jan 2023 at 14:19, wrote: > Had a language like that been created today, I wonder if some designs > might have looked a bit different so that some functions could be > called with optional arguments that specified what the user wanted returned. Frankly, I doubt it. While you can argue "returning self is more useful" vs "returning None is more clear if you get it wrong", having options does NOT improve things, and just makes everything more complicated, slower, harder to comprehend, and generally worse to work with. A language should have some sort of consistent behaviour and stick to it. If that's not possible, an object type should at least have that. ChrisA -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sat Dec 31 23:23:59 2022 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 1 Jan 2023 15:23:59 +1100 Subject: NoneType List In-Reply-To: <00fd01d91d97$c78994d0$569cbe70$@gmail.com> References: <2b238dce-3e9f-9bee-27a0-d163cb6c7cef@DancesWithMice.info> <006501d91d68$6538dd10$2faa9730$@gmail.com> <00e601d91d8f$a4e59b20$eeb0d160$@gmail.com> <00fd01d91d97$c78994d0$569cbe70$@gmail.com> Message-ID: On Sun, 1 Jan 2023 at 15:16, wrote: > > Chris, > > There is much to say about consistent behavior as compared to flexibility > and convenience. > > I have seen other languages provide functions for example, where the result > can vary and often cause confusion. R had a function that would sometimes > notice the result could be simplified and return that. Guess what? It caused > lots of problems and an option was added that said it should NOT simplify > and always return the same kind of thing. The option was presumably added because backward compatibility is important, but it would have been better to not need the option in the first place. > As a dumb example, what does a simple function like max() return if fed just > integers, just floating point or a combination of both? It seems to return > whatever type the maximum indicates. But it also accepts characters and > sorts them appropriately returning type 'str' and probably accepts and > returns all kinds of objects if you specify a key function. > > Is that so much different than we are discussing in that there isn't any > absolute consistency and things can go various ways in terms of return > value? Heck, I can even make max() return None! > ... yes? So? It still always returns the largest item in the list, for some definition of "largest". You'll never have that value returned wrapped up in a single-element list, though. ChrisA