From nospam at please.ty Wed May 1 13:07:02 2024 From: nospam at please.ty (jak) Date: Wed, 1 May 2024 19:07:02 +0200 Subject: UTF_16 question In-Reply-To: References: <08F2BE28-1252-4BD6-AED0-2323E112E0A1@damon-family.org> Message-ID: Richard Damon ha scritto: >> 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. > Thanks to you too for the reply. I was actually looking for a way to distinguish "utf16le" texts from "utf16be" ones. Unfortunately, whoever created this log file archive thought that the BOM was not important and so omitted it. Now they want to switch to "utf8 " and also save the previous. Fortunately I can be sure that the text of the log files is in some European language, so after converting the file to "utf8" I make sure that most of the bytes are less than the value 0x7F and if not I reconvert them by replacing "utf16 " "le" with "be" or vice versa. The strategy seems to be working. In the future, by writing files in "utf8" they will no longer have problems like this. From tripuraseersha at outlook.com Fri May 3 07:55:46 2024 From: tripuraseersha at outlook.com (Tripura Seersha) Date: Fri, 3 May 2024 11:55:46 +0000 Subject: Issues with uninstalling python versions on windows server Message-ID: Hi Team, I am working on an automation related to uninstalling and installing python versions on different windows servers. I have observed that uninstallation is working only with the account/login using which the python version is installed. But for automation, we are not aware which account is being used for installation on different machines. Also, with the approach of using msiexec.exe to uninstall different components of python version, though all the components are uninstalled successfully but still an entry for this version shows in the control panel with the options: Modify, repair and uninstall. I am unable to identify which component has still remained as a part of the installer. Could you please help me resolve these issues. Thanks, Tripura From loris.bennett at fu-berlin.de Thu May 2 10:34:38 2024 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Thu, 02 May 2024 16:34:38 +0200 Subject: Python Dialogs References: Message-ID: <87frv02sg1.fsf@zedat.fu-berlin.de> ram at zedat.fu-berlin.de (Stefan Ram) writes: > Me (indented by 2) and the chatbot (flush left). Lines lengths > 72! Is there a name for this kind of indentation, i.e. the stuff you are writing not being flush left? It is sort of contrary to what I think of as "normal" indentation. You seem to use it in all your postings, too, which hurts my brain, but I guess that's my problem :-) [snip (40 lines)] -- This signature is currently under constuction. From alan at csail.mit.edu Fri May 3 03:16:35 2024 From: alan at csail.mit.edu (Alan Bawden) Date: Fri, 03 May 2024 03:16:35 -0400 Subject: Python Dialogs (Posting On Python-List Prohibited) References: Message-ID: <86v83vmkks.fsf@williamsburg.bawden.org> Lawrence D'Oliveiro writes: > Assume you have an expression "s.replace('a','b').replace('c','d'). > replace('e','f').replace('g','h')". Its value is a string which > is the value of s, but with "a" replaced by "b", "c" replaced by > "d", "e" replaced by "f" and "g" replaced by "h". How to modify > this expression, so that "a", "c", "e", and "g", respectively, > are replaced only if they are words (but not parts of words)? import re replacements = (("a", "b"), ("c", "d"), ("e", "f"), ("g", "h")) text = "this be a test g eg" "".join \ ( repl.get(s, s) for repl in (dict(replacements),) for s in re.split("\\b(" + "|".join(re.escape(s[0]) for s in replacements) + ")\\b", text) ) How about just: repl = { "a" : "b", "c" : "d", "e" : "f", "g" : "h", } "".join(repl.get(s, s) for s in re.split(r"\b", text)) - Alan From jfairchild at tudado.org Fri May 3 09:56:39 2024 From: jfairchild at tudado.org (Johanne Fairchild) Date: Fri, 03 May 2024 10:56:39 -0300 Subject: how to discover what values produced an exception? Message-ID: <8734qz9ey0.fsf@tudado.org> How to discover what values produced an exception? Or perhaps---why doesn't the Python traceback show the values involved in the TypeError? For instance: --8<-------------------------------------------------------->8--- >>> (0,0) < 4 Traceback (most recent call last): File "", line 1, in TypeError: '<' not supported between instances of 'tuple' and 'int' --8<-------------------------------------------------------->8--- It could have said something like: --8<-------------------------------------------------------->8--- TypeError: '<' not supported between instances of 'tuple' and 'int' in (0,0) < 4. --8<-------------------------------------------------------->8--- We would know which were the values that caused the problem, which would be very helpful. From barry at barrys-emacs.org Fri May 3 13:04:49 2024 From: barry at barrys-emacs.org (Barry) Date: Fri, 3 May 2024 18:04:49 +0100 Subject: Issues with uninstalling python versions on windows server In-Reply-To: References: Message-ID: <6417D4DC-5114-4103-84C7-21987548D2D7@barrys-emacs.org> > On 3 May 2024, at 17:43, Tripura Seersha via Python-list wrote: > > ?Hi Team, > > I am working on an automation related to uninstalling and installing python versions on different windows servers. > > I have observed that uninstallation is working only with the account/login using which the python version is installed. But for automation, we are not aware which account is being used for installation on different machines. I would guess that this is because you installed for the user not for all-users. If true fix your install to do it for all-users and you should be able to uninstall as any user. But this will require admin privs for both install and uninstall. As assume you can find out how to bet the admin priv required for your automation. Barry > > Also, with the approach of using msiexec.exe to uninstall different components of python version, though all the components are uninstalled successfully but still an entry for this version shows in the control panel with the options: Modify, repair and uninstall. I am unable to identify which component has still remained as a part of the installer. > > Could you please help me resolve these issues. > > Thanks, > Tripura > -- > https://mail.python.org/mailman/listinfo/python-list > From list1 at tompassin.net Fri May 3 17:39:46 2024 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 3 May 2024 17:39:46 -0400 Subject: how to discover what values produced an exception? In-Reply-To: <8734qz9ey0.fsf@tudado.org> References: <8734qz9ey0.fsf@tudado.org> Message-ID: <918e3522-03e0-40e7-928d-bbf87698a7b3@tompassin.net> On 5/3/2024 9:56 AM, Johanne Fairchild via Python-list wrote: > How to discover what values produced an exception? Or perhaps---why > doesn't the Python traceback show the values involved in the TypeError? > For instance: > > --8<-------------------------------------------------------->8--- >>>> (0,0) < 4 > Traceback (most recent call last): > File "", line 1, in > TypeError: '<' not supported between instances of 'tuple' and 'int' > --8<-------------------------------------------------------->8--- > > It could have said something like: > > --8<-------------------------------------------------------->8--- > TypeError: '<' not supported between instances of 'tuple' and 'int' > in (0,0) < 4. > --8<-------------------------------------------------------->8--- > > We would know which were the values that caused the problem, which would > be very helpful. In this example it would not help at all to know the actual values. Knowing that you are trying to compare incomparable types is enough. From dieter.maurer at online.de Sat May 4 12:24:29 2024 From: dieter.maurer at online.de (dieter.maurer at online.de) Date: Sat, 4 May 2024 18:24:29 +0200 Subject: how to discover what values produced an exception? In-Reply-To: <8734qz9ey0.fsf@tudado.org> References: <8734qz9ey0.fsf@tudado.org> Message-ID: <26166.24893.646556.142871@ixdm.fritz.box> Johanne Fairchild wrote at 2024-5-3 10:56 -0300: >How to discover what values produced an exception? Or perhaps---why >doesn't the Python traceback show the values involved in the TypeError? >For instance: > >--8<-------------------------------------------------------->8--- >>>> (0,0) < 4 >Traceback (most recent call last): > File "", line 1, in >TypeError: '<' not supported between instances of 'tuple' and 'int' >--8<-------------------------------------------------------->8--- > >It could have said something like: > >--8<-------------------------------------------------------->8--- >TypeError: '<' not supported between instances of 'tuple' and 'int' > in (0,0) < 4. >--8<-------------------------------------------------------->8--- > >We would know which were the values that caused the problem, which would >be very helpful. Typically, the traceback informs you about the source code line where the exception has been raised. When the source line contains literals, you see the values. If not, then only in special (speak: rather simple) cases the knowledge of the values will help much. Usually, a more thorough analysis is required to find out the bug location and how to fix the bug. From 2QdxY4RzWzUUiLuE at potatochowder.com Sat May 4 15:33:00 2024 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Sat, 4 May 2024 15:33:00 -0400 Subject: how to discover what values produced an exception? In-Reply-To: <8734qz9ey0.fsf@tudado.org> References: <8734qz9ey0.fsf@tudado.org> Message-ID: On 2024-05-03 at 10:56:39 -0300, Johanne Fairchild via Python-list wrote: > How to discover what values produced an exception? Or perhaps---why > doesn't the Python traceback show the values involved in the TypeError? > For instance: > > --8<-------------------------------------------------------->8--- > >>> (0,0) < 4 > Traceback (most recent call last): > File "", line 1, in > TypeError: '<' not supported between instances of 'tuple' and 'int' > --8<-------------------------------------------------------->8--- > > It could have said something like: > > --8<-------------------------------------------------------->8--- > TypeError: '<' not supported between instances of 'tuple' and 'int' > in (0,0) < 4. > --8<-------------------------------------------------------->8--- > > We would know which were the values that caused the problem, which would > be very helpful. I'm not disagreeing that knowing the values could be useful in many cases. In the general case, though, it's not practical. Consider a function like this: def f(x, y): return g(x) < h(y) The printed values of x, y, g(x), and h(y) could all be millions of (or more) glyphs. Worse, one or more of those values could contain circular lists or similar structures. And h or g could have changed x or y. In summary, printing run-time values isn't always safe or useful. At least printing the types is safe. In the face of ambiguity, refuse to guess. From hjp-python at hjp.at Sat May 4 16:00:02 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 4 May 2024 22:00:02 +0200 Subject: Python Dialogs In-Reply-To: <87frv02sg1.fsf@zedat.fu-berlin.de> References: <87frv02sg1.fsf@zedat.fu-berlin.de> Message-ID: <20240504200002.fugyv4rd34dvapeg@hjp.at> On 2024-05-02 16:34:38 +0200, Loris Bennett via Python-list wrote: > ram at zedat.fu-berlin.de (Stefan Ram) writes: > > Me (indented by 2) and the chatbot (flush left). Lines lengths > 72! > > Is there a name for this kind of indentation, i.e. the stuff you are > writing not being flush left? Ramism. > It is sort of contrary to what I think of as "normal" indentation. Stefan is well known for doing everything contrary to normal convention. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From mats at wichmann.us Sat May 4 18:19:47 2024 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 4 May 2024 16:19:47 -0600 Subject: Issues with uninstalling python versions on windows server In-Reply-To: References: Message-ID: On 5/3/24 05:55, Tripura Seersha via Python-list wrote: > Hi Team, > > I am working on an automation related to uninstalling and installing python versions on different windows servers. > > I have observed that uninstallation is working only with the account/login using which the python version is installed. But for automation, we are not aware which account is being used for installation on different machines. If you want to automate things properly, you need to control installation as well as uninstallation - if things are just installed via some random user account it's hard to see how you can expect later steps without that knowledge to work out. There's a fair bit of control available; if you haven't already, take a look here: https://docs.python.org/3/using/windows.html#installing-without-ui From alan at csail.mit.edu Fri May 3 19:29:43 2024 From: alan at csail.mit.edu (Alan Bawden) Date: Fri, 03 May 2024 19:29:43 -0400 Subject: how to discover what values produced an exception? References: <8734qz9ey0.fsf@tudado.org> <918e3522-03e0-40e7-928d-bbf87698a7b3@tompassin.net> Message-ID: <86r0eimq3c.fsf@williamsburg.bawden.org> Thomas Passin writes: On 5/3/2024 9:56 AM, Johanne Fairchild via Python-list wrote: > How to discover what values produced an exception? Or perhaps---why > doesn't the Python traceback show the values involved in the TypeError? > For instance: > > --8<-------------------------------------------------------->8--- >>>> (0,0) < 4 > Traceback (most recent call last): > File "", line 1, in > TypeError: '<' not supported between instances of 'tuple' and 'int' > --8<-------------------------------------------------------->8--- > > It could have said something like: > > --8<-------------------------------------------------------->8--- > TypeError: '<' not supported between instances of 'tuple' and 'int' > in (0,0) < 4. > --8<-------------------------------------------------------->8--- > > We would know which were the values that caused the problem, which would > be very helpful. In this example it would not help at all to know the actual values. Knowing that you are trying to compare incomparable types is enough. In general, it absolutely can help. The programmer can sometimes recognize where a value of unexpected type came from just by looking at it, allowing her to quickly deduce just what went wrong without further investigation. A good error message shouldn't withhold any information that can _easily_ be included. Debugging is more art than science, so there is no real way to predict what information might prove useful in solving the crime. I emphasized "easily" because of course you have to draw the line somewhere. The fact that Python error messages often fail to mention the actual objects that caused the error has always annoyed me. I've always presumed that for some reason it just wasn't easy to do. And it's never been more than a minor annoyance to me. So the OP is not wrong for wishing for this. Other programming languages do it. Other Python programmers miss it. - Alan From olegsivokon at gmail.com Fri May 3 14:19:23 2024 From: olegsivokon at gmail.com (Left Right) Date: Fri, 3 May 2024 20:19:23 +0200 Subject: how to discover what values produced an exception? In-Reply-To: <8734qz9ey0.fsf@tudado.org> References: <8734qz9ey0.fsf@tudado.org> Message-ID: >From a practical perspective: not all values are printable (especially if printing a value results in an error: then you'd lose the original error, so, going crazy with printing of errors is usually not such a hot idea). But, if you want the values: you'd have to examine the stack, extract the values from the local variables etc. It's easier to do this interactively (unless you are in a multithreaded environment, where pdb is broken). But, you could also try to find this information automatically (by unwinding the stack to the place that generated the error, examining the local variables etc.) It's tedious and prone to errors. So, if you really want to do this automatically for every error that's going to be quite a bit of work. On Fri, May 3, 2024 at 6:58?PM Johanne Fairchild via Python-list wrote: > > How to discover what values produced an exception? Or perhaps---why > doesn't the Python traceback show the values involved in the TypeError? > For instance: > > --8<-------------------------------------------------------->8--- > >>> (0,0) < 4 > Traceback (most recent call last): > File "", line 1, in > TypeError: '<' not supported between instances of 'tuple' and 'int' > --8<-------------------------------------------------------->8--- > > It could have said something like: > > --8<-------------------------------------------------------->8--- > TypeError: '<' not supported between instances of 'tuple' and 'int' > in (0,0) < 4. > --8<-------------------------------------------------------->8--- > > We would know which were the values that caused the problem, which would > be very helpful. > -- > https://mail.python.org/mailman/listinfo/python-list From nospam at please.ty Mon May 6 06:47:43 2024 From: nospam at please.ty (jak) Date: Mon, 6 May 2024 12:47:43 +0200 Subject: Python Dialogs In-Reply-To: <87frv02sg1.fsf@zedat.fu-berlin.de> References: <87frv02sg1.fsf@zedat.fu-berlin.de> Message-ID: Loris Bennett ha scritto: > ram at zedat.fu-berlin.de (Stefan Ram) writes: > >> Me (indented by 2) and the chatbot (flush left). Lines lengths > 72! > > Is there a name for this kind of indentation, i.e. the stuff you are > writing not being flush left? It is sort of contrary to > what I think of as "normal" indentation. You seem to use it in all your > postings, too, which hurts my brain, but I guess that's my problem :-) > > [snip (40 lines)] > It's not just your problem. When the texts are particularly long and complex, I happen to use Google-Translator. It makes bad translations if the lines are interrupted by the newline, so I wrote a tool dedicated to Stefan and to all those who indent like him. This tool takes the text from the clipboard, removes all the superfluous spaces, combines all the lines in one and puts the result back into the clipboard. :-D From nospam at please.ty Mon May 6 10:15:41 2024 From: nospam at please.ty (jak) Date: Mon, 6 May 2024 16:15:41 +0200 Subject: Python Dialogs In-Reply-To: References: <87frv02sg1.fsf@zedat.fu-berlin.de> Message-ID: Stefan Ram ha scritto: > ram at zedat.fu-berlin.de (Stefan Ram) wrote or quoted: >> translation services are gonna interpret line breaks as > > I just beefed up my posting program to replace "gonna". > > Now I won't come across like some street thug, but rather > as a respectable member of human society! > > # replace complete words > replacements =\ > { rb'kind of': b'kind of', > rb'trying to': b'trying to', > rb'got to': b'got to', > rb'gonna': b'going to', > } > lines =\ > [ re.sub( rb"\b(" + b"|".join( replacements.keys() ) + rb")\b", > lambda x: replacements[ x.group() ], line ) > if len( line )and line[ 0 ]not in b'>|' else line for line in lines ] > I present to you the brutality to which your posts are subjected: for(d = s = pCLipb; *s != TEXT('\0'); s++) { if(d == pCLipb) { if(*s != TEXT(' ') && *s != TEXT('\n') && *s != TEXT('\r')) *d++ = *s; } else if(*s == TEXT(' ') || *s == TEXT('\n') || *s == TEXT('\r')) { if(d[-1] != TEXT(' ')) *d++ = TEXT(' '); } else *d++ = *s; } *d = TEXT('\0'); From rosuav at gmail.com Mon May 6 13:46:09 2024 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 May 2024 03:46:09 +1000 Subject: how to discover what values produced an exception? In-Reply-To: <86r0eimq3c.fsf@williamsburg.bawden.org> References: <8734qz9ey0.fsf@tudado.org> <918e3522-03e0-40e7-928d-bbf87698a7b3@tompassin.net> <86r0eimq3c.fsf@williamsburg.bawden.org> Message-ID: On Tue, 7 May 2024 at 03:38, Alan Bawden via Python-list wrote: > A good error message shouldn't withhold any information that can > _easily_ be included. Debugging is more art than science, so there is > no real way to predict what information might prove useful in solving > the crime. I emphasized "easily" because of course you have to draw the > line somewhere. Emphasis on "easily" is correct here. How easy is it to report the value of something that could be arbitrarily large? ChrisA From rosuav at gmail.com Mon May 6 13:48:19 2024 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 May 2024 03:48:19 +1000 Subject: Python Dialogs In-Reply-To: References: <87frv02sg1.fsf@zedat.fu-berlin.de> Message-ID: On Tue, 7 May 2024 at 03:42, jak via Python-list wrote: > > Loris Bennett ha scritto: > > ram at zedat.fu-berlin.de (Stefan Ram) writes: > > > >> Me (indented by 2) and the chatbot (flush left). Lines lengths > 72! > > > > Is there a name for this kind of indentation, i.e. the stuff you are > > writing not being flush left? It is sort of contrary to > > what I think of as "normal" indentation. You seem to use it in all your > > postings, too, which hurts my brain, but I guess that's my problem :-) > > > > [snip (40 lines)] > > > > It's not just your problem. When the texts are particularly long and > complex, I happen to use Google-Translator. It makes bad translations if > the lines are interrupted by the newline, so I wrote a tool dedicated to > Stefan and to all those who indent like him. This tool takes the text > from the clipboard, removes all the superfluous spaces, combines all the > lines in one and puts the result back into the clipboard. :-D > Fun fact: His posts are completely irrelevant to people who follow the mailing list. Due to a dispute over permissions, his posts are blocked at the gateway. So all of us folks who use the mailing list never need to see the wonky indentation. ChrisA From tripuraseersha at outlook.com Tue May 7 02:36:21 2024 From: tripuraseersha at outlook.com (Tripura Seersha) Date: Tue, 7 May 2024 06:36:21 +0000 Subject: Issues with uninstalling python versions on windows server In-Reply-To: <6417D4DC-5114-4103-84C7-21987548D2D7@barrys-emacs.org> References: <6417D4DC-5114-4103-84C7-21987548D2D7@barrys-emacs.org> Message-ID: Hi Barry, Yes, the install was for specific user. As suggested by you, when I installed a version for all users, I was able to uninstall from the account used for automation successfully. Thank you for the help on this issue. However, for installation the account being used in automation has administrative access for the system and yet fails with exit code 3. Installation is working only when we provide a specific user account in automation. Can you please suggest a resolution for this issue. Also, with the approach of using msiexec.exe to uninstall different components of python version, though all the components are uninstalled successfully(executables, core interpreter, test suite, standard library, etc. ) but still an entry for this version shows in the control panel with the options: Modify, repair and uninstall. I am unable to identify which component has still remained as a part of the installer. Please help me with this issue. Thanks, Tripura ________________________________ From: Barry Sent: 03 May 2024 22:34 To: Tripura Seersha Cc: python-list at python.org Subject: Re: Issues with uninstalling python versions on windows server > On 3 May 2024, at 17:43, Tripura Seersha via Python-list wrote: > > ?Hi Team, > > I am working on an automation related to uninstalling and installing python versions on different windows servers. > > I have observed that uninstallation is working only with the account/login using which the python version is installed. But for automation, we are not aware which account is being used for installation on different machines. I would guess that this is because you installed for the user not for all-users. If true fix your install to do it for all-users and you should be able to uninstall as any user. But this will require admin privs for both install and uninstall. As assume you can find out how to bet the admin priv required for your automation. Barry > > Also, with the approach of using msiexec.exe to uninstall different components of python version, though all the components are uninstalled successfully but still an entry for this version shows in the control panel with the options: Modify, repair and uninstall. I am unable to identify which component has still remained as a part of the installer. > > Could you please help me resolve these issues. > > Thanks, > Tripura > -- > https://mail.python.org/mailman/listinfo/python-list > From dpopov at anl.gov Tue May 7 21:32:32 2024 From: dpopov at anl.gov (Popov, Dmitry Yu) Date: Wed, 8 May 2024 01:32:32 +0000 Subject: Use of statement 'global' in scripts. Message-ID: Dear Sirs. The statement 'global', indicating variables living in the global scope, is very suitable to be used in modules. I'm wondering whether in scripts, running at the top-level invocation of the interpreter, statement 'global' is used exactly the same way as in modules? If there are any differences, I would really appreciate any comments on this. Regards, Dmitry Popov Lemont, IL USA From greg.ewing at canterbury.ac.nz Wed May 8 04:56:00 2024 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 8 May 2024 20:56:00 +1200 Subject: Use of statement 'global' in scripts. In-Reply-To: References: Message-ID: On 8/05/24 1:32 pm, Popov, Dmitry Yu wrote: > The statement 'global', indicating variables living in the global scope, is very suitable to be used in modules. I'm wondering whether in scripts, running at the top-level invocation of the interpreter, statement 'global' is used exactly the same way as in modules? The 'global' statement declares a name to be module-level, so there's no reason to use it at the top level of either a script or a module, since everything there is module-level anyway. You only need it if you want to assign to a module-level name from within a function, e.g. spam = 17 def f(): global spam spam = 42 f() # spam is now 42 A script is a module, so everything that applies to modules also applies to scripts. -- Greg From dpopov at anl.gov Wed May 8 14:52:57 2024 From: dpopov at anl.gov (Popov, Dmitry Yu) Date: Wed, 8 May 2024 18:52:57 +0000 Subject: Use of statement 'global' in scripts. In-Reply-To: References: Message-ID: Thank you! ________________________________ From: Python-list on behalf of Greg Ewing via Python-list Sent: Wednesday, May 8, 2024 3:56 AM To: python-list at python.org Subject: Re: Use of statement 'global' in scripts. On 8/05/24 1:?32 pm, Popov, Dmitry Yu wrote: > The statement 'global', indicating variables living in the global scope, is very suitable to be used in modules. I'm wondering whether in scripts, running at the top-level invocation of the interpreter, ZjQcmQRYFpfptBannerStart This Message Is From an External Sender This message came from outside your organization. ZjQcmQRYFpfptBannerEnd On 8/05/24 1:32 pm, Popov, Dmitry Yu wrote: > The statement 'global', indicating variables living in the global scope, is very suitable to be used in modules. I'm wondering whether in scripts, running at the top-level invocation of the interpreter, statement 'global' is used exactly the same way as in modules? The 'global' statement declares a name to be module-level, so there's no reason to use it at the top level of either a script or a module, since everything there is module-level anyway. You only need it if you want to assign to a module-level name from within a function, e.g. spam = 17 def f(): global spam spam = 42 f() # spam is now 42 A script is a module, so everything that applies to modules also applies to scripts. -- Greg -- https://urldefense.us/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!G_uCfscf7eWS!airWCCS1QeLAhk0AfN3VxhuV9MZkx80000YBhs5Vjf89K2WZPjhCUkXt9culFzwlX1_ON0G17lukcR79-kWAsA$ From thomas at python.org Wed May 8 18:15:13 2024 From: thomas at python.org (Thomas Wouters) Date: Thu, 9 May 2024 00:15:13 +0200 Subject: [RELEASE] Python 3.13.0 beta 1 released Message-ID: After a little bit of excitement discovering new bugs during the release, *it?s done*: 3.13.0 beta 1 is released, the 3.13 branch has been created, and features for 3.13 are frozen! The main branch is now 3.14.0a0. https://www.python.org/downloads/release/python-3130b1/ *This is a beta preview of Python 3.13* Python 3.13 is still in development. This release, 3.13.0b1, is the first of four beta release previews of 3.13. Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release. We *strongly encourage* maintainers of third-party Python projects to *test with 3.13* during the beta phase and report issues found to the Python bug tracker as soon as possible. While the release is planned to be feature complete entering the beta phase, it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase (Tuesday 2024-07-30). Our goal is to have no ABI changes after beta 4 and as few code changes as possible after 3.13.0rc1, the first release candidate. To achieve that, it will be *extremely important* to get as much exposure for 3.13 as possible during the beta phase. Please keep in mind that this is a preview release and its use is *not* recommended for production environments. Major new features of the 3.13 series, compared to 3.12 Some of the new major new features and changes in Python 3.13 are: New features - A new and improved interactive interpreter , based on PyPy ?s, featuring multi-line editing and color support, as well as colorized exception tracebacks . - An *experimental* free-threaded build mode , which disables the Global Interpreter Lock, allowing threads to run more concurrently. - A preliminary, *experimental* JIT , 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. - A modified version of mimalloc is now included, optional but enabled by default if supported by the platform, and required for the free-threaded build mode. - 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. Typing - Support for type defaults in type parameters . - A new type narrowing annotation , typing.TypeIs. - A new annotation for read-only items in TypeDicts . Removals and new deprecations - 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. - 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.) - New deprecations , most of which are scheduled for removal from Python 3.15 or 3.16. (Hey, *fellow core developer,* if a feature you find important is missing from this list, let Thomas know .) For more details on the changes to Python 3.13, see What?s new in Python 3.13 . The next pre-release of Python 3.13 will be 3.13.0b2, currently scheduled for 2024-05-28. More resources - Online Documentation - PEP 719 , 3.13 Release Schedule - Report bugs at Issues ? python/cpython ? GitHub . - Help fund Python directly (or via GitHub Sponsors ), and support the Python community . Enjoy the new releases Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Regards from droopy Amsterdam, Your release team, Thomas Wouters @thomas ?ukasz Langa @ambv Ned Deily @nad Steve Dower @steve.dower From tripuraseersha at outlook.com Fri May 10 05:39:42 2024 From: tripuraseersha at outlook.com (Tripura Seersha) Date: Fri, 10 May 2024 09:39:42 +0000 Subject: Issues with uninstalling python versions on windows server In-Reply-To: References: <6417D4DC-5114-4103-84C7-21987548D2D7@barrys-emacs.org> Message-ID: Hi Barry, Automation is using the system account using which the installation is failing with exit code 3. This account has the administrative privileges. Please help me with this issue. Thanks, Seersha ________________________________ From: Python-list on behalf of Tripura Seersha via Python-list Sent: 07 May 2024 12:06 To: Barry Cc: python-list at python.org Subject: Re: Issues with uninstalling python versions on windows server Hi Barry, Yes, the install was for specific user. As suggested by you, when I installed a version for all users, I was able to uninstall from the account used for automation successfully. Thank you for the help on this issue. However, for installation the account being used in automation has administrative access for the system and yet fails with exit code 3. Installation is working only when we provide a specific user account in automation. Can you please suggest a resolution for this issue. Also, with the approach of using msiexec.exe to uninstall different components of python version, though all the components are uninstalled successfully(executables, core interpreter, test suite, standard library, etc. ) but still an entry for this version shows in the control panel with the options: Modify, repair and uninstall. I am unable to identify which component has still remained as a part of the installer. Please help me with this issue. Thanks, Tripura ________________________________ From: Barry Sent: 03 May 2024 22:34 To: Tripura Seersha Cc: python-list at python.org Subject: Re: Issues with uninstalling python versions on windows server > On 3 May 2024, at 17:43, Tripura Seersha via Python-list wrote: > > ?Hi Team, > > I am working on an automation related to uninstalling and installing python versions on different windows servers. > > I have observed that uninstallation is working only with the account/login using which the python version is installed. But for automation, we are not aware which account is being used for installation on different machines. I would guess that this is because you installed for the user not for all-users. If true fix your install to do it for all-users and you should be able to uninstall as any user. But this will require admin privs for both install and uninstall. As assume you can find out how to bet the admin priv required for your automation. Barry > > Also, with the approach of using msiexec.exe to uninstall different components of python version, though all the components are uninstalled successfully but still an entry for this version shows in the control panel with the options: Modify, repair and uninstall. I am unable to identify which component has still remained as a part of the installer. > > Could you please help me resolve these issues. > > Thanks, > Tripura > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list From mats at wichmann.us Fri May 10 10:02:44 2024 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 10 May 2024 08:02:44 -0600 Subject: Issues with uninstalling python versions on windows server In-Reply-To: References: <6417D4DC-5114-4103-84C7-21987548D2D7@barrys-emacs.org> Message-ID: On 5/10/24 03:39, Tripura Seersha via Python-list wrote: > Hi Barry, > > Automation is using the system account using which the installation is failing with exit code 3. This account has the administrative privileges. > > Please help me with this issue. > > Thanks, > Seersha You probably have a better chance of finding the attention of people who know about the details either on the Python Discuss board (discuss.python.org), or by filing an issue - after first checking someone else isn't wrestling with the same problem you are - there are a number of uninstall-related issues open (https://github.com/python/cpython/issues) In particular, I see that this part of your issue: > I have observed that uninstallation is working only with the account/login using which the python version is installed seems to be a known problem, where the user who initiated the install has the uninstall registered to their account - see https://github.com/python/cpython/issues/69353 From adanreaza1 at gmail.com Sun May 12 19:56:28 2024 From: adanreaza1 at gmail.com (Enrder) Date: Sun, 12 May 2024 17:56:28 -0600 Subject: help Message-ID: good tader I need help to install the bcml, and is that after installing the python and I go to the command prompt and put ''pip install bcml'' to install it tells me "pip" is not recognized as an internal or external command, program or executable batch file. I have tried everything, uninstalling and installing, restoring it, activating and deactivating all the checkboxes that appear in the options section, I searched the internet and the same thing keeps happening to me. If you can help me, I would appreciate it very much. Translated with DeepL.com (free version) Enviado desde [1]Correo para Windows References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From list1 at tompassin.net Mon May 13 13:30:49 2024 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 13 May 2024 13:30:49 -0400 Subject: help In-Reply-To: References: Message-ID: <4822be23-558b-4686-ab5c-eaf4d63b20ce@tompassin.net> On 5/12/2024 7:56 PM, Enrder via Python-list wrote: > good tader > > I need help to install the bcml, and is that after installing the python > and I go to the command prompt and put ''pip install bcml'' to install it > tells me "pip" is not recognized as an internal or external command, > program or executable batch file. > > I have tried everything, uninstalling and installing, restoring it, > activating and deactivating all the checkboxes that appear in the options > section, I searched the internet and the same thing keeps happening to me. > > > > If you can help me, I would appreciate it very much. Launch pip using the following command. If you don't run python using the name "python" then use the name you usually use (e.g., "py", "python3", etc.) - python -m pip install bcml This command causes Python to load and run its own copy of pip. So the fact that the operating system can't find it doesn't matter. You should always run pip this way, especially if you end up with several different versions of Python on the same computer. From gordinator at gordinator.org Tue May 14 13:44:43 2024 From: gordinator at gordinator.org (Gordinator) Date: Tue, 14 May 2024 18:44:43 +0100 Subject: Terminal Emulator Message-ID: I wish to write a terminal emulator in Python. I am a fairly competent Python user, and I wish to try a new project idea. What references can I use when writing my terminal emulator? I wish for it to be a true terminal emulator as well, not just a Tk text widget or something like that. If you have any advice, please do let me know! From learn2program at gmail.com Tue May 14 15:06:36 2024 From: learn2program at gmail.com (Alan Gauld) Date: Tue, 14 May 2024 20:06:36 +0100 Subject: Terminal Emulator In-Reply-To: References: Message-ID: On 14/05/2024 18:44, Gordinator via Python-list wrote: > I wish to write a terminal emulator in Python. I am a fairly competent > Python user, and I wish to try a new project idea. What references can I > use when writing my terminal emulator? I wish for it to be a true > terminal emulator as well, not just a Tk text widget or something like that. The first thing is to decide which terminal. A VT100 is very different from a 3270. And even a VT330 is quite different from a VT100 although sharing a common subset of control codes. And if you start looking at graphical terminals things get even more interesting! The other thing to consider is whether it will be a standalone app or a GUI component. If the latter do you want to expose your own API or clone the manufacturers? Or both?! Or you could make it an object that can be used both in GUIs and in "robotic" or "batch" mode. So many options. Most of the specs are available online and there must be dozens of terminal emulators around written in C so you should have plenty of sample code to study. Good luck! -- 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 grant.b.edwards at gmail.com Tue May 14 15:47:18 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 14 May 2024 15:47:18 -0400 (EDT) Subject: Terminal Emulator References: Message-ID: <4Vf6MB5t85znW60@mail.python.org> On 2024-05-14, Alan Gauld via Python-list wrote: > On 14/05/2024 18:44, Gordinator via Python-list wrote: > >> I wish to write a terminal emulator in Python. I am a fairly >> competent Python user, and I wish to try a new project idea. What >> references can I use when writing my terminal emulator? I wish for >> it to be a true terminal emulator as well, not just a Tk text >> widget or something like that. > > The first thing is to decide which terminal. You also need to decide if you're going to support real serial ports or just ptys. From grant.b.edwards at gmail.com Tue May 14 16:03:33 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 14 May 2024 16:03:33 -0400 (EDT) Subject: Terminal Emulator References: Message-ID: <4Vf6jx1MWJznVGB@mail.python.org> On 2024-05-14, Alan Gauld via Python-list wrote: > On 14/05/2024 18:44, Gordinator via Python-list wrote: > >> I wish to write a terminal emulator in Python. I am a fairly >> competent Python user, and I wish to try a new project idea. What >> references can I use when writing my terminal emulator? I wish for >> it to be a true terminal emulator as well, not just a Tk text >> widget or something like that. > > The first thing is to decide which terminal. If you want to make life easier, make it a superset of a terminal that already exists in the terminfo database. Going with some sort of ANSI terminal will probably provide operability even with dumb apps which ignore $TERM and just spit out basic ANSI escape sequences. If you really want to break trail, you could invent your own control sequences, which means you'll have to write terminfo and/or termcap entries as well as the terminal emulator. > A VT100 is very different from a 3270. And even a VT330 is quite > different from a VT100 although sharing a common subset of control > codes. And if you start looking at graphical terminals things get > even more interesting! "Intersting" is putting it mildly... From mirkok.lists at googlemail.com Tue May 14 16:37:17 2024 From: mirkok.lists at googlemail.com (Mirko) Date: Tue, 14 May 2024 22:37:17 +0200 Subject: Terminal Emulator In-Reply-To: References: Message-ID: Am 14.05.24 um 19:44 schrieb Gordinator via Python-list: > I wish to write a terminal emulator in Python. I am a fairly > competent Python user, and I wish to try a new project idea. What > references can I use when writing my terminal emulator? I wish for > it to be a true terminal emulator as well, not just a Tk text widget > or something like that. > > If you have any advice, please do let me know! Not sure, what you mean with: > true terminal emulator as well, not just a Tk text widget or something like that If you want to write a GUI terminal, than that *is* a terminal emulator and *has* a text widget as its visible core. If you want to write something like getty which runs on the virtual terminals (Ctrl+Alt+F*) than that is a terminal (not a terminal emulator). In both cases, you write something that gets input from the keyboard, processes it and shows the result. How that processing is done, depends on the terminal standard, like DEC VT{100, 102, 220, 320, etc}. For a start, you might want to look at Terminator, which is a terminal emulator written in Python, Gtk and libvte (which does all the low level stuff). From avi.e.gross at gmail.com Tue May 14 17:10:41 2024 From: avi.e.gross at gmail.com (avi.e.gross at gmail.com) Date: Tue, 14 May 2024 17:10:41 -0400 Subject: Terminal Emulator In-Reply-To: References: Message-ID: <003b01daa643$2d78ebd0$886ac370$@gmail.com> The topic was to re-invent the wheel yet again and create a terminal emulator. I hesitate to say this but one approach is to consider the curses module as described by our very own Alan Gauld in a book: https://www.amazon.com/Programming-curses-Python-Alan-Gauld-ebook/dp/B091B85 B77 The topic is how to make a terminal emulator and as Alan mentions, each kind of terminal may accept various kinds of escape sequences. There are files available the are normally used by curses to get a description of sorts of the capabilities and details of a terminal like a VT100 that curses can use to decide what stream of bytes to send to update a screen. You might be able to use something similar, or better, to see what your terminal emulator should emulate. And, it may even be possible for you to emulate lots of terminals with the same basic code. -----Original Message----- From: Python-list On Behalf Of Alan Gauld via Python-list Sent: Tuesday, May 14, 2024 3:07 PM To: Gordinator ; python-list at python.org Subject: Re: Terminal Emulator On 14/05/2024 18:44, Gordinator via Python-list wrote: > I wish to write a terminal emulator in Python. I am a fairly competent > Python user, and I wish to try a new project idea. What references can I > use when writing my terminal emulator? I wish for it to be a true > terminal emulator as well, not just a Tk text widget or something like that. The first thing is to decide which terminal. A VT100 is very different from a 3270. And even a VT330 is quite different from a VT100 although sharing a common subset of control codes. And if you start looking at graphical terminals things get even more interesting! The other thing to consider is whether it will be a standalone app or a GUI component. If the latter do you want to expose your own API or clone the manufacturers? Or both?! Or you could make it an object that can be used both in GUIs and in "robotic" or "batch" mode. So many options. Most of the specs are available online and there must be dozens of terminal emulators around written in C so you should have plenty of sample code to study. Good luck! -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list From cs at cskk.id.au Tue May 14 18:35:55 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 15 May 2024 08:35:55 +1000 Subject: Terminal Emulator In-Reply-To: References: Message-ID: On 14May2024 18:44, Gordinator wrote: >I wish to write a terminal emulator in Python. I am a fairly competent >Python user, and I wish to try a new project idea. What references can >I use when writing my terminal emulator? I wish for it to be a true >terminal emulator as well, not just a Tk text widget or something like >that. Start with the `pty` module. From dpopov at anl.gov Wed May 15 14:42:14 2024 From: dpopov at anl.gov (Popov, Dmitry Yu) Date: Wed, 15 May 2024 18:42:14 +0000 Subject: Version of NymPy Message-ID: What would be the easiest way to learn which version of NumPy I have with my Anaconda distribution? From larry.martell at gmail.com Wed May 15 14:55:07 2024 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 15 May 2024 14:55:07 -0400 Subject: Version of NymPy In-Reply-To: References: Message-ID: On Wed, May 15, 2024 at 2:43?PM Popov, Dmitry Yu via Python-list wrote: > > What would be the easiest way to learn which version of NumPy I have with my Anaconda distribution? >>> import numpy >>> numpy.__version__ '1.24.4' From dpopov at anl.gov Wed May 15 14:56:14 2024 From: dpopov at anl.gov (Popov, Dmitry Yu) Date: Wed, 15 May 2024 18:56:14 +0000 Subject: Version of NymPy In-Reply-To: References: Message-ID: Thank you. ________________________________ From: Larry Martell Sent: Wednesday, May 15, 2024 1:55 PM To: Popov, Dmitry Yu Cc: Popov, Dmitry Yu via Python-list Subject: Re: Version of NymPy On Wed, May 15, 2024 at 2:?43 PM Popov, Dmitry Yu via Python-list wrote: > > What would be the easiest way to learn which version of NumPy I have with my Anaconda distribution? >>> import numpy >>> ZjQcmQRYFpfptBannerStart This Message Is From an External Sender This message came from outside your organization. ZjQcmQRYFpfptBannerEnd On Wed, May 15, 2024 at 2:43?PM Popov, Dmitry Yu via Python-list wrote: > > What would be the easiest way to learn which version of NumPy I have with my Anaconda distribution? >>> import numpy >>> numpy.__version__ '1.24.4' From python at mrabarnett.plus.com Wed May 15 15:05:09 2024 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 May 2024 20:05:09 +0100 Subject: Version of NymPy In-Reply-To: References: Message-ID: <944c1c6d-7d6e-4f1c-a90f-01e8290cf65b@mrabarnett.plus.com> On 2024-05-15 19:42, Popov, Dmitry Yu via Python-list wrote: > What would be the easiest way to learn which version of NumPy I have with my Anaconda distribution? Import numpy and print its '__version__' attribute. From gordinator at gordinator.org Wed May 15 07:24:01 2024 From: gordinator at gordinator.org (Gordinator) Date: Wed, 15 May 2024 12:24:01 +0100 Subject: Terminal Emulator In-Reply-To: References: Message-ID: > We need somethin like a portable curses module (plus colorama) Agreed, getting curses to work on Windows is SUCH a pain, and I don't think I've ever done it. Naturally, as a Linux user, I don't find much need to do it anyway. Colorama would also be cool in the standard library as well. I have worked on projects in the past where only the standard library could be used, so I 100% agree with this. But that's something for the PSF to talk about. Maybe someone could write a PEP for this. From olegsivokon at gmail.com Thu May 16 07:03:20 2024 From: olegsivokon at gmail.com (Left Right) Date: Thu, 16 May 2024 13:03:20 +0200 Subject: Version of NymPy In-Reply-To: <944c1c6d-7d6e-4f1c-a90f-01e8290cf65b@mrabarnett.plus.com> References: <944c1c6d-7d6e-4f1c-a90f-01e8290cf65b@mrabarnett.plus.com> Message-ID: Let me try to answer this properly, instead of "simply". The "problematic" part of your question is "with my Anaconda distribution". Anaconda distribution comes with the conda program that manages installed packages. A single Anaconda distribution may have multiple NumPy versions installed at the same time, although only one will be available to the Python process (note that this means that sub-processes created in this Python process won't necessarily have the same version of NumPy!). To make matters worse, it's common for Anaconda users to use pip to install packages. Now, Anaconda has a concept of virtual environments independent of Python's venv module. In order to create such environments it can be configured to either link (usually hard-link) installed packages into the dedicated directory, or to copy these packages into the said directory. This will become important once you inevitably ask the follow-up question: "why do I have this version of NumPy?". Unfortunately, you also need to consider setuptools. The traditional setup.py install command may install multiple versions of the same package into the same directory. Even worse, "pip install -e", the glorified "setup.py develop", complicates things even further by adding the "installed" package to the pth file, which can, again, create ambiguities as to the resolution of the package location. On top of this, there's an environment variable: PYTHONPATH that can be set to add an arbitrary number of source directories for Python to look up package location. So, suppose you ran: python -c "import numpy; numpy.__version__" and then ran a Jupyter notebook and discovered that the version of NumPy in that notebook is not the one you just saw in the previous output... What went wrong? You then may try: conda info numpy and get yet another answer. And then you run pip show numpy And the answer is still different! Of course, it's not necessary that all these answers are different. And, in most circumstances they are going to be consistent... but they don't have to be! Below is the list of typical problems I encountered in my attempts to resolve similar problems for Python users. Of course, this list is not exhaustive. 1. If the version in the Jupyter notebook differs from the one in the environment in which the Jupyter server was started, you need to look for the Jupyter kernel definition. There are many ways in which the Jupyter kernel definition may alter the module lookup locations, but the most common one is that using Python from the active virtual environment isn't the default for the default Jupyter kernel. 2. If installed modules in conda environments are hard-linked, and at some point pip or setuptools were used to install extra packages, you might have "botched" unrelated environments by overwriting files through hard-links without you even knowing that. 3. conda will happily install outdated versions of conda into virtual environments it creates. The format of conda virtual environments changed over time, and older versions of conda are unaware of the new format, while newer versions are unaware of the old format. If you happen to run the conda command from the wrong environment you may get unexpected results (especially if both the new and the old version of conda have created environments with the same name!) To avoid this, you'd want to deactivate all conda environments activated so far until you are at least in the base environment. 4. Usually, some diagnostic information can be gleaned from printing the value of PYTHONPATH environment variable, sys.paths list (inside Python), sys.sysconfig.get_path('platlib') (and looking into this directory for duplicate packages with different version or for the pth files.) If you discover anomalies, try to figure out if you had to use pip to install packages (this may indirectly mean using setuptools). Similarly, running "conda build" may indirectly result in running setuptools commands. Also, some popular tools like to do bad things to packages and virtual environments: pytest and tox come to mind. pytest can manipulate module lookup locations (and you will need to dissect its configuration to figure this out). tox, afaik, is unaware of conda virtual environments, and will try to create venv-style virtual environments, which will have all the same problems as using pip in conda environments does. 5. Final warning: no matter how ridiculous this is: the current directory in Python is added to the module lookup path, and it *precedes* every other lookup location. If, accidentally, you placed a numpy.py in the current directory of your Python process -- that is going to be the numpy module you import. To make this even worse, this behavior used to depend on whether you start Python with PDB active or not (with PDB, the current working directory wasn't added to the path, and module imports resolved differently). I'm not quite sure which version of Python fixed that. On Wed, May 15, 2024 at 9:10?PM MRAB via Python-list wrote: > > On 2024-05-15 19:42, Popov, Dmitry Yu via Python-list wrote: > > What would be the easiest way to learn which version of NumPy I have with my Anaconda distribution? > > Import numpy and print its '__version__' attribute. > > -- > https://mail.python.org/mailman/listinfo/python-list From gordinator at gordinator.org Thu May 16 14:46:07 2024 From: gordinator at gordinator.org (Gordinator) Date: Thu, 16 May 2024 19:46:07 +0100 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: References: Message-ID: On 16/05/2024 01:12, Lawrence D'Oliveiro wrote: > On 15 May 2024 10:31:25 GMT, Stefan Ram wrote: > >> We need somethin like a portable curses module (plus colorama) and >> it has got to work on both Windoze and Linux straight out of the box >> in standard Python. > > Something else for Windows Python users to complain that they cannot get > to install properly? To be fair, the problem is the fact that they use Windows (but I guess Linux users have to deal with venvs, so we're even. From larry.martell at gmail.com Fri May 17 20:57:43 2024 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 17 May 2024 20:57:43 -0400 Subject: PyCon Message-ID: I?m at PyCon in Pittsburgh and I?m haven?t an amazing time! From larry.martell at gmail.com Sat May 18 00:08:47 2024 From: larry.martell at gmail.com (Larry Martell) Date: Sat, 18 May 2024 00:08:47 -0400 Subject: PyCon In-Reply-To: References: Message-ID: LOn Fri, May 17, 2024 at 8:57?PM Larry Martell wrote: > I?m at PyCon in Pittsburgh and I?m haven?t an amazing time! s/haven?t/having/ From skip.montanaro at gmail.com Sat May 18 07:42:24 2024 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sat, 18 May 2024 06:42:24 -0500 Subject: PyCon In-Reply-To: References: Message-ID: > > > I?m at PyCon in Pittsburgh and I?m haven?t an amazing time! > > s/haven?t/having/ > No need to explain/correct. We understand you are excited. Many of us have been in the same state before. ;-) Enjoy, Skip > From rosuav at gmail.com Sat May 18 07:56:51 2024 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 May 2024 21:56:51 +1000 Subject: PyCon In-Reply-To: References: Message-ID: On Sat, 18 May 2024 at 21:44, Skip Montanaro via Python-list wrote: > > > > > > I?m at PyCon in Pittsburgh and I?m haven?t an amazing time! > > > > s/haven?t/having/ > > > > No need to explain/correct. We understand you are excited. Many of us have > been in the same state before. ;-) > We're fluent in autocorrupt :) If you're connecting to the online parts of PyCon, I'll see you there - I'm about to hang out in the lightning talks! Geography's a bit of a barrier for me, but thanks to livestreams, I can participate too! ChrisA From hjp-python at hjp.at Sat May 18 11:08:43 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 18 May 2024 17:08:43 +0200 Subject: Terminal Emulator In-Reply-To: <4Vf6jx1MWJznVGB@mail.python.org> References: <4Vf6jx1MWJznVGB@mail.python.org> Message-ID: <20240518150843.knm67o3uhpcdr4dz@hjp.at> On 2024-05-14 16:03:33 -0400, Grant Edwards via Python-list wrote: > On 2024-05-14, Alan Gauld via Python-list wrote: > > On 14/05/2024 18:44, Gordinator via Python-list wrote: > > > >> I wish to write a terminal emulator in Python. I am a fairly > >> competent Python user, and I wish to try a new project idea. What > >> references can I use when writing my terminal emulator? I wish for > >> it to be a true terminal emulator as well, not just a Tk text > >> widget or something like that. > > > > The first thing is to decide which terminal. > > If you want to make life easier, make it a superset of a terminal that > already exists in the terminfo database. > > Going with some sort of ANSI terminal will probably provide > operability even with dumb apps which ignore $TERM and just spit out > basic ANSI escape sequences. And if you want to go for a superset, xterm might be one of the more useful: https://www.xfree86.org/current/ctlseqs.html > If you really want to break trail, you could invent your own control > sequences, which means you'll have to write terminfo and/or termcap > entries as well as the terminal emulator. Right. A saner model than ANSI and its supersets might be a good idea conceptionally. But I'd expect quite a few programs to break. > > A VT100 is very different from a 3270. And even a VT330 is quite > > different from a VT100 although sharing a common subset of control > > codes. And if you start looking at graphical terminals things get > > even more interesting! > > "Intersting" is putting it mildly... Yup. Also there aren't many programs which use, e.g. xterm's pixel-graphics capabilities. OTOH, there is something like domterm[1], which can (theoretically) display anything a browser can display. hp [1] https://domterm.org/index.html -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hjp-python at hjp.at Sat May 18 11:17:18 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 18 May 2024 17:17:18 +0200 Subject: Terminal Emulator In-Reply-To: References: Message-ID: <20240518151718.ruuvvlaj3cqn7t2u@hjp.at> On 2024-05-14 22:37:17 +0200, Mirko via Python-list wrote: > Am 14.05.24 um 19:44 schrieb Gordinator via Python-list: > > I wish to write a terminal emulator in Python. I am a fairly competent > > Python user, and I wish to try a new project idea. What references can I > > use when writing my terminal emulator? I wish for it to be a true > > terminal emulator as well, not just a Tk text widget or something like > > that. > > > > If you have any advice, please do let me know! > > > Not sure, what you mean with: > > > true terminal emulator as well, not just a Tk text widget or > > something like that > If you want to write a GUI terminal, than that *is* a terminal emulator and > *has* a text widget as its visible core. If you want to write something like > getty which runs on the virtual terminals (Ctrl+Alt+F*) than that is a > terminal (not a terminal emulator). Getty isn't a terminal (unless there is another program of the same name). It's a small program to set up a serial communication line. Basically it waits for the modem to connect, sets the relevant parameters (bit rate, byte width, parity, ...) and then hands over to login. Of course in the case of a linux console there is no modem and no serial line involved, so it doesn't have much to do. (Of course this raises the question whether the Linux console is a terminal or a terminal emulator ...) hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hjp-python at hjp.at Sat May 18 11:19:13 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 18 May 2024 17:19:13 +0200 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: References: Message-ID: <20240518151913.w5qqsw67gndy57ry@hjp.at> On 2024-05-16 19:46:07 +0100, Gordinator via Python-list wrote: > To be fair, the problem is the fact that they use Windows (but I guess Linux > users have to deal with venvs, so we're even. I don't think Linux users have to deal with venvs any more than Windows users. Maybe even less because many distributions come with a decent set of Python packages. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From grant.b.edwards at gmail.com Sat May 18 12:48:14 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 18 May 2024 12:48:14 -0400 (EDT) Subject: Terminal Emulator (Posting On Python-List Prohibited) References: <20240518151913.w5qqsw67gndy57ry@hjp.at> Message-ID: <4VhVBk0sy7znVGB@mail.python.org> On 2024-05-18, Peter J. Holzer via Python-list wrote: > On 2024-05-16 19:46:07 +0100, Gordinator via Python-list wrote: > >> To be fair, the problem is the fact that they use Windows (but I >> guess Linux users have to deal with venvs, so we're even. > > I don't think Linux users have to deal with venvs any more than > Windows users. Maybe even less because many distributions come with > a decent set of Python packages. I've been using Python on Linux almost daily for 25 years, and I've yet to use a venv... -- Grant From mats at wichmann.us Sat May 18 14:04:07 2024 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 18 May 2024 12:04:07 -0600 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: <4VhVBk0sy7znVGB@mail.python.org> References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> Message-ID: On 5/18/24 10:48, Grant Edwards via Python-list wrote: > On 2024-05-18, Peter J. Holzer via Python-list wrote: >> On 2024-05-16 19:46:07 +0100, Gordinator via Python-list wrote: >> >>> To be fair, the problem is the fact that they use Windows (but I >>> guess Linux users have to deal with venvs, so we're even. >> >> I don't think Linux users have to deal with venvs any more than >> Windows users. Maybe even less because many distributions come with >> a decent set of Python packages. > > I've been using Python on Linux almost daily for 25 years, same here, but: and I've > yet to use a venv... Distros have do offer a good selection of packaged Python bits, yes, but only for the version of Python that's "native" to that distro release. If you need to test other versions of Python, you're mostly on your own. Just as an example, for a particular project I had one test machine running Fedora 38 until just a couple weeks ago, with Python 3.11 as "native" with a full suite of packages, but I needed to test 3.12 and then the 3.13 pre-releases, as well as occasionally sanity-check the "oldest supported Python for this project", which turned out to be 3.6. I could build all those Pythons myself and install them to a location I can "python3.xx -m pip install" to, but Fedora is nice enough to package up a whole bunch of past and future Python versions, so why? And Fedora really discourages doing installs via pip to a system-packaged Python. So venvs make managing all that pretty convenient. Dunno why everybody's so down on venvs... From arj.python at gmail.com Sat May 18 14:07:03 2024 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 18 May 2024 14:07:03 -0400 Subject: PyCon In-Reply-To: References: Message-ID: Yes, this year's pretty exciting, great keynotes, great lightnings, great location, great even sponsor talks (thought they would be pumping a lot of marketing, but the ones i went were pretty awesome technically) Organization side pretty smooth as well ? On Fri, 17 May 2024, 20:58 Larry Martell via Python-list, < python-list at python.org> wrote: > I?m at PyCon in Pittsburgh and I?m haven?t an amazing time! > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sat May 18 14:15:05 2024 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 May 2024 04:15:05 +1000 Subject: PyCon In-Reply-To: References: Message-ID: On Sun, 19 May 2024 at 04:10, Abdur-Rahmaan Janhangeer via Python-list wrote: > > Yes, this year's pretty exciting, great keynotes, great lightnings, great > location, great even sponsor talks (thought they would be pumping a lot of > marketing, but the ones i went were pretty awesome technically) > > Organization side pretty smooth as well ? I missed out on the first day's lightning talks session due to conflict with work, and it didn't seem to have been recorded. What did I miss? ChrisA From grant.b.edwards at gmail.com Sat May 18 14:41:45 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 18 May 2024 14:41:45 -0400 (EDT) Subject: Terminal Emulator (Posting On Python-List Prohibited) References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> Message-ID: <4VhXjj4ZS6znVGL@mail.python.org> On 2024-05-18, Mats Wichmann via Python-list wrote: > Distros have do offer a good selection of packaged Python bits, yes, but > only for the version of Python that's "native" to that distro release. > If you need to test other versions of Python, you're mostly on your own. For a few years I needed both 2.x and 3.x installed, but my distro (Gentoo) handled that fine (I think most others do also). Gentoo also allows multiple minor versions to be installed (currently I have 3.11 and 3.12 on this machine). But, since Gentoo is a source-based meta-distro, when I install a Python package, the package manager knows how to install it for all installed Python versions that are supported by the package. I can't think of why I would need a venv unless I needed to test something with a Python version that isn't available for Gentoo. That said, there are currently 7 versions available (2.7.18, 3.8.19, 3.9.19, 3.10.14, 3.11.9, 3.12.3, 3.13.0). 3.13 isn't marked stable yet in the Gentoo package database, and I apparently have some Python app/package installed that doesn't yet support 3.12, so I've currently got both 3.12 and 3.11. From arj.python at gmail.com Sat May 18 18:03:55 2024 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sat, 18 May 2024 18:03:55 -0400 Subject: PyCon In-Reply-To: References: Message-ID: Two interesting ones: - Norwegian library: https://fosstodon.org/@osdotsystem/112459312723574625 - One about if Ai will take our jobs, using py to find out and she concludes it will On Sat, 18 May 2024, 14:15 Chris Angelico via Python-list, < python-list at python.org> wrote: > On Sun, 19 May 2024 at 04:10, Abdur-Rahmaan Janhangeer via Python-list > wrote: > > > > Yes, this year's pretty exciting, great keynotes, great lightnings, great > > location, great even sponsor talks (thought they would be pumping a lot > of > > marketing, but the ones i went were pretty awesome technically) > > > > Organization side pretty smooth as well ? > > I missed out on the first day's lightning talks session due to > conflict with work, and it didn't seem to have been recorded. What did > I miss? > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de Sat May 18 11:31:02 2024 From: piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de (Piergiorgio Sartor) Date: Sat, 18 May 2024 17:31:02 +0200 Subject: Terminal Emulator In-Reply-To: References: Message-ID: On 14/05/2024 19.44, Gordinator wrote: > I wish to write a terminal emulator in Python. I am a fairly competent > Python user, and I wish to try a new project idea. What references can I > use when writing my terminal emulator? I wish for it to be a true > terminal emulator as well, not just a Tk text widget or something like > that. > > If you have any advice, please do let me know! I would start writing down what this "terminal emulator" should do. Then, collect information about what module / library can support the features. bye, -- piergiorgio From piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de Sat May 18 14:12:33 2024 From: piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de (Piergiorgio Sartor) Date: Sat, 18 May 2024 20:12:33 +0200 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> Message-ID: On 18/05/2024 20.04, Mats Wichmann wrote: [...] > So venvs make managing all that pretty convenient. Dunno why everybody's > so down on venvs... Only people which are *not* using python... :-) In my experience, venvs is the only possible way to use python properly. The dependency nightmare created by python, pip and all the rest cannot be resolved otherwise. It seems backward compatibility is a taboo... bye, -- piergiorgio From hjp-python at hjp.at Sun May 19 02:49:06 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 19 May 2024 08:49:06 +0200 Subject: venvs vs. package management (was: Terminal Emulator (Posting On Python-List Prohibited)) In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> Message-ID: <20240519064906.iiwcjlvdt4ripfpy@hjp.at> On 2024-05-18 20:12:33 +0200, Piergiorgio Sartor via Python-list wrote: > On 18/05/2024 20.04, Mats Wichmann wrote: > > So venvs make managing all that pretty convenient. Dunno why everybody's > > so down on venvs... > > Only people which are *not* using python... :-) > > In my experience, venvs is the only possible > way to use python properly. That's very much depends on what you mean by properly. Personally, I use venvs a lot. But most of the reasons have more to do with team culture than technical constraints. In a different situation (e.g. if all our developers used Linux and preferrably the same version) I could see myself using venvs much less or maybe not at all. > The dependency nightmare created by python, pip and all the rest > cannot be resolved otherwise. That's what package management on Linux is for. Sure, it means that you won't have the newest version of anything and some packages not at all, but you don't have to care about dependencies. Or updates. (Missing packages can be a problem: Is there a script to automatically generate .deb packages from PyPI? I haven't looked recently ...) > It seems backward compatibility is a taboo... I have recently written a script which checks out the newest version of the project, creates a fresh venv using a requirements.txt without version numbers and runs the test suite. If there is any action required (either because a test fails or because there is a newer version of any dependent package) it will create a ticket in redmine. Oh, and this script runs on a staging server which has the same Linux distribution (and hence the same Python version) as the production server. Seems to work, but that is only necessary because we are using venvs. If we relied on the distro's package management that would basically be a non-issue. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From learn2program at gmail.com Sun May 19 03:32:46 2024 From: learn2program at gmail.com (Alan Gauld) Date: Sun, 19 May 2024 08:32:46 +0100 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> Message-ID: On 18/05/2024 19:12, Piergiorgio Sartor via Python-list wrote: >> So venvs make managing all that pretty convenient. Dunno why everybody's >> so down on venvs... Not so much down on them, they are just one extra step that's mostly not needed(in my use case) > Only people which are *not* using python... :-) > > In my experience, venvs is the only possible > way to use python properly. Well, I've been using Python since 1998 on Linux, Windows and MacOS and have yet to find a use for a venv. I've played with them when they first came out but haven't actually found a scenario where I've thought "I need a venv for that!" But then I'm a sole user, I have 3 or 4 projects going but only me working on them. I only have 2 Python versions at any time and the OS handles that just fine without any venvs. > The dependency nightmare created by python, pip > and all the rest cannot be resolved otherwise. I've honestly never experienced this "nightmare". I install stuff and it just works. -- 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 piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de Sun May 19 09:44:57 2024 From: piergiorgio.sartor.this.should.not.be.used at nexgo.REMOVETHIS.de (Piergiorgio Sartor) Date: Sun, 19 May 2024 15:44:57 +0200 Subject: venvs vs. package management In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> <20240519064906.iiwcjlvdt4ripfpy@hjp.at> Message-ID: On 19/05/2024 08.49, Peter J. Holzer wrote: [...] > That's what package management on Linux is for. Sure, it means that you > won't have the newest version of anything and some packages not at all, > but you don't have to care about dependencies. Or updates. Well, that doesn't work as well. Distributions do not pack everything, this also depending on licenses. Sometimes, or often, you need to use the *latest* version of something, due to some bugfix or similar. The distribution does not always keep up to date everything, so you're stuck. The only solution is a venv, with all needed packages for the given task. Typical problem with PyTorch / TensorFlow. In case of trouble, the first answer is: "Check with the latest (nightly) release". Which means installing something *outside* the Linux distribution support. And this impossible, because this will pull in dependencies like crazy, which are not (yet) in the Linux distribution path. Saying it differently, the latest greatest update is not a wish, it's a must... So, long story short, the only solution I know are venvs... Of course, other solutions are welcome! bye, -- piergiorgio From grant.b.edwards at gmail.com Sun May 19 10:09:07 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 19 May 2024 10:09:07 -0400 (EDT) Subject: Terminal Emulator (Posting On Python-List Prohibited) References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> Message-ID: <4Vj2cg5KqnznVFv@mail.python.org> On 2024-05-19, Alan Gauld via Python-list wrote: >> The dependency nightmare created by python, pip >> and all the rest cannot be resolved otherwise. > > I've honestly never experienced this "nightmare". > I install stuff and it just works. Same here. I occasonlly use pip to install something that isn't packaged for Gentoo, but it doesn't seem to cause problems ? let alone nightmares. I also occasionally package something myself. -- Grant From list1 at tompassin.net Sun May 19 07:51:46 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 19 May 2024 07:51:46 -0400 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> Message-ID: <42fbdfc4-a023-4f28-8d1e-43458c6fad0b@tompassin.net> On 5/19/2024 3:32 AM, Alan Gauld via Python-list wrote: > On 18/05/2024 19:12, Piergiorgio Sartor via Python-list wrote: >>[snip] >> The dependency nightmare created by python, pip >> and all the rest cannot be resolved otherwise. > > I've honestly never experienced this "nightmare". > I install stuff and it just works. One way it can bite even you is if you have a program installed whose requirements claim it needs a certain library of version no higher than X, and you already already have a later version of that library installed since one of your other programs requires it. Pip won't install the new program because of this conflict. In reality, you may know the the new program would work fine with the version of the library you installed, but the packagers of the new program didn't realize they should have updated their requirements. With venvs, you can have separate environments for each. Of course this doesn't help if you need both packages in the same environment... From 2QdxY4RzWzUUiLuE at potatochowder.com Sun May 19 14:57:05 2024 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Sun, 19 May 2024 14:57:05 -0400 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: <7jr2O.73829$k13e.28263@fx14.ams4> References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> <7jr2O.73829$k13e.28263@fx14.ams4> Message-ID: On 2024-05-19 at 18:13:23 +0000, Gilmeh Serda via Python-list wrote: > Was there a reason they chose the name Pip? Package Installer for Python https://pip.pypa.io/en/stable/index.html Every time I see PIP, I think Peripheral Interchange Program, but I'm old. From python at mrabarnett.plus.com Sun May 19 15:01:20 2024 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 19 May 2024 20:01:20 +0100 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: <7jr2O.73829$k13e.28263@fx14.ams4> References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> <7jr2O.73829$k13e.28263@fx14.ams4> Message-ID: On 2024-05-19 19:13, Gilmeh Serda via Python-list wrote: > On Sun, 19 May 2024 08:32:46 +0100, Alan Gauld wrote: > >> I've honestly never experienced this "nightmare". >> I install stuff and it just works. > > Hear! Hear! Me too! And all that. > > I'm on Manjaro, which is a tad finicky about other people touching its > Python since it's used for lots of things. I install things for myself > only. > > Was there a reason they chose the name Pip? > [snip] From https://pip.pypa.io/en/stable/: "pip is the package installer for Python." It's an acronym. From 2QdxY4RzWzUUiLuE at potatochowder.com Sun May 19 14:54:41 2024 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Sun, 19 May 2024 14:54:41 -0400 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: <7jr2O.73829$k13e.28263@fx14.ams4> References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> <7jr2O.73829$k13e.28263@fx14.ams4> Message-ID: On 2024-05-19 at 18:13:23 +0000, Gilmeh Serda via Python-list wrote: > Was there a reason they chose the name Pip? Package Installer for Python https://pip.pypa.io/en/stable/index.html From barry at barrys-emacs.org Sun May 19 17:45:09 2024 From: barry at barrys-emacs.org (Barry) Date: Sun, 19 May 2024 22:45:09 +0100 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: <20240518151913.w5qqsw67gndy57ry@hjp.at> References: <20240518151913.w5qqsw67gndy57ry@hjp.at> Message-ID: <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> > On 18 May 2024, at 16:27, Peter J. Holzer via Python-list wrote: > > I don't think Linux users have to deal with venvs Modern debian (ubuntu) and fedora block users installing using pip. You must use a venv to pip install packages from pypi now. This is implemented in python and pip and enabled by the distros. There are ways to turn off the blocking, but it?s strongly discouraged by the distros. Barry From Karsten.Hilbert at gmx.net Sun May 19 18:00:28 2024 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Mon, 20 May 2024 00:00:28 +0200 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> Message-ID: Am Sun, May 19, 2024 at 10:45:09PM +0100 schrieb Barry via Python-list: > > On 18 May 2024, at 16:27, Peter J. Holzer via Python-list wrote: > > > > I don't think Linux users have to deal with venvs > > Modern debian (ubuntu) and fedora block users installing using pip. > You must use a venv to pip install packages from pypi now. Which makes one wonder how one is supposed to package Python applications requiring modules not yet packaged by Debian. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From skip.montanaro at gmail.com Sun May 19 18:08:37 2024 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 19 May 2024 17:08:37 -0500 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> Message-ID: Modern debian (ubuntu) and fedora block users installing using pip. > Even if you're telling it to install in ~/.local? I could see not allowing to run it as root. I honestly haven't tried. Maybe I should... ? I have an old laptop running XUbuntu 22.04 which I generally only use to compile the most recent branches on GitHub (main, 3.12, & 3.13 at the moment). Skip From roel at roelschroeven.net Sun May 19 18:26:03 2024 From: roel at roelschroeven.net (Roel Schroeven) Date: Mon, 20 May 2024 00:26:03 +0200 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> Message-ID: Skip Montanaro via Python-list schreef op 20/05/2024 om 0:08: > Modern debian (ubuntu) and fedora block users installing using pip. > > > > Even if you're telling it to install in ~/.local? I could see not allowing > to run it as root. I assumed pip install --user would work, but no. I tried it (on Debian 12 (bookworm)): > $ pip install --user docopt > error: externally-managed-environment > > ? This environment is externally managed > ??> To install Python packages system-wide, try apt install > ??? python3-xyz, where xyz is the package you are trying to > ??? install. > > ??? If you wish to install a non-Debian-packaged Python package, > ??? create a virtual environment using python3 -m venv path/to/venv. > ??? Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make > ??? sure you have python3-full installed. > > ??? If you wish to install a non-Debian packaged Python application, > ??? it may be easiest to use pipx install xyz, which will manage a > ??? virtual environment for you. Make sure you have pipx installed. > > ??? See /usr/share/doc/python3.11/README.venv for more information. > > note: If you believe this is a mistake, please contact your Python > installation or OS distribution provider. You can override this, at > the risk of breaking your Python installation or OS, by passing > --break-system-packages. > hint: See PEP 668 for the detailed specification. Exactly the same output for sudo pip install. For easy reference here's a link to that PEP 668: https://peps.python.org/pep-0668/ Which links to the "Externally Managed Environments" on the PyPA specs page: https://packaging.python.org/en/latest/specifications/externally-managed-environments/#externally-managed-environments -- "If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed." -? Onbekend (dikwijls toegeschreven aan Mark Twain, waarschijnlijk onterecht) From grant.b.edwards at gmail.com Sun May 19 18:33:51 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 19 May 2024 18:33:51 -0400 (EDT) Subject: Terminal Emulator (Posting On Python-List Prohibited) References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> <7jr2O.73829$k13e.28263@fx14.ams4> Message-ID: <4VjFq32szfznVFX@mail.python.org> On 2024-05-19, Gilmeh Serda via Python-list wrote: > On Sun, 19 May 2024 08:32:46 +0100, Alan Gauld wrote: > >> I've honestly never experienced this "nightmare". >> I install stuff and it just works. > > Hear! Hear! Me too! And all that. > > I'm on Manjaro, which is a tad finicky about other people touching its > Python since it's used for lots of things. I install things for myself > only. > > Was there a reason they chose the name Pip? I always assumed it was in honor of the PIP (Peripheral Interchange Program?) utility that was used to copy files around on CP/M and DEC's PDP-11 OSes. -- Grant From grant.b.edwards at gmail.com Sun May 19 18:34:34 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 19 May 2024 18:34:34 -0400 (EDT) Subject: Terminal Emulator (Posting On Python-List Prohibited) References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> Message-ID: <4VjFqt51WCznWGh@mail.python.org> On 2024-05-19, Barry via Python-list wrote: > > >> On 18 May 2024, at 16:27, Peter J. Holzer via Python-list wrote: >> >> I don't think Linux users have to deal with venvs > > Modern debian (ubuntu) and fedora block users installing using pip. You can't even use pip to do "user" installs? -- Grant From list1 at tompassin.net Sun May 19 18:49:56 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 19 May 2024 18:49:56 -0400 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> Message-ID: <54765fe0-36d9-477d-acf8-d82cd21ee709@tompassin.net> On 5/19/2024 6:08 PM, Skip Montanaro via Python-list wrote: > Modern debian (ubuntu) and fedora block users installing using pip. >> > > Even if you're telling it to install in ~/.local? I could see not allowing > to run it as root. > > I honestly haven't tried. Maybe I should... ? I have an old laptop running > XUbuntu 22.04 which I generally only use to compile the most recent > branches on GitHub (main, 3.12, & 3.13 at the moment). On some (maybe all) of my Linux VMs, pip - the one installed for the system - won't install something even with --user unless you use the --break-system-packages flag. From list1 at tompassin.net Sun May 19 19:35:13 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 19 May 2024 19:35:13 -0400 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: <4VjFqt51WCznWGh@mail.python.org> References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> <4VjFqt51WCznWGh@mail.python.org> Message-ID: <2e0dd910-6437-49a6-be38-43fea2b2d8d5@tompassin.net> On 5/19/2024 6:34 PM, Grant Edwards via Python-list wrote: > On 2024-05-19, Barry via Python-list wrote: >> >> >>> On 18 May 2024, at 16:27, Peter J. Holzer via Python-list wrote: >>> >>> I don't think Linux users have to deal with venvs >> >> Modern debian (ubuntu) and fedora block users installing using pip. > > You can't even use pip to do "user" installs? Nope, often not. The error messages I've gotten do tell you to use the "--break-system-packages" flag if you really, really want to install the package. So python3 -m pip install --user --break-system-packages [--upgrade] Or install an additional version of Python that isn't managed by the system. > Grant > From list1 at tompassin.net Sun May 19 18:28:05 2024 From: list1 at tompassin.net (Thomas Passin) Date: Sun, 19 May 2024 18:28:05 -0400 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> Message-ID: <40d0aec2-794c-4e2a-9f9c-944ab2f1f493@tompassin.net> On 5/19/2024 6:00 PM, Karsten Hilbert via Python-list wrote: > Am Sun, May 19, 2024 at 10:45:09PM +0100 schrieb Barry via Python-list: > >>> On 18 May 2024, at 16:27, Peter J. Holzer via Python-list wrote: >>> >>> I don't think Linux users have to deal with venvs >> >> Modern debian (ubuntu) and fedora block users installing using pip. >> You must use a venv to pip install packages from pypi now. > > Which makes one wonder how one is supposed to package Python > applications requiring modules not yet packaged by Debian. I confess, I sometimes install those packages using pip's self-warning option "--break-system-packages". Naturally I only install them with --user. Another option besides venvs is to install a different version of Python from python.org, not by using the system installer. For example, if your system version is, say, 3.8.10 (as it is on my Mint VM), install 3.11.9 and make sure you always launch pip with python3.11 -m pip .... I have done this on some VMs, and use the system's Python on some others. Happily none of my Linux VMs are critical for anything. I can blow them away and recreate them without worry. From hjp-python at hjp.at Mon May 20 05:58:59 2024 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 20 May 2024 11:58:59 +0200 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> Message-ID: <20240520095859.zu5oijf7pusksknp@hjp.at> On 2024-05-20 00:26:03 +0200, Roel Schroeven via Python-list wrote: > Skip Montanaro via Python-list schreef op 20/05/2024 om 0:08: > > > Modern debian (ubuntu) and fedora block users installing using pip. > > > > Even if you're telling it to install in ~/.local? I could see not allowing > > to run it as root. > > I assumed pip install --user would work, but no. I tried it (on Debian 12 > (bookworm)): > > > $ pip install --user docopt > > error: externally-managed-environment > > > > ? This environment is externally managed > > ??> To install Python packages system-wide, try apt install > > ??? python3-xyz, where xyz is the package you are trying to > > ??? install. > > > > ??? If you wish to install a non-Debian-packaged Python package, > > ??? create a virtual environment using python3 -m venv path/to/venv. > > ??? Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make > > ??? sure you have python3-full installed. > > > > ??? If you wish to install a non-Debian packaged Python application, > > ??? it may be easiest to use pipx install xyz, which will manage a > > ??? virtual environment for you. Make sure you have pipx installed. > > > > ??? See /usr/share/doc/python3.11/README.venv for more information. > > > > note: If you believe this is a mistake, please contact your Python > > installation or OS distribution provider. You can override this, at the > > risk of breaking your Python installation or OS, by passing > > --break-system-packages. > > hint: See PEP 668 for the detailed specification. > > Exactly the same output for sudo pip install. This message (quoted in all its glory) is too long to be useful. The important bit is at the end: > > You can override this, at the risk of breaking your Python > > installation or OS, by passing --break-system-packages. (I admit I didn't see this the first time I got this message) python3 -m pip install --user --break-system-packages does indeed install into ~/.local/lib/python3.XX/site-packages. This inconvenient, but otoh I have accidentally installed packages into ~/.local in the past, so maybe it's good to make that more explicit. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From olegsivokon at gmail.com Sun May 19 19:15:06 2024 From: olegsivokon at gmail.com (Left Right) Date: Mon, 20 May 2024 01:15:06 +0200 Subject: venvs vs. package management In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> <20240519064906.iiwcjlvdt4ripfpy@hjp.at> Message-ID: There are several independent problems here: 1. Very short release cycle. This is independent of the Python venv module but is indirectly influenced by Python's own release cycle. Package maintainers don't have time for proper testing, they are encouraged to release a bunch of new (and poorly tested) versions, and they never get a break. So, when you install the latest, there will be something else broken. There's never a window to properly test anything. 2. Python made a very short-sighted decision about how imports work. Python doesn't have a concept of "application", and therefore there's no way to specify dependencies per application (and imports import anything that's available, not versioned). That's why every Python application ends up carrying its own Python, with the version of its own dependencies around. Python's venv module is just an acknowledgement of this design flaw. I.e. the proper solution would've been a concept of application and per-application dependency specification, but instead we got this thing that doesn't really work (esp. when native modules and shared libraries are considered), but it "works" often enough to be useful. 3. The Python community grew to be very similar to what PHP 4 was, where there were several "poisonous" examples, which were very popular on the Web, which popularized a way of working with MySQL databases that was very conducive to SQL injections. Python has spread very bad ideas about project management. Similar to how PHP came up with mysql_real_escape() and mysql_this_time_promise_for_real_escape() and so on functions, Python came up with bad solutions to the problems that had to be fixed by removing bad functionality (or, perhaps, education). So, for example, it's very common to use requirements.txt, which is generated by running pip freeze (both practices are bad ideas). Then PyPA came up with a bunch of bad ideas in response to problems like this, eg. pyproject.toml. In an absurd way very much mirroring the situation between makefiles and makefiles generated by autotools, today Python developers are very afraid of doing simple things when it comes to project infrastructure (it absolutely has to be a lot of configuration fed into another configuration, processed by a bunch of programs to generate even more configuration...) And most Python programmers don't really know how the essential components of all of this infrastructure work. They rely on a popular / established pattern of insane multi-step configuration generation to do simple things. And the tradition thus developed is so strong, that it became really cultish. This, of course, negatively contributes to the overall quality of Python packages and tools to work with them. Unfortunately, the landscape of Python today is very diverse. There's no universally good solution to package management because it's broken in the place where nobody is allowed to fix it. Commercial and non-commercial bodies alike rely on people with a lot of experience and knowledge of particular Python gotchas to get things done. (Hey, that's me!) And in different cases, the answer to the problem will be different. Sometimes venv is good enough. Other times you may want a container or a vm image. Yet in a different situation you may want a PyPA or conda package... and there's more. On Sun, May 19, 2024 at 4:05?PM Piergiorgio Sartor via Python-list wrote: > > On 19/05/2024 08.49, Peter J. Holzer wrote: > [...] > > That's what package management on Linux is for. Sure, it means that you > > won't have the newest version of anything and some packages not at all, > > but you don't have to care about dependencies. Or updates. > > Well, that doesn't work as well. > Distributions do not pack everything, this > also depending on licenses. > > Sometimes, or often, you need to use the > *latest* version of something, due to some > bugfix or similar. > > The distribution does not always keep up > to date everything, so you're stuck. > > The only solution is a venv, with all > needed packages for the given task. > > Typical problem with PyTorch / TensorFlow. > > In case of trouble, the first answer is: > "Check with the latest (nightly) release". > > Which means installing something *outside* > the Linux distribution support. > And this impossible, because this will pull > in dependencies like crazy, which are not > (yet) in the Linux distribution path. > > Saying it differently, the latest greatest > update is not a wish, it's a must... > > So, long story short, the only solution I > know are venvs... > > Of course, other solutions are welcome! > > bye, > > -- > > piergiorgio > > -- > https://mail.python.org/mailman/listinfo/python-list From gordinator at gordinator.org Mon May 20 14:43:08 2024 From: gordinator at gordinator.org (Gordinator) Date: Mon, 20 May 2024 19:43:08 +0100 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <0A01893C-85EC-4B50-BCDB-BCA5133C6536@barrys-emacs.org> <20240520095859.zu5oijf7pusksknp@hjp.at> Message-ID: <1RM2O.83519$qrU9.62506@fx03.ams4> On 20/05/2024 10:58, Peter J. Holzer wrote: > On 2024-05-20 00:26:03 +0200, Roel Schroeven via Python-list wrote: >> Skip Montanaro via Python-list schreef op 20/05/2024 om 0:08: >>>> Modern debian (ubuntu) and fedora block users installing using pip. >>> >>> Even if you're telling it to install in ~/.local? I could see not allowing >>> to run it as root. >> >> I assumed pip install --user would work, but no. I tried it (on Debian 12 >> (bookworm)): >> >>> $ pip install --user docopt >>> error: externally-managed-environment >>> >>> ? This environment is externally managed >>> ??> To install Python packages system-wide, try apt install >>> ??? python3-xyz, where xyz is the package you are trying to >>> ??? install. >>> >>> ??? If you wish to install a non-Debian-packaged Python package, >>> ??? create a virtual environment using python3 -m venv path/to/venv. >>> ??? Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make >>> ??? sure you have python3-full installed. >>> >>> ??? If you wish to install a non-Debian packaged Python application, >>> ??? it may be easiest to use pipx install xyz, which will manage a >>> ??? virtual environment for you. Make sure you have pipx installed. >>> >>> ??? See /usr/share/doc/python3.11/README.venv for more information. >>> >>> note: If you believe this is a mistake, please contact your Python >>> installation or OS distribution provider. You can override this, at the >>> risk of breaking your Python installation or OS, by passing >>> --break-system-packages. >>> hint: See PEP 668 for the detailed specification. >> >> Exactly the same output for sudo pip install. > > This message (quoted in all its glory) is too long to be useful. The > important bit is at the end: > >>> You can override this, at the risk of breaking your Python >>> installation or OS, by passing --break-system-packages. > > (I admit I didn't see this the first time I got this message) > > python3 -m pip install --user --break-system-packages > does indeed install into ~/.local/lib/python3.XX/site-packages. > > This inconvenient, but otoh I have accidentally installed packages into > ~/.local in the past, so maybe it's good to make that more explicit. > > hp > Perhaps an alias like so: $ alias 'pip install'='pip install --user --break-system-packages' Would work here? Someone please advise if that is a good idea. From gordinator at gordinator.org Mon May 20 14:49:32 2024 From: gordinator at gordinator.org (Gordinator) Date: Mon, 20 May 2024 19:49:32 +0100 Subject: Terminal Emulator (Posting On Python-List Prohibited) In-Reply-To: <7jr2O.73829$k13e.28263@fx14.ams4> References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> <7jr2O.73829$k13e.28263@fx14.ams4> Message-ID: <0XM2O.93703$FPje.61751@fx11.ams4> > I'm on Manjaro Of course, I'm not here to tell you how to use your computer, and it's great that you're using Linux, but I'd suggest that you look into installing Arch Linux proper. Arch Linux isn't as difficult as people make it out to be (I'd argue that anyone who's had to deal with the Calamares installer has seen worse), and it's hugely rewarding as it gives you a fundamental overview of how your system operates and what makes it tick, since you need to install it yourself manually. Plus, Manjaro holds back packages by about a month or so, sometimes more, which breaks AUR packages, which are designed around Arch Linux's packages, which are newer. On top of this, the Manjaro team just can't be trusted with basic things like not having their SSL certs expire on their website (this has happened half a dozen times in the past, which is embarassing, given that things like certbot make installing a certificate the easiest thing in the world). Again, I'm not some power hungry elitist Arch Linux shill or whatever, it's your computer, use it how you want, these are just my suggestions. Don't say I didn't warn you though :) From akkana at shallowsky.com Mon May 20 17:48:12 2024 From: akkana at shallowsky.com (Akkana Peck) Date: Mon, 20 May 2024 15:48:12 -0600 Subject: pip and venvs on Debian (was: Terminal Emulator) In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> Message-ID: Alan Gauld via Python-list writes: > On 18/05/2024 19:12, Piergiorgio Sartor via Python-list wrote: > > >> So venvs make managing all that pretty convenient. Dunno why everybody's > >> so down on venvs... > > Not so much down on them, they are just one extra step that's > mostly not needed(in my use case) Years ago, I used to have trouble with pip install --user on Debian -- sometimes things would end up under .local, sometimes in other places that I've forgotten. So I reluctantly started using venvs. And you know, they work fine. I have one master venv that I created with python3 -m venv --system-site-packages ~/pythonenv/envname and I activate that automatically when I log in, so when I need to install anything that Debian doesn't package, I just pip install it (no --user or --break-system-packages needed) and it installs to that venv. Every so often I need to regenerate it (like when Debian updates the system Python version) but that's easy to do: I don't try to duplicate what's installed there, I just delete the old venv, create a new one and then pip install packages as needed. I have a few special venvs (without --system-site-packages) for specific purposes, but most of the time I'm just using my default venv and it's all pretty transparent and automatic. I know this isn't the usual pythonista model of "you should have a zillion different venvs, one for each program you use, and never use system Python packages", but it works well for me: my pip installed packages are all in a predictable place, and I get security updates for all the software Debian *does* package. That's my biggest beef with pip, the lack of an easy way to update everything at once, and it's the reason I prefer Debian packages when available. ...Akkana From roel at roelschroeven.net Tue May 21 04:03:09 2024 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 21 May 2024 10:03:09 +0200 Subject: pip and venvs on Debian In-Reply-To: References: <20240518151913.w5qqsw67gndy57ry@hjp.at> <4VhVBk0sy7znVGB@mail.python.org> Message-ID: <4d75c169-733f-44b6-aada-1f86785a61d2@roelschroeven.net> Op 20/05/2024 om 23:48 schreef Akkana Peck via Python-list: > Every so often I need to regenerate it (like when Debian updates the system Python version) but that's easy to do: I don't try to duplicate what's installed there, I just delete the old venv, create a new one and then pip install packages as needed. > > I know this isn't the usual pythonista model of "you should have a zillion different venvs, one for each program you use, and never use system Python packages", but it works well for me: my pip installed packages are all in a predictable place, and I get security updates for all the software Debian *does* package. That's my biggest beef with pip, the lack of an easy way to update everything at once, and it's the reason I prefer Debian packages when available. If you have a requirements.txt file with all packages you want, I think you can do pip -install --upgrade -r requirements.txt to update them all. That only works if you don't specify exact versions in the requirements.txt file, so don't use the output of pip freeze to generate that requirements file. Just create it yourself: it's a simple text file with one package per line. Also I prefer not to include dependencies in it for use cases like this (it's another story for packaging, where it can be useful or requirements.txt to mirror your exact environment with dependencies and specific versions). Having such a requirements.txt file also makes it easier to install all the packages again after you re-create your venv. -- "I love science, and it pains me to think that to so many are terrified of the subject or feel that choosing science means you cannot also choose compassion, or the arts, or be awed by nature. Science is not meant to cure us of mystery, but to reinvent and reinvigorate it." -- Robert Sapolsky From HenHanna at devnull.tb Tue May 21 15:14:03 2024 From: HenHanna at devnull.tb (HenHanna) Date: Tue, 21 May 2024 12:14:03 -0700 Subject: Cprod -- (writing this: itertools.product([0, 1], repeat=N ) Message-ID: How can i write this function Cprod (Cartesian Product) simply? (writing this out: itertools.product([0, 1], repeat=N ) The value can be a list or a Tuple. cprod([0, 1], 1) => ((0) (1)) cprod([0, 1], 2) => ((0,0) (0,1) (1,0) (1,1)) This works: def cprod(x, c): if c==1: return [[i] for i in x] Sub= cprod(x, c-1) return [i for F in x for i in [[F]+R for R in Sub]] ---------- Is there another way to write [F]+R ??? Other ways to improve it? From PythonList at DancesWithMice.info Tue May 21 18:44:44 2024 From: PythonList at DancesWithMice.info (dn) Date: Wed, 22 May 2024 10:44:44 +1200 Subject: Cprod -- (writing this: itertools.product([0, 1], repeat=N ) In-Reply-To: References: Message-ID: On 22/05/24 07:14, HenHanna via Python-list wrote: > > How can i write this function Cprod (Cartesian Product) simply? > > ??????????????? (writing this out: itertools.product([0, 1], repeat=N ) > > The value can be a list or a Tuple. > > ??????????????? cprod([0, 1], 1) => ((0) (1)) > > ??????????????? cprod([0, 1], 2) => ((0,0) (0,1) (1,0) (1,1)) > > > > This works: > > ?? def cprod(x, c): > ??????? if c==1: return [[i] for i in x] > ??????? Sub= cprod(x, c-1) > ??????? return [i? for F in x?? for i in [[F]+R for R in Sub]] > > > ---------- Is there another way to write [F]+R ??? > > ?????????????? Other ways to improve it? https://python.readthedocs.io/en/stable/library/itertools.html#itertools.product -- Regards, =dn From HenHanna at dev.null Wed May 22 01:21:53 2024 From: HenHanna at dev.null (HenHanna) Date: Wed, 22 May 2024 05:21:53 +0000 Subject: Cprod -- (writing this: itertools.product([0, 1], =?UTF-8?B?cmVwZWF0PU4gKQ==?= References: Message-ID: dn wrote: > On 22/05/24 07:14, HenHanna via Python-list wrote: >> >> How can i write this function Cprod (Cartesian Product) simply? >> >> ??????????????? (writing this out: itertools.product([0, 1], repeat=N >> ) >> >> The value can be a list or a Tuple. >> >> ??????????????? cprod([0, 1], 1) => ((0) (1)) >> >> ??????????????? cprod([0, 1], 2) => ((0,0) (0,1) (1,0) (1,1)) >> >> >> >> This works: >> >> ?? def cprod(x, c): >> ??????? if c==1: return [[i] for i in x] >> ??????? Sub= cprod(x, c-1) >> ??????? return [i? for F in x?? for i in [[F]+R for R in Sub]] >> >> >> ---------- Is there another way to write [F]+R ??? >> >> ?????????????? Other ways to improve it? > https://python.readthedocs.io/en/stable/library/itertools.html#itertools.product > Regards, =dn Thank you... That code looks elegant... I'll study it. From ujlain at gmail.com Wed May 22 03:06:59 2024 From: ujlain at gmail.com (Vinode Singh Ujlain) Date: Wed, 22 May 2024 12:36:59 +0530 Subject: Can't trap paramiko runtime trace-back error Message-ID: When running the code below , I get error as enumerated below. Why am I not able to trap this paramiko runtime traceback in try-except block ? Exception (client): Error reading SSH protocol banner Traceback (most recent call last): ? File "/home/uzi/.local/lib/python3.8/site-packages/paramiko/transport.py", line 2327, in _check_banner ??? buf = self.packetizer.readline(timeout) ? File "/home/uzi/.local/lib/python3.8/site-packages/paramiko/packet.py", line 381, in readline ??? buf += self._read_timeout(timeout) ? File "/home/uzi/.local/lib/python3.8/site-packages/paramiko/packet.py", line 626, in _read_timeout ??? raise socket.timeout() socket.timeout During handling of the above exception, another exception occurred: Traceback (most recent call last): ? File "/home/uzi/.local/lib/python3.8/site-packages/paramiko/transport.py", line 2143, in run ??? self._check_banner() ? File "/home/uzi/.local/lib/python3.8/site-packages/paramiko/transport.py", line 2331, in _check_banner ??? raise SSHException( paramiko.ssh_exception.SSHException: Error reading SSH protocol banner SSH error: No existing session importparamiko importtime defexecute(): try: # Define the server and credentials ip='p.q.r.s' un, up, po='name', "passwd", 22 bto, sto=60, 60 ssh_client=paramiko.SSHClient() ssh_client.load_system_host_keys() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_client.connect(hostname=ip, port=po, username=un, password=up, banner_timeout=bto, timeout=sto) shell=ssh_client.invoke_shell() defsend_command(command, wait_time=1): shell.send(command+'\n') time.sleep(wait_time) # Give the command some time to execute whilenotshell.recv_ready(): time.sleep(0.1) returnshell.recv(8192).decode() output=send_command('date') print("Output:\n", output) delssh_client exceptparamiko.SSHExceptionase: print(f"SSH error: {e}") exceptExceptionase: print(f"Error: {e}") finally: # Close the SSH client connection delssh_client execute() -- Warm Regards, Vinode Singh Ujlain | https://www.linkedin.com/in/ujlain/ ------------------------------------------------------------------------ From grant.b.edwards at gmail.com Mon May 27 14:41:15 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 27 May 2024 14:41:15 -0400 (EDT) Subject: Weird Stuff (Markdown, syntax highlighting and Python) References: Message-ID: <4Vp4Gz3DDyznVGK@mail.python.org> On 2024-05-26, Gilmeh Serda via Python-list wrote: > The web claims (I think on all pages I've read about Markdown and Python) > that this code should work, with some very minor variants on the topic: > > ```python > > import os > > with open(os.path.join('/home/user/apath', 'somefile')) as f: > print(f.read()) > ``` > > However, that is not the case. For me, that block formats as expected using Python markdown. What do you mean by "this code should work [...] that is not the case"? What markdown rendering engine are you using? -- Grant From HenHanna at devnull.tb Mon May 27 15:37:01 2024 From: HenHanna at devnull.tb (HenHanna) Date: Mon, 27 May 2024 12:37:01 -0700 Subject: Any marginally usable programming language approaches an ill defined barely usable re-implementation of half of Common-Lisp In-Reply-To: <87ikyzpccd.fsf@clsnet.nl> References: <868r5vt80v.fsf@williamsburg.bawden.org> <87jzpdx4e7.fsf@clsnet.nl> <87ikyzpccd.fsf@clsnet.nl> Message-ID: On 5/27/2024 7:18 AM, Cor wrote: > Some entity, AKA "B. Pym" , > wrote this mindboggling stuff: > (selectively-snipped-or-not-p) > >> On 12/16/2023, cor at clsnet.nl wrote: >> >>> Any marginally usable programming language approaches an ill >>> defined barely usable re-implementation of half of common-lisp >> >> The good news is, it's not Lisp that sucks, but Common Lisp. >> --- Paul Graham > > Just to set the record straight; > This is not My line. > I quoted it but don't know who the originator of that remark is. > > Cor > a few years ago... when i started learning Python... it was so exciting... Every day i thought... --- THis is Lisp in a thin-disguise ... SO Everyone gets it now. Everyone is a Lisper now. From PythonList at DancesWithMice.info Mon May 27 16:58:17 2024 From: PythonList at DancesWithMice.info (dn) Date: Tue, 28 May 2024 08:58:17 +1200 Subject: Weird Stuff (Markdown, syntax highlighting and Python) In-Reply-To: References: Message-ID: <12dcdc9e-095b-4e8e-ae03-ed45ed64856d@DancesWithMice.info> With reference to another reply here, the "Weird stuff" came from reading the question, finding it unclear, and only later realising that whereas most people write Markdown-formatted documents for later processing, or perhaps docstrings in Markdown-format for collection by documentation systems; here, the objective appears to be using Python to generate Markdown. How much have you used Markdown to any serious degree, before attempting this feat? On 26/05/24 18:28, Gilmeh Serda via Python-list wrote: > The web claims (I think on all pages I've read about Markdown and Python) > that this code should work, with some very minor variants on the topic: There are so many "variants", the problem is not "minor"! Markdown users learn to use their tool (again, see @Grant's question) and work within the implementation of that "variant". Like any other non-standardised tool, the users of some particular 'version' often fail to realise that others using different versions may not enjoy the same experience. Plus-one for standardisation! At the end of the message, the web.refs reveal use of a package which is based upon a variant of Markdown that is 20-years old(!), albeit with some updates to suit yet another variant. Neither variant-author famous for collaboration. The phrase YMMV springs to mind... Some ten years ago, an effort was made to standardise Markup, and it ended-up being called CommonMark. Why is it not called "Standard Markdown" one might ask? Because the fellow who 'invented' Markdown objected. This very objection has likely led directly to your confusions, because the particular PyPi package is based upon that original definition... Whereas, Markdown 3.6 is the most-recently updated Markdown search-hit on PyPi today, have you tried any of the others (which, ironically, may offer more recent and/or more standardised coverage)? This has worked in all of the Markdown processors I have used or tried-out: The (?reasonable) 'common-core', offers single back-ticks for code, triple back-ticks for a code-block, and the latter with or without a language specification which *usually* kicks-in syntax highlighting. > ```python > > import os > > with open(os.path.join('/home/user/apath', 'somefile')) as f: > print(f.read()) > ``` > > However, that is not the case. At least not for me (using Python 3.12.3). It's not Python 3 that is the problem. It is the "Markdown 3.6" package! > If instead I type it: I've not seen the hash-bang combination in-the-wild (but YMMV!) > #!python > > import os > > with open(os.path.join('/home/user/apath', 'somefile')) as f: > print(f.read()) > > As an indented block (four spaces) and a shebang, THEN it works. You even > get line numbers by default. An indented-block is NOT necessarily the same as a code-block - just as "code" is not necessarily "Python". Line numbers are great - although if a code snippet is extracted from the middle of some example code-file, the original line-numbers won't line-up with Markdown's... > N.b. if you don't know, you also need to generate a css file using > pygments to make this work. That's not what the package's docs suggest: https://python-markdown.github.io/extensions/fenced_code_blocks/ > Not until I started to read the markdown source code and its docs pages, > the coin dropped. > > I'm posting this for other Markdown newbies that otherwise probably would > spend hours trying to make it work. > > > Speaking of Markdown. Does anybody out there have any idea how to turn on > table borders, adjust them (color/width/etc.) and such things? Currently I > have to add HTML to do so, which works, but isn't very nice. I'd hate to > spend an additional day or two, hunting for this info. Again, heavily dependent upon the tool in-use. For example, most SSGs and doc-tools (which accept Markdown) have a .css or theming-system which enables 'decorations'. > References: > https://pypi.org/project/Markdown/ > https://python-markdown.github.io/ Further reading: https://en.wikipedia.org/wiki/Markdown https://commonmark.org https://pypi.org/search/?q=markdown -- Regards, =dn From 2QdxY4RzWzUUiLuE at potatochowder.com Mon May 27 16:59:51 2024 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Mon, 27 May 2024 16:59:51 -0400 Subject: Any marginally usable programming language approaches an ill defined barely usable re-implementation of half of Common-Lisp In-Reply-To: References: <868r5vt80v.fsf@williamsburg.bawden.org> <87jzpdx4e7.fsf@clsnet.nl> <87ikyzpccd.fsf@clsnet.nl> Message-ID: On 2024-05-27 at 12:37:01 -0700, HenHanna via Python-list wrote: > > On 5/27/2024 7:18 AM, Cor wrote: > > Some entity, AKA "B. Pym" , > > wrote this mindboggling stuff: > > (selectively-snipped-or-not-p) > > > > > On 12/16/2023, cor at clsnet.nl wrote: > > > > > > > Any marginally usable programming language approaches an ill > > > > defined barely usable re-implementation of half of common-lisp > > > > > > The good news is, it's not Lisp that sucks, but Common Lisp. > > > --- Paul Graham > > > > Just to set the record straight; > > This is not My line. > > I quoted it but don't know who the originator of that remark is. https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule From list1 at tompassin.net Mon May 27 14:08:55 2024 From: list1 at tompassin.net (Thomas Passin) Date: Mon, 27 May 2024 14:08:55 -0400 Subject: Weird Stuff (Markdown, syntax highlighting and Python) In-Reply-To: References: Message-ID: On 5/26/2024 2:28 AM, Gilmeh Serda via Python-list wrote: > The web claims (I think on all pages I've read about Markdown and Python) > that this code should work, with some very minor variants on the topic: > > ```python > > import os > > with open(os.path.join('/home/user/apath', 'somefile')) as f: > print(f.read()) > ``` There are different flavors of Markdown, so that might be a factor so far as details of the block are concerned. What do you mean by it not "working"? What do you see and what did you expect to see? What did you see different when you used the next example? How did you generate the output HTML file? > However, that is not the case. At least not for me (using Python 3.12.3). > If instead I type it: > > #!python > > import os > > with open(os.path.join('/home/user/apath', 'somefile')) as f: > print(f.read()) > > As an indented block (four spaces) and a shebang, THEN it works. You even > get line numbers by default. > > N.b. if you don't know, you also need to generate a css file using > pygments to make this work. > > Not until I started to read the markdown source code and its docs pages, > the coin dropped. > > I'm posting this for other Markdown newbies that otherwise probably would > spend hours trying to make it work. > > > Speaking of Markdown. Does anybody out there have any idea how to turn on > table borders, adjust them (color/width/etc.) and such things? Currently I > have to add HTML to do so, which works, but isn't very nice. I'd hate to > spend an additional day or two, hunting for this info. > > References: > https://pypi.org/project/Markdown/ > https://python-markdown.github.io/ > From larry.martell at gmail.com Tue May 28 08:48:22 2024 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 28 May 2024 05:48:22 -0700 Subject: Serializing pydantic enums Message-ID: Just getting started with pydantic. I have this example code: class FinishReason(Enum): stop = 'stop' class Choice(BaseModel): finish_reason: FinishReason = Field(...) But I cannot serialize this: json.dumps(Choice(finish_reason=FinishReason.stop).dict()) *** TypeError: Object of type FinishReason is not JSON serializable I get the object not the value: (Pdb) Choice(finish_reason=FinishReason.stop) Choice(finish_reason=) Also tried it with .value, same result. What am I missing here? From olegsivokon at gmail.com Tue May 28 09:23:49 2024 From: olegsivokon at gmail.com (Left Right) Date: Tue, 28 May 2024 15:23:49 +0200 Subject: Serializing pydantic enums In-Reply-To: References: Message-ID: Most Python objects aren't serializable into JSON. Pydantic isn't special in this sense. What can you do about this? -- Well, if this is a one-of situation, then, maybe just do it by hand? If this is a recurring problem: json.dumps() takes a cls argument that will be used to do the serialization. Extend json.JSONEncoder and implement the encode() method for the encoder class you are passing. I believe that the official docs have some information about this too. On Tue, May 28, 2024 at 2:50?PM Larry Martell via Python-list wrote: > > Just getting started with pydantic. I have this example code: > > class FinishReason(Enum): > stop = 'stop' > > class Choice(BaseModel): > finish_reason: FinishReason = Field(...) > > > But I cannot serialize this: > > json.dumps(Choice(finish_reason=FinishReason.stop).dict()) > *** TypeError: Object of type FinishReason is not JSON serializable > > > I get the object not the value: > > (Pdb) Choice(finish_reason=FinishReason.stop) > Choice(finish_reason=) > > > Also tried it with .value, same result. > > What am I missing here? > -- > https://mail.python.org/mailman/listinfo/python-list From kevinmwilson1956 at yahoo.com Wed May 29 00:33:23 2024 From: kevinmwilson1956 at yahoo.com (Kevin M. Wilson) Date: Wed, 29 May 2024 04:33:23 +0000 (UTC) Subject: Flubbed it in the second interation through the string: range error... HOW? References: <1901134155.5453771.1716957203090.ref@mail.yahoo.com> Message-ID: <1901134155.5453771.1716957203090@mail.yahoo.com> The following is my effort to understand how to process a string, letter, by letter: def myfunc(name):? ??? ? index = 0? ? howmax = len(name)? ? # while (index <= howmax):? ? while (index < howmax):? ? ? ? if (index % 2 == 0):? ? ? ? ? ? print('letter to upper = {}, index {}!'.format(name[index], index))? ? ? ? ? ? name = name[index].upper()? ? ? ? ? ? print('if block {} and index {}'.format(name[index], index))? ? ? ? elif (index % 2 > 0):? ? ? ? ? ? print(index)? ? ? ? ? ? print('Start: elseif block, index is {}, letter is {}'.format(index, name))? ? ? ? ? ? # print('letter to lower = {}'.format(name[index]))? ? ? ? ? ? # print('Already lowercase do noting: name = {}'.format(name[index]))? ? ? ? index += 1? ? ? ? # index = name.upper()? ? ? ?? ? ? return name? ? ? ?? myfunc('capitalism') Error message:? ? ? ? ? ? ? ? ? ? ? ? Not making sense, index is 1, letter s/b 'a'letter to upper = c, index 0! if block C and index 0 1 Start: elseif block, index is 1, letter is C --------------------------------------------------------------------------- IndexError Traceback (most recent call last) Cell In[27], line 21 17 # index = name.upper() 19 return name ---> 21 myfunc('capitalism') Cell In[27], line 8, in myfunc(name) 6 while (index < howmax): 7 if (index % 2 == 0): ----> 8 print('letter to upper = {}, index {}!'.format(name[index], index)) 9 name = name[index].upper() 10 print('if block {} and index {}'.format(name[index], index)) IndexError: string index out of range*************************************************** So, I'm doing something... Stupid!! *************************************************** "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze."? ? ? Isaiah 43:2 From kevinmwilson1956 at yahoo.com Wed May 29 00:38:55 2024 From: kevinmwilson1956 at yahoo.com (Kevin M. Wilson) Date: Wed, 29 May 2024 04:38:55 +0000 (UTC) Subject: Fw: Flubbed it in the second interation through the string: range error... HOW? In-Reply-To: <1901134155.5453771.1716957203090@mail.yahoo.com> References: <1901134155.5453771.1716957203090.ref@mail.yahoo.com> <1901134155.5453771.1716957203090@mail.yahoo.com> Message-ID: <1708304097.5451899.1716957535841@mail.yahoo.com> The format in this email is not of my making, should someone know, how to do this so that it's a readable script do tell! KMW *************************************************** "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze."? ? ? Isaiah 43:2 ----- Forwarded Message ----- From: Kevin M. Wilson via Python-list To: python-list at python.org Sent: Tuesday, May 28, 2024 at 10:35:23 PM MDTSubject: Flubbed it in the second interation through the string: range error... HOW? The following is my effort to understand how to process a string, letter, by letter: def myfunc(name):? ??? ? index = 0? ? howmax = len(name)? ? # while (index <= howmax):? ? while (index < howmax):? ? ? ? if (index % 2 == 0):? ? ? ? ? ? print('letter to upper = {}, index {}!'.format(name[index], index))? ? ? ? ? ? name = name[index].upper()? ? ? ? ? ? print('if block {} and index {}'.format(name[index], index))? ? ? ? elif (index % 2 > 0):? ? ? ? ? ? print(index)? ? ? ? ? ? print('Start: elseif block, index is {}, letter is {}'.format(index, name))? ? ? ? ? ? # print('letter to lower = {}'.format(name[index]))? ? ? ? ? ? # print('Already lowercase do noting: name = {}'.format(name[index]))? ? ? ? index += 1? ? ? ? # index = name.upper()? ? ? ?? ? ? return name? ? ? ?? myfunc('capitalism') Error message:? ? ? ? ? ? ? ? ? ? ? ? Not making sense, index is 1, letter s/b 'a'letter to upper = c, index 0! if block C and index 0 1 Start: elseif block, index is 1, letter is C --------------------------------------------------------------------------- IndexError? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call last) Cell In[27], line 21 ? ? 17? ? ? ? # index = name.upper()? ? ? ? ? ? 19? ? return name? ? ? ? ---> 21 myfunc('capitalism') Cell In[27], line 8, in myfunc(name) ? ? ? 6 while (index < howmax): ? ? ? 7? ? if (index % 2 == 0): ----> 8? ? ? ? print('letter to upper = {}, index {}!'.format(name[index], index)) ? ? ? 9? ? ? ? name = name[index].upper() ? ? 10? ? ? ? print('if block {} and index {}'.format(name[index], index)) IndexError: string index out of range*************************************************** So, I'm doing something... Stupid!! *************************************************** "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze."? ? ? Isaiah 43:2 -- https://mail.python.org/mailman/listinfo/python-list From list1 at tompassin.net Wed May 29 01:14:07 2024 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 29 May 2024 01:14:07 -0400 Subject: Flubbed it in the second interation through the string: range error... HOW? In-Reply-To: <1901134155.5453771.1716957203090@mail.yahoo.com> References: <1901134155.5453771.1716957203090.ref@mail.yahoo.com> <1901134155.5453771.1716957203090@mail.yahoo.com> Message-ID: <28615cd5-5b77-44bb-ba3a-5ce6cad7c943@tompassin.net> Your code is unreadable. The lines have all run together. And after that, kindly explain what you want your code sample to do. "Process" doesn't say much. From what I can make out about what you are trying to do, you would do better to index through your string with for i, chr in enumerate(name): # do something with the character Also, it's 2024 ... time to start using f-strings (because they are more readable than str.format()) On 5/29/2024 12:33 AM, Kevin M. Wilson via Python-list wrote: > The following is my effort to understand how to process a string, letter, by letter: > def myfunc(name):? ??? ? index = 0? ? howmax = len(name)? ? # while (index <= howmax):? ? while (index < howmax):? ? ? ? if (index % 2 == 0):? ? ? ? ? ? print('letter to upper = {}, index {}!'.format(name[index], index))? ? ? ? ? ? name = name[index].upper()? ? ? ? ? ? print('if block {} and index {}'.format(name[index], index))? ? ? ? elif (index % 2 > 0):? ? ? ? ? ? print(index)? ? ? ? ? ? print('Start: elseif block, index is {}, letter is {}'.format(index, name))? ? ? ? ? ? # print('letter to lower = {}'.format(name[index]))? ? ? ? ? ? # print('Already lowercase do noting: name = {}'.format(name[index]))? ? ? ? index += 1? ? ? ? # index = name.upper() > ? ? return name > myfunc('capitalism') > Error message:? ? ? ? ? ? ? ? ? ? ? ? Not making sense, index is 1, letter s/b 'a'letter to upper = c, index 0! > if block C and index 0 > 1 > Start: elseif block, index is 1, letter is C > --------------------------------------------------------------------------- > IndexError Traceback (most recent call last) > Cell In[27], line 21 > 17 # index = name.upper() > 19 return name > ---> 21 myfunc('capitalism') > > Cell In[27], line 8, in myfunc(name) > 6 while (index < howmax): > 7 if (index % 2 == 0): > ----> 8 print('letter to upper = {}, index {}!'.format(name[index], index)) > 9 name = name[index].upper() > 10 print('if block {} and index {}'.format(name[index], index)) > > IndexError: string index out of range*************************************************** > So, I'm doing something... Stupid!! > *************************************************** > "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze." > Isaiah 43:2 From cs at cskk.id.au Wed May 29 01:52:47 2024 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 29 May 2024 15:52:47 +1000 Subject: Flubbed it in the second interation through the string: range error... HOW? In-Reply-To: <28615cd5-5b77-44bb-ba3a-5ce6cad7c943@tompassin.net> References: <28615cd5-5b77-44bb-ba3a-5ce6cad7c943@tompassin.net> Message-ID: On 29May2024 01:14, Thomas Passin wrote: >Also, it's 2024 ... time to start using f-strings (because they are >more readable than str.format()) By which Thomas means stuff like this: print(f'if block {name[index]} and index {index}') Notice the leading "f'". Personally I wouldn't even go that far, just: print('if block', name[index], 'and index', index) But there are plenty of places where f-strings are very useful. From rosuav at gmail.com Wed May 29 03:14:51 2024 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 May 2024 17:14:51 +1000 Subject: Flubbed it in the second interation through the string: range error... HOW? In-Reply-To: References: <28615cd5-5b77-44bb-ba3a-5ce6cad7c943@tompassin.net> Message-ID: On Wed, 29 May 2024 at 16:03, Cameron Simpson via Python-list wrote: > By which Thomas means stuff like this: > > print(f'if block {name[index]} and index {index}') > > Notice the leading "f'". Personally I wouldn't even go that far, just: > > print('if block', name[index], 'and index', index) > > But there are plenty of places where f-strings are very useful. I wouldn't replace str.format() everywhere, nor would I replace percent encoding everywhere - but in this case, I think Thomas is correct. Not because it's 2024 (f-strings were brought in back in 2015, so they're hardly chronologically special), but because most of this looks like debugging output that can take advantage of this feature: print(f"if block {name[index]=} {index=}") ChrisA From o1bigtenor at gmail.com Wed May 29 06:44:50 2024 From: o1bigtenor at gmail.com (o1bigtenor) Date: Wed, 29 May 2024 05:44:50 -0500 Subject: SOLVED! Re: Weird Stuff (Markdown, syntax highlighting and Python) In-Reply-To: References: Message-ID: On Tue, May 28, 2024 at 9:48?PM Gilmeh Serda via Python-list < python-list at python.org> wrote: > > Solved by using a different method. > > - - - And that was how? TIA From python at mrabarnett.plus.com Wed May 29 07:38:17 2024 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 May 2024 12:38:17 +0100 Subject: Flubbed it in the second interation through the string: range error... HOW? In-Reply-To: <1901134155.5453771.1716957203090@mail.yahoo.com> References: <1901134155.5453771.1716957203090.ref@mail.yahoo.com> <1901134155.5453771.1716957203090@mail.yahoo.com> Message-ID: <7a6a2d11-6035-46d3-a078-ecff01909fe9@mrabarnett.plus.com> On 2024-05-29 05:33, Kevin M. Wilson via Python-list wrote: > The following is my effort to understand how to process a string, letter, by letter: > def myfunc(name):? ??? ? index = 0? ? howmax = len(name)? ? # while (index <= howmax):? ? while (index < howmax):? ? ? ? if (index % 2 == 0):? ? ? ? ? ? print('letter to upper = {}, index {}!'.format(name[index], index))? ? ? ? ? ? name = name[index].upper()? ? ? ? ? ? print('if block {} and index {}'.format(name[index], index))? ? ? ? elif (index % 2 > 0):? ? ? ? ? ? print(index)? ? ? ? ? ? print('Start: elseif block, index is {}, letter is {}'.format(index, name))? ? ? ? ? ? # print('letter to lower = {}'.format(name[index]))? ? ? ? ? ? # print('Already lowercase do noting: name = {}'.format(name[index]))? ? ? ? index += 1? ? ? ? # index = name.upper() > ? ? return name > myfunc('capitalism') > Error message:? ? ? ? ? ? ? ? ? ? ? ? Not making sense, index is 1, letter s/b 'a'letter to upper = c, index 0! > if block C and index 0 > 1 > Start: elseif block, index is 1, letter is C > --------------------------------------------------------------------------- > IndexError Traceback (most recent call last) > Cell In[27], line 21 > 17 # index = name.upper() > 19 return name > ---> 21 myfunc('capitalism') > > Cell In[27], line 8, in myfunc(name) > 6 while (index < howmax): > 7 if (index % 2 == 0): > ----> 8 print('letter to upper = {}, index {}!'.format(name[index], index)) > 9 name = name[index].upper() > 10 print('if block {} and index {}'.format(name[index], index)) > > IndexError: string index out of range*************************************************** > So, I'm doing something... Stupid!! > *************************************************** > "When you pass through the waters, I will be with you: and when you?pass through the rivers, they will not sweep over?you. When?you walk?through the fire, you will not be burned: the flames will not set you ablaze." > Isaiah 43:2 I think the code is this: def myfunc(name): index = 0 howmax = len(name) # while (index <= howmax): while (index < howmax): if (index % 2 == 0): print('letter to upper = {}, index {}!'.format(name[index], index)) name = name[index].upper() print('if block {} and index {}'.format(name[index], index)) elif (index % 2 > 0): print(index) print('Start: elseif block, index is {}, letter is {}'.format(index, name)) # print('letter to lower = {}'.format(name[index])) # print('Already lowercase do noting: name = {}'.format(name[index])) index += 1 # index = name.upper() return name myfunc('capitalism') What is: name = name[index].upper() meant to be doing? What it's _actually_ doing is getting the character at a given index, converting it to uppercase, and then assigning it to `name`, so `name` is now 1 character long. It doesn't this when 'index' is 0, so after the first iteration, `name` is a single-character string. On the second iteration it raises IndexError because the string is only 1 character long and you're asking for `name[1]`. From list1 at tompassin.net Wed May 29 07:54:09 2024 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 29 May 2024 07:54:09 -0400 Subject: Flubbed it in the second interation through the string: range error... HOW? In-Reply-To: References: <28615cd5-5b77-44bb-ba3a-5ce6cad7c943@tompassin.net> Message-ID: <5b642cc0-e7ee-446d-9158-65c6f333238b@tompassin.net> On 5/29/2024 3:14 AM, Chris Angelico via Python-list wrote: > On Wed, 29 May 2024 at 16:03, Cameron Simpson via Python-list > wrote: >> By which Thomas means stuff like this: >> >> print(f'if block {name[index]} and index {index}') >> >> Notice the leading "f'". Personally I wouldn't even go that far, just: >> >> print('if block', name[index], 'and index', index) >> >> But there are plenty of places where f-strings are very useful. > > I wouldn't replace str.format() everywhere, nor would I replace > percent encoding everywhere - but in this case, I think Thomas is > correct. Not because it's 2024 (f-strings were brought in back in > 2015, so they're hardly chronologically special), I only meant that they have been around for 9 years and are usually more readable, so just change over already. I had some inertia over them myself (imagine sticking with % formatting!) so I understand. > but because most of > this looks like debugging output that can take advantage of this > feature: > > print(f"if block {name[index]=} {index=}") > > ChrisA From 2QdxY4RzWzUUiLuE at potatochowder.com Wed May 29 09:05:16 2024 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Wed, 29 May 2024 09:05:16 -0400 Subject: Formatted Output and Argument Parsing (was: Re: Flubbed it in the second interation through the string: range error... HOW?) In-Reply-To: References: <28615cd5-5b77-44bb-ba3a-5ce6cad7c943@tompassin.net> Message-ID: On 2024-05-29 at 17:14:51 +1000, Chris Angelico via Python-list wrote: > I wouldn't replace str.format() everywhere, nor would I replace > percent encoding everywhere - but in this case, I think Thomas is > correct. Not because it's 2024 (f-strings were brought in back in > 2015, so they're hardly chronologically special), but because most of > this looks like debugging output that can take advantage of this > feature: > > print(f"if block {name[index]=} {index=}") defsnark: After years of getopt (and even more, if you include non-Python experience), I'm glad I decided to wait a decade before chugging the optparse koolaid. (For the history-impaired, getopt existed long before Python and will likely exist long after it, but getopt's "replacement" optparse lasted only from 2003 until 2011.) That said, I agree that the = thing makes f-strings eminently useful for debugging, and I wholeheartedly agree with not fixing things that aren't broken. From rosuav at gmail.com Wed May 29 09:58:09 2024 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 May 2024 23:58:09 +1000 Subject: Formatted Output and Argument Parsing (was: Re: Flubbed it in the second interation through the string: range error... HOW?) In-Reply-To: References: <28615cd5-5b77-44bb-ba3a-5ce6cad7c943@tompassin.net> Message-ID: On Wed, 29 May 2024 at 23:06, Dan Sommers via Python-list wrote: > (For the history-impaired, getopt existed long before Python and will > likely exist long after it, but getopt's "replacement" optparse lasted > only from 2003 until 2011.) Depends on your definition of "lasted". It's not getting developed further, but it's still there. If you started using it, you're welcome to keep going. https://docs.python.org/3/library/optparse.html ChrisA From grant.b.edwards at gmail.com Wed May 29 10:02:03 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 29 May 2024 10:02:03 -0400 (EDT) Subject: Flubbed it in the second interation through the string: range error... HOW? References: <28615cd5-5b77-44bb-ba3a-5ce6cad7c943@tompassin.net> Message-ID: <4Vq9zv5ZDhznVH3@mail.python.org> On 2024-05-29, Chris Angelico via Python-list wrote: > print(f"if block {name[index]=} {index=}") Holy cow! How did I not know about the f-string {=} thing? -- Grant From mats at wichmann.us Wed May 29 10:05:51 2024 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 29 May 2024 08:05:51 -0600 Subject: Flubbed it in the second interation through the string: range error... HOW? In-Reply-To: <4Vq9zv5ZDhznVH3@mail.python.org> References: <28615cd5-5b77-44bb-ba3a-5ce6cad7c943@tompassin.net> <4Vq9zv5ZDhznVH3@mail.python.org> Message-ID: <5fad0ede-41ec-4a76-94fe-299418cd72d0@wichmann.us> On 5/29/24 08:02, Grant Edwards via Python-list wrote: > On 2024-05-29, Chris Angelico via Python-list wrote: > >> print(f"if block {name[index]=} {index=}") > > Holy cow! How did I not know about the f-string {=} thing? > It's more recent than f-strings in general, so it's not that hard to miss. From list1 at tompassin.net Wed May 29 10:32:39 2024 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 29 May 2024 10:32:39 -0400 Subject: Flubbed it in the second interation through the string: range error... HOW? In-Reply-To: <1064052561.5558929.1716987352732@mail.yahoo.com> References: <1064052561.5558929.1716987352732.ref@mail.yahoo.com> <1064052561.5558929.1716987352732@mail.yahoo.com> Message-ID: <407cdc1c-f579-452f-afca-5af50f14d2cb@tompassin.net> On 5/29/2024 8:55 AM, Kevin M. Wilson wrote: > Please recall, I said the format for the email failed to retain the > proper indents. > I'll attach a picture of the code! > Purpose; to uppercase every other letter in a string. > > Thanks all, KMW Simpler is good, and readability is good. For a simple conversion that has a little touch of generality: s1 = 'this is a test' def convert(i, ch): return ch.upper() if i % 2 else ch result = ''.join([convert(i, ch) for i, ch in enumerate(s1)]) print(result) # tHiS Is a tEsT However, this has a weakness: what to do about spaces. Should they be counted among the characters to be uppercased? or should they not be included in the count of the alternation? If you want to uppercase every other letter that is not a space, things become a little more complicated. And then do you want this to apply to all whitespace or only spaces? If you want to skip changing spaces, then you need to track the state of converted characters in some way. It would probably be easier (and more readable) to use a "for x in t:" construction: def convert(convert_this, ch): """Convert character ch if convert_this is True. Don't convert spaces. """ if convert_this: if ch == ' ': return (convert_this, ch) elif convert_this: return (False, ch.upper()) return (True, ch) convert_next = False result = '' for ch in s1: convert_next, ch = convert(convert_next, ch) result += ch print(result) # tHiS Is A TeSt There could be even more complications if you allow non-ascii characters but you were asking about processing character by character so I won't get into that. (You haven't specified the problem in enough detail to answer questions like those). > *************************************************** > "When you pass through the waters, I will be with you: and when you?pass > through the rivers, they will not sweep over?you. When?you walk?through > the fire, you will not be burned: the flames will not set you ablaze." > *Isaiah 43:2 > * > > > On Wednesday, May 29, 2024 at 06:19:56 AM MDT, Thomas Passin via > Python-list wrote: > > > On 5/29/2024 3:14 AM, Chris Angelico via Python-list wrote: > > On Wed, 29 May 2024 at 16:03, Cameron Simpson via Python-list > > > wrote: > >> By which Thomas means stuff like this: > >> > >>? ? ? print(f'if block {name[index]} and index {index}') > >> > >> Notice the leading "f'". Personally I wouldn't even go that far, just: > >> > >>? ? ? print('if block', name[index], 'and index', index) > >> > >> But there are plenty of places where f-strings are very useful. > > > > I wouldn't replace str.format() everywhere, nor would I replace > > percent encoding everywhere - but in this case, I think Thomas is > > correct. Not because it's 2024 (f-strings were brought in back in > > 2015, so they're hardly chronologically special), > > I only meant that they have been around for 9 years and are usually more > readable, so just change over already.? I had some inertia over them > myself (imagine sticking with % formatting!) so I understand. > > > > but because most of > > this looks like debugging output that can take advantage of this > > feature: > > > > print(f"if block {name[index]=} {index=}") > > > > ChrisA > > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Wed May 29 10:27:47 2024 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 29 May 2024 15:27:47 +0100 Subject: Flubbed it in the second interation through the string: range error... HOW? In-Reply-To: <1708304097.5451899.1716957535841@mail.yahoo.com> References: <1901134155.5453771.1716957203090.ref@mail.yahoo.com> <1901134155.5453771.1716957203090@mail.yahoo.com> <1708304097.5451899.1716957535841@mail.yahoo.com> Message-ID: > On 29 May 2024, at 05:38, Kevin M. Wilson via Python-list wrote: > > The format in this email is not of my making, should someone know, how to do this so that it's a readable script do tell! > KMW Your mail program may have a plain-text mode to compose messages in try using that. Barry From python at mrabarnett.plus.com Wed May 29 10:59:50 2024 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 29 May 2024 15:59:50 +0100 Subject: Flubbed it in the second interation through the string: range error... HOW? In-Reply-To: <407cdc1c-f579-452f-afca-5af50f14d2cb@tompassin.net> References: <1064052561.5558929.1716987352732.ref@mail.yahoo.com> <1064052561.5558929.1716987352732@mail.yahoo.com> <407cdc1c-f579-452f-afca-5af50f14d2cb@tompassin.net> Message-ID: <4dddd92a-e0ce-44b7-b376-2de9ee6026a3@mrabarnett.plus.com> On 2024-05-29 15:32, Thomas Passin via Python-list wrote: > On 5/29/2024 8:55 AM, Kevin M. Wilson wrote: >> Please recall, I said the format for the email failed to retain the >> proper indents. >> I'll attach a picture of the code! >> Purpose; to uppercase every other letter in a string. >> >> Thanks all, KMW > > Simpler is good, and readability is good. For a simple conversion that > has a little touch of generality: > > s1 = 'this is a test' > def convert(i, ch): > return ch.upper() if i % 2 else ch > > result = ''.join([convert(i, ch) for i, ch in enumerate(s1)]) > print(result) # tHiS Is a tEsT > [snip] Small mistake there. The original code converted to uppercase on even indexes, whereas your code does it on odd ones. > However, this has a weakness: what to do about spaces. Should they be > counted among the characters to be uppercased? or should they not be > included in the count of the alternation? If you want to uppercase > every other letter that is not a space, things become a little more > complicated. And then do you want this to apply to all whitespace or > only spaces? > > If you want to skip changing spaces, then you need to track the state of > converted characters in some way. It would probably be easier (and more > readable) to use a "for x in t:" construction: > > def convert(convert_this, ch): > """Convert character ch if convert_this is True. > Don't convert spaces. > """ > if convert_this: > if ch == ' ': > return (convert_this, ch) > elif convert_this: > return (False, ch.upper()) > return (True, ch) > > convert_next = False > result = '' > for ch in s1: > convert_next, ch = convert(convert_next, ch) > result += ch > print(result) # tHiS Is A TeSt > > There could be even more complications if you allow non-ascii characters > but you were asking about processing character by character so I won't > get into that. > > (You haven't specified the problem in enough detail to answer questions > like those). > [snip] From grant.b.edwards at gmail.com Wed May 29 11:35:46 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 29 May 2024 11:35:46 -0400 (EDT) Subject: Flubbed it in the second interation through the string: range error... HOW? References: <28615cd5-5b77-44bb-ba3a-5ce6cad7c943@tompassin.net> <4Vq9zv5ZDhznVH3@mail.python.org> <5fad0ede-41ec-4a76-94fe-299418cd72d0@wichmann.us> Message-ID: <4VqD421mhcznWHd@mail.python.org> On 2024-05-29, Mats Wichmann via Python-list wrote: > On 5/29/24 08:02, Grant Edwards via Python-list wrote: >> On 2024-05-29, Chris Angelico via Python-list wrote: >> >>> print(f"if block {name[index]=} {index=}") >> >> Holy cow! How did I not know about the f-string {=} thing? > > It's more recent than f-strings in general, so it's not that hard to miss. I really should make a habit of reading through the "what's new" pages when new releases come out... -- Grant From list1 at tompassin.net Wed May 29 11:44:07 2024 From: list1 at tompassin.net (Thomas Passin) Date: Wed, 29 May 2024 11:44:07 -0400 Subject: Flubbed it in the second interation through the string: range error... HOW? In-Reply-To: <4dddd92a-e0ce-44b7-b376-2de9ee6026a3@mrabarnett.plus.com> References: <1064052561.5558929.1716987352732.ref@mail.yahoo.com> <1064052561.5558929.1716987352732@mail.yahoo.com> <407cdc1c-f579-452f-afca-5af50f14d2cb@tompassin.net> <4dddd92a-e0ce-44b7-b376-2de9ee6026a3@mrabarnett.plus.com> Message-ID: <46e34db5-6042-4923-acba-604d5ec648d9@tompassin.net> On 5/29/2024 10:59 AM, MRAB via Python-list wrote: > On 2024-05-29 15:32, Thomas Passin via Python-list wrote: >> On 5/29/2024 8:55 AM, Kevin M. Wilson wrote: >>> Please recall, I said the format for the email failed to retain the >>> proper indents. >>> I'll attach a picture of the code! >>> Purpose; to uppercase every other letter in a string. >>> >>> Thanks all, KMW >> >> Simpler is good, and readability is good.? For a simple conversion that >> has a little touch of generality: >> >> s1 = 'this is a test' >> def convert(i, ch): >> ????? return ch.upper() if i % 2 else ch >> >> result = ''.join([convert(i, ch) for i, ch in enumerate(s1)]) >> print(result)? # tHiS Is a tEsT >> > [snip] > Small mistake there. The original code converted to uppercase on even > indexes, whereas your code does it on odd ones. I wondered if anyone would catch that :) Anyway, I don't think the original question was whether to start with even or odd but ways to iterate character by character and do something, right? >> However, this has a weakness: what to do about spaces.? Should they be >> counted among the characters to be uppercased? or should they not be >> included in the count of the alternation?? If you want to uppercase >> every other letter that is not a space, things become a little more >> complicated.? And then do you want this to apply to all whitespace or >> only spaces? >> >> If you want to skip changing spaces, then you need to track the state of >> converted characters in some way.? It would probably be easier (and more >> readable) to use a "for x in t:" construction: Actually, I did mess up the action for a space. It should be: def convert(convert_this, ch): """Convert character ch if convert_this is True. Don't convert spaces. """ if ch == ' ': return (convert_this, ch) if convert_this: return (False, ch.upper()) return (True, ch) We should never get two printable uppercased characters in a row, even if there is a space between them, but my original convert(convert_this, ch) did. >> def convert(convert_this, ch): >> ????? """Convert character ch if convert_this is True. >> ????? Don't convert spaces. >> ????? """ >> ????? if convert_this: >> ????????? if ch == ' ': >> ????????????? return (convert_this, ch) >> ????????? elif convert_this: >> ????????????? return (False, ch.upper()) >> ????? return (True, ch) >> >> convert_next = False >> result = '' >> for ch in s1: >> ????? convert_next, ch = convert(convert_next, ch) >> ????? result += ch >> print(result)? # tHiS Is A TeSt >> >> There could be even more complications if you allow non-ascii characters >> but you were asking about processing character by character so I won't >> get into that. >> >> (You haven't specified the problem in enough detail to answer questions >> like those). >> > [snip] > > From larry.martell at gmail.com Wed May 29 15:27:04 2024 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 29 May 2024 12:27:04 -0700 Subject: Serializing pydantic enums In-Reply-To: References: Message-ID: On Tue, May 28, 2024 at 11:46?AM Left Right via Python-list wrote: > > Most Python objects aren't serializable into JSON. Pydantic isn't > special in this sense. > > What can you do about this? -- Well, if this is a one-of situation, > then, maybe just do it by hand? > > If this is a recurring problem: json.dumps() takes a cls argument that > will be used to do the serialization. Extend json.JSONEncoder and > implement the encode() method for the encoder class you are passing. I > believe that the official docs have some information about this too. Yeah, I know I can do this, but I seem to recall reading that pydantic handled serialization. Guess not. > On Tue, May 28, 2024 at 2:50?PM Larry Martell via Python-list > wrote: > > > > Just getting started with pydantic. I have this example code: > > > > class FinishReason(Enum): > > stop = 'stop' > > > > class Choice(BaseModel): > > finish_reason: FinishReason = Field(...) > > > > > > But I cannot serialize this: > > > > json.dumps(Choice(finish_reason=FinishReason.stop).dict()) > > *** TypeError: Object of type FinishReason is not JSON serializable > > > > > > I get the object not the value: > > > > (Pdb) Choice(finish_reason=FinishReason.stop) > > Choice(finish_reason=) > > > > > > Also tried it with .value, same result. > > > > What am I missing here? From HenHanna at devnull.tb Wed May 29 14:39:14 2024 From: HenHanna at devnull.tb (HenHanna) Date: Wed, 29 May 2024 11:39:14 -0700 Subject: Any marginally usable programming language approaches an ill defined barely usable re-implementation of half of Common-Lisp In-Reply-To: References: <868r5vt80v.fsf@williamsburg.bawden.org> <87jzpdx4e7.fsf@clsnet.nl> <87ikyzpccd.fsf@clsnet.nl> Message-ID: On 5/27/2024 1:59 PM, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > On 2024-05-27 at 12:37:01 -0700, > HenHanna via Python-list wrote: > >> >> On 5/27/2024 7:18 AM, Cor wrote: >>> Some entity, AKA "B. Pym" , >>> wrote this mindboggling stuff: >>> (selectively-snipped-or-not-p) >>> >>>> On 12/16/2023, cor at clsnet.nl wrote: >>>> >>>>> Any marginally usable programming language approaches an ill >>>>> defined barely usable re-implementation of half of common-lisp >>>> >>>> The good news is, it's not Lisp that sucks, but Common Lisp. >>>> --- Paul Graham >>> >>> Just to set the record straight; >>> This is not My line. >>> I quoted it but don't know who the originator of that remark is. > > https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule interesting!!! Are the Rules 1--9 by Greenspun good too? does Greenspun pun ? From 643-408-1753 at kylheku.com Wed May 29 14:54:33 2024 From: 643-408-1753 at kylheku.com (Kaz Kylheku) Date: Wed, 29 May 2024 18:54:33 -0000 (UTC) Subject: Any marginally usable programming language approaches an ill defined barely usable re-implementation of half of Common-Lisp References: <868r5vt80v.fsf@williamsburg.bawden.org> <87jzpdx4e7.fsf@clsnet.nl> <87ikyzpccd.fsf@clsnet.nl> Message-ID: <20240529114543.208@kylheku.com> On 2024-05-29, HenHanna wrote: > On 5/27/2024 1:59 PM, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: >> https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule > > > interesting!!! > > Are the Rules 1--9 by Greenspun good too? I don't think they exist; it's a joke. However, Greenspun's resume of accomplishments is a marvel and an inspiration, including many in Lisp. A few highlights: https://philip.greenspun.com/personal/resume "Helped architect, simulate and design prototype of HP's Precision Architecture RISC computer. The prototype took two man-years to complete and ran at VAX 11/780 speed in June 1983. This architecture became the basis of HP's computer product line for 15 years and then became the basis for the 64-bit generation of Intel processors." https://philip.greenspun.com/personal/resume-list "Automatic Layout tools for VLSI, with an emphasis on bus cells and automatic implementation of finite state machines (1984 for Symbolics)" "Design tools on Symbolics Lisp Machine for RISC CPU implemented in TTL (1982-3 for Hewlett Packard)" (in reference to the PA-RISC work). "ConSolve system for automating earthmoving, entirely implemented in Lisp (1986-1989 for ConSolve), including: * Delaunay Triangulation-based terrain model, with C0 and C1 surface models. * complete environment for earthworks and road design, including software to specify design surfaces, calculate costs of realizing design surfaces and automatic design tools * tree-structured database of zoning laws and automatic testing of design compliance * hydrology modelling to calculate drainage basins, streams and ridges * simulation of earthmoving vehicles * automated surveying using vehicles and location systems * radio interface to Caterpillar vehicle, including CRCC error detection * automatically generated user interface" -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator at mstdn.ca From PythonList at DancesWithMice.info Wed May 29 17:59:24 2024 From: PythonList at DancesWithMice.info (dn) Date: Thu, 30 May 2024 09:59:24 +1200 Subject: SOLVED! Re: Weird Stuff (Markdown, syntax highlighting and Python) In-Reply-To: References: Message-ID: <604b6d02-bace-430c-96fd-717faf0a1be3@DancesWithMice.info> On 29/05/24 06:49, Gilmeh Serda via Python-list wrote: > > Solved by using a different method. > Hedonist for hire... no job too easy! This combination of sig-file and content seems sadly ironic. How about CONTRIBUTING to the community by explaining 'the solution' to people who may find a similar problem - in the similar manner to the various members who have helped YOU, voluntarily (and despite the paucity of source-information and response)? -- Regards, =dn From larry.martell at gmail.com Wed May 29 18:29:28 2024 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 29 May 2024 15:29:28 -0700 Subject: Serializing pydantic enums In-Reply-To: References: Message-ID: On Wed, May 29, 2024 at 12:27?PM Larry Martell wrote: > > On Tue, May 28, 2024 at 11:46?AM Left Right via Python-list > wrote: > > > > Most Python objects aren't serializable into JSON. Pydantic isn't > > special in this sense. > > > > What can you do about this? -- Well, if this is a one-of situation, > > then, maybe just do it by hand? > > > > If this is a recurring problem: json.dumps() takes a cls argument that > > will be used to do the serialization. Extend json.JSONEncoder and > > implement the encode() method for the encoder class you are passing. I > > believe that the official docs have some information about this too. > > Yeah, I know I can do this, but I seem to recall reading that pydantic > handled serialization. Guess not. Actually it's as simple as adding this to any model that uses an enum model: class Config: use_enum_values = True > > On Tue, May 28, 2024 at 2:50?PM Larry Martell via Python-list > > wrote: > > > > > > Just getting started with pydantic. I have this example code: > > > > > > class FinishReason(Enum): > > > stop = 'stop' > > > > > > class Choice(BaseModel): > > > finish_reason: FinishReason = Field(...) > > > > > > > > > But I cannot serialize this: > > > > > > json.dumps(Choice(finish_reason=FinishReason.stop).dict()) > > > *** TypeError: Object of type FinishReason is not JSON serializable > > > > > > > > > I get the object not the value: > > > > > > (Pdb) Choice(finish_reason=FinishReason.stop) > > > Choice(finish_reason=) > > > > > > > > > Also tried it with .value, same result. > > > > > > What am I missing here? From mats at wichmann.us Wed May 29 19:02:08 2024 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 29 May 2024 17:02:08 -0600 Subject: Serializing pydantic enums In-Reply-To: References: Message-ID: On 5/29/24 13:27, Larry Martell via Python-list wrote: > On Tue, May 28, 2024 at 11:46?AM Left Right via Python-list > wrote: >> >> Most Python objects aren't serializable into JSON. Pydantic isn't >> special in this sense. >> >> What can you do about this? -- Well, if this is a one-of situation, >> then, maybe just do it by hand? >> >> If this is a recurring problem: json.dumps() takes a cls argument that >> will be used to do the serialization. Extend json.JSONEncoder and >> implement the encode() method for the encoder class you are passing. I >> believe that the official docs have some information about this too. > > Yeah, I know I can do this, but I seem to recall reading that pydantic > handled serialization. Guess not. Pydantic devotes some of its documentation to serialization. https://docs.pydantic.dev/latest/concepts/serialization/ As noted elsewhere, some Python objects are easy to serialize, some you need to provide some help. Consider pickling: if you write a class that isn't obviously pickleable, the getstate dunder method can be defined to help out. For Pydantic, there's a couple of ways... aliases in particular seem designed to help: there's a serialization_alias argument to the Field function. From 2QdxY4RzWzUUiLuE at potatochowder.com Wed May 29 20:32:40 2024 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Wed, 29 May 2024 20:32:40 -0400 Subject: Any marginally usable programming language approaches an ill defined barely usable re-implementation of half of Common-Lisp In-Reply-To: References: <868r5vt80v.fsf@williamsburg.bawden.org> <87jzpdx4e7.fsf@clsnet.nl> <87ikyzpccd.fsf@clsnet.nl> Message-ID: On 2024-05-29 at 11:39:14 -0700, HenHanna via Python-list wrote: > On 5/27/2024 1:59 PM, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > > https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule [...] > Are the Rules 1--9 by Greenspun good too? I don't know; let me look it up. Oh, there it is: https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule says that Greenspun said he "was just trying to give the rule a memorable name." Sadly, the citation link is failing for me right now. From HenHanna at devnull.tb Thu May 30 16:03:33 2024 From: HenHanna at devnull.tb (HenHanna) Date: Thu, 30 May 2024 13:03:33 -0700 Subject: From JoyceUlysses.txt -- words occurring exactly once Message-ID: Given a text file of a novel (JoyceUlysses.txt) ... could someone give me a pretty fast (and simple) Python program that'd give me a list of all words occurring exactly once? -- Also, a list of words occurring once, twice or 3 times re: hyphenated words (you can treat it anyway you like) but ideally, i'd treat [editor-in-chief] [go-ahead] [pen-knife] [know-how] [far-fetched] ... as one unit. From PythonList at DancesWithMice.info Thu May 30 17:18:44 2024 From: PythonList at DancesWithMice.info (dn) Date: Fri, 31 May 2024 09:18:44 +1200 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: References: Message-ID: On 31/05/24 08:03, HenHanna via Python-list wrote: > > Given a text file of a novel (JoyceUlysses.txt) ... > > could someone give me a pretty fast (and simple) Python program that'd > give me a list of all words occurring exactly once? > > ????????????? -- Also, a list of words occurring once, twice or 3 times > > > > re: hyphenated words??????? (you can treat it anyway you like) > > ?????? but ideally, i'd treat? [editor-in-chief] > ?????????????????????????????? [go-ahead]? [pen-knife] > ?????????????????????????????? [know-how]? [far-fetched] ... > ?????? as one unit. Did you mention the pay-rate for this work? Split into words - defined as you will. Use Counter. Show some (of your) code and we'll be happy to critique... -- Regards, =dn From HenHanna at devnull.tb Thu May 30 22:26:37 2024 From: HenHanna at devnull.tb (HenHanna) Date: Thu, 30 May 2024 19:26:37 -0700 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: References: Message-ID: On 5/30/2024 2:18 PM, dn wrote: > On 31/05/24 08:03, HenHanna via Python-list wrote: >> >> Given a text file of a novel (JoyceUlysses.txt) ... >> >> could someone give me a pretty fast (and simple) Python program that'd >> give me a list of all words occurring exactly once? >> >> ?????????????? -- Also, a list of words occurring once, twice or 3 times >> >> >> >> re: hyphenated words??????? (you can treat it anyway you like) >> >> ??????? but ideally, i'd treat? [editor-in-chief] >> ??????????????????????????????? [go-ahead]? [pen-knife] >> ??????????????????????????????? [know-how]? [far-fetched] ... >> ??????? as one unit. > > Split into words - defined as you will. > Use Counter. > > Show some (of your) code and we'll be happy to critique... hard to decide what to do with hyphens and apostrophes (I'd, he's, can't, haven't, A's and B's) 2-step-Process 1. make a file listing all words (one word per line) 2. then, doing the counting. using from collections import Counter Related code (for 1) that i'd used before: Rfile = open("JoyceUlysses.txt", 'r') with open( 'Out.txt', 'w' ) as fo: for line in Rfile: line = line.rstrip() wLis = line.split() for w in wLis: if w != "": w = w.rstrip(";:,'\"[]()*&^%$#@!,./<>?_-+=") w = w.lstrip(";:,'\"[]()*&^%$#@!,./<>?_-+=") fo.write(w.lower()) fo.write('\n') From HenHanna at devnull.tb Fri May 31 00:47:14 2024 From: HenHanna at devnull.tb (HenHanna) Date: Thu, 30 May 2024 21:47:14 -0700 Subject: Lprint = ( Lisp-style printing ( of lists and strings (etc.) ) in Python ) Message-ID: ;;; Pls tell me about little tricks you use in Python or Lisp. [('the', 36225), ('and', 17551), ('of', 16759), ('i', 16696), ('a', 15816), ('to', 15722), ('that', 11252), ('in', 10743), ('it', 10687)] ((the 36225) (and 17551) (of 16759) (i 16696) (a 15816) (to 15722) (that 11252) (in 10743) (it 10687)) i think the latter is easier-to-read, so i use this code (by Peter Norvig) def lispstr(exp): # "Convert a Python object back into a Lisp-readable string." if isinstance(exp, list): return '(' + ' '.join(map(lispstr, exp)) + ')' else: return str(exp) def Lprint(x): print(lispstr(x)) From pieter-l at vanoostrum.org Fri May 31 08:39:37 2024 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Fri, 31 May 2024 14:39:37 +0200 Subject: From JoyceUlysses.txt -- words occurring exactly once References: Message-ID: HenHanna writes: > Given a text file of a novel (JoyceUlysses.txt) ... > > could someone give me a pretty fast (and simple) Python program that'd > give me a list of all words occurring exactly once? > > -- Also, a list of words occurring once, twice or 3 times > > > > re: hyphenated words (you can treat it anyway you like) > > but ideally, i'd treat [editor-in-chief] > [go-ahead] [pen-knife] > [know-how] [far-fetched] ... > as one unit. > That is a famous Unix task : (Sorry, no Python) grep -o '\w*' JoyceUlysses.txt | sort | uniq -c | sort -n -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From grant.b.edwards at gmail.com Fri May 31 14:58:55 2024 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 31 May 2024 14:58:55 -0400 (EDT) Subject: From JoyceUlysses.txt -- words occurring exactly once References: Message-ID: <4VrXTW4wHHznWBT@mail.python.org> On 2024-05-31, Pieter van Oostrum via Python-list wrote: > HenHanna writes: > >> Given a text file of a novel (JoyceUlysses.txt) ... >> >> could someone give me a pretty fast (and simple) Python program that'd >> give me a list of all words occurring exactly once? >> >> -- Also, a list of words occurring once, twice or 3 times >> >> re: hyphenated words (you can treat it anyway you like) >> >> but ideally, i'd treat [editor-in-chief] >> [go-ahead] [pen-knife] >> [know-how] [far-fetched] ... >> as one unit. >> > > That is a famous Unix task : (Sorry, no Python) > > grep -o '\w*' JoyceUlysses.txt | sort | uniq -c | sort -n Yep, that's what came to my mind (though I couldn't remember the exact grep option without looking it up). However, I assume that doesn't get you very many points on a homework assignemnt from an "Intruction to Python" class. From dieter.maurer at online.de Fri May 31 13:59:15 2024 From: dieter.maurer at online.de (dieter.maurer at online.de) Date: Fri, 31 May 2024 19:59:15 +0200 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: References: Message-ID: <26202.4083.590062.42312@ixdm.fritz.box> HenHanna wrote at 2024-5-30 13:03 -0700: > >Given a text file of a novel (JoyceUlysses.txt) ... > >could someone give me a pretty fast (and simple) Python program that'd >give me a list of all words occurring exactly once? Your task can be split into several subtasks: * parse the text into words This depends on your notion of "word". In the simplest case, a word is any maximal sequence of non-whitespace characters. In this case, you can use `split` for this task * Make a list unique -- you can use `set` for this > -- Also, a list of words occurring once, twice or 3 times For this you count the number of occurrences in a `list`. You can use the `count` method of lists for this. All individual subtasks are simple. I am confident that you will be able to solve them by yourself (if you are willing to invest a bit of time). From list1 at tompassin.net Fri May 31 17:27:00 2024 From: list1 at tompassin.net (Thomas Passin) Date: Fri, 31 May 2024 17:27:00 -0400 Subject: From JoyceUlysses.txt -- words occurring exactly once In-Reply-To: References: Message-ID: <9eafa07f-a8da-4929-bc92-3a26ba464d34@tompassin.net> On 5/30/2024 4:03 PM, HenHanna via Python-list wrote: > > Given a text file of a novel (JoyceUlysses.txt) ... > > could someone give me a pretty fast (and simple) Python program that'd > give me a list of all words occurring exactly once? > > ????????????? -- Also, a list of words occurring once, twice or 3 times > > > > re: hyphenated words??????? (you can treat it anyway you like) > > ?????? but ideally, i'd treat? [editor-in-chief] > ?????????????????????????????? [go-ahead]? [pen-knife] > ?????????????????????????????? [know-how]? [far-fetched] ... > ?????? as one unit. You will probably get a thousand different suggestions, but here's a fairly direct and readable one in Python: s1 = 'Is this word is the only word repeated in this string' counts = {} for w in s1.lower().split(): counts[w] = counts.get(w, 0) + 1 print(sorted(counts.items())) # [('in', 1), ('is', 2), ('only', 1), ('repeated', 1), ('string', 1), ('the', 1), ('this', 2), ('word', 2)] Of course you can adjust the definition of what constitutes a word, handle punctuation and so on, and tinker with the output format to suit yourself. You would replace s1.lower().split() with, e.g., my_custom_word_splitter(s1). From jay at studiojpc.com Fri May 31 23:21:44 2024 From: jay at studiojpc.com (Jay Cadet | Studio JPC) Date: Sat, 1 Jun 2024 03:21:44 +0000 Subject: Cannot install python properly - python310.dll not found - no pip Message-ID: <9ed4fe7e-c58c-4da2-b481-703e82039774@Spark> Hi. I'm attempting to install and use stable diffusion. However, while installing python 3.10.6, I'm getting the error that the python 310.dll is not found. I've made sure the PATH option is enabled, but it makes no difference. I've also removed and reinstalled python multiple times. Even though I get that error, the python still installs, but when I open the webui-user.bat file in the stable diffusion folder, it opens up the command center and says that there's no module named pip. Please advise on how to fix this problem. Thank you, Jay Cadet Architectural 3D Artist / Photographer studio JPC [p] 516.567.1996 | [w] studiojpc.com | [ig] @studiojpc