From jacob.kruger.work at gmail.com Mon Apr 1 10:49:31 2024 From: jacob.kruger.work at gmail.com (Jacob Kruger) Date: Mon, 1 Apr 2024 16:49:31 +0200 Subject: Trying to use pyinstaller under python 3.11, and, recently started receiving error message about specific module/distribution In-Reply-To: References: Message-ID: Found many, many mentions of errors, with some of the same keywords, but, no resolutions that match my exact issue at all. As in, most of them are mentioning older versions of python, and, mainly different platforms - mac and linux, but, various google searches have not mentioned much of using it on windows, and having it just stop working. Now did even try shifting over to python 3.12, but, still no-go. If launch pyinstaller under python 3.10 on this exact same machine, pyinstaller runs - just keep that older version hovering around for a couple of occasional tests, partly since some of my target environments are still running older versions of python, but anyway. Also, not really relevant, but, cx_freeze is perfectly able to generate executables for this same code, but, then not combining all output into a single file - will stick to that for now, but, not always as convenient, and, still wondering what changed here. Jacob Kruger +2782 413 4791 "Resistance is futile!...Acceptance is versatile..." On 2024/03/31 14:51, Barry wrote: > >> On 31 Mar 2024, at 13:24, Jacob Kruger via Python-list wrote: >> >> pkg_resources.DistributionNotFound: The 'altgraph' distribution was not found and is required by the application > I think I have seen this error being discussed before? > > A web search for pyinstaller and that error leads to people discussing why it happens it looks like. > > Barry > > From piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de Mon Apr 1 04:51:05 2024 From: piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de (Piergiorgio Sartor) Date: Mon, 1 Apr 2024 10:51:05 +0200 Subject: Multiplication In-Reply-To: References: Message-ID: On 01/04/2024 10.40, Stefan Ram wrote: > Q: How can I multiply two variables in Python? I tried: > > a = 2 > b = 3 > print( ab ) > > but it did not work. > > A: No, this cannot work. To multiply, you need the multiplication > operator. You can import the multiplication operator from "math": > > Code example: > > from math import * > > a = 2 > b = 3 > print( a * b ) I guess the operator "*" can be imported from any module... :-) bye, -- piergiorgio From inhahe at gmail.com Mon Apr 1 13:30:27 2024 From: inhahe at gmail.com (inhahe) Date: Mon, 1 Apr 2024 13:30:27 -0400 Subject: xkcd.com/353 ( Flying with Python ) In-Reply-To: <46f330fb23ace1d942e40bd0c7182fbc@www.novabbs.com> References: <87ttknbf4r.fsf@tudado.org> <46f330fb23ace1d942e40bd0c7182fbc@www.novabbs.com> Message-ID: On Mon, Apr 1, 2024 at 1:26?PM HenHanna via Python-list < python-list at python.org> wrote: > Johanne Fairchild wrote: > > > HenHanna writes: > > >> https://xkcd.com/1306/ > >> what does SIGIL mean? > > > A glyph used in magic. Or, for Perl, the symbol in front of a variable > > name, such as $, @, and %. > > > Source: https://perldoc.perl.org/perlglossary#sigil > > > Sigil is noun. Definitions: > > > A seal; a signet. > > A sign or an image considered magical. > > A seal; a signature. > > > Source: The American Heritage? Dictionary of the English > Language, 5th Edition. > > > > > > omg... Sigil is a real word??? > > > The word "sigil" comes from the Latin term "sigillum," which means "little > sign." This Latin root is also the source of our English word "seal," > making "sigil" and "seal" doublets. > > https://en.wiktionary.org/wiki/sigil > > > I understand "sigil" as referring to symbols occultists make up and use to aid in their magick. From joel.goldstick at gmail.com Mon Apr 1 13:35:26 2024 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 1 Apr 2024 13:35:26 -0400 Subject: Multiplication In-Reply-To: References: Message-ID: On Mon, Apr 1, 2024 at 1:26?PM Piergiorgio Sartor via Python-list wrote: > > On 01/04/2024 10.40, Stefan Ram wrote: > > Q: How can I multiply two variables in Python? I tried: > > > > a = 2 > > b = 3 > > print( ab ) > > > > but it did not work. > > > > A: No, this cannot work. To multiply, you need the multiplication > > operator. You can import the multiplication operator from "math": > > > > Code example: > > > > from math import * > > > > a = 2 > > b = 3 > > print( a * b ) > > I guess the operator "*" can be imported from any module... :-) > > bye, > > -- > > piergiorgio > > -- > https://mail.python.org/mailman/listinfo/python-list >>> a = 3 >>> b = 5 >>> print(a*b) 15 >>> No import is necessary. -- Joel Goldstick From petite.abeille at gmail.com Mon Apr 1 14:21:08 2024 From: petite.abeille at gmail.com (PA) Date: Mon, 1 Apr 2024 20:21:08 +0200 Subject: xkcd.com/353 ( Flying with Python ) In-Reply-To: <87ttknbf4r.fsf@tudado.org> References: <87ttknbf4r.fsf@tudado.org> Message-ID: <31597129-BD9F-4605-A773-D8AB80F61E05@gmail.com> > On Mar 30, 2024, at 22:09, Johanne Fairchild via Python-list wrote: > > Sigil is noun. Definitions: > > A seal; a signet. > A sign or an image considered magical. > A seal; a signature. Creating Sigils The origin and design process informing Urbit's generative user avatar system, Sigils. https://urbit.org/blog/creating-sigils Implementation example: https://github.com/textprotocol/sigil From petite.abeille at gmail.com Mon Apr 1 14:21:08 2024 From: petite.abeille at gmail.com (PA) Date: Mon, 1 Apr 2024 20:21:08 +0200 Subject: xkcd.com/353 ( Flying with Python ) In-Reply-To: <87ttknbf4r.fsf@tudado.org> References: <87ttknbf4r.fsf@tudado.org> Message-ID: <31597129-BD9F-4605-A773-D8AB80F61E05@gmail.com> > On Mar 30, 2024, at 22:09, Johanne Fairchild via Python-list wrote: > > Sigil is noun. Definitions: > > A seal; a signet. > A sign or an image considered magical. > A seal; a signature. Creating Sigils The origin and design process informing Urbit's generative user avatar system, Sigils. https://urbit.org/blog/creating-sigils Implementation example: https://github.com/textprotocol/sigil From darcy at VybeNetworks.com Mon Apr 1 14:34:36 2024 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Mon, 1 Apr 2024 13:34:36 -0500 Subject: Multiplication In-Reply-To: References: Message-ID: <8dd3eb18-2916-4f0e-97b3-12c310013c0a@VybeNetworks.com> On 2024-04-01 12:35, Joel Goldstick via Python-list wrote: > On Mon, Apr 1, 2024 at 1:26?PM Piergiorgio Sartor via Python-list ^^^^^^^^^^^ >>> from math import * >>> >>> a = 2 >>> b = 3 >>> print( a * b ) >> >> I guess the operator "*" can be imported from any module... :-) > No import is necessary. Of course not. Check the date on the message. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From avi.e.gross at gmail.com Mon Apr 1 15:02:46 2024 From: avi.e.gross at gmail.com (Avi Gross) Date: Mon, 1 Apr 2024 15:02:46 -0400 Subject: Multiplication In-Reply-To: References: Message-ID: Is this a April 1 post for fools. Multiplication with an asterisk symbol is built into python. The same symbol used in other contexts has other contexts has an assortment of largely unrelated meanings such as meaning everything when used to import. On Mon, Apr 1, 2024, 1:27?PM Piergiorgio Sartor via Python-list < python-list at python.org> wrote: > On 01/04/2024 10.40, Stefan Ram wrote: > > Q: How can I multiply two variables in Python? I tried: > > > > a = 2 > > b = 3 > > print( ab ) > > > > but it did not work. > > > > A: No, this cannot work. To multiply, you need the multiplication > > operator. You can import the multiplication operator from "math": > > > > Code example: > > > > from math import * > > > > a = 2 > > b = 3 > > print( a * b ) > > I guess the operator "*" can be imported from any module... :-) > > bye, > > -- > > piergiorgio > > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Mon Apr 1 16:02:22 2024 From: PythonList at DancesWithMice.info (dn) Date: Tue, 2 Apr 2024 09:02:22 +1300 Subject: Multiplication In-Reply-To: References: Message-ID: <0b9d3ac0-63a3-4f30-98d7-b52c0eae62cf@DancesWithMice.info> The April Fools joke was on those of us who never received/have yet to receive @Stefan's OP. On 2/04/24 08:02, Avi Gross via Python-list wrote: > Is this a April 1 post for fools. > > Multiplication with an asterisk symbol is built into python. > > The same symbol used in other contexts has other contexts has an assortment > of largely unrelated meanings such as meaning everything when used to > import. > > > On Mon, Apr 1, 2024, 1:27?PM Piergiorgio Sartor via Python-list < > python-list at python.org> wrote: > >> On 01/04/2024 10.40, Stefan Ram wrote: >>> Q: How can I multiply two variables in Python? I tried: >>> >>> a = 2 >>> b = 3 >>> print( ab ) >>> >>> but it did not work. >>> >>> A: No, this cannot work. To multiply, you need the multiplication >>> operator. You can import the multiplication operator from "math": >>> >>> Code example: >>> >>> from math import * >>> >>> a = 2 >>> b = 3 >>> print( a * b ) >> >> I guess the operator "*" can be imported from any module... :-) >> >> bye, >> >> -- >> >> piergiorgio >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> -- Regards, =dn From meejah at meejah.ca Tue Apr 2 01:26:00 2024 From: meejah at meejah.ca (meejah) Date: Mon, 01 Apr 2024 23:26:00 -0600 Subject: magic-wormhole 0.14.0 Message-ID: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 Greetings, I'm pleased to announce that magic-wormhole 0.14.0 is released. Magic Wormhole is a Python library and CLI tool to securely get arbitrary data from one computer to another using short, one-time, human- pronouncable codes and end-to-end encryption. The library allows use of the lower-level protocol for things besides file-transfer. In this release are the following changes since 0.13.0: * Add completion files for bash, zsh and fish (#498) * Python 3.12 added to CI, versioneer updated (#505) * Support streaming compression of directories (#503, from @pR0Ps) * Remove obsolete compatibility code (thanks @a-detiste) * Add "ecosystem" document You can find the release on PyPI: https://pypi.org/project/magic-wormhole/ More information can be found: https://magic-wormhole.readthedocs.io/en/latest/welcome.html https://github.com/magic-wormhole/magic-wormhole thanks, meejah -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEnVor1WiOy4id680/wmAoAxKAaacFAmYLlrUACgkQwmAoAxKA aadZqggA1vCsKH7ejaph6QoDXBBGTX0yff4NtdLv6zgT61CDxNzKe2VYAqMZFE49 aGMU8jw6/2KPGtA6cEmf1UeQ/byyxBn/bHijKztrjCbaF4CkVnptF4f7g9S6jLDf f2BBj4gNJqEg343o0WmGQc9GbQWPZjHCnx/zFdQzy61PkHwxyg/pk+Esm0O7CXxQ 1j54IEtsNAzDhFtK8VlnIebT4wZkm+xQQ6yAtXcnPr/dLMag2ry6RY7xgB7zfaPz Az6uzbH7ms6vxfegEky/ZDMVZd3G9bI1sfxpr73E8HRNh7+FkkLrSa+sviMePrmW cHyMEhFBJSBpxbot1/2Lm/dhXy/yew== =xl8F -----END PGP SIGNATURE----- From barry at barrys-emacs.org Tue Apr 2 11:11:42 2024 From: barry at barrys-emacs.org (Barry) Date: Tue, 2 Apr 2024 16:11:42 +0100 Subject: Trying to use pyinstaller under python 3.11, and, recently started receiving error message about specific module/distribution In-Reply-To: References: Message-ID: > On 1 Apr 2024, at 15:52, Jacob Kruger via Python-list wrote: > > ?Found many, many mentions of errors, with some of the same keywords, but, no resolutions that match my exact issue at all. Try asking the pyinstaller developers. I think there is a mailing list. Barry > > > As in, most of them are mentioning older versions of python, and, mainly different platforms - mac and linux, but, various google searches have not mentioned much of using it on windows, and having it just stop working. > > > Now did even try shifting over to python 3.12, but, still no-go. > > > If launch pyinstaller under python 3.10 on this exact same machine, pyinstaller runs - just keep that older version hovering around for a couple of occasional tests, partly since some of my target environments are still running older versions of python, but anyway. > > > Also, not really relevant, but, cx_freeze is perfectly able to generate executables for this same code, but, then not combining all output into a single file - will stick to that for now, but, not always as convenient, and, still wondering what changed here. > > > Jacob Kruger > +2782 413 4791 > "Resistance is futile!...Acceptance is versatile..." > > >> On 2024/03/31 14:51, Barry wrote: >> >>>> On 31 Mar 2024, at 13:24, Jacob Kruger via Python-list wrote: >>> >>> pkg_resources.DistributionNotFound: The 'altgraph' distribution was not found and is required by the application >> I think I have seen this error being discussed before? >> >> A web search for pyinstaller and that error leads to people discussing why it happens it looks like. >> >> Barry >> >> > -- > https://mail.python.org/mailman/listinfo/python-list From barry at barrys-emacs.org Tue Apr 2 11:16:09 2024 From: barry at barrys-emacs.org (Barry) Date: Tue, 2 Apr 2024 16:16:09 +0100 Subject: Making 'compiled' modules work with multiple python versions on Linux In-Reply-To: References: Message-ID: > On 1 Apr 2024, at 18:14, Left Right via Python-list wrote: > > It sounds weird that symbols from Limited API are _missing_ (I'd > expect them to be there no matter what library version you link with). You have to specify the version of the limited API that you want to use. Each release adds more symbols to the limited API. So if you compile against 3.10 version it works with 3.10, 3.11, 3.12 etc, but not with 3.9. My pycxx project has test code that I use to verify pycxx?s use of python API. You could check out the source and run my tests to see how things work. It is on https://sourceforge.net/projects/cxx/ Barry From piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de Tue Apr 2 13:47:59 2024 From: piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de (Piergiorgio Sartor) Date: Tue, 2 Apr 2024 19:47:59 +0200 Subject: A technique from a chatbot In-Reply-To: References: Message-ID: On 02/04/2024 19.18, Stefan Ram wrote: > Some people can't believe it when I say that chatbots improve > my programming productivity. So, here's a technique I learned > from a chatbot! > > It is a structured "break". "Break" still is a kind of jump, > you know? > > So, what's a function to return the first word beginning with > an "e" in a given list, like for example > > [ 'delta', 'epsilon', 'zeta', 'eta', 'theta' ] > > ? Well it's > > def first_word_beginning_with_e( list_ ): > for word in list_: > if word[ 0 ]== 'e': return word > > . "return" still can be considered a kind of "goto" statement. > It can lead to errors: > > def first_word_beginning_with_e( list_ ): > for word in list_: > if word[ 0 ]== 'e': return word > something_to_be_done_at_the_end_of_this_function() > > The call sometimes will not be executed here! > So, "return" is similar to "break" in that regard. > > But in Python we can write: > > def first_word_beginning_with_e( list_ ): > return next( ( word for word in list_ if word[ 0 ]== 'e' ), None ) Doesn't look a smart advice. > . No jumps anymore, yet the loop is aborted on the first hit First of all, I fail to understand why there should be no jumps any more. It depends on how "return" and "if" are handled, I guess, in different context. Maybe they're just "masked". In any case, the "compiler" should have just done the same. > (if I guess correctly how its working). Second, it is difficult to read, which is bad. The "guess" above is just evidence of that. My personal opinion about these "chatbots", is that, while they might deliver clever solutions, they are not explaining *why* these solutions should be considered "clever". Which is the most important thing (the solution itself is _not_). bye, -- piergiorgio From list1 at tompassin.net Tue Apr 2 15:31:26 2024 From: list1 at tompassin.net (Thomas Passin) Date: Tue, 2 Apr 2024 15:31:26 -0400 Subject: A technique from a chatbot In-Reply-To: References: Message-ID: <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net> On 4/2/2024 1:47 PM, Piergiorgio Sartor via Python-list wrote: > On 02/04/2024 19.18, Stefan Ram wrote: >> ?? Some people can't believe it when I say that chatbots improve >> ?? my programming productivity. So, here's a technique I learned >> ?? from a chatbot! >> ?? It is a structured "break". "Break" still is a kind of jump, >> ?? you know? >> ?? So, what's a function to return the first word beginning with >> ?? an "e" in a given list, like for example >> [ 'delta', 'epsilon', 'zeta', 'eta', 'theta' ] >> >> ?? ? Well it's >> def first_word_beginning_with_e( list_ ): >> ???? for word in list_: >> ???????? if word[ 0 ]== 'e': return word >> >> ?? . "return" still can be considered a kind of "goto" statement. >> ?? It can lead to errors: >> >> def first_word_beginning_with_e( list_ ): >> ???? for word in list_: >> ???????? if word[ 0 ]== 'e': return word >> ???? something_to_be_done_at_the_end_of_this_function() >> ?? The call sometimes will not be executed here! >> ?? So, "return" is similar to "break" in that regard. >> ?? But in Python we can write: >> def first_word_beginning_with_e( list_ ): >> ???? return next( ( word for word in list_ if word[ 0 ]== 'e' ), None ) > > Doesn't look a smart advice. > >> ?? . No jumps anymore, yet the loop is aborted on the first hit It's worse than "not a smart advice". This code constructs an unnecessary tuple, then picks out its first element and returns that. The something_to_be_done() function may or may not be called. And it's harder to read and understand than necessary. Compare, for example, with this version: def first_word_beginning_with_e(target, wordlist): result = '' for w in wordlist: if w.startswith(target): res = w break do_something_else() return result If do_something_else() is supposed to fire only if the target is not found, then this slight modification will do: def first_word_beginning_with_e(target, wordlist): result = '' for w in wordlist: if w.startswith(target): res = w break else: do_something_else() return result [Using the "target" argument instead of "target[0]" will let you match an initial string instead of just a the first character]. > First of all, I fail to understand why there > should be no jumps any more. > It depends on how "return" and "if" are handled, > I guess, in different context. > Maybe they're just "masked". > In any case, the "compiler" should have just > done the same. > >> ?? (if I guess correctly how its working). > > Second, it is difficult to read, which is bad. > The "guess" above is just evidence of that. > > My personal opinion about these "chatbots", is > that, while they might deliver clever solutions, > they are not explaining *why* these solutions > should be considered "clever". > Which is the most important thing (the solution > itself is _not_). > > bye, > From avi.e.gross at gmail.com Wed Apr 3 01:27:00 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 3 Apr 2024 01:27:00 -0400 Subject: A technique from a chatbot In-Reply-To: <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net> References: <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net> Message-ID: <01d501da8587$8dd66c50$a98344f0$@gmail.com> I am a tad confused by a suggestion that any kind of GOTO variant is bad. The suggestion runs counter to the reality that underneath it all, compiled programs are chock full of GOTO variants even for simple things like IF-ELSE. Consider the code here: >> def first_word_beginning_with_e( list_ ): >> for word in list_: >> if word[ 0 ]== 'e': return word >> something_to_be_done_at_the_end_of_this_function() If instead the function initialized a variable to nothing useful and in the loop if it found a word beginning with e and it still contained nothing useful, copied it into the variable and then allowed the code to complete the loop and finally returned the variable, that would simply be a much less efficient solution to the problem and gain NOTHING. There are many variants you can come up with and when the conditions are complex and many points of immediate return, fine, then it may be dangerous. But a single return is fine. The function does have a flaw as it is not clear what it should do if nothing is found. Calling a silly long name does not necessarily return anything. Others, like Thomas, have shown other variants including some longer and more complex ways. A fairly simple one-liner version, not necessarily efficient, would be to just use a list comprehension that makes a new list of just the ones matching the pattern of starting with an 'e' and then returns the first entry or None. This shows the code and test it: text = ["eastern", "Western", "easter"] NorEaster = ["North", "West", "orient"] def first_word_beginning_with_e( list_ ): return(result[0] if (result := [word for word in list_ if word[0].lower() == 'e']) else None) print(first_word_beginning_with_e( text )) print(first_word_beginning_with_e( NorEaster )) Result of running it on a version of python ay least 3.8 so it supports the walrus operator: eastern None -----Original Message----- From: Python-list On Behalf Of Thomas Passin via Python-list Sent: Tuesday, April 2, 2024 3:31 PM To: python-list at python.org Subject: Re: A technique from a chatbot On 4/2/2024 1:47 PM, Piergiorgio Sartor via Python-list wrote: > On 02/04/2024 19.18, Stefan Ram wrote: >> Some people can't believe it when I say that chatbots improve >> my programming productivity. So, here's a technique I learned >> from a chatbot! >> It is a structured "break". "Break" still is a kind of jump, >> you know? >> So, what's a function to return the first word beginning with >> an "e" in a given list, like for example >> [ 'delta', 'epsilon', 'zeta', 'eta', 'theta' ] >> >> ? Well it's >> def first_word_beginning_with_e( list_ ): >> for word in list_: >> if word[ 0 ]== 'e': return word >> >> . "return" still can be considered a kind of "goto" statement. >> It can lead to errors: >> >> def first_word_beginning_with_e( list_ ): >> for word in list_: >> if word[ 0 ]== 'e': return word >> something_to_be_done_at_the_end_of_this_function() >> The call sometimes will not be executed here! >> So, "return" is similar to "break" in that regard. >> But in Python we can write: >> def first_word_beginning_with_e( list_ ): >> return next( ( word for word in list_ if word[ 0 ]== 'e' ), None ) > > Doesn't look a smart advice. > >> . No jumps anymore, yet the loop is aborted on the first hit It's worse than "not a smart advice". This code constructs an unnecessary tuple, then picks out its first element and returns that. The something_to_be_done() function may or may not be called. And it's harder to read and understand than necessary. Compare, for example, with this version: def first_word_beginning_with_e(target, wordlist): result = '' for w in wordlist: if w.startswith(target): res = w break do_something_else() return result If do_something_else() is supposed to fire only if the target is not found, then this slight modification will do: def first_word_beginning_with_e(target, wordlist): result = '' for w in wordlist: if w.startswith(target): res = w break else: do_something_else() return result [Using the "target" argument instead of "target[0]" will let you match an initial string instead of just a the first character]. > First of all, I fail to understand why there > should be no jumps any more. > It depends on how "return" and "if" are handled, > I guess, in different context. > Maybe they're just "masked". > In any case, the "compiler" should have just > done the same. > >> (if I guess correctly how its working). > > Second, it is difficult to read, which is bad. > The "guess" above is just evidence of that. > > My personal opinion about these "chatbots", is > that, while they might deliver clever solutions, > they are not explaining *why* these solutions > should be considered "clever". > Which is the most important thing (the solution > itself is _not_). > > bye, > -- https://mail.python.org/mailman/listinfo/python-list From antoon.pardon at vub.be Wed Apr 3 05:11:01 2024 From: antoon.pardon at vub.be (Antoon Pardon) Date: Wed, 3 Apr 2024 11:11:01 +0200 Subject: A missing iterator on itertools module? In-Reply-To: <66059eb6$0$7522$426a34cc@news.free.fr> References: <66059eb6$0$7522$426a34cc@news.free.fr> Message-ID: Op 28/03/2024 om 17:45 schreef ast via Python-list: > Hello > > Suppose I have these 3 strings: > > s1 = "AZERTY" > s2 = "QSDFGH" > s3 = "WXCVBN" > > and I need an itertor who delivers > > A Q W Z S C E D C ... > > I didn't found anything in itertools to do the job. The documentation mentions a roundrobin recipe. > > So I came up with this solution: > > > list(chain.from_iterable(zip("AZERTY", "QSDFGH", "WXCVBN"))) > > ['A', 'Q', 'W', 'Z', 'S', 'X', 'E', 'D', 'C', 'R', 'F', 'V', 'T', 'G', > 'B', 'Y', 'H', 'N'] But if your strings are not equal, this will only produce a partial result. From avi.e.gross at gmail.com Wed Apr 3 08:14:53 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 3 Apr 2024 08:14:53 -0400 Subject: A missing iterator on itertools module? In-Reply-To: References: <66059eb6$0$7522$426a34cc@news.free.fr> Message-ID: <004501da85c0$89673b70$9c35b250$@gmail.com> Antoon, Even if the suggested solution offers a partial result, you would need specific requirements to determine what should be done if one or more of the parts being cycled is shorter than the others. Stopping at that point is one option. Another is to continue but only interleave ones still producing and in the same order. There is a function in itertools called zip_longest() that might be considered as it keeps going but substitutes a customizable value for "missing" parts. You could then, perhaps, make a change so that sentinel is not passed along. -----Original Message----- From: Python-list On Behalf Of Antoon Pardon via Python-list Sent: Wednesday, April 3, 2024 5:11 AM To: python-list at python.org Subject: Re: A missing iterator on itertools module? Op 28/03/2024 om 17:45 schreef ast via Python-list: > Hello > > Suppose I have these 3 strings: > > s1 = "AZERTY" > s2 = "QSDFGH" > s3 = "WXCVBN" > > and I need an itertor who delivers > > A Q W Z S C E D C ... > > I didn't found anything in itertools to do the job. The documentation mentions a roundrobin recipe. > > So I came up with this solution: > > > list(chain.from_iterable(zip("AZERTY", "QSDFGH", "WXCVBN"))) > > ['A', 'Q', 'W', 'Z', 'S', 'X', 'E', 'D', 'C', 'R', 'F', 'V', 'T', 'G', > 'B', 'Y', 'H', 'N'] But if your strings are not equal, this will only produce a partial result. -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Wed Apr 3 07:50:55 2024 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 3 Apr 2024 07:50:55 -0400 Subject: A technique from a chatbot In-Reply-To: <01d501da8587$8dd66c50$a98344f0$@gmail.com> References: <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net> <01d501da8587$8dd66c50$a98344f0$@gmail.com> Message-ID: <435c439b-148b-4440-b2d2-ea3611679216@tompassin.net> On 4/3/2024 1:27 AM, AVI GROSS via Python-list wrote: > I am a tad confused by a suggestion that any kind of GOTO variant is bad. The suggestion runs counter to the reality that underneath it all, compiled programs are chock full of GOTO variants even for simple things like IF-ELSE. > > Consider the code here: > >>> def first_word_beginning_with_e( list_ ): >>> for word in list_: >>> if word[ 0 ]== 'e': return word >>> something_to_be_done_at_the_end_of_this_function() > > If instead the function initialized a variable to nothing useful and in the loop if it found a word beginning with e and it still contained nothing useful, copied it into the variable and then allowed the code to complete the loop and finally returned the variable, that would simply be a much less efficient solution to the problem and gain NOTHING. There are many variants you can come up with and when the conditions are complex and many points of immediate return, fine, then it may be dangerous. But a single return is fine. > > The function does have a flaw as it is not clear what it should do if nothing is found. Calling a silly long name does not necessarily return anything. > > Others, like Thomas, have shown other variants including some longer and more complex ways. > > A fairly simple one-liner version, not necessarily efficient, would be to just use a list comprehension that makes a new list of just the ones matching the pattern of starting with an 'e' and then returns the first entry or None. This shows the code and test it: > > text = ["eastern", "Western", "easter"] > > NorEaster = ["North", "West", "orient"] > > def first_word_beginning_with_e( list_ ): > return(result[0] if (result := [word for word in list_ if word[0].lower() == 'e']) else None) > > print(first_word_beginning_with_e( text )) > print(first_word_beginning_with_e( NorEaster )) > > Result of running it on a version of python ay least 3.8 so it supports the walrus operator: > > eastern > None The OP seems to want to return None if a match is not found. If a Python function ends without a return statement, it automatically returns None. So nothing special needs to be done. True, that is probably a special case, but it suggests that the problem posed to the chatbot was not posed well. A truly useful chatbot could have discussed many of the points we've been discussing. That would have made for a good learning experience. Instead the chatbot produced poorly constructed code that caused a bad learning experience. > [snip...] From avi.e.gross at gmail.com Wed Apr 3 11:32:44 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Wed, 3 Apr 2024 11:32:44 -0400 Subject: A technique from a chatbot In-Reply-To: <435c439b-148b-4440-b2d2-ea3611679216@tompassin.net> References: <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net> <01d501da8587$8dd66c50$a98344f0$@gmail.com> <435c439b-148b-4440-b2d2-ea3611679216@tompassin.net> Message-ID: <001901da85dc$2cecd9b0$86c68d10$@gmail.com> Sadly, Thomas, this is not even all that new. I have seen people do searches on the internet for how to do one thing at a time and then cobble together some code that does something but perhaps not quite what they intended. Some things are just inefficient such as reading data from a file, doing some calculations, writing the results to another file, reading them back in and doing more calculations and writing them out again and so on. Yes, there can be value in storing intermediate results but why read it in again when it is already in memory? And, in some cases, why not do multiple steps instead of one at a time and so on. How many people ask how to TEST the code they get, especially from an AI-like ...? -----Original Message----- From: Python-list On Behalf Of Thomas Passin via Python-list Sent: Wednesday, April 3, 2024 7:51 AM To: python-list at python.org Subject: Re: A technique from a chatbot On 4/3/2024 1:27 AM, AVI GROSS via Python-list wrote: > I am a tad confused by a suggestion that any kind of GOTO variant is bad. The suggestion runs counter to the reality that underneath it all, compiled programs are chock full of GOTO variants even for simple things like IF-ELSE. > > Consider the code here: > >>> def first_word_beginning_with_e( list_ ): >>> for word in list_: >>> if word[ 0 ]== 'e': return word >>> something_to_be_done_at_the_end_of_this_function() > > If instead the function initialized a variable to nothing useful and in the loop if it found a word beginning with e and it still contained nothing useful, copied it into the variable and then allowed the code to complete the loop and finally returned the variable, that would simply be a much less efficient solution to the problem and gain NOTHING. There are many variants you can come up with and when the conditions are complex and many points of immediate return, fine, then it may be dangerous. But a single return is fine. > > The function does have a flaw as it is not clear what it should do if nothing is found. Calling a silly long name does not necessarily return anything. > > Others, like Thomas, have shown other variants including some longer and more complex ways. > > A fairly simple one-liner version, not necessarily efficient, would be to just use a list comprehension that makes a new list of just the ones matching the pattern of starting with an 'e' and then returns the first entry or None. This shows the code and test it: > > text = ["eastern", "Western", "easter"] > > NorEaster = ["North", "West", "orient"] > > def first_word_beginning_with_e( list_ ): > return(result[0] if (result := [word for word in list_ if word[0].lower() == 'e']) else None) > > print(first_word_beginning_with_e( text )) > print(first_word_beginning_with_e( NorEaster )) > > Result of running it on a version of python ay least 3.8 so it supports the walrus operator: > > eastern > None The OP seems to want to return None if a match is not found. If a Python function ends without a return statement, it automatically returns None. So nothing special needs to be done. True, that is probably a special case, but it suggests that the problem posed to the chatbot was not posed well. A truly useful chatbot could have discussed many of the points we've been discussing. That would have made for a good learning experience. Instead the chatbot produced poorly constructed code that caused a bad learning experience. > [snip...] -- https://mail.python.org/mailman/listinfo/python-list From jacob.kruger.work at gmail.com Wed Apr 3 12:18:42 2024 From: jacob.kruger.work at gmail.com (Jacob Kruger) Date: Wed, 3 Apr 2024 18:18:42 +0200 Subject: Trying to use pyinstaller under python 3.11, and, recently started receiving error message about specific module/distribution In-Reply-To: References: Message-ID: Ok, last update for now - checked out the following page on pyinstaller.org, and, ended up posting to the mailing list, so, let's see: https://pyinstaller.org/en/latest/when-things-go-wrong.html Jacob Kruger +2782 413 4791 "Resistance is futile!...Acceptance is versatile..." On 2024/04/02 17:11, Barry wrote: > >> On 1 Apr 2024, at 15:52, Jacob Kruger via Python-list wrote: >> >> ?Found many, many mentions of errors, with some of the same keywords, but, no resolutions that match my exact issue at all. > Try asking the pyinstaller developers. I think there is a mailing list. > > Barry >> >> As in, most of them are mentioning older versions of python, and, mainly different platforms - mac and linux, but, various google searches have not mentioned much of using it on windows, and having it just stop working. >> >> >> Now did even try shifting over to python 3.12, but, still no-go. >> >> >> If launch pyinstaller under python 3.10 on this exact same machine, pyinstaller runs - just keep that older version hovering around for a couple of occasional tests, partly since some of my target environments are still running older versions of python, but anyway. >> >> >> Also, not really relevant, but, cx_freeze is perfectly able to generate executables for this same code, but, then not combining all output into a single file - will stick to that for now, but, not always as convenient, and, still wondering what changed here. >> >> >> Jacob Kruger >> +2782 413 4791 >> "Resistance is futile!...Acceptance is versatile..." >> >> >>> On 2024/03/31 14:51, Barry wrote: >>> >>>>> On 31 Mar 2024, at 13:24, Jacob Kruger via Python-list wrote: >>>> pkg_resources.DistributionNotFound: The 'altgraph' distribution was not found and is required by the application >>> I think I have seen this error being discussed before? >>> >>> A web search for pyinstaller and that error leads to people discussing why it happens it looks like. >>> >>> Barry >>> >>> >> -- >> https://mail.python.org/mailman/listinfo/python-list From billkochman777 at gmail.com Wed Apr 3 10:15:50 2024 From: billkochman777 at gmail.com (WordWeaver Evangelist) Date: Thu, 4 Apr 2024 00:15:50 +1000 Subject: Already Subscribed and Confirmed, But .... Message-ID: Hello. I already subscribed to this list several days ago. In fact, I did it two times, and I received the email with the confirmation link in it, which I clicked on and was confirmed. Despite this fact, each time that I try to post a message to the list. I get a response from the python bot stating that I need to register before I can post to the list. As I said, I already did that, and I was confirmed. I still have the email here. What must I do to work this out, as I have some important issues I need to discuss. Thank you. King regards, Bill Kochman From ethan at stoneleaf.us Wed Apr 3 12:37:45 2024 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 3 Apr 2024 09:37:45 -0700 Subject: Already Subscribed and Confirmed, But .... In-Reply-To: References: Message-ID: On 4/3/24 07:15, WordWeaver Evangelist via Python-list wrote: > Hello. I already subscribed to this list several days ago. In fact, I did it two times, and > I received the email with the confirmation link in it, which I clicked on and was confirmed. > > Despite this fact, each time that I try to post a message to the list. I get a response from > the python bot stating that I need to register before I can post to the list. As I said, I > already did that, and I was confirmed. I still have the email here. Well, this post made it through fine. -- ~Ethan~ From billkochman777 at gmail.com Wed Apr 3 15:06:43 2024 From: billkochman777 at gmail.com (WordWeaver Evangelist) Date: Thu, 4 Apr 2024 05:06:43 +1000 Subject: Help Needed With a Python Gaming Module In-Reply-To: <11059E4A-175D-4903-94C3-B375D66D6CCD@gmail.com> References: <11059E4A-175D-4903-94C3-B375D66D6CCD@gmail.com> Message-ID: Hello everyone! It has been a l-o-n-g time -- nine years in fact --since I last participated on this mailing list. At that time, I was trying to write a door/external for my PC-ANSI, Macintosh-based BBS. Thanks to some of the folks here, I got it done .... although I eventually lost the module a number of years later when I left BBSing behind, because I assumed it to be dead. Anyway, just recently I put my BBS back online again for the fourth time since 1993, and I am again endeavoring to write a new python-based external -- a game -- for my BBS. Before I continue, let me inform you that I am 70 years old, I am NOT a programmer, and I do not know any programming languages. Yes, I am a newbie, a noob, a greenhorn. :) So, if anyone here is willing to help me, you are going to need a lot of patience ..... like ChatGPT :) Following the coding example of another open-source external that was written for my BBS, I have made some significant progress, thanks in large part to spending hours and hours chatting with ChatGPT over the past two days. However, due my lack of expertise, and even though ChatGPT had me try all sorts of functions and codes and methods, there is one very perplexing issue which has prevented me from further development on my game. Even ChatGPT couldn't figure it out. But before I get into the meat of the matter and waste everyone's time here, I need to address several questions to all of you Python brainiacs. ) Is there anyone -- or any group of someones -- amongst this noble assemblage, who meets all of the following qualifications: 1. You are very familiar with Mac OS 9.2.2 2. You are either moderately or very familiar with Hermes II BBS software. 3. You are very familiar with the Jython 2 environment, which I am told is based on Python 2 and NOT Python 3. If you meet all three of those qualifications, then you may possibly be able to help me to overcome the mysterious obstacle I am now facing. Once I see what kind of responses I get, I will be very happy to share my nagging problem with you. Thank you for taking the time to read this. Here is to hoping that my coding genius is out there, ready and eager to come to my aid. Thank you in advance. Kind regads, Bill Kochman From list1 at tompassin.net Wed Apr 3 16:35:46 2024 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 3 Apr 2024 16:35:46 -0400 Subject: Help Needed With a Python Gaming Module In-Reply-To: References: <11059E4A-175D-4903-94C3-B375D66D6CCD@gmail.com> Message-ID: <3bc6ea9c-fb3f-4f6a-9703-ef1ca67125f1@tompassin.net> On 4/3/2024 3:06 PM, WordWeaver Evangelist via Python-list wrote: > Hello everyone! It has been a l-o-n-g time -- nine years in fact --since I last participated on this mailing list. > [snip] > 3. You are very familiar with the Jython 2 environment, which I am told is based on Python 2 and NOT Python 3. Yes, Jython 2 is currently more or less even with Python 2.7. You are presumably writing or hosting this in a java environment, and you may not realize that you can call Jython code from a java class (calling java classes from Jython code is dead simple). For example, I have some java servlet classes that invoke Jython classes and call their methods. If that sounds useful for your project, I can let you know how to do it. [more snips...] From pieter-l at vanoostrum.org Wed Apr 3 17:15:18 2024 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Wed, 03 Apr 2024 23:15:18 +0200 Subject: A technique from a chatbot References: Message-ID: ram at zedat.fu-berlin.de (Stefan Ram) writes: > It can lead to errors: > > def first_word_beginning_with_e( list_ ): > for word in list_: > if word[ 0 ]== 'e': return word > something_to_be_done_at_the_end_of_this_function() > > The call sometimes will not be executed here! > So, "return" is similar to "break" in that regard. That can be solved with finally: def first_word_beginning_with_e( list_ ): try: for word in list_: if word[ 0 ]== 'e': return word finally: print("something_to_be_done_at_the_end_of_this_function()") -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From michael.stemper at gmail.com Wed Apr 3 17:36:30 2024 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Wed, 3 Apr 2024 16:36:30 -0500 Subject: A technique from a chatbot In-Reply-To: <4thPN.242011$oD2.235883@fx11.ams4> References: <4thPN.242011$oD2.235883@fx11.ams4> Message-ID: On 03/04/2024 13.45, Gilmeh Serda wrote: > On 2 Apr 2024 17:18:16 GMT, Stefan Ram wrote: > >> first_word_beginning_with_e > > Here's another one: > >>>> def ret_first_eword(): > ... return [w for w in ['delta', 'epsilon', 'zeta', 'eta', 'theta'] if w.startswith('e')][0] > ... >>>> ret_first_eword() > 'epsilon' Doesn't work in the case where there isn't a word starting with 'e': >>> def find_e( l ): ... return [w for w in l if w.startswith('e')][0] ... >>> l = ['delta', 'epsilon', 'zeta', 'eta', 'theta'] >>> find_e(l) 'epsilon' >>> l = ['The','fan-jet','airline'] >>> find_e(l) Traceback (most recent call last): File "", line 1, in File "", line 2, in find_e IndexError: list index out of range >>> -- Michael F. Stemper If it isn't running programs and it isn't fusing atoms, it's just bending space. From HenHanna at devnull.tb Wed Apr 3 17:50:26 2024 From: HenHanna at devnull.tb (HenHanna) Date: Wed, 3 Apr 2024 14:50:26 -0700 Subject: xkcd.com/353 ( Flying with Python ) In-Reply-To: References: Message-ID: On 3/29/2024 11:21 PM, HenHanna wrote: > > https://xkcd.com/353/????? ( Flying with? Python ) > > > > > https://xkcd.com/1306/ ????????????????????? what does? SIGIL?? mean? -- (i got it...Thanks!) > > > > Other? xkcd?? that you like? my fav. one may be the one about [Bad-ass Hacker] [Nice-ass car]. Does he use Python? i wonder. From HenHanna at dev.null Wed Apr 3 19:08:21 2024 From: HenHanna at dev.null (HenHanna) Date: Wed, 3 Apr 2024 23:08:21 +0000 Subject: xkcd.com/353 ( Flying with Python ) References: Message-ID: <35d336abe55a5e570ded1ba15ff66390@www.novabbs.com> Blue-Maned_Hawk wrote: > HenHanna wrote: >> https://xkcd.com/1306/ >> what does SIGIL mean? > I'd define a sigil as a mandatory symbol used to indicate the properties > of a name. if i'm getting this right... Sigil is part of the language spec, whereas (in Lisp in the old days), there was a convention of using var-name like *foo* to indicate it's a dynamic variable. and sometimes **foo** for .... and %foo% or %%foo%% was used for ........... From jacob.kruger.work at gmail.com Thu Apr 4 04:47:07 2024 From: jacob.kruger.work at gmail.com (Jacob Kruger) Date: Thu, 4 Apr 2024 10:47:07 +0200 Subject: Trying to use pyinstaller under python 3.11, and, recently started receiving error message about specific module/distribution In-Reply-To: References: Message-ID: <1c7deaf7-617c-40fd-86d3-be0f50186cdd@gmail.com> Ok, had received response on pyinstaller mailing list, but, also just related to trying clean uninstall/reinstall of modules, but, while checking that out, something else occurred to me, and, it now operates as it should. Anyway, what seemed to be causing issue was actually that, since, while am working under windows 11, quite often you might need to work with case-sensitivity in file names, not by choice, but, since a lot of target platforms, like linux, etc. are case-sensitive, and, at times, when working with external modules, this might cause hassles, etc. In other words, the folder/directory where all my python source code is stored is set to be case-sensitive - there are a couple of ways to implement this under windows 10 and windows 11, via some external utilities, or by running the following command from a terminal/power-shell window, running it as administrator: fsutil.exe file SetCaseSensitiveInfo C:\folder\path enable If you instead use disable argument at the end, it then disables case-sensitivity, and, what did now was, under current project/test code, I created an additional sub-folder, copied code files, etc. over into it, disabled case-sensitivity on it, recreated the virtual environment, and installed all required modules, including pyinstaller using pip, and, when I then run pyinstaller from there, it works fine, and, does what I want it to. In other words, something to do with having case-sensitivity enabled recursively on the folder/directory containing the code and the virtual environment seemed to be causing these errors/issues, specific to altgraph, which doesn't really make sense to me, but, it's now working, so, will archive this to memory, for later reference. Jacob Kruger +2782 413 4791 "Resistance is futile!...Acceptance is versatile..." On 2024/04/02 17:11, Barry wrote: > >> On 1 Apr 2024, at 15:52, Jacob Kruger via Python-list wrote: >> >> ?Found many, many mentions of errors, with some of the same keywords, but, no resolutions that match my exact issue at all. > Try asking the pyinstaller developers. I think there is a mailing list. > > Barry >> >> As in, most of them are mentioning older versions of python, and, mainly different platforms - mac and linux, but, various google searches have not mentioned much of using it on windows, and having it just stop working. >> >> >> Now did even try shifting over to python 3.12, but, still no-go. >> >> >> If launch pyinstaller under python 3.10 on this exact same machine, pyinstaller runs - just keep that older version hovering around for a couple of occasional tests, partly since some of my target environments are still running older versions of python, but anyway. >> >> >> Also, not really relevant, but, cx_freeze is perfectly able to generate executables for this same code, but, then not combining all output into a single file - will stick to that for now, but, not always as convenient, and, still wondering what changed here. >> >> >> Jacob Kruger >> +2782 413 4791 >> "Resistance is futile!...Acceptance is versatile..." >> >> >>> On 2024/03/31 14:51, Barry wrote: >>> >>>>> On 31 Mar 2024, at 13:24, Jacob Kruger via Python-list wrote: >>>> pkg_resources.DistributionNotFound: The 'altgraph' distribution was not found and is required by the application >>> I think I have seen this error being discussed before? >>> >>> A web search for pyinstaller and that error leads to people discussing why it happens it looks like. >>> >>> Barry >>> >>> >> -- >> https://mail.python.org/mailman/listinfo/python-list From klaas at vanschelven.com Thu Apr 4 03:04:50 2024 From: klaas at vanschelven.com (Klaas van Schelven) Date: Thu, 4 Apr 2024 09:04:50 +0200 Subject: How to get insight in the relations between tracebacks of exceptions in an exception-chain Message-ID: Hi, This question is best introduced example-first: Consider the following trivial program: ``` class OriginalException(Exception): pass class AnotherException(Exception): pass def raise_another_exception(): raise AnotherException() def show_something(): try: raise OriginalException() except OriginalException: raise_another_exception() show_something() ``` running this will dump the following on screen (minus annotations on the Right-Hand-Side): ``` Traceback (most recent call last): File "...../stackoverflow_single_complication.py", line 15, in show_something t1 raise OriginalException() __main__.OriginalException During handling of the above exception, another exception occurred: Traceback (most recent call last): File "...../stackoverflow_single_complication.py", line 20, in t0 show_something() File "...../stackoverflow_single_complication.py", line 17, in show_something t2 raise_another_exception() File "...../stackoverflow_single_complication.py", line 10, in raise_another_exception t3 raise AnotherException() __main__.AnotherException ``` What we see here is first the `OriginalException` with the stackframes between the moment that it was raised and the moment it was handled. Then we see `AnotherException`, with _all_ a complete traceback from its point-of-raising to the start of the program. In itself this is perfectly fine, but a consequence of this way of presenting the information is that the stackframes are _not_ laid out on the screen in the order in which they were called (and not in the reverse order either), as per the annotations _t1_, _t0_, _t2_, _t3_. The path leading up to _t1_ is of course the same as the path leading up to _t2_, and the creators of Python have chosen to present it only once, in the latter case, presumably because that Exception is usually the most interesting one, and because it allows one to read the bottom exception bottom-up without loss of information. However, it does leave people that want to analyze the `OriginalException` somewhat mystified: what led up to it? A programmer that wants to understand what led up to _t1_ would need to [mentally] copy all the frames above the point _t2_ to the first stacktrace to get a complete view. However, in reality the point _t2_ is, AFAIK, not automatically annotated for you as a special frame, which makes the task of mentally copying the stacktrace much harder. Since the point _t2_ is in general "the failing line in the `except` block", by cross-referencing the source-code this excercise can usually be completed, but this seems unnecessarily hard. **Is it possible to automatically pinpoint _t2_ as the "handling frame"?** (The example above is given without some outer exception-handling context; I'm perfectly fine with answers that introduce it and then use `traceback` or other tools to arrive at the correct answer). This is the most trivial case that illustrates the problem; real cases have many more stack frames and thus less clearly illustrate the problem but more clearly illustrate the need for (potentially automated) clarification of what's happening that this SO question is about. regards, Klaas Previously asked here: https://stackoverflow.com/questions/78270044/how-to-get-insight-in-the-relations-between-tracebacks-of-exceptions-in-an-excep From nntp.mbourne at spamgourmet.com Thu Apr 4 15:03:45 2024 From: nntp.mbourne at spamgourmet.com (Mark Bourne) Date: Thu, 4 Apr 2024 20:03:45 +0100 Subject: A technique from a chatbot In-Reply-To: References: <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net> Message-ID: Thomas Passin wrote: > On 4/2/2024 1:47 PM, Piergiorgio Sartor via Python-list wrote: >> On 02/04/2024 19.18, Stefan Ram wrote: >>> ?? Some people can't believe it when I say that chatbots improve >>> ?? my programming productivity. So, here's a technique I learned >>> ?? from a chatbot! >>> ?? It is a structured "break". "Break" still is a kind of jump, >>> ?? you know? >>> ?? So, what's a function to return the first word beginning with >>> ?? an "e" in a given list, like for example >>> [ 'delta', 'epsilon', 'zeta', 'eta', 'theta' ] >>> >>> ?? ? Well it's >>> def first_word_beginning_with_e( list_ ): >>> ???? for word in list_: >>> ???????? if word[ 0 ]== 'e': return word >>> >>> ?? . "return" still can be considered a kind of "goto" statement. >>> ?? It can lead to errors: >>> >>> def first_word_beginning_with_e( list_ ): >>> ???? for word in list_: >>> ???????? if word[ 0 ]== 'e': return word >>> ???? something_to_be_done_at_the_end_of_this_function() >>> ?? The call sometimes will not be executed here! >>> ?? So, "return" is similar to "break" in that regard. >>> ?? But in Python we can write: >>> def first_word_beginning_with_e( list_ ): >>> ???? return next( ( word for word in list_ if word[ 0 ]== 'e' ), None ) >> >> Doesn't look a smart advice. >> >>> ?? . No jumps anymore, yet the loop is aborted on the first hit > > It's worse than "not a smart advice". This code constructs an > unnecessary tuple, then picks out its first element and returns that. I don't think there's a tuple being created. If you mean: ( word for word in list_ if word[ 0 ]== 'e' ) ...that's not creating a tuple. It's a generator expression, which generates the next value each time it's called for. If you only ever ask for the first item, it only generates that one. When I first came across them, I did find it a bit odd that generator expressions look like the tuple equivalent of list/dictionary comprehensions. FWIW, if you actually wanted a tuple from that expression, you'd need to pass the generator to tuple's constructor: tuple(word for word in list_ if word[0] == 'e') (You don't need to include an extra set of brackets when passing a generator a the only argument to a function). -- Mark. From avi.e.gross at gmail.com Thu Apr 4 16:33:57 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Thu, 4 Apr 2024 16:33:57 -0400 Subject: A technique from a chatbot In-Reply-To: References: <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net> Message-ID: <00e701da86cf$6b3e2cc0$41ba8640$@gmail.com> That is an excellent point, Mark. Some of the proposed variants to the requested problem, including mine, do indeed find all instances only to return the first. This can use additional time and space but when done, some of the overhead is also gone. What I mean is that a generator you create and invoke once, generally sits around indefinitely in your session unless it leaves your current range or something. It does only a part of the work and must remain suspended and ready to be called again to do more. If you create a generator inside a function and the function returns, presumably it can be garbage-collected. But if it is in the main body, I have to wonder what happen. There seem to be several related scenarios to consider. - You may want to find, in our example, a first instance. Right afterwards, you want the generator to disassemble anything in use. - You may want the generator to stick around and later be able to return the next instance. The generator can only really go away when another call has been made after the last available instance and it cannot look for more beyond some end. - Finally, you can call a generator with the goal of getting all instances such as by asking it to populate a list. In such a case, you may not necessarily want or need to use a generator expression and can use something straightforward and possible cheaper. What confuses the issue, for me, is that you can make fairly complex calculations in python using various forms of generators that implement a sort of just-in-time approach as generators call other generators which call yet others and so on. Imagine having folders full of files that each contain a data structure such as a dictionary or set and writing functionality that searches for the first match for a key in any of the dictionaries (or sets or whatever) along the way? Now imagine that dictionary items can be a key value pair that can include the value being a deeper dictionary, perhaps down multiple levels. You could get one generator that generates folder names or opens them and another that generates file names and reads in the data structure such as a dictionary and yet another that searches each dictionary and also any internally embedded dictionaries by calling another instance of the same generator as much as needed. You can see how this creates and often consumes generators along the way as needed and in a sense does the minimum amount of work needed to find a first instance. But what might it leave open and taking up resources if not finished in a way that dismantles it? Perhaps worse, imagine doing the search in parallel and as sone as it is found anywhere, ... -----Original Message----- From: Python-list On Behalf Of Mark Bourne via Python-list Sent: Thursday, April 4, 2024 3:04 PM To: python-list at python.org Subject: Re: A technique from a chatbot Thomas Passin wrote: > On 4/2/2024 1:47 PM, Piergiorgio Sartor via Python-list wrote: >> On 02/04/2024 19.18, Stefan Ram wrote: >>> Some people can't believe it when I say that chatbots improve >>> my programming productivity. So, here's a technique I learned >>> from a chatbot! >>> It is a structured "break". "Break" still is a kind of jump, >>> you know? >>> So, what's a function to return the first word beginning with >>> an "e" in a given list, like for example >>> [ 'delta', 'epsilon', 'zeta', 'eta', 'theta' ] >>> >>> ? Well it's >>> def first_word_beginning_with_e( list_ ): >>> for word in list_: >>> if word[ 0 ]== 'e': return word >>> >>> . "return" still can be considered a kind of "goto" statement. >>> It can lead to errors: >>> >>> def first_word_beginning_with_e( list_ ): >>> for word in list_: >>> if word[ 0 ]== 'e': return word >>> something_to_be_done_at_the_end_of_this_function() >>> The call sometimes will not be executed here! >>> So, "return" is similar to "break" in that regard. >>> But in Python we can write: >>> def first_word_beginning_with_e( list_ ): >>> return next( ( word for word in list_ if word[ 0 ]== 'e' ), None ) >> >> Doesn't look a smart advice. >> >>> . No jumps anymore, yet the loop is aborted on the first hit > > It's worse than "not a smart advice". This code constructs an > unnecessary tuple, then picks out its first element and returns that. I don't think there's a tuple being created. If you mean: ( word for word in list_ if word[ 0 ]== 'e' ) ...that's not creating a tuple. It's a generator expression, which generates the next value each time it's called for. If you only ever ask for the first item, it only generates that one. When I first came across them, I did find it a bit odd that generator expressions look like the tuple equivalent of list/dictionary comprehensions. FWIW, if you actually wanted a tuple from that expression, you'd need to pass the generator to tuple's constructor: tuple(word for word in list_ if word[0] == 'e') (You don't need to include an extra set of brackets when passing a generator a the only argument to a function). -- Mark. -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Thu Apr 4 17:10:34 2024 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 4 Apr 2024 17:10:34 -0400 Subject: A technique from a chatbot In-Reply-To: References: <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net> Message-ID: <966cf7ea-d6e9-44f3-bfdd-a2052d9dcc9d@tompassin.net> On 4/4/2024 3:03 PM, Mark Bourne via Python-list wrote: > Thomas Passin wrote: >> On 4/2/2024 1:47 PM, Piergiorgio Sartor via Python-list wrote: >>> On 02/04/2024 19.18, Stefan Ram wrote: >>>> ?? Some people can't believe it when I say that chatbots improve >>>> ?? my programming productivity. So, here's a technique I learned >>>> ?? from a chatbot! >>>> ?? It is a structured "break". "Break" still is a kind of jump, >>>> ?? you know? >>>> ?? So, what's a function to return the first word beginning with >>>> ?? an "e" in a given list, like for example >>>> [ 'delta', 'epsilon', 'zeta', 'eta', 'theta' ] >>>> >>>> ?? ? Well it's >>>> def first_word_beginning_with_e( list_ ): >>>> ???? for word in list_: >>>> ???????? if word[ 0 ]== 'e': return word >>>> >>>> ?? . "return" still can be considered a kind of "goto" statement. >>>> ?? It can lead to errors: >>>> >>>> def first_word_beginning_with_e( list_ ): >>>> ???? for word in list_: >>>> ???????? if word[ 0 ]== 'e': return word >>>> ???? something_to_be_done_at_the_end_of_this_function() >>>> ?? The call sometimes will not be executed here! >>>> ?? So, "return" is similar to "break" in that regard. >>>> ?? But in Python we can write: >>>> def first_word_beginning_with_e( list_ ): >>>> ???? return next( ( word for word in list_ if word[ 0 ]== 'e' ), None ) >>> >>> Doesn't look a smart advice. >>> >>>> ?? . No jumps anymore, yet the loop is aborted on the first hit >> >> It's worse than "not a smart advice". This code constructs an >> unnecessary tuple, then picks out its first element and returns that. > > I don't think there's a tuple being created.? If you mean: > ??? ( word for word in list_ if word[ 0 ]== 'e' ) > > ...that's not creating a tuple.? It's a generator expression, which > generates the next value each time it's called for.? If you only ever > ask for the first item, it only generates that one. Yes, I was careless when I wrote that. Still, the tuple machinery has to be created and that's not necessary here. My point was that you are asking the Python machinery to do extra work for no benefit in performance or readability. > When I first came across them, I did find it a bit odd that generator > expressions look like the tuple equivalent of list/dictionary > comprehensions. > > FWIW, if you actually wanted a tuple from that expression, you'd need to > pass the generator to tuple's constructor: > ??? tuple(word for word in list_ if word[0] == 'e') > (You don't need to include an extra set of brackets when passing a > generator a the only argument to a function). > From nntp.mbourne at spamgourmet.com Fri Apr 5 15:42:15 2024 From: nntp.mbourne at spamgourmet.com (Mark Bourne) Date: Fri, 5 Apr 2024 20:42:15 +0100 Subject: A technique from a chatbot In-Reply-To: References: <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net> <00e701da86cf$6b3e2cc0$41ba8640$@gmail.com> Message-ID: avi.e.gross at gmail.com wrote: > That is an excellent point, Mark. Some of the proposed variants to the requested problem, including mine, do indeed find all instances only to return the first. This can use additional time and space but when done, some of the overhead is also gone. What I mean is that a generator you create and invoke once, generally sits around indefinitely in your session unless it leaves your current range or something. It does only a part of the work and must remain suspended and ready to be called again to do more. It goes out of scope at the end of the function. Unless you return it or store a reference to it elsewhere, it will then be deleted. Or in this case, since the `first_word_beginning_with_e` function doesn't even have a local reference to the generator (it is just created and immediately passed as an argument to `next`), it goes out of scope once the `next` function returns. > If you create a generator inside a function and the function returns, presumably it can be garbage-collected. Exactly. It probably doesn't even need to wait for garbage collection - once the reference count is zero, it can be destroyed. > But if it is in the main body, I have to wonder what happen. If you mean in the top-level module scope outside of any function/method, then it would remain in memory until the process exits. > There seem to be several related scenarios to consider. > > - You may want to find, in our example, a first instance. Right afterwards, you want the generator to disassemble anything in use. > - You may want the generator to stick around and later be able to return the next instance. The generator can only really go away when another call has been made after the last available instance and it cannot look for more beyond some end. > - Finally, you can call a generator with the goal of getting all instances such as by asking it to populate a list. In such a case, you may not necessarily want or need to use a generator expression and can use something straightforward and possible cheaper. Yes, so you create and assign it at an appropriate scope. In the example here, it's just passed to `next` and then destroyed. Passing a generator to the `list` constructor (or the `tuple` constructor in my "FWIW") would behave similarly - you'd get the final list/tuple back, but the generator would be destroyed once that call is done. If you assigned it to a function-local variable, it would exist until the end of that function. > What confuses the issue, for me, is that you can make fairly complex calculations in python using various forms of generators that implement a sort of just-in-time approach as generators call other generators which call yet others and so on. Yes, you can. It can be quite useful when used appropriately. > Imagine having folders full of files that each contain a data structure such as a dictionary or set and writing functionality that searches for the first match for a key in any of the dictionaries (or sets or whatever) along the way? Now imagine that dictionary items can be a key value pair that can include the value being a deeper dictionary, perhaps down multiple levels. > > You could get one generator that generates folder names or opens them and another that generates file names and reads in the data structure such as a dictionary and yet another that searches each dictionary and also any internally embedded dictionaries by calling another instance of the same generator as much as needed. You probably could do that. Personally, I probably wouldn't use generators for that, or at least not custom ones - if you're talking about iterating over directories and files on disk, I'd probably just use `os.walk` (which probably is a generator) and iterate over that, opening each file and doing whatever you want with the contents. > You can see how this creates and often consumes generators along the way as needed and in a sense does the minimum amount of work needed to find a first instance. But what might it leave open and taking up resources if not finished in a way that dismantles it? You'd need to make sure any files are closed (`with open(...)` helps with that). If you're opening files within a generator, I'm pretty sure you can do something like: ``` def iter_files(directory): for filename in directory: with open(filename) as f: yield f ``` Then the file will be closed when the iterator leaves the `with` block and moved on to the next item (presumably there's some mechanism for the context manager's `__exit__` to be called if the generator is destroyed without having iterated over the items - the whole point of using `with` is that `__exit__` is guaranteed to be called whatever happens). Other than that, the generators themselves would be destroyed once they go out of scope. If there are no references to a generator left, nothing is going to be able to call `next` (nor anything else) on it, so no need for it to be kept hanging around in memory. > Perhaps worse, imagine doing the search in parallel and as sone as it is found anywhere, ... > > > > -----Original Message----- > From: Python-list On Behalf Of Mark Bourne via Python-list > Sent: Thursday, April 4, 2024 3:04 PM > To: python-list at python.org > Subject: Re: A technique from a chatbot > > Thomas Passin wrote: >> On 4/2/2024 1:47 PM, Piergiorgio Sartor via Python-list wrote: >>> On 02/04/2024 19.18, Stefan Ram wrote: >>>> Some people can't believe it when I say that chatbots improve >>>> my programming productivity. So, here's a technique I learned >>>> from a chatbot! >>>> It is a structured "break". "Break" still is a kind of jump, >>>> you know? >>>> So, what's a function to return the first word beginning with >>>> an "e" in a given list, like for example >>>> [ 'delta', 'epsilon', 'zeta', 'eta', 'theta' ] >>>> >>>> ? Well it's >>>> def first_word_beginning_with_e( list_ ): >>>> for word in list_: >>>> if word[ 0 ]== 'e': return word >>>> >>>> . "return" still can be considered a kind of "goto" statement. >>>> It can lead to errors: >>>> >>>> def first_word_beginning_with_e( list_ ): >>>> for word in list_: >>>> if word[ 0 ]== 'e': return word >>>> something_to_be_done_at_the_end_of_this_function() >>>> The call sometimes will not be executed here! >>>> So, "return" is similar to "break" in that regard. >>>> But in Python we can write: >>>> def first_word_beginning_with_e( list_ ): >>>> return next( ( word for word in list_ if word[ 0 ]== 'e' ), None ) >>> >>> Doesn't look a smart advice. >>> >>>> . No jumps anymore, yet the loop is aborted on the first hit >> >> It's worse than "not a smart advice". This code constructs an >> unnecessary tuple, then picks out its first element and returns that. > > I don't think there's a tuple being created. If you mean: > ( word for word in list_ if word[ 0 ]== 'e' ) > > ...that's not creating a tuple. It's a generator expression, which > generates the next value each time it's called for. If you only ever > ask for the first item, it only generates that one. > > When I first came across them, I did find it a bit odd that generator > expressions look like the tuple equivalent of list/dictionary > comprehensions. > > FWIW, if you actually wanted a tuple from that expression, you'd need to > pass the generator to tuple's constructor: > tuple(word for word in list_ if word[0] == 'e') > (You don't need to include an extra set of brackets when passing a > generator a the only argument to a function). > From nntp.mbourne at spamgourmet.com Fri Apr 5 15:59:54 2024 From: nntp.mbourne at spamgourmet.com (Mark Bourne) Date: Fri, 5 Apr 2024 20:59:54 +0100 Subject: A technique from a chatbot In-Reply-To: References: <7d38d9e2-78fb-43af-971f-e0d4afb8b039@tompassin.net> Message-ID: Stefan Ram wrote: > Mark Bourne wrote or quoted: >> I don't think there's a tuple being created. If you mean: >> ( word for word in list_ if word[ 0 ]== 'e' ) >> ...that's not creating a tuple. It's a generator expression, which >> generates the next value each time it's called for. If you only ever >> ask for the first item, it only generates that one. > > Yes, that's also how I understand it! > > In the meantime, I wrote code for a microbenchmark, shown below. > > This code, when executed on my computer, shows that the > next+generator approach is a bit faster when compared with > the procedural break approach. But when the order of the two > approaches is being swapped in the loop, then it is shown to > be a bit slower. So let's say, it takes about the same time. There could be some caching going on, meaning whichever is done second comes out a bit faster. > However, I also tested code with an early return (not shown below), > and this was shown to be faster than both code using break and > code using next+generator by a factor of about 1.6, even though > the code with return has the "function call overhead"! To be honest, that's how I'd probably write it - not because of any thought that it might be faster, but just that's it's clearer. And if there's a `do_something_else()` that needs to be called regardless of the whether a word was found, split it into two functions: ``` def first_word_beginning_with_e(target, wordlist): for w in wordlist: if w.startswith(target): return w return '' def find_word_and_do_something_else(target, wordlist): result = first_word_beginning_with_e(target, wordlist) do_something_else() return result ``` > But please be aware that such results depend on the implementation > and version of the Python implementation being used for the benchmark > and also of the details of how exactly the benchmark is written. > > import random > import string > import timeit > > print( 'The following loop may need a few seconds or minutes, ' > 'so please bear with me.' ) > > time_using_break = 0 > time_using_next = 0 > > for repetition in range( 100 ): > for i in range( 100 ): # Yes, this nesting is redundant! > > list_ = \ > [ ''.join \ > ( random.choices \ > ( string.ascii_lowercase, k=random.randint( 1, 30 ))) > for i in range( random.randint( 0, 50 ))] > > start_time = timeit.default_timer() > for word in list_: > if word[ 0 ]== 'e': > word_using_break = word > break > else: > word_using_break = '' > time_using_break += timeit.default_timer() - start_time > > start_time = timeit.default_timer() > word_using_next = \ > next( ( word for word in list_ if word[ 0 ]== 'e' ), '' ) > time_using_next += timeit.default_timer() - start_time > > if word_using_next != word_using_break: > raise Exception( 'word_using_next != word_using_break' ) > > print( f'{time_using_break = }' ) > print( f'{time_using_next = }' ) > print( f'{time_using_next / time_using_break = }' ) > From shannon_makasale at hotmail.com Fri Apr 5 17:32:16 2024 From: shannon_makasale at hotmail.com (shannon makasale) Date: Fri, 5 Apr 2024 21:32:16 +0000 Subject: Running issues Message-ID: Hi there, My name is Shannon. I installed Python 3.12 on my laptop a couple months ago, but realised my school requires me to use 3.11.1. I uninstalled 3.12 and installed 3.11.1. Unfortunately, I am unable to run python now. It keeps asking to be modified, repaired or uninstalled. Do you have any suggestions on how to fix this? Any help you can offer is greatly appreciated. Thank you for your time. Hope to hear from you soon. Shannon Makasale From list1 at tompassin.net Fri Apr 5 18:13:41 2024 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 5 Apr 2024 18:13:41 -0400 Subject: Running issues In-Reply-To: References: Message-ID: <5b54eed4-de7d-4414-941d-62e049672666@tompassin.net> On 4/5/2024 5:32 PM, shannon makasale via Python-list wrote: > Hi there, > My name is Shannon. I installed Python 3.12 on my laptop a couple months ago, but realised my school requires me to use 3.11.1. > > I uninstalled 3.12 and installed 3.11.1. > > Unfortunately, I am unable to run python now. It keeps asking to be modified, repaired or uninstalled. > > Do you have any suggestions on how to fix this? It would be helpful to know how you uninstalled it. The message you saw looks like it comes from the installer rather than from the Python interpreter. Try invoking Python with "py" (assuming you are using Windows). That is the standard Python launcher that is installed by the installer from python.org. For the future, know that you can have several different versions of Python installed at the same time. On Windows, you can launch a specific version using the launcher: py -3.11 py -3.12 And so on. On Linux you should use the full name, such as python3.11 python3.12 etc., depending on which versions have been installed. "python3" will get you the version used by the system, which may not be the one you want to use. To install Python packages with pip, make sure you specify which version of pip to use, like this: py -3.11 -m pip (Windows) or python3.11 -m pip (Linux) Otherwise you make accidentally install the package into the wrong Python installation. > Any help you can offer is greatly appreciated. Thank you for your time. > > > Hope to hear from you soon. > > > > Shannon Makasale From o1bigtenor at gmail.com Fri Apr 5 18:15:38 2024 From: o1bigtenor at gmail.com (o1bigtenor) Date: Fri, 5 Apr 2024 17:15:38 -0500 Subject: Running issues In-Reply-To: References: Message-ID: On Fri, Apr 5, 2024 at 4:40?PM shannon makasale via Python-list < python-list at python.org> wrote: > Hi there, > My name is Shannon. I installed Python 3.12 on my laptop a couple months > ago, but realised my school requires me to use 3.11.1. > > I uninstalled 3.12 and installed 3.11.1. > > Unfortunately, I am unable to run python now. It keeps asking to be > modified, repaired or uninstalled. > > Do you have any suggestions on how to fix this? > Sorry - - - but you just haven't given enough information so that you can be helped. What OS are you using? How did you install python 3.12? How did you un-install it? How did you install python3.11.1? With answers to all of the questions - - - it would be much easier to answer you? HTH From python at mrabarnett.plus.com Fri Apr 5 18:25:35 2024 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 5 Apr 2024 23:25:35 +0100 Subject: Running issues In-Reply-To: References: Message-ID: On 2024-04-05 22:32, shannon makasale via Python-list wrote: > Hi there, > My name is Shannon. I installed Python 3.12 on my laptop a couple months ago, but realised my school requires me to use 3.11.1. > > I uninstalled 3.12 and installed 3.11.1. > > Unfortunately, I am unable to run python now. It keeps asking to be modified, repaired or uninstalled. > > Do you have any suggestions on how to fix this? > > Any help you can offer is greatly appreciated. Thank you for your time. > > > Hope to hear from you soon. > That?s the installer. All it does is install the software. There isn?t an IDE as such, although there is IDLE, which you should be able to find on the Start Menu under Python (assuming you?re using Windows). There are a number of 3rd-party editors available that you can use when working with Python, or you can use Visual Studio Code from Microsoft. From mats at wichmann.us Sat Apr 6 15:37:56 2024 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 6 Apr 2024 13:37:56 -0600 Subject: Running issues In-Reply-To: References: Message-ID: On 4/5/24 15:32, shannon makasale via Python-list wrote: > Hi there, > My name is Shannon. I installed Python 3.12 on my laptop a couple months ago, but realised my school requires me to use 3.11.1. they can suggest 3.11 and there might be a good reason for that, but you should not worry about something as specific as "3.11.1" - use the latest release in the 3.11 series. > I uninstalled 3.12 and installed 3.11.1. > > Unfortunately, I am unable to run python now. It keeps asking to be modified, repaired or uninstalled. > > Do you have any suggestions on how to fix this? I think it's been covered in previous replies, but to be even more explicit: *Don't* re-run the Python Installer. Windows will sort of "remember" it and may present it to you when you try to launch, and for some reason the core team appears unwilling to name it something less ambiguous, like python_setup, despite that having been requested several times over the years. You would probably do well to just remove that file (for the case you've described, python-3.11.1-amd64.exe). Python itself is a command-line tool. You can launch python from inside a command shell (Windows Terminal is actually a good choice, even though it's not installed by default), usually by typing "py" (unless you somehow declined to install the Python launcher), or you can navigate to it through the start menu. You will, however, probably want to use some sort of editor to work inside or it gets quite tedious. You can use the included IDLE also via the start menu, or install one of the many free choices available. Your school's curriculum may well guide you here, if you want to be able to follow along exactly with classroom presentation, screenshots, etc. From weijiawenyong at hotmail.com Sun Apr 7 21:31:57 2024 From: weijiawenyong at hotmail.com (Wenyong Wei) Date: Mon, 8 Apr 2024 01:31:57 +0000 Subject: ModuleNotFoundError: No module named 'Paramiko' In-Reply-To: References: Message-ID: Dear Sir/Madam, Recently I encounter a problem that I can't import paramiko in my computer. My PC running on window 10 64 bits. I have investigate this issue via internet, there are a lot of solutions for this issue, after trying most of the steps, I still can't run this module, the major steps I have try are: 1. Install python ver 3.7.1 or 3.11.8 by itself or customer installation (changing the installation folder) and check add python to the path. 2. pip install paramiko, if ver 3.7.1 installed, need to upgrade the pip version. 3. Checking the environment path, there are two path related to the python, one for python.exe, the other for \Lib\site-packages\paramiko can you please provide advice on this issue? BR Ken From sravan.chitikesi at iprotechs.com Mon Apr 8 13:42:55 2024 From: sravan.chitikesi at iprotechs.com (Sravan Kumar Chitikesi) Date: Mon, 8 Apr 2024 23:12:55 +0530 Subject: ModuleNotFoundError: No module named 'Paramiko' In-Reply-To: References: Message-ID: pip may be pointed to another python version. try to remove other python versions and re install pip Regards, *Sravan Chitikesi* AWS Solutions Architect - Associate On Mon, Apr 8, 2024 at 10:58?PM Wenyong Wei via Python-list < python-list at python.org> wrote: > > Dear Sir/Madam, > > Recently I encounter a problem that I can't import paramiko in my > computer. My PC running on window 10 64 bits. I have investigate this issue > via internet, there are a lot of solutions for this issue, after trying > most of the steps, I still can't run this module, the major steps I have > try are: > > > 1. > Install python ver 3.7.1 or 3.11.8 by itself or customer installation > (changing the installation folder) and check add python to the path. > 2. > pip install paramiko, if ver 3.7.1 installed, need to upgrade the pip > version. > 3. > Checking the environment path, there are two path related to the python, > one for python.exe, the other for \Lib\site-packages\paramiko > > can you please provide advice on this issue? > > > > BR > > Ken > -- > https://mail.python.org/mailman/listinfo/python-list > From maillist at schwertberger.de Mon Apr 8 14:01:08 2024 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Mon, 8 Apr 2024 20:01:08 +0200 Subject: ModuleNotFoundError: No module named 'Paramiko' In-Reply-To: References: Message-ID: <8424e635-82eb-4ac0-9eb1-e06819198c81@schwertberger.de> To be sure, you can always go the the directory of the Python interpreter and open a cmd window there. (By entering 'cmd' into the explorer address bar.) Then enter 'python.exe -mpip install paramiko'. This way you can be sure that you're not running a pip.exe that belongs to another Python interpreter. From list1 at tompassin.net Mon Apr 8 14:31:29 2024 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 8 Apr 2024 14:31:29 -0400 Subject: ModuleNotFoundError: No module named 'Paramiko' In-Reply-To: <8424e635-82eb-4ac0-9eb1-e06819198c81@schwertberger.de> References: <8424e635-82eb-4ac0-9eb1-e06819198c81@schwertberger.de> Message-ID: <7becbe28-2c5d-494e-95c9-c4f1fd699fa3@tompassin.net> On 4/8/2024 2:01 PM, Dietmar Schwertberger via Python-list wrote: > To be sure, you can always go the the directory of the Python > interpreter and open a cmd window there. > (By entering 'cmd' into the explorer address bar.) > Then enter 'python.exe -mpip install paramiko'. > This way you can be sure that you're not running a pip.exe that belongs > to another Python interpreter. This is not quite right. The best name of the Python executable may or may not be "python.exe". The command line needs a space after the "-m": -m pip install For , you can check if "python" runs the intended version by using the -V option (must be capitalized): python -V On Windows, Python from python.org usually installs a launcher named "py", which will run the last version installed: py -m pip install ... Or it can run a specific version, e.g.: py -3.7 -m pip install ... This will run Python 3.7 if installed. On Linux, you can run the desired version with, e.g., python3.7 -m pip ... From Keith.S.Thompson+u at gmail.com Mon Apr 8 15:35:12 2024 From: Keith.S.Thompson+u at gmail.com (Keith Thompson) Date: Mon, 08 Apr 2024 12:35:12 -0700 Subject: ModuleNotFoundError: No module named 'Paramiko' References: <8424e635-82eb-4ac0-9eb1-e06819198c81@schwertberger.de> <7becbe28-2c5d-494e-95c9-c4f1fd699fa3@tompassin.net> Message-ID: <87wmp7fy1b.fsf@nosuchdomain.example.com> Thomas Passin writes: > On 4/8/2024 2:01 PM, Dietmar Schwertberger via Python-list wrote: >> To be sure, you can always go the the directory of the Python >> interpreter and open a cmd window there. >> (By entering 'cmd' into the explorer address bar.) >> Then enter 'python.exe -mpip install paramiko'. >> This way you can be sure that you're not running a pip.exe that >> belongs to another Python interpreter. > > This is not quite right. The best name of the Python executable may or > may not be "python.exe". The command line needs a space after the > "-m": No, the option and its argument can be bundled. "-mpip" is equivalent to "-m pip". (The space might make it clearer for human readers.) [...] -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u at gmail.com Working, but not speaking, for Medtronic void Void(void) { Void(); } /* The recursive call of the void */ From list1 at tompassin.net Mon Apr 8 18:35:41 2024 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 8 Apr 2024 18:35:41 -0400 Subject: ModuleNotFoundError: No module named 'Paramiko' In-Reply-To: <87wmp7fy1b.fsf@nosuchdomain.example.com> References: <8424e635-82eb-4ac0-9eb1-e06819198c81@schwertberger.de> <7becbe28-2c5d-494e-95c9-c4f1fd699fa3@tompassin.net> <87wmp7fy1b.fsf@nosuchdomain.example.com> Message-ID: <72daad28-0fc6-42b7-b871-94e0d78fd85c@tompassin.net> On 4/8/2024 3:35 PM, Keith Thompson via Python-list wrote: > Thomas Passin writes: >> On 4/8/2024 2:01 PM, Dietmar Schwertberger via Python-list wrote: >>> To be sure, you can always go the the directory of the Python >>> interpreter and open a cmd window there. >>> (By entering 'cmd' into the explorer address bar.) >>> Then enter 'python.exe -mpip install paramiko'. >>> This way you can be sure that you're not running a pip.exe that >>> belongs to another Python interpreter. >> >> This is not quite right. The best name of the Python executable may or >> may not be "python.exe". The command line needs a space after the >> "-m": > > No, the option and its argument can be bundled. "-mpip" is equivalent > to "-m pip". (The space might make it clearer for human readers.) Oh, surprise, thanks for the correction. My apologies to Dietmar. I'd stick with the space, though, because it's often required by other programs. No sense developing a conflicting habit... From mats at wichmann.us Tue Apr 9 09:50:12 2024 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 9 Apr 2024 07:50:12 -0600 Subject: ModuleNotFoundError: No module named 'Paramiko' In-Reply-To: References: Message-ID: <7ed22ed2-cce8-486e-846c-143481edc44b@wichmann.us> On 4/7/24 19:31, Wenyong Wei via Python-list wrote: > > Dear Sir/Madam, > > Recently I encounter a problem that I can't import paramiko in my computer. My PC running on window 10 64 bits. I have investigate this issue via internet, there are a lot of solutions for this issue, after trying most of the steps, I still can't run this module, the major steps I have try are: > > > 1. > Install python ver 3.7.1 or 3.11.8 by itself or customer installation (changing the installation folder) and check add python to the path. > 2. > pip install paramiko, if ver 3.7.1 installed, need to upgrade the pip version. > 3. > Checking the environment path, there are two path related to the python, one for python.exe, the other for \Lib\site-packages\paramiko > > can you please provide advice on this issue? Going to be more explicit than the other answers: === If an attempted import gives you ModuleNotFound, that *always* means the package is not installed... not at all, or just not in the paths that copy of Python is looking in. === The problem arises in part because most package installation instructions take the simplest approach and just tell you to (for example) pip install paramiko So it's installed. But where did it go? You can check where it went: pip show paramiko That path ("location") needs to be one where your Python interpreter is looking. If all goes well, "pip" and "python" are perfectly matched, but in the current world, there are often several Python interpreters installed (projects may require a specific version, an IDE may grab its own version, something may create and setup a virtualenv, alternate worlds like Conda may set up a Python, the list goes on), and for any given installation on Windows, python.exe and the pip excutable pip.exe go in different directories anyway, and the Windows PATH doesn't always include both, and you easily get mismatches. As others have said, the way to avoid mismatches is to use pip As A Module, specifically a module of the Python you want to use. So if you're using the Python Launcher, that looks like: py -m pip install paramiko Hope this helps. From thomas at python.org Tue Apr 9 15:17:49 2024 From: thomas at python.org (Thomas Wouters) Date: Tue, 9 Apr 2024 21:17:49 +0200 Subject: [RELEASE] Python 3.12.3 and 3.13.0a6 released Message-ID: *It?s time to eclipse the Python 3.11.9 release with two releases*, one of which is the *very last alpha release of Python 3.13*: Python 3.12.3 300+ of the finest commits went into this latest maintenance release of the latest Python version, the most stablest, securest, bugfreeest we could make it. https://www.python.org/downloads/release/python-3123/ Python 3.13.0a6 What?s that? The last alpha release? Just one more month until feature freeze! Get your features done, get your bugs fixed, let?s get 3.13.0 ready for people to actually use! Until then, let?s test with alpha 6. The highlights of 3.13 you ask? Well: - In the interactive interpreter, exception tracebacks are now colorized by default . - A preliminary, *experimental* JIT was added , providing the ground work for significant performance improvements. - The (cyclic) garbage collector is now incremental , which should mean shorter pauses for collection in programs with a lot of objects. - Docstrings now have their leading indentation stripped , reducing memory use and the size of .pyc files. (Most tools handling docstrings already strip leading indentation.) - The dbm module has a new dbm.sqlite3 backend that is used by default when creating new files. - PEP 594 (Removing dead batteries from the standard library) scheduled removals of many deprecated modules: aifc, audioop, chunk, cgi, cgitb, crypt, imghdr, mailcap, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau, telnetlib, uu, xdrlib, lib2to3. - Many other removals of deprecated classes, functions and methods in various standard library modules. - New deprecations , most of which are scheduled for removal from Python 3.15 or 3.16. - C API removals and deprecations . (Some removals present in alpha 1 were reverted in alpha 2, as the removals were deemed too disruptive at this time.) (Hey, *fellow core developer,* if a feature you find important is missing from this list, let Thomas know . It?s getting to be really important now!) https://www.python.org/downloads/release/python-3130a6/ 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 contributions to the Python Software Foundation or CPython itself . Thomas ?can you tell I haven?t had coffee today? Wouters on behalf of your release team, Ned Deily Steve Dower Pablo Galindo Salgado ?ukasz Langa -- Thomas Wouters From weijiawenyong at hotmail.com Tue Apr 9 19:36:03 2024 From: weijiawenyong at hotmail.com (Wenyong Wei) Date: Tue, 9 Apr 2024 23:36:03 +0000 Subject: ModuleNotFoundError: No module named 'Paramiko' In-Reply-To: References: Message-ID: hi Sravan, Thanks for your response, checked and found there is only one python in my PC. ________________________________ From: Sravan Kumar Chitikesi Sent: Tuesday, 9 April 2024 3:42 AM To: Wenyong Wei Cc: python-list at python.org Subject: Re: ModuleNotFoundError: No module named 'Paramiko' pip may be pointed to another python version. try to remove other python versions and re install pip Regards, Sravan Chitikesi AWS Solutions Architect - Associate On Mon, Apr 8, 2024 at 10:58?PM Wenyong Wei via Python-list > wrote: Dear Sir/Madam, Recently I encounter a problem that I can't import paramiko in my computer. My PC running on window 10 64 bits. I have investigate this issue via internet, there are a lot of solutions for this issue, after trying most of the steps, I still can't run this module, the major steps I have try are: 1. Install python ver 3.7.1 or 3.11.8 by itself or customer installation (changing the installation folder) and check add python to the path. 2. pip install paramiko, if ver 3.7.1 installed, need to upgrade the pip version. 3. Checking the environment path, there are two path related to the python, one for python.exe, the other for \Lib\site-packages\paramiko can you please provide advice on this issue? BR Ken -- https://mail.python.org/mailman/listinfo/python-list From arj.python at gmail.com Wed Apr 10 00:31:44 2024 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Wed, 10 Apr 2024 08:31:44 +0400 Subject: [RELEASE] Python 3.12.3 and 3.13.0a6 released In-Reply-To: References: Message-ID: I have to comment on this one: "Docstrings now have their leading indentation stripped" Incredibly useful! Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius On Tue, Apr 9, 2024 at 11:18?PM Thomas Wouters via Python-list < python-list at python.org> wrote: > *It?s time to eclipse the Python 3.11.9 release with two releases*, one of > which is the *very last alpha release of Python 3.13*: > < > https://discuss.python.org/t/python-3-12-3-and-3-13-0a6-released/50601#python-3123-1 > >Python > 3.12.3 > > 300+ of the finest commits went into this latest maintenance release of the > latest Python version, the most stablest, securest, bugfreeest we could > make it. > https://www.python.org/downloads/release/python-3123/ > < > https://discuss.python.org/t/python-3-12-3-and-3-13-0a6-released/50601#python-3130a6-2 > >Python > 3.13.0a6 > > What?s that? The last alpha release? Just one more month until feature > freeze! Get your features done, get your bugs fixed, let?s get 3.13.0 ready > for people to actually use! Until then, let?s test with alpha 6. The > highlights of 3.13 you ask? Well: > > - In the interactive interpreter, exception tracebacks are now colorized > by default > >. > - A preliminary, *experimental* JIT was added > < > https://docs.python.org/dev/whatsnew/3.13.html#experimental-jit-compiler>, > providing the ground work for significant performance improvements. > - The (cyclic) garbage collector is now incremental > < > https://docs.python.org/dev/whatsnew/3.13.html#incremental-garbage-collection > >, > which should mean shorter pauses for collection in programs with a lot > of > objects. > - Docstrings now have their leading indentation stripped > >, > reducing memory use and the size of .pyc files. (Most tools handling > docstrings already strip leading indentation.) > - The dbm module has a > new dbm.sqlite3 backend > that is used by > default when creating new files. > - PEP 594 (Removing dead batteries from the standard library) > scheduled removals of many > deprecated modules: aifc, audioop, chunk, cgi, cgitb, crypt, imghdr, > mailcap, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau, > telnetlib, uu, xdrlib, lib2to3. > - Many other removals > of deprecated > classes, functions and methods in various standard library modules. > - New deprecations > , most of > which are scheduled for removal from Python 3.15 or 3.16. > - C API removals > and deprecations . > (Some removals present in alpha 1 were reverted in alpha 2, as the > removals > were deemed too disruptive at this time.) > > (Hey, *fellow core developer,* if a feature you find important is missing > from this list, let Thomas know . It?s getting to be > really important now!) > https://www.python.org/downloads/release/python-3130a6/ > < > https://discuss.python.org/t/python-3-12-3-and-3-13-0a6-released/50601#we-hope-you-enjoy-the-new-releases-3 > >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 contributions to the Python Software > Foundation or CPython itself > . > > Thomas ?can you tell I haven?t had coffee today? Wouters > on behalf of your release team, > > Ned Deily > Steve Dower > Pablo Galindo Salgado > ?ukasz Langa > -- > Thomas Wouters > -- > https://mail.python.org/mailman/listinfo/python-list > From billkochman777 at gmail.com Wed Apr 10 14:50:49 2024 From: billkochman777 at gmail.com (WordWeaver Evangelist) Date: Thu, 11 Apr 2024 04:50:49 +1000 Subject: How to Add ANSI Color to User Response Message-ID: Hello List, I have a simple question. I use the following textPrompt in some of my Jython modules: '\nYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, forceUppercase=True) Is there a way to add an ANSI color code to the end where the conditions are, so that the color of the user?s input is of a color of my choosing, instead of just white? Thank you very much in advance. Kind regards, Bill Kochman From grant.b.edwards at gmail.com Wed Apr 10 15:53:20 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 10 Apr 2024 15:53:20 -0400 (EDT) Subject: How to Add ANSI Color to User Response References: Message-ID: <4VFD5r6ZpKznV1q@mail.python.org> On 2024-04-10, WordWeaver Evangelist via Python-list wrote: > I have a simple question. I use the following textPrompt in some of my Jython modules: > '\nYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, forceUppercase=True) > Is there a way to add an ANSI color code to the end where the > conditions are, so that the color of the user?s input is of a color > of my choosing, instead of just white? I'm not sure what is meant by "the end where the conditions are", nor do I know what "textPrompt" refers to. Are you asking how to put a second escape sequence at the end of the string literal after the colon? -- Grant From PythonList at DancesWithMice.info Wed Apr 10 17:43:37 2024 From: PythonList at DancesWithMice.info (dn) Date: Thu, 11 Apr 2024 09:43:37 +1200 Subject: How to Add ANSI Color to User Response In-Reply-To: References: Message-ID: <0edb314f-9859-4876-ba1e-befb5a6f1da2@DancesWithMice.info> On 11/04/24 06:50, WordWeaver Evangelist via Python-list wrote: > I have a simple question. I use the following textPrompt in some of my Jython modules: > '\nYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, forceUppercase=True) > Is there a way to add an ANSI color code to the end where the conditions are, so that the color of the user?s input is of a color of my choosing, instead of just white? > Thank you very much in advance. > Kind regards, > Bill Kochman Haven't tried using any of theses techniques, but may define input() color, as well as print():- How to print colored terminal text in Python MAR 06, 2024 ... https://byby.dev/py-print-colored-terminal-text -- Regards =dn From learn2program at gmail.com Wed Apr 10 18:41:23 2024 From: learn2program at gmail.com (Alan Gauld) Date: Wed, 10 Apr 2024 23:41:23 +0100 Subject: How to Add ANSI Color to User Response In-Reply-To: References: Message-ID: <1b305568-7ba1-4329-9f39-a0d22d769272@yahoo.co.uk> On 10/04/2024 19:50, WordWeaver Evangelist via Python-list wrote: > I have a simple question. I use the following textPrompt in some of my Jython modules: > '\nYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, forceUppercase=True) > Is there a way to add an ANSI color code to the end Normally, for any kind of fancy terminal work, I'd say use curses. But I suspect Jython may not support curses? On the offchance it does do curses it would look like: import curses def main(scr): if curses.has_colors(): # check the terminal supports color curses.start_color(). # init the color system curses.init_pair(1,curses.COLOR_YELLOW,curses.COLOR_BLUE) # Now start adding text coloring as desired... scr.addstr(0,0,"This string is yellow and blue", curses.color_pair(1)) scr.refresh(). # make it visible else: scr.addstr("Sorry, no colors available") curses.wrapper(main) HTH -- 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 pf at pfortin.com Wed Apr 10 19:44:49 2024 From: pf at pfortin.com (Pierre Fortin) Date: Wed, 10 Apr 2024 19:44:49 -0400 Subject: How to Add ANSI Color to User Response In-Reply-To: References: Message-ID: <20240410194449.0b2ba78f@pfortin.com> On Thu, 11 Apr 2024 04:50:49 +1000 WordWeaver Evangelist via Python-list wrote: >Hello List, > >I have a simple question. I use the following textPrompt in some of my Jython modules: > '\nYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, forceUppercase=True) >Is there a way to add an ANSI color code to the end where the conditions are, so that the color of the user?s input is of a color of my choosing, instead of just white? >Thank you very much in advance. >Kind regards, >Bill Kochman Over the years, I've tried different mechanisms for applying colors until I got my hands on f-stings; then I created a tiny module with all the colors (cR, cG, etc) which made my life so much simpler (attached). The module includes background colors (bX); but I very rarely use those. Then, I just use the module like this: # place the module in a directory where your script is # e.g., $ mkdir mymods (rename as desired) from mymods.colors import * # or just include the contents inline # this simply switches from one color to the next print( f"{cR}red, {cB}blue, {cG}green {cO}are colors." ) # color just the response ans = input( f"Answer?: {cG}" ) # turn off color on next line print( f"{cO}You entered: {cY}{ans}{cO}" ) # ^^^^ # to turn off each color (white commas), change the above to: print( f"{cR}red{cO}, {cB}blue{cO}, {cG}green {cO}are colors." ) On Windows, you'll need to add this *before* using the colors: import os if os.name == 'nt': # Only if we are running on Windows from ctypes import windll w = windll.kernel32 # enable ANSI VT100 colors on Windows. w.SetConsoleMode(w.GetStdHandle(-11), 7) HTH, Pierre From bouncingcats at gmail.com Wed Apr 10 22:24:59 2024 From: bouncingcats at gmail.com (David) Date: Thu, 11 Apr 2024 02:24:59 +0000 Subject: How to Add ANSI Color to User Response In-Reply-To: References: Message-ID: On Wed, 10 Apr 2024 at 18:51, WordWeaver Evangelist via Python-list wrote: > I have a simple question. I use the following textPrompt in some of my > Jython modules: > '\n [1;33mYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, forceUppercase=True) > Is there a way to add an ANSI color code to the end where the conditions > are, so that the color of the user?s input is of a color of my choosing, > instead of just white? Hi Bill, Here's a tutorial: https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html Note the sentence: "once you print out the special code enabling a color, the color persists forever until someone else prints out the code for a different color, or prints out the Reset code to disable it." Here's a more detailed specification: https://en.wikipedia.org/wiki/ANSI_escape_code And here's a conversation: http://mywiki.wooledge.org/BashFAQ/037 (see the first sentence, and then under the heading "Discussion") that might help you decide whether this approach will satisy your need in your particular circumstances of operating system, Python version, and terminal settings. From grant.b.edwards at gmail.com Wed Apr 10 22:37:31 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 10 Apr 2024 22:37:31 -0400 (EDT) Subject: How to Add ANSI Color to User Response References: <1b305568-7ba1-4329-9f39-a0d22d769272@yahoo.co.uk> Message-ID: <4VFP4C59J4znTq9@mail.python.org> On 2024-04-10, Alan Gauld via Python-list wrote: > On 10/04/2024 19:50, WordWeaver Evangelist via Python-list wrote: > >> I have a simple question. I use the following textPrompt in some of my Jython modules: >> '\nYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, forceUppercase=True) >> Is there a way to add an ANSI color code to the end > > Normally, for any kind of fancy terminal work, I'd say use curses. If you want to use the terminal escape sequences provided by terminfo and ncurses, but don't want to use the ncurses windowing functions, here are some notes on how to do that: https://github.com/GrantEdwards/Python-curses-and-terminfo That too is C-Python oriented, and I don't really know how to do the same things using Jython. -- Grant From PythonList at DancesWithMice.info Thu Apr 11 01:40:38 2024 From: PythonList at DancesWithMice.info (dn) Date: Thu, 11 Apr 2024 17:40:38 +1200 Subject: Data Ethics (Virtual) Meeting Message-ID: <0681520a-4be0-49f9-bcb5-9f6cbc76ada7@DancesWithMice.info> Virtual meeting, Wed 17 April, 1800 for 1830 (NZST, ie 0630 UTC) Data Ethics Emma McDonald is the Director of the Interim Centre for Data Ethics and Innovation at Stats NZ (New Zealand Government Department of Statistics) Emma will talk about why Stats NZ is establishing a Centre for Data Ethics and Innovation, and why it needs to be set up as a network that draws on and leverages knowledge and expertise across relevant work programmes and people across agencies. As an initiative, the Centre is there to help agencies develop and maintain secure and trusted data environments. A large part of this is drawing on a diverse network of people who can support the with sharing the importance of data ethics being a critical component of data driven technologies. Will be of-interest to Quants, Data Science, and Machine Learning folk; as well as those of us with wider interest in what should/not happen with personal, public, and corporate data... She will be wanting to hear what folk have to say, and is interested to recruit competent individuals for hui*, consultations, and the like. WebRef: https://data.govt.nz/leadership/the-interim-centre-for-data-ethics-and-innovation/ from which you can access their Work Programme and Guidance developed to-date. Please RSVP at https://www.meetup.com/nzpug-auckland/events/299764076/ * hui is the Te Reo Maori word for meeting or conference (Te Reo is one of New Zealand's official languages) -- Regards =dn From list1 at tompassin.net Wed Apr 10 20:01:51 2024 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 10 Apr 2024 20:01:51 -0400 Subject: How to Add ANSI Color to User Response In-Reply-To: <1b305568-7ba1-4329-9f39-a0d22d769272@yahoo.co.uk> References: <1b305568-7ba1-4329-9f39-a0d22d769272@yahoo.co.uk> Message-ID: <36bf592b-d202-476f-b6d3-62af691a97cf@tompassin.net> On 4/10/2024 6:41 PM, Alan Gauld via Python-list wrote: > On 10/04/2024 19:50, WordWeaver Evangelist via Python-list wrote: > >> I have a simple question. I use the following textPrompt in some of my Jython modules: >> '\nYour choice is? (A B C D E): ', maxChars=1, autoAccept=False, forceUppercase=True) >> Is there a way to add an ANSI color code to the end > > Normally, for any kind of fancy terminal work, I'd say use curses. > But I suspect Jython may not support curses? > > On the offchance it does do curses it would look like: > > import curses > > def main(scr): > if curses.has_colors(): # check the terminal supports color > curses.start_color(). # init the color system > curses.init_pair(1,curses.COLOR_YELLOW,curses.COLOR_BLUE) > > # Now start adding text coloring as desired... > scr.addstr(0,0,"This string is yellow and blue", > curses.color_pair(1)) > > scr.refresh(). # make it visible > else: scr.addstr("Sorry, no colors available") > > curses.wrapper(main) > > HTH Curses is a C module, and there is a Python interface to it. Jython would have to find an equivalent Java library. Still, isn't the case that the terminal color output commands are pretty standard? They could just be stuck into the output string. Doing more fancy things, like moving the cursor arbitrarily, probably differ but the OP just mentioned colors. From perso.olivier.barthelemy at gmail.com Thu Apr 11 08:42:22 2024 From: perso.olivier.barthelemy at gmail.com (Olivier B.) Date: Thu, 11 Apr 2024 14:42:22 +0200 Subject: First two bytes of 'stdout' are lost Message-ID: I am trying to use StringIO to capture stdout, in code that looks like this: import sys from io import StringIO old_stdout = sys.stdout sys.stdout = mystdout = StringIO() print( "patate") mystdout.seek(0) sys.stdout = old_stdout print(mystdout.read()) Well, it is not exactly like this, since this works properly This code is actually run from C++ using the C Python API. This worked quite well, so the code was right at some point. But now, two things changed: - Now using python 3.11.7 instead of 3.7.12 - Now using only the python limited C API And it seems that now, mystdout.read() always misses the first two characters that have been written to stdout. My first ideas was something related to the BOM improperly truncated at some point, but i am manipulating UTF-8, so the bom would be 3 bytes, not 2. I ruled out wrong C++ code to extract the string from the python variable, since running a python print of the content of mystdout in the real stdout also misses the two first characters. Hopefully someone has a clue on what would have changed in Python for this to stop working compared to python 3.7? From perso.olivier.barthelemy at gmail.com Thu Apr 11 09:09:32 2024 From: perso.olivier.barthelemy at gmail.com (Olivier B.) Date: Thu, 11 Apr 2024 15:09:32 +0200 Subject: First two bytes of 'stdout' are lost In-Reply-To: References: Message-ID: Partly answering myself: For some reason, right after mystdout has been created, i now have to do mystdout.seek(0) and this solves the issue. No idea why though.. Le jeu. 11 avr. 2024 ? 14:42, Olivier B. a ?crit : > > I am trying to use StringIO to capture stdout, in code that looks like this: > > import sys > from io import StringIO > old_stdout = sys.stdout > sys.stdout = mystdout = StringIO() > print( "patate") > mystdout.seek(0) > sys.stdout = old_stdout > print(mystdout.read()) > > Well, it is not exactly like this, since this works properly > > This code is actually run from C++ using the C Python API. > This worked quite well, so the code was right at some point. But now, > two things changed: > - Now using python 3.11.7 instead of 3.7.12 > - Now using only the python limited C API > > And it seems that now, mystdout.read() always misses the first two > characters that have been written to stdout. > > My first ideas was something related to the BOM improperly truncated > at some point, but i am manipulating UTF-8, so the bom would be 3 > bytes, not 2. > > I ruled out wrong C++ code to extract the string from the python > variable, since running a python print of the content of mystdout in > the real stdout also misses the two first characters. > > Hopefully someone has a clue on what would have changed in Python for > this to stop working compared to python 3.7? From list1 at tompassin.net Thu Apr 11 09:19:09 2024 From: list1 at tompassin.net (Thomas Passin) Date: Thu, 11 Apr 2024 09:19:09 -0400 Subject: First two bytes of 'stdout' are lost In-Reply-To: References: Message-ID: <804f3151-f662-4419-b1d2-9b0788a6585b@tompassin.net> On 4/11/2024 8:42 AM, Olivier B. via Python-list wrote: > I am trying to use StringIO to capture stdout, in code that looks like this: > > import sys > from io import StringIO > old_stdout = sys.stdout > sys.stdout = mystdout = StringIO() > print( "patate") > mystdout.seek(0) > sys.stdout = old_stdout > print(mystdout.read()) > > Well, it is not exactly like this, since this works properly > > This code is actually run from C++ using the C Python API. > This worked quite well, so the code was right at some point. But now, > two things changed: > - Now using python 3.11.7 instead of 3.7.12 > - Now using only the python limited C API > > And it seems that now, mystdout.read() always misses the first two > characters that have been written to stdout. > > My first ideas was something related to the BOM improperly truncated > at some point, but i am manipulating UTF-8, so the bom would be 3 > bytes, not 2. > > I ruled out wrong C++ code to extract the string from the python > variable, since running a python print of the content of mystdout in > the real stdout also misses the two first characters. > > Hopefully someone has a clue on what would have changed in Python for > this to stop working compared to python 3.7? I've not used the C API, so just for fun I asked ChatGPT about this and it suggested that a flush after writing to StringIO might do it. It suggested using a custom class for this purpose: class MyStringIO(StringIO): def write(self, s): # Override write method to ensure all characters are written correctly super().write(s) self.flush() You would use it like this: sys.stdout = mystdout = MyStringIO() I haven't tested it but it seems reasonable, although I would have naively expected to lose bytes from the end, not the beginning. From cs at cskk.id.au Thu Apr 11 17:41:05 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 12 Apr 2024 07:41:05 +1000 Subject: How to Add ANSI Color to User Response In-Reply-To: <1b305568-7ba1-4329-9f39-a0d22d769272@yahoo.co.uk> References: <1b305568-7ba1-4329-9f39-a0d22d769272@yahoo.co.uk> Message-ID: On 10Apr2024 23:41, Alan Gauld wrote: >Normally, for any kind of fancy terminal work, I'd say use curses. My problem with curses is that it takes over the whole terminal - you need to manage everything from that point on. Great if you want it (eg some full-terminal tool like `top`) but complex overkill for small interactive (or not interactive) commands which are basicly printing lines of text. Which is what many of my scripts are. That said, you don't _have_ to use curses to run the whole terminal. You can use it to just look up the terminal capabilities and use those strings. I haven't tried that for colours, but here's some same code from my `cs.upd` module using curses to look up various cursor motion type things: ... up the top ... try: import curses except ImportError as curses_e: warning("cannot import curses: %s", curses_e) curses = None ... later we cache the available motions ... try: # pylint: disable=no-member curses.setupterm(fd=backend_fd) except TypeError: pass else: for ti_name in ( 'vi', # cursor invisible 'vs', # cursor visible 'cuu1', # cursor up one line 'dl1', # delete one line 'il1', # insert one line 'el', # clear to end of line ): # pylint: disable=no-member s = curses.tigetstr(ti_name) if s is not None: s = s.decode('ascii') self._ti_strs[ti_name] = s ... then a method to access the cache ... def ti_str(self, ti_name): ''' Fetch the terminfo capability string named `ti_name`. Return the string or `None` if not available. ''' return self._ti_strs.get(ti_name, None) ... and even later, use the method ... # emit cursor_up cursor_up = self.ti_str('cuu1') movetxts.append(cursor_up * (to_slot - from_slot)) Generally, when I add ANSI colours I do it via a little module of my own, `cs.ansi_colour`, which you can get from PyPI using `pip`. The two most useful items in it for someone else are probably `colourise` and `colourise_patterns`. Link: https://github.com/cameron-simpson/css/blob/26504f1df55e1bbdef00c3ff7f0cb00b2babdc01/lib/python/cs/ansi_colour.py#L96 I particularly use it to automatically colour log messages on a terminal, example code: https://github.com/cameron-simpson/css/blob/26504f1df55e1bbdef00c3ff7f0cb00b2babdc01/lib/python/cs/logutils.py#L824 From cs at cskk.id.au Thu Apr 11 17:55:55 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 12 Apr 2024 07:55:55 +1000 Subject: First two bytes of 'stdout' are lost In-Reply-To: References: Message-ID: On 11Apr2024 14:42, Olivier B. wrote: >I am trying to use StringIO to capture stdout, in code that looks like this: > >import sys >from io import StringIO >old_stdout = sys.stdout >sys.stdout = mystdout = StringIO() >print( "patate") >mystdout.seek(0) >sys.stdout = old_stdout >print(mystdout.read()) > >Well, it is not exactly like this, since this works properly Aye, I just tried that. All good. >This code is actually run from C++ using the C Python API. >This worked quite well, so the code was right at some point. But now, >two things changed: > - Now using python 3.11.7 instead of 3.7.12 > - Now using only the python limited C API Maybe you should post the code then: the exact Python code and the exact C++ code. >And it seems that now, mystdout.read() always misses the first two >characters that have been written to stdout. > >My first ideas was something related to the BOM improperly truncated >at some point, but i am manipulating UTF-8, so the bom would be 3 >bytes, not 2. I didn't think UTF-8 needed a BOM. Somone will doubtless correct me. However, does the `mystdout.read()` code _know_ you're using UTF-8? I have the vague impression that eg some Windows systems default to UTF-16 of some flavour, possibly _with_ a BOM. I'm suggesting that you rigorously check that the bytes->text bits know what text encoding they're using. If you've left an encoding out anywhere, put it in explicitly. >Hopefully someone has a clue on what would have changed in Python for >this to stop working compared to python 3.7? None at all, alas. My experience with the Python C API is very limited. From gvanem at yahoo.no Wed Apr 10 23:00:32 2024 From: gvanem at yahoo.no (Gisle Vanem) Date: Thu, 11 Apr 2024 05:00:32 +0200 Subject: How to Add ANSI Color to User Response In-Reply-To: <20240410194449.0b2ba78f@pfortin.com> References: <20240410194449.0b2ba78f@pfortin.com> Message-ID: Pierre Fortin wrote: > Over the years, I've tried different mechanisms for applying colors until > I got my hands on f-stings; then I created a tiny module with all the > colors (cR, cG, etc) which made my life so much simpler (attached). Attachments are stripped off in this list. It would be nice to see this tiny module of yours. An URL or attach as inline text please. From nospam at please.ty Fri Apr 12 14:40:09 2024 From: nospam at please.ty (jak) Date: Fri, 12 Apr 2024 20:40:09 +0200 Subject: help: pandas and 2d table Message-ID: Hi everyone. I state that I don't know anything about 'pandas' but I intuited that it could do what I want. I get, through the "read_excel" method, a table similar to this: obj| foo1 foo2 foo3 foo4 foo5 foo6 ----------------------------------- foo1| aa ab zz ad ae af | foo2| ba bb bc bd zz bf | foo3| ca zz cc cd ce zz | foo4| da db dc dd de df | foo5| ea eb ec zz ee ef | foo6| fa fb fc fd fe ff And I would like to get a result similar to this: { 'zz':[('foo1','foo3'), ('foo2','foo5'), ('foo3','foo2'), ('foo3','foo6'), ('foo5','foo4') ] } Would you show me the path, please? Thank you in advance. From pf at pfortin.com Sat Apr 13 02:18:07 2024 From: pf at pfortin.com (Pierre Fortin) Date: Sat, 13 Apr 2024 02:18:07 -0400 Subject: How to Add ANSI Color to User Response In-Reply-To: References: <20240410194449.0b2ba78f@pfortin.com> Message-ID: <20240413021807.4e35853d@pfortin.com> On Thu, 11 Apr 2024 05:00:32 +0200 Gisle Vanem via Python-list wrote: >Pierre Fortin wrote: > >> Over the years, I've tried different mechanisms for applying colors until >> I got my hands on f-stings; then I created a tiny module with all the >> colors (cR, cG, etc) which made my life so much simpler (attached). > >Attachments are stripped off in this list. >It would be nice to see this tiny module of yours. >An URL or attach as inline text please. #!/bin/python # -*- mode: python; -*- # Copyright: # 2024-Present, Pierre Fortin # License: # GPLv3 or any later version: https://www.gnu.org/licenses/gpl-3.0.en.html # Created: # 2023-11-10 Initial script # Updated: # Usage: f"{cR}red text {cG}green text{cO}; colors off" # or: print( cY, "yellow text", cO ) # VT100 type terminal colors ESC = "\u001b"; # Foreground Colors _black = f"{ESC}[30m"; _red = f"{ESC}[31m"; _green = f"{ESC}[32m"; _yellow = f"{ESC}[33m" _blue = f"{ESC}[34m"; _magenta = f"{ESC}[35m"; _cyan = f"{ESC}[36m"; _white = f"{ESC}[37m" # Background Colors _black_ = f"{ESC}[40m"; _red_ = f"{ESC}[41m"; _green_ = f"{ESC}[42m"; _yellow_ = f"{ESC}[43m" _blue_ = f"{ESC}[44m"; _magenta_ = f"{ESC}[45m"; _cyan_ = f"{ESC}[46m"; _white_ = f"{ESC}[47m" _off = f"{ESC}[0m" ANSIEraseLine = '\033[2K\033[1G' EL = ANSIEraseLine # short alias # Color abbreviations (shortcuts for f-sting use) cK=_black; cR=_red; cG=_green; cY=_yellow; cB=_blue; cM=_magenta; cC=_cyan; cW=_white; cO=_off # background colors; use {cO} to turn off any color bK=_black_; bR=_red_; bG=_green_; bY=_yellow_; bB=_blue_; bM=_magenta_; bC=_cyan_; bW=_white_ From nospam at please.ty Sat Apr 13 09:00:35 2024 From: nospam at please.ty (jak) Date: Sat, 13 Apr 2024 15:00:35 +0200 Subject: help: pandas and 2d table In-Reply-To: References: Message-ID: Stefan Ram ha scritto: > jak wrote or quoted: >> Would you show me the path, please? > > I was not able to read xls here, so I used csv instead; Warning: > the script will overwrite file "file_20240412201813_tmp_DML.csv"! > > import pandas as pd > > with open( 'file_20240412201813_tmp_DML.csv', 'w' )as out: > print( '''obj,foo1,foo2,foo3,foo4,foo5,foo6 > foo1,aa,ab,zz,ad,ae,af > foo2,ba,bb,bc,bd,zz,bf > foo3,ca,zz,cc,cd,ce,zz > foo4,da,db,dc,dd,de,df > foo5,ea,eb,ec,zz,ee,ef > foo6,fa,fb,fc,fd,fe,ff''', file=out ) > > df = pd.read_csv( 'file_20240412201813_tmp_DML.csv' ) > > result = {} > > for rownum, row in df.iterrows(): > iterator = row.items() > _, rowname = next( iterator ) > for colname, value in iterator: > if value not in result: result[ value ]= [] > result[ value ].append( ( rowname, colname )) > > print( result ) > In reality what I wanted to achieve was this: what = 'zz' result = {what: []} for rownum, row in df.iterrows(): iterator = row.items() _, rowname = next(iterator) for colname, value in iterator: if value == what: result[what] += [(rowname, colname)] print(result) In any case, thank you again for pointing me in the right direction. I had lost myself looking for a pandas method that would do this in a single shot or almost. From mats at wichmann.us Sat Apr 13 13:07:37 2024 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 13 Apr 2024 11:07:37 -0600 Subject: help: pandas and 2d table In-Reply-To: References: Message-ID: <8b63c74a-d8e5-4c3a-ac3e-b240c88b7dcb@wichmann.us> On 4/13/24 07:00, jak via Python-list wrote: > Stefan Ram ha scritto: >> jak wrote or quoted: >>> Would you show me the path, please? >> >> ?? I was not able to read xls here, so I used csv instead; Warning: >> ?? the script will overwrite file "file_20240412201813_tmp_DML.csv"! >> >> import pandas as pd >> >> with open( 'file_20240412201813_tmp_DML.csv', 'w' )as out: >> ???? print( '''obj,foo1,foo2,foo3,foo4,foo5,foo6 >> foo1,aa,ab,zz,ad,ae,af >> foo2,ba,bb,bc,bd,zz,bf >> foo3,ca,zz,cc,cd,ce,zz >> foo4,da,db,dc,dd,de,df >> foo5,ea,eb,ec,zz,ee,ef >> foo6,fa,fb,fc,fd,fe,ff''', file=out ) >> >> df = pd.read_csv( 'file_20240412201813_tmp_DML.csv' ) >> >> result = {} >> >> for rownum, row in df.iterrows(): >> ???? iterator = row.items() >> ???? _, rowname = next( iterator ) >> ???? for colname, value in iterator: >> ???????? if value not in result: result[ value ]= [] >> ???????? result[ value ].append( ( rowname, colname )) >> >> print( result ) >> > > In reality what I wanted to achieve was this: > > ??? what = 'zz' > ??? result = {what: []} > > ??? for rownum, row in df.iterrows(): > ??????? iterator = row.items() > ??????? _, rowname = next(iterator) > ??????? for colname, value in iterator: > ??????????? if value == what: > ??????????????? result[what] += [(rowname, colname)] > ??? print(result) > > In any case, thank you again for pointing me in the right direction. I > had lost myself looking for a pandas method that would do this in a > single shot or almost. > > doesn't Pandas have a "where" method that can do this kind of thing? Or doesn't it match what you are looking for? Pretty sure numpy does, but that's a lot to bring in if you don't need the rest of numpy. From tjandacw at gmail.com Sat Apr 13 13:14:35 2024 From: tjandacw at gmail.com (Tim Williams) Date: Sat, 13 Apr 2024 13:14:35 -0400 Subject: help: pandas and 2d table In-Reply-To: <8b63c74a-d8e5-4c3a-ac3e-b240c88b7dcb@wichmann.us> References: <8b63c74a-d8e5-4c3a-ac3e-b240c88b7dcb@wichmann.us> Message-ID: On Sat, Apr 13, 2024 at 1:10?PM Mats Wichmann via Python-list < python-list at python.org> wrote: > On 4/13/24 07:00, jak via Python-list wrote: > > doesn't Pandas have a "where" method that can do this kind of thing? Or > doesn't it match what you are looking for? Pretty sure numpy does, but > that's a lot to bring in if you don't need the rest of numpy. > > pandas.DataFrame.where ? pandas 2.2.2 documentation (pydata.org) From python at aliases.systohc.net Sat Apr 13 14:49:15 2024 From: python at aliases.systohc.net (Fabiano Sidler) Date: Sat, 13 Apr 2024 20:49:15 +0200 Subject: Custom importer and errors Message-ID: <0aeaf41e-83a5-4b16-8b1b-117193b7f032@aliases.systohc.net> Hi folks! I'd like to split my package tree into several IDE projects and build a custom importer to import ??? 'top.child1.child2' from the directory ??? /top.child1.child2/__init__.py so basically replacing the dots with slashes and having the package content lying directly in the project folder. I have come up with this: === usercustomize.py === ?1 import sys ?2 from importlib.machinery import ModuleSpec ?3 from pathlib import Path ?4 ?5 Loader = type(__spec__.loader) ?6 ?7 class IdeHelper: ?8???? @classmethod ?9???? def find_spec(cls, name, path, target=None): 10???????? for dirname in sys.path: 11???????????? dirobj = Path(dirname) 12???????????? if dirobj.name == name: 13???????????????? break 14???????? else: 15???????????? return None 16???????? origin = str(dirobj.joinpath('__init__.py').absolute()) 17???????? ret = ModuleSpec(name, Loader(name, origin), origin=origin) 18???????? return ret 19 20 sys.meta_path.append(IdeHelper) which I'm on the right direction with. Unfortunately, I'm getting errors while importing a subpackage. With 'import top.child1' the error is ??? ModuleNotFoundError: No module named 'top.child1'; 'top' is not a package whereas with 'from top import child1' the error changes to ??? ImportError: cannot import name 'child1' from 'top' (unknown location) How can I make this work? Best wishes, Fabiano From nospam at please.ty Sat Apr 13 17:35:57 2024 From: nospam at please.ty (jak) Date: Sat, 13 Apr 2024 23:35:57 +0200 Subject: help: pandas and 2d table In-Reply-To: References: <8b63c74a-d8e5-4c3a-ac3e-b240c88b7dcb@wichmann.us> Message-ID: Stefan Ram ha scritto: > df = df.where( df == 'zz' ).stack().reset_index() > result ={ 'zz': list( zip( df.iloc[ :, 0 ], df.iloc[ :, 1 ]))} Since I don't know Pandas, I will need a month at least to understand these 2 lines of code. Thanks again. From nospam at please.ty Mon Apr 15 02:05:18 2024 From: nospam at please.ty (jak) Date: Mon, 15 Apr 2024 08:05:18 +0200 Subject: help: pandas and 2d table In-Reply-To: References: <8b63c74a-d8e5-4c3a-ac3e-b240c88b7dcb@wichmann.us> Message-ID: Stefan Ram ha scritto: > jak wrote or quoted: >> Stefan Ram ha scritto: >>> df = df.where( df == 'zz' ).stack().reset_index() >>> result ={ 'zz': list( zip( df.iloc[ :, 0 ], df.iloc[ :, 1 ]))} >> Since I don't know Pandas, I will need a month at least to understand >> these 2 lines of code. Thanks again. > > Here's a technique to better understand such code: > > Transform it into a program with small statements and small > expressions with no more than one call per statement if possible. > (After each litte change check that the output stays the same.) > > import pandas as pd > > # Warning! Will overwrite the file 'file_20240412201813_tmp_DML.csv'! > with open( 'file_20240412201813_tmp_DML.csv', 'w' )as out: > print( '''obj,foo1,foo2,foo3,foo4,foo5,foo6 > foo1,aa,ab,zz,ad,ae,af > foo2,ba,bb,bc,bd,zz,bf > foo3,ca,zz,cc,cd,ce,zz > foo4,da,db,dc,dd,de,df > foo5,ea,eb,ec,zz,ee,ef > foo6,fa,fb,fc,fd,fe,ff''', file=out ) > # Note the "index_col=0" below, which is important here! > df = pd.read_csv( 'file_20240412201813_tmp_DML.csv', index_col=0 ) > > selection = df.where( df == 'zz' ) > selection_stack = selection.stack() > df = selection_stack.reset_index() > df0 = df.iloc[ :, 0 ] > df1 = df.iloc[ :, 1 ] > z = zip( df0, df1 ) > l = list( z ) > result ={ 'zz': l } > print( result ) > > I suggest to next insert print statements to print each intermediate > value: > > # Note the "index_col=0" below, which is important here! > df = pd.read_csv( 'file_20240412201813_tmp_DML.csv', index_col=0 ) > print( 'df = \n', type( df ), ':\n"', df, '"\n' ) > > selection = df.where( df == 'zz' ) > print( "result of where( df == 'zz' ) = \n", type( selection ), ':\n"', > selection, '"\n' ) > > selection_stack = selection.stack() > print( 'result of stack() = \n', type( selection_stack ), ':\n"', > selection_stack, '"\n' ) > > df = selection_stack.reset_index() > print( 'result of reset_index() = \n', type( df ), ':\n"', df, '"\n' ) > > df0 = df.iloc[ :, 0 ] > print( 'value of .iloc[ :, 0 ]= \n', type( df0 ), ':\n"', df0, '"\n' ) > > df1 = df.iloc[ :, 1 ] > print( 'value of .iloc[ :, 1 ] = \n', type( df1 ), ':\n"', df1, '"\n' ) > > z = zip( df0, df1 ) > print( 'result of zip( df0, df1 )= \n', type( z ), ':\n"', z, '"\n' ) > > l = list( z ) > print( 'result of list( z )= \n', type( l ), ':\n"', l, '"\n' ) > > result ={ 'zz': l } > print( "value of { 'zz': l }= \n", type( result ), ':\n"', > result, '"\n' ) > > print( result ) > > Now you can see what each single step does! > > df = > : > " foo1 foo2 foo3 foo4 foo5 foo6 > obj > foo1 aa ab zz ad ae af > foo2 ba bb bc bd zz bf > foo3 ca zz cc cd ce zz > foo4 da db dc dd de df > foo5 ea eb ec zz ee ef > foo6 fa fb fc fd fe ff " > > result of where( df == 'zz' ) = > : > " foo1 foo2 foo3 foo4 foo5 foo6 > obj > foo1 NaN NaN zz NaN NaN NaN > foo2 NaN NaN NaN NaN zz NaN > foo3 NaN zz NaN NaN NaN zz > foo4 NaN NaN NaN NaN NaN NaN > foo5 NaN NaN NaN zz NaN NaN > foo6 NaN NaN NaN NaN NaN NaN " > > result of stack() = > : > " obj > foo1 foo3 zz > foo2 foo5 zz > foo3 foo2 zz > foo6 zz > foo5 foo4 zz > dtype: object " > > result of reset_index() = > : > " obj level_1 0 > 0 foo1 foo3 zz > 1 foo2 foo5 zz > 2 foo3 foo2 zz > 3 foo3 foo6 zz > 4 foo5 foo4 zz " > > value of .iloc[ :, 0 ]= > : > " 0 foo1 > 1 foo2 > 2 foo3 > 3 foo3 > 4 foo5 > Name: obj, dtype: object " > > value of .iloc[ :, 1 ] = > : > " 0 foo3 > 1 foo5 > 2 foo2 > 3 foo6 > 4 foo4 > Name: level_1, dtype: object " > > result of zip( df0, df1 )= > : > " " > > result of list( z )= > : > " [('foo1', 'foo3'), ('foo2', 'foo5'), ('foo3', 'foo2'), ('foo3', 'foo6'), ('foo5', 'foo4')]" > > value of { 'zz': l }= > : > " {'zz': [('foo1', 'foo3'), ('foo2', 'foo5'), ('foo3', 'foo2'), ('foo3', 'foo6'), ('foo5', 'foo4')]}" > > {'zz': [('foo1', 'foo3'), ('foo2', 'foo5'), ('foo3', 'foo2'), ('foo3', 'foo6'), ('foo5', 'foo4')]} > > The script reads a CSV file and stores the data in a Pandas > DataFrame object named "df". The "index_col=0" parameter tells > Pandas to use the first column as the index for the DataFrame, > which is kinda like column headers. > > The "where" creates a new DataFrame selection that contains > the same data as df, but with all values replaced by NaN (Not > a Number) except for the values that are equal to 'zz'. > > "stack" returns a Series with a multi-level index created > by pivoting the columns. Here it gives a Series with the > row-col-addresses of a all the non-NaN values. The general > meaning of "stack" might be the most complex operation of > this script. It's explained in the pandas manual (see there). > > "reset_index" then just transforms this Series back into a > DataFrame, and ".iloc[ :, 0 ]" and ".iloc[ :, 1 ]" are the > first and second column, respectively, of that DataFrame. These > then are zipped to get the desired form as a list of pairs. > And this is a technique very similar to reverse engineering. Thanks for the explanation and examples. All this is really clear and I was able to follow it easily because I have already written a version of this code in C without any kind of external library that uses the .CSV version of the table as data ( 234 code lines :^/ ). From info at egenix.com Mon Apr 15 14:23:06 2024 From: info at egenix.com (eGenix Team) Date: Mon, 15 Apr 2024 20:23:06 +0200 Subject: =?UTF-8?Q?ANN=3A_Python_Meeting_D=C3=BCsseldorf_-_17=2E04=2E2024?= Message-ID: <18d3ae8d-bd4f-4457-9e73-6a203d32040f@egenix.com> /This announcement is in German since it targets a local user group//meeting in D?sseldorf, Germany/ Ank?ndigung Python Meeting D?sseldorf - April 2024 Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. *17.04.2024, 18:00 Uhr* Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden , Bachstr. 145, 40217 D?sseldorf Programm Bereits angemeldete Vortr?ge: * Marc-Andr? Lemburg: /*Advanced parsing structured data* with Python's new match statement / * Jens Diemer: /Anbindung von *Tinkerforge* in Home Assistant / * Charlie Clark: /Eine kleine *Datenanalyse */ * Detlef Lannert: /?berblick ?ber *CLI-Frameworks*/ Weitere Vortr?ge k?nnen gerne noch angemeldet werden. Bei Interesse, bitte unter info at pyddf.de melden. Startzeit und Ort Wir treffen uns um 18:00 Uhr im B?rgerhaus in den D?sseldorfer Arcaden. Das B?rgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet sich an der Seite der Tiefgarageneinfahrt der D?sseldorfer Arcaden. ?ber dem Eingang steht ein gro?es "Schwimm? in Bilk" Logo. Hinter der T?r direkt links zu den zwei Aufz?gen, dann in den 2. Stock hochfahren. Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt. >>> Eingang in Google Street View *?? Wichtig*: Bitte nur dann anmelden, wenn ihr absolut sicher seid, dass ihr auch kommt. Angesichts der begrenzten Anzahl Pl?tze, haben wir kein Verst?ndnis f?r kurzfristige Absagen oder No-Shows. Einleitung Das Python Meeting D?sseldorf ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet. Einen guten ?berblick ?ber die Vortr?ge bietet unser PyDDF YouTube-Kanal , auf dem wir Videos der Vortr?ge nach den Meetings ver?ffentlichen. Veranstaltet wird das Meeting von der eGenix.com GmbH , Langenfeld, in Zusammenarbeit mit Clark Consulting & Research , D?sseldorf: Format Das Python Meeting D?sseldorf nutzt eine Mischung aus (Lightning) Talks und offener Diskussion. Vortr?ge k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit HDMI und FullHD Aufl?sung steht zur Verf?gung. (Lightning) Talk Anmeldung bitte formlos per EMail an info at pyddf.de Kostenbeteiligung Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Da Tagungsraum, Beamer, Internet und Getr?nke Kosten produzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst. Sch?ler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. Anmeldung Da wir nur 25 Personen in dem angemieteten Raum empfangen k?nnen, m?chten wir bitten, sich vorher anzumelden. *Meeting Anmeldung* bitte per Meetup Weitere Informationen Weitere Informationen finden Sie auf der Webseite des Meetings: https://pyddf.de/ Viel Spa? ! -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Apr 15 2024) >>> Python Projects, Coaching and Support ... https://www.egenix.com/ >>> Python Product Development ... https://consulting.egenix.com/ ________________________________________________________________________ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/ From perso.olivier.barthelemy at gmail.com Thu Apr 25 10:13:26 2024 From: perso.olivier.barthelemy at gmail.com (Olivier B.) Date: Thu, 25 Apr 2024 16:13:26 +0200 Subject: Changing path to python in pip.exe, ipython.exe, etc Message-ID: I am building a python work environment where - i build python from sources - install pip with the wheel bundled with python - then install things with pip, like Jupyter That environment is then deployed on various machines, at various installation folders. One issue I encounter, is the path to python in scripts like pip, ipython, jupyter, etc is the original path where python is installed. On linux, i can just do some sed in the problematic scripts. On windows however, those scripts are python embedded in an EXE. Probably generated by the same tool, as they all have a similar size and a structure of an exe that contains a compressed __main__.py that launch the relevant python module for the command. What is the tool that creates those executables, and is there a way to regenerate them from the python that has been deployed somewhere else, so they point to the correct final path to python on that machine? Since pip is able to create ipython.exe with path to my python embedded for example, i assume i already have all i need in my python installation to regenerate them? From nospam at please.ty Sat Apr 27 14:45:35 2024 From: nospam at please.ty (jak) Date: Sat, 27 Apr 2024 20:45:35 +0200 Subject: UTF_16 question Message-ID: Hi everyone, one thing that I do not understand is happening to me: I have some text files with different characteristics, among these there are that they have an UTF_32_le coding, utf_32be, utf_16_le, utf_16_be all of them without BOM. With those utf_32_xx I have no problem but with the UTF_16_xx I have. If I have an utf_16_le coded file and I read it with encoding='utf_16_le' I have no problem I read it, with encoding='utf_16_be' I can read it without any error even if the data I receive have the inverted bytes. The same thing happens with the utf_16_be codified file, I read it, both with encoding='utf_16_be' and with 'utf_16_le' without errors but in the last case the bytes are inverted. What did I not understand? What am I doing wrong? thanks in advance From nospam at please.ty Sat Apr 27 20:50:08 2024 From: nospam at please.ty (jak) Date: Sun, 28 Apr 2024 02:50:08 +0200 Subject: UTF_16 question In-Reply-To: References: Message-ID: Stefan Ram ha scritto: > jak wrote or quoted: >> I read it, both with encoding='utf_16_be' and >> with 'utf_16_le' without errors but in the last case the bytes are >> inverted. > > I think the order of the octets (bytes) is exactly the difference > between these two encodings, so your observation isn't really > surprising. The computer can't report an error here since it > can't infer the correct encoding from the file data. It's like > that koan: "A bit has the value 1. What does that mean?". > Understood. They are just 2 bytes and there is no difference between them. Thank you. From richard at damon-family.org Mon Apr 29 12:41:48 2024 From: richard at damon-family.org (Richard Damon) Date: Mon, 29 Apr 2024 12:41:48 -0400 Subject: UTF_16 question In-Reply-To: References: Message-ID: <08F2BE28-1252-4BD6-AED0-2323E112E0A1@damon-family.org> > On Apr 29, 2024, at 12:23?PM, jak via Python-list wrote: > > ?Hi everyone, > one thing that I do not understand is happening to me: I have some text > files with different characteristics, among these there are that they > have an UTF_32_le coding, utf_32be, utf_16_le, utf_16_be all of them > without BOM. With those utf_32_xx I have no problem but with the > UTF_16_xx I have. If I have an utf_16_le coded file and I read it with > encoding='utf_16_le' I have no problem I read it, with > encoding='utf_16_be' I can read it without any error even if the data I > receive have the inverted bytes. The same thing happens with the > utf_16_be codified file, I read it, both with encoding='utf_16_be' and > with 'utf_16_le' without errors but in the last case the bytes are > inverted. What did I not understand? What am I doing wrong? > > thanks in advance > > -- > https://mail.python.org/mailman/listinfo/python-list That is why the BOM was created. A lot of files can be ?correctly? read as either UTF-16-LE or UTF-1-BE encoded, as most of the 16 bit codes are valid, so unless the wrong encoding happens to hit something that is invalid (most likely something looking like a Surrogage Pair without a match), there isn?t an error in reading the file. The BOM character was specifically designed to be an invalid code if read by the wrong encoding (if you ignore the possibility of the file having a NUL right after the BOM) If you know the files likely contains a lot of ?ASCII? characters, then you might be able to detect that you got it wrong, due to seeing a lot of 0xXX00 characters and few 0x00XX characters, but that doesn?t create an ?error? normally.