From PythonList at DancesWithMice.info Thu Apr 1 00:35:05 2021 From: PythonList at DancesWithMice.info (dn) Date: Thu, 1 Apr 2021 17:35:05 +1300 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> Message-ID: On 01/04/2021 13.54, Chris Angelico wrote: > On Thu, Apr 1, 2021 at 11:39 AM dn via Python-list > wrote: >> >> On 01/04/2021 12.14, Chris Angelico wrote: >>> I think this code makes some sort of argument in the debate about >>> whether Python has too much flexibility or if it's the best >>> metaprogramming toolset in the world. I'm not sure which side of the >>> debate it falls on, though. >>> >>> class Building: >>> resource = None >>> @classmethod >>> def __init_subclass__(bldg): >>> super().__init_subclass__() >>> print("Building:", bldg.__name__) >>> def make_recipe(recip): >>> print(recip.__name__.replace("_", " "), "is made in a", >>> bldg.__name__.replace("_", " ")) >>> bldg.__init_subclass__ = classmethod(make_recipe) >>> >>> >>> class Extractor(Building): ... >>> class Refinery(Building): ... >>> >>> class Crude(Extractor): >>> resource = "Oil" >>> time: 1 >>> Crude: 1 >>> >>> class Plastic(Refinery): >>> Crude: 3 >>> time: 6 >>> Residue: 1 >>> Plastic: 2 >>> >>> class Rubber(Refinery): >>> Crude: 3 >>> time: 6 >>> Residue: 2 >>> Rubber: 2 >> >> >> [pauses for a moment, to let his mind unwind and return to (what passes >> as) 'reality'] > > Real and imaginary are the same thing, just rotated a quarter turn.... In which dimension(s)? >> Without looking into the details/context: surely there's a more >> straightforward approach? > > Perhaps, but there are potentially a LOT of recipes, and I needed to > be able to cleanly edit those, even if the code at the top was a mess. > (The goal here is to map out production patterns in the game > "Satisfactory", for the curious. It's easy to add other things, like > computer manufacturing or bauxite processing, simply by adding more > recipes.) > > My original plan was basically pairwise tuple summing (deriving a set > of "oil in, water in, rubber out, fuel out" for each set of recipes, > where some might be zero), but it turned out that that wasn't flexible > enough, and it really needed more options than that. Which was where my mind was going*. Why not a dict of inputs, processes, and outputs**? Each dict having variable length, from None, and key:values assigned at declaration/init. In the case of process, the contained objects could be Python-functions. With "compact representation" (3.6+) the functions could also be relied upon to represent a 'production line' or pipeline of functions. * but it strayed so far, I had to ask for it back ** in my mindless state, this combination of three activities seemed familiar, to the point of providing much-needed comfort. >> As to this, I'm slightly amused, but perhaps not in a good way: >> >> class Sanatorium( Building ): >> patient_name = "Chris" >> duration_of_treatment = "life" > > I already have certificates from Rutledge's Asylum and MaayaInsane's > (unnamed) asylum, so that seems pretty likely. Noted you on the list of lauded alumni at the latter. When you left the former, did they allow you to keep the t-shirt, or did you have to buy your own memorabilia? (https://mysterious.americanmcgee.com/products/rutledge-asylum-mug) The latter's treatment list sounds remarkably like .mil training. I know of plenty with that t-shirt - but can't think of a one sporting a mug... Should you have one, kindly bring it (with appropriate contents) come ANZAC Day at the end of this month... >> Thus, design suggestion: add a 'back-door' to the __init_subclass__ to >> ensure access to the Internet from any/all buildings! > > Perfect. Nobody'll find it. I'll have full access to Usenet News from > a secret panel in one of the padded sections of the wall. Surely, in such a state of mind, one's natural 'home' would be "the dark web"? Curiously, last night, the nieces (now long passed that age) were talking about the different modes they used to get to various of their schools. (nostalgia in one's twenties???) Which, it should have been expected, opened the way for their father to indulge in the usual grey-hair stories as: walking so many miles barefoot through the snow, falling backwards off the horse because there were so many others climbing up in-front, ... After rolling their eyes (compulsory Dad-joke, -dance, -comment, ... behavioral-response) they attempted to de-rail his, um, railing, by reminding everyone that I went to (boarding) school (aka gentle asylum for young boys - at a considerable distance from 'polite society') by long-distance train. The only understanding of which came when they watched the Harry Potter films and saw the school-kids collecting at a ?London terminus on their way to magic-school. Magic, you ask? Well, maybe more "sinister". We did manage to find a loose floor-board, but a sad life-lesson was learned, when certain ones (un-named*) took it upon themselves to eat all of the contraband secreted there. Another dorm[itory] did manage to prise-open a wall-panel. Their boasting created a (far too) open secret, and the staff (warders) duly relieved them of their treasure... * but not un-punished! Hence the phrase/motto: "stand-and-deliver - hand over all of your chocolate, and no-one will be hurt!" -- Regards, =dn From greg.ewing at canterbury.ac.nz Thu Apr 1 02:32:32 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 1 Apr 2021 19:32:32 +1300 Subject: Canonical conversion of dict of dicts to list of dicts In-Reply-To: References: <874kgs7u0j.fsf@hornfels.zedat.fu-berlin.de> <87wnto6dc0.fsf@hornfels.zedat.fu-berlin.de> <13843347-22f8-74c2-3b8f-07e59940f581@DancesWithMice.info> <87sg4bsuwp.fsf@hornfels.zedat.fu-berlin.de> <96e1966d-51dd-620b-64c4-a715aeef1aee@DancesWithMice.info> Message-ID: On 31/03/21 7:37 pm, dn wrote: > Python offers mutable (can be changed) and immutable (can't) objects > (remember: 'everything is an object'): > https://docs.python.org/3/reference/datamodel.html?highlight=mutable%20data While that's true, it's actually irrelevant to this situation. > $ a = "bob" > $ b = a > $ b = "bert" > $ a > 'bob' Here, you're not even attempting to modify the object that is bound to b; instead, you're rebinding the name b to a different object. Whether the object to which b was previously bound is mutable or not makes no difference. You can see this if you do the equivalent thing with lists: >>> a = ["alice", "bob", "carol"] >>> b = a >>> b ['alice', 'bob', 'carol'] >>> b = ['dave', 'edward', 'felicity'] >>> a ['alice', 'bob', 'carol'] >>> b ['dave', 'edward', 'felicity'] -- Greg From loris.bennett at fu-berlin.de Thu Apr 1 02:46:10 2021 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Thu, 01 Apr 2021 08:46:10 +0200 Subject: Retrieving non-/etc/passwd users with Python 3? References: <87czvfsemi.fsf@hornfels.zedat.fu-berlin.de> <878s63sd9c.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <87czvezeml.fsf@hornfels.zedat.fu-berlin.de> Christian Heimes writes: > On 31/03/2021 14.45, Loris Bennett wrote: >> Chris Angelico writes: >> >>> On Wed, Mar 31, 2021 at 11:21 PM Loris Bennett >>> wrote: >>>> >>>> Hi, >>>> >>>> I want to get a list of users on a Linux system using Python 3.6. All >>>> the users I am interested in are just available via LDAP and are not in >>>> /etc/passwd. Thus, in a bash shell I can use 'getent' to display them. >>>> >>>> When I try to install the PyPi package >>>> >>>> getent >>>> >>>> I get the error >>>> >>>> File "/tmp/pip-build-vu4lziex/getent/setup.py", line 9, in >>>> long_description = file('README.rst').read(), >>>> NameError: name 'file' is not defined >>>> >>>> I duckduckwent a bit and the problem seems to be that 'file' from Python >>>> 2 has been replaced by 'open' in Python 3. >>>> >>>> So what's the standard way of getting a list of users in this case? >>>> >>> >>> I don't have LDAP experience so I don't know for sure, but is the >>> stdlib "pwd" module suitable, or does it only read /etc/passwd? >>> >>> https://docs.python.org/3/library/pwd.html >>> >>> Failing that, one option - and not as bad as you might think - is >>> simply to run getent using the subprocess module, and parse its >>> output. Sometimes that's easier than finding (or porting!) a library. >> >> D'oh! Thanks, 'pwd' is indeed exactly what I need. When I read the >> documentation here >> >> https://docs.python.org/3.6/library/pwd.html >> >> I mistakenly got the impression that it was only going to give me the >> local users. It doesn't actually say that, but it mentions /etc/shadow >> and not getent. However, it does talk about the "account and password >> database", which is a clue (although our passwords are on an other >> system entirely), since "database" is more getent terminology. >> >> In any case, I think 'pwd' is hiding its light under a bushel a bit >> here. > > Please open a documentation bug :) I'll have a look :) > The pwd and grp module use the libc API to get users from the local > account database. On Linux and glibc the account database is handled by > NSS and nsswitch.conf. > > By the way I recommend that you use SSSD instead of talking to LDAP > directly. You'll have a much more pleasant experience. Yes, we do use SSSD, but my grasp of what it does is pretty much limited to "as well as looking at the local /etc/passwd it can also talk to LDAP" :/ Cheers, Loris -- This signature is currently under construction. From zen.supagood at gmail.com Thu Apr 1 07:50:39 2021 From: zen.supagood at gmail.com (Alexey) Date: Thu, 1 Apr 2021 04:50:39 -0700 (PDT) Subject: memory consumption In-Reply-To: References: <7c09728f-2a39-4e3d-ba5f-cc417cb67e9dn@googlegroups.com> <8012307d-b23b-4604-b8fb-7851de577b06n@googlegroups.com> <9d572fc8-07d5-4a44-a3dd-d93db5845826n@googlegroups.com> <8dfdd577-a813-48f4-afc4-bfa22e086711n@googlegroups.com> <151c52f0-a725-b13d-8352-e9fed8c2eb21@btinternet.com> <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> Message-ID: Found it. As I said before the problem was lurking in the cache. Few days ago I read about circular references and things like that and I thought to myself that it might be the case. To build the cache I was using lots of 'setdefault' methods chained together self.__cache.setdefault(cluster_name, {}).setdefault(database_name, {})... and instead of wring a long lines I decided to divide it to increase readability cluster = self.__cache.setdefault(cluster_name, {}) database = database.setdefault(database_name, {}) ... and I guess that was the problem. First thing I did was to rewrite this back to single line. And it helped. In the morning I tried different approach and decided to clear cache with different way. So instead of doing self.__cache.clear(), self.__cache = None or even 'del self.__cache' I did: for item in list(self.__cache.keys()): del self.__cache[item] and againg effect was positive. As a result I decided to rewrite all the methods to build,update and get from cache without 'setdefault' and to use "for loop" instead of dict.clear(). I don't understand underlying processes and why I had this issues. In my opinion if you're leaving the function scope you don't have to worry about what variables you're leaving there. There are other guys at StackOverflow who has similar problems with big dictionaries and memory but they're using different approaches. Thanks you everyone for your time and advices! I think the problem is solved and I hope some one will find this helpful From doctor at doctor.nl2k.ab.ca Thu Apr 1 07:52:49 2021 From: doctor at doctor.nl2k.ab.ca (The Doctor) Date: Thu, 1 Apr 2021 11:52:49 -0000 (UTC) Subject: XanaNews Statistic for comp.lang.python. 4/1/2021 5:52:47 AM Message-ID: XanaNews Statistic for comp.lang.python. 4/1/2021 5:52:47 AM >From article 587730 (3/1/2021 4:09:02 AM) to article 588588 (3/31/2021 11:40:40 PM) Number of threads ................... 385 Number of articles .................. 895 Average articles per thread ......... 2.32 Number of unanswered posts .......... 326 Number of posts from XanaNews users .. 0 Top Threads Ranking Articles Subject ------- -------- ---------------------------------- 1 85 .title() - annoying mistake 2 40 Why assert is not a function? 3 33 python documentation 4 33 neonumeric - C++ arbitrary precision arithmetic library 5 31 memory consumption 6 23 convert script awk in python 7 17 Ann: New Python curses book 8 17 Re: weirdness with list() 9 16 Canonical conversion of dict of dicts to list of dicts 10 14 How to loop over a text file (to remove tags and normalize) using Python 11 11 port to PDOS (especially mainframe) 12 11 Choosable dependency 13 9 Re: editor recommendations? 14 9 Re: XML RPC changes between 3.7 and 3.9 yield 401 http error 15 9 Looking for people interested in a Python register virtual machine project 16 9 Application problems 17 9 A 35mm film camera represented in Python object 18 9 Code Formatter Questions 19 8 How to create both a c extension and a pure python package 20 8 How to implement logging for an imported module? 21 8 How do I read .csv files 22 7 Button placement 23 7 program python 24 7 Pips for python2 and python3 25 6 Re: ? DA ARRESTARE SUBITO L'AVVOCATO PEDOFILO ED ASSASSINO DANIELE MINOTTI DI GENOVA, RAPALLO E CRIMINALE STUDIO LEGALE LISI (FOTO https://ecampus.aicel.org/wp-content/uploads/Daniele-Minotti-300x300.jpg )! 26 6 Problem with printing statement when condition is false 27 6 Horrible abuse of __init_subclass__, or elegant hack? 28 6 Question about generators 29 5 Best practices regarding PYTHONPATH 30 5 Apriori Algorithm 31 5 python curses constant names for mouse wheel movements? 32 5 file location/directory 33 5 Retrieving non-/etc/passwd users with Python 3? 34 5 "unexpected argument" 35 4 a + not b 36 4 REPL peculiarity 37 4 Uninstall error 38 4 SSL certificate issue 39 4 Regarding Python installation issue 40 4 firewall in python 41 4 trouble using pygame 42 4 Found a problem 43 4 Re: try to install Python3.9.2 / setup failed 44 4 Compare word to word files 45 4 Help Please 46 4 pygame font issue 47 3 Unable to find 'edit with ide' option in the Context menu 48 3 i am getting the following error code while trying to reinstall pip 49 3 Apriori Algorithm 50 3 Access to python37_d.lib 51 3 thought 52 3 Getting Modify Setup message 53 3 Re: is not recognized as an internal or external command, operable program or batch file. 54 3 How to set up a 'listening' Unix domain socket 55 3 pygame "font not intialized" 56 3 pygame errors 57 3 IDLE python 58 2 Re: solution manual for Horngren?s Cost Accounting: A Managerial Emphasis 16th Edition 59 2 PYTHONBREAKPOINT=remote_pdb.set_trace Top Posters Ranking Articles Name Most Used Newsreader ------- -------- -------------------------- -------------------- 1 167 TestBank store G2 2 61 Vagrant G2 3 54 Chris Angelico 4 51 students help G2 5 19 Robert Latest slrn 6 19 Terry Reedy Mozilla 7 18 dn Mozilla 8 17 Grant Edwards slrn 9 16 Cameron Simpson Mutt 10 16 Avi Gross Microsoft Outlook 11 15 Alan Gauld Mozilla 12 14 Alexey G2 13 13 MRAB Mozilla 14 12 Mr Flibble Mozilla 15 12 Peter Otten Mozilla 16 10 Thomas Jollans Mozilla 17 10 Dennis Lee Bieber ForteAgent 18 10 Quentin Bock 19 9 Dan Stromberg 20 9 Richard Damon Mozilla 21 9 PEDOFILO SATANISTASSASSINO G2 22 8 Loris Bennett Gnus 23 8 Skip Montanaro 24 8 python at blackward.eu Roundcube Webmail 25 8 Igor Korot 26 7 Abdur-Rahmaan Janhangeer 27 7 moi G2 28 7 Stestagg 29 7 Benjamin Schollnick Apple Mail ( 30 6 Paul Edwards G2 31 6 Andreas Nigg G2 32 6 Dieter Maurer VM 33 6 Paul Bryan Evolution 34 5 Mats Wichmann Mozilla 35 5 ANDREAS NIGG. BANK J SAFRA G2 36 5 D.M. Procida MacSOUP 37 5 Paul Rubin Gnus 38 5 Michael Torrie Mozilla 39 5 Marco Sulla 40 5 Manfred Lotz Claws Mail 41 4 Microsoft Outlook 42 4 S Monzur 43 4 Stefan Ram 44 4 Bischoop slrn 45 4 alberto G2 46 4 Jon Ribbens slrn 47 3 LUIGI ROTUNNO LA TORRE RES G2 48 3 Serhiy Storchaka Mozilla 49 3 Tim Johnson Mozilla 50 3 Christian Gollwitzer Mozilla 51 3 Dan Ciprus (dciprus) 52 3 jak Mozilla 53 3 lucas 54 3 Mirko Mozilla 55 3 Rob Cliffe Mozilla 56 3 Alan Bawden Gnus 57 3 Russell tin 58 3 Frank Millman Mozilla 59 3 Bonita Montero Mozilla 60 3 Marco Ippolito 61 3 sarang shah G2 62 2 Barry iPad Mail ( 63 2 Eli the Bearded Vectrex rn 64 2 Yoosuf Oluwatosin WebService 65 2 2QdxY4RzWzUUiLuE at potatocho 66 2 Johann Klammer Mozilla 67 2 Inada Naoki 68 2 Christian Heimes 69 2 Larry Martell 70 2 Ethan Furman Mozilla 71 2 Gys Mozilla 72 2 Albert-Jan Roskam 73 2 Pankaj Jangid Gnus 74 2 Karen Shaeffer Apple Mail ( 75 2 Travis Griggs Apple Mail ( 76 2 Peter J. Holzer Mutt 77 2 Sibylle Koczian Mozilla 78 2 tommy yama 79 2 Chris M. Thomasson Mozilla 80 2 Barry Scott Apple Mail ( 81 2 Haroldo Stenger G2 82 2 Pablo Galindo Salgado 83 2 Peter Pearson slrn 84 2 D'Arcy Cain Mozilla 85 2 Python Mozilla 86 1 Tomasz Rola Mutt 87 1 GoWar561 G2 88 1 Arjav Jain 89 1 Karsten Hilbert 90 1 Gisle Vanem Mozilla 91 1 Gene Heskett KMail 92 1 Kathleen Kennedy 93 1 Deepak Shetty G2 94 1 Anis4Games 95 1 Viktor Juric G2 96 1 Lars Liedtke Mozilla 97 1 Matt Wheeler Apple Mail ( 98 1 Julio O?a 99 1 ACE 012 100 1 Emerlynn Wee G2 101 1 Giovanni Zibordi G2 102 1 Guido van Rossum 103 1 ??? G2 104 1 M.-A. Lemburg Mozilla 105 1 Bob Martin xnews (by Bob Martin, in 106 1 Brian Oney K- 107 1 William Ray Wing Apple Mail ( 108 1 David Kolovratn?k Mutt 109 1 Chris Green tin 110 1 Victor Dib 111 1 Ben Bacarisse 112 1 Joseph L. Casale 113 1 Joel Goldstick 114 1 Michal Jaworski 115 1 Jaya Yogasundaram 116 1 Sam Mozilla 117 1 Ming Mutt 118 1 Roland Mueller 119 1 Hexamorph Mozilla 120 1 garabik-news-2005-05 at kassi tin 121 1 manfred.schmidt at posteo.de Posteo Webmail 122 1 Lele Gaifax Gnus 123 1 David Lowry-Duda 124 1 John O'Hagan Claws Mail 125 1 Greg Ewing Mozilla 126 1 CLYMATIC GAMING G2 127 1 The Cool Life iPhone Mail ( 128 1 James Lu 129 1 Robin Becker Mozilla 130 1 DAVIDE BALDI - OSM NETWORK G2 131 1 Sagar, Neha 132 1 Schachner, Joseph 133 1 Souhaila Es G2 134 1 Lee Congdon 135 1 Ricky Ky G2 136 1 Mike Dewhirst Mozilla 137 1 Alex Kaye 138 1 Anssi Saari Gnus 139 1 APURVA DHOK 140 1 Muhammad Mughees G2 141 1 Irv Kalb Apple Mail ( 142 1 info cmcc 143 1 Premmy Top Newsreaders Ranking Articles Newsreader Users ------- -------- -------------------------------------------- ----- 1 349 G2 24 2 164 Mozilla 33 3 162 43 4 46 slrn 5 5 21 Mutt 5 6 20 Microsoft Outlook 2 7 20 Gnus 6 8 16 Apple Mail ( 7 9 10 ForteAgent 1 10 8 Roundcube Webmail 1 11 6 Evolution 1 12 6 Claws Mail 2 13 6 VM 1 14 5 MacSOUP 1 15 5 tin 3 16 2 Vectrex rn 1 17 2 WebService 1 18 2 iPad Mail ( 1 19 1 xnews (by Bob Martin, in ooRexx & ncurses) 1 20 1 K- 1 21 1 Posteo Webmail 1 22 1 iPhone Mail ( 1 23 1 KMail 1 -- The lie of USenet is dying is rebuff by these statistics Usenet lives or the internet dies From barry at barrys-emacs.org Thu Apr 1 07:57:04 2021 From: barry at barrys-emacs.org (Barry) Date: Thu, 1 Apr 2021 12:57:04 +0100 Subject: memory consumption In-Reply-To: <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> References: <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> Message-ID: <159974CC-2DB0-49EE-8106-49668C6E24AA@barrys-emacs.org> > On 31 Mar 2021, at 09:42, Alexey wrote: > > ??????, 31 ????? 2021 ?. ? 01:20:06 UTC+3, Dan Stromberg: >>> On Tue, Mar 30, 2021 at 1:25 AM Alexey wrote: >>> >>> >>> I'm sorry. I didn't understand your question right. If I have 4 workers, >>> they require 4Gb >>> in idle state and some extra memory when they execute other tasks. If I >>> increase workers >>> count up to 16, they`ll eat all the memory I have (16GB) on my machine and >>> will crash as soon >>> as system get swapped. >>> >> What if you increase the machine's (operating system's) swap space? Does >> that take care of the problem in practice? > > I can`t do that because it will affect other containers running on this host. > In my opinion it may significantly reduce their performance. Assuming this a modern linux then you should have control groups that allow you to set limits on memory and swap for each container. Are you running with systemd? Barry > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Thu Apr 1 08:19:55 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Apr 2021 23:19:55 +1100 Subject: XanaNews Statistic for comp.lang.python. 4/1/2021 5:52:47 AM In-Reply-To: References: Message-ID: On Thu, Apr 1, 2021 at 10:56 PM The Doctor via Python-list wrote: > Top Posters > > Ranking Articles Name Most Used Newsreader > ------- -------- -------------------------- -------------------- > 1 167 TestBank store G2 > 2 61 Vagrant G2 > 3 54 Chris Angelico > 4 51 students help G2 Ouch. I'm up there among the spambots. ChrisA From rosuav at gmail.com Thu Apr 1 08:26:34 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Apr 2021 23:26:34 +1100 Subject: memory consumption In-Reply-To: References: <7c09728f-2a39-4e3d-ba5f-cc417cb67e9dn@googlegroups.com> <8012307d-b23b-4604-b8fb-7851de577b06n@googlegroups.com> <9d572fc8-07d5-4a44-a3dd-d93db5845826n@googlegroups.com> <8dfdd577-a813-48f4-afc4-bfa22e086711n@googlegroups.com> <151c52f0-a725-b13d-8352-e9fed8c2eb21@btinternet.com> <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> Message-ID: On Thu, Apr 1, 2021 at 10:56 PM Alexey wrote: > > Found it. As I said before the problem was lurking in the cache. > Few days ago I read about circular references and things like that and > I thought to myself that it might be the case. To build the cache I was > using lots of 'setdefault' methods chained together > > self.__cache.setdefault(cluster_name, {}).setdefault(database_name, {})... > > and instead of wring a long lines I decided to divide it to increase > readability > > cluster = self.__cache.setdefault(cluster_name, {}) > database = database.setdefault(database_name, {}) > ... > and I guess that was the problem. > > First thing I did was to rewrite this back to single line. If the cache is always and only used in this way, it might be cleaner to use a defaultdict(dict) instead of the setdefault calls. Or, since this appears to be a two-level cache: self.__cache = defaultdict(lambda: defaultdict(dict)) and then you can simply reference self.__cache[cluster_name][database_name] to read or update the cache. > And it helped. > In the morning I tried different approach and decided to clear cache > with different way. So instead of doing self.__cache.clear(), > self.__cache = None or even 'del self.__cache' I did: > > for item in list(self.__cache.keys()): > del self.__cache[item] > > and againg effect was positive. As a result I decided to rewrite all the > methods to build,update and get from cache without 'setdefault' and > to use "for loop" instead of dict.clear(). That seems very strange. Why should this be more effective than self.__cache.clear()? I don't get it. Having that be more efficient than either self.__cache=None or del self.__cache (which will be equivalent), I can understand. But better than clearing the dict? Seems very odd. Ideally, though, you'd want to NOT have those reference loops. I presume the database objects need to have a reference to whatever 'self' is, but perhaps the cache can be done externally to the object, which would make all the references one-way instead of circular. But that's something only you can investigate. ChrisA From maroloccio at gmail.com Thu Apr 1 08:45:59 2021 From: maroloccio at gmail.com (Marco Ippolito) Date: Thu, 1 Apr 2021 09:45:59 -0300 Subject: memory consumption In-Reply-To: <159974CC-2DB0-49EE-8106-49668C6E24AA@barrys-emacs.org> References: <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> <159974CC-2DB0-49EE-8106-49668C6E24AA@barrys-emacs.org> Message-ID: > >> What if you increase the machine's (operating system's) swap space? Does > >> that take care of the problem in practice? > > > > I can`t do that because it will affect other containers running on this > > host. > > In my opinion it may significantly reduce their performance. > > Assuming this a modern linux then you should have control groups that allow > you to set limits on memory and swap for each container. > > Are you running with systemd? If their problem is that their memory goes from `` to `` and then back down to `` rather than ``, how could `cgroups` have helped in that case? I suspect the high watermark of `` needs to be reachable still and, secondly, that a forceful constraint whilst running would crash the container? How else could one approach it? From zen.supagood at gmail.com Thu Apr 1 08:49:38 2021 From: zen.supagood at gmail.com (Alexey) Date: Thu, 1 Apr 2021 05:49:38 -0700 (PDT) Subject: memory consumption In-Reply-To: References: <159974CC-2DB0-49EE-8106-49668C6E24AA@barrys-emacs.org> <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> Message-ID: <65ce6e04-e1e8-491c-beef-ad72fe717de5n@googlegroups.com> ???????, 1 ?????? 2021 ?. ? 14:57:29 UTC+3, Barry: > > On 31 Mar 2021, at 09:42, Alexey wrote: > > > > ?????, 31 ????? 2021 ?. ? 01:20:06 UTC+3, Dan Stromberg: > >>> On Tue, Mar 30, 2021 at 1:25 AM Alexey wrote: > >>> > >>> > >>> I'm sorry. I didn't understand your question right. If I have 4 workers, > >>> they require 4Gb > >>> in idle state and some extra memory when they execute other tasks. If I > >>> increase workers > >>> count up to 16, they`ll eat all the memory I have (16GB) on my machine and > >>> will crash as soon > >>> as system get swapped. > >>> > >> What if you increase the machine's (operating system's) swap space? Does > >> that take care of the problem in practice? > > > > I can`t do that because it will affect other containers running on this host. > > In my opinion it may significantly reduce their performance. > Assuming this a modern linux then you should have control groups that allow you to set limits on memory and swap for each container. > > Are you running with systemd? I really don't know. From maroloccio at gmail.com Thu Apr 1 08:56:01 2021 From: maroloccio at gmail.com (Marco Ippolito) Date: Thu, 1 Apr 2021 09:56:01 -0300 Subject: memory consumption In-Reply-To: <65ce6e04-e1e8-491c-beef-ad72fe717de5n@googlegroups.com> References: <159974CC-2DB0-49EE-8106-49668C6E24AA@barrys-emacs.org> <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> <65ce6e04-e1e8-491c-beef-ad72fe717de5n@googlegroups.com> Message-ID: > > Are you running with systemd? > > I really don't know. An example of how to check: ``` $ readlink /sbin/init /lib/systemd/systemd ``` You want to check which program runs as PID 1. ``` ps 1 ``` From barry at barrys-emacs.org Thu Apr 1 09:01:50 2021 From: barry at barrys-emacs.org (Barry) Date: Thu, 1 Apr 2021 14:01:50 +0100 Subject: memory consumption In-Reply-To: References: Message-ID: <5F4F33FD-8F21-4D2D-A8BC-33154D96DF15@barrys-emacs.org> > On 1 Apr 2021, at 13:46, Marco Ippolito wrote: > > ? >> >>>> What if you increase the machine's (operating system's) swap space? Does >>>> that take care of the problem in practice? >>> >>> I can`t do that because it will affect other containers running on this >>> host. >>> In my opinion it may significantly reduce their performance. >> >> Assuming this a modern linux then you should have control groups that allow >> you to set limits on memory and swap for each container. >> >> Are you running with systemd? > > If their problem is that their memory goes from `` to `` and then > back down to `` rather than ``, how could `cgroups` have helped in > that case? > > I suspect the high watermark of `` needs to be reachable still and, > secondly, that a forceful constraint whilst running would crash the container? > > How else could one approach it? > I was responding to the assertion that adding swap to the system would impact other containers. The solution I have used is to set service/container resource limits to ensure they work as expected. I was not suggestion this a fix for the memory leak. Barry From mats at wichmann.us Thu Apr 1 10:21:30 2021 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 1 Apr 2021 08:21:30 -0600 Subject: memory consumption In-Reply-To: References: <8012307d-b23b-4604-b8fb-7851de577b06n@googlegroups.com> <9d572fc8-07d5-4a44-a3dd-d93db5845826n@googlegroups.com> <8dfdd577-a813-48f4-afc4-bfa22e086711n@googlegroups.com> <151c52f0-a725-b13d-8352-e9fed8c2eb21@btinternet.com> <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> Message-ID: <3d3b4101-0fef-9ece-41c4-440f2d75bdfe@wichmann.us> On 4/1/21 5:50 AM, Alexey wrote: > Found it. As I said before the problem was lurking in the cache. > Few days ago I read about circular references and things like that and > I thought to myself that it might be the case. To build the cache I was > using lots of 'setdefault' methods chained together > > self.__cache.setdefault(cluster_name, {}).setdefault(database_name, {})... > > and instead of wring a long lines I decided to divide it to increase > readability > > cluster = self.__cache.setdefault(cluster_name, {}) > database = database.setdefault(database_name, {}) > ... > and I guess that was the problem. I guess it is worth mentioning here that there are people who feel you shouldn't use setdefault() this way. setdefault is primarily a "getter", which has the side effect of filling in dict entry if one did not exist before returning it, and there some folks feel that using it primarily as a "setter" is abusing the interface... Do with that what you will :) From zen.supagood at gmail.com Thu Apr 1 10:22:03 2021 From: zen.supagood at gmail.com (Alexey) Date: Thu, 1 Apr 2021 07:22:03 -0700 (PDT) Subject: memory consumption In-Reply-To: References: <7c09728f-2a39-4e3d-ba5f-cc417cb67e9dn@googlegroups.com> <8012307d-b23b-4604-b8fb-7851de577b06n@googlegroups.com> <9d572fc8-07d5-4a44-a3dd-d93db5845826n@googlegroups.com> <8dfdd577-a813-48f4-afc4-bfa22e086711n@googlegroups.com> <151c52f0-a725-b13d-8352-e9fed8c2eb21@btinternet.com> <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> Message-ID: ???????, 1 ?????? 2021 ?. ? 15:27:01 UTC+3, Chris Angelico: > On Thu, Apr 1, 2021 at 10:56 PM Alexey wrote: > > > > Found it. As I said before the problem was lurking in the cache. > > Few days ago I read about circular references and things like that and > > I thought to myself that it might be the case. To build the cache I was > > using lots of 'setdefault' methods chained together > > > > self.__cache.setdefault(cluster_name, {}).setdefault(database_name, {})... > > > > and instead of wring a long lines I decided to divide it to increase > > readability > > > > cluster = self.__cache.setdefault(cluster_name, {}) > > database = database.setdefault(database_name, {}) > > ... > > and I guess that was the problem. > > > > First thing I did was to rewrite this back to single line. > If the cache is always and only used in this way, it might be cleaner > to use a defaultdict(dict) instead of the setdefault calls. Or, since > this appears to be a two-level cache: > > self.__cache = defaultdict(lambda: defaultdict(dict)) > > and then you can simply reference > self.__cache[cluster_name][database_name] to read or update the cache. I agree > Having that be more efficient than either self.__cache=None or del > self.__cache (which will be equivalent), I can understand. But better > than clearing the dict? Seems very odd. In this particular case 'cache.clear()' just don't work (in context of releasing memory). If someone can tell me why, I'll be very thankful > Ideally, though, you'd want to NOT have those reference loops. I > presume the database objects need to have a reference to whatever > 'self' is, but perhaps the cache can be done externally to the object, > which would make all the references one-way instead of circular. But > that's something only you can investigate. I did some refactoring and changed my code already. From zen.supagood at gmail.com Thu Apr 1 10:31:26 2021 From: zen.supagood at gmail.com (Alexey) Date: Thu, 1 Apr 2021 07:31:26 -0700 (PDT) Subject: memory consumption In-Reply-To: References: <5F4F33FD-8F21-4D2D-A8BC-33154D96DF15@barrys-emacs.org> Message-ID: ???????, 1 ?????? 2021 ?. ? 16:02:15 UTC+3, Barry: > > On 1 Apr 2021, at 13:46, Marco Ippolito wrote: > > > > > >> > >>>> What if you increase the machine's (operating system's) swap space? Does > >>>> that take care of the problem in practice? > >>> > >>> I can`t do that because it will affect other containers running on this > >>> host. > >>> In my opinion it may significantly reduce their performance. > >> > >> Assuming this a modern linux then you should have control groups that allow > >> you to set limits on memory and swap for each container. > >> > >> Are you running with systemd? > > > > If their problem is that their memory goes from `` to `` and then > > back down to `` rather than ``, how could `cgroups` have helped in > > that case? > > > > I suspect the high watermark of `` needs to be reachable still and, > > secondly, that a forceful constraint whilst running would crash the container? > > > > How else could one approach it? > > > I was responding to the assertion that adding swap to the system would impact other containers. > The solution I have used is to set service/container resource limits to ensure they work as expected. > > I was not suggestion this a fix for the memory leak. I think it's good advice anyway. Thanks! From zen.supagood at gmail.com Thu Apr 1 10:46:37 2021 From: zen.supagood at gmail.com (Alexey) Date: Thu, 1 Apr 2021 07:46:37 -0700 (PDT) Subject: memory consumption In-Reply-To: References: <8012307d-b23b-4604-b8fb-7851de577b06n@googlegroups.com> <9d572fc8-07d5-4a44-a3dd-d93db5845826n@googlegroups.com> <8dfdd577-a813-48f4-afc4-bfa22e086711n@googlegroups.com> <151c52f0-a725-b13d-8352-e9fed8c2eb21@btinternet.com> <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> <3d3b4101-0fef-9ece-41c4-440f2d75bdfe@wichmann.us> Message-ID: <216e2428-7333-4197-98e5-4d064f0541d2n@googlegroups.com> ???????, 1 ?????? 2021 ?. ? 17:21:59 UTC+3, Mats Wichmann: > On 4/1/21 5:50 AM, Alexey wrote: > > Found it. As I said before the problem was lurking in the cache. > > Few days ago I read about circular references and things like that and > > I thought to myself that it might be the case. To build the cache I was > > using lots of 'setdefault' methods chained together > > > > self.__cache.setdefault(cluster_name, {}).setdefault(database_name, {})... > > > > and instead of wring a long lines I decided to divide it to increase > > readability > > > > cluster = self.__cache.setdefault(cluster_name, {}) > > database = database.setdefault(database_name, {}) > > ... > > and I guess that was the problem. > I guess it is worth mentioning here that there are people who feel you > shouldn't use setdefault() this way. setdefault is primarily a "getter", > which has the side effect of filling in dict entry if one did not exist > before returning it, and there some folks feel that using it primarily > as a "setter" is abusing the interface... > > Do with that what you will :) Ok ) From rudy at matela.com.br Thu Apr 1 11:12:33 2021 From: rudy at matela.com.br (Rudy Matela) Date: Thu, 1 Apr 2021 12:12:33 -0300 Subject: [ANN] Free Python tutorial with exercises, cscx.org Message-ID: Hello python-list members, I would like to announce the following educational project: Computer Science by Example https://cscx.org/ is a collection of short programming exercises. The site can automatically grade students' solutions and it accepts submissions in Python. The exercises start simple, then increase in difficulty and complexity gradually. Here are some examples: * Print "Hello, World!": https://cscx.org/hello * Add two numbers: https://cscx.org/add1 * Compute the factorial of a number: https://cscx.org/factorial * Compute the GCD of two numbers: https://cscx.org/gcd * Solve the change-making problem: https://cscx.org/cash The website has a tutorial section covering Python's basics. I tried to make the content easy to use by instructors/lecturers, feel free to use this with your students. The backend of the website is open source and you can find it on https://github.com/rudymatela/udge -- Rudy From rosuav at gmail.com Thu Apr 1 02:25:05 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 1 Apr 2021 17:25:05 +1100 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> Message-ID: On Thu, Apr 1, 2021 at 3:36 PM dn via Python-list wrote: > > On 01/04/2021 13.54, Chris Angelico wrote: > > Real and imaginary are the same thing, just rotated a quarter turn.... > > In which dimension(s)? Cartesian. > >> Without looking into the details/context: surely there's a more > >> straightforward approach? > > > > Perhaps, but there are potentially a LOT of recipes, and I needed to > > be able to cleanly edit those, even if the code at the top was a mess. > > (The goal here is to map out production patterns in the game > > "Satisfactory", for the curious. It's easy to add other things, like > > computer manufacturing or bauxite processing, simply by adding more > > recipes.) > > > > My original plan was basically pairwise tuple summing (deriving a set > > of "oil in, water in, rubber out, fuel out" for each set of recipes, > > where some might be zero), but it turned out that that wasn't flexible > > enough, and it really needed more options than that. > > Which was where my mind was going*. Why not a dict of inputs, processes, > and outputs**? Each dict having variable length, from None, and > key:values assigned at declaration/init. In the case of process, the > contained objects could be Python-functions. With "compact > representation" (3.6+) the functions could also be relied upon to > represent a 'production line' or pipeline of functions. Perhaps, but the key here is the input method. It wouldn't look nearly as clean. > > I already have certificates from Rutledge's Asylum and MaayaInsane's > > (unnamed) asylum, so that seems pretty likely. > > Noted you on the list of lauded alumni at the latter. Hmm, where do you see that list? I'm curious. > When you left the former, did they allow you to keep the t-shirt, or did > you have to buy your own memorabilia? > (https://mysterious.americanmcgee.com/products/rutledge-asylum-mug) I beg your pardon? What is this "left"? I'm still there! Actually I pay my membership on a monthly basis, and in return, my walls are lavishly decorated in Alice art. > The latter's treatment list sounds remarkably like .mil training. I know > of plenty with that t-shirt - but can't think of a one sporting a mug... > Should you have one, kindly bring it (with appropriate contents) come > ANZAC Day at the end of this month... https://streamlabs.com/maayainsane/merch/1053635 This is what I'd bring. They're the standard mugs that I offer to guests. Well, I would if ever I had guests, but hermitism is a thing... > Magic, you ask? Well, maybe more "sinister". We did manage to find a > loose floor-board, but a sad life-lesson was learned, when certain ones > (un-named*) took it upon themselves to eat all of the contraband > secreted there. Uh oh. How old was the contraband? ChrisA From mahira.522564 at gmail.com Thu Apr 1 11:08:49 2021 From: mahira.522564 at gmail.com (Mahira Pamnani) Date: Thu, 1 Apr 2021 20:38:49 +0530 Subject: Issues in starting Python application Message-ID: Sir I have been trying hard to install Python on my PC since a long time. The application gets installed but, for reasons unknown, it doesn't start. It keeps asking to repair, modify or uninstall the application. I have tried doing that too, but it still doesn't give any results. Please guide me on how to solve this issue. Thank you From zen.supagood at gmail.com Thu Apr 1 10:25:02 2021 From: zen.supagood at gmail.com (Alexey) Date: Thu, 1 Apr 2021 07:25:02 -0700 (PDT) Subject: memory consumption In-Reply-To: References: <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> <159974CC-2DB0-49EE-8106-49668C6E24AA@barrys-emacs.org> Message-ID: <04cb5b56-3674-4f06-88d2-ff4e8652f440n@googlegroups.com> ???????, 1 ?????? 2021 ?. ? 15:46:21 UTC+3, Marco Ippolito: > I suspect the high watermark of `` needs to be reachable still and, > secondly, that a forceful constraint whilst running would crash the container? Exactly. From zen.supagood at gmail.com Thu Apr 1 10:27:35 2021 From: zen.supagood at gmail.com (Alexey) Date: Thu, 1 Apr 2021 07:27:35 -0700 (PDT) Subject: memory consumption In-Reply-To: References: <159974CC-2DB0-49EE-8106-49668C6E24AA@barrys-emacs.org> <89cf74ea-810e-4522-bf01-305a290b51e0n@googlegroups.com> <65ce6e04-e1e8-491c-beef-ad72fe717de5n@googlegroups.com> Message-ID: <686141b1-f70b-49f3-95f4-a62ff2784bd6n@googlegroups.com> ???????, 1 ?????? 2021 ?. ? 15:56:23 UTC+3, Marco Ippolito: > > > Are you running with systemd? > > > > I really don't know. > An example of how to check: > > ``` > $ readlink /sbin/init > /lib/systemd/systemd > ``` > > You want to check which program runs as PID 1. Thank you Marco From maroloccio at gmail.com Thu Apr 1 11:38:48 2021 From: maroloccio at gmail.com (Marco Ippolito) Date: Thu, 1 Apr 2021 12:38:48 -0300 Subject: Issues in starting Python application In-Reply-To: References: Message-ID: On 2021-04-01, Mahira Pamnani wrote: > Sir > I have been trying hard to install Python on my PC since a long time. The > application gets installed but, for reasons unknown, it doesn't start. > It keeps asking to repair, modify or uninstall the application. > I have tried doing that too, but it still doesn't give any results. > Please guide me on how to solve this issue. > Thank you What do you do that takes you to this offer to repair? For example: I click on the Start menu and try to select... . Maybe a screenshot of the moment in which the problem manifests itself? From python at net153.net Thu Apr 1 11:38:29 2021 From: python at net153.net (Sam) Date: Thu, 1 Apr 2021 10:38:29 -0500 Subject: memory consumption In-Reply-To: <7c09728f-2a39-4e3d-ba5f-cc417cb67e9dn@googlegroups.com> References: <7c09728f-2a39-4e3d-ba5f-cc417cb67e9dn@googlegroups.com> Message-ID: <057b4084-488b-32ce-6c97-c74043fa1426@net153.net> On 3/29/21 5:12 AM, Alexey wrote: > Hello everyone! > I'm experiencing problems with memory consumption. > > I have a class which is doing ETL job. What`s happening inside: > - fetching existing objects from DB via SQLAchemy > - iterate over raw data > - create new/update existing objects > - commit changes > > Before processing data I create internal cache(dictionary) and store all existing objects in it. > Every 10000 items I do bulk insert and flush. At the end I run commit command. > > Problem. Before executing, my interpreter process weighs ~100Mb, after first run memory increases up to 500Mb > and after second run it weighs 1Gb. If I will continue to run this class, memory wont increase, so I think > it's not a memory leak, but rather Python wont release allocated memory back to OS. Maybe I'm wrong. > > What I tried after executing: > - gc.collect() > - created snapshots with tracemalloc and searched for some garbage, diff = > smapshot_before_run - smapshot_after_run > - searched for links with "objgraph" library to internal cache(dictionary > containing elements from DB) > - cleared the cache(dictionary) > - db.session.expire_all() > > This class is a periodic celery task. So when each worker executes this class at least two times, > all celery workers need 1Gb of RAM. Before celery there was a cron script and this class was executed via API call > and the problem was the same. So no matter how I run, interpreter consumes 1Gb of RAM after two runs. > > I see few solutions to this problem > 1. Execute this class in separate process. But I had few errors when the same SQLAlchemy connection being shared > between different processes. > 2. Restart celery worker after executing this task by throwing exception. > 3. Use separate queue for such tasks, but then worker will stay idle most of the time. > All this is looks like a crutch. Do I have any other options ? > > I'm using: > Python - 3.6.13 > Celery - 4.1.0 > Flask-RESTful - 0.3.6 > Flask-SQLAlchemy - 2.3.2 > > Thanks in advance! > I had the (mis)pleasure of dealing with a multi-terabyte postgresql instance many years ago and figuring out why random scripts were eating up system memory became quite common. All of our "ETL" scripts were either written in Perl, Java, or Python but the results were always the same, if a process grew to using 1gb of memory (as your case), then it never "released" it back to the OS. What this basically means is that your script at one time did in fact use/need 1GB of memory. That becomes the "high watermark" and in most cases usage will stay at that level. And if you think about it, it makes sense. Your python program went through the trouble of requesting memory space from the OS, it makes no sense for it to give it back to the OS as if it needed 1GB in the past, it will probably need 1GB in the future so you will just waste time with syscalls. Even the glibc docs state calling free() does not necessarily mean that the OS will allocate the "freed" memory back to the global memory space. There are basically two things you can try. First, try working in smaller batch sizes. 10,000 is a lot, try 100. Second, as you hinted, try moving the work to a separate process. The simple way to do this would be to move away from modules that use threads and instead use something that creates child processes with fork(). Regards, From ikorot01 at gmail.com Thu Apr 1 11:56:24 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Thu, 1 Apr 2021 10:56:24 -0500 Subject: Issues in starting Python application In-Reply-To: References: Message-ID: Hi, On Thu, Apr 1, 2021 at 10:41 AM Marco Ippolito wrote: > > On 2021-04-01, Mahira Pamnani wrote: > > Sir > > I have been trying hard to install Python on my PC since a long time. The > > application gets installed but, for reasons unknown, it doesn't start. > > It keeps asking to repair, modify or uninstall the application. > > I have tried doing that too, but it still doesn't give any results. > > Please guide me on how to solve this issue. > > Thank you > > What do you do that takes you to this offer to repair? > > For example: I click on the Start menu and try to select... . > > Maybe a screenshot of the moment in which the problem manifests itself? Don't send a screenshot to the list - it will get rejected. After you install python do this: Open Windows Command Prompt. Type "python" (without quotes) and press Enter. Will you get a python prompt (liike >>>)? Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From maroloccio at gmail.com Thu Apr 1 12:08:55 2021 From: maroloccio at gmail.com (Marco Ippolito) Date: Thu, 1 Apr 2021 13:08:55 -0300 Subject: NOT ABLE TO DOWNLOAD speech_recognition ON MY COMPUTER In-Reply-To: References: Message-ID: On 2021-04-01, ????Y wrote: > When I enter the command pip install speech_recognition it say?s we cannot > find a compatible version. Try: ``` pip install SpeechRecognition ``` What's the output? From mats at wichmann.us Thu Apr 1 12:39:26 2021 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 1 Apr 2021 10:39:26 -0600 Subject: Issues in starting Python application In-Reply-To: References: Message-ID: <9c67bc9b-8868-0edd-cd9c-5c93a62abcfc@wichmann.us> On 4/1/21 9:08 AM, Mahira Pamnani wrote: > Sir > I have been trying hard to install Python on my PC since a long time. The > application gets installed but, for reasons unknown, it doesn't start. > It keeps asking to repair, modify or uninstall the application. > I have tried doing that too, but it still doesn't give any results. > Please guide me on how to solve this issue. You're ending up rerunning the installer - this seems to have been happening to quite a few Windows users recently. The program you're launching is doing what it's intended to do - manage the Python _installation_, but it's not Python itself. Try launching Python from the start menu - navigate to "Python 3.9" and start either "Python 3.9 (64-bit)" or "IDLE (Python 3.9 64-bit)" depending on whether you want the bare interpreter or the IDLE development environment, or From a command shell type "py" to activate the Python Launcher. Also see here: https://docs.python.org/3/using/windows.html From grant.b.edwards at gmail.com Thu Apr 1 11:55:01 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 1 Apr 2021 15:55:01 -0000 (UTC) Subject: Issues in starting Python application References: Message-ID: On 2021-04-01, Mahira Pamnani wrote: > I have been trying hard to install Python on my PC since a long time. The > application gets installed but, for reasons unknown, it doesn't start. > It keeps asking to repair, modify or uninstall the application. That's because you're re-running the installer, not the installed Python application. -- Grant From shanmukhsrinivas973 at gmail.com Thu Apr 1 12:06:38 2021 From: shanmukhsrinivas973 at gmail.com (=?utf-8?Q?=E1=97=B7=E1=91=8C=E1=91=8E=E1=91=8EY?=) Date: Thu, 1 Apr 2021 21:36:38 +0530 Subject: NOT ABLE TO DOWNLOAD speech_recognition ON MY COMPUTER Message-ID: Hello everyone. I am not able to download speech_recognition . I am not professional just a beggnier but I decided and started developing a voice commanding software and I need to download speech_recognition. When I enter the command pip install speech_recognition it say's we cannot find a compatible version. My windows version is windows [Version 10.0.19042.844] . is there any way I can download it. I will be waiting for your advice. From ikorot01 at gmail.com Thu Apr 1 13:24:51 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Thu, 1 Apr 2021 12:24:51 -0500 Subject: NOT ABLE TO DOWNLOAD speech_recognition ON MY COMPUTER In-Reply-To: References: Message-ID: Hi, On Thu, Apr 1, 2021 at 12:23 PM ????Y wrote: > > Hello everyone. I am not able to download speech_recognition . I am not > professional just a beggnier but I decided and started developing a voice > commanding software and I need to download speech_recognition. When I > enter the command pip install speech_recognition it say's we cannot find > a compatible version. My windows version is > windows [Version 10.0.19042.844] . is there any way I can download it. I > will be waiting for your advice. Someone just answered on another thread. ;-) Try to install SpeechRecognition Thank you. > > > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Thu Apr 1 14:00:40 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 Apr 2021 05:00:40 +1100 Subject: [ANN] Free Python tutorial with exercises, cscx.org In-Reply-To: References: Message-ID: On Fri, Apr 2, 2021 at 2:14 AM Rudy Matela wrote: > > Hello python-list members, > > I would like to announce the following educational project: > > Computer Science by Example https://cscx.org/ is a collection of short > programming exercises. The site can automatically grade students' > solutions and it accepts submissions in Python. > What versions of Python does it support? The setup page is not clear. ChrisA From md_sohail91 at yahoo.com Thu Apr 1 14:42:33 2021 From: md_sohail91 at yahoo.com (Md Sohail Ansari) Date: Thu, 1 Apr 2021 18:42:33 +0000 (UTC) Subject: Unable to use pip to install packages References: <284381786.1658275.1617302553221.ref@mail.yahoo.com> Message-ID: <284381786.1658275.1617302553221@mail.yahoo.com> Hi Team, Thanks for your support. I am having trouble installing any packages using pip in Python 3.x (earlier had Python 3.8.3, so changed to 3.8.8) in Windows 10. Please help me with below issues: -----------------------------------------------C:\Users\mohsohai>pip install pytestTraceback (most recent call last):? File "C:\Users\mohsohai\AppData\Local\Programs\Python\Python38\Scripts\pip-script.py", line 11, in ? ? load_entry_point('pip==21.0.1', 'console_scripts', 'pip')()? File "c:\users\mohsohai\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\cli\main.py", line 71, in main? ? command = create_command(cmd_name, isolated=("--isolated" in cmd_args))? File "c:\users\mohsohai\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\commands\__init__.py", line 96, in create_command? ? module = importlib.import_module(module_path)? File "c:\users\mohsohai\appdata\local\programs\python\python38\lib\importlib\__init__.py", line 127, in import_module? ? return _bootstrap._gcd_import(name[level:], package, level)? File "", line 1014, in _gcd_import? File "", line 991, in _find_and_load? File "", line 975, in _find_and_load_unlocked? File "", line 671, in _load_unlocked? File "", line 783, in exec_module? File "", line 219, in _call_with_frames_removed? File "c:\users\mohsohai\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\commands\install.py", line 12, in ? ? from pip._internal.cache import WheelCacheModuleNotFoundError: No module named 'pip._internal.cache'------------------------------------------------- Note: Have included pip in Enviromnet Variables Thank you,Sohail. From python at mrabarnett.plus.com Thu Apr 1 15:58:14 2021 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 1 Apr 2021 20:58:14 +0100 Subject: Unable to use pip to install packages In-Reply-To: <284381786.1658275.1617302553221@mail.yahoo.com> References: <284381786.1658275.1617302553221.ref@mail.yahoo.com> <284381786.1658275.1617302553221@mail.yahoo.com> Message-ID: <290f799d-30e3-959d-f94c-5adeb6d2fde0@mrabarnett.plus.com> On 2021-04-01 19:42, Md Sohail Ansari via Python-list wrote: > Hi Team, > Thanks for your support. I am having trouble installing any packages using pip in Python 3.x (earlier had Python 3.8.3, so changed to 3.8.8) in Windows 10. > Please help me with below issues: > -----------------------------------------------C:\Users\mohsohai>pip install pytestTraceback (most recent call last):? File "C:\Users\mohsohai\AppData\Local\Programs\Python\Python38\Scripts\pip-script.py", line 11, in ? ? load_entry_point('pip==21.0.1', 'console_scripts', 'pip')()? File "c:\users\mohsohai\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\cli\main.py", line 71, in main? ? command = create_command(cmd_name, isolated=("--isolated" in cmd_args))? File "c:\users\mohsohai\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\commands\__init__.py", line 96, in create_command? ? module = importlib.import_module(module_path)? File "c:\users\mohsohai\appdata\local\programs\python\python38\lib\importlib\__init__.py", line 127, in import_module? ? return _bootstrap._gcd_import(name[level:], package, level)? File "", line 1014, in _gcd_import? File "", line 991, in _find_and_load? File "", line 975, in _find_and_load_unlocked? File "", line 671, in _load_unlocked? File "", line 783, in exec_module? File "", line 219, in _call_with_frames_removed? File "c:\users\mohsohai\appdata\local\programs\python\python38\lib\site-packages\pip\_internal\commands\install.py", line 12, in ? ? from pip._internal.cache import WheelCacheModuleNotFoundError: No module named 'pip._internal.cache'------------------------------------------------- > Note: Have included pip in Enviromnet Variables > Thank you,Sohail. > I recommend you use the pip module with Python launcher: py -m pip install pytest It just makes life easier. From DomainAdmin at DancesWithMice.info Thu Apr 1 16:50:31 2021 From: DomainAdmin at DancesWithMice.info (David L Neil) Date: Fri, 2 Apr 2021 09:50:31 +1300 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> Message-ID: Officially April-Fools Day is over (here), but... On 01/04/2021 19.25, Chris Angelico wrote: > On Thu, Apr 1, 2021 at 3:36 PM dn via Python-list > wrote: >> >> On 01/04/2021 13.54, Chris Angelico wrote: >>> Real and imaginary are the same thing, just rotated a quarter turn.... >> >> In which dimension(s)? > > Cartesian. Isn't this water you get out of the ground and then deliver using an horse-pulled vehicle? >>>> Without looking into the details/context: surely there's a more >>>> straightforward approach? >>> >>> Perhaps, but there are potentially a LOT of recipes, and I needed to >>> be able to cleanly edit those, even if the code at the top was a mess. >>> (The goal here is to map out production patterns in the game >>> "Satisfactory", for the curious. It's easy to add other things, like >>> computer manufacturing or bauxite processing, simply by adding more >>> recipes.) >>> >>> My original plan was basically pairwise tuple summing (deriving a set >>> of "oil in, water in, rubber out, fuel out" for each set of recipes, >>> where some might be zero), but it turned out that that wasn't flexible >>> enough, and it really needed more options than that. >> >> Which was where my mind was going*. Why not a dict of inputs, processes, >> and outputs**? Each dict having variable length, from None, and >> key:values assigned at declaration/init. In the case of process, the >> contained objects could be Python-functions. With "compact >> representation" (3.6+) the functions could also be relied upon to >> represent a 'production line' or pipeline of functions. > > Perhaps, but the key here is the input method. It wouldn't look nearly as clean. Not sure about that. For example, is it immediately-obvious which of "Crude", "Residue", and "Plastic" are inputs; and which outputs? >>> I already have certificates from Rutledge's Asylum and MaayaInsane's >>> (unnamed) asylum, so that seems pretty likely. >> >> Noted you on the list of lauded alumni at the latter. > > Hmm, where do you see that list? I'm curious. Appeared to be some sort of 'leader board' for the game. Recognised your handle there. Think it was https://www.twitch.tv/maayainsane. Perhaps I was looking at the same time as you logged-in? Daren't disappear down that rabbit-hole again... >> When you left the former, did they allow you to keep the t-shirt, or did >> you have to buy your own memorabilia? >> (https://mysterious.americanmcgee.com/products/rutledge-asylum-mug) > > I beg your pardon? What is this "left"? I'm still there! Actually I > pay my membership on a monthly basis, and in return, my walls are > lavishly decorated in Alice art. Whereas us lateral-thinkers don't like the feeling of being fenced-in. >> The latter's treatment list sounds remarkably like .mil training. I know >> of plenty with that t-shirt - but can't think of a one sporting a mug... >> Should you have one, kindly bring it (with appropriate contents) come >> ANZAC Day at the end of this month... > > https://streamlabs.com/maayainsane/merch/1053635 > This is what I'd bring. They're the standard mugs that I offer to > guests. Well, I would if ever I had guests, but hermitism is a > thing... Is that the same as (anti-) club-ism (cue Groucho: https://www.goodreads.com/quotes/6517787-i-wouldn-t-want-to-belong-to-a-club-that-would) After suffering the RSA's ?quaint tradition of rum-in-milk (that BEFORE Dawn Parade, and thereafter marching on a less-than flat surface) I have learned to guard against the pre-dawn cold by heading for the Hot Chocolate counter - can't say the mugs look like that though. >> Magic, you ask? Well, maybe more "sinister". We did manage to find a >> loose floor-board, but a sad life-lesson was learned, when certain ones >> (un-named*) took it upon themselves to eat all of the contraband >> secreted there. > > Uh oh. How old was the contraband? Was between 'tuck days' (when we were allowed to acquire such goodies - once?twice per week). The theory being that we would all contribute, in anticipation of some later "midnight feast") - such gyre and gimble-ing being more Jabberwock than Alice! -- Regards =dn From PythonList at DancesWithMice.info Thu Apr 1 16:54:18 2021 From: PythonList at DancesWithMice.info (dn) Date: Fri, 2 Apr 2021 09:54:18 +1300 Subject: XanaNews Statistic for comp.lang.python. 4/1/2021 5:52:47 AM In-Reply-To: References: Message-ID: <086925a7-cadd-bb19-6e1a-ce16decf45a2@DancesWithMice.info> On 02/04/2021 01.19, Chris Angelico wrote: > On Thu, Apr 1, 2021 at 10:56 PM The Doctor via Python-list > wrote: >> Top Posters >> >> Ranking Articles Name Most Used Newsreader >> ------- -------- -------------------------- -------------------- >> 1 167 TestBank store G2 >> 2 61 Vagrant G2 >> 3 54 Chris Angelico >> 4 51 students help G2 > > Ouch. I'm up there among the spambots. No, not true! We all know you are ham-ming it up*... However, after some reflection, is the bot part not true? * slang term: https://idioms.thefreedictionary.com/hamming+it+up -- Regards, =dn From rosuav at gmail.com Thu Apr 1 17:03:41 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 Apr 2021 08:03:41 +1100 Subject: XanaNews Statistic for comp.lang.python. 4/1/2021 5:52:47 AM In-Reply-To: <086925a7-cadd-bb19-6e1a-ce16decf45a2@DancesWithMice.info> References: <086925a7-cadd-bb19-6e1a-ce16decf45a2@DancesWithMice.info> Message-ID: On Fri, Apr 2, 2021 at 7:55 AM dn via Python-list wrote: > > On 02/04/2021 01.19, Chris Angelico wrote: > > On Thu, Apr 1, 2021 at 10:56 PM The Doctor via Python-list > > wrote: > >> Top Posters > >> > >> Ranking Articles Name Most Used Newsreader > >> ------- -------- -------------------------- -------------------- > >> 1 167 TestBank store G2 > >> 2 61 Vagrant G2 > >> 3 54 Chris Angelico > >> 4 51 students help G2 > > > > Ouch. I'm up there among the spambots. > > > No, not true! > We all know you are ham-ming it up*... > > However, after some reflection, is the bot part not true? > Oh yes, that's a known fact. Particularly on Twitch.tv, where I'm known for developing myself on livestream. ChrisA From rosuav at gmail.com Thu Apr 1 17:13:00 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 Apr 2021 08:13:00 +1100 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> Message-ID: On Fri, Apr 2, 2021 at 7:52 AM David L Neil via Python-list wrote: > > Officially April-Fools Day is over (here), but... This wasn't a prank post, although it was intended to give amusement rather than real education or debate or anything. So there's nothing wrong with keeping it going. :) > On 01/04/2021 19.25, Chris Angelico wrote: > > On Thu, Apr 1, 2021 at 3:36 PM dn via Python-list > > wrote: > >> > >> On 01/04/2021 13.54, Chris Angelico wrote: > >>> Real and imaginary are the same thing, just rotated a quarter turn.... > >> > >> In which dimension(s)? > > > > Cartesian. > > Isn't this water you get out of the ground and then deliver using an > horse-pulled vehicle? Yes. Also, this is the guy who said "I think not" and promptly vanished from the world. (For those not familiar, the Cartesian coordinate system or the Cartesian plane is what you'd normally use for graphing a mathematical function. You can label the axes as "x" and "y" to graph something like "y = sin(x)", or you can label them as "real" and "imaginary" and use it to depict complex numbers. Though David's response has the elegance of true *art*, if you examine the words carefully.) > > Perhaps, but the key here is the input method. It wouldn't look nearly as clean. > > Not sure about that. For example, is it immediately-obvious which of > "Crude", "Residue", and "Plastic" are inputs; and which outputs? Well, it's a simple matter of chronology. First you have crude oil, then time passes, and then you have plastic and residue. It makes sense ONLY if you think of it with a specific ordering, which implies Python 3.7 or later. > >>> I already have certificates from Rutledge's Asylum and MaayaInsane's > >>> (unnamed) asylum, so that seems pretty likely. > >> > >> Noted you on the list of lauded alumni at the latter. > > > > Hmm, where do you see that list? I'm curious. > > Appeared to be some sort of 'leader board' for the game. Recognised your > handle there. Think it was https://www.twitch.tv/maayainsane. Perhaps I > was looking at the same time as you logged-in? Daren't disappear down > that rabbit-hole again... Makes sense. I'm very active there, you'll see me chatting a good bit during her streams. I'm not sure what leaderboard you were seeing, but it's probably something involving recent financial support (she's a highly competent digital artist and absolutely deserves the support). > >> The latter's treatment list sounds remarkably like .mil training. I know > >> of plenty with that t-shirt - but can't think of a one sporting a mug... > >> Should you have one, kindly bring it (with appropriate contents) come > >> ANZAC Day at the end of this month... > > > > https://streamlabs.com/maayainsane/merch/1053635 > > This is what I'd bring. They're the standard mugs that I offer to > > guests. Well, I would if ever I had guests, but hermitism is a > > thing... > > Is that the same as (anti-) club-ism > (cue Groucho: > https://www.goodreads.com/quotes/6517787-i-wouldn-t-want-to-belong-to-a-club-that-would) > > After suffering the RSA's ?quaint tradition of rum-in-milk (that BEFORE > Dawn Parade, and thereafter marching on a less-than flat surface) I have > learned to guard against the pre-dawn cold by heading for the Hot > Chocolate counter - can't say the mugs look like that though. Hot chocolate? Ahh, now, that's the other thing I drink a lot of. I even have a dedicated mug with a Cadbury logo on it. Sadly, not easily purchasable, but this one was a gift from a family member who knows full well that I have my priorities straight. > >> Magic, you ask? Well, maybe more "sinister". We did manage to find a > >> loose floor-board, but a sad life-lesson was learned, when certain ones > >> (un-named*) took it upon themselves to eat all of the contraband > >> secreted there. > > > > Uh oh. How old was the contraband? > > Was between 'tuck days' (when we were allowed to acquire such goodies - > once?twice per week). The theory being that we would all contribute, in > anticipation of some later "midnight feast") - such gyre and gimble-ing > being more Jabberwock than Alice! Ah, I see. So you'd get some tucker, and tuck it away for later, but the whole scheme came... unstuck. ChrisA From real-not-anti-spam-address at apple-juice.co.uk Thu Apr 1 17:47:06 2021 From: real-not-anti-spam-address at apple-juice.co.uk (D.M. Procida) Date: Thu, 1 Apr 2021 22:47:06 +0100 Subject: A 35mm film camera represented in Python object References: <1p5o1as.ard2i1w91fiN%real-not-anti-spam-address@apple-juice.co.uk> Message-ID: <1p6zawo.r2kztc1b3uzsyN%real-not-anti-spam-address@apple-juice.co.uk> D.M. Procida wrote: > Hi everyone, I've created - > a representation of a Canonet G-III QL17 in Python. > > There's also documentation: . > > It's a pure Python model of the physical sub-systems of a camera and > their interactions. So far it's at a fairly high level - I haven't yet > got down to the level of individual springs and levers yet. I'm now working on the exposure system, which in the published version so far just models inputs and outputs of the system as a whole. I want to start to model its functionality by modelling the interactions of its components - the levers, cams and so on. It seems to me I have fundamentally two approaches that I could take: The first is to model the movement of each lever as a series of discrete steps (hundreds of tiny steps, to maintain accuracy). Pro: it models movement through physical positions; con: it's ugly that it breaks continuous movement into arbitrary steps. The second is not to move each lever in such detail, but to consider its interactions: given the state of each of the other parts of the system, what *would* be the outcome if something were to try to move the lever from such-and-such a position to another? Pro: it feels more elegant than the brute-force stepping of the alternative; con: it also feels like a bit of a cheat. But neither approach really captures for me the interaction of moving analog components, which in the case of this camera also have some circular logic to them - the movement of A determines that of B which determines that of C which determines that of D which finally also affects the movement of A. Any thoughts or wise ideas? Daniele From Richard at Damon-Family.org Thu Apr 1 18:10:46 2021 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 1 Apr 2021 18:10:46 -0400 Subject: A 35mm film camera represented in Python object In-Reply-To: <1p6zawo.r2kztc1b3uzsyN%real-not-anti-spam-address@apple-juice.co.uk> References: <1p5o1as.ard2i1w91fiN%real-not-anti-spam-address@apple-juice.co.uk> <1p6zawo.r2kztc1b3uzsyN%real-not-anti-spam-address@apple-juice.co.uk> Message-ID: On 4/1/21 5:47 PM, D.M. Procida wrote: > D.M. Procida wrote: > >> Hi everyone, I've created - >> a representation of a Canonet G-III QL17 in Python. >> >> There's also documentation: . >> >> It's a pure Python model of the physical sub-systems of a camera and >> their interactions. So far it's at a fairly high level - I haven't yet >> got down to the level of individual springs and levers yet. > I'm now working on the exposure system, which in the published version > so far just models inputs and outputs of the system as a whole. I want > to start to model its functionality by modelling the interactions of its > components - the levers, cams and so on. > > It seems to me I have fundamentally two approaches that I could take: > > The first is to model the movement of each lever as a series of discrete > steps (hundreds of tiny steps, to maintain accuracy). Pro: it models > movement through physical positions; con: it's ugly that it breaks > continuous movement into arbitrary steps. > > The second is not to move each lever in such detail, but to consider its > interactions: given the state of each of the other parts of the system, > what *would* be the outcome if something were to try to move the lever > from such-and-such a position to another? Pro: it feels more elegant > than the brute-force stepping of the alternative; con: it also feels > like a bit of a cheat. > > But neither approach really captures for me the interaction of moving > analog components, which in the case of this camera also have some > circular logic to them - the movement of A determines that of B which > determines that of C which determines that of D which finally also > affects the movement of A. > > Any thoughts or wise ideas? > > Daniele If you keep track of the positions as a floating point number, the precision will be more than you could actually measure it. -- Richard Damon From miked at dewhirst.com.au Thu Apr 1 18:31:11 2021 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Fri, 2 Apr 2021 09:31:11 +1100 Subject: A 35mm film camera represented in Python object In-Reply-To: <1p6zawo.r2kztc1b3uzsyN%real-not-anti-spam-address@apple-juice.co.uk> References: <1p5o1as.ard2i1w91fiN%real-not-anti-spam-address@apple-juice.co.uk> <1p6zawo.r2kztc1b3uzsyN%real-not-anti-spam-address@apple-juice.co.uk> Message-ID: On 2/04/2021 8:47 am, D.M. Procida wrote: > D.M. Procida wrote: > >> Hi everyone, I've created - >> a representation of a Canonet G-III QL17 in Python. >> >> There's also documentation: . >> >> It's a pure Python model of the physical sub-systems of a camera and >> their interactions. So far it's at a fairly high level - I haven't yet >> got down to the level of individual springs and levers yet. > I'm now working on the exposure system, which in the published version > so far just models inputs and outputs of the system as a whole. I want > to start to model its functionality by modelling the interactions of its > components - the levers, cams and so on. > > It seems to me I have fundamentally two approaches that I could take: > > The first is to model the movement of each lever as a series of discrete > steps (hundreds of tiny steps, to maintain accuracy). Pro: it models > movement through physical positions; con: it's ugly that it breaks > continuous movement into arbitrary steps. If in doubt model the real world. > > The second is not to move each lever in such detail, but to consider its > interactions: given the state of each of the other parts of the system, > what *would* be the outcome if something were to try to move the lever > from such-and-such a position to another? Pro: it feels more elegant > than the brute-force stepping of the alternative; con: it also feels > like a bit of a cheat. Usually taking shortcuts means losing information. You can only drop intermediate data which doesn't trigger other events. Go with your instinct > > But neither approach really captures for me the interaction of moving > analog components, which in the case of this camera also have some > circular logic to them - the movement of A determines that of B which > determines that of C which determines that of D which finally also > affects the movement of A. Connect things which are connected and recalculate A in passive mode. > > Any thoughts or wise ideas? May the force be with you > > Daniele -- Signed email is an absolute defence against phishing. This email has been signed with my private key. If you import my public key you can automatically decrypt my signature and be sure it came from me. Just ask and I'll send it to you. Your email software can handle signing. -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 495 bytes Desc: OpenPGP digital signature URL: From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Apr 1 18:41:56 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 1 Apr 2021 15:41:56 -0700 Subject: A 35mm film camera represented in Python object In-Reply-To: References: <1p5o1as.ard2i1w91fiN%real-not-anti-spam-address@apple-juice.co.uk> <1p6zawo.r2kztc1b3uzsyN%real-not-anti-spam-address@apple-juice.co.uk> Message-ID: On 2021-04-01 at 18:10:46 -0400, Richard Damon wrote: > On 4/1/21 5:47 PM, D.M. Procida wrote: > > D.M. Procida wrote: > > > >> Hi everyone, I've created - > >> a representation of a Canonet G-III QL17 in Python. > >> > >> There's also documentation: . > >> > >> It's a pure Python model of the physical sub-systems of a camera and > >> their interactions. So far it's at a fairly high level - I haven't yet > >> got down to the level of individual springs and levers yet. > > I'm now working on the exposure system, which in the published version > > so far just models inputs and outputs of the system as a whole. I want > > to start to model its functionality by modelling the interactions of its > > components - the levers, cams and so on. > > > > It seems to me I have fundamentally two approaches that I could take: > > > > The first is to model the movement of each lever as a series of discrete > > steps (hundreds of tiny steps, to maintain accuracy). Pro: it models > > movement through physical positions; con: it's ugly that it breaks > > continuous movement into arbitrary steps. > > > > The second is not to move each lever in such detail, but to consider its > > interactions: given the state of each of the other parts of the system, > > what *would* be the outcome if something were to try to move the lever > > from such-and-such a position to another? Pro: it feels more elegant > > than the brute-force stepping of the alternative; con: it also feels > > like a bit of a cheat. > > > > But neither approach really captures for me the interaction of moving > > analog components, which in the case of this camera also have some > > circular logic to them - the movement of A determines that of B which > > determines that of C which determines that of D which finally also > > affects the movement of A. > > > > Any thoughts or wise ideas? > > > > Daniele > > If you keep track of the positions as a floating point number, the > precision will be more than you could actually measure it. I won't disagree with Richard, although I will give you a general warning about floating point rounding issues: if you do, in fact, end up with your first solution and lots and lots (millions? billions? more?) of discrete calculations, be aware that what looks like a lot of precision in the beginning may not be all that precise (or accurate) in the end. Also, doesn't the overall motion of the camera as a whole also depend on external factors, such as whether/how it's mounted or handheld, the nature of the "ground" (e.g., soft wet sand vs. hard concrete vs. someone standing on a boat in the water), an experienced photographer "squeezing" the shutter release vs. a newbie "pressing the button"? I can think of plenty of variables; I guess it depends on what you're trying to model and how accurate you intend to be (or not to be). From rosuav at gmail.com Thu Apr 1 18:55:37 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 Apr 2021 09:55:37 +1100 Subject: A 35mm film camera represented in Python object In-Reply-To: References: <1p5o1as.ard2i1w91fiN%real-not-anti-spam-address@apple-juice.co.uk> <1p6zawo.r2kztc1b3uzsyN%real-not-anti-spam-address@apple-juice.co.uk> Message-ID: On Fri, Apr 2, 2021 at 9:43 AM <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > On 2021-04-01 at 18:10:46 -0400, > Richard Damon wrote: > > > On 4/1/21 5:47 PM, D.M. Procida wrote: > > > D.M. Procida wrote: > > > > > >> Hi everyone, I've created - > > >> a representation of a Canonet G-III QL17 in Python. > > >> > > >> There's also documentation: . > > >> > > >> It's a pure Python model of the physical sub-systems of a camera and > > >> their interactions. So far it's at a fairly high level - I haven't yet > > >> got down to the level of individual springs and levers yet. > > > I'm now working on the exposure system, which in the published version > > > so far just models inputs and outputs of the system as a whole. I want > > > to start to model its functionality by modelling the interactions of its > > > components - the levers, cams and so on. > > > > > > It seems to me I have fundamentally two approaches that I could take: > > > > > > The first is to model the movement of each lever as a series of discrete > > > steps (hundreds of tiny steps, to maintain accuracy). Pro: it models > > > movement through physical positions; con: it's ugly that it breaks > > > continuous movement into arbitrary steps. > > > > > > The second is not to move each lever in such detail, but to consider its > > > interactions: given the state of each of the other parts of the system, > > > what *would* be the outcome if something were to try to move the lever > > > from such-and-such a position to another? Pro: it feels more elegant > > > than the brute-force stepping of the alternative; con: it also feels > > > like a bit of a cheat. > > > > > > But neither approach really captures for me the interaction of moving > > > analog components, which in the case of this camera also have some > > > circular logic to them - the movement of A determines that of B which > > > determines that of C which determines that of D which finally also > > > affects the movement of A. > > > > > > Any thoughts or wise ideas? > > > > > > Daniele > > > > If you keep track of the positions as a floating point number, the > > precision will be more than you could actually measure it. > > I won't disagree with Richard, although I will give you a general > warning about floating point rounding issues: if you do, in fact, end > up with your first solution and lots and lots (millions? billions? > more?) of discrete calculations, be aware that what looks like a lot of > precision in the beginning may not be all that precise (or accurate) in > the end. Inaccuracy introduced by FP rounding is likely to be dwarfed by inaccuracy of measurement. 53-bit precision is pretty accurate compared to most real-world measurement. ChrisA From arj.python at gmail.com Thu Apr 1 18:55:49 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 2 Apr 2021 02:55:49 +0400 Subject: XanaNews Statistic for comp.lang.python. 4/1/2021 5:52:47 AM In-Reply-To: References: Message-ID: So, is that mail spam or ...? From Richard at Damon-Family.org Thu Apr 1 19:01:55 2021 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 1 Apr 2021 19:01:55 -0400 Subject: A 35mm film camera represented in Python object In-Reply-To: References: <1p5o1as.ard2i1w91fiN%real-not-anti-spam-address@apple-juice.co.uk> <1p6zawo.r2kztc1b3uzsyN%real-not-anti-spam-address@apple-juice.co.uk> Message-ID: <593ea0ff-d84f-0605-bef1-5e68664b88a8@Damon-Family.org> On 4/1/21 6:41 PM, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > On 2021-04-01 at 18:10:46 -0400, > Richard Damon wrote: > >> On 4/1/21 5:47 PM, D.M. Procida wrote: >>> D.M. Procida wrote: >>> >>>> Hi everyone, I've created - >>>> a representation of a Canonet G-III QL17 in Python. >>>> >>>> There's also documentation: . >>>> >>>> It's a pure Python model of the physical sub-systems of a camera and >>>> their interactions. So far it's at a fairly high level - I haven't yet >>>> got down to the level of individual springs and levers yet. >>> I'm now working on the exposure system, which in the published version >>> so far just models inputs and outputs of the system as a whole. I want >>> to start to model its functionality by modelling the interactions of its >>> components - the levers, cams and so on. >>> >>> It seems to me I have fundamentally two approaches that I could take: >>> >>> The first is to model the movement of each lever as a series of discrete >>> steps (hundreds of tiny steps, to maintain accuracy). Pro: it models >>> movement through physical positions; con: it's ugly that it breaks >>> continuous movement into arbitrary steps. >>> >>> The second is not to move each lever in such detail, but to consider its >>> interactions: given the state of each of the other parts of the system, >>> what *would* be the outcome if something were to try to move the lever >>> from such-and-such a position to another? Pro: it feels more elegant >>> than the brute-force stepping of the alternative; con: it also feels >>> like a bit of a cheat. >>> >>> But neither approach really captures for me the interaction of moving >>> analog components, which in the case of this camera also have some >>> circular logic to them - the movement of A determines that of B which >>> determines that of C which determines that of D which finally also >>> affects the movement of A. >>> >>> Any thoughts or wise ideas? >>> >>> Daniele >> If you keep track of the positions as a floating point number, the >> precision will be more than you could actually measure it. > I won't disagree with Richard, although I will give you a general > warning about floating point rounding issues: if you do, in fact, end > up with your first solution and lots and lots (millions? billions? > more?) of discrete calculations, be aware that what looks like a lot of > precision in the beginning may not be all that precise (or accurate) in > the end. > > Also, doesn't the overall motion of the camera as a whole also depend on > external factors, such as whether/how it's mounted or handheld, the > nature of the "ground" (e.g., soft wet sand vs. hard concrete > vs. someone standing on a boat in the water), an experienced > photographer "squeezing" the shutter release vs. a newbie "pressing the > button"? I can think of plenty of variables; I guess it depends on what > you're trying to model and how accurate you intend to be (or not to be). Actually, I would contend that due to all the factors that you can't take into account accurately makes the use of floating point more applicable. Yes, you need to realize that just because the value has many digits, you KNOW that is only an approximation, and you process accordingly, knowing you just has an approximation. The real question comes, what is the purpose of the simulation? You can NEVER simulate everything, and some parts of 'simulating' requires actual hardware to interact with. Sometimes the real thing is the best simulation available. -- Richard Damon From * at eli.users.panix.com Thu Apr 1 19:19:10 2021 From: * at eli.users.panix.com (Eli the Bearded) Date: Thu, 1 Apr 2021 23:19:10 +0000 (UTC) Subject: A 35mm film camera represented in Python object References: <1p5o1as.ard2i1w91fiN%real-not-anti-spam-address@apple-juice.co.uk> <593ea0ff-d84f-0605-bef1-5e68664b88a8@Damon-Family.org> Message-ID: In comp.lang.python, Richard Damon wrote: > On 4/1/21 6:41 PM, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: >> Richard Damon wrote: >>> If you keep track of the positions as a floating point number, the >>> precision will be more than you could actually measure it. >> I won't disagree with Richard, although I will give you a general >> warning about floating point rounding issues: if you do, in fact, end >> up with your first solution and lots and lots (millions? billions? >> more?) of discrete calculations, be aware that what looks like a lot of >> precision in the beginning may not be all that precise (or accurate) in >> the end. I'm having a hard time figuring where the floating point rounding issues enter in. My reading is that instead of N discrete steps (level 12 is 1% moved, lever 12 is 2% moved, lever 12 is 3% moved and makes contact to cam 3, lever 12 is 4% moved and cam 3 is 5% moved; or what not) using floating points lever 12 could move 0.0 to > 1, and cam 3 start moving at lever 12 => 0.04. >> Also, doesn't the overall motion of the camera as a whole also depend on >> external factors, such as whether/how it's mounted or handheld, the >> nature of the "ground" (e.g., soft wet sand vs. hard concrete >> vs. someone standing on a boat in the water), an experienced >> photographer "squeezing" the shutter release vs. a newbie "pressing the >> button"? I can think of plenty of variables; I guess it depends on what >> you're trying to model and how accurate you intend to be (or not to be). I suspect very little of the motion of parts *inside* the camera see meaningful changes from that. The motion of the camera relative to the scene is meaningful for how motion blurred a shot will be. But the springs and levers that move as the shutter release button is pushed will be basically only moving relative to the camera, and not much changed by tripod or handheld. > Actually, I would contend that due to all the factors that you can't > take into account accurately makes the use of floating point more > applicable. Yes, you need to realize that just because the value has > many digits, you KNOW that is only an approximation, and you process > accordingly, knowing you just has an approximation. All of the parts of the camera were built with some engineering tolerance. Using a precision in code that exceeds that tolerance fails to accurately model the camera. > The real question comes, what is the purpose of the simulation? You can > NEVER simulate everything, and some parts of 'simulating' requires > actual hardware to interact with. Sometimes the real thing is the best > simulation available. The purpose was stated in the original post: model a particular camera in software from the point of view of someone who has done repair work. If lever 12 is bent, and only touches cam 3 after 15% (or => 0.15) motion that changes the way the camera works. I believe those sorts of things are meant to be visible in this model. Elijah ------ would use floating point, or fixed point as if floating From PythonList at DancesWithMice.info Thu Apr 1 19:42:25 2021 From: PythonList at DancesWithMice.info (dn) Date: Fri, 2 Apr 2021 12:42:25 +1300 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> Message-ID: <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> On 02/04/2021 10.13, Chris Angelico wrote: > On Fri, Apr 2, 2021 at 7:52 AM David L Neil via Python-list > wrote: >> Officially April-Fools Day is over (here), but... > This wasn't a prank post, although it was intended to give amusement > rather than real education or debate or anything. So there's nothing > wrong with keeping it going. :) The Python 'education' is offered at a lower density than the explanations of slang in variants of ?the? English-language... >>> Cartesian. >> >> Isn't this water you get out of the ground and then deliver using an >> horse-pulled vehicle? > > Yes. Also, this is the guy who said "I think not" and promptly > vanished from the world. > > (For those not familiar, the Cartesian coordinate system or the > Cartesian plane is what you'd normally use for graphing a mathematical > function. You can label the axes as "x" and "y" to graph something > like "y = sin(x)", or you can label them as "real" and "imaginary" and > use it to depict complex numbers. Though David's response has the > elegance of true *art*, if you examine the words carefully.) The Cartesian coordinate system, as used in geometry, mapping, etc, was named after the French philosopher Ren? Descartes. Possibly Descartes' most famous quotation is "je pense, donc je suis", which some reason (best known to others) we were taught in Latin, as "cogito, ergo sum". Most will be familiar with the English translation, "I think, therefore I am". A[n] horse-drawn (pulled) vehicle might be a cART, and cARTESIAN water comes from an underground supply or aquifer. Whilst we are 'messing around' with [human] languages, my French vocabulary/translation capability has been extended by discovering that "artesian" is "artois". Artois was a kingdom/principality that is part of modern France, 'up' by the Belgian border. A man with French heritage, but purported to be Dutch, built a brewery in Belgium. Hence today one of that country's most famous exports is "Stella Artois" beer ("stella" meaning "star"!). (but this isn't teaching me much Python - or OpenCV: this weekend's objective...) >>> Perhaps, but the key here is the input method. It wouldn't look nearly as clean. >> >> Not sure about that. For example, is it immediately-obvious which of >> "Crude", "Residue", and "Plastic" are inputs; and which outputs? > > Well, it's a simple matter of chronology. First you have crude oil, > then time passes, and then you have plastic and residue. It makes > sense ONLY if you think of it with a specific ordering, which implies > Python 3.7 or later. My anxiety over 'ordering' comes to the fore: if there are multiple inputs and/or multiple outputs, how can one tell where the former series ends and the latter begins? "Explicit" cf "implicit"? > Hot chocolate? Ahh, now, that's the other thing I drink a lot of. I > even have a dedicated mug with a Cadbury logo on it. Sadly, not easily > purchasable, but this one was a gift from a family member who knows > full well that I have my priorities straight. Cadbury do not make chocolate! Neither do Hershey, for that matter! There, now that I've upset most of the English-speaking world... PS they use the milk to 'water down' the chocolate! It's much like buying Easter Eggs: the density of chocolate is much lower for the price. View https://www.whittakers.co.nz/en_NZ/products/72-dark-ghana/block-250g before questioning my curmugeonly credentials! >>>> Magic, you ask? Well, maybe more "sinister". We did manage to find a >>>> loose floor-board, but a sad life-lesson was learned, when certain ones >>>> (un-named*) took it upon themselves to eat all of the contraband >>>> secreted there. >>> >>> Uh oh. How old was the contraband? >> >> Was between 'tuck days' (when we were allowed to acquire such goodies - >> once?twice per week). The theory being that we would all contribute, in >> anticipation of some later "midnight feast") - such gyre and gimble-ing >> being more Jabberwock than Alice! > > Ah, I see. So you'd get some tucker, and tuck it away for later, but > the whole scheme came... unstuck. Time for another language lesson? "tucker" is Australian slang for food. Hence "tucker-bag", the 'waltzer's' equivalent of a lunch-box or tiffin tin. Back when Australia was re-considering their choice for National Anthem, I was in full expectation (and great hope) that they would select "Waltzing Matilda". Sadly, they did not (instead: "Advance Australia Fair"). However, within one poem/song it is possible to learn a considerable number of (100-year old) Australian slang terms... Whilst visiting Freemantle (Western Australia), as a guest of Royal Australian Navy Vets, we were marched-away from the Remembrance Day Parade to the tune of Waltzing Matilda - something of an highlight (for me at least)! Contrarily "tuck" in (old) English slang represented "sweets" (or "lollies", "candy", etc, in other forms of English). Some say it had wider application, but I don't recall it ever being used more generally as "food" or "meal". That said, "tuck in" is certainly slang for 'start eating [your meal]'. However, the phrase "best bib and tucker" means "Sunday best" clothing or 'dressing for dinner. Those who are still following-along in the hope of a Python reference may like to contemplate the similar implications carried by "The Monty Python Matching Tie and Handkerchief". >From "tuck" we get "tuck shop" (which Wikipedia tells us is indeed closely-related to schools and confectionery (https://en.wikipedia.org/wiki/Tuck_shop)!). With that understanding(?) or allusion you may feel equipped to realise the specialty nature of the "cheese shop", and thus the Monty-Pythonesque previous name for PyPi! Toodle-pip! (https://en.wiktionary.org/wiki/toodle_pip) -- Regards, =dn From shanmukhsrinivas973 at gmail.com Fri Apr 2 04:40:18 2021 From: shanmukhsrinivas973 at gmail.com (=?utf-8?Q?=E1=97=B7=E1=91=8C=E1=91=8E=E1=91=8EY?=) Date: Fri, 2 Apr 2021 14:10:18 +0530 Subject: not able to download PyAudio Message-ID: Hello everyone I am not able to download PyAudio. I tried by typing pip install in PyAudio in cmd but it show's no compatible version availbale. What should I do? . ********Y From egon at frerich.eu Fri Apr 2 05:16:50 2021 From: egon at frerich.eu (Egon Frerich) Date: Fri, 2 Apr 2021 11:16:50 +0200 Subject: how to separate the strings in a string Message-ID: <655159b3-c091-5e6e-c1bc-9b0b7ef48577@frerich.eu> I have a string like '"ab,c" , def' and need to separate it into "ab,c" and "def". split separates at the first ',': >>> bl '"a,bc", def' >>> bl.split(',') ['"a', 'bc"', ' def'] Egon -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From Karsten.Hilbert at gmx.net Fri Apr 2 05:51:56 2021 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Fri, 2 Apr 2021 11:51:56 +0200 Subject: Aw: not able to download PyAudio In-Reply-To: References: Message-ID: The same as with speech recognition. Research. Karsten > Gesendet: Freitag, 02. April 2021 um 10:40 Uhr > Von: "????Y" > An: "Igor Korot" > Cc: "python-list at python.org" > Betreff: not able to download PyAudio > > Hello everyone > I am not able to download PyAudio. I tried by typing pip install in > PyAudio in cmd but it show's no compatible version availbale. What should > I do? . > > > > ********Y > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From bschollnick at schollnick.net Fri Apr 2 06:09:28 2021 From: bschollnick at schollnick.net (Benjamin Schollnick) Date: Fri, 2 Apr 2021 06:09:28 -0400 Subject: not able to download PyAudio In-Reply-To: References: Message-ID: <0812515C-F0EB-4BA0-B380-20E2E54EC8DD@schollnick.net> > On Apr 2, 2021, at 4:40 AM, ????Y wrote: > > Hello everyone > I am not able to download PyAudio. I tried by typing pip install in > PyAudio in cmd but it show's no compatible version availbale. What should > I do? . There seems to be some confusion, which I can understand? ?No compatible version?, simply means that Pip was unable to find a version of for your version of python. Please note, that does not mean that a version *EXISTS*, just that it could not find a version for your platform. So go to https://pypi.org and do a search. - Benjamin From __peter__ at web.de Fri Apr 2 06:38:37 2021 From: __peter__ at web.de (Peter Otten) Date: Fri, 2 Apr 2021 12:38:37 +0200 Subject: how to separate the strings in a string In-Reply-To: <655159b3-c091-5e6e-c1bc-9b0b7ef48577@frerich.eu> References: <655159b3-c091-5e6e-c1bc-9b0b7ef48577@frerich.eu> Message-ID: <5e5c9f38-e22b-d7b4-e2d6-162cb61d102e@web.de> On 02/04/2021 11:16, Egon Frerich wrote: > I have a string like > > '"ab,c" , def' > > and need to separate it into > > "ab,c" and "def". > > split separates at the first ',': > >>>> bl > '"a,bc", def' >>>> bl.split(',') > ['"a', 'bc"', ' def'] > The initial string looks like it's close enough to the CSV format. Unfortunately Python's csv module operates on files, not strings -- to use it you have to wrap the string into a stream: >>> import csv >>> import io >>> next(csv.reader(io.StringIO('"ab,c" , def'))) ['ab,c ', ' def'] Apply str.strip() on every part to remove leading and trailing whitespace: >>> def mysplit(s): return [part.strip() for part in next(csv.reader(io.StringIO(s)))] >>> mysplit('"ab,c" , def') ['ab,c', 'def'] From __peter__ at web.de Fri Apr 2 06:38:37 2021 From: __peter__ at web.de (Peter Otten) Date: Fri, 2 Apr 2021 12:38:37 +0200 Subject: how to separate the strings in a string In-Reply-To: <655159b3-c091-5e6e-c1bc-9b0b7ef48577@frerich.eu> References: <655159b3-c091-5e6e-c1bc-9b0b7ef48577@frerich.eu> Message-ID: <5e5c9f38-e22b-d7b4-e2d6-162cb61d102e@web.de> On 02/04/2021 11:16, Egon Frerich wrote: > I have a string like > > '"ab,c" , def' > > and need to separate it into > > "ab,c" and "def". > > split separates at the first ',': > >>>> bl > '"a,bc", def' >>>> bl.split(',') > ['"a', 'bc"', ' def'] > The initial string looks like it's close enough to the CSV format. Unfortunately Python's csv module operates on files, not strings -- to use it you have to wrap the string into a stream: >>> import csv >>> import io >>> next(csv.reader(io.StringIO('"ab,c" , def'))) ['ab,c ', ' def'] Apply str.strip() on every part to remove leading and trailing whitespace: >>> def mysplit(s): return [part.strip() for part in next(csv.reader(io.StringIO(s)))] >>> mysplit('"ab,c" , def') ['ab,c', 'def'] From __peter__ at web.de Fri Apr 2 07:26:50 2021 From: __peter__ at web.de (Peter Otten) Date: Fri, 2 Apr 2021 13:26:50 +0200 Subject: how to separate the strings in a string In-Reply-To: <5e5c9f38-e22b-d7b4-e2d6-162cb61d102e@web.de> References: <655159b3-c091-5e6e-c1bc-9b0b7ef48577@frerich.eu> <5e5c9f38-e22b-d7b4-e2d6-162cb61d102e@web.de> Message-ID: On 02/04/2021 12:38, Peter Otten wrote: > On 02/04/2021 11:16, Egon Frerich wrote: >> I have a string like >> >> '"ab,c" , def' >> >> and need to separate it into >> >> "ab,c" and "def". >> >> split separates at the first ',': >> >>>>> bl >> '"a,bc", def' >>>>> bl.split(',') >> ['"a', 'bc"', ' def'] >> > > The initial string looks like it's close enough to the CSV format. > Unfortunately Python's csv module operates on files, not strings -- to > use it you have to wrap the string into a stream: > >>>> import csv >>>> import io >>>> next(csv.reader(io.StringIO('"ab,c" , def'))) > ['ab,c ', ' def'] > > > Apply str.strip() on every part to remove leading and trailing whitespace: > > >>>> def mysplit(s): > ????return [part.strip() for part in next(csv.reader(io.StringIO(s)))] > >>>> mysplit('"ab,c" , def') > ['ab,c', 'def'] > I forgot that the reader() accepts arbitrary iterables. Instead of io.StringIO(s) you can just write [s]. From __peter__ at web.de Fri Apr 2 07:26:50 2021 From: __peter__ at web.de (Peter Otten) Date: Fri, 2 Apr 2021 13:26:50 +0200 Subject: how to separate the strings in a string In-Reply-To: <5e5c9f38-e22b-d7b4-e2d6-162cb61d102e@web.de> References: <655159b3-c091-5e6e-c1bc-9b0b7ef48577@frerich.eu> <5e5c9f38-e22b-d7b4-e2d6-162cb61d102e@web.de> Message-ID: On 02/04/2021 12:38, Peter Otten wrote: > On 02/04/2021 11:16, Egon Frerich wrote: >> I have a string like >> >> '"ab,c" , def' >> >> and need to separate it into >> >> "ab,c" and "def". >> >> split separates at the first ',': >> >>>>> bl >> '"a,bc", def' >>>>> bl.split(',') >> ['"a', 'bc"', ' def'] >> > > The initial string looks like it's close enough to the CSV format. > Unfortunately Python's csv module operates on files, not strings -- to > use it you have to wrap the string into a stream: > >>>> import csv >>>> import io >>>> next(csv.reader(io.StringIO('"ab,c" , def'))) > ['ab,c ', ' def'] > > > Apply str.strip() on every part to remove leading and trailing whitespace: > > >>>> def mysplit(s): > ????return [part.strip() for part in next(csv.reader(io.StringIO(s)))] > >>>> mysplit('"ab,c" , def') > ['ab,c', 'def'] > I forgot that the reader() accepts arbitrary iterables. Instead of io.StringIO(s) you can just write [s]. From zen.supagood at gmail.com Fri Apr 2 08:32:29 2021 From: zen.supagood at gmail.com (Alexey) Date: Fri, 2 Apr 2021 05:32:29 -0700 (PDT) Subject: memory consumption In-Reply-To: References: <057b4084-488b-32ce-6c97-c74043fa1426@net153.net> <7c09728f-2a39-4e3d-ba5f-cc417cb67e9dn@googlegroups.com> Message-ID: <4c21d67c-0e83-4fc7-aa94-2e09cea4675cn@googlegroups.com> > I had the (mis)pleasure of dealing with a multi-terabyte postgresql > instance many years ago and figuring out why random scripts were eating > up system memory became quite common. > > All of our "ETL" scripts were either written in Perl, Java, or Python > but the results were always the same, if a process grew to using 1gb of > memory (as your case), then it never "released" it back to the OS. What > this basically means is that your script at one time did in fact > use/need 1GB of memory. That becomes the "high watermark" and in most > cases usage will stay at that level. And if you think about it, it makes > sense. Your python program went through the trouble of requesting memory > space from the OS, it makes no sense for it to give it back to the OS as > if it needed 1GB in the past, it will probably need 1GB in the future so > you will just waste time with syscalls. Even the glibc docs state > calling free() does not necessarily mean that the OS will allocate the > "freed" memory back to the global memory space. > > There are basically two things you can try. First, try working in > smaller batch sizes. 10,000 is a lot, try 100. Second, as you hinted, > try moving the work to a separate process. The simple way to do this > would be to move away from modules that use threads and instead use > something that creates child processes with fork(). Thank you! Decided to use separate process, because despite some improvements and positive effects when it runs within Celery in production environment there are still some significant overheads. Another problem occurred with "Using Connection Pools with Multiprocessing or os.fork()" but I figured it out with 'Engine.dispose()' and and 'pool_pre_ping'. Solutions can be found in official documentation for SQLAlchemy. From rosuav at gmail.com Thu Apr 1 20:00:10 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 2 Apr 2021 11:00:10 +1100 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> Message-ID: On Fri, Apr 2, 2021 at 10:43 AM dn via Python-list wrote: > > On 02/04/2021 10.13, Chris Angelico wrote: > > Well, it's a simple matter of chronology. First you have crude oil, > > then time passes, and then you have plastic and residue. It makes > > sense ONLY if you think of it with a specific ordering, which implies > > Python 3.7 or later. > > My anxiety over 'ordering' comes to the fore: if there are multiple > inputs and/or multiple outputs, how can one tell where the former series > ends and the latter begins? > > "Explicit" cf "implicit"? The exact same way. Before time passes, you have all of the inputs; after time passes, you have all of the outputs. (The way the game goes, all inputs are consumed simultaneously and all outputs produced simultaneously, so there's no chronological distinctions between them.) > > Hot chocolate? Ahh, now, that's the other thing I drink a lot of. I > > even have a dedicated mug with a Cadbury logo on it. Sadly, not easily > > purchasable, but this one was a gift from a family member who knows > > full well that I have my priorities straight. > > Cadbury do not make chocolate! > Neither do Hershey, for that matter! > There, now that I've upset most of the English-speaking world... > > PS they use the milk to 'water down' the chocolate! It's much like > buying Easter Eggs: the density of chocolate is much lower for the price. Chocolate comes in tiers. 1: Top tier chocolates - fine chocolates - are made by true artisans, and are generally purchased in smaller quantities due to pricing. (Although I did once buy something like 50kg of Lindor balls. That was a gooood day.) 2: Everyday chocolate. Mass-produced, so it's lower quality but far lower in price. Sure, it's not as amazing as eating Guylian or Godiva, but you can eat a block of Cadbury every day and still be within budget. 3: Cooking chocolate. Comes cheaper than typical block chocolate, is usually firmer, and takes more effort to make good use of, but you can take a potato peeler to it and put chocolate shavings on your Pavlova, which doesn't really work as well with a block of Dairy Milk. 4: Cheap chocolate. Easter eggs, bulk stuff, the sorts of things you throw at children to keep them happy. Sometimes has nostalgia value, but it's low-grade stuff. Some of it isn't too bad, but you end up paying MORE for it than you would for tier two chocolate, since it's usually packaged up far too much. Also, some of it is downright disgusting. I won't name names, but one time I had access to a bulk load of white chocolate (and yes, you could say that white chocolate isn't chocolate to start with, but some of it is actually good), and it tasted like milk powder. Why people pay so much for low-grade chocolate wrapped up in fiddly foil covers, I don't know. > View > https://www.whittakers.co.nz/en_NZ/products/72-dark-ghana/block-250g > before questioning my curmugeonly credentials! Oh yes, that's definitely one of the good brands. By "credentials", do you mean that you have some connection with the company? If not, that's fine, but it would certainly be notable if you do! ChrisA From mikedianeterry at gmail.com Thu Apr 1 20:40:09 2021 From: mikedianeterry at gmail.com (mikedianeterry at gmail.com) Date: Thu, 1 Apr 2021 17:40:09 -0700 Subject: all versions of python fail to indent after conditional statement Message-ID: <1B8C9520-18F9-4EAD-9BD5-ACDA2BA23E71@hxcore.ol> The following snap shot of system prompt illustrates my problem. I have tried 3.8, 3.92 and 3.10 with the same result. When I run in the window interface it doesn't even display one row of ... but does print if I hit return twice. I'm new to Python and was excited about learning it but am becoming very frustrated over a bug in such a simple conditional statement - please help as I would really like to master Python. Regards, Michael Terry Microsoft Windows [Version 10.0.19041.867] (c) 2020 Microsoft Corporation. All rights reserved. C:\WINDOWS\system32>py Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:18:16) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> dog_has_fleas=True >>> if dog_has_fleas: ... print('too bad') File "", line 2 print('too bad') ^ IndentationError: expected an indented block >>> Microsoft Windows [Version 10.0.19041.867] Sent from [1]Mail for Windows 10 References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From alan.gauld at yahoo.co.uk Fri Apr 2 04:32:21 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 2 Apr 2021 09:32:21 +0100 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> Message-ID: On 02/04/2021 00:42, dn via Python-list wrote: > Contrarily "tuck" in (old) English slang represented "sweets" (or Not that old. We still use it occasionally today. And we certainly had a "tuck shop" at school. It was where you bought lunch if not eating in the refectory. ie. sandwiches, crisps, pop etc. But its main sales were sweets including chocolate bars (bringing us back to Cadbury :-) Unusually, our tuck shop was run by the student body. The school prefects were the operating committee and responsible for finding volunteers to staff it and order supplies and bank the proceeds 9with the school secretary) -- 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 tjreedy at udel.edu Fri Apr 2 08:09:29 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 2 Apr 2021 08:09:29 -0400 Subject: not able to download PyAudio In-Reply-To: <0812515C-F0EB-4BA0-B380-20E2E54EC8DD@schollnick.net> References: <0812515C-F0EB-4BA0-B380-20E2E54EC8DD@schollnick.net> Message-ID: On 4/2/2021 6:09 AM, Benjamin Schollnick wrote: > >> On Apr 2, 2021, at 4:40 AM, ????Y wrote: >> >> Hello everyone >> I am not able to download PyAudio. I tried by typing pip install in >> PyAudio in cmd but it show's no compatible version availbale. What should >> I do? . > > There seems to be some confusion, which I can understand? > > ?No compatible version?, simply means that Pip was unable to find a version of for your version of python. > > Please note, that does not mean that a version *EXISTS*, just that it could not find a version for your platform. > > So go to https://pypi.org and do a search. https://pypi.org/project/PyAudio/#files shows that the latest version on pypi is for 3.6, uploaded 4 years ago. https://www.lfd.uci.edu/~gohlke/pythonlibs/ has binaries for 3.7-9, but you have to download manually to your machine using the instructions at the top of the page. -- Terry Jan Reedy From python at mrabarnett.plus.com Fri Apr 2 11:41:24 2021 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 2 Apr 2021 16:41:24 +0100 Subject: all versions of python fail to indent after conditional statement In-Reply-To: <1B8C9520-18F9-4EAD-9BD5-ACDA2BA23E71@hxcore.ol> References: <1B8C9520-18F9-4EAD-9BD5-ACDA2BA23E71@hxcore.ol> Message-ID: On 2021-04-02 01:40, mikedianeterry at gmail.com wrote: > > > The following snap shot of system prompt illustrates my problem. I have > tried 3.8, 3.92 and 3.10 with the same result. When I run in the window > interface it doesn't even display one row of ... but does print if I hit > return twice. I'm new to Python and was excited about learning it but am > becoming very frustrated over a bug in such a simple conditional statement > - please help as I would really like to master Python. > > Regards, > > Michael Terry > > > > Microsoft Windows [Version 10.0.19041.867] > > (c) 2020 Microsoft Corporation. All rights reserved. > > C:\WINDOWS\system32>py > > > > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:18:16) [MSC v.1928 64 > bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for > more information. > > > > >>> dog_has_fleas=True > > >>> if dog_has_fleas: > > ... print('too bad') > > File "", line 2 > > print('too bad') > > ^ > > IndentationError: expected an indented block > It said that it expected an indented block. You didn't indent the block. Python uses indentation, but the Python prompt doesn't indent automatically, you have to do that yourself. From pfeiffer at cs.nmsu.edu Fri Apr 2 11:42:01 2021 From: pfeiffer at cs.nmsu.edu (Joe Pfeiffer) Date: Fri, 02 Apr 2021 09:42:01 -0600 Subject: all versions of python fail to indent after conditional statement References: <1B8C9520-18F9-4EAD-9BD5-ACDA2BA23E71@hxcore.ol> Message-ID: <1bczvczoae.fsf@pfeifferfamily.net> It's not a bug, it's a design choice you are disagreeing with: managing indentation is your job, not the interpreter's. For anything other than an absolutely trivial three-line script, I write in an editor that does a good job helping me manage indentation (in my case, emacs in Python mode). writes: > The following snap shot of system prompt illustrates my problem. I have > tried 3.8, 3.92 and 3.10 with the same result. When I run in the window > interface it doesn't even display one row of ... but does print if I hit > return twice. I'm new to Python and was excited about learning it but am > becoming very frustrated over a bug in such a simple conditional statement > - please help as I would really like to master Python. > > Regards, > > Michael Terry > > > > Microsoft Windows [Version 10.0.19041.867] > > (c) 2020 Microsoft Corporation. All rights reserved. > > C:\WINDOWS\system32>py > > > > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:18:16) [MSC v.1928 64 > bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for > more information. > > > > >>> dog_has_fleas=True > > >>> if dog_has_fleas: > > ... print('too bad') > > File "", line 2 > > print('too bad') > > ^ > > IndentationError: expected an indented block > > >>> Microsoft Windows [Version 10.0.19041.867] > > > > > > Sent from [1]Mail for Windows 10 > > > > References > > Visible links > 1. https://go.microsoft.com/fwlink/?LinkId=550986 From mats at wichmann.us Fri Apr 2 12:16:27 2021 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 2 Apr 2021 10:16:27 -0600 Subject: all versions of python fail to indent after conditional statement In-Reply-To: <1bczvczoae.fsf@pfeifferfamily.net> References: <1B8C9520-18F9-4EAD-9BD5-ACDA2BA23E71@hxcore.ol> <1bczvczoae.fsf@pfeifferfamily.net> Message-ID: <70943a36-74a1-b601-acc9-d346baec0c95@wichmann.us> On 4/2/21 9:42 AM, Joe Pfeiffer wrote: > It's not a bug, it's a design choice you are disagreeing with: managing > indentation is your job, not the interpreter's. For anything other than > an absolutely trivial three-line script, I write in an editor that does > a good job helping me manage indentation (in my case, emacs in Python > mode). The Python interactive interpreter is very useful for doing quick experiments in, but for any kind of serious work, you definitiely want an editor with an understanding of Python syntax to help you out. Even the included IDLE development environment will auto-indent for you. So will vim, emacs, Visual Studio Code, PyCharm, Eric, Atom, Wing IDE and a host of others. No need to get frustrated!!! > writes: > >> The following snap shot of system prompt illustrates my problem. I have >> tried 3.8, 3.92 and 3.10 with the same result. When I run in the window >> interface it doesn't even display one row of ... but does print if I hit >> return twice. I'm new to Python and was excited about learning it but am >> becoming very frustrated over a bug in such a simple conditional statement >> - please help as I would really like to master Python. From avigross at verizon.net Fri Apr 2 12:50:03 2021 From: avigross at verizon.net (Avi Gross) Date: Fri, 2 Apr 2021 12:50:03 -0400 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> Message-ID: <011901d727e0$3ac55f10$b0501d30$@verizon.net> Chris, Now that it is April 2, I have to ask which of the methods for dealing with chocolate is more pythonic and is there a module for that? Next April, can we switch beans and discuss different grades of coffee and which ones are best to shave at home with a potato peeler? I think that would be equally relevant. I will agree that some kinds of pie-thon have chocolate as a middle ingredient but what good is any kind of pie without coffee? Oops, I should have sent this yesterday! Avi -----Original Message----- From: Python-list On Behalf Of Chris Angelico Sent: Thursday, April 1, 2021 8:00 PM To: Python Subject: Re: Horrible abuse of __init_subclass__, or elegant hack? On Fri, Apr 2, 2021 at 10:43 AM dn via Python-list wrote: > > On 02/04/2021 10.13, Chris Angelico wrote: > > Well, it's a simple matter of chronology. First you have crude oil, > > then time passes, and then you have plastic and residue. It makes > > sense ONLY if you think of it with a specific ordering, which > > implies Python 3.7 or later. > > My anxiety over 'ordering' comes to the fore: if there are multiple > inputs and/or multiple outputs, how can one tell where the former > series ends and the latter begins? > > "Explicit" cf "implicit"? The exact same way. Before time passes, you have all of the inputs; after time passes, you have all of the outputs. (The way the game goes, all inputs are consumed simultaneously and all outputs produced simultaneously, so there's no chronological distinctions between them.) > > Hot chocolate? Ahh, now, that's the other thing I drink a lot of. I > > even have a dedicated mug with a Cadbury logo on it. Sadly, not > > easily purchasable, but this one was a gift from a family member who > > knows full well that I have my priorities straight. > > Cadbury do not make chocolate! > Neither do Hershey, for that matter! > There, now that I've upset most of the English-speaking world... > > PS they use the milk to 'water down' the chocolate! It's much like > buying Easter Eggs: the density of chocolate is much lower for the price. Chocolate comes in tiers. 1: Top tier chocolates - fine chocolates - are made by true artisans, and are generally purchased in smaller quantities due to pricing. (Although I did once buy something like 50kg of Lindor balls. That was a gooood day.) 2: Everyday chocolate. Mass-produced, so it's lower quality but far lower in price. Sure, it's not as amazing as eating Guylian or Godiva, but you can eat a block of Cadbury every day and still be within budget. 3: Cooking chocolate. Comes cheaper than typical block chocolate, is usually firmer, and takes more effort to make good use of, but you can take a potato peeler to it and put chocolate shavings on your Pavlova, which doesn't really work as well with a block of Dairy Milk. 4: Cheap chocolate. Easter eggs, bulk stuff, the sorts of things you throw at children to keep them happy. Sometimes has nostalgia value, but it's low-grade stuff. Some of it isn't too bad, but you end up paying MORE for it than you would for tier two chocolate, since it's usually packaged up far too much. Also, some of it is downright disgusting. I won't name names, but one time I had access to a bulk load of white chocolate (and yes, you could say that white chocolate isn't chocolate to start with, but some of it is actually good), and it tasted like milk powder. Why people pay so much for low-grade chocolate wrapped up in fiddly foil covers, I don't know. > View > https://www.whittakers.co.nz/en_NZ/products/72-dark-ghana/block-250g > before questioning my curmugeonly credentials! Oh yes, that's definitely one of the good brands. By "credentials", do you mean that you have some connection with the company? If not, that's fine, but it would certainly be notable if you do! ChrisA -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Fri Apr 2 12:57:40 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 Apr 2021 03:57:40 +1100 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: <011901d727e0$3ac55f10$b0501d30$@verizon.net> References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> <011901d727e0$3ac55f10$b0501d30$@verizon.net> Message-ID: On Sat, Apr 3, 2021 at 3:51 AM Avi Gross via Python-list wrote: > > Chris, > > Now that it is April 2, I have to ask which of the methods for dealing with > chocolate is more pythonic and is there a module for that? I have a JavaScript front end package called "Chocolate Factory", which works well for making a web app with a Python back end. > Next April, can we switch beans and discuss different grades of coffee and > which ones are best to shave at home with a potato peeler? Sure! I don't have any experience with shaving coffee, though, so I'll leave that thread for you. > I think that would be equally relevant. > > I will agree that some kinds of pie-thon have chocolate as a middle > ingredient but what good is any kind of pie without coffee? Ohh, you've perhaps never tasted a good Aussie meat pie. With or without coffee, those are awesome. > Oops, I should have sent this yesterday! Blame timezones :) ChrisA From lukasz at langa.pl Fri Apr 2 14:01:53 2021 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Fri, 2 Apr 2021 20:01:53 +0200 Subject: [RELEASE] Python 3.9.3 and 3.8.9 are now available Message-ID: <10795108-4D09-48D0-9CF5-0FB27A6E8A1B@langa.pl> Those are expedited security releases, recommended to all users. Get them here: https://www.python.org/downloads/release/python-393/ https://www.python.org/downloads/release/python-389/ Security Content bpo-43631 : high-severity CVE-2021-3449 and CVE-2021-3450 were published for OpenSSL, it?s been upgraded to 1.1.1k in CI, and macOS and Windows installers. bpo-42988 : CVE-2021-3426: Remove the getfile feature of the pydoc module which could be abused to read arbitrary files on the disk (directory traversal vulnerability). Moreover, even source code of Python modules can contain sensitive data like passwords. Vulnerability reported by David Schw?rer. bpo-43285 : ftplib no longer trusts the IP address value returned from the server in response to the PASV command by default. This prevents a malicious FTP server from using the response to probe IPv4 address and port combinations on the client network. Code that requires the former vulnerable behavior may set a trust_server_pasv_ipv4_address attribute on their ftplib.FTP instances to True to re-enable it. bpo-43439 : Add audit hooks for gc.get_objects(), gc.get_referrers() and gc.get_referents(). Patch by Pablo Galindo. Release Calendar Due to the security fixes, those releases are made a month sooner than planned. I decided to keep the release calendar intact, meaning that the last full regular maintenance release of Python 3.8 is still planned for May 3rd 2021, after which it will shift to source releases only for security bug fixes only. Maintenance releases for the 3.9 series will continue at regular bi-monthly intervals, with 3.9.3 planned for May 3rd 2021 as well. What?s new? The Python 3.9 series contains many new features and optimizations over 3.8. See the ?What?s New in Python 3.9 ? document for more information about features included in the 3.9 series. We also have a detailed change log for 3.9.3 specifically. Detailed information about all changes made in version 3.8.9 can be found in its respective changelog . We hope you enjoy those new releases! Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Your friendly release team, Ned Deily @nad Steve Dower @steve.dower ?ukasz Langa @ambv From PythonList at DancesWithMice.info Fri Apr 2 16:33:55 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 3 Apr 2021 09:33:55 +1300 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> Message-ID: <5794a6a9-5c37-820f-8d52-bcab701a4771@DancesWithMice.info> On 02/04/2021 21.32, Alan Gauld via Python-list wrote: > On 02/04/2021 00:42, dn via Python-list wrote: > >> Contrarily "tuck" in (old) English slang represented "sweets" (or > > Not that old. We still use it occasionally today. And we > certainly had a "tuck shop" at school. It was where you > bought lunch if not eating in the refectory. ie. sandwiches, > crisps, pop etc. But its main sales were sweets including > chocolate bars (bringing us back to Cadbury :-) > > Unusually, our tuck shop was run by the student body. The > school prefects were the operating committee and > responsible for finding volunteers to staff it and > order supplies and bank the proceeds 9with the school > secretary) Old? I suspect we need a veritable line of people holding up their hands so that we can count on their fingers the number of years since we were at our respective schools! We did not have any choice of meals: one ate what was given - or did not. (yes, that is in-itself a choice) Thus "tuck" was a cupboard/closet from which we could purchase confectionery for pleasurable-eating. Given that today we refer to such as 'junk foods', I have no need to comment further on the (perceived) quality of our meals... although I suspect one could/can only 'graduate' from such institutions after putting-in considerable practise at varied complaints about the food - or is that merely a tradition? Once I had 'debugged' chocolate (and tested the range assiduously and exhaustively), Bournville was the only Cadbury chocolate I would consider. Today, even that seems to lack, er, chocolate, and has an unsatisfactory after-taste. Over here, Cadbury attempted to replace ingredients with Palm Oil. It caused a minor-revolution. The result tasted ghastly and left a slick and messy taste in one's mouth. Needless to say, whilst many were dumped (in the harbor?) the company hurriedly reversed that decision. However, (and ensuring Python remains within the subject of conversation) it is worth noting that the Cadbury brothers had some ideas about caring for workers/contributors in similar manner to PSF's interests in egalitarianism and diversity - certainly a quality-of-life beyond those of the often quoted 'advances' credited to Henry Ford. https://www.cadbury.co.uk/about-bournville (maybe they are recognised in British cf US management texts?) -- Regards, =dn From PythonList at DancesWithMice.info Fri Apr 2 17:15:06 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 3 Apr 2021 10:15:06 +1300 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> Message-ID: On 02/04/2021 13.00, Chris Angelico wrote: > On Fri, Apr 2, 2021 at 10:43 AM dn via Python-list > wrote: >> >> On 02/04/2021 10.13, Chris Angelico wrote: >>> Well, it's a simple matter of chronology. First you have crude oil, >>> then time passes, and then you have plastic and residue. It makes >>> sense ONLY if you think of it with a specific ordering, which implies >>> Python 3.7 or later. >> >> My anxiety over 'ordering' comes to the fore: if there are multiple >> inputs and/or multiple outputs, how can one tell where the former series >> ends and the latter begins? >> >> "Explicit" cf "implicit"? > > The exact same way. Before time passes, you have all of the inputs; > after time passes, you have all of the outputs. (The way the game > goes, all inputs are consumed simultaneously and all outputs produced > simultaneously, so there's no chronological distinctions between > them.) Ah, I hadn't suspended enough of (my) reality to realise that we are talking about a game. Morphology in the arms of Morpheus? English Idiom/quotation: https://en.wiktionary.org/wiki/in_the_arms_of_Morpheus > Chocolate comes in tiers. > > 1: Top tier chocolates - fine chocolates - are made by true artisans, It is well to remember artisans (people who work with artesian water?), but I'm more interested in being an aficionado - thus any addition/alteration to the chocolate is at best diminution, and at worst, 'pollution'! Stop being distracted, AND save money! > 2: Everyday chocolate. ...can eat a block of Cadbury every day I realised that the days of my six-pack were over when I met chocolate. These days rather than an eight-pack, I'm settling for an ate-pack! "Six pack" abs: https://www.menshealth.com/uk/building-muscle/a747790/four-week-six-pack-plan/ "Ate-pack": I saw it. I ate it! > 3: Cooking chocolate. Eating this sounds much like drinking from a plain, brown, bag... > 4: Cheap chocolate. This is like trying to write Python code as if it were Java - they even taste much the same! >> View >> https://www.whittakers.co.nz/en_NZ/products/72-dark-ghana/block-250g >> before questioning my curmugeonly credentials! > > Oh yes, that's definitely one of the good brands. By "credentials", do > you mean that you have some connection with the company? If not, > that's fine, but it would certainly be notable if you do! Meaning that you'd only love me for my (access to) chocolate? (I'd feel so used - if the chocolate 'high' allowed) Sadly, my only connection to the company is purchaser:supplier. However, I should volunteer to be a taster, or to use my ?expertise to train their staff. Do you think they have an 'all you can eat' policy? Is there such a thing as F/LOSS in the chocolate world? What does it mean to fork a block of chocolate? Where is their repository? My overwhelming qualifications and thus "credentials", and those which I seem to be extending most often these days, involve ageing (dis-)gracefully and becoming a curmudgeon. Definition of 'grumpy old man': https://www.dictionary.com/browse/curmudgeon Bah, the chocolate these days is nothing like what we had when I were a lad...! -- Regards, =dn From rosuav at gmail.com Fri Apr 2 17:36:02 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 3 Apr 2021 08:36:02 +1100 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> Message-ID: On Sat, Apr 3, 2021 at 8:16 AM dn via Python-list wrote: > Is there such a thing as F/LOSS in the chocolate world? What does it > mean to fork a block of chocolate? Where is their repository? > It means exactly what you'd expect. The tricky part comes when you try to knife the block of chocolate, and it makes for a hilarious party game. ChrisA From PythonList at DancesWithMice.info Fri Apr 2 18:10:18 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 3 Apr 2021 11:10:18 +1300 Subject: Friday Finking: initialising values and implied tuples Message-ID: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> When there are several items to be defined and initialised, how do you prefer to format the code, and why? Apprentice: learn options Journeyman: consider and discuss Python Master: define, declare, and correct/advise/tutor Some do not realise that using a tuple is a convenient way to convey multiple values. Indeed if a function returns multiple values, that is exactly what is happening, eg return x, y, z Further, some think that the surrounding parentheses, ie ( surrounding ); 'define' the data-construct to be a tuple. This is not completely-correct. In fact, it is the comma-separated list (in this context) which identifies the data as a tuple - a 'tuple literal'. https://docs.python.org/3/reference/expressions.html?highlight=literal%20tuple#parenthesized-forms [yes, there'll be folk who decide that this *brief* intro should be the discussion topic...] The essence is to apply various values to a series of objects. Simple? Using tuples can have its advantages, but as their length increases humans have difficulties with the positional nature/relationship. Here are a couple of ways that you may/not have seen, to express the need (and perhaps you could contribute more?). Which one(s) make sense to you; for visual reasons, 'speed', cognition, ... ? (a) basic linear presentation: resource = "Oil" time = 1 crude = 2 residue = 3 my_list = "long" (b) using explicit tuples: ( resource, time, crude, residue, my_list ) = ( "Oil", 1, 2, 3, "long" ) (c) linear and indented tuples: ( resource, time, crude, residue, my_list ) = ( "Oil", 1, 2, 3, "long" ) (d) linear and differently-indented tuples: ( resource, time, crude, residue, my_list ) = ( "Oil", 1, 2, 3, "long" ) (e) implicit tuples: resource, time, crude, residue, my_list = "Oil", 1, 2, 3, "long" NB a multiple-line expression is not possible using an 'implicit' format! (unless one uses unattractive/distracting back-slashes) (f) the space-saver: resource = "Oil"; time = 1; crude = 2; residue = 3; my_list = "long" Perhaps your editor/IDE prefers or frustrates one/other of the choices? Perhaps your formatter/linter grinds you into submission? Perhaps you have different approaches depending upon the number of objects in the 'list' and the proximity of column-79, or by nature of the application? -- -- Regards, =dn From maroloccio at gmail.com Fri Apr 2 18:25:07 2021 From: maroloccio at gmail.com (Marco Ippolito) Date: Fri, 2 Apr 2021 19:25:07 -0300 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> Message-ID: > (a) basic linear presentation: > > resource = "Oil" > time = 1 > crude = 2 > residue = 3 > my_list = "long" > > (b) using explicit tuples: > > ( resource, time, crude, residue, my_list ) = ( "Oil", 1, 2, 3, "long" ) > > (c) linear and indented tuples: > > ( > resource, > time, > crude, > residue, > my_list > ) = ( > "Oil", > 1, > 2, > 3, > "long" > ) Choose: (a). In (b) I have a problem matching identifiers to values horizontally at a glance and in (c) I have the same problem vertically: i.e. "is 3 the value for residue or crude above/to-the-left?" Cognitive burden slows down and fatigues. Alternatively, if the data "fits together", use a `namedtuple` with kwarg initialisation or structured data types like `dataclasses`. From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Apr 2 18:58:55 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 2 Apr 2021 15:58:55 -0700 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> Message-ID: On 2021-04-02 at 19:25:07 -0300, Marco Ippolito wrote: > > (a) basic linear presentation: > > > > resource = "Oil" > > time = 1 > > crude = 2 > > residue = 3 > > my_list = "long" > > > > (b) using explicit tuples: > > > > ( resource, time, crude, residue, my_list ) = ( "Oil", 1, 2, 3, "long" ) > > > > (c) linear and indented tuples: > > > > ( > > resource, > > time, > > crude, > > residue, > > my_list > > ) = ( > > "Oil", > > 1, > > 2, > > 3, > > "long" > > ) > > Choose: (a). I agree. That said, I sometimes end up with something like this: ( resource, time, crude, residue, my_list ) = \ ( "Oil", 1, 2, 3, "long" ) which mitigates matching up which value goes with which name. But as soon as either tuple overflows one physical line, it's back to (a). I did go through a phase where I tried (c); note the past tense. > In (b) I have a problem matching identifiers to values horizontally at > a glance and in (c) I have the same problem vertically: i.e. "is 3 the > value for residue or crude above/to-the-left?" > > Cognitive burden slows down and fatigues. Yep. > Alternatively, if the data "fits together", use a `namedtuple` with > kwarg initialisation or structured data types like `dataclasses`. IMO, that's usually more troule than it's worth, although thing = new_thing( resource="Oil", time=1, crude=2, residue=3, my_list="long") is often better than a collection of positional parameters. From rob.cliffe at btinternet.com Fri Apr 2 21:41:59 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Sat, 3 Apr 2021 02:41:59 +0100 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> Message-ID: <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> On 02/04/2021 23:10, dn via Python-list wrote: > (f) the space-saver: > > resource = "Oil"; time = 1; crude = 2; residue = 3; my_list = "long" > > IMO This can be OK when the number of items is VERY small (like 2) and not expected to increase (or decrease).? Especially if there are multiple similar initialisations: ??? x = 1; y = 2 ??? ??? ... ??? x = 2 ; y = 6 This saves vertical space and the similarity of the initialisations may be more apparent.? It also means only a single line need be cut/pasted/modified. No doubt others will disagree. This answer reflects my willingness to use multiple statements on a line OCCASIONALLY, WHEN I think it is appropriate (as I have said or implied in other posts), whereas many people seem to regard this as completely taboo. Another example: ??? x1 = 42; y1 =? 3;? z1 = 10 ??? x2 = 41; y2 = 12; z2 = 9 ??? x3 =? 8;? y3 =? 8;? z3 = 10 (please imagine it's in a fixed font with everything neatly vertically aligned). This has see-at-a-glance STRUCTURE: the letters are aligned vertically and the "subscripts" horizontally.? Write it as 9 lines and it becomes an amorphous mess in which mistakes are harder to spot. Rob Cliffe From alan.gauld at yahoo.co.uk Fri Apr 2 18:42:37 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 2 Apr 2021 23:42:37 +0100 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> Message-ID: On 02/04/2021 23:10, dn via Python-list wrote: > When there are several items to be defined and initialised, how do you > prefer to format the code, and why? > (a) basic linear presentation: > > resource = "Oil" > time = 1 > crude = 2 > residue = 3 > my_list = "long" In production code I'd almost always go with this one. It's the only option that both keeps the variable and value together and allows me to add an explanatory comment if necessary. > (e) implicit tuples: > > resource, time, crude, residue, my_list = "Oil", 1, 2, 3, "long" Occasionally, and in personal code, I'll use this. Although this would be about as many items I'd ever have in one list. But in production code, if items are related, I'd use it. eg. x,y = 42,50 # starting coordinates hour,min,sec = 0,0,0 # default start time But in both those cases I'd more likely define a variable to be a tuple: eg. start = (42,50) # starting coordinates -- 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 alan.gauld at yahoo.co.uk Fri Apr 2 19:05:30 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sat, 3 Apr 2021 00:05:30 +0100 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: <5794a6a9-5c37-820f-8d52-bcab701a4771@DancesWithMice.info> References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> <5794a6a9-5c37-820f-8d52-bcab701a4771@DancesWithMice.info> Message-ID: On 02/04/2021 21:33, dn via Python-list wrote: > Bournville was the only Cadbury chocolate I would > consider. Today, even that seems to lack Cadbury has always been a budget chocolate brand(*) here; its a mass market option loaded with sugar and little else. Certainly doesn't compare to Suchards, Lindt, Nestle or Green & Black, or even Lidl's own brand: Fin Carre (especially their "Rich Dark" milk choco! mmmm). (*)I'm guessing Hershey is the equivalent stateside? > conversation) it is worth noting that the Cadbury brothers had some > ideas about caring for workers/contributors in similar manner to PSF's > interests in egalitarianism and diversity - certainly a quality-of-life > beyond those of the often quoted 'advances' credited to Henry Ford. Indeed, social engineering that to some extent still exists today. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Apr 2 23:09:22 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 2 Apr 2021 20:09:22 -0700 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> Message-ID: On 2021-04-03 at 02:41:59 +0100, Rob Cliffe via Python-list wrote: > ??? x1 = 42; y1 =? 3;? z1 = 10 > ??? x2 = 41; y2 = 12; z2 = 9 > ??? x3 =? 8;? y3 =? 8;? z3 = 10 > (please imagine it's in a fixed font with everything neatly vertically > aligned). > This has see-at-a-glance STRUCTURE: the letters are aligned vertically > and the "subscripts" horizontally.? Write it as 9 lines and it becomes > an amorphous mess in which mistakes are harder to spot. I agree that writing it as 9 lines is an accident waiting to happen, but if you must see that structure, then go all in: (x1, y1, z1) = (43, 3, 10) (x2, y2, z2) = (41, 12, 9) (x3, y3, z3) = ( 8, 8, 10) Or even: ((x1, y1, z1) (x2, y2, z2) (x3, y3, z3)) = ((43, 3, 10) (41, 12, 9) ( 8, 8, 10)) Or not. YMMV. I guess this doesn't come up enough in my own code to worry about it. From greg.ewing at canterbury.ac.nz Sat Apr 3 01:45:31 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 3 Apr 2021 18:45:31 +1300 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> Message-ID: On 3/04/21 10:36 am, Chris Angelico wrote: > It means exactly what you'd expect. The tricky part comes when you try > to knife the block of chocolate, and it makes for a hilarious party > game. A guillotine could be useful in the case of Whittaker's. IMO they don't make the grooves deep enough, making it quite tricky to break off a row cleanly. I'd upload a patch for that, but it doesn't seem to be open source. At least I can't find it on chochub. -- Greg From pjfarley3 at earthlink.net Sat Apr 3 01:25:18 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Sat, 3 Apr 2021 01:25:18 -0400 Subject: Python curses question: How to separate foreground and background colors from the value returned by inch()? Message-ID: <000001d72849$bc7ea8e0$357bfaa0$@earthlink.net> The window.inch(([y, x])) function returns the character and attributes of the character at the current or specified window position. But how does one separate the foreground and background colors from the resulting value? colors = window.inch(0.0) & A_ATTRIBUTES That should return the combined color + attributes value, but how to separate the foreground and background color values from that result? Should the following reliably work? fg, bg = curses.pair_content (curses.pair_number(window.inch(0,0) & A_ATTRIBUTES)) Peter From PythonList at DancesWithMice.info Sat Apr 3 02:35:20 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 3 Apr 2021 19:35:20 +1300 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: <727bcf76-2a2f-fecf-f090-e9ade0658ab0@DancesWithMice.info> <70808abb-972d-6534-073d-2bc7d1895ba0@DancesWithMice.info> Message-ID: <120dcbb3-a18b-c311-ff9a-f1251caad866@DancesWithMice.info> On 03/04/2021 18.45, Greg Ewing wrote: > On 3/04/21 10:36 am, Chris Angelico wrote: >> It means exactly what you'd expect. The tricky part comes when you try >> to knife the block of chocolate, and it makes for a hilarious party >> game. > > A guillotine could be useful in the case of Whittaker's. > IMO they don't make the grooves deep enough, making it > quite tricky to break off a row cleanly. You're so right! It has become a filial duty, to be performed every time I go to see my 90-year old mother. Also, noted the uneven division. Some of the 'squares' are significantly larger/smaller than others! > I'd upload a patch for that, but it doesn't seem to be > open source. At least I can't find it on chochub. Recommend you use our local facility: https://git.nzoss.org.nz/users/sign_in -- Regards, =dn From rob.cliffe at btinternet.com Sat Apr 3 08:00:25 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Sat, 3 Apr 2021 13:00:25 +0100 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> Message-ID: On 03/04/2021 04:09, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > On 2021-04-03 at 02:41:59 +0100, > Rob Cliffe via Python-list wrote: > >> ??? x1 = 42; y1 =? 3;? z1 = 10 >> ??? x2 = 41; y2 = 12; z2 = 9 >> ??? x3 =? 8;? y3 =? 8;? z3 = 10 >> (please imagine it's in a fixed font with everything neatly vertically >> aligned). >> This has see-at-a-glance STRUCTURE: the letters are aligned vertically >> and the "subscripts" horizontally.? Write it as 9 lines and it becomes >> an amorphous mess in which mistakes are harder to spot. > I agree that writing it as 9 lines is an accident waiting to happen, but > if you must see that structure, then go all in: > > (x1, y1, z1) = (43, 3, 10) > (x2, y2, z2) = (41, 12, 9) > (x3, y3, z3) = ( 8, 8, 10) Agreed, that is even easier to read.? (It would be kinda nice if the compiler could optimise the tuples away, for those of us who are paranoid about performance.) > > Or even: > > ((x1, y1, z1) > (x2, y2, z2) > (x3, y3, z3)) = ((43, 3, 10) > (41, 12, 9) > ( 8, 8, 10)) > > Or not. YMMV. I guess this doesn't come up enough in my own code to > worry about it. From pjfarley3 at earthlink.net Sat Apr 3 14:24:57 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Sat, 3 Apr 2021 14:24:57 -0400 Subject: Python curses question: How to separate foreground and background colors from the value returned by inch()? In-Reply-To: <000001d72849$bc7ea8e0$357bfaa0$@earthlink.net> References: <000001d72849$bc7ea8e0$357bfaa0$@earthlink.net> Message-ID: <000001d728b6$a7883740$f698a5c0$@earthlink.net> > -----Original Message----- > From: pjfarley3 at earthlink.net > Sent: Saturday, April 3, 2021 1:25 AM > To: python-list at python.org > Subject: Python curses question: How to separate foreground and background > colors from the value returned by inch()? > > The window.inch(([y, x])) function returns the character and attributes of > the character at the current or specified window position. But how does one > separate the foreground and background colors from the resulting value? > > colors = window.inch(0.0) & A_ATTRIBUTES > > That should return the combined color + attributes value, but how to > separate the foreground and background color values from that result? > Should the following reliably work? > > fg, bg = curses.pair_content (curses.pair_number(window.inch(0,0) & > A_ATTRIBUTES)) > > Peter Following up my own question because I experimented and found my own answer. The snippet below reliably extracts the foreground and background colors on both Ubuntu 20.04 (WSL2) and in a Win 10 console or Terminal window (addstr() displays added to show intermediate values): y, x = stdscr.getyx() attr = stdscr.inch(6, 0) stdscr.move(y, x) stdscr.addstr("inch(6,0)={:08X}={}\n".format(attr, attr)) pair = curses.pair_number(attr) if platform.system() == "Windows": pair = pair >> 16 stdscr.addstr("pair(6,0)={:08X}={}\n".format(pair, pair)) fg, bg = curses.pair_content (pair) stdscr.addstr("color(6,0) fg={:08X}={},bg={:08X}={}\n".format(fg, fg, bg, bg)) The same sequence (minus the getyx() and move() operations) also works for the window.getbkgd() function: attr = stdscr.getbkgd() stdscr.addstr("scrbkgd={:08X}={}\n".format(attr, attr)) pair = curses.pair_number(attr) if platform.system() == "Windows": pair = pair >> 16 fg, bg = curses.pair_content (pair) stdscr.addstr("color(scrbkgd) fg={:08X}={},bg={:08X}={}\n".format(fg, fg, bg, bg)) Windows snippet results: inch(6,0)=5A000030=1509949488 pair(6,0)=0000005A=90 color(6,0) fg=00000059=89,bg=00000000=0 scrbkgd=00000020=32 color(scrbkgd) fg=00000007=7,bg=00000000=0 Ubuntu results: inch(6,0)=00005A30=23088 pair(6,0)=0000005A=90 color(6,0) fg=00000059=89,bg=-0000001=-1 scrbkgd=00000000=0 color(scrbkgd) fg=-0000001=-1,bg=-0000001=-1 Test environments were: 1. Ubuntu 20.04 (WSL2), python 3.8.5 and 3.9.0+, ncurses6/focal,now 6.2-0ubuntu2 amd64 2. Win10 console and Terminal windows, python 3.8.7, windows-curses 2.2.0 ISTM that maybe I ought to figure out how to file a documentation bug / enhancement request. The official documentation of the returned values of these functions is woefully incomplete, including that ncurses returns -1 values for "default" colors in the *ix environment while the Windows version returns actual color values for default values. Obviously an implementation difference between ncurses and PDCurses, but worth noting somewhere. I'm not sure if the necessity of shifting the "pair" result for Windows is a necessary documentation addition or an actual bug in the underlying code. Without the shift, the code aborts with these errors in Windows: Traceback (most recent call last): File "C:\Users\MyUser\test\curses-color.py", line 126, in curses.wrapper(main) File "C:\Python38\lib\curses\__init__.py", line 105, in wrapper return func(stdscr, *args, **kwds) File "C:\Users\MyUser\test\curses-color.py", line 72, in main fg, bg = curses.pair_content (pair) OverflowError: signed short integer is greater than maximum Guidance on how to file requests for documentation corrections / clarifications would be appreciated. I do already have a generic module that reliably shows the results using both of the above snippets. Peter -- From pjfarley3 at earthlink.net Sat Apr 3 18:40:10 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Sat, 3 Apr 2021 18:40:10 -0400 Subject: Python curses question: How to separate foreground and background colors from the value returned by inch()? Message-ID: <000301d728da$4dee6690$e9cb33b0$@earthlink.net> I figured out how to file a couple of issues on the python tracker site. 43715 inch() and scrbkgd() documentation omissions 43716 curses.pair_number() value issue Peter > -----Original Message----- > From: pjfarley3 at earthlink.net > Sent: Saturday, April 3, 2021 2:25 PM > To: 'python-list at python.org' > Subject: RE: Python curses question: How to separate foreground and > background colors from the value returned by inch()? > > Guidance on how to file requests for documentation corrections / clarifications > would be appreciated. I do already have a generic module that reliably shows > the results using both of the above snippets. -- From fabiojspereira at gmail.com Sat Apr 3 17:56:50 2021 From: fabiojspereira at gmail.com (=?utf-8?Q?F=C3=A1bio_Pereira?=) Date: Sat, 3 Apr 2021 18:56:50 -0300 Subject: ENC: About \033[m In-Reply-To: <9C651B45-3A34-433E-AC39-C3D139FB19C6@hxcore.ol> References: <9C651B45-3A34-433E-AC39-C3D139FB19C6@hxcore.ol> Message-ID: print("{}".format("\033[0;30;43m*\033[m"*40)) print("{:^40}".format("v")) print("{:^54}".format("\033[7;30;43mProgramac,ao Python\033[m")) print("{:^54}".format("\033[7;30;43mFabio JS Pereira\033[m")) print("{:^40}".format("\033[7;30;43mProgramac,ao Python\033[m")) print("{:^40}".format("\033[7;30;43mFabio JS Pereira\033[m")) print("{:^40}".format("1234567890123456789012345678901234567890")) print("{:^40}".format("^")) Saida : Porque quando se usa formatac,ao de cores, o python nao consegue centralizar dentro da cadeia de 40 caracteres ? Tive que colocar 54 no parametro pois de alguma forma esta sendo considerado os caracteres de dentro do comando \033[m Enviado do [1]Email para Windows 10 References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From nospam at please.ty Sun Apr 4 04:24:21 2021 From: nospam at please.ty (jak) Date: Sun, 4 Apr 2021 10:24:21 +0200 Subject: Horrible abuse of __init_subclass__, or elegant hack? References: Message-ID: Il 01/04/2021 01:14, Chris Angelico ha scritto: > I think this code makes some sort of argument in the debate about > whether Python has too much flexibility or if it's the best > metaprogramming toolset in the world. I'm not sure which side of the > debate it falls on, though. > > class Building: > resource = None > @classmethod > def __init_subclass__(bldg): > super().__init_subclass__() > print("Building:", bldg.__name__) > def make_recipe(recip): > print(recip.__name__.replace("_", " "), "is made in a", > bldg.__name__.replace("_", " ")) > bldg.__init_subclass__ = classmethod(make_recipe) > > > class Extractor(Building): ... > class Refinery(Building): ... > > class Crude(Extractor): > resource = "Oil" > time: 1 > Crude: 1 > > class Plastic(Refinery): > Crude: 3 > time: 6 > Residue: 1 > Plastic: 2 > > class Rubber(Refinery): > Crude: 3 > time: 6 > Residue: 2 > Rubber: 2 > > Full code is here if you want context: > https://github.com/Rosuav/shed/blob/master/satisfactory-production.py > > Subclassing Building defines a class that is a building. (The ellipsis > body is a placeholder; I haven't implemented stuff where the buildings > know about their power consumptions and such. Eventually they'll have > other attributes.) But subclassing a building defines a recipe that is > produced in that building. Markers placed before the "time" are > ingredients, those after the "time" are products. > > There are actually a lot of interesting wrinkles to trying to replace > __init_subclass__ on the fly. Things get quite entertaining if you > don't use the decorator, or if you define and decorate the function > outside of the class, or various other combinations. > > On a scale of 1 to "submit this to The Daily WTF immediately", how bad > is this code? :) > > ChrisA > Hi, from https://github.com/Rosuav/shed/blob/master/satisfactory-production.py I get this error: cmd console Win10: $> py -V Python 3.8.6 $> py CrisAngelico.py Building: Extractor Building: Refinery Building: Blender Building: Packager Building: Assembler Crude is made in a Extractor Water is made in a Extractor Plastic is made in a Refinery Rubber is made in a Refinery Traceback (most recent call last): File "CrisAngelico.py", line 123, in class Rubber(Refinery): File "CrisAngelico.py", line 72, in make_recipe if net <= alternate["makes"] and costs >= alternate["costs"]: TypeError: '<=' not supported between instances of 'Counter' and 'Counter' :^( From rosuav at gmail.com Sun Apr 4 05:13:28 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 4 Apr 2021 19:13:28 +1000 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: Message-ID: On Sun, Apr 4, 2021 at 6:26 PM jak wrote: > > Il 01/04/2021 01:14, Chris Angelico ha scritto: > > I think this code makes some sort of argument in the debate about > > whether Python has too much flexibility or if it's the best > > metaprogramming toolset in the world. I'm not sure which side of the > > debate it falls on, though. > > > > class Building: > > resource = None > > @classmethod > > def __init_subclass__(bldg): > > super().__init_subclass__() > > print("Building:", bldg.__name__) > > def make_recipe(recip): > > print(recip.__name__.replace("_", " "), "is made in a", > > bldg.__name__.replace("_", " ")) > > bldg.__init_subclass__ = classmethod(make_recipe) > > > > > > class Extractor(Building): ... > > class Refinery(Building): ... > > > > class Crude(Extractor): > > resource = "Oil" > > time: 1 > > Crude: 1 > > > > class Plastic(Refinery): > > Crude: 3 > > time: 6 > > Residue: 1 > > Plastic: 2 > > > > class Rubber(Refinery): > > Crude: 3 > > time: 6 > > Residue: 2 > > Rubber: 2 > > > > Full code is here if you want context: > > https://github.com/Rosuav/shed/blob/master/satisfactory-production.py > > > > Subclassing Building defines a class that is a building. (The ellipsis > > body is a placeholder; I haven't implemented stuff where the buildings > > know about their power consumptions and such. Eventually they'll have > > other attributes.) But subclassing a building defines a recipe that is > > produced in that building. Markers placed before the "time" are > > ingredients, those after the "time" are products. > > > > There are actually a lot of interesting wrinkles to trying to replace > > __init_subclass__ on the fly. Things get quite entertaining if you > > don't use the decorator, or if you define and decorate the function > > outside of the class, or various other combinations. > > > > On a scale of 1 to "submit this to The Daily WTF immediately", how bad > > is this code? :) > > > > ChrisA > > > > Hi, > from https://github.com/Rosuav/shed/blob/master/satisfactory-production.py > I get this error: > > cmd console Win10: > $> py -V > Python 3.8.6 > > $> py CrisAngelico.py > Building: Extractor > Building: Refinery > Building: Blender > Building: Packager > Building: Assembler > Crude is made in a Extractor > Water is made in a Extractor > Plastic is made in a Refinery > Rubber is made in a Refinery > Traceback (most recent call last): > File "CrisAngelico.py", line 123, in > class Rubber(Refinery): > File "CrisAngelico.py", line 72, in make_recipe > if net <= alternate["makes"] and costs >= alternate["costs"]: > TypeError: '<=' not supported between instances of 'Counter' and 'Counter' > Huh. I forget sometimes which version something was introduced in. Apparently the comparison operators on Counters came in with Python 3.10. Sorry about that. As an alternative, subtraction is very approximately equivalent (if subtracting one counter from another yields nothing, then the first one is smaller in total content than the second), so it should be possible to adjust it. ChrisA From skip.montanaro at gmail.com Sun Apr 4 07:40:53 2021 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 4 Apr 2021 06:40:53 -0500 Subject: About \033[m In-Reply-To: References: <9C651B45-3A34-433E-AC39-C3D139FB19C6@hxcore.ol> Message-ID: > Porque quando se usa formatac,ao de cores, o python nao consegue > centralizar dentro da cadeia de 40 caracteres ? > > Tive que colocar 54 no parametro pois de alguma forma esta sendo > considerado os caracteres de dentro do comando \033[m Python doesn't know there is anything special about escape sequences (that they take up no space on the screen). I think you will have better results if you place the escape sequences in the format specifier: print("\033[7;30;43m{:^40}\033[m".format("Programac,ao Python")) ( haven't tried this, but I think it will work as you expect.) Skip From nospam at please.ty Sun Apr 4 12:18:55 2021 From: nospam at please.ty (jak) Date: Sun, 4 Apr 2021 18:18:55 +0200 Subject: Horrible abuse of __init_subclass__, or elegant hack? References: Message-ID: Il 04/04/2021 11:13, Chris Angelico ha scritto: > On Sun, Apr 4, 2021 at 6:26 PM jak wrote: >> >> Il 01/04/2021 01:14, Chris Angelico ha scritto: >>> I think this code makes some sort of argument in the debate about >>> whether Python has too much flexibility or if it's the best >>> metaprogramming toolset in the world. I'm not sure which side of the >>> debate it falls on, though. >>> >>> class Building: >>> resource = None >>> @classmethod >>> def __init_subclass__(bldg): >>> super().__init_subclass__() >>> print("Building:", bldg.__name__) >>> def make_recipe(recip): >>> print(recip.__name__.replace("_", " "), "is made in a", >>> bldg.__name__.replace("_", " ")) >>> bldg.__init_subclass__ = classmethod(make_recipe) >>> >>> >>> class Extractor(Building): ... >>> class Refinery(Building): ... >>> >>> class Crude(Extractor): >>> resource = "Oil" >>> time: 1 >>> Crude: 1 >>> >>> class Plastic(Refinery): >>> Crude: 3 >>> time: 6 >>> Residue: 1 >>> Plastic: 2 >>> >>> class Rubber(Refinery): >>> Crude: 3 >>> time: 6 >>> Residue: 2 >>> Rubber: 2 >>> >>> Full code is here if you want context: >>> https://github.com/Rosuav/shed/blob/master/satisfactory-production.py >>> >>> Subclassing Building defines a class that is a building. (The ellipsis >>> body is a placeholder; I haven't implemented stuff where the buildings >>> know about their power consumptions and such. Eventually they'll have >>> other attributes.) But subclassing a building defines a recipe that is >>> produced in that building. Markers placed before the "time" are >>> ingredients, those after the "time" are products. >>> >>> There are actually a lot of interesting wrinkles to trying to replace >>> __init_subclass__ on the fly. Things get quite entertaining if you >>> don't use the decorator, or if you define and decorate the function >>> outside of the class, or various other combinations. >>> >>> On a scale of 1 to "submit this to The Daily WTF immediately", how bad >>> is this code? :) >>> >>> ChrisA >>> >> >> Hi, >> from https://github.com/Rosuav/shed/blob/master/satisfactory-production.py >> I get this error: >> >> cmd console Win10: >> $> py -V >> Python 3.8.6 >> >> $> py CrisAngelico.py >> Building: Extractor >> Building: Refinery >> Building: Blender >> Building: Packager >> Building: Assembler >> Crude is made in a Extractor >> Water is made in a Extractor >> Plastic is made in a Refinery >> Rubber is made in a Refinery >> Traceback (most recent call last): >> File "CrisAngelico.py", line 123, in >> class Rubber(Refinery): >> File "CrisAngelico.py", line 72, in make_recipe >> if net <= alternate["makes"] and costs >= alternate["costs"]: >> TypeError: '<=' not supported between instances of 'Counter' and 'Counter' >> > > Huh. I forget sometimes which version something was introduced in. > Apparently the comparison operators on Counters came in with Python > 3.10. Sorry about that. As an alternative, subtraction is very > approximately equivalent (if subtracting one counter from another > yields nothing, then the first one is smaller in total content than > the second), so it should be possible to adjust it. > > ChrisA > I modified your code in the following way: line 65-66: from: if (qty <= alternate["per_minute"] and (costs[Extractor], costs) > (alternate["costs"][Extractor], alternate["costs"]) to: if (qty <= alternate["per_minute"] and (costs[Extractor], set(costs)) > (alternate["costs"][Extractor], set(alternate["costs"])) and line 72: from: if net <= alternate["makes"] and costs >= alternate["costs"]: to: if set(net) <= set(alternate["makes"]) and set(costs) >= set(alternate["costs"]): The program runs now. Is the result correct? Building: Extractor Building: Refinery Building: Blender Building: Packager Building: Assembler Crude is made in a Extractor Water is made in a Extractor Plastic is made in a Refinery Rubber is made in a Refinery Fuel is made in a Refinery Heavy Oil Residue is made in a Refinery Polymer Resin is made in a Refinery Residual Fuel is made in a Refinery Diluted Fuel is made in a Blender Canister is made in a Extractor Package Water is made in a Packager Diluted Packaged Fuel is made in a Refinery Unpackage Fuel is made in a Packager Petroleum Coke is made in a Refinery Residual Plastic is made in a Refinery Residual Rubber is made in a Refinery Recycled Plastic is made in a Refinery Recycled Rubber is made in a Refinery Sulfur is made in a Extractor Coal is made in a Extractor Compacted is made in a Assembler Turbofuel is made in a Refinery Turbo Heavy Fuel is made in a Refinery Turbo Blend Fuel is made in a Blender Specify one or more target items Exit code: 0 (forgive me your trouble) cheers From nospam at please.ty Sun Apr 4 12:22:22 2021 From: nospam at please.ty (jak) Date: Sun, 4 Apr 2021 18:22:22 +0200 Subject: Horrible abuse of __init_subclass__, or elegant hack? References: Message-ID: Il 04/04/2021 18:18, jak ha scritto: > Il 04/04/2021 11:13, Chris Angelico ha scritto: >> On Sun, Apr 4, 2021 at 6:26 PM jak wrote: >>> >>> Il 01/04/2021 01:14, Chris Angelico ha scritto: copy / paste corrupted the tabs, sorry From rosuav at gmail.com Sun Apr 4 14:24:55 2021 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 5 Apr 2021 04:24:55 +1000 Subject: Horrible abuse of __init_subclass__, or elegant hack? In-Reply-To: References: Message-ID: On Mon, Apr 5, 2021 at 2:21 AM jak wrote: > > I modified your code in the following way: > > line 65-66: > from: > > if (qty <= alternate["per_minute"] > and (costs[Extractor], costs) > (alternate["costs"][Extractor], > alternate["costs"]) > > to: > if (qty <= alternate["per_minute"] > and (costs[Extractor], set(costs)) > > (alternate["costs"][Extractor], set(alternate["costs"])) Unfortunately, set comparisons aren't equivalent. The point of these checks is to see if the quantities are also lower (or higher) than on the other side. It'd probably be easiest to monkeypatch the functionality in. You can either borrow the implementation from the CPython sources (it uses all() and a couple of nested loops to scan over everything), or use this implementation: class Counter(Counter): def __le__(self, other): return not (self - other) def __gt__(self, other): return not (self <= other) When you subtract a Counter from a Counter, anything that would become negative is omitted, so if subtracting the Counters results in an empty container, this one is less than that one. > The program runs now. Is the result correct? > > Specify one or more target items Well, it successfully ran to completion, which is a good sign, but it's impossible to say whether it's correct since it didn't actually produce any real output. Try adding an argument: PRODUCING: Fuel ==================================== Requires Oil at 100.00% Produces 40/min Fuel Produces 30/min Resin Crude - Extractor at 100.00% Fuel - Refinery at 100.00% Requires Oil at 250.00% Requires Water at 83.33% Produces 100/min Fuel Produces 100/min Plastic Crude - Extractor at 250.00% Plastic - Refinery at 500.00% Water - Extractor at 83.33% Diluted Fuel - Blender at 100.00% Requires Oil at 125.00% Requires Water at 83.33% Produces 100/min Fuel Produces 50/min Rubber Crude - Extractor at 125.00% Rubber - Refinery at 250.00% Water - Extractor at 83.33% Diluted Fuel - Blender at 100.00% Requires Water at 83.33% Requires Oil at 62.50% Produces 100/min Fuel Produces 25/min Resin Crude - Extractor at 62.50% Heavy Oil Residue - Refinery at 125.00% Water - Extractor at 83.33% Diluted Fuel - Blender at 100.00% I've incorporated this change (and a small clarifying tweak to the failure message) into the pushed version, so rather than manually making the change, you could grab a fresh copy, if that's easier. Thanks for pointing this out. I like to support more Python versions than just the unreleased alpha!! ChrisA From julien.hofmann.samsung at gmail.com Sun Apr 4 14:57:27 2021 From: julien.hofmann.samsung at gmail.com (Julien Hofmann) Date: Sun, 4 Apr 2021 11:57:27 -0700 (PDT) Subject: Matplotlib scale Message-ID: <7115e161-7e87-46f8-a1df-916e02389db4n@googlegroups.com> Hi everyone, I've created a code to run a 2D mapping using matplotlib from a .csv file. I've tried to set the maximum color (red) of the scale as 80% of the maximum value and not as the maximum value of my .csv file. Does someone know how to modify that? I've tried different solution but it doesn't work. Thanks import os import matplotlib.pyplot as plt import pandas as pd import numpy as np from matplotlib import colorbar, colors import matplotlib.tri as tri #os.chdir("C:/Users/Julien Hofmann/Desktop/Nano-indentation") data = pd.read_csv("Cartographie.csv",sep=';') nb_lignes=21 nb_colonnes=27 fig = plt.figure(figsize=(15,12)) ax = plt.subplot(1,1,1) x=np.linspace(0,(data["x"][len(data["x"])-1]-data["x"][0])*1000,nb_colonnes) y=np.linspace(0,(data["y"][len(data["y"])-1]-data["y"][0])*1000,nb_lignes) X,Y=np.meshgrid(x,y) z=np.array(data["Durete"]) triang = tri.Triangulation(data["x"], data["y"]) interpolator = tri.LinearTriInterpolator(triang, z) Xi, Yi = np.meshgrid(x, y) zi = interpolator(Xi, Yi) cntr1 = ax.contourf(x, y, z.reshape(nb_lignes,nb_colonnes), levels=150, cmap="jet") cbar = fig.colorbar(cntr1, ax=ax) ax.axis('on') From lukasz at langa.pl Sun Apr 4 15:24:50 2021 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Sun, 4 Apr 2021 21:24:50 +0200 Subject: [RELEASE] Python 3.9.4 hotfix is now available Message-ID: <10FDFEAA-E598-4CCC-9A1C-D8B6F8FD53EA@langa.pl> Python 3.9.3 was released two days ago on Friday, April 2nd. It contains important security content listed below for reference. Unfortunately, it also introduced an unintentional ABI incompatibility, making some C extensions built with Python 3.9.0 - 3.9.2 crash with Python 3.9.3 on 32-bit systems. To minimize disruption, I decided to recall 3.9.3 and introduce this hotfix release: 3.9.4. We highly recommend upgrading your Python 3.9 installations to 3.9.4 at your earliest convenience. Get it here: https://www.python.org/downloads/release/python-394/ What is ?ABI compatibility?? Python guarantees that within a given language series (like the current 3.9) binary extensions written in C or C++ and compiled against headers of one release (like 3.9.0) will be importable from other versions in the same series (like 3.9.3). If this weren?t the case, library authors would have to ship separate binary wheels on PyPI for every single bugfix release of Python. That would be very inconvenient. What broke in Python 3.9.3? In a fix for a corner-case crash around recursion limits and exceptions, the PyThreadState struct needed to change. While PyThreadState?s only documented public member is the *interp field , it?s not uncommon for C extensions to access other fields in this struct as well. When I approved the backport of this fix, I missed the fact that the variable size change would change the memory layout of said struct on 32-bit systems (on 64-bit systems alignment rules made the size change backwards compatible). Merging the backport was a mistake, and so 3.9.4 reverts it to restore compatibility with binary extensions built against Python 3.9.0 - 3.9.2. Details in bpo-43710 . Security Content in Python 3.9.3 bpo-43631 : high-severity CVE-2021-3449 and CVE-2021-3450 were published for OpenSSL, it?s been upgraded to 1.1.1k in CI, and macOS and Windows installers. bpo-42988 : CVE-2021-3426: Remove the getfile feature of the pydoc module which could be abused to read arbitrary files on the disk (directory traversal vulnerability). Moreover, even source code of Python modules can contain sensitive data like passwords. Vulnerability reported by David Schw?rer. bpo-43285 : ftplib no longer trusts the IP address value returned from the server in response to the PASV command by default. This prevents a malicious FTP server from using the response to probe IPv4 address and port combinations on the client network. Code that requires the former vulnerable behavior may set a trust_server_pasv_ipv4_address attribute on their ftplib.FTP instances to True to re-enable it. bpo-43439 : Add audit hooks for gc.get_objects(), gc.get_referrers() and gc.get_referents(). Patch by Pablo Galindo. Release Calendar Maintenance releases for the 3.9 series will continue at regular bi-monthly intervals, with 3.9.5 planned for May 3rd 2021 as well. What?s new? The Python 3.9 series contains many new features and optimizations over 3.8. See the ?What?s New in Python 3.9 ? document for more information about features included in the 3.9 series. We also have a detailed change log for 3.9.3 specifically. Detailed information about all changes made in version 3.8.9 can be found in its respective changelog . We hope you enjoy those new releases! Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Your friendly release team, ?ukasz Langa @ambv Ned Deily @nad Steve Dower @steve.dower From PythonList at DancesWithMice.info Sun Apr 4 17:53:35 2021 From: PythonList at DancesWithMice.info (dn) Date: Mon, 5 Apr 2021 09:53:35 +1200 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> Message-ID: <08459919-e952-c263-ea35-cb73bbd91252@DancesWithMice.info> On 03/04/2021 11.25, Marco Ippolito wrote: >> (a) basic linear presentation: >> >> resource = "Oil" >> time = 1 >> crude = 2 >> residue = 3 >> my_list = "long" >> >> (b) using explicit tuples: >> >> ( resource, time, crude, residue, my_list ) = ( "Oil", 1, 2, 3, "long" ) >> >> (c) linear and indented tuples: >> >> ( >> resource, >> time, >> crude, >> residue, >> my_list >> ) = ( >> "Oil", >> 1, >> 2, >> 3, >> "long" >> ) > > Choose: (a). > > In (b) I have a problem matching identifiers to values horizontally at a > glance and in (c) I have the same problem vertically: i.e. "is 3 the value for > residue or crude above/to-the-left?" > > Cognitive burden slows down and fatigues. +1 > Alternatively, if the data "fits together", use a `namedtuple` with kwarg > initialisation or structured data types like `dataclasses`. Whereas the other formats cannot, it would be very easy to turn an (a) type of list into a dataclass! -- Regards, =dn From PythonList at DancesWithMice.info Sun Apr 4 19:47:53 2021 From: PythonList at DancesWithMice.info (dn) Date: Mon, 5 Apr 2021 11:47:53 +1200 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> Message-ID: On 04/04/2021 01.00, Rob Cliffe via Python-list wrote: > > > On 03/04/2021 04:09, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: >> On 2021-04-03 at 02:41:59 +0100, >> Rob Cliffe via Python-list wrote: >> >>> ???? x1 = 42; y1 =? 3;? z1 = 10 >>> ???? x2 = 41; y2 = 12; z2 = 9 >>> ???? x3 =? 8;? y3 =? 8;? z3 = 10 >>> (please imagine it's in a fixed font with everything neatly vertically >>> aligned). >>> This has see-at-a-glance STRUCTURE: the letters are aligned vertically >>> and the "subscripts" horizontally.? Write it as 9 lines and it becomes >>> an amorphous mess in which mistakes are harder to spot. >> I agree that writing it as 9 lines is an accident waiting to happen, but >> if you must see that structure, then go all in: >> >> ???? (x1, y1, z1) = (43,? 3, 10) >> ???? (x2, y2, z2) = (41, 12,? 9) >> ???? (x3, y3, z3) = ( 8,? 8, 10) > Agreed, that is even easier to read.? (It would be kinda nice if the > compiler could optimise the tuples away, for those of us who are > paranoid about performance.) I think I've read that the compiler is smart-enough to realise that the RHS 'literal-tuples'?'tuple-literals' are being used as a 'mechanism', and thus the inits are in-lined. Apologies: I can't find a web.ref. Likely one of our colleagues, who is 'into' Python-internals, could quickly clarify... Can I invite you/us/all/each to think on these ideas a bit further? (I'd like to conflate a few earlier contributions, if I may) Way back, when people like @Alan and myself were young and innocent (and the power to run mainframe computers was produced by dinosaurs running in treadmills) we didn't have PEP-008 advice, but suffered hard-limits, such as 80-column cards. Both RAM and secondary-storage costs were $big, so we were taught all manner of 'conservation' techniques, eg scX = 1 # starting co-ordinates scY = 2 scZ = 3 The abbreviated names required noticeably shorter processing times. The comment was necessary because "sc" or "scX" could be interpreted as abbreviations for many, diverse, things. However, the obvious draw-back? Later in the code, when we came to "scX", we had no such handy-reminder/Cliff-Notes! (and yes, teaching-languages, such as Dartmouth BASIC, did limit variable-names to single letters, etc, - and yes, once common letters such as r, e, i, n, x, etc had been assigned one might be forced to use "q" to count the number of eggs. What? Once such languages have warped one's mind, recovery is all-but impossible! So, now you know...) Accordingly, having over-come the limits of the past, current advice is to choose names wisely - and in doing-so, obviate the need for such comments, eg starting_coordinate_X = 1 ... The initial 'complaint' against the idea of "long" identifiers relates to typing competence. It's all very well to have meaningful-names, but the more typing that has to be done, the more opportunity for errors to be introduced/creep-in/insinuate themselves (let's be clear - it's not my typing, it's all the error's fault!) However, today's editors and IDEs are sufficient agile as to be able to suggest intelligent and context-aware "completion" suggestions - most even allowing the choice to be made without lifting hands from keyboard. So, can we discard the 'too hard' complaint? A point made earlier (in the thread), was that some of the data-items 'belonged together' and thus it would be reasonably sensible to group them, eg (x1, y1, z1) = (43, 3, 10) This is often the reason for a longer 'list' of initialisations (but the converse does not apply: a longer list may not consist of closely-related data-items!) The implication is that the x, y, and z values are related, eg a 3D co-ordinate; and thus it does not impose "cognitive load" to initialise them in a relative fashion (the second value "3", relates to the second identifier "y1"). The small number of elements is relevant! Good thinking! Another suggestion for this situation, is to use a named-tuples. From the (fine) manual: "Named tuples assign meaning to each position in a tuple and allow for more readable, self-documenting code. They can be used wherever regular tuples are used, and they add the ability to access fields by name instead of position index." (https://docs.python.org/3/library/collections.html?highlight=namedtuple#collections.namedtuple) Borrowing the manual's example-code (apologies for any unfortunate word-wrapping by my email-client): >>> # Basic example >>> Point = namedtuple('Point', ['x', 'y']) >>> p = Point(11, y=22) # instantiate with positional or keyword arguments >>> p[0] + p[1] # indexable like the plain tuple (11, 22) 33 >>> x, y = p # unpack like a regular tuple >>> x, y (11, 22) >>> p.x + p.y # fields also accessible by name 33 >>> p # readable __repr__ with a name=value style Point(x=11, y=22) The drawback/cost/effort-required is that the named-tuple must have been defined previously, and only then can we employ such to initialise a group of values. Assuming we chose a more illuminating identifier than "p", later in the code it would be quite apparent what "p.x" means (per critique, above), eg: starting_point = Point(11, y=22) It may also be worth noting that named_tuples can be pre-set with default values. This may reduce the lines of code to achieve initialisation - assuming we (coders) remember the default-values (correctly). Thinking a bit more deeply, if we are going to take advantage of the named-tuple which offers access to the data as a collection (eg "p"), as well as to the individual/component values (eg "p.x") perhaps we should be examining just how this data is used within the code. In which case, a class-y guy such as I (if I keep saying it often-enough, will you believe me?) will quickly prefer a custom-class over a named-tuple (also they've been available for longer, thus 'tradition'). Not only will the individual data-items be mutable, but the initialisation process happens as/at instantiation: class coordinates(): def __init__( x, y, z=None ): self.x = x ... ... starting_coordinates = coordinates( 1, 2, 3 ) Alternately, the dataclass approach (per earlier contribution), or remove the relative nature of argument-tuples by using explicit (named-) parameters: def __init__( x=0, y=0, z=None ): ... ... starting_coordinates = coordinates( x=1, y=2, z=3 ) This is 'self-documenting'. Thus no need for explanatory comments. Using a structured-object, we have the capability to do more with the data, either as an entity or individually, eg def move_horizontally( delta=1 ): self.x += delta Of course, it all hinges on how the data-items will be used after the initialisation stage. There is utterly no point in coding a class merely to shorten an initialisation-phase! (Same logic applies to named-tuples) Did you spot how various contributors identified when they prefer one method in a specific situation, but reach for another under differing circumstances! -- Regards, =dn From greg.ewing at canterbury.ac.nz Sun Apr 4 20:55:50 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 5 Apr 2021 12:55:50 +1200 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> Message-ID: On 5/04/21 11:47 am, dn wrote: > I think I've read that the compiler is smart-enough to realise that the > RHS 'literal-tuples'?'tuple-literals' are being used as a 'mechanism', > and thus the inits are in-lined. It does indeed seem to do this in some cases: >>> def g(i, j, k): ... a, b, c = i, j, k ... >>> dis(g) 2 0 LOAD_FAST 0 (i) 2 LOAD_FAST 1 (j) 4 LOAD_FAST 2 (k) 6 ROT_THREE 8 ROT_TWO 10 STORE_FAST 3 (a) 12 STORE_FAST 4 (b) 14 STORE_FAST 5 (c) 16 LOAD_CONST 0 (None) 18 RETURN_VALUE If the RHS is a literal, it's a bit different: >>> def f(): ... a, b, c = 1, 2, 3 ... >>> dis(f) 2 0 LOAD_CONST 1 ((1, 2, 3)) 2 UNPACK_SEQUENCE 3 4 STORE_FAST 0 (a) 6 STORE_FAST 1 (b) 8 STORE_FAST 2 (c) 10 LOAD_CONST 0 (None) 12 RETURN_VALUE Here the tuple creation is being done at compile time, so there's still an unpacking operation. It might not be much different speed-wise from loading the values separately, though. -- Greg From 2QdxY4RzWzUUiLuE at potatochowder.com Sun Apr 4 22:06:08 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Sun, 4 Apr 2021 19:06:08 -0700 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> Message-ID: On 2021-04-05 at 11:47:53 +1200, dn via Python-list wrote: > Did you spot how various contributors identified when they prefer one > method in a specific situation, but reach for another under differing > circumstances! What? Use cases matter? I'm *shocked*. :-/ Of all the methodologies I used since those dinosaurs-on-the-treadmill days (you had *dinosaurs*; we had to evolve fish with legs to relieve us from having to run on our own treadmills), use cases was the one I continued to pull out long after that department went away. If I have a larger project that uses 3D points, I *might* reach for a named tuple, but if it's smaller and I know that there will only ever be two points, then px, py, pz, qx, qy, and qz is good enough. From tjreedy at udel.edu Sun Apr 4 22:11:50 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 4 Apr 2021 22:11:50 -0400 Subject: About \033[m In-Reply-To: References: <9C651B45-3A34-433E-AC39-C3D139FB19C6@hxcore.ol> Message-ID: On 4/4/2021 7:40 AM, Skip Montanaro wrote: >> Porque quando se usa formatac,ao de cores, o python nao consegue >> > centralizar dentro da cadeia de 40 caracteres ? >> >> Tive que colocar 54 no parametro pois de alguma forma esta sendo >> considerado os caracteres de dentro do comando \033[m > > > Python doesn't know there is anything special about escape sequences (that > they take up no space on the screen). I think you will have better results > if you place the escape sequences in the format specifier: > > print("\033[7;30;43m{:^40}\033[m".format("Programac,ao Python")) or print(f"\033[7;30;43m{"Programac,ao Python":^40}\033[m") -- Terry Jan Reedy From bouncingcats at gmail.com Sun Apr 4 23:28:48 2021 From: bouncingcats at gmail.com (David) Date: Mon, 5 Apr 2021 13:28:48 +1000 Subject: Using pytest, sometimes does not capture stderr Message-ID: Hi, I have just begun using pytest at a basic level and I am seeing behaviour that I do not understand. My platform is Debian 10.9 There are 3 files involved, contents are provided below, and attached. - module_1.py passes the test as expected - module_2.py has a tiny change, and fails unexpectedly. - my_test.py runs the same test on each module Can anyone explain why the module_2.py test fails? Is it because stderr during module import is not the same as during test? Is it something to do with mutable defaults? How to investigate this? And how can I get the test to pass without changing module_2? Thanks :) #--------------------------------------------------------------------- Here is the file module_1.py: #!/usr/bin/python3 import sys def msg(*args): print(*args, file=sys.stderr) #--------------------------------------------------------------------- Here is the file module_2.py: #!/usr/bin/python3 import sys MSG_DESTINATION = sys.stderr def msg(*args): print(*args, file=MSG_DESTINATION) #--------------------------------------------------------------------- Here is the file: my_test.py #!/usr/bin/python3 import module_1 import module_2 def test__1(capsys): module_1.msg("a", "message") captured = capsys.readouterr() assert captured.err == """a message\n""" def test__2(capsys): module_2.msg("a", "message") captured = capsys.readouterr() assert captured.err == """a message\n""" #--------------------------------------------------------------------- Here is the pytest output: $ pytest-3 ======================== test session starts ========================= platform linux -- Python 3.7.3, pytest-3.10.1, py-1.7.0, pluggy-0.8.0 rootdir: /mnt/hart/home/d10/david/work/src/py/lab/pytest/capture/bug, inifile: collected 2 items my_test.py .F [100%] ============================== FAILURES ============================== ______________________________ test__2 _______________________________ capsys = <_pytest.capture.CaptureFixture object at 0x7ff6457134a8> def test__2(capsys): module_2.msg("a", "message") captured = capsys.readouterr() > assert captured.err == """a message\n""" E AssertionError: assert '' == 'a message\n' E + a message my_test.py:14: AssertionError ------------------------ Captured stderr call ------------------------ a message ================= 1 failed, 1 passed in 0.03 seconds ================= -------------- next part -------------- ============================= test session starts ============================== platform linux -- Python 3.7.3, pytest-3.10.1, py-1.7.0, pluggy-0.8.0 rootdir: /mnt/hart/home/d10/david/work/src/py/lab/pytest/capture/bug, inifile: collected 2 items my_test.py .F [100%] =================================== FAILURES =================================== ___________________________________ test__2 ____________________________________ capsys = <_pytest.capture.CaptureFixture object at 0x7f9f8cc33278> def test__2(capsys): module_2.msg("a", "message") captured = capsys.readouterr() > assert captured.err == """a message\n""" E AssertionError: assert '' == 'a message\n' E + a message my_test.py:14: AssertionError ----------------------------- Captured stderr call ----------------------------- a message ====================== 1 failed, 1 passed in 0.03 seconds ====================== From cs at cskk.id.au Sun Apr 4 23:43:50 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 5 Apr 2021 13:43:50 +1000 Subject: Using pytest, sometimes does not capture stderr In-Reply-To: References: Message-ID: On 05Apr2021 13:28, David wrote: >I have just begun using pytest at a basic level and I am >seeing behaviour that I do not understand. > >My platform is Debian 10.9 > >There are 3 files involved, contents are provided below, and attached. >- module_1.py passes the test as expected >- module_2.py has a tiny change, and fails unexpectedly. >- my_test.py runs the same test on each module > >Can anyone explain why the module_2.py test fails? >Is it because stderr during module import is not the same as during test? >Is it something to do with mutable defaults? >How to investigate this? >And how can I get the test to pass without changing module_2? > >Thanks :) > >#--------------------------------------------------------------------- >Here is the file module_1.py: >#!/usr/bin/python3 >import sys >def msg(*args): > print(*args, file=sys.stderr) > >#--------------------------------------------------------------------- >Here is the file module_2.py: >#!/usr/bin/python3 >import sys >MSG_DESTINATION = sys.stderr >def msg(*args): > print(*args, file=MSG_DESTINATION) The code in module_2.py runs at different times. When it is imported, sys.stderr is the OS-provided stderr. That reference is kept in MSG_DESTINATION. Then your test code runs, and changes sys.stderr. It then runs msg(), which writes to the _original_ sys.stderr as preserved by MSG_DESTINATION. Thus not captured. By contrast, module_1.py looks up sys.stderr inside msg(), and finds the new one the code harness put at sys.stderr. So it writes to the thing that captures stuff. Cheers, Cameron Simpson From bouncingcats at gmail.com Sun Apr 4 23:56:27 2021 From: bouncingcats at gmail.com (David) Date: Mon, 5 Apr 2021 13:56:27 +1000 Subject: Using pytest, sometimes does not capture stderr In-Reply-To: References: Message-ID: On Mon, 5 Apr 2021 at 13:44, Cameron Simpson wrote: > On 05Apr2021 13:28, David wrote: > >Can anyone explain why the module_2.py test fails? > >Is it because stderr during module import is not the same as during test? > >Is it something to do with mutable defaults? > >How to investigate this? > >And how can I get the test to pass without changing module_2? > The code in module_2.py runs at different times. > When it is imported, sys.stderr is the OS-provided stderr. That > reference is kept in MSG_DESTINATION. > Then your test code runs, and changes sys.stderr. It then runs msg(), > which writes to the _original_ sys.stderr as preserved by > MSG_DESTINATION. Thus not captured. > By contrast, module_1.py looks up sys.stderr inside msg(), and finds the > new one the code harness put at sys.stderr. So it writes to the thing > that captures stuff. Hi Cameron, Thanks for confirming my suspicions so quickly. What you wrote makes sense, but there are two points that still puzzle me. 1) The final line of the pytest failure output seems to shows that pytest did capture (or is at least aware of) the stderr message from module_2. 2) My actual code that I would like to test does look like module_2. Is there any way to test it with pytest? Thanks. From cs at cskk.id.au Mon Apr 5 00:25:54 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 5 Apr 2021 14:25:54 +1000 Subject: Using pytest, sometimes does not capture stderr In-Reply-To: References: Message-ID: On 05Apr2021 13:56, David wrote: >On Mon, 5 Apr 2021 at 13:44, Cameron Simpson wrote: >> On 05Apr2021 13:28, David wrote: >> >Can anyone explain why the module_2.py test fails? >> >Is it because stderr during module import is not the same as during test? >> >Is it something to do with mutable defaults? >> >How to investigate this? >> >And how can I get the test to pass without changing module_2? > >> The code in module_2.py runs at different times. > >> When it is imported, sys.stderr is the OS-provided stderr. That >> reference is kept in MSG_DESTINATION. > >> Then your test code runs, and changes sys.stderr. It then runs msg(), >> which writes to the _original_ sys.stderr as preserved by >> MSG_DESTINATION. Thus not captured. > >> By contrast, module_1.py looks up sys.stderr inside msg(), and finds the >> new one the code harness put at sys.stderr. So it writes to the thing >> that captures stuff. > >Thanks for confirming my suspicions so quickly. What you wrote >makes sense, but there are two points that still puzzle me. >1) The final line of the pytest failure output seems to shows that > pytest did capture (or is at least aware of) the stderr message > from module_2. Yes. Unsure what's going on there. It could be timing. Suppose this happens: - pytest pushes a capturing stderr onto sys.stderr - pytest loads your module, which imports module_1 and module_2 - the test runner pushes a separate stderr capturer for the test? - module_1 finds the per-test sys.stderr value - module_2 finds pytest's outermost capturer (present when it was imported), and doesn't look up sys.stderr at test time, instead using the outer capturer >2) My actual code that I would like to test does look like module_2. > Is there any way to test it with pytest? I'd be inclined to give msg() an optional file= parameter: def msg(*args, file=None): if file is None: file = MSG_DESTINATION print(*args, file=file) Then your test code can go: msg("a", "message", file=sys.stderr) which looks up sys.stderr as it is inside the test itself, and passes it to msg(). Thus captured. If you truly need to test msg() _without_ the file= parameter, you could monkey patch module_2: old_MSG_DESTINATION = module_2.MSG_DESTINATION module_2.MSG_DESTINATION = sys.stderr # now the module_2 module has an updated reference for sys.stderr ... msg("a", "message") ... module_2.MSG_DESTINATION = old_MSG_DESTINATION # normality restored Cheers, Cameron Simpson From bouncingcats at gmail.com Mon Apr 5 01:05:59 2021 From: bouncingcats at gmail.com (David) Date: Mon, 5 Apr 2021 15:05:59 +1000 Subject: Using pytest, sometimes does not capture stderr In-Reply-To: References: Message-ID: On Mon, 5 Apr 2021 at 14:26, Cameron Simpson wrote: > On 05Apr2021 13:56, David wrote: > >Thanks for confirming my suspicions so quickly. What you wrote > >makes sense, but there are two points that still puzzle me. > >1) The final line of the pytest failure output seems to shows that > > pytest did capture (or is at least aware of) the stderr message > > from module_2. > Yes. Unsure what's going on there. It could be timing. Suppose this > happens: > - pytest pushes a capturing stderr onto sys.stderr > - pytest loads your module, which imports module_1 and module_2 > - the test runner pushes a separate stderr capturer for the test? > - module_1 finds the per-test sys.stderr value > - module_2 finds pytest's outermost capturer (present when it was > imported), and doesn't look up sys.stderr at test time, instead using > the outer capturer Ok. I do understand that my function parameter defaults are defined when the function is defined, so something like this could happen. > >2) My actual code that I would like to test does look like module_2. > > Is there any way to test it with pytest? > I'd be inclined to give msg() an optional file= parameter: Understood. > If you truly need to test msg() _without_ the file= parameter, you could > monkey patch module_2: I tried this, it works too. Thanks so much for your guidance! It's great to be steered through puzzlement by experts. I hope you're having a good day, you made mine better :) From __peter__ at web.de Mon Apr 5 07:14:09 2021 From: __peter__ at web.de (Peter Otten) Date: Mon, 5 Apr 2021 13:14:09 +0200 Subject: Using pytest, sometimes does not capture stderr In-Reply-To: References: Message-ID: On 05/04/2021 06:25, Cameron Simpson wrote: > If you truly need to test msg() _without_ the file= parameter, you could > monkey patch module_2: > > old_MSG_DESTINATION = module_2.MSG_DESTINATION > module_2.MSG_DESTINATION = sys.stderr > # now the module_2 module has an updated reference for sys.stderr > ... > msg("a", "message") > ... > module_2.MSG_DESTINATION = old_MSG_DESTINATION > # normality restored I was about to write "use contextlib.redirect_sterr()", and noted my error just before hitting send. There is a tool in the stdlib that might work though: from unittest import mock with mock.patch("module_2.MSG_DESTINATION", sys.stderr): msg("a", "message") From __peter__ at web.de Mon Apr 5 07:14:09 2021 From: __peter__ at web.de (Peter Otten) Date: Mon, 5 Apr 2021 13:14:09 +0200 Subject: Using pytest, sometimes does not capture stderr In-Reply-To: References: Message-ID: On 05/04/2021 06:25, Cameron Simpson wrote: > If you truly need to test msg() _without_ the file= parameter, you could > monkey patch module_2: > > old_MSG_DESTINATION = module_2.MSG_DESTINATION > module_2.MSG_DESTINATION = sys.stderr > # now the module_2 module has an updated reference for sys.stderr > ... > msg("a", "message") > ... > module_2.MSG_DESTINATION = old_MSG_DESTINATION > # normality restored I was about to write "use contextlib.redirect_sterr()", and noted my error just before hitting send. There is a tool in the stdlib that might work though: from unittest import mock with mock.patch("module_2.MSG_DESTINATION", sys.stderr): msg("a", "message") From Bischoop at vimart.net Mon Apr 5 08:25:55 2021 From: Bischoop at vimart.net (Bischoop) Date: Mon, 5 Apr 2021 12:25:55 -0000 (UTC) Subject: Yield after the return in Python function. Message-ID: The return suspends the function execution so how is it that in below example I got output: def doit(): return 0 yield 0 print(doit()) From frank at chagford.com Mon Apr 5 08:38:14 2021 From: frank at chagford.com (Frank Millman) Date: Mon, 5 Apr 2021 14:38:14 +0200 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On 2021-04-05 2:25 PM, Bischoop wrote: > The return suspends the function execution so how is it that in below > example I got output: > > def doit(): > return 0 > yield 0 > > print(doit()) > The 'yield' in the function makes the function a 'generator' function. 'Calling' a generator function does not execute the function, it returns a generator object. You have to iterate over the generator object (e.g. by calling next() on it) in order to execute the function and return values. Frank Millman From frank at chagford.com Mon Apr 5 08:38:14 2021 From: frank at chagford.com (Frank Millman) Date: Mon, 5 Apr 2021 14:38:14 +0200 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On 2021-04-05 2:25 PM, Bischoop wrote: > The return suspends the function execution so how is it that in below > example I got output: > > def doit(): > return 0 > yield 0 > > print(doit()) > The 'yield' in the function makes the function a 'generator' function. 'Calling' a generator function does not execute the function, it returns a generator object. You have to iterate over the generator object (e.g. by calling next() on it) in order to execute the function and return values. Frank Millman From rob.cliffe at btinternet.com Mon Apr 5 12:20:13 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 5 Apr 2021 17:20:13 +0100 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> Message-ID: On 05/04/2021 00:47, dn via Python-list wrote: > On 04/04/2021 01.00, Rob Cliffe via Python-list wrote: >> >> On 03/04/2021 04:09, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: >>> On 2021-04-03 at 02:41:59 +0100, >>> Rob Cliffe via Python-list wrote: >>> >>>> ???? x1 = 42; y1 =? 3;? z1 = 10 >>>> ???? x2 = 41; y2 = 12; z2 = 9 >>>> ???? x3 =? 8;? y3 =? 8;? z3 = 10 >>>> (please imagine it's in a fixed font with everything neatly vertically >>>> aligned). >>>> This has see-at-a-glance STRUCTURE: the letters are aligned vertically >>>> and the "subscripts" horizontally.? Write it as 9 lines and it becomes >>>> an amorphous mess in which mistakes are harder to spot. >>> I agree that writing it as 9 lines is an accident waiting to happen, but >>> if you must see that structure, then go all in: >>> >>> ???? (x1, y1, z1) = (43,? 3, 10) >>> ???? (x2, y2, z2) = (41, 12,? 9) >>> ???? (x3, y3, z3) = ( 8,? 8, 10) >> Agreed, that is even easier to read.? (It would be kinda nice if the >> compiler could optimise the tuples away, for those of us who are >> paranoid about performance.) > I think I've read that the compiler is smart-enough to realise that the > RHS 'literal-tuples'?'tuple-literals' are being used as a 'mechanism', > and thus the inits are in-lined. Apologies: I can't find a web.ref. > Likely one of our colleagues, who is 'into' Python-internals, could > quickly clarify... > [snip] It doesn't appear to, at least not always.? In Python 3.8.3: from dis import dis def f(): x = 1 ; y = 2 def g(): (x,y) = (1,2) dis(f) dis(g) Output: ? 2?????????? 0 LOAD_CONST?????????????? 1 (1) ????????????? 2 STORE_FAST?????????????? 0 (x) ????????????? 4 LOAD_CONST?????????????? 2 (2) ????????????? 6 STORE_FAST?????????????? 1 (y) ????????????? 8 LOAD_CONST?????????????? 0 (None) ???????????? 10 RETURN_VALUE ? 3?????????? 0 LOAD_CONST?????????????? 1 ((1, 2)) ????????????? 2 UNPACK_SEQUENCE????????? 2 ????????????? 4 STORE_FAST?????????????? 0 (x) ????????????? 6 STORE_FAST?????????????? 1 (y) ????????????? 8 LOAD_CONST?????????????? 0 (None) ???????????? 10 RETURN_VALUE Thinking some more about this, this (removing the tuples) is not a straightforward optimisation to do. Example 1: ??? (x, y) = (y, x) is not the same as ??? x = y ; y = x Example 2: ??? L[v], y = a, f() is not the same as ??? L[v] = a ; y = f() if v is a global changed by f(). I guess it's safe if the RHS is a tuple containing only ??? constants, by which I think I mean number/string literals and built-in constants (None, True etc.). ??? variables (NOT expressions containing variables such as "z+1") which do not occur on the LHS ??? tuple/list/dictionary/set displays which themselves contain only the above, or nested displays which themselves ... etc. It appears (even though I use Windows where timing anything is a nightmare) that tuple versions are slightly slower. Rob Cliffe From rosuav at gmail.com Mon Apr 5 12:52:10 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Apr 2021 02:52:10 +1000 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> Message-ID: On Tue, Apr 6, 2021 at 2:32 AM Rob Cliffe via Python-list wrote: > > > > It doesn't appear to, at least not always. In Python 3.8.3: > from dis import dis > def f(): x = 1 ; y = 2 > def g(): (x,y) = (1,2) > dis(f) > dis(g) > > Output: > 2 0 LOAD_CONST 1 (1) > 2 STORE_FAST 0 (x) > 4 LOAD_CONST 2 (2) > 6 STORE_FAST 1 (y) > 8 LOAD_CONST 0 (None) > 10 RETURN_VALUE > 3 0 LOAD_CONST 1 ((1, 2)) > 2 UNPACK_SEQUENCE 2 > 4 STORE_FAST 0 (x) > 6 STORE_FAST 1 (y) > 8 LOAD_CONST 0 (None) > 10 RETURN_VALUE > Thinking some more about this, this (removing the tuples) is not a > straightforward optimisation to do. It's important to be aware of the semantics here. Saying "x = 1; y = 2" requires that x be set before 2 is calculated (imagine if it had been "y = x + 2" or something), whereas "x, y = 1, 2" has to do the opposite, fully evaluating the right hand side before doing any of the assignments. > I guess it's safe if the RHS is a tuple containing only > constants, by which I think I mean number/string literals and > built-in constants (None, True etc.). > variables (NOT expressions containing variables such as "z+1") > which do not occur on the LHS > tuple/list/dictionary/set displays which themselves contain only > the above, or nested displays which themselves ... etc. Nope, there's no "it's safe if" other than constants - which are already handled differently. If there is ANY Python code executed to calculate those values, it could depend on the previous assignments being completed. But the tuples aren't a problem here. They're a highly optimized way of grabbing multiple things at once. In the "x, y = 1, 2" case, the compiler would be free to implement it as "LOAD_CONST 1, LOAD_CONST 2, ROT_TWO, STORE_FAST x, STORE_FAST y" (equivalent to what you'd see for "x, y = y, x"), but it doesn't, so we can fairly confidently expect that the tuple is faster. BTW, if you want to play around with CPython's optimizations, there's another case to consider: def f(): x = y = 1 1 0 LOAD_CONST 1 (1) 2 DUP_TOP 4 STORE_FAST 0 (x) 6 STORE_FAST 1 (y) The constant gets loaded once (which is semantically important), and then duplicated on the stack, leaving two available for storing. Feel free to play around with different combinations here. For instance, "x, y = a, b = 1, 2" should now be unsurprising, but perhaps there'll be some more complicated examples that are interesting to explore. I love dis stuff. :) ChrisA From rob.cliffe at btinternet.com Mon Apr 5 13:18:50 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 5 Apr 2021 18:18:50 +0100 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> Message-ID: <6c1b74c3-daf5-5bf7-b1cf-ec36ed8ce195@btinternet.com> On 05/04/2021 17:52, Chris Angelico wrote: > On Tue, Apr 6, 2021 at 2:32 AM Rob Cliffe via Python-list > wrote: >> >> >> It doesn't appear to, at least not always. In Python 3.8.3: >> from dis import dis >> def f(): x = 1 ; y = 2 >> def g(): (x,y) = (1,2) >> dis(f) >> dis(g) >> >> Output: >> 2 0 LOAD_CONST 1 (1) >> 2 STORE_FAST 0 (x) >> 4 LOAD_CONST 2 (2) >> 6 STORE_FAST 1 (y) >> 8 LOAD_CONST 0 (None) >> 10 RETURN_VALUE >> 3 0 LOAD_CONST 1 ((1, 2)) >> 2 UNPACK_SEQUENCE 2 >> 4 STORE_FAST 0 (x) >> 6 STORE_FAST 1 (y) >> 8 LOAD_CONST 0 (None) >> 10 RETURN_VALUE >> Thinking some more about this, this (removing the tuples) is not a >> straightforward optimisation to do. > It's important to be aware of the semantics here. Saying "x = 1; y = > 2" requires that x be set before 2 is calculated (imagine if it had > been "y = x + 2" or something), whereas "x, y = 1, 2" has to do the > opposite, fully evaluating the right hand side before doing any of the > assignments. > >> I guess it's safe if the RHS is a tuple containing only >> constants, by which I think I mean number/string literals and >> built-in constants (None, True etc.). >> variables (NOT expressions containing variables such as "z+1") >> which do not occur on the LHS >> tuple/list/dictionary/set displays which themselves contain only >> the above, or nested displays which themselves ... etc. > Nope, there's no "it's safe if" other than constants - which are > already handled differently. How are constants handled differently (apart from using LOAD_CONST)?? See my dis example above. > If there is ANY Python code executed to > calculate those values, it could depend on the previous assignments > being completed. I don't understand.? What semantic difference could there be between ??? x = { 1: 2 } ?? ; ?? y = [3, 4]?? ;?? z = (5, 6) and ??? x, y, z = { 1:2 }, [3, 4], (5, 6) ?? Why is it not safe to convert the latter to the former? But I withdraw "set" from my "safe" list because I now realise that "set" could be reassigned. > > But the tuples aren't a problem here. They're a highly optimized way > of grabbing multiple things at once. In the "x, y = 1, 2" case, the > compiler would be free to implement it as "LOAD_CONST 1, LOAD_CONST 2, > ROT_TWO, STORE_FAST x, STORE_FAST y" (equivalent to what you'd see for > "x, y = y, x"), but it doesn't, so we can fairly confidently expect > that the tuple is faster. Not according to the Windows timings I mentioned in my previous post. > > BTW, if you want to play around with CPython's optimizations, there's > another case to consider: > > def f(): x = y = 1 > 1 0 LOAD_CONST 1 (1) > 2 DUP_TOP > 4 STORE_FAST 0 (x) > 6 STORE_FAST 1 (y) > > The constant gets loaded once (which is semantically important), and > then duplicated on the stack, leaving two available for storing. Feel > free to play around with different combinations here. For instance, > "x, y = a, b = 1, 2" should now be unsurprising, but perhaps there'll > be some more complicated examples that are interesting to explore. > > I love dis stuff. :) > > ChrisA Best wishes Rob Cliffe From rob.cliffe at btinternet.com Mon Apr 5 13:26:36 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 5 Apr 2021 18:26:36 +0100 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> Message-ID: On 05/04/2021 17:52, Chris Angelico wrote: I don't understand.? What semantic difference could there be between ??? x = { 1: 2 } ?? ; ?? y = [3, 4]?? ;?? z = (5, 6) and ??? x, y, z = { 1:2 }, [3, 4], (5, 6) ?? Why is it not safe to convert the latter to the former? But I withdraw "set" from my "safe" list because I now realise that "set" could be reassigned. Correction: set literals like {7,8} should still be OK as far as I can see. Rob Cliffe From rosuav at gmail.com Mon Apr 5 13:33:44 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Apr 2021 03:33:44 +1000 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: <6c1b74c3-daf5-5bf7-b1cf-ec36ed8ce195@btinternet.com> References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> <6c1b74c3-daf5-5bf7-b1cf-ec36ed8ce195@btinternet.com> Message-ID: On Tue, Apr 6, 2021 at 3:26 AM Rob Cliffe via Python-list wrote: > > > > On 05/04/2021 17:52, Chris Angelico wrote: > > On Tue, Apr 6, 2021 at 2:32 AM Rob Cliffe via Python-list > > wrote: > >> > >> > >> It doesn't appear to, at least not always. In Python 3.8.3: > >> from dis import dis > >> def f(): x = 1 ; y = 2 > >> def g(): (x,y) = (1,2) > >> dis(f) > >> dis(g) > >> > >> Output: > >> 2 0 LOAD_CONST 1 (1) > >> 2 STORE_FAST 0 (x) > >> 4 LOAD_CONST 2 (2) > >> 6 STORE_FAST 1 (y) > >> 8 LOAD_CONST 0 (None) > >> 10 RETURN_VALUE > >> 3 0 LOAD_CONST 1 ((1, 2)) > >> 2 UNPACK_SEQUENCE 2 > >> 4 STORE_FAST 0 (x) > >> 6 STORE_FAST 1 (y) > >> 8 LOAD_CONST 0 (None) > >> 10 RETURN_VALUE > >> Thinking some more about this, this (removing the tuples) is not a > >> straightforward optimisation to do. > > It's important to be aware of the semantics here. Saying "x = 1; y = > > 2" requires that x be set before 2 is calculated (imagine if it had > > been "y = x + 2" or something), whereas "x, y = 1, 2" has to do the > > opposite, fully evaluating the right hand side before doing any of the > > assignments. > > > >> I guess it's safe if the RHS is a tuple containing only > >> constants, by which I think I mean number/string literals and > >> built-in constants (None, True etc.). > >> variables (NOT expressions containing variables such as "z+1") > >> which do not occur on the LHS > >> tuple/list/dictionary/set displays which themselves contain only > >> the above, or nested displays which themselves ... etc. > > Nope, there's no "it's safe if" other than constants - which are > > already handled differently. > How are constants handled differently (apart from using LOAD_CONST)? > See my dis example above. > > If there is ANY Python code executed to > > calculate those values, it could depend on the previous assignments > > being completed. > I don't understand. What semantic difference could there be between > x = { 1: 2 } ; y = [3, 4] ; z = (5, 6) > and > x, y, z = { 1:2 }, [3, 4], (5, 6) > ? Why is it not safe to convert the latter to the former? > But I withdraw "set" from my "safe" list because I now realise that > "set" could be reassigned. Firstly, anything with any variable at all can involve a lookup, which can trigger arbitrary code (so "variables which do not occur on the LHS" is not sufficient). But in general, it's not safe to do too many order-of-evaluation changes when it's not actual literals. The only exception would be, as you put in this particular example, list/dict/set display, but NOT the name "set" (so you can't make an empty set this way). So basically, it's literals, and things that people treat like literals; otherwise, the order of evaluation has to be maintained. One good way to get an idea for which non-literals are "likely to be safe" (in scare quotes because, honestly, it's REALLY HARD to know what's actually safe) would be to look at ast.literal_eval; if it would accept the expression, it's quite probably safe. But even that isn't actually a perfect indication: >>> set = lambda: print("Wat") >>> eval("set()") Wat >>> ast.literal_eval("set()") set() Generally, unless you can mathematically prove that there's absolutely no way the result could possibly be different, it's best to maintain the correct order of evaluation. ChrisA From tjreedy at udel.edu Mon Apr 5 12:02:35 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 5 Apr 2021 12:02:35 -0400 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On 4/5/2021 8:25 AM, Bischoop wrote: > The return suspends the function execution so how is it that in below > example I got output: > > def doit(): > return 0 > yield 0 > > print(doit()) *Any* use of 'yield' in a function makes the function a generator function. This is a simple rule that any person, and just as important, any automated algorithm, can understand. If there were a 'dead (unreachable) code' exception, a reader or compiler would have to analyze each use of 'yield' and decide whether it is reachable or not. And we would have to decide whether just 1 or all 'yield's had to be reachable. In the following code, in 3.x, it is also clear that 'yield' is unreachable. >>> def f(): if False: yield 0 return 1 >>> f() But 'False' could be a more complex and less obvious but still equivalent expression, such and 'a and .... and not a'*. Is 'log(a) = 0' tautologically False? *While 'a and not a' == False in logic, in Python it might raise NameError. But that would still mean that it is never True, making 'yield 0' still unreachable. -- Terry Jan Reedy From khaldi.rami at gmail.com Mon Apr 5 13:19:27 2021 From: khaldi.rami at gmail.com (Rami Khaldi) Date: Mon, 5 Apr 2021 19:19:27 +0200 Subject: error on os.open API Message-ID: Hello, It seems that the os.open API cannot distinguish between a permission error and the fact that a directory cannot be opened like files. The following script reproduces the scenario (tested on Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on win32) : *import osos.system('mkdir someDirectory')open("someDirectory")* *Result:* *Traceback (most recent call last): File "", line 1, in PermissionError: [Errno 13] Permission denied: 'someDirectory'* Kind regards, Rami Khaldi From rosuav at gmail.com Mon Apr 5 13:53:56 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Apr 2021 03:53:56 +1000 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On Tue, Apr 6, 2021 at 3:46 AM Terry Reedy wrote: > *While 'a and not a' == False in logic, in Python it might raise > NameError. But that would still mean that it is never True, making > 'yield 0' still unreachable. > And even just the lookup can have side effects, if your code is pathologically stupid. >>> class Wat(dict): ... def __missing__(self, key): ... global count ... count -= 1 ... return count ... >>> count = 2 >>> eval("print(a and not a)", Wat(print=print)) True So Python can't afford to treat this as dead code. ChrisA From rosuav at gmail.com Mon Apr 5 13:57:48 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Apr 2021 03:57:48 +1000 Subject: error on os.open API In-Reply-To: References: Message-ID: On Tue, Apr 6, 2021 at 3:50 AM Rami Khaldi wrote: > > Hello, > > It seems that the os.open API cannot distinguish between a permission error > and the fact that a directory cannot be opened like files. > The following script reproduces the scenario (tested on Python 3.8.2 > (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on > win32) : > > > > *import osos.system('mkdir someDirectory')open("someDirectory")* > > > *Result:* > > > > *Traceback (most recent call last): File "", line 1, in > PermissionError: [Errno 13] Permission denied: 'someDirectory'* > Is this the actual code? You're not using os.open() here, you're using the built-in open() function. But also, it IS possible to open directories: >>> os.open(".", os.O_RDONLY) 3 Maybe you don't have permission to open that directory? ChrisA From maroloccio at gmail.com Mon Apr 5 14:01:42 2021 From: maroloccio at gmail.com (Marco Ippolito) Date: Mon, 5 Apr 2021 15:01:42 -0300 Subject: error on os.open API In-Reply-To: References: Message-ID: > It seems that the os.open API cannot distinguish between a permission error > and the fact that a directory cannot be opened like files. > The following script reproduces the scenario (tested on Python 3.8.2 > (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on > win32) : > > *import osos.system('mkdir someDirectory')open("someDirectory")* > > *Result:* > > *Traceback (most recent call last): File "", line 1, in > PermissionError: [Errno 13] Permission denied: 'someDirectory'* It errors as expected for me: ``` Traceback (most recent call last): File "/tmp/throwaway.py", line 4, in open("someDirectory") IsADirectoryError: [Errno 21] Is a directory: 'someDirectory' ``` Are you able to write a simple file instead? ``` import pathlib pathlib.Path("throwaway.txt").write_text("Test successful") ``` From tjreedy at udel.edu Mon Apr 5 15:00:53 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 5 Apr 2021 15:00:53 -0400 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On 4/5/2021 1:53 PM, Chris Angelico wrote: > On Tue, Apr 6, 2021 at 3:46 AM Terry Reedy wrote: >> *While 'a and not a' == False in logic, in Python it might raise >> NameError. But that would still mean that it is never True, making >> 'yield 0' still unreachable. When I wrote that, I knew I might be missing something else. > And even just the lookup can have side effects, if your code is > pathologically stupid. Or pathologically clever. >>>> class Wat(dict): > ... def __missing__(self, key): > ... global count > ... count -= 1 > ... return count '__missing__' is new since I learned Python. I barely took note of its addition and have never used it. Thanks for the example of what it can do. One could also make it randomly return True or False. >>>> count = 2 >>>> eval("print(a and not a)", Wat(print=print)) > True > > So Python can't afford to treat this as dead code. This gets to the point that logic and math are usually atemporal or at least static (as in a frozen snapshot), while computing is dynamic. In algebra, the canon is that all instances of a variable are replaced by the same value. Python *could* do the same for expresssions: load 'a' (in this case) once into a register or stack slot and use that value consistently throughout the expression. Replacing the eval with the following exec has the same effect. exec("tem=a; print(tem and not tem)", Wat(print=print)) # print False In this example, one could disable the binding with __setitem__ (resulting in printing 0), but python code cannot disable internal register or stack assignments. -- Terry Jan Reedy From rosuav at gmail.com Mon Apr 5 15:32:25 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Apr 2021 05:32:25 +1000 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On Tue, Apr 6, 2021 at 5:14 AM Terry Reedy wrote: > > On 4/5/2021 1:53 PM, Chris Angelico wrote: > > On Tue, Apr 6, 2021 at 3:46 AM Terry Reedy wrote: > >> *While 'a and not a' == False in logic, in Python it might raise > >> NameError. But that would still mean that it is never True, making > >> 'yield 0' still unreachable. > > When I wrote that, I knew I might be missing something else. > > > And even just the lookup can have side effects, if your code is > > pathologically stupid. > > Or pathologically clever. > > >>>> class Wat(dict): > > ... def __missing__(self, key): > > ... global count > > ... count -= 1 > > ... return count > > '__missing__' is new since I learned Python. I barely took note of its > addition and have never used it. Thanks for the example of what it can > do. One could also make it randomly return True or False. Yep. It could be done with a __getitem__ method instead; the point is that simply looking up a simple name can have side effects and/or be nondeterministic. > >>>> count = 2 > >>>> eval("print(a and not a)", Wat(print=print)) > > True > > > > So Python can't afford to treat this as dead code. > > This gets to the point that logic and math are usually atemporal or at > least static (as in a frozen snapshot), while computing is dynamic. In > algebra, the canon is that all instances of a variable are replaced by > the same value. Right - or rather, that in algebra, a "variable" is really a placeholder for a single, specific value, which may perhaps be unknown to us, but which has a very well-defined value. (At least, that's the case with most values, and with a convergent series. Things can break down a bit with a divergent series, but even then, analytic continuation can sometimes give you a well-defined value.) > Python *could* do the same for expresssions: load 'a' (in this case) > once into a register or stack slot and use that value consistently > throughout the expression. Replacing the eval with the following exec > has the same effect. True, but I think that this would be enough of a semantic change that Python should be very VERY careful about doing it. A *programmer* can choose to do this (and we see it sometimes as an optimization, since global lookups can be a lot more costly), but the interpreter shouldn't. > exec("tem=a; print(tem and not tem)", Wat(print=print)) > # print False > > In this example, one could disable the binding with __setitem__ > (resulting in printing 0), but python code cannot disable internal > register or stack assignments. > Indeed. That said, though, I think that any namespace in which referencing the same simple name more than once produces this sort of bizarre behaviour should be considered, well, unusual. NORMAL code won't have to concern itself with this. But the language spec doesn't require us to write normal code...... ChrisA From rob.cliffe at btinternet.com Mon Apr 5 15:35:32 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 5 Apr 2021 20:35:32 +0100 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> <6c1b74c3-daf5-5bf7-b1cf-ec36ed8ce195@btinternet.com> Message-ID: <8f95cf18-5861-7a43-1673-087125f05b2c@btinternet.com> On 05/04/2021 18:33, Chris Angelico wrote: > > Firstly, anything with any variable at all can involve a lookup, which > can trigger arbitrary code (so "variables which do not occur on the > LHS" is not sufficient). Interesting.? I was going to ask: How could you make a variable lookup trigger arbitrary code? Then I saw your post in the "Yield after the return in Python function" thread.? (Took me a while to understand it.)? So I ask: Can you make a variable lookup trigger arbitrary code, other than in code passed to eval/exec/compile? TIA Rob Cliffe From david at lowryduda.com Mon Apr 5 15:50:23 2021 From: david at lowryduda.com (David Lowry-Duda) Date: Mon, 5 Apr 2021 15:50:23 -0400 Subject: Matplotlib scale In-Reply-To: <7115e161-7e87-46f8-a1df-916e02389db4n@googlegroups.com> References: <7115e161-7e87-46f8-a1df-916e02389db4n@googlegroups.com> Message-ID: Hello, > I've created a code to run a 2D mapping using matplotlib from a .csv > file. > I've tried to set the maximum color (red) of the scale as 80% of the maximum value and not as the maximum value of my .csv file. > Does someone know how to modify that? If I understand what you're trying to do, I think you might want to investigate `clim` and `set_clim`. You can see more about this with `plt.clim?`, or https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.clim.html. I didn't sit down to create an example data file to try this out explicitly, but if you still have trouble I could try to make a workable example. - DLD From rosuav at gmail.com Mon Apr 5 16:05:36 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 6 Apr 2021 06:05:36 +1000 Subject: Friday Finking: initialising values and implied tuples In-Reply-To: <8f95cf18-5861-7a43-1673-087125f05b2c@btinternet.com> References: <2e70794d-2430-9136-09a1-42792e5a3aa4@DancesWithMice.info> <8c87805f-2586-cc2b-d167-238241753191@btinternet.com> <6c1b74c3-daf5-5bf7-b1cf-ec36ed8ce195@btinternet.com> <8f95cf18-5861-7a43-1673-087125f05b2c@btinternet.com> Message-ID: On Tue, Apr 6, 2021 at 5:36 AM Rob Cliffe via Python-list wrote: > > > > On 05/04/2021 18:33, Chris Angelico wrote: > > > > Firstly, anything with any variable at all can involve a lookup, which > > can trigger arbitrary code (so "variables which do not occur on the > > LHS" is not sufficient). > Interesting. I was going to ask: How could you make a variable lookup > trigger arbitrary code? > Then I saw your post in the "Yield after the return in Python function" > thread. (Took me a while to understand it.) So I ask: > Can you make a variable lookup trigger arbitrary code, other than in > code passed to eval/exec/compile? Hmm. When you're defining a class, the metaclass can set the namespace dictionary, does that count? class Wat(dict): def __getitem__(self, name): print("HEY! You're looking for %r!" % name) return 42 def __setitem__(self, name, value): print("Okay, I'm setting %r to %r." % (name, value)) # I'm totally not. class WutFace(type): @classmethod def __prepare__(cls, name, bases): return Wat() class Gotcha(metaclass=WutFace): a = b + 1 But for top-level code in a module, or for function locals, I'm not sure of any way to do this. It might be possible to mess with sys.modules[__name__] but the __dict__ attribute can't be changed, so you might need to first subclass the module. In general, though, even if you can't find an example of how to do it, you have to assume that it could happen somewhere, some time. (It might also be possible to mess with the builtins module, which would effectively catch any name lookups that aren't resolved locally or at module level. Again, not sure if that would count.) ChrisA From julien.hofmann.samsung at gmail.com Mon Apr 5 16:17:48 2021 From: julien.hofmann.samsung at gmail.com (Julien Hofmann) Date: Mon, 5 Apr 2021 13:17:48 -0700 (PDT) Subject: Matplotlib scale In-Reply-To: References: <7115e161-7e87-46f8-a1df-916e02389db4n@googlegroups.com> Message-ID: <8af74249-db8e-4227-9d21-1be3aeba74ban@googlegroups.com> Le lundi 5 avril 2021 ? 21:50:49 UTC+2, David Lowry-Duda a ?crit?: Thank you for your response! I just tried it but it doesn't make what I want. Bassically, I would like to not put any color for every values above 0.8 times the maximum value (ie. 488). Hence, the ''maximum'' color (ie. red) would correspond to 488 and not to 610 as currently. From tjol at tjol.eu Mon Apr 5 07:53:35 2021 From: tjol at tjol.eu (Thomas Jollans) Date: Mon, 5 Apr 2021 13:53:35 +0200 Subject: Matplotlib scale In-Reply-To: <7115e161-7e87-46f8-a1df-916e02389db4n@googlegroups.com> References: <7115e161-7e87-46f8-a1df-916e02389db4n@googlegroups.com> Message-ID: On 04/04/2021 20:57, Julien Hofmann wrote: > Hi everyone, > > > I've created a code to run a 2D mapping using matplotlib from a .csv file. > I've tried to set the maximum color (red) of the scale as 80% of the maximum value and not as the maximum value of my .csv file. > Does someone know how to modify that? Most (or all?) matplotlib functions and methods that take a cmap argument also take vmin and vmax arguments to specify the maximum and minimum values to assign colours to. https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contourf.html So adding vmax=0.8*np.max(z) to your contourf() call should do the trick. A couple of quick data visualisation tips: 1. if your colour map doesn't cover the full range of data, your colour bar should indicate this. Call fig.colorbar(...., extend='max'). 2. 'jet' is a *terrible* colour map and you should *never* use it. It distorts your data, making people see patterns that aren't there, and is all but useless in black & white printouts or to the colour-blind. This seminal talk from 2015 explains why the default Matplotlib colour maps are what they are: https://www.youtube.com/watch?v=xAoljeRJ3lU -- Thomas > I've tried different solution but it doesn't work. > > Thanks > > import os > import matplotlib.pyplot as plt > import pandas as pd > import numpy as np > from matplotlib import colorbar, colors > import matplotlib.tri as tri > > #os.chdir("C:/Users/Julien Hofmann/Desktop/Nano-indentation") > data = pd.read_csv("Cartographie.csv",sep=';') > > nb_lignes=21 > nb_colonnes=27 > > > fig = plt.figure(figsize=(15,12)) > ax = plt.subplot(1,1,1) > x=np.linspace(0,(data["x"][len(data["x"])-1]-data["x"][0])*1000,nb_colonnes) > y=np.linspace(0,(data["y"][len(data["y"])-1]-data["y"][0])*1000,nb_lignes) > X,Y=np.meshgrid(x,y) > > > z=np.array(data["Durete"]) > triang = tri.Triangulation(data["x"], data["y"]) > interpolator = tri.LinearTriInterpolator(triang, z) > Xi, Yi = np.meshgrid(x, y) > zi = interpolator(Xi, Yi) > cntr1 = ax.contourf(x, y, z.reshape(nb_lignes,nb_colonnes), levels=150, cmap="jet") > cbar = fig.colorbar(cntr1, ax=ax) > ax.axis('on') -- Dr. Thomas Jollans ? +49 6201 8759879 ? tjol at tjol.eu From avigross at verizon.net Mon Apr 5 19:22:09 2021 From: avigross at verizon.net (Avi Gross) Date: Mon, 5 Apr 2021 19:22:09 -0400 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: <012401d72a72$80387160$80a95420$@verizon.net> Terry: ... '__missing__' is new since I learned Python ... With so many new dunder variables added, I am wondering when some dunderhead comes up with: __mifflin__ The documented use paper is: https://theoffice.fandom.com/wiki/Dunder_Mifflin_Paper_Company -----Original Message----- From: Python-list On Behalf Of Terry Reedy Sent: Monday, April 5, 2021 3:01 PM To: python-list at python.org Subject: Re: Yield after the return in Python function. On 4/5/2021 1:53 PM, Chris Angelico wrote: > On Tue, Apr 6, 2021 at 3:46 AM Terry Reedy wrote: >> *While 'a and not a' == False in logic, in Python it might raise >> NameError. But that would still mean that it is never True, making >> 'yield 0' still unreachable. When I wrote that, I knew I might be missing something else. > And even just the lookup can have side effects, if your code is > pathologically stupid. Or pathologically clever. >>>> class Wat(dict): > ... def __missing__(self, key): > ... global count > ... count -= 1 > ... return count '__missing__' is new since I learned Python. I barely took note of its addition and have never used it. Thanks for the example of what it can do. One could also make it randomly return True or False. >>>> count = 2 >>>> eval("print(a and not a)", Wat(print=print)) > True > > So Python can't afford to treat this as dead code. This gets to the point that logic and math are usually atemporal or at least static (as in a frozen snapshot), while computing is dynamic. In algebra, the canon is that all instances of a variable are replaced by the same value. Python *could* do the same for expresssions: load 'a' (in this case) once into a register or stack slot and use that value consistently throughout the expression. Replacing the eval with the following exec has the same effect. exec("tem=a; print(tem and not tem)", Wat(print=print)) # print False In this example, one could disable the binding with __setitem__ (resulting in printing 0), but python code cannot disable internal register or stack assignments. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list From greg.ewing at canterbury.ac.nz Mon Apr 5 20:02:11 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 6 Apr 2021 12:02:11 +1200 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On 6/04/21 4:02 am, Terry Reedy wrote: > *Any* use of 'yield' in a function makes the function a generator > function.? ...? If there were a 'dead > (unreachable) code' exception, a reader or compiler would have to > analyze each use of 'yield' and decide whether it is reachable or not. It would also break existing code. An unreachable "yield" is sometimes used as a way to get a generator that doesn't yield anything. -- Greg From drsalists at gmail.com Mon Apr 5 22:36:03 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 5 Apr 2021 19:36:03 -0700 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On Mon, Apr 5, 2021 at 10:46 AM Terry Reedy wrote: > If there were a 'dead > (unreachable) code' exception, a reader or compiler would have to > analyze each use of 'yield' and decide whether it is reachable or not. > It's also subject to how hard the compiler feels like trying in any given release. Many compilers have simple unreachable code warnings. But to do a 100% accurate job of yield detection would be equivalent to the halting problem, which is a classic problem in computer science that cannot be solved 100% accurately in finite time. From tjreedy at udel.edu Mon Apr 5 21:42:34 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 5 Apr 2021 21:42:34 -0400 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On 4/5/2021 3:32 PM, Chris Angelico wrote: > On Tue, Apr 6, 2021 at 5:14 AM Terry Reedy wrote: >> Python *could* do the same for expresssions: load 'a' (in this case) >> once into a register or stack slot and use that value consistently >> throughout the expression. Replacing the eval with the following exec >> has the same effect. > > True, but I think that this would be enough of a semantic change that > Python should be very VERY careful about doing it. I consider it beyond a possibility. > A *programmer* can > choose to do this (and we see it sometimes as an optimization, since > global lookups can be a lot more costly), but the interpreter > shouldn't. Agreed. My interest is in elucidating the different between math and computing. The reason some prohibit rebinding bound names within a local context is to make code more like math. But this example should that Python code can effectively rebind names 'invisibly'. Side note: Since a loop is equivalent to a recursive tail call, I think rebinding once per loop should be considered to be consistent with no-rebinding. When an compiler or interpreter re-writes tail recursion as while looping, the result is the same. I don't believe in forcing people to take the detour of using recursion syntax, which for many is harder to write and understand. >> exec("tem=a; print(tem and not tem)", Wat(print=print)) >> # print False >> >> In this example, one could disable the binding with __setitem__ >> (resulting in printing 0), but python code cannot disable internal >> register or stack assignments. > Indeed. That said, though, I think that any namespace in which > referencing the same simple name more than once produces this sort of > bizarre behaviour should be considered, well, unusual. NORMAL code > won't have to concern itself with this. But the language spec doesn't > require us to write normal code...... I believe in the freedom to write 'strange code'. But my other interest is how to talk about Python and 'normal' code. -- Terry Jan Reedy From julien.hofmann.samsung at gmail.com Tue Apr 6 04:16:39 2021 From: julien.hofmann.samsung at gmail.com (Julien Hofmann) Date: Tue, 6 Apr 2021 01:16:39 -0700 (PDT) Subject: Matplotlib scale In-Reply-To: References: <7115e161-7e87-46f8-a1df-916e02389db4n@googlegroups.com> Message-ID: <4d734f25-38dc-4f32-afd9-f47f27e7c206n@googlegroups.com> Thank you for your response, and thank you for the different tips concerning visualisation. I'll improve it. I've tried to put vmin and vmax in contourf(). It works but the values above 80% of the maximum value still remain red which makes the cartography not really clear. I think I should in black, or white, every values above 80% of the maximum value. From pablogsal at gmail.com Tue Apr 6 07:27:23 2021 From: pablogsal at gmail.com (Pablo Galindo Salgado) Date: Tue, 6 Apr 2021 12:27:23 +0100 Subject: [RELEASE] The last Python 3.10 alpha (3.10.0a7) is available - Prepare for beta freeze Message-ID: Brrrrr..... do you feel that? That's the chill of *beta freeze* coming closer. Meanwhile, your friendly CPython release team doesn?t rest even on holidays and we have prepared a shiny new release for you: Python 3.10.0a7. **************************************************** Dear fellow core developer: This alpha is the last release before feature freeze (2021-05-03), so make sure that all new features and PEPs are landed in the master branch before we release the first beta. Please, be specially mindfully to check the CI and the buildbots, maybe even using the test-with-buildbots label in GitHub before merging so the release team don?t need to fix a bunch of reference leaks or platform-specific problems on the first beta release. **************************************************** *Go get the new alpha here:* https://www.python.org/downloads/release/python-3100a7/ *Python 3.10.0a7*Release Date: April 5, 2021 This is an early developer preview of Python 3.10 *Major new features of the 3.10 series, compared to 3.9* Python 3.10 is still in development. This release, 3.10.0a7 is the last of seven planned alpha releases. Alpha releases are intended to make it easier to test the current state of new features and bug fixes and to test the release process. During the alpha phase, features may be added up until the start of the beta phase (2021-05-03) and, if necessary, may be modified or deleted up until the release candidate phase (2021-10-04). Please keep in mind that this is a preview release and its use is not recommended for production environments. Many new features for Python 3.10 are still being planned and written. Among the new major new features and changes so far: PEP 623 ? Deprecate and prepare for the removal of the wstr member in PyUnicodeObject. PEP 604 ? Allow writing union types as X | Y PEP 612 ? Parameter Specification Variables PEP 626 ? Precise line numbers for debugging and other tools. bpo-38605: from __future__ import annotations (PEP 563) is now the default. PEP 618 ? Add Optional Length-Checking To zip. bpo-12782: Parenthesized context managers are now officially allowed. PEP 632 ? Deprecate distutils module. PEP 613 ? Explicit Type Aliases PEP 634 ? Structural Pattern Matching: Specification PEP 635 ? Structural Pattern Matching: Motivation and Rationale PEP 636 ? Structural Pattern Matching: Tutorial PEP 644 ? Require OpenSSL 1.1.1 or newer PEP 624 ? Remove Py_UNICODE encoder APIs PEP 597 ? Add optional EncodingWarning (Hey, fellow core developer, if a feature you find important is missing from this list, let Pablo know.) The next pre-release of Python 3.10 will be 3.10.0b1 ( the first beta release and feature freeze ), currently scheduled for Monday, 2021-05-03. *And now for something completely different* In physics, the twin paradox is a thought experiment in special relativity involving identical twins, one of whom makes a journey into space in a high-speed rocket and returns home to find that the twin who remained on Earth has aged more. This result appears puzzling because each twin sees the other twin as moving, and so, as a consequence of an incorrect and naive application of time dilation and the principle of relativity, each should paradoxically find the other to have aged less. However, this scenario can be resolved by realising that the travelling twin is undergoing acceleration, which makes him a non-inertial observer. In both views, there is no symmetry between the spacetime paths of the twins. Therefore, the twin paradox is not a paradox in the sense of a logical contradiction. Your friendly release team, Pablo Galindo Salgado @pablogsal Ned Deily @nad Steve Dower @steve.dower From rudy at matela.com.br Tue Apr 6 14:39:34 2021 From: rudy at matela.com.br (Rudy Matela) Date: Tue, 6 Apr 2021 15:39:34 -0300 Subject: [ANN] Free Python tutorial with exercises, cscx.org In-Reply-To: References: Message-ID: <20210406183934.o5v5quown2brfio4@zero.localdomain> On Fri, Apr 02, 2021 at 05:00:40AM +1100, Chris Angelico wrote: > On Fri, Apr 2, 2021 at 2:14 AM Rudy Matela wrote: > > Computer Science by Example https://cscx.org/ is a collection of short > > programming exercises. The site can automatically grade students' > > solutions and it accepts submissions in Python. > > What versions of Python does it support? The setup page is not clear. It supports Python 2 and 3. When you submit solutions to the exercises, the system looks at the hashbang (#!) to check whether you are using Python 2 or 3: #!/usr/bin/env python2 or #!/usr/bin/env python3 When none of these are present it defaults to Python 3. The examples in the tutorial section (https://cscx.org/programming-basics) are done so that they are compatible with both versions of the language. So if you have either 2 or 3, you'll be able to follow the tutorial and exercises. I'll add this clarification in the setup section and the FAQ later this week. From eryksun at gmail.com Tue Apr 6 21:38:06 2021 From: eryksun at gmail.com (Eryk Sun) Date: Tue, 6 Apr 2021 20:38:06 -0500 Subject: error on os.open API In-Reply-To: References: Message-ID: On 4/5/21, Rami Khaldi wrote: > > It seems that the os.open API cannot distinguish between a permission error > and the fact that a directory cannot be opened like files. > The following script reproduces the scenario (tested on Python 3.8.2 > (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on > win32) : In Windows, C open() calls WinAPI CreateFileW(), which defaults to opening regular files by default, i.e. it calls the NTAPI NtCreateFile() system function with the option FILE_NON_DIRECTORY_FILE. If the filesystem supports file streams (NTFS, ReFS), then the primary stream in a directory is an index stream of type $INDEX_ALLOCATION. (A directory can also have $DATA streams, but I digress.) An open can override the FILE_NON_DIRECTORY_FILE option by explicitly opening the index stream in the directory. For example: fd = os.open('someDirectory::$INDEX_ALLOCATION', 0) Alternatively, if CreateFileW() is called with the flag FILE_FLAG_BACKUP_SEMANTICS, then it does not use the NtCreateFile() option FILE_NON_DIRECTORY_FILE to limit the open type. This means directories can be opened. If you want to limit this case to just opening directories, add a trailing slash to the name. The Universal C Runtime has an undocumented flag for C open() -- _O_OBTAIN_DIR (0x2000) -- which makes it use the CreateFileW() flag FILE_FLAG_BACKUP_SEMANTICS. So you can also open "someDirectory" in Windows in Python 3.5 and later as follows: fd = os.open('someDirectory', 0x2000) or fd = os.open('someDirectory/', 0x2000) > *Traceback (most recent call last): File "", line 1, in > PermissionError: [Errno 13] Permission denied: 'someDirectory'* Unfortunately, there are 4 layers of errors when traversing the APIs involved here: Python <-> C <-> WinAPI <-> NTAPI. Important and helpful details are often lost. When an NtCreateFile() system call fails because an attempt was made to open a directory as a file, the status code explains itself: STATUS_FILE_IS_A_DIRECTORY (0xC00000BA). WinAPI CreateFileW() unhelpfully translates this status code to ERROR_ACCESS_DENIED (5). Finally, C open() translates the Windows error code as EACCES (13). Unfortunately the interpreter doesn't have enough information to know that it should raise IsADirectoryError instead of PermissionError. From jfong at ms4.hinet.net Wed Apr 7 02:47:56 2021 From: jfong at ms4.hinet.net (Jach Feng) Date: Tue, 6 Apr 2021 23:47:56 -0700 (PDT) Subject: [ANN] Free Python tutorial with exercises, cscx.org In-Reply-To: References: Message-ID: <0c8fe4b8-f059-4b51-b0b6-296d5e945c1en@googlegroups.com> Rudy Matela ? 2021?4?1? ?????11:13:03 [UTC+8] ?????? > Hello python-list members, > > I would like to announce the following educational project: > > Computer Science by Example https://cscx.org/ is a collection of short > programming exercises. The site can automatically grade students' > solutions and it accepts submissions in Python. > > The exercises start simple, then increase in difficulty and complexity > gradually. Here are some examples: > > * Print "Hello, World!": https://cscx.org/hello > * Add two numbers: https://cscx.org/add1 > * Compute the factorial of a number: https://cscx.org/factorial > * Compute the GCD of two numbers: https://cscx.org/gcd > * Solve the change-making problem: https://cscx.org/cash > > The website has a tutorial section covering Python's basics. > > I tried to make the content easy to use by instructors/lecturers, feel free > to use this with your students. The backend of the website is open source > and you can find it on > https://github.com/rudymatela/udge > > -- Rudy Is there any reason a student/beginner learn Python now start from Python2? --Jach From mohsen.owzar at gmail.com Wed Apr 7 04:35:31 2021 From: mohsen.owzar at gmail.com (Mohsen Owzar) Date: Wed, 7 Apr 2021 01:35:31 -0700 (PDT) Subject: How to access a variable from one tab in another tab of a notebook? Message-ID: Hi guys I have written a GUI with two tabs, Tab 1 and Tab 2 as shown below: On Tab 2 should be my settings parameters placed like "Val". If the user types a value greater than 5 in the entry field, the background color of Tab1 should be changed from light green to gray and the button "B1" should be disabled The problem is that I can't use the variable "val" from Tab2 in Tab 1, even if I have defined in every function and file as the global. It brought all the times the error message "val is not defined in Tab 1". You can run the top level "TabTop" to see my GUIs and uncomment the if part in Tab1 to see the error message. Any help is really appreciated Regards Mohsen # Filename: Tab1.py from tkinter import * def gen_t1(frame): f = LabelFrame(frame, text='f', bg='lightgreen') f.pack(expand=True, fill='both') b1 = Button(f, text='B1').pack() ## if val > 5: ## f_enabled = 'disabled' ## f['bg'] = 'lightgray' ## else: ## f_enabled = 'normal' ## f['bg'] = 'lightgreen' ###################################### # Filename: Tab2.py from tkinter import * def gen_t2(frame): def getValue(event): val = ent.get() print(val) lbl = Label(frame, text='Val').pack() ent = Entry(frame) ent.pack() ent.insert(0, '2') ent.bind('', getValue) The code for the top level is: ###################################### # Filename: TabTop from tkinter import * from tkinter import ttk from Tab1 import gen_t1 from Tab2 import gen_t2 global nb firstTime1 = 1 firstTime2 = 1 root = Tk() root.title('Tab-Tester') root.geometry('300x200') nb = ttk.Notebook(root) tab1 = Frame(nb) tab2 = Frame(nb) nb.add(tab1, text ='Tab 1') nb.add(tab2, text ='Tab 2') nb.pack(expand = 1, fill ="both") def on_tab_change(event): global firstTime1, firstTime2 tab = event.widget.tab('current','text') if tab == 'Tab 1': print('Tab 1') if firstTime1 == 1: gen_t1(tab1) firstTime1 = 0 elif tab == 'Tab 2': print('Tab 2') if firstTime2 == 1: gen_t2(tab2) firstTime2 = 0 nb.bind('<>', on_tab_change) root.mainloop() From rosuav at gmail.com Wed Apr 7 07:28:20 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 Apr 2021 21:28:20 +1000 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On Tue, Apr 6, 2021 at 12:40 PM Terry Reedy wrote: > > On 4/5/2021 3:32 PM, Chris Angelico wrote: > > > On Tue, Apr 6, 2021 at 5:14 AM Terry Reedy wrote: > >> Python *could* do the same for expresssions: load 'a' (in this case) > >> once into a register or stack slot and use that value consistently > >> throughout the expression. Replacing the eval with the following exec > >> has the same effect. > > > > True, but I think that this would be enough of a semantic change that > > Python should be very VERY careful about doing it. > > I consider it beyond a possibility. > I just realised that the whole eval/exec/namespace stuff is massive overkill. All you need is an object that is inconsistent in its boolification... >>> class Wat: ... def __bool__(self): ... self.state = not getattr(self, "state", False) ... return self.state ... >>> a = Wat() >>> a and not a True ChrisA From mal at europython.eu Wed Apr 7 07:40:25 2021 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 7 Apr 2021 13:40:25 +0200 Subject: Presenting our EuroPython 2021 logo Message-ID: <469e181d-3813-0d2d-7a5b-a66b05f61aa8@europython.eu> Over the last couple of weeks, we have worked with our designer Jessica Pe?a to come up with a logo which reflects both our desire to come together online during the pandemic and shows how well our community is interconnected around the world. Here's our brand new logo for EuroPython 2021 Online: https://blog.europython.eu/presenting-our-europython-2020-logo/ Hope you like it :-) We will soon make EuroPython 2021 merchandise available with the new logo in our EuroPython merch shop, so you can order t-shirts, sweatshirts, caps and mugs to show your support and love for the conference. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/presenting-our-europython-2020-logo/ Tweet: https://twitter.com/europython/status/1379750330347499520 Enjoy, -- EuroPython 2021 Team https://www.europython-society.org/ From stestagg at gmail.com Wed Apr 7 08:29:54 2021 From: stestagg at gmail.com (Stestagg) Date: Wed, 7 Apr 2021 13:29:54 +0100 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On Wed, Apr 7, 2021 at 12:31 PM Chris Angelico wrote: > > I just realised that the whole eval/exec/namespace stuff is massive > overkill. All you need is an object that is inconsistent in its > boolification... > > Somewhat related: https://bugs.python.org/issue42899 Steve From rosuav at gmail.com Wed Apr 7 08:42:04 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 7 Apr 2021 22:42:04 +1000 Subject: Yield after the return in Python function. In-Reply-To: References: Message-ID: On Wed, Apr 7, 2021 at 10:30 PM Stestagg wrote: > > > > On Wed, Apr 7, 2021 at 12:31 PM Chris Angelico wrote: >> >> >> I just realised that the whole eval/exec/namespace stuff is massive >> overkill. All you need is an object that is inconsistent in its >> boolification... >> > > Somewhat related: https://bugs.python.org/issue42899 > Yup. There are a very few edge cases where pathological behaviour can be optimized out. Sometimes, there's an alternative way to describe it (for example, containment is defined as "identity or equality"), but other times, you can't actually pin down the exact semantics in Python code. Or maybe it's possible, but really hard; the precise meaning of "yield from iterable" is quite the read - check out PEP 380, and notice that even just calling a method isn't as simple as it looks :) ChrisA From jf_byrnes at comcast.net Wed Apr 7 17:32:51 2021 From: jf_byrnes at comcast.net (Jim Byrnes) Date: Wed, 7 Apr 2021 16:32:51 -0500 Subject: pandas/jupyther notebook? Message-ID: linux mint 20 python 3.8 jupyter 1.0.0 jedi 0.18.0 I am teaching myself pandas/jupyter notebooks. The problem I am having is tab autocomplete seems to be working erratically. Googling shows that most people solve autocomplete problems by putting import pandas as pd %config Completer.use_jedi = False in the first cell. I have done that and still have the following problem. if I type: df = pd.read it will drop down a list box that has read_csv in it. If I then type: emp it will fill in employees.csv. If I type: df.h type head, but if I type: df['Gender'] = df['Gender'].ast it will not complete astype. I wonder if someone can tell me why this is happening and maybe how to fix it. Thanks, Jim From alan.gauld at yahoo.co.uk Wed Apr 7 19:49:37 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 8 Apr 2021 00:49:37 +0100 Subject: How to access a variable from one tab in another tab of a notebook? In-Reply-To: References: Message-ID: On 07/04/2021 09:35, Mohsen Owzar wrote: > The problem is that I can't use the variable "val" from Tab2 in Tab 1, > # Filename: Tab1.py > from tkinter import * > > def gen_t1(frame): > f = LabelFrame(frame, text='f', bg='lightgreen') > f.pack(expand=True, fill='both') > > b1 = Button(f, text='B1').pack() > > ## if val > 5: > # Filename: Tab2.py > from tkinter import * > > def gen_t2(frame): > def getValue(event): > val = ent.get() > print(val) Note that val is a local variable within a nested function. It only exists while the nested function is executing. As soon as the function ends val is thrown away. If you want the value of the entry you need to store it in a variable that is visible after the function exits (by returning it perhaps? or setting a global - ugly) But you still have the problem of making that visible to Tab1. You could import tab2 into tab1 and use Tab2.varName But this is why GUIs are often(usually?) built as a class because you can store all the state variables within the instance and access them from all the methods. You can do it with functions but you usually wind up with way too many globals to be comfortable. > from Tab1 import gen_t1 > from Tab2 import gen_t2 ... > def on_tab_change(event): > global firstTime1, firstTime2 > > tab = event.widget.tab('current','text') > if tab == 'Tab 1': > print('Tab 1') > if firstTime1 == 1: > gen_t1(tab1) > firstTime1 = 0 Probably nicer to use boolean values for firstTime1 and firstTime2, ie True and False rather than their numeric equivalents. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From mohsen.owzar at gmail.com Thu Apr 8 01:01:43 2021 From: mohsen.owzar at gmail.com (Mohsen Owzar) Date: Wed, 7 Apr 2021 22:01:43 -0700 (PDT) Subject: How to access a variable from one tab in another tab of a notebook? In-Reply-To: References: Message-ID: <00106d2d-c143-4faa-9b7f-e4e220bac807n@googlegroups.com> Alan Gauld schrieb am Donnerstag, 8. April 2021 um 02:05:01 UTC+2: > On 07/04/2021 09:35, Mohsen Owzar wrote: > > > The problem is that I can't use the variable "val" from Tab2 in Tab 1, > > # Filename: Tab1.py > > from tkinter import * > > > > def gen_t1(frame): > > f = LabelFrame(frame, text='f', bg='lightgreen') > > f.pack(expand=True, fill='both') > > > > b1 = Button(f, text='B1').pack() > > > > ## if val > 5: > > # Filename: Tab2.py > > from tkinter import * > > > > def gen_t2(frame): > > def getValue(event): > > val = ent.get() > > print(val) > Note that val is a local variable within a nested function. > It only exists while the nested function is executing. > As soon as the function ends val is thrown away. > > If you want the value of the entry you need to store it > in a variable that is visible after the function exits > (by returning it perhaps? or setting a global - ugly) > > But you still have the problem of making that visible > to Tab1. You could import tab2 into tab1 and use Tab2.varName > > But this is why GUIs are often(usually?) built as a class > because you can store all the state variables within > the instance and access them from all the methods. > > You can do it with functions but you usually wind up > with way too many globals to be comfortable. > > from Tab1 import gen_t1 > > from Tab2 import gen_t2 > ... > > def on_tab_change(event): > > global firstTime1, firstTime2 > > > > tab = event.widget.tab('current','text') > > if tab == 'Tab 1': > > print('Tab 1') > > if firstTime1 == 1: > > gen_t1(tab1) > > firstTime1 = 0 > Probably nicer to use boolean values for > firstTime1 and firstTime2, ie True and False > rather than their numeric equivalents. > > HTH > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos Hi Alan G, Thanks a lot for giving me this solution. Because I'm a newbie in Python and write programs since a couple of months, and I'm not so familiar with classes, would be very nice to give me a code, how I have to change my code into a class form. I tried without a class and I ran into problems that the defined frame and entry are not defined. Best regards Mohsen From alan.gauld at yahoo.co.uk Thu Apr 8 06:06:01 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 8 Apr 2021 11:06:01 +0100 Subject: How to access a variable from one tab in another tab of a notebook? In-Reply-To: <00106d2d-c143-4faa-9b7f-e4e220bac807n@googlegroups.com> References: <00106d2d-c143-4faa-9b7f-e4e220bac807n@googlegroups.com> Message-ID: On 08/04/2021 06:01, Mohsen Owzar wrote: >> But this is why GUIs are often(usually?) built as a class >> because you can store all the state variables within >> the instance and access them from all the methods. >> >> You can do it with functions but you usually wind up >> with way too many globals to be comfortable. > Because I'm a newbie in Python and write programs since > a couple of months, and I'm not so familiar with classes, OK, In that case you should probably read up on classes and play around with them to get used to the ideas of classes, objects and methods. You can carry on using functions but you will need to keep track of quite a lot of global variables which can get messy in bigger programs. Classes just keep things a bit more tidy. > would be very nice to give me a code, how I have to > change my code into a class form. > I tried without a class and I ran into problems that > the defined frame and entry are not defined. One of the problems in your code is that you are not storing references to the widgets you create. You are relying on the containment tree to store the references and keep them alive. But that makes it difficult to access. As a general rule of thumb if you are creating any widget that responds to events you should keep a reference to it - ie. create a variable. For example in your code you have a section like this: def gen_t2(frame): def getValue(event):... lbl = Label(frame, text='Val').pack() ent = Entry(frame) ent.pack() ent.insert(0, '2') ent.bind('', getValue) And you call it like this: if firstTime2 == 1: if firstTime2 == 1: gen_t2(tab2) firstTime2 = 0 gen_t2(tab2) firstTime2 = 0 Inside the function you store a reference to the Entry as ent. but ent disappears as soon as the function ends, you cannot use ent to access your entry outside the function. You need to return the widget like so: def gen_t2(frame): def getValue(event):... ... ent.bind('', getValue) return ent And then call it like: if firstTime2: entry_field = gen_t2(tab2) firstTime2 = False Now you can access your Entry field via the global variable entry_field. I suspect you should forget about the classes for now, focus on getting the functions to work, especially returning values and storing those in global variables that you can access from elsewhere. These principles are just as important when you get round to studying classes later. And remember that global variables in one module can be accessed from another module by importing the first module into the second and using the module name as prefix. import tab2 txt = tab2.entry_field.get() HTH You might also find the functions, namespaces and GUI sections of my tutorial useful (see below). -- 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 cseberino at gmail.com Thu Apr 8 10:05:16 2021 From: cseberino at gmail.com (cseb...@gmail.com) Date: Thu, 8 Apr 2021 07:05:16 -0700 (PDT) Subject: question about basics of creating a PROXY to MONITOR network activity Message-ID: <7afbeeb6-a1dd-4c7b-ba23-c560a5878f4dn@googlegroups.com> I'm trying to create an application that stands in between all connections to a remote server to monitor behavior for security and compliance reasons. I'm guessing I'll have all users log into this middle man proxy application instead of logging into the original website? Are there any frameworks or existing Python apps to help with this project? Thanks, Chris From rosuav at gmail.com Thu Apr 8 10:17:59 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Apr 2021 00:17:59 +1000 Subject: question about basics of creating a PROXY to MONITOR network activity In-Reply-To: <7afbeeb6-a1dd-4c7b-ba23-c560a5878f4dn@googlegroups.com> References: <7afbeeb6-a1dd-4c7b-ba23-c560a5878f4dn@googlegroups.com> Message-ID: On Fri, Apr 9, 2021 at 12:11 AM cseb... at gmail.com wrote: > > I'm trying to create an application that stands in between all > connections to a remote server to monitor behavior for > security and compliance reasons. > > I'm guessing I'll have all users log into this middle man proxy > application instead of logging into the original website? > > Are there any frameworks or existing Python apps to help > with this project? Yes, they'd all need to log in to the middle man. That has significant impact on things like SSL, unless you also own the remote server and can use the same certificate. I'd recommend looking into one of the well-known web app frameworks like Django or Flask, and making sure you know how all of that works. Also, you'd better be really REALLY sure that your monitoring is legal, ethical, and not deceptive. ChrisA From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Apr 8 10:41:15 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 8 Apr 2021 07:41:15 -0700 Subject: question about basics of creating a PROXY to MONITOR network activity In-Reply-To: References: <7afbeeb6-a1dd-4c7b-ba23-c560a5878f4dn@googlegroups.com> Message-ID: On 2021-04-09 at 00:17:59 +1000, Chris Angelico wrote: > Also, you'd better be really REALLY sure that your monitoring is > legal, ethical, and not deceptive. Not to mention *secure*. Your monitor increases the attack surface of the system as a whole. If I break into your monitor, can I recover passwords (yours, users, servers, etc.)? Can I snoop on traffic? Can I snoop metadata (like when which users are talking to which servers) not otherwise available on your network? From rosuav at gmail.com Thu Apr 8 13:44:58 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Apr 2021 03:44:58 +1000 Subject: question about basics of creating a PROXY to MONITOR network activity In-Reply-To: References: <7afbeeb6-a1dd-4c7b-ba23-c560a5878f4dn@googlegroups.com> Message-ID: On Fri, Apr 9, 2021 at 12:42 AM <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > On 2021-04-09 at 00:17:59 +1000, > Chris Angelico wrote: > > > Also, you'd better be really REALLY sure that your monitoring is > > legal, ethical, and not deceptive. > > Not to mention *secure*. Your monitor increases the attack surface of > the system as a whole. If I break into your monitor, can I recover > passwords (yours, users, servers, etc.)? Can I snoop on traffic? Can I > snoop metadata (like when which users are talking to which servers) not > otherwise available on your network? Is it even possible to be secure in that way? This is, by definition, a MITM, and in order to be useful, it *will* have to decrypt everything. So if someone compromises the monitor, they get everything. But try asking those questions minus the "break into the monitor" part. Does the mere presence of the monitor mean that someone *else* can start monitoring too? TBH though, I think the other questions are going to largely shut this down. ChrisA From jf_byrnes at comcast.net Thu Apr 8 16:39:24 2021 From: jf_byrnes at comcast.net (Jim Byrnes) Date: Thu, 8 Apr 2021 15:39:24 -0500 Subject: pandas/jupyther notebook? In-Reply-To: References: Message-ID: On 4/7/21 4:32 PM, Jim Byrnes wrote: > linux mint 20 > python 3.8 > jupyter 1.0.0 > jedi 0.18.0 > > I am teaching myself pandas/jupyter notebooks. The problem I am having > is tab autocomplete seems to be working erratically. > > Googling shows that most people solve autocomplete problems by putting > > ?import pandas as pd > %config Completer.use_jedi = False > > in the first cell. I have done that and still have the following problem. > > if I type: df = pd.read it will drop down a list box that has > read_csv in it. If I then type: emp it will fill in employees.csv. > If I type: df.h type head, but if I type: > > df['Gender'] = df['Gender'].ast? it will not complete astype. > > I wonder if someone can tell me why this is happening and maybe how to > fix it. > > Thanks,? Jim > After some further digging I found that this line added to the notebook fixed the problem for me. %config IPCompleter.greedy=True Regards, Jim From f20170548 at pilani.bits-pilani.ac.in Thu Apr 8 18:22:22 2021 From: f20170548 at pilani.bits-pilani.ac.in (VISHESH MANGLA) Date: Thu, 8 Apr 2021 15:22:22 -0700 (PDT) Subject: PyWin32 : When using Microsoft Word in code , opening it doesn't work Message-ID: <11552c19-ac37-4f4e-b718-de371224e569n@googlegroups.com> Please help with this . https://github.com/mhammond/pywin32/issues/1689 From rosuav at gmail.com Thu Apr 8 18:32:04 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 9 Apr 2021 08:32:04 +1000 Subject: PyWin32 : When using Microsoft Word in code , opening it doesn't work In-Reply-To: <11552c19-ac37-4f4e-b718-de371224e569n@googlegroups.com> References: <11552c19-ac37-4f4e-b718-de371224e569n@googlegroups.com> Message-ID: On Fri, Apr 9, 2021 at 8:26 AM VISHESH MANGLA wrote: > > Please help with this . > > https://github.com/mhammond/pywin32/issues/1689 Did you follow the instructions in the first line of the issue, saying how you should seek support? ChrisA From f20170548 at pilani.bits-pilani.ac.in Thu Apr 8 18:35:41 2021 From: f20170548 at pilani.bits-pilani.ac.in (VISHESH MANGLA) Date: Thu, 8 Apr 2021 15:35:41 -0700 (PDT) Subject: PyWin32 : When using Microsoft Word in code , opening it doesn't work In-Reply-To: References: <11552c19-ac37-4f4e-b718-de371224e569n@googlegroups.com> Message-ID: On Friday, April 9, 2021 at 4:02:37 AM UTC+5:30, Chris Angelico wrote: > On Fri, Apr 9, 2021 at 8:26 AM VISHESH MANGLA > wrote: > > > > Please help with this . > > > > https://github.com/mhammond/pywin32/issues/1689 > Did you follow the instructions in the first line of the issue, saying > how you should seek support? > > ChrisA obviously I did but their mailing list requires them to respond to your email when they haven't done since I made the request 1 month back.I did that atleast thrice. So I 'm stuck. From tjreedy at udel.edu Thu Apr 8 18:33:52 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 8 Apr 2021 18:33:52 -0400 Subject: PyWin32 : When using Microsoft Word in code , opening it doesn't work In-Reply-To: <11552c19-ac37-4f4e-b718-de371224e569n@googlegroups.com> References: <11552c19-ac37-4f4e-b718-de371224e569n@googlegroups.com> Message-ID: On 4/8/2021 6:22 PM, VISHESH MANGLA wrote: > Please help with this . > > https://github.com/mhammond/pywin32/issues/1689 Closed by Mark Hammond as a support requrest rather than a bug report or feature request. -- Terry Jan Reedy From f20170548 at pilani.bits-pilani.ac.in Thu Apr 8 18:41:12 2021 From: f20170548 at pilani.bits-pilani.ac.in (VISHESH MANGLA) Date: Thu, 8 Apr 2021 15:41:12 -0700 (PDT) Subject: PyWin32 : When using Microsoft Word in code , opening it doesn't work In-Reply-To: References: <11552c19-ac37-4f4e-b718-de371224e569n@googlegroups.com> Message-ID: On Friday, April 9, 2021 at 4:05:52 AM UTC+5:30, VISHESH MANGLA wrote: > On Friday, April 9, 2021 at 4:02:37 AM UTC+5:30, Chris Angelico wrote: > > On Fri, Apr 9, 2021 at 8:26 AM VISHESH MANGLA > > wrote: > > > > > > Please help with this . > > > > > > https://github.com/mhammond/pywin32/issues/1689 > > Did you follow the instructions in the first line of the issue, saying > > how you should seek support? > > > > ChrisA > obviously I did but their mailing list requires them to respond to your email when they haven't done since I made the request 1 month back.I did that atleast thrice. So I 'm stuck. which* From python at mrabarnett.plus.com Thu Apr 8 19:09:10 2021 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 9 Apr 2021 00:09:10 +0100 Subject: PyWin32 : When using Microsoft Word in code , opening it doesn't work In-Reply-To: References: <11552c19-ac37-4f4e-b718-de371224e569n@googlegroups.com> Message-ID: On 2021-04-08 23:35, VISHESH MANGLA wrote: > On Friday, April 9, 2021 at 4:02:37 AM UTC+5:30, Chris Angelico wrote: >> On Fri, Apr 9, 2021 at 8:26 AM VISHESH MANGLA >> wrote: >> > >> > Please help with this . >> > >> > https://github.com/mhammond/pywin32/issues/1689 >> Did you follow the instructions in the first line of the issue, saying >> how you should seek support? >> >> ChrisA > obviously I did but their mailing list requires them to respond to your email when they haven't done since I made the request 1 month back.I did that atleast thrice. So I 'm stuck. > I found some documentation: https://docs.microsoft.com/en-us/office/vba/api/word.document It looks like there's no "SaveAs" method, but there's a "SaveAs2" method. Try that instead. From f20170548 at pilani.bits-pilani.ac.in Thu Apr 8 19:15:37 2021 From: f20170548 at pilani.bits-pilani.ac.in (VISHESH MANGLA) Date: Thu, 8 Apr 2021 16:15:37 -0700 (PDT) Subject: PyWin32 : When using Microsoft Word in code , opening it doesn't work In-Reply-To: References: <11552c19-ac37-4f4e-b718-de371224e569n@googlegroups.com> Message-ID: <65d07330-9ac4-438a-9944-7e6efa74d494n@googlegroups.com> On Friday, April 9, 2021 at 4:42:38 AM UTC+5:30, MRAB wrote: > On 2021-04-08 23:35, VISHESH MANGLA wrote: > > On Friday, April 9, 2021 at 4:02:37 AM UTC+5:30, Chris Angelico wrote: > >> On Fri, Apr 9, 2021 at 8:26 AM VISHESH MANGLA > >> wrote: > >> > > >> > Please help with this . > >> > > >> > https://github.com/mhammond/pywin32/issues/1689 > >> Did you follow the instructions in the first line of the issue, saying > >> how you should seek support? > >> > >> ChrisA > > obviously I did but their mailing list requires them to respond to your email when they haven't done since I made the request 1 month back.I did that atleast thrice. So I 'm stuck. > > > I found some documentation: > > https://docs.microsoft.com/en-us/office/vba/api/word.document > > It looks like there's no "SaveAs" method, but there's a "SaveAs2" > method. Try that instead. the code is running , it's working, what do you say that? There must be `SaveAs` From python at mrabarnett.plus.com Thu Apr 8 20:19:04 2021 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 9 Apr 2021 01:19:04 +0100 Subject: PyWin32 : When using Microsoft Word in code , opening it doesn't work In-Reply-To: <65d07330-9ac4-438a-9944-7e6efa74d494n@googlegroups.com> References: <11552c19-ac37-4f4e-b718-de371224e569n@googlegroups.com> <65d07330-9ac4-438a-9944-7e6efa74d494n@googlegroups.com> Message-ID: <116ac4a3-2692-9223-fa34-faad32410808@mrabarnett.plus.com> On 2021-04-09 00:15, VISHESH MANGLA wrote: > On Friday, April 9, 2021 at 4:42:38 AM UTC+5:30, MRAB wrote: >> On 2021-04-08 23:35, VISHESH MANGLA wrote: >> > On Friday, April 9, 2021 at 4:02:37 AM UTC+5:30, Chris Angelico wrote: >> >> On Fri, Apr 9, 2021 at 8:26 AM VISHESH MANGLA >> >> wrote: >> >> > >> >> > Please help with this . >> >> > >> >> > https://github.com/mhammond/pywin32/issues/1689 >> >> Did you follow the instructions in the first line of the issue, saying >> >> how you should seek support? >> >> >> >> ChrisA >> > obviously I did but their mailing list requires them to respond to your email when they haven't done since I made the request 1 month back.I did that atleast thrice. So I 'm stuck. >> > >> I found some documentation: >> >> https://docs.microsoft.com/en-us/office/vba/api/word.document >> >> It looks like there's no "SaveAs" method, but there's a "SaveAs2" >> method. Try that instead. > the code is running , it's working, what do you say that? There must be `SaveAs` > Why, then, does the traceback say "AttributeError: Open.SaveAs"? From tjreedy at udel.edu Thu Apr 8 20:17:57 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 8 Apr 2021 20:17:57 -0400 Subject: PyWin32 : When using Microsoft Word in code , opening it doesn't work In-Reply-To: References: <11552c19-ac37-4f4e-b718-de371224e569n@googlegroups.com> Message-ID: On 4/8/2021 6:35 PM, VISHESH MANGLA wrote: > On Friday, April 9, 2021 at 4:02:37 AM UTC+5:30, Chris Angelico wrote: >> On Fri, Apr 9, 2021 at 8:26 AM VISHESH MANGLA >> wrote: >>> >>> Please help with this . >>> >>> https://github.com/mhammond/pywin32/issues/1689 >> Did you follow the instructions in the first line of the issue, saying >> how you should seek support? >> >> ChrisA > obviously I did Not at all obvious that you did so. People routinely seek help without first doing what they should do first. > but their mailing list > requires them to respond to your email > when they haven't done since I made the request > 1 month back.I did that atleast thrice. So I 'm stuck. Next time, help youself and us and say this ;-). -- Terry Jan Reedy From mohsen.owzar at gmail.com Fri Apr 9 00:14:16 2021 From: mohsen.owzar at gmail.com (Mohsen Owzar) Date: Thu, 8 Apr 2021 21:14:16 -0700 (PDT) Subject: How to access a variable from one tab in another tab of a notebook? In-Reply-To: References: <00106d2d-c143-4faa-9b7f-e4e220bac807n@googlegroups.com> Message-ID: <143ac892-e671-43ea-ae19-e96da3702b87n@googlegroups.com> Alan Gauld schrieb am Donnerstag, 8. April 2021 um 15:40:19 UTC+2: > On 08/04/2021 06:01, Mohsen Owzar wrote: > > >> But this is why GUIs are often(usually?) built as a class > >> because you can store all the state variables within > >> the instance and access them from all the methods. > >> > >> You can do it with functions but you usually wind up > >> with way too many globals to be comfortable. > > Because I'm a newbie in Python and write programs since > > a couple of months, and I'm not so familiar with classes, > OK, In that case you should probably read up on classes > and play around with them to get used to the ideas of > classes, objects and methods. > > You can carry on using functions but you will need to > keep track of quite a lot of global variables which > can get messy in bigger programs. Classes just keep > things a bit more tidy. > > would be very nice to give me a code, how I have to > > change my code into a class form. > > I tried without a class and I ran into problems that > > the defined frame and entry are not defined. > One of the problems in your code is that you are not > storing references to the widgets you create. You are > relying on the containment tree to store the references > and keep them alive. But that makes it difficult to > access. As a general rule of thumb if you are creating > any widget that responds to events you should keep > a reference to it - ie. create a variable. > > For example in your code you have a section like this: > > def gen_t2(frame): > def getValue(event):... > lbl = Label(frame, text='Val').pack() > > ent = Entry(frame) > ent.pack() > ent.insert(0, '2') > > ent.bind('', getValue) > And you call it like this: > > if firstTime2 == 1: if firstTime2 == 1: > gen_t2(tab2) > firstTime2 = 0 > > gen_t2(tab2) > firstTime2 = 0 > > Inside the function you store a reference to the Entry as ent. > but ent disappears as soon as the function ends, you cannot > use ent to access your entry outside the function. > You need to return the widget like so: > > def gen_t2(frame): > def getValue(event):... > > ... > ent.bind('', getValue) > return ent > > And then call it like: > > if firstTime2: > entry_field = gen_t2(tab2) > firstTime2 = False > > Now you can access your Entry field via the global > variable entry_field. > > I suspect you should forget about the classes for now, focus > on getting the functions to work, especially returning values > and storing those in global variables that you can access from > elsewhere. These principles are just as important when you > get round to studying classes later. > > And remember that global variables in one module can be > accessed from another module by importing the first module > into the second and using the module name as prefix. > > import tab2 > > txt = tab2.entry_field.get() > > HTH > > You might also find the functions, namespaces and GUI sections > of my tutorial useful (see below). > -- > 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 Hello Alan, I'm so happy that you have so good explained to me, what I have to do. Now, it is a bit clearer how I can use the variables or references in another modules. I try to follow your suggestions to see if I can solve my problem. Again thank you very much. Best regards Mohsen From tjol at tjol.eu Fri Apr 9 04:29:44 2021 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 9 Apr 2021 10:29:44 +0200 Subject: pandas/jupyther notebook? In-Reply-To: References: Message-ID: <3869f071-19b6-fdcf-0fec-f1450a226023@tjol.eu> On 07/04/2021 23:32, Jim Byrnes wrote: > linux mint 20 > python 3.8 > jupyter 1.0.0 > jedi 0.18.0 > > I am teaching myself pandas/jupyter notebooks. The problem I am having > is tab autocomplete seems to be working erratically. > > Googling shows that most people solve autocomplete problems by putting > > ?import pandas as pd > %config Completer.use_jedi = False One solution is to downgrade to jedi 0.17.2 > > in the first cell. I have done that and still have the following problem. > > if I type: df = pd.read it will drop down a list box that has > read_csv in it. If I then type: emp it will fill in > employees.csv. If I type: df.h type head, but if I type: > > df['Gender'] = df['Gender'].ast? it will not complete astype. > > I wonder if someone can tell me why this is happening and maybe how to > fix it. > > Thanks,? Jim > -- Dr. Thomas Jollans m ? +49 6201 8759879 e ? tjol at tjol.eu From petite.abeille at gmail.com Fri Apr 9 10:59:12 2021 From: petite.abeille at gmail.com (Petite Abeille) Date: Fri, 9 Apr 2021 16:59:12 +0200 Subject: python text://protocol client? Message-ID: Hello, Would you know of any python text://protocol client? Or server? Thanks in advance. [1] https://textprotocol.org [2] https://github.com/textprotocol/public [3] https://github.com/textprotocol/publictext From jf_byrnes at comcast.net Fri Apr 9 09:19:11 2021 From: jf_byrnes at comcast.net (Jim Byrnes) Date: Fri, 9 Apr 2021 08:19:11 -0500 Subject: pandas/jupyther notebook? In-Reply-To: <3869f071-19b6-fdcf-0fec-f1450a226023@tjol.eu> References: <3869f071-19b6-fdcf-0fec-f1450a226023@tjol.eu> Message-ID: On 4/9/21 3:29 AM, Thomas Jollans wrote: > On 07/04/2021 23:32, Jim Byrnes wrote: >> linux mint 20 >> python 3.8 >> jupyter 1.0.0 >> jedi 0.18.0 >> >> I am teaching myself pandas/jupyter notebooks. The problem I am having >> is tab autocomplete seems to be working erratically. >> >> Googling shows that most people solve autocomplete problems by putting >> >> ?import pandas as pd >> %config Completer.use_jedi = False > > One solution is to downgrade to jedi 0.17.2 > > >> That did not work for me. I ended up upgrading jupyter, ipython and jedi to the latest versions via pip and adding %config IPCompleter.greedy=True in the first cell of the notebook. Regards, Jim From arishmallickmp2 at gmail.com Fri Apr 9 01:33:59 2021 From: arishmallickmp2 at gmail.com (arishmallickmp2 at gmail.com) Date: Fri, 9 Apr 2021 11:03:59 +0530 Subject: Problem in uninstalling python Message-ID: I am encountering problem in uninstalling python. Please help me in this. Sent from [1]Mail for Windows 10 References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From pbryan at anode.ca Fri Apr 9 11:32:34 2021 From: pbryan at anode.ca (Paul Bryan) Date: Fri, 09 Apr 2021 08:32:34 -0700 Subject: Problem in uninstalling python In-Reply-To: References: Message-ID: Please describe your problem in detail. Paul On Fri, 2021-04-09 at 11:03 +0530, arishmallickmp2 at gmail.com wrote: > ?? I am encountering problem in uninstalling python. Please help me > in this. > > > > ?? Sent from [1]Mail for Windows 10 > > > > References > > ?? Visible links > ?? 1. https://go.microsoft.com/fwlink/?LinkId=550986 From ikorot01 at gmail.com Fri Apr 9 11:48:58 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Fri, 9 Apr 2021 10:48:58 -0500 Subject: Problem in uninstalling python In-Reply-To: References: Message-ID: Hi, On Fri, Apr 9, 2021 at 10:35 AM Paul Bryan wrote: > > Please describe your problem in detail. > > Paul > > > On Fri, 2021-04-09 at 11:03 +0530, arishmallickmp2 at gmail.com wrote: > > I am encountering problem in uninstalling python. Please help me > > in this. I presume you tried to send a screenshot to the list... Please don't!! The list will DROP ANY AND ALL attachments. Rather cut-and-paste any error you receive to the body of your message. Thank you. > > > > > > > > Sent from [1]Mail for Windows 10 > > > > > > > > References > > > > Visible links > > 1. https://go.microsoft.com/fwlink/?LinkId=550986 > > -- > https://mail.python.org/mailman/listinfo/python-list From * at eli.users.panix.com Fri Apr 9 13:08:25 2021 From: * at eli.users.panix.com (Eli the Bearded) Date: Fri, 9 Apr 2021 17:08:25 +0000 (UTC) Subject: python text://protocol client? References: Message-ID: In comp.lang.python, Petite Abeille wrote: > Would you know of any python text://protocol client? Or server? The whole thing was started (judging by git commits) about a month ago. https://github.com/textprotocol?tab=overview&from=2021-03-01&to=2021-03-31 March 7: First repository I suspect no one has cared to reimplement it any language since then. > Thanks in advance. > > [1] https://textprotocol.org I have read that and I don't understand what one does with this protocol or why. > [2] https://github.com/textprotocol/public > [3] https://github.com/textprotocol/publictext The Lua code is not long, under 2k LOC. Why don't you just study it and create your own python version if you care? Elijah ------ has not been given enough reason to care to read the code From petite.abeille at gmail.com Fri Apr 9 14:28:08 2021 From: petite.abeille at gmail.com (Petite Abeille) Date: Fri, 9 Apr 2021 20:28:08 +0200 Subject: python text://protocol client? In-Reply-To: References: Message-ID: <5D1C5087-1873-4A00-8A62-7076E7F2D8FE@gmail.com> > On Apr 9, 2021, at 19:08, Eli the Bearded <*@eli.users.panix.com> wrote: > > The Lua code is not long, under 2k LOC. Shortish indeed. Wonder how much python code that would translates into. To be found out. From mats at wichmann.us Fri Apr 9 14:34:53 2021 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 9 Apr 2021 12:34:53 -0600 Subject: python text://protocol client? In-Reply-To: References: Message-ID: On 4/9/21 11:08 AM, Eli the Bearded wrote: > In comp.lang.python, Petite Abeille wrote: >> Would you know of any python text://protocol client? Or server? > > The whole thing was started (judging by git commits) about a month ago. > > https://github.com/textprotocol?tab=overview&from=2021-03-01&to=2021-03-31 > > March 7: First repository > > I suspect no one has cared to reimplement it any language since then. seems to be part of "multiformats" work, Juan Benet's things that Protocol Labs are working on for IPFS. I've used the multihash Python package and it's pretty nice. From petite.abeille at gmail.com Fri Apr 9 14:41:27 2021 From: petite.abeille at gmail.com (Petite Abeille) Date: Fri, 9 Apr 2021 20:41:27 +0200 Subject: python text://protocol client? In-Reply-To: References: Message-ID: <919FCF24-922B-45F3-ADF7-B735CB0852D8@gmail.com> > On Apr 9, 2021, at 20:34, Mats Wichmann wrote: > > seems to be part of "multiformats" work, Multiformats, yes! https://multiformats.io Specifically, multiaddr in this case: https://github.com/multiformats/multiaddr + service discovery: https://en.wikipedia.org/wiki/Zero-configuration_networking#DNS-SD ?0? From josephh.roffey at gmail.com Sat Apr 10 06:57:12 2021 From: josephh.roffey at gmail.com (Joseph Roffey) Date: Sat, 10 Apr 2021 03:57:12 -0700 (PDT) Subject: HELP Please, Python Program Help Message-ID: Hi, Im looking for some help with my program, I have been set a task to make a Strain Calculator. I need it to input two numbers, choosing either Metres or Inches for the 'Change in Length' divided by the 'Original Length' which can also be in Metres or Inches, the out put number also needs to give an option for the answer to be in metres or inches. this is what i have come up with so far... txt = "Strain Calculator" x = txt.title() print(x) # This function divides two numbers def divide(x, y): return x / y print("Select operation.") print("1.Strain") while True: # Take input from the user choice = input("Enter choice(1): ") # Check if choice is one of the five options if choice in ('1'): num1 = float(input("Change in Length: ")) num2 = float(input("Original Length: ")) if choice == '1': print(num1, "/", num2, "=", divide(num1, num2)) break else: print("Invalid Input") From PythonList at DancesWithMice.info Sat Apr 10 09:11:33 2021 From: PythonList at DancesWithMice.info (dn) Date: Sun, 11 Apr 2021 01:11:33 +1200 Subject: HELP Please, Python Program Help In-Reply-To: References: Message-ID: <2adc5203-0cc8-dbb4-b0d6-9a2a36e60904@DancesWithMice.info> On 10/04/2021 22.57, Joseph Roffey wrote: > Hi, Im looking for some help with my program, I have been set a task to make a Strain Calculator. I need it to input two numbers, choosing either Metres or Inches for the 'Change in Length' divided by the 'Original Length' which can also be in Metres or Inches, the out put number also needs to give an option for the answer to be in metres or inches. > > this is what i have come up with so far... What is the problem? > txt = "Strain Calculator" > x = txt.title() what is the above/ > print(x) > > # This function divides two numbers > def divide(x, y): > return x / y Why use a function instead of operating in-line? -- Regards, =dn From fabiofz at gmail.com Sat Apr 10 09:58:50 2021 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Sat, 10 Apr 2021 10:58:50 -0300 Subject: PyDev 8.3.0 Released In-Reply-To: <8bba981affaccf70230e271b43a6e3e26c07e8c8.news@pydev.p.sourceforge.net> References: <8bba981affaccf70230e271b43a6e3e26c07e8c8.news@pydev.p.sourceforge.net> Message-ID: PyDev 8.3.0 Release Highlights - *Java 11* is now required to run PyDev. - *External linters* - Configurations of the linters can be saved to the project or user settings. - Flake8 has a more flexible UI for configuration. - *Others* - Option to add comments all at a single indent (note: this is now the default). - LRU for context-insensitive completion/quick fix. - Fixed some code-completion cases where *self* was wrongly added. - Environment variables are now supported in *.pydevproject* (expected format: *${env_var:VAR_NAME}*). About PyDev PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development, now also available for Python on Visual Studio Code. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. It is also available as a standalone through LiClipse with goodies such as multiple cursors, theming and support for many other languages, such as Django Templates, Jinja2, Html, JavaScript, etc. Links: PyDev: http://pydev.org PyDev Blog: http://pydev.blogspot.com PyDev on VSCode: http://pydev.org/vscode LiClipse: http://www.liclipse.com PyVmMonitor - Python Profiler: http://www.pyvmmonitor.com/ Cheers, Fabio Zadrozny From cseberino at gmail.com Sat Apr 10 10:52:59 2021 From: cseberino at gmail.com (cseb...@gmail.com) Date: Sat, 10 Apr 2021 07:52:59 -0700 (PDT) Subject: question about basics of creating a PROXY to MONITOR network activity In-Reply-To: References: <7afbeeb6-a1dd-4c7b-ba23-c560a5878f4dn@googlegroups.com> Message-ID: > Is it even possible to be secure in that way? This is, by definition, > a MITM, and in order to be useful, it *will* have to decrypt > everything. So if someone compromises the monitor, they get > everything. Chris I hear all your security concerns and I'm aware of them. I *really* don't want to have to fight SSL. Encryption was the biggest concern and I'd rather not mess with it to do something useful. I've never used CloudFlare but if I'm not mistaken, it can be considered a useful "MITM" service? Do they have to decrypt traffic and increase the attack surface to be useful? I just want to create a "safe" MITM service so to speak. cs From pbryan at anode.ca Sat Apr 10 12:17:33 2021 From: pbryan at anode.ca (Paul Bryan) Date: Sat, 10 Apr 2021 09:17:33 -0700 Subject: question about basics of creating a PROXY to MONITOR network activity In-Reply-To: References: <7afbeeb6-a1dd-4c7b-ba23-c560a5878f4dn@googlegroups.com> Message-ID: There is absolutely nothing wrong with building your own reverse proxy in front of your own service, as long as you control both. This constitutes a tiered network/application architecture, and it's a common practice. There's no man in the middle; there's no imposter; its all "you".? If your proxy becomes the endpoint that clients now must connect to (i.e. nothing "in front" of your new proxy), you will have to deal with TLS (aka SSL). Having the TLS certificate match the DNS address of your new endpoint is a central tenet of security, and allows clients to trust that they are connecting to the intended endpoint (there is not?a?man in the middle). How you secure the network traffic between your proxy and the service it fronts becomes an important factor. If you claim that data is always encrypted in transit, then either: a) your reverse proxy must be colocated with the service it fronts on the same machine; b) your network infrastructure transparently encrypts traffic between your proxy and the service; or? c) your proxy must negotiate its own TLS connection(s) with the service. Negotiating TLS connections independently for each hop through a network will add overhead, and degrade the performance of your service. This can be major pain point when composing an application of microservices, where each service must be able to securely connect to another over a network. This is where a service mesh proxy (e.g. Envoy) comes into play, or even full blown service mesh with service discovery, certificate management, access policies (e.g.?Istio).? On Sat, 2021-04-10 at 07:52 -0700, cseb... at gmail.com wrote: > > > Is it even possible to be secure in that way? This is, by > > definition, > > a MITM, and in order to be useful, it *will* have to decrypt > > everything. So if someone compromises the monitor, they get > > everything. > > Chris > > I hear all your security concerns and I'm aware of them.? I *really* > don't want to have to > fight SSL.? Encryption was the biggest concern and I'd rather not > mess with it to do something > useful. > > I've never used CloudFlare but if I'm not mistaken, it can be > considered a useful "MITM" service? > Do they have to decrypt traffic and increase the attack surface to be > useful? > > I just want to create a "safe" MITM service so to speak. > > cs From torriem at gmail.com Sat Apr 10 12:26:16 2021 From: torriem at gmail.com (Michael Torrie) Date: Sat, 10 Apr 2021 10:26:16 -0600 Subject: question about basics of creating a PROXY to MONITOR network activity In-Reply-To: References: <7afbeeb6-a1dd-4c7b-ba23-c560a5878f4dn@googlegroups.com> Message-ID: On 4/10/21 8:52 AM, cseb... at gmail.com wrote: > >> Is it even possible to be secure in that way? This is, by definition, >> a MITM, and in order to be useful, it *will* have to decrypt >> everything. So if someone compromises the monitor, they get >> everything. > > Chris > > I hear all your security concerns and I'm aware of them. I *really* don't want to have to > fight SSL. Encryption was the biggest concern and I'd rather not mess with it to do something > useful. > > I've never used CloudFlare but if I'm not mistaken, it can be considered a useful "MITM" service? > Do they have to decrypt traffic and increase the attack surface to be useful? Cloudfare does not do any kind of MITM stuff. Cloudfare requires some set up on the part of the server owner, and that takes several forms. One recommended method is have Cloudfare sign a special certificate that you install on your web server, which encrypts between your server and Cloudfare. Then you provide cloudfare with an SSL certificate and key to use when they serve up your site to the world. > I just want to create a "safe" MITM service so to speak. For my own purposes, sometimes I'll create a limited, wildcard certificate signed by my own authority which works only in my own browser (this is the same technique used by certain regimes to MITM the entire country!). The proxy then uses that certificate. It's useful for some debugging tasks. Or alternatively I'll create a proxy intended to run on localhost only that proxies an encrypted source to a local, non-encrypted channel. For example, I might want to examine why a connection to an IMAPS port is failing. So I'll proxy IMAPS to IMAP so I can sniff the IMAP locally to find out why the interaction is failing. From cseberino at gmail.com Sat Apr 10 14:35:12 2021 From: cseberino at gmail.com (Christian Seberino) Date: Sat, 10 Apr 2021 13:35:12 -0500 Subject: question about basics of creating a PROXY to MONITOR network activity In-Reply-To: References: <7afbeeb6-a1dd-4c7b-ba23-c560a5878f4dn@googlegroups.com> Message-ID: > > > a) your reverse proxy must be colocated with the service it fronts on the > same machine; > b) your network infrastructure transparently encrypts traffic between your > proxy and the service; or > c) your proxy must negotiate its own TLS connection(s) with the service. > Paul Thanks. I'm curious, do you know which of your options CloudFlare uses? It has to stand in between you and all the sites you visit while allowing encryption right? cs From pbryan at anode.ca Sat Apr 10 14:50:26 2021 From: pbryan at anode.ca (Paul Bryan) Date: Sat, 10 Apr 2021 11:50:26 -0700 Subject: question about basics of creating a PROXY to MONITOR network activity In-Reply-To: References: <7afbeeb6-a1dd-4c7b-ba23-c560a5878f4dn@googlegroups.com> Message-ID: <2fb2204b42889d9203163cff84e3dcb479629373.camel@anode.ca> Cloudflare operates as a reverse proxy in front of your service(s); clients of your services access them through an endpoint that Cloudflare stands up. DNS records point to Cloudflare, and TLS certificates must be provisioned in Cloudflare to match. For all intents and purposes, you would be outsourcing a part of your service network infrastructure to Cloudflare. Paul? On Sat, 2021-04-10 at 13:35 -0500, Christian Seberino wrote: > > > > a) your reverse proxy must be colocated with the service it fronts > > on the same machine; > > b) your network infrastructure transparently encrypts traffic > > between your proxy and the service; or? > > c) your proxy must negotiate its own TLS connection(s) with the > > service. > > > > > Paul > > Thanks. I'm curious, do you know which of your options CloudFlare > uses?? It has to stand in between > you and all the sites you visit while allowing encryption right? > > cs? From rustbuckett at pm.me Sat Apr 10 16:29:19 2021 From: rustbuckett at pm.me (Russell) Date: Sat, 10 Apr 2021 20:29:19 +0000 (UTC) Subject: Ann: New Python curses book References: <1A4D63D5-871B-44A9-BED6-6778894462EF@icloud.com> Message-ID: I believe this is it: https://www.amazon.com/dp/B091CL3DTK/ref=cm_sw_su_dp But for some reason the ASIN is different. William Ray Wing wrote: > I???ve ordered the book (physical volume). It will fulfill a need I???ve had for some time. Unfortunately, it is only available in the UK store, so the shipping cost by far outweighs the book???s cost. Hope for other???s sake, it migrates to the other Amazon stores fairly quickly. > > Thanks, > Bill > >> On Mar 30, 2021, at 7:12 AM, Alan Gauld via Python-list wrote: >> >> I've just published, in Kindle and paperback formats, >> my book on "Programming curses with Python". >> >> https://www.amazon.co.uk/dp/B091B85B77/ >> >> (It should be available in most other Amazon stores too) > -- rust 0x68caecc97f6a90122e51c0692c88d9cb6b58a3dc From rustbuckett at pm.me Sat Apr 10 16:29:22 2021 From: rustbuckett at pm.me (Russell) Date: Sat, 10 Apr 2021 20:29:22 +0000 (UTC) Subject: all versions of python fail to indent after conditional statement References: <1B8C9520-18F9-4EAD-9BD5-ACDA2BA23E71@hxcore.ol> Message-ID: I would recommend reading a book that introduces and explains Python rather than just diving in. I'm been enjoying "Introducing Python: Modern Computing in Simple Packages" which can be found at https://amzn.com/1492051365. It started from the beginning and would answer the questions/difficulties you've raised here. It would help set you on your quest to master Python. mikedianeterry at gmail.com wrote: > > > The following snap shot of system prompt illustrates my problem. I have > tried 3.8, 3.92 and 3.10 with the same result. When I run in the window > interface it doesn't even display one row of ... but does print if I hit > return twice. I'm new to Python and was excited about learning it but am > becoming very frustrated over a bug in such a simple conditional statement > - please help as I would really like to master Python. > > Regards, > > Michael Terry > > > > Microsoft Windows [Version 10.0.19041.867] > > (c) 2020 Microsoft Corporation. All rights reserved. > > C:\WINDOWS\system32>py > > > > Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:18:16) [MSC v.1928 64 > bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for > more information. > > > > >>> dog_has_fleas=True > > >>> if dog_has_fleas: > > ... print('too bad') > > File "", line 2 > > print('too bad') > > ^ > > IndentationError: expected an indented block > > >>> Microsoft Windows [Version 10.0.19041.867] > > > > > > Sent from [1]Mail for Windows 10 > > > > References > > Visible links > 1. https://go.microsoft.com/fwlink/?LinkId=550986 -- rust 0x68caecc97f6a90122e51c0692c88d9cb6b58a3dc From tdldev at gmail.com Sun Apr 11 12:10:41 2021 From: tdldev at gmail.com (Jack Dangler) Date: Sun, 11 Apr 2021 12:10:41 -0400 Subject: Ann: New Python curses book In-Reply-To: References: <1A4D63D5-871B-44A9-BED6-6778894462EF@icloud.com> Message-ID: <6fb3c5bd-faa8-1dd1-b0fe-92cac6a5beee@gmail.com> On 4/10/21 4:29 PM, Russell via Python-list wrote: > I believe this is it: > https://www.amazon.com/dp/B091CL3DTK/ref=cm_sw_su_dp > > But for some reason the ASIN is different. > > William Ray Wing wrote: >> I???ve ordered the book (physical volume). It will fulfill a need I???ve had for some time. Unfortunately, it is only available in the UK store, so the shipping cost by far outweighs the book???s cost. Hope for other???s sake, it migrates to the other Amazon stores fairly quickly. >> >> Thanks, >> Bill >> >>> On Mar 30, 2021, at 7:12 AM, Alan Gauld via Python-list wrote: >>> >>> I've just published, in Kindle and paperback formats, >>> my book on "Programming curses with Python". >>> >>> https://www.amazon.co.uk/dp/B091B85B77/ >>> >>> (It should be available in most other Amazon stores too) > I just found it and put it in the cart, and got this on checkout - Items:$5.99 Shipping & handling:$0.00 ------------------------------------------------------------------------ Total before tax:$5.99 Estimated tax to be collected:$0.36 ------------------------------------------------------------------------ Order total:$6.35 It must be available here as well, now. (I'm in the US). From daniel at wavesofdawn.com Sun Apr 11 19:53:23 2021 From: daniel at wavesofdawn.com (Daniel Nelson) Date: Sun, 11 Apr 2021 16:53:23 -0700 Subject: Ann: New Python curses book In-Reply-To: References: Message-ID: On Tue, Mar 30, 2021 at 12:12:19PM +0100, Alan Gauld via Python-list wrote: > I've just published, in Kindle and paperback formats, > my book on "Programming curses with Python". > > https://www.amazon.co.uk/dp/B091B85B77/ > > (It should be available in most other Amazon stores too) This looks handy, I'd love to buy a copy but I don't do business with Amazon if I can avoid it. Any chance this will be available from other locations? -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From keller.steve at gmx.de Mon Apr 12 04:29:30 2021 From: keller.steve at gmx.de (Steve Keller) Date: Mon, 12 Apr 2021 10:29:30 +0200 Subject: Style qeustion: Multiple return values Message-ID: Just a short style question: When returning multiple return values, do you use parenthesis? E.g. would you write def foo(): return 1, 2 a, b = foo() or do you prefer def foo(): return (1, 2) (a, b) = foo() Steve From PythonList at DancesWithMice.info Mon Apr 12 06:19:00 2021 From: PythonList at DancesWithMice.info (dn) Date: Mon, 12 Apr 2021 22:19:00 +1200 Subject: Style qeustion: Multiple return values In-Reply-To: References: Message-ID: <4ca81149-223b-ffe6-c34c-e97553569204@DancesWithMice.info> On 12/04/2021 20.29, Steve Keller wrote: > Just a short style question: When returning multiple return values, do > you use parenthesis? > > E.g. would you write > > def foo(): > return 1, 2 > > a, b = foo() > > or do you prefer > > def foo(): > return (1, 2) > > (a, b) = foo() Steve The data-structure being returned is a tuple. The tuple is defined by the comma-separator - not the parentheses. Of course, the way you use them (first example) involves "unpacking" after the tuple 'crosses' the equals/assignment. Thus, the answer to your question is a matter of style, and thus the understanding of those who might read the code. FWIW: I leave them out because it is easier on my eyes whilst scanning the line of code. -- Regards, =dn From rosuav at gmail.com Mon Apr 12 06:32:11 2021 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 12 Apr 2021 20:32:11 +1000 Subject: Style qeustion: Multiple return values In-Reply-To: <4ca81149-223b-ffe6-c34c-e97553569204@DancesWithMice.info> References: <4ca81149-223b-ffe6-c34c-e97553569204@DancesWithMice.info> Message-ID: On Mon, Apr 12, 2021 at 8:20 PM dn via Python-list wrote: > > On 12/04/2021 20.29, Steve Keller wrote: > > Just a short style question: When returning multiple return values, do > > you use parenthesis? > > Thus, the answer to your question is a matter of style, and thus the > understanding of those who might read the code. > Yes, just like the subject line says :) My personal preference: If the purpose is simply to return two values (which will almost always be unpacked immediately), I would omit the parens. ChrisA From alan.gauld at yahoo.co.uk Mon Apr 12 04:13:58 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 12 Apr 2021 09:13:58 +0100 Subject: Ann: New Python curses book In-Reply-To: References: Message-ID: On 12/04/2021 00:53, Daniel Nelson wrote: >> (It should be available in most other Amazon stores too) > > This looks handy, I'd love to buy a copy but I don't do business with > Amazon if I can avoid it. Any chance this will be available from other > locations? I tried to publish it on several open-source web sites but none of them responded to me so I went with Amazon as the commercial site most people turn to first and with the widest reach. Also the Amazon publishing tools are very easy to use. However, one of their conditions for low cost books is exclusivity, so no it won't appear anywhere else unless I increase the price significantly which I don't want to do. What I might do is host the original translation of the C document as a PDF on my own web site. But that's not likely to show up in many searches! If I get round to that I'll announce it here. -- 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 tjreedy at udel.edu Mon Apr 12 06:08:20 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Apr 2021 06:08:20 -0400 Subject: Style qeustion: Multiple return values In-Reply-To: References: Message-ID: On 4/12/2021 4:29 AM, Steve Keller wrote: > Just a short style question: When returning multiple return values, do > you use parenthesis? > > E.g. would you write > > def foo(): > return 1, 2 > > a, b = foo() > > or do you prefer > > def foo(): > return (1, 2) > > (a, b) = foo() No. Parentheses are for grouping (and separation from surrounding code). () and (1,) (can be though of as) group(ing) the a zero-width space and one-comma pair respectively and separate them from the rest of the code. -- Terry Jan Reedy From qberz2005 at gmail.com Mon Apr 12 12:48:23 2021 From: qberz2005 at gmail.com (Quentin Bock) Date: Mon, 12 Apr 2021 12:48:23 -0400 Subject: googletrans in python Message-ID: Can someone explain the basics of googletrans in python? I want to make a program that translates stories into English, but I'm not sure how to get a translation printed. Also, is this needed to be done in an HTML file inside python? If so can someone provide basic code for a translation and how that should be written and work? Thank you From drsalists at gmail.com Mon Apr 12 12:54:13 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 12 Apr 2021 09:54:13 -0700 Subject: Style qeustion: Multiple return values In-Reply-To: References: Message-ID: On Mon, Apr 12, 2021 at 1:30 AM Steve Keller wrote: > Just a short style question: When returning multiple return values, do > you use parenthesis? > > E.g. would you write > > def foo(): > return 1, 2 > > a, b = foo() > > or do you prefer > > def foo(): > return (1, 2) > > (a, b) = foo() > I prefer the parens; it's too easy to miss a comma when reading. The parentheses make it more clear that you're looking at a tuple. pycodestyle and pylint don't appear to care one way or the other. From 2QdxY4RzWzUUiLuE at potatochowder.com Mon Apr 12 13:41:34 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Mon, 12 Apr 2021 10:41:34 -0700 Subject: Style qeustion: Multiple return values In-Reply-To: References: Message-ID: On 2021-04-12 at 09:54:13 -0700, Dan Stromberg wrote: > On Mon, Apr 12, 2021 at 1:30 AM Steve Keller wrote: > > > Just a short style question: When returning multiple return values, do > > you use parenthesis? > > > > E.g. would you write > > > > def foo(): > > return 1, 2 > > > > a, b = foo() > > > > or do you prefer > > > > def foo(): > > return (1, 2) > > > > (a, b) = foo() > > > > I prefer the parens; it's too easy to miss a comma when reading. The > parentheses make it more clear that you're looking at a tuple. If I were to write it like this: a,b = foo() rather than like this: a, b = foo() then I might agree that the comma might be mistakable for a dot or even "disappear" altogether. To the compiler, the extraneous space doesn't matter, but to a human reader, it makes a huge difference. That said, consider this function: def f(*args): whatever() Do you prefer f(a, b) or f((a, b))? Okay, so it's a trick question, but that's how I think about *returning* multiple values, too: "a, b" is two values, but "(a, b)" is one value that happens to be a tuple. Lastly, with names like foo, a, and b, we might be misfocused. Does any of this change with names like coordinate, account_number, or distance? Do meaningful names help, or do they merely distract from the commas and the parentheses? (x_coord, y_coord) = locate_target(parameters) likely_name, probability = best_match(parameters) From drsalists at gmail.com Mon Apr 12 13:42:39 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 12 Apr 2021 10:42:39 -0700 Subject: googletrans in python In-Reply-To: References: Message-ID: Does this help? https://zetcode.com/python/googletrans/ It was the first google search hit on 'googletrans python example'. On Mon, Apr 12, 2021 at 9:49 AM Quentin Bock wrote: > Can someone explain the basics of googletrans in python? > I want to make a program that translates stories into English, but I'm not > sure how to get a translation printed. Also, is this needed to be done in > an HTML file inside python? > If so can someone provide basic code for a translation and how that should > be written and work? > Thank you > -- > https://mail.python.org/mailman/listinfo/python-list > From info at wingware.com Mon Apr 12 13:58:13 2021 From: info at wingware.com (Wingware) Date: Mon, 12 Apr 2021 13:58:13 -0400 Subject: ANN: Wing Python IDE 7.2.9 has been released Message-ID: Wing 7.2.9 adds remote development for 64-bit Raspberry Pi, improves auto-closing of quotes, optimizes change tracking when large numbers of project files change at once, improves debugger data display for some value types, and makes a number of other usability improvements. Details:? https://wingware.com/news/2021-04-12 Downloads:?? https://wingware.com/downloads == About Wing == Wing is a light-weight but full-featured Python IDE designed specifically for Python, with powerful editing, code inspection, testing, and debugging capabilities. Wing's deep code analysis provides auto-completion, auto-editing, and refactoring that speed up development. Its top notch debugger works with any Python code, locally or on a remote host. Wing also supports test-driven development, version control, UI color and layout customization, and includes extensive documentation and support. Wing is available in three product levels:? Wing Pro is the full-featured Python IDE for professional developers, Wing Personal is a free Python IDE for students and hobbyists (omits some features), and Wing 101 is a very simplified free Python IDE for beginners (omits many features). Learn more at https://wingware.com/ From andreas.r.maier at gmx.de Mon Apr 12 12:01:57 2021 From: andreas.r.maier at gmx.de (Andreas R Maier) Date: Mon, 12 Apr 2021 18:01:57 +0200 Subject: Immutable view classes - inherit from dict or from Mapping? References: Message-ID: <8A082402-D63D-4978-A772-1C37A5E30AB3@gmx.de> Hi, I have written some classes that represent immutable views on collections (see "immutable-views" package on Pypi). Currently, these view classes inherit from the abstract collection classes such as Mapping, Sequence, Set. However, they implement the read-only methods of dict, list and set, which provides some more methods compared to the abstract collection classes. For example, class "dict" provides copy() or __reversed__() and the newer OR-operator methods all of which are not defined on the abstract class "Mapping". Note that the view classes do not provide any of the modifying methods of "dict" and "list", because after all the views are supposed to be immutable. My question is, should the dict view class inherit from Mapping or from dict, and likewise, should the list view class inherit from Sequence or from list? Thanks Andy From rob.cliffe at btinternet.com Mon Apr 12 14:13:29 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 12 Apr 2021 19:13:29 +0100 Subject: Style qeustion: Multiple return values In-Reply-To: References: Message-ID: <46e7384b-c6f1-ac34-1175-9e97a0158199@btinternet.com> On 12/04/2021 09:29, Steve Keller wrote: > Just a short style question: When returning multiple return values, do > you use parenthesis? > > E.g. would you write > > def foo(): > return 1, 2 > > a, b = foo() > > or do you prefer > > def foo(): > return (1, 2) > > (a, b) = foo() > > > Steve My personal view: It's a matter of style; do whatever looks best to you.? Looking at my own code I'm not consistent in my choice.? That said: ??? return item, cost??? # If I think of these as two distinct values I'd be inclined to omit the parentheses. ??? return (x,y)??? ??? ????? # If I'm returning a point which I think of as a single entity, I'd probably put them in, ????????????????????????????????????? #?? especially, for consistency, if the rest of my code contains lots of `(x,y)`s, `(u,v)`s etc. ??? return (long-expression1, long-expression2) ??? ??? ??? ??? ??? ??? ??? ??? ?????? # It might be hard to spot the comma at first glance so the parentheses might help to recognise a tuple. Best wishes Rob Cliffe From Karsten.Hilbert at gmx.net Mon Apr 12 15:24:23 2021 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Mon, 12 Apr 2021 21:24:23 +0200 Subject: googletrans in python In-Reply-To: References: Message-ID: Am Mon, Apr 12, 2021 at 12:48:23PM -0400 schrieb Quentin Bock: > Can someone explain the basics of googletrans in python? > I want to make a program that translates stories into English, but I'm not > sure how to get a translation printed. Also, is this needed to be done in > an HTML file inside python? > If so can someone provide basic code for a translation and how that should > be written and work? You might want to post the entire homework assignment verbatim. That way people might better understand which part of it to help you with in what way. As to your description of what you want to achieve -- what did you already try ? Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From enopatch at gmail.com Mon Apr 12 18:06:12 2021 From: enopatch at gmail.com (Jaime) Date: Mon, 12 Apr 2021 23:06:12 +0100 Subject: How does "__doc__ % globals()" work? Message-ID: Hi all. Line 102 of https://github.com/python/peps/blob/master/pep2html.py says: print(__doc__ % globals(), file=out) and I've just spent all day trying to understand "__doc__ % globals()". Sure, I realise that globals() is a standard-library built-in functions that returns a dictionary representing the current global symbol table, and that the result of this expression is the value of the dictionary where the key is "__doc__", but I can't understand how this works. I've searched through dictionary tutorials to see whether they mention accessing dictionary values using a % (percent) operator, and they don't. I've searched through printf-string formatting tutorials, and they all say that I need a %-sign to start, and then some parentheses, so it can't be that either. Can someone please put me out of my misery - what, exactly, is the percent (%) sign doing in the expression "__doc__ % globals()"? Thank you! From tjreedy at udel.edu Mon Apr 12 18:53:59 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 12 Apr 2021 18:53:59 -0400 Subject: googletrans in python In-Reply-To: References: Message-ID: On 4/12/2021 12:48 PM, Quentin Bock wrote: > Can someone explain the basics of googletrans in python? You most likely want to install https://pypi.org/project/googletrans/ -- Terry Jan Reedy From rosuav at gmail.com Mon Apr 12 19:00:38 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Apr 2021 09:00:38 +1000 Subject: How does "__doc__ % globals()" work? In-Reply-To: References: Message-ID: On Tue, Apr 13, 2021 at 8:57 AM Jaime wrote: > > Hi all. Line 102 of https://github.com/python/peps/blob/master/pep2html.py says: > > print(__doc__ % globals(), file=out) > > and I've just spent all day trying to understand "__doc__ % > globals()". The docstring for any function, class, or module, is available under the name __doc__. It's a string, so what you're seeing is simply an example of string formatting/interpolation, with the docstring containing markers that get populated by globals. ChrisA From rshepard at appl-ecosys.com Mon Apr 12 19:11:21 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 12 Apr 2021 16:11:21 -0700 (PDT) Subject: Comparing text strings Message-ID: I'm running Slackware64-14.2 and keep a list of installed packages. When a package is upgraded I want to remove the earlier version, and I've not before written a script like this. Could there be a module or tool that already exists to do this? If not, which string function would be best suited to the task? Here's an example: atftp-0.7.2-x86_64-2_SBo.tgz atftp-0.7.4-x86_64-1_SBo.tgz and there are others like this. I want the python3 script to remove the first one. Tools like like 'find' or 'sort -u' won't work because while the file name is the same the version or build numbers differ. All suggestions welcome. Rich From crt.gorican at gmail.com Mon Apr 12 19:15:14 2021 From: crt.gorican at gmail.com (Crt Gorican) Date: Tue, 13 Apr 2021 01:15:14 +0200 Subject: Error 2503 Message-ID: Dear Python team, I am writing to you because I am desperate. I've tried everything I could find on the internet before writing to you. I've started developing a python script in my IDE and the python was simply not working for me. I've tried it in cmd and there was this message "The system cannot execute the specified program.". I've added the python path and the problem was still not resolved so I've decided to uninstall it and then the error 2503 occurred. I am also sending you the pictures when I tried removing and modifying with installer and a log file. I am looking forward to your response. Yours faithfully, ?rt G. From ethan at stoneleaf.us Mon Apr 12 19:39:08 2021 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 12 Apr 2021 16:39:08 -0700 Subject: How does "__doc__ % globals()" work? In-Reply-To: References: Message-ID: On 4/12/21 3:06 PM, Jaime wrote: > Hi all. Line 102 of https://github.com/python/peps/blob/master/pep2html.py says: > > print(__doc__ % globals(), file=out) > > I realise that globals() is a standard-library > built-in function that returns a dictionary representing the current > global symbol table, and that the result of this expression is the > value of the dictionary where the key is "__doc__" This is not correct. There are a couple ways to use %-interpolation: some_name = 'Jaime' # simple `hello, %s` % (some_name, ) # hello, Jaime # keyed `hello, %(a_name)s` % {'a_name': 'Ethan'} # hello, Ethan What you are seeing is the keyed version. So, if the module had, for example: version = 1.3 author = 'GvR' date = '2021-04-12' and the doc string was __doc__ = "version %(version)s was initially created by %(author)s" then __doc__ % globals() would substitute the `author` and `version` keys into __doc__, and printing that would yield version 1.3 was initially created by GvR Note that extra keys are ignored. -- ~Ethan~ From cs at cskk.id.au Mon Apr 12 19:40:46 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 13 Apr 2021 09:40:46 +1000 Subject: Error 2503 In-Reply-To: References: Message-ID: On 13Apr2021 01:15, Crt Gorican wrote: >Dear Python team, > >I am writing to you because I am desperate. I've tried everything I >could find on the internet before writing to you. >I've started developing a python script in my IDE and the python was >simply not working for me. >I've tried it in cmd and there was this message "The system cannot >execute the specified program.". >I've added the python path and the problem was still not resolved so >I've decided to uninstall it and then the error 2503 occurred. >I am also sending you the pictures when I tried removing and modifying >with installer and a log file. >I am looking forward to your response. Unfortunately this is not enough information. What Operating System are you using? What IDE are you using? Did you install Python? Or was it already present on your system? This mailing list removes attachments, so we have not received your pictures. You could post them to a snapshotting web service and provide the URLs, but it would be better where possibly to paste the text from your commands and the output here in your message. You wrote: >I've tried it in cmd and there was this message "The system cannot >execute the specified program.". >I've added the python path and the problem was still not resolved so What command did you type, and at what prompt did you type it? Sometimes people type shell commands at the Python prompt and vice versa. >I've decided to uninstall it and then the error 2503 occurred. CWhat process did you do for the uninstall? If you're on Windows, I at least am not a Windows person. But others on this list are. Cheers, Cameron Simpson From 2QdxY4RzWzUUiLuE at potatochowder.com Mon Apr 12 19:41:45 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Mon, 12 Apr 2021 16:41:45 -0700 Subject: Comparing text strings In-Reply-To: References: Message-ID: On 2021-04-12 at 16:11:21 -0700, Rich Shepard wrote: > I'm running Slackware64-14.2 and keep a list of installed packages. When a > package is upgraded I want to remove the earlier version, and I've not > before written a script like this. Could there be a module or tool that > already exists to do this? If not, which string function would be best > suited to the task? > > Here's an example: > atftp-0.7.2-x86_64-2_SBo.tgz > atftp-0.7.4-x86_64-1_SBo.tgz > > and there are others like this. I want the python3 script to remove the > first one. Tools like like 'find' or 'sort -u' won't work because while the > file name is the same the version or build numbers differ. > > All suggestions welcome. The trick to this is to define "one" in the phrase "first one." What makes a package name a first one, or a second one? Is it the prefix before the first hyphen? Always? Does Slackware define all the possible bits, pieces, and permutations of package names, versions, builds, etc.? I don't know whether or how Slackware handles "compound" package names (e.g., python-flask), but at some point, you're going to have to pull apart (aka---gasp--parse), the package names to come up with the name itself and the version (and the architecture, etc.), compare the name parts to find the "duplicates," and then compare the versions (and maybe the build number) to eliminate the lesser ones. You'll also have to watch for the transitions from, say, 0.9 to 0.10, or from 1.0rc2 to 1.0, which may not sort simply. So to answer your question, a string function like split is a good start. IMO, if you think about the edge cases early, you'll have a better chance at not being bitten by them. From cs at cskk.id.au Mon Apr 12 19:53:24 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 13 Apr 2021 09:53:24 +1000 Subject: Comparing text strings In-Reply-To: References: Message-ID: On 12Apr2021 16:11, Rich Shepard wrote: >I'm running Slackware64-14.2 and keep a list of installed packages. When a >package is upgraded I want to remove the earlier version, and I've not >before written a script like this. Could there be a module or tool that >already exists to do this? If not, which string function would be best >suited to the task? > >Here's an example: >atftp-0.7.2-x86_64-2_SBo.tgz >atftp-0.7.4-x86_64-1_SBo.tgz > >and there are others like this. I want the python3 script to remove the >first one. Tools like like 'find' or 'sort -u' won't work because while the >file name is the same the version or build numbers differ. I do not know if there are preexisting modules/tools for this, but I recommend looking at slackware's package management tool - they usually have some kind of 'clean" operation to purge "old" package install files. Sometimes that purges all the install files, not just the obsolete ones, so take care. If you're writing a script, what you want to do is read the names and extract the version information from them, and also the "package name" - the bit which identifies the package and does not change with an upgrade. I would then make a dict mapping package names to a list of versions and/or the full "...tgz" names above. (Actually, use a defaultdict(list), it will avoid a lot of tedious mucking about.) Alternatively, and now that I think about it, more simply: _if_ the package files can be sorted by version, then all you need to do is read a sorted listing and note that latest fil for a particular package. If you need another one, it should be newer and you can remove the "known" package file, and update your record that to the new one. Note that this depends on sorting by version. A lexical sort (eg "ls|sort") will look good intil a package version crosses a boundary like this: 1.9.1 1.10.0 A lexical sort will put those the other way around because "9" > "1". Wrongness will ensue. Cheers, Cameron Simpson From rosuav at gmail.com Mon Apr 12 19:57:12 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Apr 2021 09:57:12 +1000 Subject: Comparing text strings In-Reply-To: References: Message-ID: On Tue, Apr 13, 2021 at 9:54 AM Cameron Simpson wrote: > Note that this depends on sorting by version. A lexical sort (eg > "ls|sort") will look good intil a package version crosses a boundary > like this: > > 1.9.1 > 1.10.0 > > A lexical sort will put those the other way around because "9" > "1". > Wrongness will ensue. > GNU sort has a -V option to sort by version numbers. I don't know how well that'd handle other tags though. ChrisA From rshepard at appl-ecosys.com Mon Apr 12 22:11:24 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 12 Apr 2021 19:11:24 -0700 (PDT) Subject: Comparing text strings In-Reply-To: References: Message-ID: On Tue, 13 Apr 2021, Cameron Simpson wrote: > I do not know if there are preexisting modules/tools for this, but I > recommend looking at slackware's package management tool - they usually > have some kind of 'clean" operation to purge "old" package install files. > Sometimes that purges all the install files, not just the obsolete ones, > so take care. Cameron, slackpkg clean removes all non-core distribution files. That's how I FUBAR'd my system a couple of months ago. > If you're writing a script, what you want to do is read the names and > extract the version information from them, and also the "package name" - > the bit which identifies the package and does not change with an upgrade. Yes, that's the approach I would take. > I would then make a dict mapping package names to a list of versions > and/or the full "...tgz" names above. (Actually, use a > defaultdict(list), it will avoid a lot of tedious mucking about.) Okay. That didn't occur to me. > Alternatively, and now that I think about it, more simply: _if_ the > package files can be sorted by version, then all you need to do is read a > sorted listing and note that latest fil for a particular package. If you > need another one, it should be newer and you can remove the "known" > package file, and update your record that to the new one. The problem is not that simple. Sometimes the package maintainer upgrades the package for the same version number so there could be abc-1.0_1_SBo.tgz and abc-1.0_2_SBo.tgz. The more involved route will be taken. Thanks! Rich From cs at cskk.id.au Mon Apr 12 22:23:20 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 13 Apr 2021 12:23:20 +1000 Subject: Comparing text strings In-Reply-To: References: Message-ID: On 12Apr2021 19:11, Rich Shepard wrote: >On Tue, 13 Apr 2021, Cameron Simpson wrote: >>Alternatively, and now that I think about it, more simply: _if_ the >>package files can be sorted by version, then all you need to do is read a >>sorted listing and note that latest fil for a particular package. If you >>need another one, it should be newer and you can remove the "known" >>package file, and update your record that to the new one. > >The problem is not that simple. Sometimes the package maintainer upgrades >the package for the same version number so there could be abc-1.0_1_SBo.tgz >and abc-1.0_2_SBo.tgz. The more involved route will be taken. If that _1, _2 thing is like RedHat's -1, -2 suffixes for later releases of the same source package version, you could just include that in the version string. Looks like it counts up. Cheers, Cameron Simpson From PythonList at DancesWithMice.info Tue Apr 13 02:24:43 2021 From: PythonList at DancesWithMice.info (dn) Date: Tue, 13 Apr 2021 18:24:43 +1200 Subject: Style qeustion: Multiple return values In-Reply-To: References: <4ca81149-223b-ffe6-c34c-e97553569204@DancesWithMice.info> Message-ID: <341e996a-be06-90b3-ba6f-839495e45888@DancesWithMice.info> On 12/04/2021 22.32, Chris Angelico wrote: > On Mon, Apr 12, 2021 at 8:20 PM dn via Python-list > wrote: >> >> On 12/04/2021 20.29, Steve Keller wrote: >>> Just a short style question: When returning multiple return values, do >>> you use parenthesis? >> >> Thus, the answer to your question is a matter of style, and thus the >> understanding of those who might read the code. >> > > Yes, just like the subject line says :) It's cheeky day at your place is it? Time for your English lesson: with correct vocal-emphasis, the first part of the statement reads as an affirmation or agreement with the OP: ...the answer to your question *is* a matter of style... Perhaps I should have written in English-English prose? ...the answer to your question *is indeed* a matter of style... To follow-through, the second clause offers an idea of how the OP might like to proceed in settling-on his/her own style... > My personal preference: If the purpose is simply to return two values > (which will almost always be unpacked immediately), I would omit the > parens. +1 In response to A.N.Other who countered this view, my aged-eyes agree that a,b = foo() ie without space, is asking for trouble. It's far too easily (mis-)read as: ab = foo() which is why such single-character horizontal-spacing is as helpful to us silver-surfers as Python's block indentation idiom! Thus: a, b = foo() ie with space. Artists and designers refer to such as "the value of negative space"! To this end, in *my style* (ie the one, true, and only-acceptable way to write Python#) spaces are used* to assist the eye to separate ("parse") the components of the code-line - and conversely, a lack of spaces to indicate a 'tight linkage' within looser lists/streams of elements. For functions, adding a space after the opening and before the closing parentheses helps identify the beginning and end of the list of arguments or parameters, eg def my_function( fred, barney, wilma, betty ): NB putting a space before the left-parenthesis creates a disconnection: def my_function ( fred ### or even my_function (fred, ... To my taste (which may all be in my mouth), the spaces after each comma (and "betty" may also be followed by an optional/notional comma) help to make it clear that there are four parameters. However, it may seem confusing to then offer: def my_function( fred=None, barney=None, etc ): That said "fred=None" is a single unit, and clearly separated from "barney", whereas: def my_function( fred = None, barney = None, etc ): does not seem to help the eye associate the two?four parameters with their default values - indeed to be able to reliably count that there are two?four parameters within the function signature! However... adding typing to the mix does give pause for thought. Now, each parameter is a veritable list of object-name, colon, type (which may itself be multi-part), equals, default-value. Phew! The solution (again, to my taste) is to define each parameter on its own/a separate line - using the parentheses to both group the parameter-list and to continue the statement in multi-line form. YMMV! - also, your eyes may be better than mine! (in which case) My eyes have probably seen a lot more than yours - and if you'd seen some of the code-messes I've seen, your eyes would be clouding-over too! * even if some, including our linter over-lords, seem to feel they are "wrong"! # if you believe this, you'll believe anything... -- Regards, =dn From rosuav at gmail.com Tue Apr 13 02:29:10 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 13 Apr 2021 16:29:10 +1000 Subject: Style qeustion: Multiple return values In-Reply-To: <341e996a-be06-90b3-ba6f-839495e45888@DancesWithMice.info> References: <4ca81149-223b-ffe6-c34c-e97553569204@DancesWithMice.info> <341e996a-be06-90b3-ba6f-839495e45888@DancesWithMice.info> Message-ID: On Tue, Apr 13, 2021 at 4:26 PM dn via Python-list wrote: > > On 12/04/2021 22.32, Chris Angelico wrote: > > On Mon, Apr 12, 2021 at 8:20 PM dn via Python-list > > wrote: > >> > >> On 12/04/2021 20.29, Steve Keller wrote: > >>> Just a short style question: When returning multiple return values, do > >>> you use parenthesis? > >> > >> Thus, the answer to your question is a matter of style, and thus the > >> understanding of those who might read the code. > >> > > > > Yes, just like the subject line says :) > > > It's cheeky day at your place is it? Isn't it always? > Time for your English lesson: with correct vocal-emphasis, the first > part of the statement reads as an affirmation or agreement with the OP: > > ...the answer to your question *is* a matter of style... > > Perhaps I should have written in English-English prose? > > ...the answer to your question *is indeed* a matter of style... > Yes, but this followed a logical argument as if to prove the point, when the point was already assumed by the question :) ChrisA From rshepard at appl-ecosys.com Tue Apr 13 08:45:40 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 13 Apr 2021 05:45:40 -0700 (PDT) Subject: Comparing text strings In-Reply-To: References: Message-ID: On Tue, 13 Apr 2021, Cameron Simpson wrote: >> The problem is not that simple. Sometimes the package maintainer upgrades >> the package for the same version number so there could be abc-1.0_1_SBo.tgz >> and abc-1.0_2_SBo.tgz. The more involved route will be taken. > > If that _1, _2 thing is like RedHat's -1, -2 suffixes for later releases > of the same source package version, you could just include that in the > version string. Looks like it counts up. Cameron, There are two variables: the application/tool version number and the build number. They're both embedded within the filename string. I don't know in advance the build numbers if it's that variable that's changed. The list of installed files is (currently) less than 500 lines so a character-by-character comparison when two rows begin with the same string will not take long. Thanks again, Rich From __peter__ at web.de Tue Apr 13 08:47:50 2021 From: __peter__ at web.de (Peter Otten) Date: Tue, 13 Apr 2021 14:47:50 +0200 Subject: Immutable view classes - inherit from dict or from Mapping? In-Reply-To: <8A082402-D63D-4978-A772-1C37A5E30AB3@gmx.de> References: <8A082402-D63D-4978-A772-1C37A5E30AB3@gmx.de> Message-ID: <081d5dde-3246-52c5-9a7a-1a795b998bbc@web.de> On 12/04/2021 18:01, Andreas R Maier wrote: > Hi, > I have written some classes that represent immutable views on collections (see "immutable-views" package on Pypi). > > Currently, these view classes inherit from the abstract collection classes such as Mapping, Sequence, Set. However, they implement the read-only methods of dict, list and set, which provides some more methods compared to the abstract collection classes. For example, class "dict" provides copy() or __reversed__() and the newer OR-operator methods all of which are not defined on the abstract class "Mapping". > > Note that the view classes do not provide any of the modifying methods of "dict" and "list", because after all the views are supposed to be immutable. > > My question is, should the dict view class inherit from Mapping or from dict, and likewise, should the list view class inherit from Sequence or from list? It's easy to add methods, and hard to remove them -- therefore I'd inherit from Mapping rather than dict. As to the | operator, maybe it could be added to Mapping? From __peter__ at web.de Tue Apr 13 08:47:50 2021 From: __peter__ at web.de (Peter Otten) Date: Tue, 13 Apr 2021 14:47:50 +0200 Subject: Immutable view classes - inherit from dict or from Mapping? In-Reply-To: <8A082402-D63D-4978-A772-1C37A5E30AB3@gmx.de> References: <8A082402-D63D-4978-A772-1C37A5E30AB3@gmx.de> Message-ID: <081d5dde-3246-52c5-9a7a-1a795b998bbc@web.de> On 12/04/2021 18:01, Andreas R Maier wrote: > Hi, > I have written some classes that represent immutable views on collections (see "immutable-views" package on Pypi). > > Currently, these view classes inherit from the abstract collection classes such as Mapping, Sequence, Set. However, they implement the read-only methods of dict, list and set, which provides some more methods compared to the abstract collection classes. For example, class "dict" provides copy() or __reversed__() and the newer OR-operator methods all of which are not defined on the abstract class "Mapping". > > Note that the view classes do not provide any of the modifying methods of "dict" and "list", because after all the views are supposed to be immutable. > > My question is, should the dict view class inherit from Mapping or from dict, and likewise, should the list view class inherit from Sequence or from list? It's easy to add methods, and hard to remove them -- therefore I'd inherit from Mapping rather than dict. As to the | operator, maybe it could be added to Mapping? From pengyu.ut at gmail.com Tue Apr 13 10:10:02 2021 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 13 Apr 2021 09:10:02 -0500 Subject: ipython display figure Message-ID: Hi, https://www.fuzzingbook.org/html/Grammars.html I am trying to follow an example on the above page. But it does not show a figure. Could anybody let me know how to display the figure? $ ipython3 Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) Type 'copyright', 'credits' or 'license' for more information IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help. [ins] In [1]: from fuzzingbook.Grammars import * [ins] In [2]: from IPython.display import SVG, display [ins] In [3]: SVG(show_diagram(syntax_diagram_expr(EXPR_GRAMMAR[''][0]))) Out[3]: -- Regards, Peng From qberz2005 at gmail.com Tue Apr 13 10:25:11 2021 From: qberz2005 at gmail.com (Quentin Bock) Date: Tue, 13 Apr 2021 10:25:11 -0400 Subject: googletrans problems in python Message-ID: so I've been experiencing problems with googletrans in python and just found a solution that actually works for me. If you have not tried this option and are having problems with googletrans try this method: *This may work for some and not other I'm too sure install googletrans 3.1.0 using pip it should be like this pip install googeltrans==3.1.0a0 this should give a working googletrans to those like me who were struggling with finding a working version of it. From mats at wichmann.us Tue Apr 13 12:05:30 2021 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 13 Apr 2021 10:05:30 -0600 Subject: Comparing text strings In-Reply-To: References: Message-ID: <7c6f3f04-7c1d-7fb6-f569-71a05eb2100b@wichmann.us> On 4/12/21 5:11 PM, Rich Shepard wrote: > I'm running Slackware64-14.2 and keep a list of installed packages. When a > package is upgraded I want to remove the earlier version, and I've not > before written a script like this. Could there be a module or tool that > already exists to do this? If not, which string function would be best > suited to the task? > > Here's an example: > atftp-0.7.2-x86_64-2_SBo.tgz > atftp-0.7.4-x86_64-1_SBo.tgz > > and there are others like this. I want the python3 script to remove the > first one. Tools like like 'find' or 'sort -u' won't work because while the > file name is the same the version or build numbers differ. Yes, you've identified why this is hard: package versioning takes many forms. As suggested elsewhere, for Linux distribution packages, the only reliable approach is to lean on the distro's packaging infrastructure in some way, because those version strings (plus package metadata which may have "replaces" or "obsoletes" or some similar information) all have a defined meaning to *it* - it's the intended audience. Don't know if Slack exposes this information in some way, it may be hard to make a reliable script if not. I know Debian actually does what you're looking for as a feature of the packaging system (apt-get autoclean), and the Fedora/RedHat universe does not, so I've also looked for what you're looking for :) From grant.b.edwards at gmail.com Mon Apr 12 21:15:03 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 13 Apr 2021 01:15:03 -0000 (UTC) Subject: Comparing text strings References: Message-ID: On 2021-04-12, 2QdxY4RzWzUUiLuE at potatochowder.com <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > I don't know whether or how Slackware handles "compound" package names > (e.g., python-flask), but at some point, you're going to have to pull > apart (aka---gasp--parse), the package names to come up with the name > itself and the version (and the architecture, etc.), compare the name > parts to find the "duplicates," and then compare the versions (and maybe > the build number) to eliminate the lesser ones. > > You'll also have to watch for the transitions from, say, 0.9 to 0.10, or > from 1.0rc2 to 1.0, which may not sort simply. Indeed. Sorting version numbers is very dark magic, and you'll need to know way more than you want to about the version numbering conventions in your distro. There may be all sorts of exceptions and special cases (like handling an rcNN version-number suffix as mentioned above). -- Grant From storchaka at gmail.com Tue Apr 13 12:35:17 2021 From: storchaka at gmail.com (Serhiy Storchaka) Date: Tue, 13 Apr 2021 19:35:17 +0300 Subject: Immutable view classes - inherit from dict or from Mapping? In-Reply-To: <8A082402-D63D-4978-A772-1C37A5E30AB3@gmx.de> References: <8A082402-D63D-4978-A772-1C37A5E30AB3@gmx.de> Message-ID: 12.04.21 19:01, Andreas R Maier ????: > Hi, > I have written some classes that represent immutable views on collections (see "immutable-views" package on Pypi). > > Currently, these view classes inherit from the abstract collection classes such as Mapping, Sequence, Set. However, they implement the read-only methods of dict, list and set, which provides some more methods compared to the abstract collection classes. For example, class "dict" provides copy() or __reversed__() and the newer OR-operator methods all of which are not defined on the abstract class "Mapping". > > Note that the view classes do not provide any of the modifying methods of "dict" and "list", because after all the views are supposed to be immutable. > > My question is, should the dict view class inherit from Mapping or from dict, and likewise, should the list view class inherit from Sequence or from list? If it is a view, and represents a data stored in another object, it cannot be a subclass of concrete collection class. From storchaka at gmail.com Tue Apr 13 12:40:00 2021 From: storchaka at gmail.com (Serhiy Storchaka) Date: Tue, 13 Apr 2021 19:40:00 +0300 Subject: Immutable view classes - inherit from dict or from Mapping? In-Reply-To: <081d5dde-3246-52c5-9a7a-1a795b998bbc@web.de> References: <8A082402-D63D-4978-A772-1C37A5E30AB3@gmx.de> <081d5dde-3246-52c5-9a7a-1a795b998bbc@web.de> Message-ID: 13.04.21 15:47, Peter Otten ????: > As to the | operator, maybe it could be added to Mapping? The | operator returns a new instance, but constructor is not a part of the Mapping interface. You cannot make a general implementation, and making __or__ an abstract method will break all existing Mapping interface implementations which do not have the __or__ method. From stestagg at gmail.com Tue Apr 13 12:51:59 2021 From: stestagg at gmail.com (Stestagg) Date: Tue, 13 Apr 2021 17:51:59 +0100 Subject: ipython display figure In-Reply-To: References: Message-ID: I'm guessing here a little bit, but it looks like the author expects you to run this code in a jupyter notebook, rather than in an ipython interactive console. The jupyter and ipython projects are related (the same?) which can cause some confusion, but if you run the code you shared in a jupyter lab environment, then the SVG should display. As an example, you should be able to view the expected SVG in the following google colab book: https://colab.research.google.com/drive/10KL9mV92L8yPe_5wL089C-m6i0N8ct7Q?usp=sharing Steve On Tue, Apr 13, 2021 at 3:12 PM Peng Yu wrote: > Hi, > > https://www.fuzzingbook.org/html/Grammars.html > > I am trying to follow an example on the above page. But it does not > show a figure. Could anybody let me know how to display the figure? > > $ ipython3 > Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) > Type 'copyright', 'credits' or 'license' for more information > IPython 7.22.0 -- An enhanced Interactive Python. Type '?' for help. > > [ins] In [1]: from fuzzingbook.Grammars import * > > [ins] In [2]: from IPython.display import SVG, display > > [ins] In [3]: > SVG(show_diagram(syntax_diagram_expr(EXPR_GRAMMAR[''][0]))) > Out[3]: > > -- > Regards, > Peng > -- > https://mail.python.org/mailman/listinfo/python-list > From nospam at please.ty Tue Apr 13 13:17:58 2021 From: nospam at please.ty (jak) Date: Tue, 13 Apr 2021 19:17:58 +0200 Subject: Comparing text strings References: Message-ID: Il 13/04/2021 01:11, Rich Shepard ha scritto: > I'm running Slackware64-14.2 and keep a list of installed packages. When a > package is upgraded I want to remove the earlier version, and I've not > before written a script like this. Could there be a module or tool that > already exists to do this? If not, which string function would be best > suited to the task? > > Here's an example: > atftp-0.7.2-x86_64-2_SBo.tgz > atftp-0.7.4-x86_64-1_SBo.tgz > > and there are others like this. I want the python3 script to remove the > first one. Tools like like 'find' or 'sort -u' won't work because while the > file name is the same the version or build numbers differ. > > All suggestions welcome. > > Rich > If I understand your problem correctly, the problem would be dealing with numbers as such in file names. This is just a track but it might help you. This example splits filenames into strings and numbers into tuples, appends the tuple into a list, and then sorts the list: files = ['atftp-0.7.4-x86_64-2_SBo.tgz', 'atftp-0.7.2-x86_64-1_SBo.tgz'] digit = None da = '' tfn = tuple() ltafn = list() for f in files: for c in f: if str(c).isdigit(): if not digit: if len(da) > 0: tfn += (da,) da = '' digit = True da += c else: da += c else: if digit: if len(da) > 0: tfn += (int(da),) da = '' digit = False da += c else: da += c if len(da) > 0: if da.isdigit(): tfn += (int(da),) else: tfn += (da,) da = '' ltafn += [tfn, ] tfn = () ltafn.sort() for t in files: print(t) print() for t in ltafn: nn = '' for f in t: nn += str(f) print(nn) From mwojnarski at paperity.org Tue Apr 13 14:03:14 2021 From: mwojnarski at paperity.org (Marcin Wojnarski) Date: Tue, 13 Apr 2021 20:03:14 +0200 Subject: Hypertag - new language for HTML templating with Django support (announcement) Message-ID: <178cc66d351.b81620581848.940952461094481077@paperity.org> Hello everyone, Hypertag (http://hypertag.io/) is a new language for document generation and HTML templating that has been released recently. Inspired by indentation-based template languages (Slim, Haml, Shpaml), it provides clean, readable syntax and multiple original features: - native custom tags inside scripts - DOM tree manipulation during document construction - complex expressions with all Python operators - control blocks, local variables - Python-like granular imports - pipeline syntax and filters - full Django integration - and more... Hypertag enhances modularity and code reuse inside presentation code to an unprecedented degree. Available on GitHub and PyPI: - https://github.com/mwojnars/hypertag - https://pypi.org/project/hypertag-lang/ Language Reference: - http://hypertag.io/ Install from PyPI as "hypertag-lang". Regards, -- Marcin Wojnarski, Founder and CEO at Paperity, http://www.paperity.org http://www.linkedin.com/in/marcinwojnarski https://www.facebook.com/Paperity https://twitter.com/Paperity Paperity. Open science aggregated. From rshepard at appl-ecosys.com Tue Apr 13 14:24:22 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 13 Apr 2021 11:24:22 -0700 (PDT) Subject: Comparing text strings In-Reply-To: References: Message-ID: On Tue, 13 Apr 2021, jak wrote: > If I understand your problem correctly, the problem would be dealing with > numbers as such in file names. This is just a track but it might help you. > This example splits filenames into strings and numbers into tuples, > appends the tuple into a list, and then sorts the list: jak, Yes, it would be the version and build numbers that differ when two files have the same initial string (application name). Thanks very much, Rich From qberz2005 at gmail.com Tue Apr 13 15:15:49 2021 From: qberz2005 at gmail.com (Quentin Bock) Date: Tue, 13 Apr 2021 15:15:49 -0400 Subject: translating external files type thing Message-ID: okay, so I'm making a translating program, and I have files set to be translated (they're in Icelandic) and I want all of them to be read in English but I'm not sure how to open the files and translate them at the same time. I'm also not even sure how to translate an external file to English from another language. I can't show code for this because I don't know if it's possible to do what I'm asking. Hopefully, this question is understandable Thanks From drsalists at gmail.com Tue Apr 13 16:02:54 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 13 Apr 2021 13:02:54 -0700 Subject: translating external files type thing In-Reply-To: References: Message-ID: Hi. Does this give you any ideas? #!/usr/bin/env python3 """Quick translation program - English to Icelandic.""" # import pprint import googletrans # pprint.pprint(googletrans.LANGUAGES) translator = googletrans.Translator() with open('input-file', 'r') as file_: english_text = file_.read() translated = translator.translate(english_text, src='en', dest='is') with open('output-file', 'w') as file_: file_.write(translated.text) My input-file contains: This is a test of the emergency broadcast system. I like the music of Bj?rk. HTH. On Tue, Apr 13, 2021 at 12:16 PM Quentin Bock wrote: > okay, so I'm making a translating program, and I have files set to be > translated (they're in Icelandic) and I want all of them to be read in > English but I'm not sure how to open the files and translate them at the > same time. I'm also not even sure how to translate an external file > to English from another language. > I can't show code for this because I don't know if it's possible to do what > I'm asking. > Hopefully, this question is understandable > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list > From avigross at verizon.net Tue Apr 13 16:53:09 2021 From: avigross at verizon.net (Avi Gross) Date: Tue, 13 Apr 2021 16:53:09 -0400 Subject: translating external files type thing In-Reply-To: References: Message-ID: <049e01d730a7$030cc840$092658c0$@verizon.net> https://translate.google.com/?sl=is&tl=en&op=translate Or, you could do it the hard way. Kidding aside, there may be a python module you can hand a file name or contents to and have it do much of the job using some API that may tap into the above Google resource. Dan specifically suggested importing googletrans ... -----Original Message----- From: Python-list On Behalf Of Quentin Bock Sent: Tuesday, April 13, 2021 3:16 PM To: python-list at python.org Subject: translating external files type thing okay, so I'm making a translating program, and I have files set to be translated (they're in Icelandic) and I want all of them to be read in English but I'm not sure how to open the files and translate them at the same time. I'm also not even sure how to translate an external file to English from another language. I can't show code for this because I don't know if it's possible to do what I'm asking. Hopefully, this question is understandable Thanks -- https://mail.python.org/mailman/listinfo/python-list From rshepard at appl-ecosys.com Tue Apr 13 17:53:30 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 13 Apr 2021 14:53:30 -0700 (PDT) Subject: UI design: combobox or radiobuttons? Message-ID: My applications use environmental data, each of which has to specify the units (e.g., cm, m, km, ft, yd, mi). With the widget sets I've used (wxPython and TKinter) I've always used a combobox with the acceptable choices in it. I'm now planning a new application using PyQt5 and it occured to me that a set of radio buttons would also work. While a set of radiobuttons occupies more room on the parent widget than does a combobox are there any technical or user issues that would suggest using one over the other? TIA, Rich From mirkok.lists at googlemail.com Tue Apr 13 18:14:33 2021 From: mirkok.lists at googlemail.com (Mirko) Date: Wed, 14 Apr 2021 00:14:33 +0200 Subject: UI design: combobox or radiobuttons? In-Reply-To: References: Message-ID: <607617C9.5020800@googlemail.com> Am 13.04.2021 um 23:53 schrieb Rich Shepard: > My applications use environmental data, each of which has to specify > the > units (e.g., cm, m, km, ft, yd, mi). With the widget sets I've used > (wxPython and TKinter) I've always used a combobox with the acceptable > choices in it. I'm now planning a new application using PyQt5 and it > occured > to me that a set of radio buttons would also work. > > While a set of radiobuttons occupies more room on the parent widget > than > does a combobox are there any technical or user issues that would > suggest > using one over the other? > > TIA, > > Rich I use radiobuttons if the list of choices is small and static, like about 2 - 5 fixed entries. Comboboxes are better for larger lists, or if the user can add own entries, or if there's a chance that the program needs more entries later. IME, radiobuttons cause more visual distraction while comboboxes can be less obvious for less tech-savvy people. OTOH, comboboxes require two clicks. For your situation with units, I would probably go for radios if the user needs to change the units often and combos if radios would make the view more complex and less obvious. From enopatch at gmail.com Tue Apr 13 19:09:49 2021 From: enopatch at gmail.com (Jaime) Date: Wed, 14 Apr 2021 00:09:49 +0100 Subject: How does "__doc__ % globals()" work? In-Reply-To: Message-ID: <607624c4.1c69fb81.98dec.2dd1@mx.google.com> Chris and Ethan, Thank you both for your explanations - as soon as I read them, I understood where I was going wrong. I also found the mapping key "%(PROGRAM)s" inside the docstring on line 4 of https://github.com/python/peps/blob/master/pep2html.py Thanks again, Jaime. From tjreedy at udel.edu Tue Apr 13 18:39:36 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 13 Apr 2021 18:39:36 -0400 Subject: translating external files type thing In-Reply-To: <049e01d730a7$030cc840$092658c0$@verizon.net> References: <049e01d730a7$030cc840$092658c0$@verizon.net> Message-ID: On 4/13/2021 4:53 PM, Avi Gross via Python-list wrote: > https://translate.google.com/?sl=is&tl=en&op=translate > > Or, you could do it the hard way. > > Kidding aside, there may be a python module you can hand a file name or > contents to and have it do much of the job using some API that may tap into > the above Google resource. For one chunk of text under 5000 chars, the website is easiest. > Dan specifically suggested importing googletrans ... The author reverse engineered the undocumented ticket used by the web page. It will work until Google either bans one's IP address or disables googletrans by changing the protocol. Since Google's paid service only charges for chars over 500_000 in a month, Google is likely better off leaving the protocol alone and only banning users who would actually pay if signed up. > -----Original Message----- > From: Python-list On > Behalf Of Quentin Bock > Sent: Tuesday, April 13, 2021 3:16 PM > To: python-list at python.org > Subject: translating external files type thing > > okay, so I'm making a translating program, and I have files set to be > translated (they're in Icelandic) and I want all of them to be read in > English but I'm not sure how to open the files and translate them at the > same time. I'm also not even sure how to translate an external file to > English from another language. > I can't show code for this because I don't know if it's possible to do what > I'm asking. > Hopefully, this question is understandable Thanks > -- > https://mail.python.org/mailman/listinfo/python-list > -- Terry Jan Reedy From alan.gauld at yahoo.co.uk Tue Apr 13 19:35:23 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 14 Apr 2021 00:35:23 +0100 Subject: UI design: combobox or radiobuttons? In-Reply-To: References: Message-ID: On 13/04/2021 22:53, Rich Shepard wrote: > While a set of radiobuttons occupies more room on the parent widget than > does a combobox are there any technical or user issues that would suggest > using one over the other? readability? If the combo box puts the units immediately beside the value then it will be more readable than if it is a row of radio buttons above/below or beside the value. But if the radio buttons represent a unit choice that applies to all values on the screen then that is more noticeable and thus more readable than a single small combobox choice lurking in a corner somewhere. -- 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 rshepard at appl-ecosys.com Tue Apr 13 22:20:31 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 13 Apr 2021 19:20:31 -0700 (PDT) Subject: UI design: combobox or radiobuttons? In-Reply-To: References: Message-ID: On Wed, 14 Apr 2021, Alan Gauld via Python-list wrote: > readability? If the combo box puts the units immediately beside the value > then it will be more readable than if it is a row of radio buttons > above/below or beside the value. > > But if the radio buttons represent a unit choice that applies to all > values on the screen then that is more noticeable and thus more readable > than a single small combobox choice lurking in a corner somewhere. Excellent points, Alan. Thanks very much, Rich From rustbuckett at pm.me Tue Apr 13 22:54:34 2021 From: rustbuckett at pm.me (Russell) Date: Wed, 14 Apr 2021 02:54:34 +0000 (UTC) Subject: [ANN] Free Python tutorial with exercises, cscx.org References: <0c8fe4b8-f059-4b51-b0b6-296d5e945c1en@googlegroups.com> Message-ID: Jach Feng wrote: > Is there any reason a student/beginner learn Python now start from Python2? > > --Jach Only if you want a job porting python2 to python3. Python 2.x is officially End Of Life. -- rust 0x68caecc97f6a90122e51c0692c88d9cb6b58a3dc From mutazilah at gmail.com Wed Apr 14 06:35:45 2021 From: mutazilah at gmail.com (Paul Edwards) Date: Wed, 14 Apr 2021 03:35:45 -0700 (PDT) Subject: port to PDOS (especially mainframe) In-Reply-To: <619bf63f-d499-4e43-8eba-dde8e825d2bdn@googlegroups.com> References: <5c89d4f3-7ab3-80b4-c208-285216f16d77@gmail.com> <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> <8cb3be58-64c7-4251-b573-f08a286bd245n@googlegroups.com> <7ce030e3-6bc3-4187-9f1d-2fd33b9541ebn@googlegroups.com> <619bf63f-d499-4e43-8eba-dde8e825d2bdn@googlegroups.com> Message-ID: I have succeeded in producing a Python 3.3 executable despite being built with a C library that only supports C90. I had to provide my own mini-posix wrappers that convert open() into fopen() etc. With that in place, plus a compiler where char = wchar_t, there were not a lot of changes required to the Python mainline (see below). However, the executable doesn't work yet. Here's the current state: C:\devel\python\Modules>python Traceback (most recent call last): File "", line 1755, in _install File "", line 1726, in _setup ImportError: importlib requires posix or nt Fatal Python error: Py_Initialize: importlib install failed Current thread 0x00000000: That error message comes from here: C:\devel\python\Python>head importlib.h which is not human readable. It is generated by this code: C:\devel\python\Lib\importlib>grep "posix or nt" _bootstrap.py but I don't know what it needs to satisfy that. It's a bit strange that it can only be posix or nt when VMS is supported in 3.3 too. BFN. Paul. Index: Modules/main.c =================================================================== RCS file: c:\cvsroot/python/Modules/main.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -r1.1.1.1 -r1.2 728a729 > #ifndef PUREISO 738a740 > #endif Index: Modules/signalmodule.c =================================================================== RCS file: c:\cvsroot/python/Modules/signalmodule.c,v retrieving revision 1.1.1.1 retrieving revision 1.3 diff -r1.1.1.1 -r1.3 418a419 > #ifndef PUREISO 419a421 > #endif 429a432 > #ifndef PUREISO 433a437 > #endif Index: Objects/longobject.c =================================================================== RCS file: c:\cvsroot/python/Objects/longobject.c,v retrieving revision 1.1.1.1 retrieving revision 1.3 diff -r1.1.1.1 -r1.3 939,944d938 < #ifndef HAVE_LONG_LONG < # error "PyLong_FromVoidPtr: sizeof(void*) > sizeof(long), but no long long" < #endif < #if SIZEOF_LONG_LONG < SIZEOF_VOID_P < # error "PyLong_FromVoidPtr: sizeof(PY_LONG_LONG) < sizeof(void*)" < #endif 948c942,944 < return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)(Py_uintptr_t)p); --- > #if SIZEOF_VOID_P <= SIZEOF_LONG > return PyLong_FromUnsignedLong((unsigned long)(Py_uintptr_t)p); > #else 949a946,950 > #if SIZEOF_LONG_LONG < SIZEOF_VOID_P > # error "PyLong_FromVoidPtr: sizeof(long long) < sizeof(void*)" > #endif > return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)(Py_uintptr_t)p); > #endif /* SIZEOF_VOID_P <= SIZEOF_LONG */ 986c987 < #ifdef HAVE_LONG_LONG --- > #if 1 /*def HAVE_LONG_LONG */ 996a998 > #ifdef HAVE_LONG_LONG 1037a1040 > #endif 1040a1044 > #ifdef HAVE_LONG_LONG 1066a1071 > #endif 1139a1145 > #ifdef HAVE_LONG_LONG 1187a1194 > #endif 1191a1199 > #ifdef HAVE_LONG_LONG 1223a1232 > #endif 1227a1237 > #ifdef HAVE_LONG_LONG 1256a1267 > #endif 1257a1269 > #ifdef HAVE_LONG_LONG 1291a1304 > #endif 1303a1317 > #ifdef HAVE_LONG_LONG 1389a1404 > #endif Index: Objects/unicodeobject.c =================================================================== RCS file: c:\cvsroot/python/Objects/unicodeobject.c,v retrieving revision 1.1.1.1 retrieving revision 1.3 diff -r1.1.1.1 -r1.3 2243c2243 < #ifdef HAVE_WCHAR_H --- > #if defined(HAVE_WCHAR_H) || defined(PUREISO) 2865c2865 < #ifdef HAVE_WCHAR_H --- > #if defined(HAVE_WCHAR_H) || defined(PUREISO) 9148c9148 < // TODO: honor direction and do a forward or backwards search --- > /*TODO: honor direction and do a forward or backwards search */ Index: Parser/tokenizer.c =================================================================== RCS file: c:\cvsroot/python/Parser/tokenizer.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -r1.1.1.1 -r1.2 1720a1721,1723 > #ifdef PUREISO > return (NULL); > #else 1758a1762 > #endif /* PUREISO */ Index: Python/fileutils.c =================================================================== RCS file: c:\cvsroot/python/Python/fileutils.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -r1.1.1.1 -r1.2 40c40 < #ifdef HAVE_STAT --- > #if 1 /* def HAVE_STAT */ 279a280 > #ifdef HAVE_STAT 304a306 > #endif Index: Python/getopt.c =================================================================== RCS file: c:\cvsroot/python/Python/getopt.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -r1.1.1.1 -r1.2 33c33,35 < #include --- > #ifdef HAVE_WCHAR_H > # include > #endif Index: Python/pythonrun.c =================================================================== RCS file: c:\cvsroot/python/Python/pythonrun.c,v retrieving revision 1.1.1.1 retrieving revision 1.5 diff -r1.1.1.1 -r1.5 300a301,304 > /* Init Unicode implementation; relies on the codec registry */ > if (_PyUnicode_Init() < 0) > Py_FatalError("Py_Initialize: can't initialize unicode"); > 318,321d321 < /* Init Unicode implementation; relies on the codec registry */ < if (_PyUnicode_Init() < 0) < Py_FatalError("Py_Initialize: can't initialize unicode"); < 1009a1010 > #ifndef PUREISO 1021a1023 > #endif 1075a1078 > #ifndef PUREISO 1140a1144 > #endif /* PUREISO */ Index: Python/random.c =================================================================== RCS file: c:\cvsroot/python/Python/random.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -r1.1.1.1 -r1.2 4c4 < #else --- > #elif defined(HAVE_FCNTL_H) 119c119 < #if !defined(MS_WINDOWS) && !defined(__VMS) --- > #if !defined(MS_WINDOWS) && !defined(__VMS) && !defined(PUREISO) 239a240,241 > #elif defined(PUREISO) > return(-1); 287a290,291 > #elif defined(PUREISO) > return; Index: Python/sysmodule.c =================================================================== RCS file: c:\cvsroot/python/Python/sysmodule.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -r1.1.1.1 -r1.2 1581c1581 < #if !defined(MS_WINDOWS) --- > #if !defined(MS_WINDOWS) && !defined(PUREISO) From rainyis14 at gmail.com Wed Apr 14 09:41:37 2021 From: rainyis14 at gmail.com (Rainyis) Date: Wed, 14 Apr 2021 15:41:37 +0200 Subject: Website Message-ID: Hello, I am Sergio Llorente, and I want to create a web about python. I will publish apps, scripts.. made by python. I will like to put python in the domain. The domain will be like all-about-python.com but in Spanish( todosobrepython.com). Can I use it? Thanks in advance, Sergio From pbryan at anode.ca Wed Apr 14 12:02:59 2021 From: pbryan at anode.ca (Paul Bryan) Date: Wed, 14 Apr 2021 09:02:59 -0700 Subject: Website In-Reply-To: References: Message-ID: Yes. On Wed, 2021-04-14 at 15:41 +0200, Rainyis wrote: > Hello, > I am Sergio Llorente, and I want to create a web about python. I > will publish apps, scripts.. made by python. I will like to put > python in > the domain. The domain will be like all-about-python.com but in > Spanish( > todosobrepython.com). Can I use it? > > Thanks in advance, > Sergio From qberz2005 at gmail.com Wed Apr 14 12:13:38 2021 From: qberz2005 at gmail.com (Quentin Bock) Date: Wed, 14 Apr 2021 12:13:38 -0400 Subject: FileNotFoundError: [Errno 2] No such file or directory: '' Message-ID: I receive this error when I try to open a file The file (what I'm trying to open) is in the same folder as the program I'm trying to open it from; why is it saying no such file or directory? this is the only part of the code that causes the error file = open('Egils Saga 1-15.txt', "r") file.close() From drsalists at gmail.com Wed Apr 14 13:35:22 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 14 Apr 2021 10:35:22 -0700 Subject: FileNotFoundError: [Errno 2] No such file or directory: '' In-Reply-To: References: Message-ID: On Wed, Apr 14, 2021 at 9:14 AM Quentin Bock wrote: > I receive this error when I try to open a file > The file (what I'm trying to open) is in the same folder as the program I'm > trying to open it from; why is it saying no such file or directory? > > this is the only part of the code that causes the error > > file = open('Egils Saga 1-15.txt', "r") > > file.close() > Python will try to open the file in the directory you are currently in, rather than the directory your program is in. Try cd'ing to the appropriate directory first. Or specify a full to your file in the open. From nospam at please.ty Wed Apr 14 13:35:45 2021 From: nospam at please.ty (jak) Date: Wed, 14 Apr 2021 19:35:45 +0200 Subject: FileNotFoundError: [Errno 2] No such file or directory: '' References: Message-ID: Il 14/04/2021 18:13, Quentin Bock ha scritto: > I receive this error when I try to open a file > The file (what I'm trying to open) is in the same folder as the program I'm > trying to open it from; why is it saying no such file or directory? > > this is the only part of the code that causes the error > > file = open('Egils Saga 1-15.txt', "r") > > file.close() > >>> file = open('Egils Saga 1-15.txt', "r") >>> file.read() 'Hello from Egils Saga 1-15.txt' >>> file.close() Try to check your 'current working directory': >>> import os >>> os.getcwd() 'D:\\tmp' # where the file is >>> From drsalists at gmail.com Wed Apr 14 13:55:36 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 14 Apr 2021 10:55:36 -0700 Subject: FileNotFoundError: [Errno 2] No such file or directory: '' In-Reply-To: References: Message-ID: Open a cmd.exe, command.exe or powershell, and: cd c:\my\dir\ect\ory Then run your script. Or put an os.chdir(r'c:\my\dir\ect\ory') at the top of your script. Or use file = open(r'c:\my\dir\ect\ory\Egils Saga 1-15.txt', 'r') BTW, "file" means something to python other than just a variable name. You can replace it, as your code below (and my example above) does, but it obscures the thing you're replacing. That's why I like to use file_ instead of file. On Wed, Apr 14, 2021 at 10:42 AM Quentin Bock wrote: > Okay, how exactly do I do that? > Thanks > > On Wed, 14 Apr 2021 at 13:35, Dan Stromberg wrote: > >> >> >> On Wed, Apr 14, 2021 at 9:14 AM Quentin Bock wrote: >> >>> I receive this error when I try to open a file >>> The file (what I'm trying to open) is in the same folder as the program >>> I'm >>> trying to open it from; why is it saying no such file or directory? >>> >>> this is the only part of the code that causes the error >>> >>> file = open('Egils Saga 1-15.txt', "r") >>> >>> file.close() >>> >> >> Python will try to open the file in the directory you are currently in, >> rather than the directory your program is in. >> >> Try cd'ing to the appropriate directory first. Or specify a full to your >> file in the open. >> >> >> From alan.gauld at yahoo.co.uk Wed Apr 14 13:16:02 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 14 Apr 2021 18:16:02 +0100 Subject: Ann: New Python curses book In-Reply-To: References: Message-ID: On 30/03/2021 12:12, Alan Gauld via Python-list wrote: > I've just published, in Kindle and paperback formats, I've just noticed that the kindle version has several indentation problems in the code listings. I can't do anything to fix it because it is all perfectly aligned in the Word file I submit, it's caused somewhere in the Amazon conversion process. (In fact it's possibly its OK on some Kindle devices/apps, just not the web reader I was using!) Hopefully the expected readership will be smart enough to: a) figure it out from the context and b) download the sample code which is correctly formatted. The paper version should be fine (apart from one error on p44 which has now been fixed!). Apologies to anyone who got stung by this. -- 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 alan.gauld at yahoo.co.uk Wed Apr 14 13:45:44 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 14 Apr 2021 18:45:44 +0100 Subject: port to PDOS (especially mainframe) In-Reply-To: References: <5c89d4f3-7ab3-80b4-c208-285216f16d77@gmail.com> <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> <8cb3be58-64c7-4251-b573-f08a286bd245n@googlegroups.com> <7ce030e3-6bc3-4187-9f1d-2fd33b9541ebn@googlegroups.com> <619bf63f-d499-4e43-8eba-dde8e825d2bdn@googlegroups.com> Message-ID: On 14/04/2021 11:35, Paul Edwards wrote: > I have succeeded in producing a Python 3.3 executable ... > However, the executable doesn't work yet. Late to this party but how big is the assembler? It might be easier to translate the Python to C! I've done that in the past and with the aid of a few functions to mimic common Python constructs (dicts, foreach() etc) it was verbose but not too painful. If its <5K? lines of Python it might be easier. Just a thought. -- 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 rshepard at appl-ecosys.com Wed Apr 14 14:55:58 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 14 Apr 2021 11:55:58 -0700 (PDT) Subject: Ann: New Python curses book In-Reply-To: References: Message-ID: On Wed, 14 Apr 2021, Alan Gauld via Python-list wrote: > The paper version should be fine (apart from one error on p44 which has > now been fixed!). Alan, What's the error and correction so I can change it in my dead tree version? Rich From mstemper at gmail.com Wed Apr 14 15:37:45 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Wed, 14 Apr 2021 14:37:45 -0500 Subject: FileNotFoundError: [Errno 2] No such file or directory: '' In-Reply-To: References: Message-ID: On 14/04/2021 12.55, Dan Stromberg wrote: > Open a cmd.exe, command.exe or powershell, and: > > cd c:\my\dir\ect\ory > Then run your script. > > Or put an os.chdir(r'c:\my\dir\ect\ory') at the top of your script. > > Or use file = open(r'c:\my\dir\ect\ory\Egils Saga 1-15.txt', 'r') > > BTW, "file" means something to python other than just a variable name. You > can replace it, as your code below (and my example above) does, but it > obscures the thing you're replacing. That's why I like to use file_ > instead of file. Personally, I'd use a meaningful name. For instance, I might do saga = open(r'c:\my\dir\ect\ory\Egils Saga 1-15.txt', 'r') or even with open(r'c:\my\dir\ect\ory\Egils Saga 1-15.txt', 'r') as saga: The latter form eliminates the need for saga.close(). (I'm sure that you know that; it's directed at the OP.) -- Michael F. Stemper The FAQ for rec.arts.sf.written is at Please read it before posting. From mutazilah at gmail.com Wed Apr 14 16:04:40 2021 From: mutazilah at gmail.com (Paul Edwards) Date: Wed, 14 Apr 2021 13:04:40 -0700 (PDT) Subject: port to PDOS (especially mainframe) In-Reply-To: References: <5c89d4f3-7ab3-80b4-c208-285216f16d77@gmail.com> <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> <8cb3be58-64c7-4251-b573-f08a286bd245n@googlegroups.com> <7ce030e3-6bc3-4187-9f1d-2fd33b9541ebn@googlegroups.com> <619bf63f-d499-4e43-8eba-dde8e825d2bdn@googlegroups.com> Message-ID: <60f9336b-d150-4b1f-a43c-964d207fe587n@googlegroups.com> On Thursday, April 15, 2021 at 4:32:51 AM UTC+10, Alan Gauld wrote: > On 14/04/2021 11:35, Paul Edwards wrote: > > I have succeeded in producing a Python 3.3 executable > ... > > However, the executable doesn't work yet. > Late to this party but how big is the assembler? Assuming the stuff in "asma" has no dependency on the other .py files, it is 35,000 lines of code! I think I might need a linker from them too. I haven't seen the output of asma yet. > It might be easier to translate the Python to C! I would also have a maintenance problem going that way. I think other people would like Python to be available on MVS/380 too, for other projects. BTW, my Python is a 1.5 MB executable. That is without optimization and without symbols. BFN. Paul. From mgogala at yahoo.com Wed Apr 14 19:16:38 2021 From: mgogala at yahoo.com (Mladen Gogala) Date: Wed, 14 Apr 2021 23:16:38 +0000 (UTC) Subject: Website References: Message-ID: On Wed, 14 Apr 2021 15:41:37 +0200, Rainyis wrote: > Hello, > I am Sergio Llorente, and I want to create a web about python. I will > publish apps, scripts.. made by python. I will like to put python in the > domain. The domain will be like all-about-python.com but in Spanish( > todosobrepython.com). Can I use it? > > Thanks in advance, > Sergio I give you my permission. May the Force be with you and your website. -- Mladen Gogala Database Consultant https://dbwhisperer.wordpress.com From eryksun at gmail.com Thu Apr 15 00:40:14 2021 From: eryksun at gmail.com (Eryk Sun) Date: Wed, 14 Apr 2021 23:40:14 -0500 Subject: FileNotFoundError: [Errno 2] No such file or directory: '' In-Reply-To: References: Message-ID: On 4/14/21, Quentin Bock wrote: > > this is the only part of the code that causes the error > > file = open('Egils Saga 1-15.txt', "r") Here's an app_abspath() function to resolve a filename against the directory of the main script: import os import sys def get_main_file(): if hasattr(sys, 'frozen'): return sys.executable main = getattr(sys.modules.get('__main__'), '__file__', '') return os.path.abspath(main) if main else '' def get_main_dir(): return os.path.dirname(get_main_file()) or os.getcwd() def app_abspath(filename): return os.path.join(get_main_dir(), filename) file = open(app_abspath('Egils Saga 1-15.txt'), 'r') In the frozen script case, sys.executable is the main 'script'. For a "-c" command, there is no main file, so it uses the current working directory. Using the variable name "file" is fine so long as compatibility with Python 2 isn't required. In Python 3, "file" is not a reserved keyword and not the name of a builtin function or type. From dciprus at cisco.com Thu Apr 15 08:36:58 2021 From: dciprus at cisco.com (Dan Ciprus (dciprus)) Date: Thu, 15 Apr 2021 12:36:58 +0000 Subject: Website In-Reply-To: References: Message-ID: <20210415123657.esogxxczurvjj7js@localhost> https://en.wikipedia.org/wiki/Sergio_Llorente wow .. you made it that far ? Jokes aside .. why are you asking for a permission to get a domain ? I would love to read a deeper explanation what made you send an email to this mailing list. On Wed, Apr 14, 2021 at 03:41:37PM +0200, Rainyis wrote: >Hello, >I am Sergio Llorente, and I want to create a web about python. I >will publish apps, scripts.. made by python. I will like to put python in >the domain. The domain will be like all-about-python.com but in Spanish( >todosobrepython.com). Can I use it? > >Thanks in advance, >Sergio >-- >https://mail.python.org/mailman/listinfo/python-list -- Daniel Ciprus .:|:.:|:. CONSULTING ENGINEER.CUSTOMER DELIVERY Cisco Systems Inc. dciprus at cisco.com tel: +1-703-484-0205 mob: +1-540-223-7098 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: From alan.gauld at yahoo.co.uk Thu Apr 15 04:37:23 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 15 Apr 2021 09:37:23 +0100 Subject: Ann: New Python curses book In-Reply-To: References: Message-ID: On 14/04/2021 19:55, Rich Shepard wrote: > On Wed, 14 Apr 2021, Alan Gauld via Python-list wrote: > >> The paper version should be fine (apart from one error on p44 which has >> now been fixed!). > > Alan, > > What's the error and correction so I can change it in my dead tree version? > > Rich In the main() function the block of code starting with the 'with' statement should be indented to be part of main(). It has been left at the outermost indentation level. The source code file is correct so check against that. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From rshepard at appl-ecosys.com Thu Apr 15 09:23:53 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 15 Apr 2021 06:23:53 -0700 (PDT) Subject: Ann: New Python curses book In-Reply-To: References: Message-ID: On Thu, 15 Apr 2021, Alan Gauld via Python-list wrote: > In the main() function the block of code starting with the 'with' > statement should be indented to be part of main(). It has been left at the > outermost indentation level. > > The source code file is correct so check against that. Thanks, Alan. Rich From o1bigtenor at gmail.com Thu Apr 15 09:49:45 2021 From: o1bigtenor at gmail.com (o1bigtenor) Date: Thu, 15 Apr 2021 08:49:45 -0500 Subject: Website In-Reply-To: <20210415123657.esogxxczurvjj7js@localhost> References: <20210415123657.esogxxczurvjj7js@localhost> Message-ID: On Thu, Apr 15, 2021 at 7:40 AM Dan Ciprus (dciprus) via Python-list wrote: > > https://en.wikipedia.org/wiki/Sergio_Llorente > > wow .. you made it that far ? > > Jokes aside .. why are you asking for a permission to get a domain ? I would > love to read a deeper explanation what made you send an email to this mailing > list. > > On Wed, Apr 14, 2021 at 03:41:37PM +0200, Rainyis wrote: > >Hello, > >I am Sergio Llorente, and I want to create a web about python. I > >will publish apps, scripts.. made by python. I will like to put python in > >the domain. The domain will be like all-about-python.com but in Spanish( > >todosobrepython.com). Can I use it? > > > >Thanks in advance, > >Sergio > >-- > >https://mail.python.org/mailman/listinfo/python-list > I would suggest that you quite missed the point of the question. To me he is asking if he can use the word "python", which carries a lot of meaning in the computer world, in his domain name. I'd be handing him top marks for his asking rather than laughing that he did ask. Its a very polite and respectful thing to ask before registering the domain imo. Regards From dciprus at cisco.com Thu Apr 15 09:54:15 2021 From: dciprus at cisco.com (Dan Ciprus (dciprus)) Date: Thu, 15 Apr 2021 13:54:15 +0000 Subject: Website In-Reply-To: References: <20210415123657.esogxxczurvjj7js@localhost>, Message-ID: Well I did not get the point of his question, obviously so apologies for being sarcastic at the beginning. This triggered my reaction because of the history of "funny" questions which you can find in this mailing list. Sent from my smartphone Do Not Get Outlook for Android ! ________________________________ From: o1bigtenor Sent: Thursday, April 15, 2021 9:49:45 AM To: Dan Ciprus (dciprus) Cc: Rainyis ; python-list at python.org Subject: Re: Website On Thu, Apr 15, 2021 at 7:40 AM Dan Ciprus (dciprus) via Python-list wrote: > > https://en.wikipedia.org/wiki/Sergio_Llorente > > wow .. you made it that far ? > > Jokes aside .. why are you asking for a permission to get a domain ? I would > love to read a deeper explanation what made you send an email to this mailing > list. > > On Wed, Apr 14, 2021 at 03:41:37PM +0200, Rainyis wrote: > >Hello, > >I am Sergio Llorente, and I want to create a web about python. I > >will publish apps, scripts.. made by python. I will like to put python in > >the domain. The domain will be like all-about-python.com but in Spanish( > >todosobrepython.com). Can I use it? > > > >Thanks in advance, > >Sergio > >-- > >https://mail.python.org/mailman/listinfo/python-list > I would suggest that you quite missed the point of the question. To me he is asking if he can use the word "python", which carries a lot of meaning in the computer world, in his domain name. I'd be handing him top marks for his asking rather than laughing that he did ask. Its a very polite and respectful thing to ask before registering the domain imo. Regards From cspealma at redhat.com Thu Apr 15 09:57:30 2021 From: cspealma at redhat.com (Calvin Spealman) Date: Thu, 15 Apr 2021 09:57:30 -0400 Subject: Website In-Reply-To: References: Message-ID: The PSF guidelines on trademark usage are generous and well documented here: https://www.python.org/psf/trademarks/ Good luck with your website! On Wed, Apr 14, 2021 at 11:43 AM Rainyis wrote: > Hello, > I am Sergio Llorente, and I want to create a web about python. I > will publish apps, scripts.. made by python. I will like to put python in > the domain. The domain will be like all-about-python.com but in Spanish( > todosobrepython.com). Can I use it? > > Thanks in advance, > Sergio > -- > https://mail.python.org/mailman/listinfo/python-list > > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER calvin.spealman at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From o1bigtenor at gmail.com Thu Apr 15 09:59:43 2021 From: o1bigtenor at gmail.com (o1bigtenor) Date: Thu, 15 Apr 2021 08:59:43 -0500 Subject: Website In-Reply-To: References: <20210415123657.esogxxczurvjj7js@localhost> Message-ID: On Thu, Apr 15, 2021 at 8:54 AM Dan Ciprus (dciprus) wrote: > > Well I did not get the point of his question, obviously so apologies for being sarcastic at the beginning. This triggered my reaction because of the history of "funny" questions which you can find in this mailing list. > Agreed that there are far too many questions asked here that might not be that useful. I don't know for sure but thought I understood the 'spirit' of the question - - - I hope that I did! (Or I get to look like a turkey - - - - LOL - - - - as my wife so often tells me - - - LOL) Regards From o1bigtenor at gmail.com Thu Apr 15 11:37:23 2021 From: o1bigtenor at gmail.com (o1bigtenor) Date: Thu, 15 Apr 2021 10:37:23 -0500 Subject: Website In-Reply-To: References: Message-ID: On Thu, Apr 15, 2021 at 8:59 AM Calvin Spealman wrote: > > The PSF guidelines on trademark usage are generous and well documented > here: https://www.python.org/psf/trademarks/ > > Good luck with your website! > > On Wed, Apr 14, 2021 at 11:43 AM Rainyis wrote: > > > Hello, > > I am Sergio Llorente, and I want to create a web about python. I > > will publish apps, scripts.. made by python. I will like to put python in > > the domain. The domain will be like all-about-python.com but in Spanish( > > todosobrepython.com). Can I use it? > > > > Thanks in advance, > > Senor Sergio This , from the previous attached doc : Uses that Always Require Approval Any commercial use of the PSF trademarks in product or company names must be approved first by the PSF. Some uses, like calling a company "The Python Company," or a product "Python Language" or "Python IDE" will be refused. This is because they are overly broad, or confusing as to whether the Python programming language is open source or commercial, or whether your product or organization is affiliated with or sponsored by PSF. would suggest that you contact the Python Trademark Committee. I would assume that searching on the Python webpage should enable one to find some contact information for such. I, for one, without any influence, would suggest to such committee that you be allowed to register such titled domain. (Please do remember that I have no connection with said committee just that you did ask and did so in a way that, imo anyway, showed you were working in the spirit of the matter at very least!) Regards From jorge.conforte at inpe.br Thu Apr 15 13:58:35 2021 From: jorge.conforte at inpe.br (Jorge Conforte) Date: Thu, 15 Apr 2021 14:58:35 -0300 Subject: TIME IN XARRAY Message-ID: <9f570438-3db7-05a8-26f2-58c452278caa@inpe.br> Hi, I'm using xarray to read netcdf data and I had to time in my data the values: xarray.DataArray 'time' (time: 507)> array(['1979-01-01T00:00:00.000000000', '1979-02-01T00:00:00.000000000', ?????? '1979-03-01T00:00:00.000000000', ..., '2021-01-01T00:00:00.000000000', ?????? '2021-02-01T00:00:00.000000000', '2021-03-01T00:00:00.000000000'], ????? dtype='datetime64[ns]') Please, how can I get the years and months values from this array. Thanks, Conrado From rosuav at gmail.com Thu Apr 15 14:20:15 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 16 Apr 2021 04:20:15 +1000 Subject: TIME IN XARRAY In-Reply-To: <9f570438-3db7-05a8-26f2-58c452278caa@inpe.br> References: <9f570438-3db7-05a8-26f2-58c452278caa@inpe.br> Message-ID: On Fri, Apr 16, 2021 at 4:16 AM Jorge Conforte wrote: > I'm using xarray to read netcdf data and I had to time in my data the > values: > > xarray.DataArray 'time' (time: 507)> > array(['1979-01-01T00:00:00.000000000', '1979-02-01T00:00:00.000000000', > '1979-03-01T00:00:00.000000000', ..., > '2021-01-01T00:00:00.000000000', > '2021-02-01T00:00:00.000000000', '2021-03-01T00:00:00.000000000'], > dtype='datetime64[ns]') > > > Please, how can I get the years and months values from this array. > Looks like your "time" values are ISO-8601 dates, stored as strings. You should be able to parse them easily by hand, or hand them to datetime.datetime.fromisoformat(). ChrisA From Matthew.Dodson at Giants.NFL.net Thu Apr 15 14:02:07 2021 From: Matthew.Dodson at Giants.NFL.net (Dodson, Matthew) Date: Thu, 15 Apr 2021 18:02:07 +0000 Subject: Repair Install of 64 bit python Message-ID: Hi, Having an issue after installing 64 bit python. Can't pip install any packages. Get the error "No module named pip". Thanks, Matt Matthew Dodson 2020 Data Analytics/Video Intern New York Football Giants Quest Diagnostics Training Center 1925 Giants Drive East Rutherford, NJ 07073 o: 201-806-1749 Matthew.Dodson at Giants.NFL.net This e-mail is intended only for the use of the individual or entity named above and contains confidential and privileged information. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender of the e-mail and destroy the original message. UNLESS CLEARLY STATED, NOTHING IN THIS E-MAIL, IN ANY E-MAIL THREAD OF WHICH IT MAY BE A PART, OR IN ANY ATTACHMENTS THERETO, SHALL CONSTITUTE A BINDING CONTRACT, OR ANY CONTRACTUAL OBLIGATION, OR ANY INTENT TO ENTER INTO ANY BINDING OBLIGATIONS. From o1bigtenor at gmail.com Thu Apr 15 21:36:56 2021 From: o1bigtenor at gmail.com (o1bigtenor) Date: Thu, 15 Apr 2021 20:36:56 -0500 Subject: Repair Install of 64 bit python In-Reply-To: References: Message-ID: On Thu, Apr 15, 2021 at 8:03 PM Dodson, Matthew wrote: > > Hi, > > Having an issue after installing 64 bit python. Can't pip install any packages. Get the error "No module named pip". > No expert here but to me that reads like you need to install 'pip'. On linux I need to make sure its pip3 - - - for python 3. Then after that's done you sounds be able to go $ pip3 install xxxxx . HTH From mal at europython.eu Fri Apr 16 05:34:11 2021 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 16 Apr 2021 11:34:11 +0200 Subject: EuroPython 2021: Launching the conference website Message-ID: <07f0bac1-43ff-d1eb-1b6e-0aa41996c2d9@europython.eu> During the last few weeks the team has been hard at work making final changes to the website, and we are excited to announce the launch of the conference website for EuroPython 2021 today ! * EuroPython 2021 Conference Website * https://ep2021.europython.eu/ We have also migrated the accounts from last year's website to the new one, so you should be able to login right away. That said, we still recommend changing your password as best practice. If you don't have an account yet, you can easily create one to be ready for ticket sales. Quick Summary ------------- EuroPython 2021 will be run online from July 26 - August 1: - Two workshop/training days (July 26 - 27) - Three conference days (July 28 - 30) - Two sprint days (July 31 - August 1) The sessions will be scheduled to ensure they are also accessible for those in the Asian and Americas time zones. More updates ------------ - Ticket sales will start on Monday, April 19. We have refined the ticket structure for EuroPython 2021 to make it easier to understand and added a table outlining the differences between the various ticket types. - Financial aid will once again be available, since we've grown our team. We'd like to enable more people from lower income countries to attend. Applications can be filed starting Wednesday, April 21. - The Call for Papers (CFP) will be opened on Monday, April 26. If you want to prepare, you can already have a look at the CFP page on the website. The CFP will stay open for two weeks. A mentorship program for first time speakers is planned as well. - Sponsorship packages are already available for review. If you decide to sponsor until May 7, you can get a 10% Early Bird discount on your packages. We will send out more detailed posts on the above items in due course. Please subscribe to our newsletter if you want to make sure to get all information: https://ep2021.europython.eu/newsletter/ Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/europython-2021-launching-the-conference-website/ Tweet: https://twitter.com/europython/status/1382986951830204420 Enjoy, -- EuroPython 2021 Team https://www.europython-society.org/ From __peter__ at web.de Fri Apr 16 08:18:53 2021 From: __peter__ at web.de (Peter Otten) Date: Fri, 16 Apr 2021 14:18:53 +0200 Subject: TIME IN XARRAY In-Reply-To: References: <9f570438-3db7-05a8-26f2-58c452278caa@inpe.br> Message-ID: <1d28423f-cb34-1750-3f80-9dd85105c6fc@web.de> On 15/04/2021 20:20, Chris Angelico wrote: > On Fri, Apr 16, 2021 at 4:16 AM Jorge Conforte wrote: >> I'm using xarray to read netcdf data and I had to time in my data the >> values: >> >> xarray.DataArray 'time' (time: 507)> >> array(['1979-01-01T00:00:00.000000000', '1979-02-01T00:00:00.000000000', >> '1979-03-01T00:00:00.000000000', ..., >> '2021-01-01T00:00:00.000000000', >> '2021-02-01T00:00:00.000000000', '2021-03-01T00:00:00.000000000'], >> dtype='datetime64[ns]') >> >> >> Please, how can I get the years and months values from this array. >> > > Looks like your "time" values are ISO-8601 dates, stored as strings. > You should be able to parse them easily by hand, or hand them to > datetime.datetime.fromisoformat(). The dtype is a strong hint that there is a numpy or pandas datetime object underneath the misleading repr(). Assuming that x is the column array I'd try [d.year for d in x] or x.map(operator.attrgetter("year")) From __peter__ at web.de Fri Apr 16 08:18:53 2021 From: __peter__ at web.de (Peter Otten) Date: Fri, 16 Apr 2021 14:18:53 +0200 Subject: TIME IN XARRAY In-Reply-To: References: <9f570438-3db7-05a8-26f2-58c452278caa@inpe.br> Message-ID: <1d28423f-cb34-1750-3f80-9dd85105c6fc@web.de> On 15/04/2021 20:20, Chris Angelico wrote: > On Fri, Apr 16, 2021 at 4:16 AM Jorge Conforte wrote: >> I'm using xarray to read netcdf data and I had to time in my data the >> values: >> >> xarray.DataArray 'time' (time: 507)> >> array(['1979-01-01T00:00:00.000000000', '1979-02-01T00:00:00.000000000', >> '1979-03-01T00:00:00.000000000', ..., >> '2021-01-01T00:00:00.000000000', >> '2021-02-01T00:00:00.000000000', '2021-03-01T00:00:00.000000000'], >> dtype='datetime64[ns]') >> >> >> Please, how can I get the years and months values from this array. >> > > Looks like your "time" values are ISO-8601 dates, stored as strings. > You should be able to parse them easily by hand, or hand them to > datetime.datetime.fromisoformat(). The dtype is a strong hint that there is a numpy or pandas datetime object underneath the misleading repr(). Assuming that x is the column array I'd try [d.year for d in x] or x.map(operator.attrgetter("year")) From dciprus at cisco.com Fri Apr 16 09:13:02 2021 From: dciprus at cisco.com (Dan Ciprus (dciprus)) Date: Fri, 16 Apr 2021 13:13:02 +0000 Subject: Repair Install of 64 bit python In-Reply-To: References: Message-ID: <20210416131300.xjytudlzlzloaj3q@localhost> Isn't the recommended python3 way of pip-ing stuff: python3 -m pip install ... .. just curious. On Thu, Apr 15, 2021 at 08:36:56PM -0500, o1bigtenor wrote: >On Thu, Apr 15, 2021 at 8:03 PM Dodson, Matthew > wrote: >> >> Hi, >> >> Having an issue after installing 64 bit python. Can't pip install any packages. Get the error "No module named pip". >> > >No expert here but to me that reads like you need to install 'pip'. > >On linux I need to make sure its pip3 - - - for python 3. >Then after that's done you sounds be able to go $ pip3 install xxxxx . > >HTH >-- >https://mail.python.org/mailman/listinfo/python-list -- Daniel Ciprus .:|:.:|:. CONSULTING ENGINEER.CUSTOMER DELIVERY Cisco Systems Inc. dciprus at cisco.com tel: +1-703-484-0205 mob: +1-540-223-7098 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: From cs at cskk.id.au Fri Apr 16 10:15:03 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 17 Apr 2021 00:15:03 +1000 Subject: Repair Install of 64 bit python In-Reply-To: <20210416131300.xjytudlzlzloaj3q@localhost> References: <20210416131300.xjytudlzlzloaj3q@localhost> Message-ID: On 16Apr2021 13:13, Dan Ciprus (dciprus) wrote: >Isn't the recommended python3 way of pip-ing stuff: > >python3 -m pip install ... > >.. just curious. If there's only one Python 3 installed then "pip3 install ..." _ought_ to be equivalent. However, in the face of virtualenvs etc there may often be several pip3s. Using "python3 -m pip install ..." ensures that you are using the pip which is associated with "python3" (which you can adjust to be whichever python3 you intend). This is why the "-m pip" form is recommended: it definitely installs in the Python you'd be running. Cheers, Cameron Simpson From zljubisic at gmail.com Fri Apr 16 09:51:57 2021 From: zljubisic at gmail.com (Zoran) Date: Fri, 16 Apr 2021 06:51:57 -0700 (PDT) Subject: Async telnet, which package and how? Message-ID: Hi, I have to asynchronously connect to many home routers with telnet protocol in order to get some values. Upon getting input data (ip, username, password), I should connect to the router, execute commands, get their results, postprocess results and finally return certain values. Everything should work in asyncio loop. I searched a bit and I found that people usually use telnetlib3 for such task, but I can't find out examples that shows how to use telnetlib3.TelnetClient for my use case. If someone here has some experiences or has some demo code, please share. Regards. From qberz2005 at gmail.com Fri Apr 16 13:11:32 2021 From: qberz2005 at gmail.com (Quentin Bock) Date: Fri, 16 Apr 2021 13:11:32 -0400 Subject: setting user input equal to target language in Google Translator Message-ID: is it possible to set the target language of a translation to be the input from a user? I have tried inputting specific abbreviations that would normally be accepted as the target language but it remains in Icelandic and I would like to change the target language based on the user's input without creating hundred of scenarios for each inputted language or country. Thanks From mutazilah at gmail.com Fri Apr 16 13:59:06 2021 From: mutazilah at gmail.com (Paul Edwards) Date: Fri, 16 Apr 2021 10:59:06 -0700 (PDT) Subject: port to PDOS (especially mainframe) In-Reply-To: References: <5c89d4f3-7ab3-80b4-c208-285216f16d77@gmail.com> <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> <8cb3be58-64c7-4251-b573-f08a286bd245n@googlegroups.com> <7ce030e3-6bc3-4187-9f1d-2fd33b9541ebn@googlegroups.com> <619bf63f-d499-4e43-8eba-dde8e825d2bdn@googlegroups.com> Message-ID: <2daa8fd5-8763-4924-9910-edab1639baa8n@googlegroups.com> On Wednesday, April 14, 2021 at 8:35:59 PM UTC+10, Paul Edwards wrote: > ImportError: importlib requires posix or nt > but I don't know what it needs to satisfy that. > > It's a bit strange that it can only be posix or nt when VMS is supported in 3.3 too. The resolution to this problem was to include: {"posix", PyInit_posix}, in config.c and compile posixmodule.c. I'm now on to the next problem. BFN. Paul. From __peter__ at web.de Fri Apr 16 14:22:35 2021 From: __peter__ at web.de (Peter Otten) Date: Fri, 16 Apr 2021 20:22:35 +0200 Subject: setting user input equal to target language in Google Translator In-Reply-To: References: Message-ID: On 16/04/2021 19:11, Quentin Bock wrote: > is it possible to set the target language of a translation to be the input > from a user? > I have tried inputting specific abbreviations that would normally be > accepted as the target language but it remains in Icelandic and I would > like to change the target language based on the user's input without > creating hundred of scenarios for each inputted language or country. > Thanks Hi, Quentin! When you ask a question it is best to give the code you have. For beginner problems you may even get a hint from people who haven't used the library in question. That said, I have just installed googletrans, and changing the destination language appears to be as easy as >>> import googletrans as gt >>> t = gt.Translator() >>> for language in ["de", "fr", "es"]: ... print(t.translate("Hello, world!", dest=language).text) ... Hallo Welt! Bonjour le monde! ?Hola Mundo! Does that help? From __peter__ at web.de Fri Apr 16 14:22:35 2021 From: __peter__ at web.de (Peter Otten) Date: Fri, 16 Apr 2021 20:22:35 +0200 Subject: setting user input equal to target language in Google Translator In-Reply-To: References: Message-ID: On 16/04/2021 19:11, Quentin Bock wrote: > is it possible to set the target language of a translation to be the input > from a user? > I have tried inputting specific abbreviations that would normally be > accepted as the target language but it remains in Icelandic and I would > like to change the target language based on the user's input without > creating hundred of scenarios for each inputted language or country. > Thanks Hi, Quentin! When you ask a question it is best to give the code you have. For beginner problems you may even get a hint from people who haven't used the library in question. That said, I have just installed googletrans, and changing the destination language appears to be as easy as >>> import googletrans as gt >>> t = gt.Translator() >>> for language in ["de", "fr", "es"]: ... print(t.translate("Hello, world!", dest=language).text) ... Hallo Welt! Bonjour le monde! ?Hola Mundo! Does that help? From mutazilah at gmail.com Fri Apr 16 16:02:43 2021 From: mutazilah at gmail.com (Paul Edwards) Date: Fri, 16 Apr 2021 13:02:43 -0700 (PDT) Subject: port to PDOS (especially mainframe) In-Reply-To: <87wnt2oxfb.fsf@nightsong.com> References: <5c89d4f3-7ab3-80b4-c208-285216f16d77@gmail.com> <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> <8cb3be58-64c7-4251-b573-f08a286bd245n@googlegroups.com> <7ce030e3-6bc3-4187-9f1d-2fd33b9541ebn@googlegroups.com> <619bf63f-d499-4e43-8eba-dde8e825d2bdn@googlegroups.com> <87wnt2oxfb.fsf@nightsong.com> Message-ID: On Saturday, April 17, 2021 at 5:13:31 AM UTC+10, Paul Rubin wrote: > Paul Edwards writes: > > I have succeeded in producing a Python 3.3 executable despite being > > built with a C library that only supports C90. > It seems to me that you might have an easier time porting MicroPython > than CPython, if MicroPython fills your requirements. The documentation for "asma" says it requires Python 3.3 or above, and I have no idea how accurate that claim is. I'll only know whether *my* flavor of Python 3.3 is good enough for "asma" when I reach that point. BFN. Paul. From drsalists at gmail.com Fri Apr 16 16:17:56 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 16 Apr 2021 13:17:56 -0700 Subject: port to PDOS (especially mainframe) In-Reply-To: References: <5c89d4f3-7ab3-80b4-c208-285216f16d77@gmail.com> <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> <8cb3be58-64c7-4251-b573-f08a286bd245n@googlegroups.com> <7ce030e3-6bc3-4187-9f1d-2fd33b9541ebn@googlegroups.com> <619bf63f-d499-4e43-8eba-dde8e825d2bdn@googlegroups.com> <87wnt2oxfb.fsf@nightsong.com> Message-ID: On Fri, Apr 16, 2021 at 1:05 PM Paul Edwards wrote: > On Saturday, April 17, 2021 at 5:13:31 AM UTC+10, Paul Rubin wrote: > > Paul Edwards writes: > > > I have succeeded in producing a Python 3.3 executable despite being > > > built with a C library that only supports C90. > > > It seems to me that you might have an easier time porting MicroPython > > than CPython, if MicroPython fills your requirements. > > The documentation for "asma" says it requires Python 3.3 > or above, and I have no idea how accurate that claim is. > > I'll only know whether *my* flavor of Python 3.3 is good > enough for "asma" when I reach that point. > It'd probably be pretty simple to build micropython on a Linux system, and try to run asma on that. I've built micropython Linux before. If asma runs there, it'd suggest you might do well to port micropython to PDOS instead. Micropython has the dual benefits of being small and being supported. CPython 3.3 doesn't even get security fixes anymore. From mutazilah at gmail.com Fri Apr 16 16:29:58 2021 From: mutazilah at gmail.com (Paul Edwards) Date: Fri, 16 Apr 2021 13:29:58 -0700 (PDT) Subject: port to PDOS (especially mainframe) In-Reply-To: References: <5c89d4f3-7ab3-80b4-c208-285216f16d77@gmail.com> <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> <8cb3be58-64c7-4251-b573-f08a286bd245n@googlegroups.com> <7ce030e3-6bc3-4187-9f1d-2fd33b9541ebn@googlegroups.com> <619bf63f-d499-4e43-8eba-dde8e825d2bdn@googlegroups.com> <87wnt2oxfb.fsf@nightsong.com> Message-ID: <109b9319-22b1-4ac3-ae0f-19902b10b303n@googlegroups.com> On Saturday, April 17, 2021 at 6:18:29 AM UTC+10, Dan Stromberg wrote: > If asma runs there, it'd suggest you might do well to port micropython to > PDOS instead. > > Micropython has the dual benefits of being small and being supported. > CPython 3.3 doesn't even get security fixes anymore. Ok, thanks. I'll consider doing that as well. BFN. Paul. From nospam at please.ty Fri Apr 16 17:51:50 2021 From: nospam at please.ty (jak) Date: Fri, 16 Apr 2021 23:51:50 +0200 Subject: port to PDOS (especially mainframe) References: <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> Message-ID: Il 23/03/2021 10:23, Paul Edwards ha scritto: > Hello. I have a new operating system called PDOS > which works on both PC and mainframe, which > can be found here: > > http://pdos.sourceforge.net/ > > I know nothing about Python, my focus is on C90, > but I wish to run this mainframe assembler, asma, > which was written in Python, not C: > > https://github.com/s390guy/SATK > > It needs Python 3.3 as a minimum, so I wish to port > that version, first to the PC version of PDOS, then to > the mainframe version. > > I don't wish to run configure, I want to hand-construct > the makefile. PDOS is a very simple system, so I only > want to produce a single executable, no DLLs etc. I > don't need extensions to work or anything, all I need > to be able to do is run asma. > > I've started constructing a makefile (see below), which > I execute with pdmake, included in PDOS. I only have > a C90 runtime library, no more, no less, so I don't know > whether Python will actually build in my environment, > but so far things have been building successfully. > > However I'm currently stuck on this unresolved > external: > > python.a(abstract.o)(.text+0x668c):abstract.c: undefined reference to `PyExc_StopIteration' > > What source file is meant to define that variable > (PyExc_StopIteration) as opposed to just declaring > it or using it? I tried looking at the OS/2 EMX for > hints, but wasn't able to figure it out. > > Note that I am building a Win32 executable to start > with, but it is linking against my own C90 library > which will call either Microsoft's MSVCRT.DLL on > Windows, or my own MSVCRT.DLL when running > on PDOS/386 (aka PD-Windows). > > I also don't know whether Python will survive being > transferred to an EBCDIC environment, as that is > where it will ultimately need to be compiled and > linked (MVS/380), or at least assembled, before it > can wind up on PDOS/3X0. Well, maybe it can all > be done on Windows. I need to see what asma > is capable of. > > Thanks. Paul. > > > > # Produce Windows executables > # links with PDPCLIB created by makefile.msv > > CC=gccwin > CFLAGS=-O0 > LD=ldwin > LDFLAGS= > AS=aswin > AR=arwin > STRIP=stripwin > COPTS=-S $(CFLAGS) -fno-common -ansi -I. -I../Include -I../../pdos/pdpclib -D__WIN32__ > > all: clean python.exe > > python.exe: python.o ../Python/strdup.o ../Objects/object.o ../Objects/abstract.o \ > ../Python/errors.o ../Objects/bytesobject.o > rm -f python.a > ar r python.a ../Python/strdup.o ../Objects/object.o ../Objects/abstract.o > ar r python.a ../Python/errors.o ../Objects/bytesobject.o > $(LD) $(LDFLAGS) -o python.exe ../../pdos/pdpclib/w32start.o python.o python.a ../../pdos/pdpclib/msvcrt.a ../../pdos/src/kernel32.a > $(STRIP) python.exe > > .c.o: > $(CC) $(COPTS) -o $*.s $< > $(AS) -o $@ $*.s > rm -f $*.s > > clean: > rm -f *.o python.exe > Hi, one thing is not clear to me, do you absolutely need to use "asma"? http://www.z390.org/ From mutazilah at gmail.com Fri Apr 16 18:39:20 2021 From: mutazilah at gmail.com (Paul Edwards) Date: Fri, 16 Apr 2021 15:39:20 -0700 (PDT) Subject: port to PDOS (especially mainframe) In-Reply-To: References: <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> Message-ID: <86e0478c-d35f-4392-b091-b808610d553cn@googlegroups.com> On Saturday, April 17, 2021 at 7:52:07 AM UTC+10, jak wrote: > Hi, > one thing is not clear to me, do you absolutely need to use "asma"? > > http://www.z390.org/ The link you provided is to something that runs on PC environments. I want to produce EBCDIC executables that run on a S/3X0 (or z/Arch) machine (even if I personally do that via emulation). The only way I currently have of doing that is to assemble and link using what comes with MVS 3.8J. But that's all written in S/370 assembler using features that only exist on MVS. PDOS/3X0 doesn't support all those features. It only supports C90-compliant applications. Meanwhile, 35,000 lines (or more) of lovingly handcrafted Python code are going to waste. :-) BFN. Paul. From drsalists at gmail.com Sat Apr 17 00:36:51 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 16 Apr 2021 21:36:51 -0700 Subject: port to PDOS (especially mainframe) In-Reply-To: <86e0478c-d35f-4392-b091-b808610d553cn@googlegroups.com> References: <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> <86e0478c-d35f-4392-b091-b808610d553cn@googlegroups.com> Message-ID: On Fri, Apr 16, 2021 at 3:40 PM Paul Edwards wrote: > On Saturday, April 17, 2021 at 7:52:07 AM UTC+10, jak wrote: > > > Hi, > > one thing is not clear to me, do you absolutely need to use "asma"? > > > > http://www.z390.org/ > > The link you provided is to something that runs on PC > environments. > > I want to produce EBCDIC executables that run on a > S/3X0 (or z/Arch) machine (even if I personally do > that via emulation). > I thought EBCDIC was analogous to ASCII? Is it also analogous to a.out, ELF and COFF? From mutazilah at gmail.com Sat Apr 17 04:56:46 2021 From: mutazilah at gmail.com (Paul Edwards) Date: Sat, 17 Apr 2021 01:56:46 -0700 (PDT) Subject: port to PDOS (especially mainframe) In-Reply-To: References: <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> Message-ID: On Saturday, April 17, 2021 at 7:52:07 AM UTC+10, jak wrote: > one thing is not clear to me, do you absolutely need to use "asma"? > > http://www.z390.org/ I forgot to mention that it also requires Java. So instead of porting Python to the S/3X0 I would need to port Java. Note that Java (and Python for that matter) are available for later versions of z/OS, but as far as I am aware, they are not available for the free MVS that hobbyists use, ie MVS 3.8J, and it's definitely not available for the environment I'm actually interested in, which is PDOS/3X0. BFN. Paul. From mutazilah at gmail.com Sat Apr 17 05:04:33 2021 From: mutazilah at gmail.com (Paul Edwards) Date: Sat, 17 Apr 2021 02:04:33 -0700 (PDT) Subject: port to PDOS (especially mainframe) In-Reply-To: References: <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> <86e0478c-d35f-4392-b091-b808610d553cn@googlegroups.com> Message-ID: On Saturday, April 17, 2021 at 2:37:23 PM UTC+10, Dan Stromberg wrote: > > I want to produce EBCDIC executables that run on a > > S/3X0 (or z/Arch) machine (even if I personally do > > that via emulation). > > > I thought EBCDIC was analogous to ASCII? EBCDIC is an alternative to ASCII. E.g. the character '0' is at position x'F0' in EBCDIC compared to x'30' in ASCII. Note that in EBCDIC, the letters 'A' to 'Z' are not contiguous either, and the C90 standard has been carefully worded and designed so that you can rely on digits being contiguous, but not letters. > Is it also analogous to a.out, ELF and COFF? MVS 3.8J doesn't use any of those formats. The executable format is just called "MVS load module". And the object format is just called "object code". I'm not aware of any special names for them. PDOS/3X0 currently only runs MVS load modules, but I have plans for a PDOS-generic which will run under PDOS/3X0, and will use FAT instead of the MVS file system (basically just a VTOC, equivalent of a root directory, no subdirectories). So the VTOC would have one important flat file which PDOS-generic will access to provide a FAT facility to any applications running under PDOS-generic. Those applications will need to be specific to PDOS-generic and they may well be a.out/ELF/COFF - I haven't reached that point yet. I'm still preparing the assembler, I can't do what I want without that. :-) BFN. Paul. From nospam at please.ty Sat Apr 17 06:12:37 2021 From: nospam at please.ty (jak) Date: Sat, 17 Apr 2021 12:12:37 +0200 Subject: port to PDOS (especially mainframe) References: <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> Message-ID: Il 17/04/2021 10:56, Paul Edwards ha scritto: > On Saturday, April 17, 2021 at 7:52:07 AM UTC+10, jak wrote: > >> one thing is not clear to me, do you absolutely need to use "asma"? >> >> http://www.z390.org/ > > I forgot to mention that it also requires Java. So instead > of porting Python to the S/3X0 I would need to port > Java. > > Note that Java (and Python for that matter) are available > for later versions of z/OS, but as far as I am aware, they > are not available for the free MVS that hobbyists use, ie > MVS 3.8J, and it's definitely not available for the > environment I'm actually interested in, which is PDOS/3X0. > > BFN. Paul. > I looked at the "asma" folder and noticed that some files were touched 6 years ago. I could deduce from this that the authors might have an older version, perhaps developed for an older version of python, probably for the 2.x versions. You could try contacting the authors to ask about this. Python 2.x porting would probably be easier. From mutazilah at gmail.com Sat Apr 17 09:12:25 2021 From: mutazilah at gmail.com (Paul Edwards) Date: Sat, 17 Apr 2021 06:12:25 -0700 (PDT) Subject: port to PDOS (especially mainframe) In-Reply-To: References: <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> Message-ID: <15731cd1-0dc1-4526-8783-1e4812d281fcn@googlegroups.com> On Saturday, April 17, 2021 at 8:12:52 PM UTC+10, jak wrote: > I looked at the "asma" folder and noticed that some files were touched 6 > years ago. I could deduce from this that the authors might have an older > version, perhaps developed for an older version of python, probably for > the 2.x versions. You could try contacting the authors to ask about > this. Python 2.x porting would probably be easier. I looked at the "README" history (where Python 3.3 is given as a requirement, down the bottom): https://github.com/s390guy/SATK/commits/master/README and I can see that on 2014-08-13 he cited 3.3 as an explicit requirement. BFN. Paul. From tjreedy at udel.edu Fri Apr 16 17:37:21 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Apr 2021 17:37:21 -0400 Subject: port to PDOS (especially mainframe) In-Reply-To: References: <5c89d4f3-7ab3-80b4-c208-285216f16d77@gmail.com> <04534e58-4375-403b-980b-f44c062ce282n@googlegroups.com> <8cb3be58-64c7-4251-b573-f08a286bd245n@googlegroups.com> <7ce030e3-6bc3-4187-9f1d-2fd33b9541ebn@googlegroups.com> <619bf63f-d499-4e43-8eba-dde8e825d2bdn@googlegroups.com> <87wnt2oxfb.fsf@nightsong.com> Message-ID: On 4/16/2021 4:02 PM, Paul Edwards wrote: > On Saturday, April 17, 2021 at 5:13:31 AM UTC+10, Paul Rubin wrote: >> Paul Edwards writes: >>> I have succeeded in producing a Python 3.3 executable despite being >>> built with a C library that only supports C90. Not surprising. CPython was restricted to C90 until fairly recently to be portable across major systems, including Windows with MS Visual C. At least some C99 features are used now and more are being comtemplated. -- Terry Jan Reedy From tjreedy at udel.edu Fri Apr 16 17:40:13 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 16 Apr 2021 17:40:13 -0400 Subject: Repair Install of 64 bit python In-Reply-To: References: <20210416131300.xjytudlzlzloaj3q@localhost> Message-ID: On 4/16/2021 10:15 AM, Cameron Simpson wrote: > On 16Apr2021 13:13, Dan Ciprus (dciprus) wrote: >> Isn't the recommended python3 way of pip-ing stuff: >> >> python3 -m pip install ... >> >> .. just curious. > > If there's only one Python 3 installed then "pip3 install ..." _ought_ > to be equivalent. However, in the face of virtualenvs etc there may > often be several pip3s. > > Using "python3 -m pip install ..." ensures that you are using the pip > which is associated with "python3" (which you can adjust to be whichever > python3 you intend). This is why the "-m pip" form is recommended: it > definitely installs in the Python you'd be running. It requires that pip itself be installed for pythonx, which can be ensured with "pythonx -m ensurepip". -- Terry Jan Reedy From qberz2005 at gmail.com Sat Apr 17 18:56:35 2021 From: qberz2005 at gmail.com (Quentin Bock) Date: Sat, 17 Apr 2021 18:56:35 -0400 Subject: need help with a translation issue Message-ID: I'm trying to take the user input and let them change the target language or dest code: from deep_translator import GoogleTranslator import googletrans import sys language_list = googletrans.LANGUAGES print(language_list) feedback = input("Would you like to translate a sentence of your own? (yes/no)") if feedback == 'no': sys.exit() while feedback == 'yes': user_choice = input ("Enter a language (the abbreviation or correctly spelled name of the language): ").lower() user_sentence = input("Enter a sentence you want translated: ") user_translation = GoogleTranslator(source='en', target=user_choice).translate(user_sentence) print(user_translation) feedback = input ("Would you like to translate a sentence of your own? (yes/no)") if feedback == 'no': sys.exit() when ran, this will bring an error saying that your inputted language is not supported why is this? From PythonList at DancesWithMice.info Sat Apr 17 19:57:15 2021 From: PythonList at DancesWithMice.info (dn) Date: Sun, 18 Apr 2021 11:57:15 +1200 Subject: need help with a translation issue In-Reply-To: References: Message-ID: On 18/04/2021 10.56, Quentin Bock wrote: > I'm trying to take the user input and let them change the target language > or dest > code: > ... > language_list = googletrans.LANGUAGES > print(language_list) ... > user_choice = input ("Enter a language (the abbreviation or correctly > spelled name of the language): ").lower() ... > user_translation = GoogleTranslator(source='en', > target=user_choice).translate(user_sentence) Where is the "user_choice" related back to "language_list"? Alternately, what's there to stop some nefarious/stupid user (like me!) entering "gobbledegook" and complaining that the program fails? -- -- Regards, =dn From python at mrabarnett.plus.com Sat Apr 17 20:33:25 2021 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 18 Apr 2021 01:33:25 +0100 Subject: need help with a translation issue In-Reply-To: References: Message-ID: <7f8a4a52-d0f8-5496-7d1b-535750a9721d@mrabarnett.plus.com> On 2021-04-17 23:56, Quentin Bock wrote: > I'm trying to take the user input and let them change the target language > or dest > code: > > from deep_translator import GoogleTranslator > import googletrans > import sys > > language_list = googletrans.LANGUAGES > print(language_list) > > feedback = input("Would you like to translate a sentence of your own? > (yes/no)") > > if feedback == 'no': > sys.exit() > > while feedback == 'yes': > > user_choice = input ("Enter a language (the abbreviation or correctly > spelled name of the language): ").lower() > > user_sentence = input("Enter a sentence you want translated: ") > > user_translation = GoogleTranslator(source='en', > target=user_choice).translate(user_sentence) > > print(user_translation) > > feedback = input ("Would you like to translate a sentence of your own? > (yes/no)") > > if feedback == 'no': > sys.exit() > when ran, this will bring an error saying that your inputted language is > not supported > why is this? > All I can say is that it works for me! From rosuav at gmail.com Sat Apr 17 22:00:52 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 18 Apr 2021 12:00:52 +1000 Subject: need help with a translation issue In-Reply-To: References: Message-ID: On Sun, Apr 18, 2021 at 9:58 AM dn via Python-list wrote: > Alternately, what's there to stop some nefarious/stupid user (like me!) > entering "gobbledegook" and complaining that the program fails? "What is the French for fiddle-de-dee?" -- the Red Queen, to Alice (Incidentally, Google attempts to translate it as "violon-de-dee", and declares that the input was indeed in English, disagreeing quite firmly with Alice on both points.) ChrisA From PythonList at DancesWithMice.info Sat Apr 17 23:59:55 2021 From: PythonList at DancesWithMice.info (dn) Date: Sun, 18 Apr 2021 15:59:55 +1200 Subject: need help with a translation issue In-Reply-To: References: Message-ID: <217b1d1b-e1ca-02cb-da55-9e9ef3abf84f@DancesWithMice.info> Longer response: NB I've not used the system and only quickly reviewed https://py-googletrans.readthedocs.io/_/downloads/en/documentation/pdf/ NBB I am treating you (and/or other interested-readers) as something of a 'beginner'. No insult is intended should I appear to be 'talking down'. On 18/04/2021 10.56, Quentin Bock wrote: > I'm trying to take the user input and let them change the target language > or dest > code: > > from deep_translator import GoogleTranslator > import googletrans > import sys > > language_list = googletrans.LANGUAGES > print(language_list) Why print this? Should this output be labelled, or otherwise explained to the user? Looking at what is output (yourself), is it a list or a dictionary? When using it, is the code referring to a list or list of dictionary keys (country-codes), should it be looking at the country-names, or even both? (I'm not sure of your intent) > feedback = input("Would you like to translate a sentence of your own? > (yes/no)") > > if feedback == 'no': > sys.exit() When reviewing code: if the same lines are (basically) repeated, is this (often) a recommendation to employ a function? Given that the user has kicked-off the program[me], is it necessary to ask if (s)he wants to translate some text? Will anyone reply "no" at this point? Thus, (instead of asking) could we reasonably set "feedback" to "yes"? That said, what if the user replies "YES" (or some less logical combination of the same letters)? > while feedback == 'yes': Some might suggest that "feedback" should be a boolean value, thus: while feedback: > user_choice = input ("Enter a language (the abbreviation or correctly > spelled name of the language): ").lower() So, the acceptable response is either the code or the name of the language? > user_sentence = input("Enter a sentence you want translated: ") > > user_translation = GoogleTranslator(source='en', > target=user_choice).translate(user_sentence) Yet (according to the docs), the "target" value should be a language-code, eg 'fr' rather than 'french'. (remember: I've not used the library, so you're the expert...) > print(user_translation) Some would suggest that if "user_translation" is defined on one line and only ever used on the following, the two lines should be conflated. (some of us don't agree, especially if it makes testing more awkward) > feedback = input ("Would you like to translate a sentence of your own? > (yes/no)") > > if feedback == 'no': > sys.exit() A UX (User Experience) consideration: If the user has a series of translations to be made, will (s)he want to keep repeating the same language/code? Could you code the input statement to have a default value on the second and ensuing times through the loop? In this mode, if the user hits Enter without entering any text-data, the code could 'remember' the language and save manual-effort. A thought about design: This code consists of a loop which has two purposes 1 translate some text 2 continue looping or stop A useful guide (and testing aid) is "SRP" (the Single Responsibility Principle) which has a more-technical definition, but let's stick to its name. Each routine should have only a single task to perform (and should do it well). Let's consider the first 'purpose': def translate(): user_choice = input ("Enter...): ").lower() user_sentence = input("Enter a sentence you want translated: ") user_translation = GoogleTranslator(source='en', target=user_choice).translate(user_sentence) Applying SRP again, we might debate that last line, because it is not (easily) possible to distinguish between an error at class instantiation-time (eg "target" is not an acceptable language-code), and an error at translation-time. Let's go the next step and separate-out the input functionality. How about a function like: def translate( target_language_code, english_text ): translator = GoogleTranslator( source='en', target=target_language_code ) return translator.translate( english_text ) Why? There is virtue in what appears to be extra, even unnecessary, coding effort! This is very easily tested - and can be (even more easily) automatically tested: def test_translator( ... ): assert translate( "fr", "hello" ) == "bonjour" assert translate( "de", "thank you" ) == "danke sch?n" ... test for error using non-existent language-code ... test for error using non-English text I'll leave you to work-out how to encapsulate the inputs into a function - especially if you plan to implement the default-value idea/service to users. (!) The second purpose, after extracting the above, leaves us with a "control loop" (in real-time systems it is termed an "event loop"), and pretty-much the code as-is (after any amendments per comments-above). while feedback: print( translate() ) feedback = input ("Would you like to translate a sentence of your own? (yes/no)") if feedback == 'no': sys.exit() That's the second purpose done! - or is it? Consider the while - it creates an "infinite loop". If we ever write code like this, the *second* thought should *always* be: "how am I going to stop it?"! You did - well done! However, let's ask: what happens when the loop ends? Answer: the program stops. Duh! So, why do we have a sys.exit() inside the loop? Couldn't that be taken for granted if we re-word the use of "feedback" appropriately, to control the repetition? (which follows from earlier comment on the same identifier!) Within that, here's another UX/design consideration: are we only interested in "yes" and "no" - what about all the other things a user might type, mis-type, or other mistakes which could be made? Perhaps we should consider a convention (or would it become a "rule"?) that if the user types *any* text beginning with "y" (or "Y"?), then the loop will repeat - whereas any other text (or nothing but the enter key) will be considered as 'no'. Perhaps you'd prefer to be more positive, er, negative, in this choice? Regardless, we can refine it down to something like: translations_to_do = True while translations_to_do: print( translate() ) feedback = input (...) translations_to_do = feedback and feedback[ 0 ] in [ 'n', "N" ] Why the two halves to the condition? Consider the case where the use types nothing (except the enter key): what would happen when the code "feedback[ 0 ]" was executed? Once again, refining SRP to the nth-degree, perhaps we could take the two 'control lines' out of the loop and replace them with a function call: continue_looping = True while continue_looping: print( translate() ) continue_looping = fetch_user_feedback() Does that look like "clean code"? Is it minimalist, yet also clearly communicating what the program will do? The criticism of such an approach is that you've ended-up with a bunch of small functions. Thus, the logic may appear fractured or the code-body feel 'bitsy'. The former shouldn't become the case (IMHO) and is largely countered by carefully-considered choices for [function] names. These in-turn [should] make the code eminently 'readable'. The second is true, *but* each small routine can be tested independently of [all] the others. There's plenty of room to discuss "dependence" and "independence"! For the purposes of our code-review: each routine can be changed internally (ie providing its "signature" remains the same) without affecting the total, ie not requiring any code to change in some other routine (that the "independence" bit!). Plus, each routine can be easily "re-used", ie is virtuous according to Object-Oriented philosophy. A worthwhile separation is to keep 'I/O' distinct from 'process'. Let's go a little crazy to illustrate that ideal:- Imagine that someone likes this program, but wants a whole series of text-items translated. His text is stored in a database table (and he doesn't want to manually re-type 'everything', despite thinking your program is 'the best thing since sliced bread"). What now? A second program, with almost identical code? What about that SRP hassle then? Well, we can very easily pick-and-choose from amongst all those small functions to "re-use" some as-is, and replace the ones handling manual input with database queries. Hey, a great win! However, *my* demo above shows me as not following 'the rules'. What? Shock, horror! That's the problem with "print( translate() )" - and we're back to an earlier comment - perhaps it should be: translation = translate() report( translation ) Now, the report() function can be responsible for deciding if the translation should be printed (original spec) or INPUT to a database table. We've well-and-truly disappearing down a 'rabbit hole' now! (Apologies, - I noted Chris making "Alice in Wonderland" references) If you haven't already, now is a good time to ask just how relevant some of these 'rules' - or are they 'ideas' - might be! Here's another: "YAGNI" (You Aren't Going to Need It) - don't try to make a simple program into the be-all-and-end-all just in-case some idiot (I mean: nice person, like me) comes along asking for database-output. That said, designing for 'independence' will facilitate such extensions, should they (ever) be required. - and another: "YMMV" (Your Mileage May Vary) - from the motor industry expecting us to excuse their outlandish claims about how little fuel a car requires/how many miles or km it will travel on a single electric-charge. We apply it to say that what my team thinks is 'the one true way' to do things, may be quite different to what you/your team think is 'correct'! NB 'umble scribe has (lazily) not tested these code-snippets Web.Ref: https://towardsdatascience.com/5-principles-to-write-solid-code-examples-in-python-9062272e6bdc -- Regards, =dn From jsf80238 at gmail.com Sun Apr 18 09:46:53 2021 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 18 Apr 2021 07:46:53 -0600 Subject: Determine what the calling program is Message-ID: I should state at the start that I have a solution to my problem. I am writing to see if there is a better solution. I have a program that runs via crontab every five minutes. It polls a Box.com folder for files and, if any are found, it copies them locally and performs a computation on them that can exceed five minutes. It pushes the results back up to Box. (Box.com ensures that only complete files are visible when I poll.) Files are dropped into this Box.com folder rarely, but to ensure a good customer experience I do not want to set my crontab to run less frequently. My hardware cannot support multiple simultaneous computations. I have written a piece of code to detect if more than 1 instance of my program is running, and I put this code into a separate module (support.py) so that other programs can use it. support.py contains: -------------------------------------------------------------------------------- import sys def check(calling_program): import psutil # some logic here to count # count = N if count > 1: print(f"I was called by {calling_program}.") sys.exit() if __name__ == "__main__": check() -------------------------------------------------------------------------------- actual-program.py contains: -------------------------------------------------------------------------------- import support.py support.check(__file__) # Poll, and if files download, perform expensive computations, push results -------------------------------------------------------------------------------- To me it would be more elegant to be able to do something like this: def check(): # Something here that tells me the name of the calling program import psutil # ... And then the calling program just does: support.check() From pkpearson at nowhere.invalid Sun Apr 18 11:41:46 2021 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 18 Apr 2021 15:41:46 GMT Subject: Comparing text strings References: Message-ID: On Sun, 18 Apr 2021 06:38:16 GMT, Gilmeh Serda wrote: > On Mon, 12 Apr 2021 16:11:21 -0700, Rich Shepard wrote: > >> All suggestions welcome. > > Assuming you want to know which is the oldest version and that the same > scheme is used all the time, could this work? > >>>> s1='atftp-0.7.2-x86_64-2_SBo.tgz' >>>> s2='atftp-0.7.4-x86_64-1_SBo.tgz' >>>> s1>s2 > False >>>> s2>s1 > True [snip] However, beware: >>> s2='atftp-0.7.4-x86_64-1_SBo.tgz' >>> s3='atftp-0.7.10-x86_64-1_SBo.tgz' >>> s2>s3 True -- To email me, substitute nowhere->runbox, invalid->com. From dieter at handshake.de Sun Apr 18 12:28:10 2021 From: dieter at handshake.de (Dieter Maurer) Date: Sun, 18 Apr 2021 18:28:10 +0200 Subject: Determine what the calling program is In-Reply-To: References: Message-ID: <24700.24090.165225.487719@ixdm.fritz.box> Jason Friedman wrote at 2021-4-18 07:46 -0600: > ... >I have a program that runs via crontab every five minutes. It polls a >Box.com folder for files and, if any are found, it copies them locally and >performs a computation on them that can exceed five minutes. It pushes the >results back up to Box. (Box.com ensures that only complete files are >visible when I poll.) Files are dropped into this Box.com folder rarely, >but to ensure a good customer experience I do not want to set my crontab to >run less frequently. My hardware cannot support multiple simultaneous >computations. Programs typically use some form of file locking to detect attempts to run the same program multiple times. The optimal form of locking depends on the operating system. Under *nix, so called advisory locks seem promising. From kushal at locationd.net Sun Apr 18 13:27:19 2021 From: kushal at locationd.net (Kushal Kumaran) Date: Sun, 18 Apr 2021 10:27:19 -0700 Subject: Determine what the calling program is In-Reply-To: (Jason Friedman's message of "Sun, 18 Apr 2021 07:46:53 -0600") References: Message-ID: <87im4jsdu0.fsf@copper.locationd.net> On Sun, Apr 18 2021 at 07:46:53 AM, Jason Friedman wrote: > I should state at the start that I have a solution to my problem. I am > writing to see if there is a better solution. > > I have a program that runs via crontab every five minutes. It polls a > Box.com folder for files and, if any are found, it copies them locally and > performs a computation on them that can exceed five minutes. It pushes the > results back up to Box. (Box.com ensures that only complete files are > visible when I poll.) Files are dropped into this Box.com folder rarely, > but to ensure a good customer experience I do not want to set my crontab to > run less frequently. My hardware cannot support multiple simultaneous > computations. > > I have written a piece of code to detect if more than 1 instance of my > program is running, and I put this code into a separate module (support.py) > so that other programs can use it. > > support.py contains: > -------------------------------------------------------------------------------- > import sys > def check(calling_program): > import psutil > # some logic here to count > # count = N > if count > 1: > print(f"I was called by {calling_program}.") > sys.exit() > if __name__ == "__main__": > check() > -------------------------------------------------------------------------------- > > actual-program.py contains: > -------------------------------------------------------------------------------- > import support.py > support.check(__file__) > # Poll, and if files download, perform expensive computations, push results > -------------------------------------------------------------------------------- > > To me it would be more elegant to be able to do something like this: > > def check(): > # Something here that tells me the name of the calling program > import psutil > # ... > > And then the calling program just does: > support.check() The standard library provides locking primitives in the Unix-specific fcntl module. You can use those to make sure only a single instance of your process runs. Use the non-blocking forms of the lock to ensure that if you are unable to get the lock, you exit rather than wait. If your process waits for locks, the crontab will keep piling on waiters. There are libraries[1][2] on pypi that wrap the platform-specific locking primitives and provide terse APIs. A simpler solution might be to use the flock(1) command, if you have it available, directly in the crontab entry. [1] https://pypi.org/project/fasteners/ [2] https://pypi.org/project/oslo.concurrency/ -- regards, kushal From PythonList at DancesWithMice.info Sun Apr 18 15:35:24 2021 From: PythonList at DancesWithMice.info (dn) Date: Mon, 19 Apr 2021 07:35:24 +1200 Subject: Comparing text strings In-Reply-To: <7c6f3f04-7c1d-7fb6-f569-71a05eb2100b@wichmann.us> References: <7c6f3f04-7c1d-7fb6-f569-71a05eb2100b@wichmann.us> Message-ID: On 14/04/2021 04.05, Mats Wichmann wrote: > On 4/12/21 5:11 PM, Rich Shepard wrote: >> I'm running Slackware64-14.2 and keep a list of installed packages. >> When a >> package is upgraded I want to remove the earlier version, and I've not >> before written a script like this. Could there be a module or tool that >> already exists to do this? If not, which string function would be best >> suited to the task? >> >> Here's an example: >> atftp-0.7.2-x86_64-2_SBo.tgz >> atftp-0.7.4-x86_64-1_SBo.tgz The 'trick' here is to understand how the distro handles versioning (and multiple architectures, etc) and then to split the long name into components before comparison, simplified example: only relevant comparison if x86_64 == x86_64, then atftp ? atftp == same, and thus 0.7.4 ? 0.7.4 => version update (perhaps) >> and there are others like this. I want the python3 script to remove the >> first one. Tools like like 'find' or 'sort -u' won't work because >> while the >> file name is the same the version or build numbers differ. > > Yes, you've identified why this is hard: package versioning takes many > forms.? As suggested elsewhere, for Linux distribution packages, the > only reliable approach is to lean on the distro's packaging > infrastructure in some way, because those version strings (plus package > metadata which may have "replaces" or "obsoletes" or some similar > information) all have a defined meaning to *it* - it's the intended > audience. > > Don't know if Slack exposes this information in some way, it may be hard > to make a reliable script if not. I know Debian actually does what > you're looking for as a feature of the packaging system (apt-get > autoclean), and the Fedora/RedHat universe does not, so I've also looked > for what you're looking for :) Not a sand-box I've played in. However, dnf is at least partly-written in Python (it may still employs the older rpm, even yum, code). Maybe the OP could learn from, or even piggy-back off, the existing code? (which may be at https://github.com/rpm-software-management/dnf) -- Regards, =dn From PythonList at DancesWithMice.info Sun Apr 18 16:04:10 2021 From: PythonList at DancesWithMice.info (dn) Date: Mon, 19 Apr 2021 08:04:10 +1200 Subject: Determine what the calling program is In-Reply-To: References: Message-ID: <22da9982-7723-717b-6785-0b30d48a3971@DancesWithMice.info> On 19/04/2021 01.46, Jason Friedman wrote: > I should state at the start that I have a solution to my problem. I am > writing to see if there is a better solution. > > I have a program that runs via crontab every five minutes. It polls a > Box.com folder for files and, if any are found, it copies them locally and > performs a computation on them that can exceed five minutes. It pushes the > results back up to Box. (Box.com ensures that only complete files are > visible when I poll.) Files are dropped into this Box.com folder rarely, > but to ensure a good customer experience I do not want to set my crontab to > run less frequently. My hardware cannot support multiple simultaneous > computations. > > I have written a piece of code to detect if more than 1 instance of my > program is running, and I put this code into a separate module (support.py) > so that other programs can use it. In a similar situation, one of my teams used an (OpSys) environment variable (available in both *nux and MS-Win). - when the application starts, it checks for the variable - if exists, stops running, else may proceed During code review (when I noticed this tactic) I was slightly surprised, because back when I was young (men were men, and knights were bold, ...), we used file-stubs. However, such systems face two complementary, potential-problems: 'single-instance' (which is being addressed), and 'blocking-instance'. If there is a risk that the long-running computations may fail into a never-ending loop, the system effectively dies (but silently!) and source files (ie at Box.com) may accumulate without receiving attention. Accordingly, the above-mentioned environment-variable was filled with a time-stamp. Then a second step in the check-routine reviewed the time since the 'blocking' instance started, in order to log or raise suitable alerts if things went awry. YMMV! An alternative, if the system already uses a database, is to keep a local record in the DB of all the files lodged at box.com. This can include a note that each file has/not been processed (plus any other stats or logging you may deem appropriate). A third state would be 'in process'. Now, at start-up, the application can quickly check to see if there is any file in that state... -- Regards, =dn From invalid at invalid.com Sun Apr 18 17:25:34 2021 From: invalid at invalid.com (Gys) Date: Sun, 18 Apr 2021 23:25:34 +0200 Subject: TIME IN XARRAY In-Reply-To: References: <9f570438-3db7-05a8-26f2-58c452278caa@inpe.br> Message-ID: On 4/15/21 7:58 PM, Jorge Conforte wrote: > > > Hi, > > > I'm using xarray to read netcdf data and I had to time in my data the > values: > > > xarray.DataArray 'time' (time: 507)> > array(['1979-01-01T00:00:00.000000000', '1979-02-01T00:00:00.000000000', > ?????? '1979-03-01T00:00:00.000000000', ..., > '2021-01-01T00:00:00.000000000', > ?????? '2021-02-01T00:00:00.000000000', '2021-03-01T00:00:00.000000000'], > ????? dtype='datetime64[ns]') > > > Please, how can I get the years and months values from this array. > > > Thanks, > > > Conrado Hi, maybe this : from datetime import datetime import time # Convert Event to a string Event="1979-01-01T00:00:00.000000000" strDate=time.strftime(Event) print("Date string ",strDate) # Get the Year from the string strDate print("Year ",strDate[0:4]) # Get the month from the string strDate print("Month ",strDate[5:7]) print() # # Convert Event to a datetime object Event="1979-01-01T00:00:00.000000000" dtmDate=datetime.strptime(Event,"%Y-%m-%dT%H:%M:%S.000000000") print("datetime object",dtmDate) # Get the Year from the datetime object print("Year ",dtmDate.year) # Get the month from the datetime object print("Month ",dtmDate.month) -hth Gys From cs at cskk.id.au Sun Apr 18 18:54:06 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 19 Apr 2021 08:54:06 +1000 Subject: Determine what the calling program is In-Reply-To: References: Message-ID: On 18Apr2021 07:46, Jason Friedman wrote: >I should state at the start that I have a solution to my problem. I am >writing to see if there is a better solution. [...] >I have written a piece of code to detect if more than 1 instance of my >program is running, and I put this code into a separate module (support.py) >so that other programs can use it. [... sniff the process table ...] Sniffing ps has always seemed unreliable to me. It is usually better to use some kind of filesystem based lock, named to represent your task. My personal preference is lock directories. Shell version goes like this: if mkdir /my/lock/directory/name-of-task then .. do task .. rmdir /my/lock/directory/name-of-task else echo "lock /my/lock/directory/name-of-task already taken" fi Simple, reliable, even works over NFS if you care. In Python this looks like (sketch, untested): try: os.mkdir('/my/lock/directory/name-of-task') except FileExistsError: error("lock taken") else: .. do task .. os.rmdir('/my/lock/directory/name-of-task') You can even put a pid file in there for added richness, identifying the pid of the competing process. Or whatever. You can also make O_EXCL or O_CREAT/unwriteable files for locks: # untested, check spelling etc os.open('/my/lock/directory/name-of-task', O_CREAT|O_WRONLY, 0o000) On a UNIX system this opens an unwriteable file for write (you get to open it for write because it is new, but its permissions are unwriteable, preventing anyone else from opening it for write). These (mkdir, os.open) have the benefits of making a nice direct filesystem object rather than hoping to see your task in ps. And ps sniffing is racey, in addition to its other issues. Cheers, Cameron Simpson From drsalists at gmail.com Sun Apr 18 19:48:02 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 18 Apr 2021 16:48:02 -0700 Subject: Determine what the calling program is In-Reply-To: References: Message-ID: I use this little program for shell-level locking. It just checks for a pid file. If the pid file does not exist, or the pid no longer exists, it'll start the process, and write the new process' pid to the pid file. It's at: https://stromberg.dnsalias.org/svn/just-one/ ...and usage looks like: $ ./just-one -h below cmd output started 2021 Sun Apr 18 04:44:03 PM PDT Usage: ./just-one --command command --string string The "string" part needs to be a unique identifier for each process you want only one of. The command, naturally, is a shell command. I just noticed that I don't have a web page describing it yet. I'll probably set one up a little later. It does not use locking: advisory or mandatory. Just a lock file containing a pid. HTH. On Sun, Apr 18, 2021 at 6:47 AM Jason Friedman wrote: > I should state at the start that I have a solution to my problem. I am > writing to see if there is a better solution. > > I have a program that runs via crontab every five minutes. It polls a > Box.com folder for files and, if any are found, it copies them locally and > performs a computation on them that can exceed five minutes. It pushes the > results back up to Box. (Box.com ensures that only complete files are > visible when I poll.) Files are dropped into this Box.com folder rarely, > but to ensure a good customer experience I do not want to set my crontab to > run less frequently. My hardware cannot support multiple simultaneous > computations. > > I have written a piece of code to detect if more than 1 instance of my > program is running, and I put this code into a separate module (support.py) > so that other programs can use it. > > support.py contains: > > -------------------------------------------------------------------------------- > import sys > def check(calling_program): > import psutil > # some logic here to count > # count = N > if count > 1: > print(f"I was called by {calling_program}.") > sys.exit() > if __name__ == "__main__": > check() > > -------------------------------------------------------------------------------- > > actual-program.py contains: > > -------------------------------------------------------------------------------- > import support.py > support.check(__file__) > # Poll, and if files download, perform expensive computations, push results > > -------------------------------------------------------------------------------- > > To me it would be more elegant to be able to do something like this: > > def check(): > # Something here that tells me the name of the calling program > import psutil > # ... > > And then the calling program just does: > support.check() > -- > https://mail.python.org/mailman/listinfo/python-list > From drsalists at gmail.com Sun Apr 18 19:55:28 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 18 Apr 2021 16:55:28 -0700 Subject: Determine what the calling program is In-Reply-To: References: Message-ID: It's now at: https://stromberg.dnsalias.org/~strombrg/just-one/ From loris.bennett at fu-berlin.de Mon Apr 19 05:52:42 2021 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Mon, 19 Apr 2021 11:52:42 +0200 Subject: Current thinking on required options Message-ID: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> Hi, I have various small programs which tend to have an interface like the following example: usage: grocli [-h] [-o {check,add,delete}] [-u USERS [USERS ...]] [-g GROUP] Command line grouper tool optional arguments: -h, --help show this help message and exit -o {check,add,delete}, --operation {check,add,delete} operation to apply -u USERS [USERS ...], --users USERS [USERS ...] users to apply operation to -g GROUP, --group GROUP group to apply operation to However, the options -o, -u, and -g are required, not optional. The documentation https://docs.python.org/3/library/argparse.html#required advises against required options and here https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments a way of adding a section 'required arguments' to the usage is described. I would be interested to know what the general thinking on "required options" is. Is there just a better way of designing such interfaces? Cheers, Loris -- This signature is currently under construction. From gisle.vanem at gmail.com Mon Apr 19 07:16:52 2021 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Mon, 19 Apr 2021 13:16:52 +0200 Subject: Current thinking on required options In-Reply-To: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <5dae71b8-dc90-fb1f-c03c-6e0915ef9c68@gmail.com> Loris Bennett wrote: > usage: grocli [-h] [-o {check,add,delete}] [-u USERS [USERS ...]] [-g GROUP] > > Command line grouper tool > > optional arguments: > -h, --help show this help message and exit > -o {check,add,delete}, --operation {check,add,delete} > operation to apply > -u USERS [USERS ...], --users USERS [USERS ...] > users to apply operation to > -g GROUP, --group GROUP > group to apply operation to > > However, the options -o, -u, and -g are required, not optional. Just a nitpick. To quote from https://en.wikipedia.org/wiki/Usage_message "To indicate required arguments, Angled brackets are commonly used, ..." So then it should better be written as: grocli [-h] <-o {check,add,delete}> <-u USERS [USERS ...]> <-g GROUP> -- --gv From __peter__ at web.de Mon Apr 19 07:29:08 2021 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Apr 2021 13:29:08 +0200 Subject: Current thinking on required options In-Reply-To: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> Message-ID: On 19/04/2021 11:52, Loris Bennett wrote: > Hi, > > I have various small programs which tend to have an interface like the > following example: > > usage: grocli [-h] [-o {check,add,delete}] [-u USERS [USERS ...]] [-g GROUP] > > Command line grouper tool > > optional arguments: > -h, --help show this help message and exit > -o {check,add,delete}, --operation {check,add,delete} > operation to apply > -u USERS [USERS ...], --users USERS [USERS ...] > users to apply operation to > -g GROUP, --group GROUP > group to apply operation to > > However, the options -o, -u, and -g are required, not optional. > > The documentation > > https://docs.python.org/3/library/argparse.html#required > > advises against required options and here > > https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments > > a way of adding a section 'required arguments' to the usage is > described. > > I would be interested to know what the general thinking on "required > options" is. Is there just a better way of designing such interfaces? For the example above you could realize the operation through subparsers and switch group and users. In cases where no such "natural" order of arguments exists I'd have no qualms to use required options. Personally I've not yet come across such a case. From __peter__ at web.de Mon Apr 19 07:29:08 2021 From: __peter__ at web.de (Peter Otten) Date: Mon, 19 Apr 2021 13:29:08 +0200 Subject: Current thinking on required options In-Reply-To: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> Message-ID: On 19/04/2021 11:52, Loris Bennett wrote: > Hi, > > I have various small programs which tend to have an interface like the > following example: > > usage: grocli [-h] [-o {check,add,delete}] [-u USERS [USERS ...]] [-g GROUP] > > Command line grouper tool > > optional arguments: > -h, --help show this help message and exit > -o {check,add,delete}, --operation {check,add,delete} > operation to apply > -u USERS [USERS ...], --users USERS [USERS ...] > users to apply operation to > -g GROUP, --group GROUP > group to apply operation to > > However, the options -o, -u, and -g are required, not optional. > > The documentation > > https://docs.python.org/3/library/argparse.html#required > > advises against required options and here > > https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments > > a way of adding a section 'required arguments' to the usage is > described. > > I would be interested to know what the general thinking on "required > options" is. Is there just a better way of designing such interfaces? For the example above you could realize the operation through subparsers and switch group and users. In cases where no such "natural" order of arguments exists I'd have no qualms to use required options. Personally I've not yet come across such a case. From loris.bennett at fu-berlin.de Mon Apr 19 07:55:22 2021 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Mon, 19 Apr 2021 13:55:22 +0200 Subject: Current thinking on required options References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> <5dae71b8-dc90-fb1f-c03c-6e0915ef9c68@gmail.com> Message-ID: <87k0oywkt1.fsf@hornfels.zedat.fu-berlin.de> Gisle Vanem writes: > Loris Bennett wrote: > >> usage: grocli [-h] [-o {check,add,delete}] [-u USERS [USERS ...]] [-g GROUP] >> >> Command line grouper tool >> >> optional arguments: >> -h, --help show this help message and exit >> -o {check,add,delete}, --operation {check,add,delete} >> operation to apply >> -u USERS [USERS ...], --users USERS [USERS ...] >> users to apply operation to >> -g GROUP, --group GROUP >> group to apply operation to >> >> However, the options -o, -u, and -g are required, not optional. > > Just a nitpick. > > To quote from https://en.wikipedia.org/wiki/Usage_message > "To indicate required arguments, Angled brackets are > commonly used, ..." > > So then it should better be written as: > grocli [-h] <-o {check,add,delete}> <-u USERS [USERS ...]> <-g GROUP> I would take that with a pinch of salt. The Wikipedia page doesn't give any examples, let alone any that might be considered somehow typical or representative. Looking at a few tools I use regularly (awk, cat, grep, sed, ssh, tmux) I couldn't find any which use the angled-bracket notation. So maybe the notation is not common or just not many programs have this type of option. The latter would correspond with sentiment in the argparse documentation that it is an approach to be avoided. In any case, the usage line is generated automatically by argsparse. However, I am more interested in what an alternative approach might look like. Cheers, Loris -- This signature is currently under construction. From mal at europython.eu Mon Apr 19 08:08:09 2021 From: mal at europython.eu (M.-A. Lemburg) Date: Mon, 19 Apr 2021 14:08:09 +0200 Subject: EuroPython 2021: Ticket sales started Message-ID: <783a4895-063a-f2ac-e760-981a34f41362@europython.eu> We're pleased to announce the start of the EuroPython 2021 ticket sales: * EuroPython 2021 Ticket Sales Open * https://ep2021.europython.eu/registration/buy-tickets/ Updated ticket structure ------------------------ For EuroPython 2021, we'll have more than 10 training sessions and workshops spread across two days. There is a combined ticket available for those who wish to attend both. We also added a new livestream-only ticket for getting access to the live streams. It's free, but you'll miss out on the interactivity. Ticket types ------------ - Combined tickets: Access to the whole seven day conference, including training sessions, workshops, conference days and sprints. - Conference + sprint tickets: Access to conference days and sprints. - Sprint-only tickets: Free access to the sprint days only. - Livestream-only tickets: Free access to the live streams of the conference sessions only. No access to the conference system. Ticket tiers ------------ - Business tickets: For people using Python to make a living and people who want to support our grants program. - Personal tickets: For people enjoying Python in their free time or as a freelancer. More details ------------ For full details, which include ticket prices, a comparison features and the link to the ticket shop, please see our registration page. Our financial aid program will be available starting Wednesday, April 21. Participate in Talk Voting -------------------------- With a conference or combined ticket, you will also be able to tell us what you?d like to see at EuroPython 2021 by voting on the submitted talk proposals. Talk voting will start after the end of the Call for Proposals (CFP). Guido van Rossum Core Developer Grant ------------------------------------- For Python Core Developers, we have put a special grant in place, which will allow core developers to get free combined tickets to the conference. If you want to sign up, please check our grant page for details on how to apply. Quick Summary ------------- EuroPython 2021 will be run online from July 26 - August 1: - Two workshop/training days (July 26 - 27) - Three conference days (July 28 - 30) - Two sprint days (July 31 - August 1) The sessions will be scheduled to ensure they are also accessible for those in the Asian and Americas time zones. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/europython-2021-ticket-sales-started/ Tweet: https://twitter.com/europython/status/1384076406418595846 Enjoy, -- EuroPython 2021 Team https://www.europython-society.org/ From barry at barrys-emacs.org Mon Apr 19 11:09:45 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 19 Apr 2021 16:09:45 +0100 Subject: Determine what the calling program is In-Reply-To: References: Message-ID: > On 18 Apr 2021, at 14:46, Jason Friedman wrote: > > I should state at the start that I have a solution to my problem. I am > writing to see if there is a better solution. > > I have a program that runs via crontab every five minutes. It polls a > Box.com folder for files and, if any are found, it copies them locally and > performs a computation on them that can exceed five minutes. It pushes the > results back up to Box. (Box.com ensures that only complete files are > visible when I poll.) Files are dropped into this Box.com folder rarely, > but to ensure a good customer experience I do not want to set my crontab to > run less frequently. My hardware cannot support multiple simultaneous > computations. > > I have written a piece of code to detect if more than 1 instance of my > program is running, and I put this code into a separate module (support.py) > so that other programs can use it. The way to do this simply on a unix system is to use a lock file and code like this: lock_file = open(os.path.join(lock_dir, 'lockfile'), 'w') try: fcntl.flock(lock_file, fcntl.LOCK_EX|fcntl.LOCK_NB) except IOError as e: if e.errno == errno.EWOULDBLOCK: log('CA base directory "%s" already locked, exiting', ca_base_dir) sys.exit(0) else: log('Non-locking related IOError for file %s', lock_file) raise Only the first time the code runs will the lock be granted. You can then do the possible long running task. When a second copy of the program runs from cron it will get the EWOULDBLOCK error and you can just exit. Barry > > support.py contains: > -------------------------------------------------------------------------------- > import sys > def check(calling_program): > import psutil > # some logic here to count > # count = N > if count > 1: > print(f"I was called by {calling_program}.") > sys.exit() > if __name__ == "__main__": > check() > -------------------------------------------------------------------------------- > > actual-program.py contains: > -------------------------------------------------------------------------------- > import support.py > support.check(__file__) > # Poll, and if files download, perform expensive computations, push results > -------------------------------------------------------------------------------- > > To me it would be more elegant to be able to do something like this: > > def check(): > # Something here that tells me the name of the calling program > import psutil > # ... > > And then the calling program just does: > support.check() > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Mon Apr 19 11:21:01 2021 From: barry at barrys-emacs.org (Barry) Date: Mon, 19 Apr 2021 16:21:01 +0100 Subject: Current thinking on required options In-Reply-To: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <3E75315D-5E03-4264-AC74-D0E313C5F82A@barrys-emacs.org> > On 19 Apr 2021, at 10:57, Loris Bennett wrote: > > ?Hi, > > I have various small programs which tend to have an interface like the > following example: > > usage: grocli [-h] [-o {check,add,delete}] [-u USERS [USERS ...]] [-g GROUP] > > Command line grouper tool > > optional arguments: > -h, --help show this help message and exit > -o {check,add,delete}, --operation {check,add,delete} > operation to apply > -u USERS [USERS ...], --users USERS [USERS ...] > users to apply operation to > -g GROUP, --group GROUP > group to apply operation to > > However, the options -o, -u, and -g are required, not optional. You could use positional args like this: grocli check user,user group Barry > > The documentation > > https://docs.python.org/3/library/argparse.html#required > > advises against required options and here > > https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments > > a way of adding a section 'required arguments' to the usage is > described. > > I would be interested to know what the general thinking on "required > options" is. Is there just a better way of designing such interfaces? > > Cheers, > > Loris > > -- > This signature is currently under construction. > -- > https://mail.python.org/mailman/listinfo/python-list > From drsalists at gmail.com Mon Apr 19 12:04:09 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 19 Apr 2021 09:04:09 -0700 Subject: Current thinking on required options In-Reply-To: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> Message-ID: On Mon, Apr 19, 2021 at 2:55 AM Loris Bennett wrote: > However, the options -o, -u, and -g are required, not optional. > > The documentation > > https://docs.python.org/3/library/argparse.html#required > > advises against required options and here > > > https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments > > a way of adding a section 'required arguments' to the usage is > described. > Of _course_ some options need to be required. I can't imagine what the author of that page was thinking. From pbryan at anode.ca Mon Apr 19 12:29:58 2021 From: pbryan at anode.ca (Paul Bryan) Date: Mon, 19 Apr 2021 09:29:58 -0700 Subject: Current thinking on required options In-Reply-To: References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <58edda72bfabd2910ddf3d4aa06bb235f7f8a347.camel@anode.ca> Calling them options?when they're required?seems like a problem. ? On Mon, 2021-04-19 at 09:04 -0700, Dan Stromberg wrote: > On Mon, Apr 19, 2021 at 2:55 AM Loris Bennett > > wrote: > > > However, the options -o, -u, and -g are required, not optional. > > > > The documentation > > > > ? https://docs.python.org/3/library/argparse.html#required > > > > advises against required options and here > > > > > > https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments > > > > a way of adding a section 'required arguments' to the usage is > > described. > > > > Of _course_ some options need to be required. > > I can't imagine what the author of that page was thinking. From drsalists at gmail.com Mon Apr 19 12:37:58 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 19 Apr 2021 09:37:58 -0700 Subject: Current thinking on required options In-Reply-To: <58edda72bfabd2910ddf3d4aa06bb235f7f8a347.camel@anode.ca> References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> <58edda72bfabd2910ddf3d4aa06bb235f7f8a347.camel@anode.ca> Message-ID: I guess maybe it seems like a problem to someone who hasn't used command line tools much, based solely on a simplistic interpretation of the terminology. But strictly speaking, they're "command line options", or better "command line arguments", not "options". On Mon, Apr 19, 2021 at 9:30 AM Paul Bryan wrote: > Calling them options?when they're required?seems like a problem. ? > > On Mon, 2021-04-19 at 09:04 -0700, Dan Stromberg wrote: > > On Mon, Apr 19, 2021 at 2:55 AM Loris Bennett > wrote: > > However, the options -o, -u, and -g are required, not optional. > > The documentation > > https://docs.python.org/3/library/argparse.html#required > > advises against required options and here > > > > https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments > > a way of adding a section 'required arguments' to the usage is > described. > > > Of _course_ some options need to be required. > > I can't imagine what the author of that page was thinking. > > > From jon+usenet at unequivocal.eu Mon Apr 19 12:38:24 2021 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Mon, 19 Apr 2021 16:38:24 -0000 (UTC) Subject: Current thinking on required options References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> <58edda72bfabd2910ddf3d4aa06bb235f7f8a347.camel@anode.ca> Message-ID: On 2021-04-19, Paul Bryan wrote: > Calling them options?when they're required?seems like a problem. ? The option is what the value is, not whether there is a value at all. If you order a coffee then you may have an option as to what temperature it is, that doesn't mean the coffee having a temperature is optional. From hjp-python at hjp.at Mon Apr 19 13:45:35 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 19 Apr 2021 19:45:35 +0200 Subject: Current thinking on required options In-Reply-To: References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> <58edda72bfabd2910ddf3d4aa06bb235f7f8a347.camel@anode.ca> Message-ID: <20210419174535.GA1554@hjp.at> On 2021-04-19 16:38:24 -0000, Jon Ribbens via Python-list wrote: > On 2021-04-19, Paul Bryan wrote: > > Calling them options?when they're required?seems like a problem. ? > > The option is what the value is, not whether there is a value at all. > If you order a coffee then you may have an option as to what temperature > it is, that doesn't mean the coffee having a temperature is optional. No, but you having to specify the temperature is optional. Yoy might order an extra-hot coffee or s luke-warm coffee, but most of the time you will just order a coffee and accept it being at the default temperature. I would agree with others that options should in general be optional. I do break that that rule sometimes, though: If there are several required arguments and they have no obvious natural order, I might use required options for those just to prevent the user (me) from swapping them. 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 bill at celestial.net Mon Apr 19 14:09:28 2021 From: bill at celestial.net (Bill Campbell) Date: Mon, 19 Apr 2021 11:09:28 -0700 Subject: Current thinking on required options In-Reply-To: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <20210419180928.GA18817@hazlitt.celestial.com> On Mon, Apr 19, 2021, Loris Bennett wrote: >Hi, > >I have various small programs which tend to have an interface like the >following example: > > usage: grocli [-h] [-o {check,add,delete}] [-u USERS [USERS ...]] [-g GROUP] I would do this with the action is first argument. Usage: grocli check|add|delete [-u USERS ...] Bill -- INTERNET: bill at celestial.com Bill Campbell; Celestial Software LLC URL: http://www2.celestial.com/ 6641 E. Mercer Way Mobile: (206) 947-5591 PO Box 820 Fax: (206) 232-9186 Mercer Island, WA 98040-0820 Force always attracts men of low morality. -- Albert Einstein From rosuav at gmail.com Mon Apr 19 14:21:16 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 20 Apr 2021 04:21:16 +1000 Subject: Current thinking on required options In-Reply-To: <20210419180928.GA18817@hazlitt.celestial.com> References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> <20210419180928.GA18817@hazlitt.celestial.com> Message-ID: On Tue, Apr 20, 2021 at 4:18 AM Bill Campbell wrote: > > On Mon, Apr 19, 2021, Loris Bennett wrote: > >Hi, > > > >I have various small programs which tend to have an interface like the > >following example: > > > > usage: grocli [-h] [-o {check,add,delete}] [-u USERS [USERS ...]] [-g GROUP] > > I would do this with the action is first argument. > > Usage: grocli check|add|delete [-u USERS ...] > Which aligns well with a concept of subcommands (or, in argparse terms, subparsers). ChrisA From unbreakable at secmail.pro Mon Apr 19 14:22:00 2021 From: unbreakable at secmail.pro (Unbreakable Disease) Date: Mon, 19 Apr 2021 18:22:00 +0000 Subject: do ya still use python? In-Reply-To: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> Message-ID: On 19.04.2021 17:37, JWS wrote: > On Monday, April 19, 2021 at 11:44:11 AM UTC-5, Unbreakable Disease wrote: >> almost no useful posts here for almost a year. is python dying? > I can't tell what group you are referencing. > comp.lang.python is still active. > I'm doing a tkinter project now. Active for these moron spammers who keep it alive thanks to all stupid dudes who think Stack Overflow has an answer to every solution. -- Tip me: bc1qtwmjzywve5v7z6jzk4dkg7v6masw2erpahsn9f bitcoin:bc1qtwmjzywve5v7z6jzk4dkg7v6masw2erpahsn9f From grant.b.edwards at gmail.com Mon Apr 19 12:27:13 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 19 Apr 2021 16:27:13 -0000 (UTC) Subject: Current thinking on required options References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> Message-ID: On 2021-04-19, Dan Stromberg wrote: > On Mon, Apr 19, 2021 at 2:55 AM Loris Bennett wrote: > >> However, the options -o, -u, and -g are required, not optional. >> >> The documentation >> >> https://docs.python.org/3/library/argparse.html#required >> >> advises against required options and here >> >> >> https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments >> >> a way of adding a section 'required arguments' to the usage is >> described. >> > > Of _course_ some options need to be required. Traditionally, required "things" were called arguments and were not prefixed with a hyphen. Optional "things" were called options (hence the similarity in spelling between "optional" and "option"). > I can't imagine what the author of that page was thinking. -- Grant From ethan at stoneleaf.us Mon Apr 19 15:45:14 2021 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 19 Apr 2021 12:45:14 -0700 Subject: do ya still use python? In-Reply-To: References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> Message-ID: On 4/19/21 11:22 AM, Unbreakable Disease wrote: [offensive drivel] List, my apologies -- not sure how that one got through. -- ~Ethan~ Python List Moderator From drsalists at gmail.com Mon Apr 19 15:50:26 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 19 Apr 2021 12:50:26 -0700 Subject: Current thinking on required options In-Reply-To: References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> Message-ID: On Mon, Apr 19, 2021 at 12:36 PM Grant Edwards wrote: > On 2021-04-19, Dan Stromberg wrote: > > On Mon, Apr 19, 2021 at 2:55 AM Loris Bennett < > loris.bennett at fu-berlin.de> wrote: > > > >> However, the options -o, -u, and -g are required, not optional. > >> > >> The documentation > >> > >> https://docs.python.org/3/library/argparse.html#required > >> > >> advises against required options and here > >> > >> > >> > https://stackoverflow.com/questions/24180527/argparse-required-arguments-listed-under-optional-arguments > >> > >> a way of adding a section 'required arguments' to the usage is > >> described. > >> > > > > Of _course_ some options need to be required. > > Traditionally, required "things" were called arguments and were not > prefixed with a hyphen. Optional "things" were called options (hence > the similarity in spelling between "optional" and "option"). > This is a silly thread. "option" should be conflated with "optional" no more than "argument" should be conflated with "a logician's disagreement". $ cpio below cmd output started 2021 Mon Apr 19 12:47:07 PM PDT cpio: You must specify one of -oipt options. Try `cpio --help' or `cpio --usage' for more information. Try 'cpio --help' or 'cpio --usage' for more information. $ tar below cmd output started 2021 Mon Apr 19 12:49:47 PM PDT tar: You must specify one of the '-Acdtrux', '--delete' or '--test-label' options Try 'tar --help' or 'tar --usage' for more information. From hjp-python at hjp.at Mon Apr 19 17:10:32 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 19 Apr 2021 23:10:32 +0200 Subject: Determine what the calling program is In-Reply-To: <22da9982-7723-717b-6785-0b30d48a3971@DancesWithMice.info> References: <22da9982-7723-717b-6785-0b30d48a3971@DancesWithMice.info> Message-ID: <20210419211032.GA28591@hjp.at> On 2021-04-19 08:04:10 +1200, dn via Python-list wrote: > In a similar situation, one of my teams used an (OpSys) environment > variable (available in both *nux and MS-Win). > - when the application starts, it checks for the variable > - if exists, stops running, else may proceed That doesn't work on Unix-like OSs. An environment variable can only be passwd to child processes, not to the parent or unrelated processes. So it can't be used to lock out other processes - they wouldn't ever see the variable. hp -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp at hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: From hjp-python at hjp.at Mon Apr 19 17:13:41 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 19 Apr 2021 23:13:41 +0200 Subject: Determine what the calling program is In-Reply-To: References: Message-ID: <20210419211341.GB28591@hjp.at> On 2021-04-19 08:54:06 +1000, Cameron Simpson wrote: > My personal preference is lock directories. Shell version goes like > this: > > if mkdir /my/lock/directory/name-of-task > then > .. do task .. > rmdir /my/lock/directory/name-of-task > else > echo "lock /my/lock/directory/name-of-task already taken" > fi > > Simple, reliable, even works over NFS if you care. Reliable only if "fail locked" is acceptable. If that process dies for some reason the lock directory will stay behind, blocking other processes until somebody notices the problem and removes it. The fcntl method suggested by several people has the advantage that the lock vanished with the process which holds it. 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 cs at cskk.id.au Mon Apr 19 17:46:12 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 20 Apr 2021 07:46:12 +1000 Subject: Determine what the calling program is In-Reply-To: <20210419211341.GB28591@hjp.at> References: <20210419211341.GB28591@hjp.at> Message-ID: On 19Apr2021 23:13, Peter J. Holzer wrote: >On 2021-04-19 08:54:06 +1000, Cameron Simpson wrote: >> My personal preference is lock directories. Shell version goes like >> this: >> >> if mkdir /my/lock/directory/name-of-task >> then >> .. do task .. >> rmdir /my/lock/directory/name-of-task >> else >> echo "lock /my/lock/directory/name-of-task already taken" >> fi >> >> Simple, reliable, even works over NFS if you care. > >Reliable only if "fail locked" is acceptable. If that process dies for >some reason the lock directory will stay behind, blocking other >processes until somebody notices the problem and removes it. A Python context manager narrows the range of circumstances for this failure quite a lot. But yes. >The fcntl method suggested by several people has the advantage that the >lock vanished with the process which holds it. This is very true. OTOH, mkdir's easy to debug if it hangs around. Cheers, Cameron Simpson From barry at barrys-emacs.org Mon Apr 19 18:17:11 2021 From: barry at barrys-emacs.org (Barry) Date: Mon, 19 Apr 2021 23:17:11 +0100 Subject: Determine what the calling program is In-Reply-To: References: Message-ID: <11165341-AA57-4473-AA53-69CEA8347E58@barrys-emacs.org> > On 19 Apr 2021, at 22:49, Cameron Simpson wrote: > > ?On 19Apr2021 23:13, Peter J. Holzer wrote: >>> On 2021-04-19 08:54:06 +1000, Cameron Simpson wrote: >>> My personal preference is lock directories. Shell version goes like >>> this: >>> >>> if mkdir /my/lock/directory/name-of-task >>> then >>> .. do task .. >>> rmdir /my/lock/directory/name-of-task >>> else >>> echo "lock /my/lock/directory/name-of-task already taken" >>> fi >>> >>> Simple, reliable, even works over NFS if you care. >> >> Reliable only if "fail locked" is acceptable. If that process dies for >> some reason the lock directory will stay behind, blocking other >> processes until somebody notices the problem and removes it. > > A Python context manager narrows the range of circumstances for this > failure quite a lot. But yes. > >> The fcntl method suggested by several people has the advantage that the >> lock vanished with the process which holds it. > > This is very true. OTOH, mkdir's easy to debug if it hangs around. Only the fcntl method is robust. Your suggestion with mkdir is not reliable in practice. If you need a lock in the sh env then there are standard patterns using the flock command. See the man page for examples. Barry > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > From avigross at verizon.net Mon Apr 19 19:56:39 2021 From: avigross at verizon.net (Avi Gross) Date: Mon, 19 Apr 2021 19:56:39 -0400 Subject: Current thinking on required options References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <014901d73577$a3d11d10$eb735730$@verizon.net> Sidestepping the wording of "options" is the very real fact that providing names for even required parts can be helpful in many cases. There re programs that may not require anything on the command line to be done but many need something to provide some flexibility. So, I tend to agree that in many cases you need an explicit or implicit argument for a program to do something useful. If I have a simple program that looks up a phone number when given a name, it would require a name UNLESS the default behavior is to show ALL entries or repeat whatever I asked for last time by keeping track or provide the number I ask for most or pick a random one or return silently having done nothing ... But I want to point out something OBVIOUS. The requested program in my view HAS NO required arguments! All are in a sense optional but at the same time are all mandatory in some circumstances. It can be called two equally valid ways: grocli [-h] OR grocli -o {check,add,delete} -u USERS [USERS ...]] -g GROUP When called to ask for help, none of the other arguments are required or are ignored or worse. When called with the second properly formed set of arguments, in any order, I assume any "-h" is either ignored or an error. So I would possibly have TWO usage statements and in both cases, NO optional arguments! Either you ask for help or you provide everything else. Clearly your actual code can be designed many ways including allowing all combinations and throwing in help when asked for in addition to doing what is requested or allowing multiple -u arguments instead of multiple arguments following a single -u and so forth. Heck, it can perhaps accept random additional arguments and pass them along to another command it uses internally without question in a "..." situation. So a syntax for defining a program as documentation like the above may need an OR approach or be even more complex when say two or more arguments can be used but only ONE is allowed and then it may be mandatory. Picture a -m to suggest units are metric versus ... And this "-h" notation is very common in programs and can cause the description of how a program should be used more complex than it needs to be if you insist on just one line showing how to use it rather than giving several valid usages. -----Original Message----- From: Python-list On Behalf Of Dan Stromberg Sent: Monday, April 19, 2021 12:04 PM To: Loris Bennett Cc: Python List Subject: Re: Current thinking on required options On Mon, Apr 19, 2021 at 2:55 AM Loris Bennett wrote: > However, the options -o, -u, and -g are required, not optional. > > The documentation > > https://docs.python.org/3/library/argparse.html#required > > advises against required options and here > > > https://stackoverflow.com/questions/24180527/argparse-required-argumen > ts-listed-under-optional-arguments > > a way of adding a section 'required arguments' to the usage is > described. > Of _course_ some options need to be required. I can't imagine what the author of that page was thinking. -- https://mail.python.org/mailman/listinfo/python-list From jon+usenet at unequivocal.eu Mon Apr 19 20:53:14 2021 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 20 Apr 2021 00:53:14 -0000 (UTC) Subject: do ya still use python? References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> Message-ID: On 2021-04-20, Paul Rubin wrote: > Ethan Furman writes: >> List, my apologies -- not sure how that one got through. > > It was trollishly written but was a reasonable observation on the state > of the Usenet group. I didn't realize it had come through (or reached) > the mailing list. Anyway the state of affairs for us Usenet die-hards > isn't so great. Why do you say that? The group seems quite lively to me (and no I'm not counting spam etc). From drsalists at gmail.com Mon Apr 19 23:47:49 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 19 Apr 2021 20:47:49 -0700 Subject: do ya still use python? In-Reply-To: References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> Message-ID: On Mon, Apr 19, 2021 at 5:55 PM Jon Ribbens via Python-list < python-list at python.org> wrote: > On 2021-04-20, Paul Rubin wrote: > > Ethan Furman writes: > >> List, my apologies -- not sure how that one got through. > > > > It was trollishly written but was a reasonable observation on the state > > of the Usenet group. I didn't realize it had come through (or reached) > > the mailing list. Anyway the state of affairs for us Usenet die-hards > > isn't so great. > > Why do you say that? The group seems quite lively to me > (and no I'm not counting spam etc). > Actually, this list is less busy than it was a decade or two ago, but that's probably because of things like stackoverflow, python-dev, pypy-dev, cython-devel, python-ideas, distutils-sig, issue trackers, code-quality, and probably others. There was a time when most python-related discussion happened here on python-list/comp.lang.python. From jkn_gg at nicorp.f9.co.uk Tue Apr 20 05:08:49 2021 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Tue, 20 Apr 2021 02:08:49 -0700 (PDT) Subject: do ya still use python? In-Reply-To: <87mtttmqnm.fsf@nightsong.com> References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> <87mtttmqnm.fsf@nightsong.com> Message-ID: <46fee176-946b-4b02-8212-a8d63fb840acn@googlegroups.com> On Tuesday, April 20, 2021 at 7:11:41 AM UTC+1, Paul Rubin wrote: > Jon Ribbens writes: > > Why do you say that? The group seems quite lively to me (and no I'm > > not counting spam etc). > No there is a lot happening in the Python world that never gets > mentioned here. Look at the 3.10 and 3.9.x release notes: many new > language features that we'd never have heard of if we only got our news > from here. These things would have been the topics of endless > discussions back in the day. The newsgroup was once a good place to > keep track of what was happening Python-wise, but it no longer is. This > is sad. I agree with Paul - sadly this Usenet forum is seriously less valuable than it used to be. I have been a semi-lurker here for more than 20 years (pre Python 1.5) and the S/N ration has massively changed since then. This is as much a reflection of the reduced status of Usenet groups as in the rise of Python and the associated change in 'demographic'. But as another Usenet fan I find it disappointing. You wouldn't see Tim Peters or even Guido here nowadays, and Steven D'Aprano was IMO forced out for no good reason ... you see the results here every day... J^n From alan.gauld at yahoo.co.uk Tue Apr 20 04:32:40 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 20 Apr 2021 09:32:40 +0100 Subject: do ya still use python? In-Reply-To: References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> Message-ID: On 20/04/2021 04:47, Dan Stromberg wrote: > Actually, this list is less busy than it was a decade or two ago, but > that's probably because of things like stackoverflow, python-dev, pypy-dev, > cython-devel, python-ideas, distutils-sig, issue trackers, code-quality, > and probably others. > > There was a time when most python-related discussion happened here on > python-list/comp.lang.python. > It's also a reflection of Python's maturity in the market. It is no longer a cute language that folks stumble across and need lots of support to get up and running. There are all sorts of formal and informal training routes available. People are far more likely to have a buddy at work using Python that they can ask stuff. We see the same trend on the tutor list, traffic has dropped off by a factor of 3-5 times what it was at its peak. And the questions are changing too, fewer basic things about loops and writing functions, more about specific library modules and such. (That's why I now have time to regularly read this list instead of dipping in once or twice a month! :-) -- 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 me at xguest.net Mon Apr 19 21:38:27 2021 From: me at xguest.net (X Guest) Date: Tue, 20 Apr 2021 09:38:27 +0800 Subject: do ya still use python? In-Reply-To: References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> Message-ID: <62bed006-29dd-465e-bb1f-3d92ed56e4d3@www.fastmail.com> we are in ML industry where python is used widely. On Tue, Apr 20, 2021, at 8:53 AM, Jon Ribbens via Python-list wrote: > On 2021-04-20, Paul Rubin > wrote: > > Ethan Furman > writes: > >> List, my apologies -- not sure how that one got through. > > > > It was trollishly written but was a reasonable observation on the state > > of the Usenet group. I didn't realize it had come through (or reached) > > the mailing list. Anyway the state of affairs for us Usenet die-hards > > isn't so great. > > Why do you say that? The group seems quite lively to me > (and no I'm not counting spam etc). > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://xguest.net/ From roel at roelschroeven.net Tue Apr 20 16:47:09 2021 From: roel at roelschroeven.net (Roel Schroeven) Date: Tue, 20 Apr 2021 22:47:09 +0200 Subject: Current thinking on required options In-Reply-To: <014901d73577$a3d11d10$eb735730$@verizon.net> References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> <014901d73577$a3d11d10$eb735730$@verizon.net> Message-ID: Avi Gross via Python-list schreef op 20/04/2021 om 1:56: > Sidestepping the wording of "options" is the very real fact that providing > names for even required parts can be helpful in many cases. Very true. It's very much like named arguments in Python function calls: they help to document precisely and explicitly what's happening, instead of having to rely on remembering the order of arguments/options. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From PythonList at DancesWithMice.info Tue Apr 20 17:44:24 2021 From: PythonList at DancesWithMice.info (dn) Date: Wed, 21 Apr 2021 09:44:24 +1200 Subject: do ya still use python? In-Reply-To: References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> Message-ID: <188843a0-626e-73cb-4f2a-35f9c8619b29@DancesWithMice.info> On 20/04/2021 20.32, Alan Gauld via Python-list wrote: > On 20/04/2021 04:47, Dan Stromberg wrote: > >> Actually, this list is less busy than it was a decade or two ago, but >> that's probably because of things like stackoverflow, python-dev, pypy-dev, >> cython-devel, python-ideas, distutils-sig, issue trackers, code-quality, >> and probably others. >> >> There was a time when most python-related discussion happened here on >> python-list/comp.lang.python. >> > > It's also a reflection of Python's maturity in the market. It is no > longer a cute language that folks stumble across and need lots of > support to get up and running. There are all sorts of formal and > informal training routes available. People are far more likely > to have a buddy at work using Python that they can ask stuff. > > We see the same trend on the tutor list, traffic has dropped off > by a factor of 3-5 times what it was at its peak. And the questions > are changing too, fewer basic things about loops and writing > functions, more about specific library modules and such. (That's > why I now have time to regularly read this list instead of > dipping in once or twice a month! :-) +1 As @Dan says, there are now many other avenues of enquiry. Per @Alan's own, there are also many sources of training and reference resources. Accordingly, and particularly at the beginner end of the trail, it is much easier to find an answer oneself (than it once was). The Python community itself has offered those more-specialised fora/forums partly in a bid to syphon-off such topics and thus reduce traffic on the more general list. Similarly, when was the last time you went to a well-attended PUG meeting? (cf a PyCon) Is it a 'failure', or a 'success'? Are there reasons why someone might prefer StackOverflow to this list? Are they more to do with the person, or something the Python Community should address? -- Regards, =dn From tjreedy at udel.edu Tue Apr 20 19:16:53 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Apr 2021 19:16:53 -0400 Subject: do ya still use python? In-Reply-To: <188843a0-626e-73cb-4f2a-35f9c8619b29@DancesWithMice.info> References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> <188843a0-626e-73cb-4f2a-35f9c8619b29@DancesWithMice.info> Message-ID: On 4/20/2021 5:44 PM, dn via Python-list wrote: > Are there reasons why someone might prefer StackOverflow to this list? For programming questions with testable answers, generally yes. But I sometimes advise SO questioners to redirect questions here when more appropriate. Advantages include that questions and answers can be searched within a tag, can be commented separately, and can be edited. The latter is important. Web forums that imitate mail lists with indelible sequential postings are not much better. > Are they more to do with the person, or something the Python Community > should address? Not the first, nor the second officially. But many Python Community members already answer python-tagged questions. I specifically monitor python-idle questions. The PSF could set up a imitation site, or perhaps sponsor 'Python Pitstop' on stackexchange, but why bother? -- Terry Jan Reedy From tjreedy at udel.edu Tue Apr 20 19:19:10 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 20 Apr 2021 19:19:10 -0400 Subject: do ya still use python? In-Reply-To: References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> Message-ID: On 4/20/2021 4:32 AM, Alan Gauld via Python-list wrote: > We see the same trend on the tutor list, traffic has dropped off > by a factor of 3-5 times what it was at its peak. And the questions > are changing too, fewer basic things about loops and writing > functions, more about specific library modules and such. I suspect that at least some such questions have good answers on StackOverflow that questioners could profitably read first. -- Terry Jan Reedy From loris.bennett at fu-berlin.de Wed Apr 21 01:47:27 2021 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Wed, 21 Apr 2021 07:47:27 +0200 Subject: Current thinking on required options References: <87tuo2wqhh.fsf@hornfels.zedat.fu-berlin.de> <014901d73577$a3d11d10$eb735730$@verizon.net> Message-ID: <87sg3kfats.fsf@hornfels.zedat.fu-berlin.de> Roel Schroeven writes: > Avi Gross via Python-list schreef op 20/04/2021 om 1:56: >> Sidestepping the wording of "options" is the very real fact that providing >> names for even required parts can be helpful in many cases. > > Very true. It's very much like named arguments in Python function calls: they > help to document precisely and explicitly what's happening, instead of having to > rely on remembering the order of arguments/options. Thanks to all for the discussion, which I did not think was silly - to me "option" and "optional" are much more closely related than the two meanings of "argument", which, while obviously sharing the same root, have diverged significantly. However, I am grateful for the cpio and tar examples. I'll probably stick with the "required options" and just tweak the usage output of argparse to make it clear that some options are not optional :-) Cheers, Loris From o1bigtenor at gmail.com Wed Apr 21 06:07:23 2021 From: o1bigtenor at gmail.com (o1bigtenor) Date: Wed, 21 Apr 2021 05:07:23 -0500 Subject: do ya still use python? In-Reply-To: References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> Message-ID: On Tue, Apr 20, 2021 at 6:26 PM Terry Reedy wrote: > > On 4/20/2021 4:32 AM, Alan Gauld via Python-list wrote: > > > We see the same trend on the tutor list, traffic has dropped off > > by a factor of 3-5 times what it was at its peak. And the questions > > are changing too, fewer basic things about loops and writing > > functions, more about specific library modules and such. > > I suspect that at least some such questions have good answers on > StackOverflow that questioners could profitably read first. > Respectfully - - - - I would disagree. I am finding when I'm looking for answers that the generalist sites most often cough up responses - - - - - yes there are responses - - - but those responses are for software of at best 5 to 6 years ago and all too often its for software of 15 + years ago. Most often those 'answers' just aren't applicable anymore. Not saying that there never are answers but I've gotten to including a 'date' in my searching and then there are a not less links proffered by the search engine! HTH From mal at europython.eu Wed Apr 21 09:40:13 2021 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 21 Apr 2021 15:40:13 +0200 Subject: EuroPython 2021: Financial Aid Applications Open Message-ID: We are happy to announce the start of our financial aid program for this year?s EuroPython. * EuroPython 2021 Financial Aid * https://ep2021.europython.eu/registration/financial-aid/ As part of our commitment to the Python community and to increase our reach to lower income countries, we will provide financial aid for people in need to enable them to attend EuroPython 2021. Financial Aid Sponsor for EuroPython 2021: The EuroPython Society (EPS) is sponsoring EUR 10,000 worth of financial aid this year. We offer financial aid in the following two ways: - Discounted ticket. Get a standard conference ticket for the conference with a very affordable price. - Free ticket. For exceptional cases, we offer the standard conference ticket for free. Conference tickets include access to conference days (Wed-Fri), sponsored workshops, Beginners? Day workshop and sprints. Please note: Access to our regular training sessions and workshops is not included in the conference ticket. Grant Eligibility ----------------- EuroPython is a wonderful place to meet and share your experience with Python developers from Europe and all around the world. Our goal is to support people who want to help improve the Python community: conference speakers, active developers from smaller Python communities and open source contributors. Our grants are open to all people in need of financial aid. We take into account the following criteria during the selection process: - Contributors: Potential speakers/trainers of EuroPython (those who have submitted a proposal), volunteers and other contributors to EuroPython and/or Python community projects. - Economic factors: We want everybody to have a chance to join EuroPython, regardless of economic situation or income level. - Country based: As EuroPython 2021 will be run online and there may be participants joining outside of Europe, we understand not all countries have the same income levels and cost of living. - Diversity: We aim to be the most diverse and inclusive event possible. How to apply ------------ Please see our financial aid page for details on how to apply: https://ep2021.europython.eu/registration/financial-aid/ Quick Summary ------------- EuroPython 2021 will be run online from July 26 - August 1: - Two workshop/training days (July 26 - 27) - Three conference days (July 28 - 30) - Two sprint days (July 31 - August 1) The sessions will be scheduled to ensure they are also accessible for those in the Asian and Americas time zones. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/europython-2021-financial-aid/ Tweet: https://twitter.com/europython/status/1384808840055730177 Enjoy, -- EuroPython 2021 Team https://www.europython-society.org/ From Bischoop at vimart.net Wed Apr 21 11:01:56 2021 From: Bischoop at vimart.net (Bischoop) Date: Wed, 21 Apr 2021 15:01:56 -0000 (UTC) Subject: do ya still use python? References: Message-ID: On 2021-04-19, Unbreakable Disease wrote: >> do ya still use python? That's why we're all here. > almost no useful posts here for almost a year. is python dying? It's not a Python thing, it's Usenet that's not used as much today as decade ago. There's a lot of places in a Internet to talk Python: Discord,FB, Forums. Feel free to write some useful posts :-) From avigross at verizon.net Wed Apr 21 12:12:04 2021 From: avigross at verizon.net (Avi Gross) Date: Wed, 21 Apr 2021 12:12:04 -0400 Subject: do ya still use python? In-Reply-To: References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> Message-ID: <01a701d736c9$1247c9e0$36d75da0$@verizon.net> Yes, Python is a moving target, as are quite a few such things these days. The changes when release 3 came along mean that what you find by a search may not apply to your situation. And as new features get added, some advice might shift. The presence of so many add-on modules also means that the simplest way to do something is not to do it but use code that has already been done and hopefully has been used enough so many bugs have been ironed out. Modules and packages of various sorts also can change and I often see a neat new feature that is later deprecated as it is replaced by a neater or more abstract version or ... So it is sometimes worthwhile to put humans back into the process after searching for something like how to read in data from some file format. I once wanted to be able to read in data from EXCEL sheets in another language and spent many hours trying various packages a search suggested but oddly, one after another did not work for ME. One, for example, required a JAVA installation different than what I had. Some packages were no longer available or maintained. Some did not easily do what I wanted. Some worked with older versions of the EXCEL file formats. I eventually found one I liked. But a human with experience might have steered me to something up-front that was being used NOW by people with minimal problems and that was compatible. There is of course much to be said for asking people to show they did SOME work before bothering others. I always do that if I can guess at what keywords might help zoom in on useful info. But as the internet continues to grow, there are too many things found that are not helpful especially when some search words have alternate meanings as in other human languages. But perhaps the purpose of some groups varies. If you want a discussion of the best way to do something and what the tradeoffs might be or whether it may be better to use other tools, or which way to add a new feature to your language and so on, you want different kinds of people involved depending on the topic. Alan runs a tutorial group of sorts intended to help people who are often quite new to python. I hung out there a while and realized my personal interests tended to be in other directions than helping people do things in simple basic ways. I was way beyond that and interested in what is more elegant or efficient or uses some novel feature or even how to use modules already designed for it. But for students in a class wanting a little hint for their homework, this is often the wrong approach. Maybe after they have mastered some basics, they might benefit from looking deeper. But at their stage, searching the internet for answers may not work well as they may not even know how to ask the right way or be turned off by some of what they read that assumes they already know much more. So there really is room for many forums and methods and ideally people should try to focus on the ones that work better for what they are doing. -----Original Message----- From: Python-list On Behalf Of o1bigtenor Sent: Wednesday, April 21, 2021 6:07 AM To: Terry Reedy Cc: Python Subject: Re: do ya still use python? On Tue, Apr 20, 2021 at 6:26 PM Terry Reedy wrote: > > On 4/20/2021 4:32 AM, Alan Gauld via Python-list wrote: > > > We see the same trend on the tutor list, traffic has dropped off by > > a factor of 3-5 times what it was at its peak. And the questions are > > changing too, fewer basic things about loops and writing functions, > > more about specific library modules and such. > > I suspect that at least some such questions have good answers on > StackOverflow that questioners could profitably read first. > Respectfully - - - - I would disagree. I am finding when I'm looking for answers that the generalist sites most often cough up responses - - - - - yes there are responses - - - but those responses are for software of at best 5 to 6 years ago and all too often its for software of 15 + years ago. Most often those 'answers' just aren't applicable anymore. Not saying that there never are answers but I've gotten to including a 'date' in my searching and then there are a not less links proffered by the search engine! HTH -- https://mail.python.org/mailman/listinfo/python-list From stephie at osohq.com Wed Apr 21 13:11:34 2021 From: stephie at osohq.com (Stephie Glaser) Date: Wed, 21 Apr 2021 11:11:34 -0600 Subject: =?UTF-8?Q?ANN=3A_Early_access_to_roles_in_sqlalchemy=2Doso_=E2=80=93_aut?= =?UTF-8?Q?horization_as_a_spec?= Message-ID: We build Oso, a library for building authorization into your application ( https://docs.osohq.com/). We've previously shared our base Python libary, and our integrations with Python frameworks/ORMS: flask-oso, django-oso, and sqlalchemy-oso. We are working on a new version of the library that treats authorization more like a spec (starting with sqlalchemy-oso). It provides building blocks for common patterns like roles, hierarchies, etc. From there, you can customize it as needed using Oso's underlying policy language. We're providing early access to the library for those who are interested in providing feedback. Email stephie at osohq.com if interested. *Some useful links:* Quickstart & Install: https://docs.osohq.com/getting-started/quickstart.html sqlalchemy-oso library: https://docs.osohq.com/python/reference/frameworks/sqlalchemy.html Built-in roles with SQLAlchemy: https://docs.osohq.com/python/reference/frameworks/sqlalchemy/sqlalchemy_roles_ref.html django-oso library: https://docs.osohq.com/python/reference/frameworks/django.html flask-oso library: https://docs.osohq.com/python/reference/frameworks/flask.html Polar, Oso's policy language: https://docs.osohq.com/python/reference/polar.html Join us on Slack for any questions: http://join-slack.osohq.com Stephie Glaser Developer Relations, Oso From tjreedy at udel.edu Thu Apr 22 16:00:26 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 22 Apr 2021 16:00:26 -0400 Subject: do ya still use python? In-Reply-To: References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> Message-ID: On 4/21/2021 6:07 AM, o1bigtenor wrote: > On Tue, Apr 20, 2021 at 6:26 PM Terry Reedy wrote: >> >> On 4/20/2021 4:32 AM, Alan Gauld via Python-list wrote: >> >>> We see the same trend on the tutor list, traffic has dropped off >>> by a factor of 3-5 times what it was at its peak. And the questions >>> are changing too, fewer basic things about loops and writing >>> functions, more about specific library modules and such. >> >> I suspect that at least some such questions have good answers on >> StackOverflow that questioners could profitably read first. >> > Respectfully - - - - I would disagree. > I am finding when I'm looking for answers that the generalist sites > most often cough up responses - - - - - yes there are responses > - - - but those responses are for software of at best 5 to 6 years > ago and all too often its for software of 15 + years ago. Alan and I were specifically discussing questions about Python standard library modules, which are currently maintained and mostly stable. Many beginner questions are likely to have useful answers tagged , , and sometimes something more specific. Someone on the tutor list could even look on SO for the beginner and perhaps answer with a link. But that is for Alan, etc, to decide. I merely offered that as a suggestion. -- Terry Jan Reedy From zen96285 at gmail.com Thu Apr 22 19:53:05 2021 From: zen96285 at gmail.com (Andy AO) Date: Fri, 23 Apr 2021 07:53:05 +0800 Subject: The split() function of Python's built-in module has changed in a puzzling way - is this a bug? Message-ID: Upgrading from Python 3.6.8 to Python 3.9.0 and executing unit tests revealed a significant change in the behavior of re.split(). but looking at the relevant documentation ? Changelog and re - Regular expression operations - Python 3.9.4 documentation yet no change is found. number = '123'def test_Asterisk_quantifier_with_capture_group(self): resultList = re.split(r'(\d*)', self.number) if platform.python_version() == '3.6.8': self.assertEqual(resultList,['', '123', '']) else: self.assertEqual(resultList,['', '123', '', '', '']) I feel that this is clearly not in line with the description of the function in the split documentation, and it is also strange that after replacing * with +, the behavior is still the same as in 3.6.8. 1. why is this change not in the documentation? Is it because I didn?t find it? 2. Why did the behavior change this way? Was a bug introduced, or was it a bug fix? From travisgriggs at gmail.com Fri Apr 23 01:34:52 2021 From: travisgriggs at gmail.com (Travis Griggs) Date: Fri, 23 Apr 2021 05:34:52 +0000 Subject: Fun Generators Message-ID: <1E31D4C0-2537-4464-BB82-95E01FEAD473@gmail.com> Doing an "industry experience" talk to an incoming class at nearby university tomorrow. Have a couple points where I might do some "fun things" with python. Said students have been learning some python3. I'm soliciting any *fun* generators people may have seen or written? Not so much the cool or clever ones. Or the mathematical ones (e.g. fib). Something more inane and "fun". But still showcasing generators uniqueness. Short and simple is good. Thanks in advance! From frank at chagford.com Fri Apr 23 01:55:37 2021 From: frank at chagford.com (Frank Millman) Date: Fri, 23 Apr 2021 07:55:37 +0200 Subject: Fun Generators In-Reply-To: <1E31D4C0-2537-4464-BB82-95E01FEAD473@gmail.com> References: <1E31D4C0-2537-4464-BB82-95E01FEAD473@gmail.com> Message-ID: <4c33f6b5-9126-c363-75c1-0e686f13651d@chagford.com> On 2021-04-23 7:34 AM, Travis Griggs wrote: > Doing an "industry experience" talk to an incoming class at nearby university tomorrow. Have a couple points where I might do some "fun things" with python. Said students have been learning some python3. > > I'm soliciting any *fun* generators people may have seen or written? Not so much the cool or clever ones. Or the mathematical ones (e.g. fib). Something more inane and "fun". But still showcasing generators uniqueness. Short and simple is good. > > Thanks in advance! > Have you looked at this? http://www.dabeaz.com/generators/ Frank Millman From frank at chagford.com Fri Apr 23 01:55:37 2021 From: frank at chagford.com (Frank Millman) Date: Fri, 23 Apr 2021 07:55:37 +0200 Subject: Fun Generators In-Reply-To: <1E31D4C0-2537-4464-BB82-95E01FEAD473@gmail.com> References: <1E31D4C0-2537-4464-BB82-95E01FEAD473@gmail.com> Message-ID: <4c33f6b5-9126-c363-75c1-0e686f13651d@chagford.com> On 2021-04-23 7:34 AM, Travis Griggs wrote: > Doing an "industry experience" talk to an incoming class at nearby university tomorrow. Have a couple points where I might do some "fun things" with python. Said students have been learning some python3. > > I'm soliciting any *fun* generators people may have seen or written? Not so much the cool or clever ones. Or the mathematical ones (e.g. fib). Something more inane and "fun". But still showcasing generators uniqueness. Short and simple is good. > > Thanks in advance! > Have you looked at this? http://www.dabeaz.com/generators/ Frank Millman From tjol at tjol.eu Fri Apr 23 03:52:41 2021 From: tjol at tjol.eu (Thomas Jollans) Date: Fri, 23 Apr 2021 09:52:41 +0200 Subject: The split() function of Python's built-in module has changed in a puzzling way - is this a bug? In-Reply-To: References: Message-ID: <93c0079a-1721-9a59-af4f-f2118c98a4a2@tjol.eu> On 23/04/2021 01:53, Andy AO wrote: > Upgrading from Python 3.6.8 to Python 3.9.0 and executing unit tests > revealed a significant change in the behavior of re.split(). > > but looking at the relevant documentation ? Changelog python.org/3/whatsnew/changelog.html> and re - Regular expression > operations - Python 3.9.4 documentation > > yet no change is found. > > number = '123'def test_Asterisk_quantifier_with_capture_group(self): > resultList = re.split(r'(\d*)', self.number) > if platform.python_version() == '3.6.8': > self.assertEqual(resultList,['', '123', '']) > > else: > self.assertEqual(resultList,['', '123', '', '', '']) Hi Andy, That's interesting. The old result is less surprising, but of course both are technically correct as the 4th element in the result matches your regexp. The oldest version of Python I had lying around to test is 3.7; that has the same behaviour as 3.9. I suspect that this behaviour is related to the following note in the docs for re.split: Changed in version 3.7: Added support of splitting on a pattern that could match an empty string. (your pattern can match an empty string, so I suppose it wasn't technically supported in 3.6?) -- Thomas > > I feel that this is clearly not in line with the description of the > function in the split documentation, and it is also strange that after > replacing * with +, the behavior is still the same as in 3.6.8. > > 1. why is this change not in the documentation? Is it because I didn?t > find it? > 2. Why did the behavior change this way? Was a bug introduced, or was it > a bug fix? From david at lowryduda.com Fri Apr 23 12:22:59 2021 From: david at lowryduda.com (David Lowry-Duda) Date: Fri, 23 Apr 2021 12:22:59 -0400 Subject: do ya still use python? In-Reply-To: <188843a0-626e-73cb-4f2a-35f9c8619b29@DancesWithMice.info> References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> <188843a0-626e-73cb-4f2a-35f9c8619b29@DancesWithMice.info> Message-ID: > Are there reasons why someone might prefer StackOverflow to this list? > Are they more to do with the person, or something the Python Community > should address? I think general discoverability is a driving force. A beginner has a problem, goes to google, types in their problem, and sees some links to the documentation and stackoverflow first (typically). And that's where they are. SO also ranks responses to a question, which the list doesn't do. There are lots of things that I think SO is better suited for than mailing lists --- but of course I also think there are lots of things the list is better suited for than fora like SO. - DLD From david at lowryduda.com Fri Apr 23 12:18:23 2021 From: david at lowryduda.com (David Lowry-Duda) Date: Fri, 23 Apr 2021 12:18:23 -0400 Subject: do ya still use python? In-Reply-To: <46fee176-946b-4b02-8212-a8d63fb840acn@googlegroups.com> References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> <87mtttmqnm.fsf@nightsong.com> <46fee176-946b-4b02-8212-a8d63fb840acn@googlegroups.com> Message-ID: > You wouldn't see Tim Peters or even Guido here nowadays, and > Steven D'Aprano was IMO forced out for no good reason ... you see > the results here every day... What happened to Steven D'Aprano? - DLD From jpic at yourlabs.org Fri Apr 23 13:02:04 2021 From: jpic at yourlabs.org (J. Pic) Date: Fri, 23 Apr 2021 19:02:04 +0200 Subject: do ya still use python? In-Reply-To: References: <7349be1a-dcf7-4812-881c-58f8ad84eb1bn@googlegroups.com> <87y2ddg57m.fsf@nightsong.com> <87mtttmqnm.fsf@nightsong.com> <46fee176-946b-4b02-8212-a8d63fb840acn@googlegroups.com> Message-ID: CPython powers Mars Ingenuity Helicopter: https://github.com/readme/nasa-ingenuity-helicopter All CPython contributors got a new GitHub badge to show off. From travisgriggs at gmail.com Fri Apr 23 13:29:20 2021 From: travisgriggs at gmail.com (Travis Griggs) Date: Fri, 23 Apr 2021 17:29:20 +0000 Subject: Fun Generators In-Reply-To: <4c33f6b5-9126-c363-75c1-0e686f13651d@chagford.com> References: <1E31D4C0-2537-4464-BB82-95E01FEAD473@gmail.com> <4c33f6b5-9126-c363-75c1-0e686f13651d@chagford.com> Message-ID: <4FA5DA75-DF06-4701-9025-B527086FE03E@gmail.com> > On Apr 23, 2021, at 05:55, Frank Millman wrote: > > On 2021-04-23 7:34 AM, Travis Griggs wrote: >> Doing an "industry experience" talk to an incoming class at nearby university tomorrow. Have a couple points where I might do some "fun things" with python. Said students have been learning some python3. >> I'm soliciting any *fun* generators people may have seen or written? Not so much the cool or clever ones. Or the mathematical ones (e.g. fib). Something more inane and "fun". But still showcasing generators uniqueness. Short and simple is good. >> Thanks in advance! > > Have you looked at this? > > http://www.dabeaz.com/generators/ > > Frank Millman > > -- > https://mail.python.org/mailman/listinfo/python-list I hadn't. But now I have. These are really cool. But not as whimsical/simple as I would have hoped. They're actually useful :) From drsalists at gmail.com Fri Apr 23 13:39:01 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 23 Apr 2021 10:39:01 -0700 Subject: Fun Generators In-Reply-To: <4FA5DA75-DF06-4701-9025-B527086FE03E@gmail.com> References: <1E31D4C0-2537-4464-BB82-95E01FEAD473@gmail.com> <4c33f6b5-9126-c363-75c1-0e686f13651d@chagford.com> <4FA5DA75-DF06-4701-9025-B527086FE03E@gmail.com> Message-ID: On Fri, Apr 23, 2021 at 10:30 AM Travis Griggs wrote: > > On Apr 23, 2021, at 05:55, Frank Millman wrote: > > > > On 2021-04-23 7:34 AM, Travis Griggs wrote: > >> Doing an "industry experience" talk to an incoming class at nearby > university tomorrow. Have a couple points where I might do some "fun > things" with python. Said students have been learning some python3. > >> I'm soliciting any *fun* generators people may have seen or written? > Not so much the cool or clever ones. Or the mathematical ones (e.g. fib). > Something more inane and "fun". But still showcasing generators uniqueness. > Short and simple is good. > >> Thanks in advance! > > > > Have you looked at this? > > > > http://www.dabeaz.com/generators/ > > > > Frank Millman > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > I hadn't. But now I have. These are really cool. But not as > whimsical/simple as I would have hoped. They're actually useful :) > Perhaps not the best example, but a bit whimsical - there's a "Daffy Duck" bidirectional generator in this presentation: https://stromberg.dnsalias.org/~dstromberg/Intro-to-Python/Python%20Generators,%20Iterators%20and%20Comprehensions.pdf Full Disclosure: I created the presentation. From drsalists at gmail.com Fri Apr 23 13:53:14 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 23 Apr 2021 10:53:14 -0700 Subject: The split() function of Python's built-in module has changed in a puzzling way - is this a bug? In-Reply-To: References: Message-ID: On Thu, Apr 22, 2021 at 8:53 PM Andy AO wrote: > Upgrading from Python 3.6.8 to Python 3.9.0 and executing unit tests > revealed a significant change in the behavior of re.split(). > > but looking at the relevant documentation ? Changelog python.org/3/whatsnew/changelog.html> and re - Regular expression > operations - Python 3.9.4 documentation > > yet no change is found. > > number = '123'def test_Asterisk_quantifier_with_capture_group(self): > resultList = re.split(r'(\d*)', self.number) > if platform.python_version() == '3.6.8': > self.assertEqual(resultList,['', '123', '']) > > else: > self.assertEqual(resultList,['', '123', '', '', '']) > > I feel that this is clearly not in line with the description of the > function in the split documentation, and it is also strange that after > replacing * with +, the behavior is still the same as in 3.6.8. > > 1. why is this change not in the documentation? Is it because I didn?t > find it? > 2. Why did the behavior change this way? Was a bug introduced, or was it > a bug fix? > -- > https://mail.python.org/mailman/listinfo/python-list Interesting, and make sure to check out the FutureWarning: $ pythons --command 'import re; number = "123"; print(re.split(r"(\d*)", number))' below cmd output started 2021 Fri Apr 23 10:48:32 AM PDT /usr/local/cpython-0.9/bin/python (unknown) good skipped /usr/local/cpython-1.0/bin/python (1.0.1) bad File "", line 1 import re; number = "123"; print(re.split(r"(\d*)", number)) ^ SyntaxError: invalid syntax /usr/local/cpython-1.1/bin/python (1.1) bad File "", line 1 import re; number = "123"; print(re.split(r"(\d*)", number)) ^ SyntaxError: invalid syntax /usr/local/cpython-1.2/bin/python (1.2) bad File "", line 1 import re; number = "123"; print(re.split(r"(\d*)", number)) ^ SyntaxError: invalid syntax /usr/local/cpython-1.3/bin/python (1.3) bad File "", line 1 import re; number = "123"; print(re.split(r"(\d*)", number)) ^ SyntaxError: invalid syntax /usr/local/cpython-1.4/bin/python (1.4) bad File "", line 1 import re; number = "123"; print(re.split(r"(\d*)", number)) ^ SyntaxError: invalid syntax /usr/local/cpython-1.5/bin/python (1.5.2) good ['', '123', ''] /usr/local/cpython-1.6/bin/python (1.6.1) good ['', '123', ''] /usr/local/cpython-2.0/bin/python (2.0.1) good ['', '123', ''] /usr/local/cpython-2.1/bin/python (2.1.0) good ['', '123', ''] /usr/local/cpython-2.2/bin/python (2.2.0) good ['', '123', ''] /usr/local/cpython-2.3/bin/python (2.3.0) good ['', '123', ''] /usr/local/cpython-2.4/bin/python (2.4.0) good ['', '123', ''] /usr/local/cpython-2.5/bin/python (2.5.6) good ['', '123', ''] /usr/local/cpython-2.6/bin/python (2.6.9) good ['', '123', ''] /usr/local/cpython-2.7/bin/python (2.7.16) good ['', '123', ''] /usr/local/cpython-3.0/bin/python (3.0.1) good ['', '123', ''] /usr/local/cpython-3.1/bin/python (3.1.5) good ['', '123', ''] /usr/local/cpython-3.2/bin/python (3.2.5) good ['', '123', ''] /usr/local/cpython-3.3/bin/python (3.3.7) good ['', '123', ''] /usr/local/cpython-3.4/bin/python (3.4.8) good ['', '123', ''] /usr/local/cpython-3.5/bin/python (3.5.5) good ['', '123', ''] /usr/local/cpython-3.5/lib/python3.5/re.py:203: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) /usr/local/cpython-3.6/bin/python (3.6.0) good ['', '123', ''] /usr/local/cpython-3.6/lib/python3.6/re.py:212: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) /usr/local/cpython-3.7/bin/python (3.7.0) good ['', '123', '', '', ''] /usr/local/cpython-3.8/bin/python (3.8.0) good ['', '123', '', '', ''] /usr/local/cpython-3.9/bin/python (3.9.0) good ['', '123', '', '', ''] /usr/local/cpython-3.10/bin/python (3.10.0a6) good ['', '123', '', '', ''] WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by jnr.posix.JavaLibCHelper (file:/usr/local/jython-2.7/jython.jar) to method sun.nio.ch.SelChImpl.getFD() WARNING: Please consider reporting this to the maintainers of jnr.posix.JavaLibCHelper WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release /usr/local/jython-2.7/bin/jython (2.7.0) good WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by jnr.posix.JavaLibCHelper (file:/usr/local/jython-2.7/jython.jar) to method sun.nio.ch.SelChImpl.getFD() WARNING: Please consider reporting this to the maintainers of jnr.posix.JavaLibCHelper WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release ['', '123', ''] /usr/local/pypy-5.3.1/bin/pypy (2.7.10) good ['', '123', ''] /usr/local/pypy-5.9.0/bin/pypy (2.7.13) good ['', '123', ''] /usr/local/pypy-5.10.0/bin/pypy (2.7.13) good ['', '123', ''] /usr/local/pypy-6.0.0/bin/pypy (2.7.13) good ['', '123', ''] /usr/local/pypy-7.0.0/bin/pypy (2.7.13) good ['', '123', ''] /usr/local/pypy-7.3.0/bin/pypy (2.7.13) good ['', '123', ''] /usr/local/pypy3-5.5.0/bin/pypy3 (3.3.5) good ['', '123', ''] /usr/local/pypy3-5.8.0-with-lzma-fixes/bin/pypy3 (3.5.3) good ['', '123', ''] /usr/local/pypy3-5.8.0-with-lzma-fixes/lib-python/3/re.py:203: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) /usr/local/pypy3-5.8.0/bin/pypy3 (3.5.3) good ['', '123', ''] /usr/local/pypy3-5.8.0/lib-python/3/re.py:203: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) /usr/local/pypy3-5.9.0/bin/pypy3 (3.5.3) good ['', '123', ''] /usr/local/pypy3-5.9.0/lib-python/3/re.py:203: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) /usr/local/pypy3-5.10.0/bin/pypy3 (3.5.3) good ['', '123', ''] /usr/local/pypy3-5.10.0/lib-python/3/re.py:203: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) /usr/local/pypy3-6.0.0/bin/pypy3 (3.5.3) good ['', '123', ''] /usr/local/pypy3-6.0.0/lib-python/3/re.py:203: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) /usr/local/pypy3-7.0.0/bin/pypy3 (3.5.3) good ['', '123', ''] /usr/local/pypy3-7.0.0/lib-python/3/re.py:203: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) /usr/local/pypy3-7.2.0/bin/pypy3 (3.6.9) good ['', '123', ''] /usr/local/pypy3-7.2.0/lib-python/3/re.py:212: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) /usr/local/pypy3-7.3.0/bin/pypy3 (3.6.9) good ['', '123', ''] /usr/local/pypy3-7.3.0/lib-python/3/re.py:212: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) /usr/local/pypy3-7.3.3/bin/pypy3 (3.7.9) good ['', '123', ''] /usr/local/pypy3-7.3.3/lib-python/3/re.py:215: FutureWarning: split() requires a non-empty pattern match. return _compile(pattern, flags).split(string, maxsplit) /usr/local/micropython-1.11/bin/micropython (3.4.0) good ['', '123', ''] /usr/local/micropython-1.12/bin/micropython (3.4.0) good ['', '123', ''] /usr/local/micropython-git-2017-06-16/bin/micropython (3.4.0) good ['', '123', ''] /usr/local/micropython-git-2018-06-06/bin/micropython (3.4.0) good ['', '123', ''] From zljubisic at gmail.com Fri Apr 23 17:31:40 2021 From: zljubisic at gmail.com (Zoran) Date: Fri, 23 Apr 2021 14:31:40 -0700 (PDT) Subject: async watch directory for new files Message-ID: Hi, I need to watch for new files in directory, and when it shows up, I should create async task with file's full path for it, and wait for new file. If anyone here used a library for such task, please share which one. Regards. From hjp-python at hjp.at Sat Apr 24 09:31:54 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sat, 24 Apr 2021 15:31:54 +0200 Subject: Simple question - end a raw string with a single backslash ? In-Reply-To: References: <20201018141316.GB15694@hjp.at> <191966cf-53ec-ac56-fe87-bce91c2f9e93@gmail.com> Message-ID: <20210424133154.GA26278@hjp.at> On 2020-10-19 06:24:18 -0000, Mladen Gogala via Python-list wrote: > On Mon, 19 Oct 2020 02:44:25 +0000, Stefan Ram wrote: > > Mladen Gogala writes: > >>In Perl, there are no classes. > > > > If there are no classes in Perl, then what does > > > > bless REF,CLASSNAME > > > > do? > > bless \$ref will make the given reference a reference to the class. And classes is Perl > are called "modules". However, Perl classes are not the classes in the real sense. There > is no inheritance. That's wrong. Perl classes have inheritance, and they always have had it since they were introduced in Perl 5.0 (in 1994). > You can have a similar thing in C: it's called "struct", it can do > similar things like Perl modules. Nope. C structs are data structures. Perl modules are primarily a way to structure code. > But C isn't object oriented. Inheritance is an essential > characteristic of object orientation. You can have that even in C. One of my first major C programs (back in the 1980s) was object-oriented (including inheritance). I didn't even know what "object oriented" meant back then, but the library we used for the GUI stuff used that style so it felt natural to extend it to "application level" objects. > There were attempts to turn Perl into OO language with Moose > (https://metacpan.org/pod/Moose) Moose just adds syntactic sugar. It may be easier to read (especially for people used to other OO languages) and save a bit of typing, but it doesn't add anything you couldn't do in plain Perl5. 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 gheskett at shentel.net Sat Apr 24 10:05:15 2021 From: gheskett at shentel.net (Gene Heskett) Date: Sat, 24 Apr 2021 10:05:15 -0400 Subject: async watch directory for new files In-Reply-To: References: Message-ID: <202104241005.15259.gheskett@shentel.net> On Friday 23 April 2021 17:31:40 Zoran wrote: > Hi, > > I need to watch for new files in directory, and when it shows up, I > should create async task with file's full path for it, and wait for > new file. > > If anyone here used a library for such task, please share which one. > > Regards. inotifywait contains several variations of a notifier, I use it rather heavly here to automate such goings on as my incoming e-mail. The variation I use most is launched by a bash script, when then waits for its return with the name of the new file, that bash script then takes an action determined by the name that was returned. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From gisle.vanem at gmail.com Sat Apr 24 10:23:09 2021 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Sat, 24 Apr 2021 16:23:09 +0200 Subject: "py.ini" question Message-ID: I have a question about the Python launcher; c:\Windows\py.exe and the py.ini file. I have both Python 3.6 (32-bit) and Python 3.8 (64-bit) installed. And I have a 'c:\Users\Gisle\AppData\Local\py.ini' with this only: [defaults] python=3.6 A copy of this is also in 'c:\Windows\py.ini'. So when I do a: py -3 -c "import sys; print(sys.version)" I would assume a "3.6..." would be printed. But no, py.exe chooses to run my newest Python 3.8: 3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)] Only when I do 'py -3.6 -c ...', I get what I'd expect. So is a 'py.ini' and the '[defaults]' simply ignored or is my syntax wrong? -- --gv From rshepard at appl-ecosys.com Sat Apr 24 10:24:35 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 24 Apr 2021 07:24:35 -0700 (PDT) Subject: Ad-hoc SQL query builder for Python3? Message-ID: My web searches are not finding what I need to include in an application I'm building: an ad-hoc sql query builder. End users will want to query their data for reports not included in the built-in queries. My searches find a windows-only tool that apparently costs developers for the version to include in their applications. I'm looking for a F/OSS tool and I'm sure these are available somewhere. Suggestions are needed. TIA, Rich From mats at wichmann.us Sat Apr 24 11:34:30 2021 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 24 Apr 2021 09:34:30 -0600 Subject: "py.ini" question In-Reply-To: References: Message-ID: <738f0cd1-2aa5-7541-5784-1524dea8e8b1@wichmann.us> On 4/24/21 8:23 AM, Gisle Vanem wrote: > I have a question about the Python launcher; > ? c:\Windows\py.exe and the py.ini file. > > I have both Python 3.6 (32-bit) and Python 3.8 (64-bit) > installed. And I have a 'c:\Users\Gisle\AppData\Local\py.ini' > with this only: > ? [defaults] > ? python=3.6 > > A copy of this is also in 'c:\Windows\py.ini'. > So when I do a: > ? py -3 -c "import sys; print(sys.version)" > > I would assume a "3.6..." would be printed. > But no, py.exe chooses to run my newest Python 3.8: > ? 3.8.9 (default, Apr 13 2021, 15:54:59)? [GCC 10.2.0 64 bit (AMD64)] > > Only when I do 'py -3.6 -c ...', I get what I'd expect. > > So is a 'py.ini' and the '[defaults]' simply ignored > or is my syntax wrong? > You could try this: "If an environment variable PYLAUNCH_DEBUG is set (to any value), the launcher will print diagnostic information to stderr (i.e. to the console). While this information manages to be simultaneously verbose and terse, it should allow you to see what versions of Python were located, why a particular version was chosen and the exact command-line used to execute the target Python." and see what it teaches you... From jpic at yourlabs.org Sat Apr 24 11:49:19 2021 From: jpic at yourlabs.org (J. Pic) Date: Sat, 24 Apr 2021 17:49:19 +0200 Subject: Ad-hoc SQL query builder for Python3? In-Reply-To: References: Message-ID: Maybe search or ask dba stackexchange for more, meanwhile, here's a popular one: https://github.com/dbeaver/dbeaver From rshepard at appl-ecosys.com Sat Apr 24 12:49:11 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 24 Apr 2021 09:49:11 -0700 (PDT) Subject: Ad-hoc SQL query builder for Python3? In-Reply-To: References: Message-ID: On Sat, 24 Apr 2021, J. Pic wrote: > Maybe search or ask dba stackexchange for more, meanwhile, here's a > popular one: https://github.com/dbeaver/dbeaver J., I use dbeaver-ce now and then as an admin tool. I didn't consider it as an included component in a desktop application. I'll look at it from that perspective. Thanks, Rich From PythonList at DancesWithMice.info Sat Apr 24 12:51:30 2021 From: PythonList at DancesWithMice.info (dn) Date: Sun, 25 Apr 2021 04:51:30 +1200 Subject: Ad-hoc SQL query builder for Python3? In-Reply-To: References: Message-ID: <7ecd6d89-1b9f-ea0f-1b93-ef78b4396fc4@DancesWithMice.info> On 25/04/2021 02.24, Rich Shepard wrote: > My web searches are not finding what I need to include in an application > I'm > building: an ad-hoc sql query builder. > > End users will want to query their data for reports not included in the > built-in queries. My searches find a windows-only tool that apparently > costs > developers for the version to include in their applications. I'm looking > for > a F/OSS tool and I'm sure these are available somewhere. > > Suggestions are needed. Which RDBMS? MySQL Workbench Oracle Application Builder(s) Sundry tools built on PHP - for varying definitions of F/LOSS and 'ad-hoc'! -- Regards, =dn From dieter at handshake.de Sat Apr 24 12:52:05 2021 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 24 Apr 2021 18:52:05 +0200 Subject: async watch directory for new files In-Reply-To: References: Message-ID: <24708.19637.90744.100631@ixdm.fritz.box> Zoran wrote at 2021-4-23 14:31 -0700: >I need to watch for new files in directory, and when it shows up, I should create async task with file's full path for it, and wait for new file. > >If anyone here used a library for such task, please share which one. The solution likely depends on the OS you are using. For Linux, `inotify` informs applications about file system changes. PyPI contains a binding for it -- with identical name. From barry at barrys-emacs.org Sat Apr 24 14:01:27 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Sat, 24 Apr 2021 19:01:27 +0100 Subject: "py.ini" question In-Reply-To: References: Message-ID: <9286A39C-9FB5-4BFF-9B41-AAE90934C88F@barrys-emacs.org> > On 24 Apr 2021, at 15:23, Gisle Vanem wrote: > > I have a question about the Python launcher; > c:\Windows\py.exe and the py.ini file. > > I have both Python 3.6 (32-bit) and Python 3.8 (64-bit) > installed. And I have a 'c:\Users\Gisle\AppData\Local\py.ini' > with this only: > [defaults] > python=3.6 > > A copy of this is also in 'c:\Windows\py.ini'. > So when I do a: > py -3 -c "import sys; print(sys.version)" > > I would assume a "3.6..." would be printed. > But no, py.exe chooses to run my newest Python 3.8: > 3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)] > > Only when I do 'py -3.6 -c ...', I get what I'd expect. > > So is a 'py.ini' and the '[defaults]' simply ignored > or is my syntax wrong? You can find out what py.exe is using for its config by running: py -0 The entry with an * at the end is the default. On windows 10 your personal py.ini is in %localappdata%\py.ini do you have one? type %localappdata%\py.ini If not you might want to create one that sets things up as you need them configured. Here is what I have on my windows 10: C:\Users\barry>py -0 Installed Pythons found by py Launcher for Windows -3.10-64 -3.10-32 -3.9-64 * -3.9-32 -3.8-64 -3.8-32 -3.7-64 -3.7-32 -3.6-64 -3.6-32 -3.5-64 -3.5-32 -3.4-64 -3.4-32 -2.7-64 -2.7-32 C:\Users\barry>type %localappdata%\py.ini [defaults] python=3.9-64 python3=3.9-64 C:\Users\barry>py Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. Barry > > -- > --gv > -- > https://mail.python.org/mailman/listinfo/python-list > From gisle.vanem at gmail.com Sat Apr 24 15:56:15 2021 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Sat, 24 Apr 2021 21:56:15 +0200 Subject: "py.ini" question In-Reply-To: <9286A39C-9FB5-4BFF-9B41-AAE90934C88F@barrys-emacs.org> References: <9286A39C-9FB5-4BFF-9B41-AAE90934C88F@barrys-emacs.org> Message-ID: Barry Scott wrote: >> A copy of this is also in 'c:\Windows\py.ini'. >> So when I do a: >> py -3 -c "import sys; print(sys.version)" >> >> I would assume a "3.6..." would be printed. >> But no, py.exe chooses to run my newest Python 3.8: >> 3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)] >> >> Only when I do 'py -3.6 -c ...', I get what I'd expect. >> >> So is a 'py.ini' and the '[defaults]' simply ignored >> or is my syntax wrong? > On windows 10 your personal py.ini is in %localappdata%\py.ini > do you have one? Yes, that's my 'c:\Users\Gisle\AppData\Local\py.ini' in my case. > C:\Users\barry>py -0 > Installed Pythons found by py Launcher for Windows > -3.10-64 > -3.10-32 > -3.9-64 * > -3.9-32 > -3.8-64 > -3.8-32 > -3.7-64 > -3.7-32 > -3.6-64 > -3.6-32 > -3.5-64 > -3.5-32 > -3.4-64 > -3.4-32 > -2.7-64 > -2.7-32 On that, I'm getting: Requested Python version (0) not installed Is that '-0' some 3.9+ feature? > C:\Users\barry>py > Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. With a 'py', I get: Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32 With 'py -3.6' or 'py 3.8' I get the expected. But with 'py -3': Python 3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)] on win32 Since I'm on a 64-bit Python, a 'py -3' totally seems to ignore 'py.ini', unless it says: [defaults] python3=3.6 python3=3.6-32 Strange as always. And yes, Mats Wichmann, I've tried a 'set PYLAUNCH_DEBUG=1'. No help. -- --gv From zljubisic at gmail.com Sat Apr 24 16:12:56 2021 From: zljubisic at gmail.com (Zoran) Date: Sat, 24 Apr 2021 13:12:56 -0700 (PDT) Subject: async watch directory for new files In-Reply-To: References: <24708.19637.90744.100631@ixdm.fritz.box> Message-ID: <498567c7-6042-4d78-a33c-76599251768cn@googlegroups.com> On Saturday, 24 April 2021 at 18:52:24 UTC+2, Dieter Maurer wrote: > Zoran wrote at 2021-4-23 14:31 -0700: > >I need to watch for new files in directory, and when it shows up, I should create async task with file's full path for it, and wait for new file. > > > >If anyone here used a library for such task, please share which one. > The solution likely depends on the OS you are using. > > For Linux, `inotify` informs applications about file system changes. > PyPI contains a binding for it -- with identical name. As I can see https://pypi.org/project/inotify/ is not asyncio frendly. Whatever I use, it should be asynchronous. Final OS is linux (Centos 7), but I am doing development on Windows 10 machine, so it would be nice if I have something that works on both. From rosuav at gmail.com Sat Apr 24 16:57:37 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 Apr 2021 06:57:37 +1000 Subject: "py.ini" question In-Reply-To: References: <9286A39C-9FB5-4BFF-9B41-AAE90934C88F@barrys-emacs.org> Message-ID: On Sun, Apr 25, 2021 at 5:57 AM Gisle Vanem wrote: > > With 'py -3.6' or 'py 3.8' I get the expected. > But with 'py -3': > Python 3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)] on win32 > I believe that's because you're asking for "the latest in the 3.x series". ChrisA From rosuav at gmail.com Sat Apr 24 16:59:04 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 25 Apr 2021 06:59:04 +1000 Subject: async watch directory for new files In-Reply-To: <498567c7-6042-4d78-a33c-76599251768cn@googlegroups.com> References: <24708.19637.90744.100631@ixdm.fritz.box> <498567c7-6042-4d78-a33c-76599251768cn@googlegroups.com> Message-ID: On Sun, Apr 25, 2021 at 6:16 AM Zoran wrote: > > On Saturday, 24 April 2021 at 18:52:24 UTC+2, Dieter Maurer wrote: > > Zoran wrote at 2021-4-23 14:31 -0700: > > >I need to watch for new files in directory, and when it shows up, I should create async task with file's full path for it, and wait for new file. > > > > > >If anyone here used a library for such task, please share which one. > > The solution likely depends on the OS you are using. > > > > For Linux, `inotify` informs applications about file system changes. > > PyPI contains a binding for it -- with identical name. > > As I can see https://pypi.org/project/inotify/ is not asyncio frendly. > Whatever I use, it should be asynchronous. > Final OS is linux (Centos 7), but I am doing development on Windows 10 machine, so it would be nice if I have something that works on both. Bear in mind that asyncio is NOT the only way to be asynchronous. So what you're asking for is, very specifically, an asyncio-compatible inotify. Turns out, there's an ainotify on PyPI that might be what you want. ChrisA From zljubisic at gmail.com Sun Apr 25 01:15:24 2021 From: zljubisic at gmail.com (Zoran) Date: Sat, 24 Apr 2021 22:15:24 -0700 (PDT) Subject: async watch directory for new files In-Reply-To: References: <24708.19637.90744.100631@ixdm.fritz.box> <498567c7-6042-4d78-a33c-76599251768cn@googlegroups.com> Message-ID: > Bear in mind that asyncio is NOT the only way to be asynchronous. So > what you're asking for is, very specifically, an asyncio-compatible > inotify. Turns out, there's an ainotify on PyPI that might be what you > want. Yes there is: https://github.com/rbarrois/aionotify https://asyncinotify.readthedocs.io/en/latest/ https://pypi.org/project/aionotify/ https://pypi.org/project/butter/ https://github.com/giannitedesco/minotaur https://pypi.org/project/watchgod/ ... There are many of them. I hoped that someone with experience here can suggest a library that he has been used on some project. From mats at wichmann.us Sun Apr 25 10:30:42 2021 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 25 Apr 2021 08:30:42 -0600 Subject: "py.ini" question In-Reply-To: References: <9286A39C-9FB5-4BFF-9B41-AAE90934C88F@barrys-emacs.org> Message-ID: On 4/24/21 2:57 PM, Chris Angelico wrote: > On Sun, Apr 25, 2021 at 5:57 AM Gisle Vanem wrote: >> >> With 'py -3.6' or 'py 3.8' I get the expected. >> But with 'py -3': >> Python 3.8.9 (default, Apr 13 2021, 15:54:59) [GCC 10.2.0 64 bit (AMD64)] on win32 >> > I believe that's because you're asking for "the latest in the 3.x series". unless differently described by the ini file, which is what the OP is trying to do. I just added a 3.10 alpha to my Windows setup (I don't do my programming there, so there hadn't been any need), and set up an ini file to leave 3.9 as the default and all works as expected - py -0, py, py -3, py -3.10 all given me the one I would expect to get based on that setup (-0 shows 3.9-64 starred, despite 3.10-64 being "the latest). Personally stumped why it's not working for Gisle. From zljubisic at gmail.com Sun Apr 25 14:50:43 2021 From: zljubisic at gmail.com (Zoran) Date: Sun, 25 Apr 2021 11:50:43 -0700 (PDT) Subject: async watch directory for new files In-Reply-To: References: Message-ID: > > > Implementations are usually just callback-based. (Apologies for the > generic link, I haven't needed this in Python yet: anyway, those are the > keywords.) :) before asking a question here I googled the subject a lot. Anyway, the simplest solution is this one: import asyncio import pathlib from watchgod import awatch, Change watch_dir = pathlib.Path(r'C:\Users\User\watch_folder') async def main(): async for changes in awatch(str(watch_dir)): while changes: change_type, path = changes.pop() if change_type == Change.added: print('processing:', path) loop = asyncio.get_event_loop() loop.run_until_complete(main()) watchgod library is quite young. I hope that there will be no suprises. From rosuav at gmail.com Sun Apr 25 14:59:22 2021 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Apr 2021 04:59:22 +1000 Subject: async watch directory for new files In-Reply-To: References: Message-ID: On Mon, Apr 26, 2021 at 4:56 AM Zoran wrote: > > > > > > > Implementations are usually just callback-based. (Apologies for the > > generic link, I haven't needed this in Python yet: anyway, those are the > > keywords.) > > :) before asking a question here I googled the subject a lot. We couldn't tell that from your question. ChrisA From Ralf_M at t-online.de Sun Apr 25 15:05:41 2021 From: Ralf_M at t-online.de (Ralf M.) Date: Sun, 25 Apr 2021 21:05:41 +0200 Subject: "py.ini" question In-Reply-To: References: <9286A39C-9FB5-4BFF-9B41-AAE90934C88F@barrys-emacs.org> Message-ID: <21e5e21b-3294-baa9-b08c-2d8400f2404d@t-online.de> Am 25.04.2021 um 16:30 schrieb Mats Wichmann: > > On 4/24/21 2:57 PM, Chris Angelico wrote: >> On Sun, Apr 25, 2021 at 5:57 AM Gisle Vanem >> wrote: >>> >>> With 'py -3.6' or 'py 3.8' I get the expected. >>> But with 'py -3': >>> ??? Python 3.8.9 (default, Apr 13 2021, 15:54:59)? [GCC 10.2.0 64 bit >>> (AMD64)] on win32 >>> >> I believe that's because you're asking for "the latest in the 3.x >> series". > > unless differently described by the ini file, which is what the OP is > trying to do. > > I just added a 3.10 alpha to my Windows setup (I don't do my programming > there, so there hadn't been any need), and set up an ini file to leave > 3.9 as the default and all works as expected - py -0, py, py -3, py > -3.10 all given me the one I would expect to get based on that setup (-0 > shows 3.9-64 starred, despite 3.10-64 being "the latest). > > Personally stumped why it's not working for Gisle. I think the problem / misunderstanding is that Gisle put in py.ini only [defaults] python=3.6 and expected this to make py -3 start 3.6. However py -3 looks for a key named 'python3' and, not finding it, uses default behaviour (ignoring the 'python' key), i.e. starts the most modern stable 3.x. The py.ini documentation is a bit hard to find in the help file and hard to understand as the interesting part talks about environment variables and shebang line commands, not py.ini settings and py.exe parameters. However, the behaviour is the same in both cases and the relevant example is: "If PY_PYTHON=3.1-32, the command python will use the 32-bit implementation of 3.1 whereas the command python3 will use the latest installed Python (PY_PYTHON was not considered at all as a major version was specified.)" I tried the (rather insane) py.ini [defaults] python=3.7 python2=3.8 python4=2.7 and it works as documented (py -3 shows default behaviour as there is no 'python3' in py.ini): C:\>py Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit(AMD64)] on win32 C:\>py -2 Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32 C:\>py -3 Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32 C:\>py -4 Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:19:08) [MSC v.1500 32 bit (Intel)] on win32 From alan.gauld at yahoo.co.uk Sat Apr 24 19:05:44 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 25 Apr 2021 00:05:44 +0100 Subject: Ad-hoc SQL query builder for Python3? In-Reply-To: References: Message-ID: On 24/04/2021 15:24, Rich Shepard wrote: > My web searches are not finding what I need to include in an application I'm > building: an ad-hoc sql query builder. > > End users will want to query their data for reports not included in the > built-in queries. I assume you understand the huge risks involved in such a tool. Letting users loose on their own data (and possibly other peoples) allows for huge potential damage/data loss etc. You can reduce the risk by finding ways to limit the access to read-only and tightly controlling which tables etc can be accessed. But many SQL builder tools don't do that and simply provide a way to create queries, including drop table, delete from etc. (Quite reasonably since they are usually aimed at DBAs rather than ordinary users) As a minimum ensure you have auto-backup processes in place every time the tool is opened. -- 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 alan.gauld at yahoo.co.uk Sun Apr 25 12:51:20 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 25 Apr 2021 17:51:20 +0100 Subject: "py.ini" question In-Reply-To: References: Message-ID: On 24/04/2021 15:23, Gisle Vanem wrote: > I have a question about the Python launcher; > c:\Windows\py.exe and the py.ini file. > > I have both Python 3.6 (32-bit) and Python 3.8 (64-bit) > installed. And I have a 'c:\Users\Gisle\AppData\Local\py.ini' > with this only: > [defaults] > python=3.6 I don't really use python on Windows so don't use this file. However, based on some of the other responses, what happens if you don't specify a version? ie. just type py -c "... And also what happens if you add an explicit python3 line as in Barry's example: [defaults] python=3.6 python3=3.6 As I say, pure speculation on my part. But if it helps... -- 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 zljubisic at gmail.com Sat Apr 24 16:13:50 2021 From: zljubisic at gmail.com (Zoran) Date: Sat, 24 Apr 2021 13:13:50 -0700 (PDT) Subject: async watch directory for new files In-Reply-To: References: <202104241005.15259.gheskett@shentel.net> Message-ID: <940ced1f-15db-4ed4-9d73-bc322699ad52n@googlegroups.com> > inotifywait contains several variations of a notifier, I use it rather > heavly here to automate such goings on as my incoming e-mail. Can you be more specific about inotifywait? Do you have an link or something? From zljubisic at gmail.com Sun Apr 25 15:44:16 2021 From: zljubisic at gmail.com (Zoran) Date: Sun, 25 Apr 2021 12:44:16 -0700 (PDT) Subject: async watch directory for new files In-Reply-To: References: Message-ID: Anyway, thanks for participating. From rshepard at appl-ecosys.com Sun Apr 25 15:51:11 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 25 Apr 2021 12:51:11 -0700 (PDT) Subject: Ad-hoc SQL query builder for Python3? In-Reply-To: References: Message-ID: On Sun, 25 Apr 2021, Alan Gauld via Python-list wrote: > I assume you understand the huge risks involved in such a tool. Letting > users loose on their own data (and possibly other peoples) allows for huge > potential damage/data loss etc. Alan, I disagree about the risk. Regardless of the form of the Select statement it does not delete any rows. Users will be able to specify attributes (columns) and instances (rows) but not delete or update any table. > You can reduce the risk by finding ways to limit the access to read-only > and tightly controlling which tables etc can be accessed. > But many SQL builder tools don't do that and simply provide a way to > create queries, including drop table, delete from etc. (Quite reasonably > since they are usually aimed at DBAs rather than ordinary users) That's if the inclusion of the tool allows it. Of course, if the user knows SQL they could do what they want directly on the database ignoring the application entirely. If they knew enough to do this they would be using a database rather than a spreadsheet in the first place. :-) Regards, Rich From hjp-python at hjp.at Sun Apr 25 17:01:18 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 25 Apr 2021 23:01:18 +0200 Subject: Ad-hoc SQL query builder for Python3? In-Reply-To: References: Message-ID: <20210425210118.GA32467@hjp.at> On 2021-04-25 00:05:44 +0100, Alan Gauld via Python-list wrote: > On 24/04/2021 15:24, Rich Shepard wrote: > > My web searches are not finding what I need to include in an application I'm > > building: an ad-hoc sql query builder. What should that sql query builder build the queries from? Or in other words what is the user supposed to input? > > End users will want to query their data for reports not included in the > > built-in queries. > > I assume you understand the huge risks involved in such a tool. > Letting users loose on their own data (and possibly other peoples) > allows for huge potential damage/data loss etc. > > You can reduce the risk by finding ways to limit the access > to read-only and tightly controlling which tables etc can be > accessed. Yes. > But many SQL builder tools don't do that and simply > provide a way to create queries, including drop table, The SQL builder tool isn't the right place to do this. Access privileges need to be managed in the database. 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 gheskett at shentel.net Sun Apr 25 17:28:31 2021 From: gheskett at shentel.net (Gene Heskett) Date: Sun, 25 Apr 2021 17:28:31 -0400 Subject: async watch directory for new files In-Reply-To: <940ced1f-15db-4ed4-9d73-bc322699ad52n@googlegroups.com> References: <202104241005.15259.gheskett@shentel.net> <940ced1f-15db-4ed4-9d73-bc322699ad52n@googlegroups.com> Message-ID: <202104251728.31096.gheskett@shentel.net> On Saturday 24 April 2021 16:13:50 Zoran wrote: > > inotifywait contains several variations of a notifier, I use it > > rather heavly here to automate such goings on as my incoming e-mail. > > Can you be more specific about inotifywait? > Do you have an link or something? No need for a link or URL, it should be available from the repo's of your distro. Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) If we desire respect for the law, we must first make the law respectable. - Louis D. Brandeis Genes Web page From rshepard at appl-ecosys.com Sun Apr 25 18:23:57 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 25 Apr 2021 15:23:57 -0700 (PDT) Subject: Ad-hoc SQL query builder for Python3? In-Reply-To: <20210425210118.GA32467@hjp.at> References: <20210425210118.GA32467@hjp.at> Message-ID: On Sun, 25 Apr 2021, Peter J. Holzer wrote: > What should that sql query builder build the queries from? Or in other > words what is the user supposed to input? Peter, >From the dialog box offering tables, columns, and rows from which a SELECT statement will be constructed. This is not a console application with a CLI; it has a GUI so there's no direct access to the backend db from within the application. Regards, Rich From PythonList at DancesWithMice.info Sun Apr 25 19:07:57 2021 From: PythonList at DancesWithMice.info (dn) Date: Mon, 26 Apr 2021 11:07:57 +1200 Subject: Ad-hoc SQL query builder for Python3? In-Reply-To: References: Message-ID: This message is not meant as a personal attack. The intention is to offer criticism of the way a vague question and its apparently non-specific replies, have produced less than satisfying 'results' - for everyone. A broad question can be good. I ask them too(!) 'Good', in the sense that its open-ness allows for a wide-range of replies. At the same time, the 'problem' with such a width, is that many options proffered will not suit the specific case. You possess sufficient understanding of 'the problem' to judge that point. Based (only) upon what was told in the posted-question, does anyone else? Thus, can such replies be considered "errors" or "mistakes", particularly when they are volunteered - and doubly-so when they do answer some version of an understanding, of some interpretation, of the vague wording, of the original question? Don't all problem-solving approaches, such as brain-storming, reject more ideas than they 'keep' - by definition? The difficulty with open-ended questions lacking 'anchors', such as 'which database', is that respondents must make assumptions, eg my earlier response. Obviously, it was useless to you. It was rendered a complete waste-of-time (both yours and mine), by the single word "PostgreSQL"! When could I realise that? When did you? Arguing later, about the appropriateness (or otherwise) of such assumptions, does not lead to a solution. Similarly, the adding of previously-unmentioned, but material constraints. How do they affect the respondent? Positively or negatively? What does the manner in which these are expressed do for your reputation? Note also the final exclamation mark of my first response, indicating the expectation that the provided list be heavily-subject to *your* interpretations of 'open' and 'ad-hoc' - and my ability to only make vague assumptions of what you really want... (it was NOT a question-mark!) All access to the DB (in this application user-access) should be controlled by a coordination of VIEWs and ACLs - and thus read-only to such an application. @Alan offered a serious warning about "risk". Meantime, I had presumed such as unnecessary. Which view was correct? Which unnecessary or unhelpful? What in the original question proves such? A competent DBA would be horrified by the assumption that a user won't ever access the DB merely because (s)he doesn't "knows SQL", ie "security by obscurity"! Further, the very lack of access and security controls is a good reason not to use SQLite; but the reply to such a suggestion might say that SQLite/single-user is only a reduced-environment dev/test-tool and thus irrelevant to the end-user environment. Both 'sides' of which are based upon yet another assumption! (NB not a question requesting, or requiring, a written answer!)) Similarly, you defined F/LOSS for me, even though I had indicated recognition of the $free aspect of the spec: "costs ... to include". As you probably realise, many others define the term differently, hence "for varying definitions" - allowing that some will accept Oracle on the grounds of offering a $free advantage, but also that the corporation certainly does not follow "open source" principles required/desired by many others. You have presumed to explain "ad hoc" to someone who trains the full-range of users/professionals in the use and management of Databases - and thus understands it (also) as a term which has a single 'dictionary definition' and yet has come to mean slightly different things to different people. Similarly, you appear to question warnings from a(nother) person who has sufficient experience to have quite literally 'forgotten more about DBs than you (appear to) have learned'. Were such statements made with assumptions about the respondent? How could you know about our knowledge/experience - one way or the other? How could anyone else, about you? Please notice how the first use of the word "spreadsheet", which can (now) be assumed to be material in your thinking, does not occur until the *fourth* exchange. Hence @Peter's response moving the conversation in a quite different direction! (and hopefully one that is more helpful to you) Is it possible that you have criticised responses, rather than allowing for the fact that your respondents have necessarily made assumptions? Would it be more reasonable to assess that any 'fault' is in the assumption, and that such assumption is directly related to the wide-open expression of the question? Have your replies appreciated the freely-given advice and motivation behind them, or have they (perhaps) had the effect of de-motivating the very people who seek to be helpful (to you)? Please note: The questions (above) are Socratic and rhetorical. No reply is requested or required. They ask you to think about maintaining constructive relationships. You certainly do not need to explain yourself to us (nor us to you). Per the opening comment, the idea behind this message is that we become better at helping each other... -- -- Regards, =dn From stephen_tucker at sil.org Mon Apr 26 02:38:34 2021 From: stephen_tucker at sil.org (Stephen Tucker) Date: Mon, 26 Apr 2021 07:38:34 +0100 Subject: Are there Python modules that allow a program to write to the screen? Message-ID: Hi, I have old software written in GWBASIC that I use to plot diagrams on the screen. In Windows 10, I have to resort to using the DOSBox emulator to run it. I would dearly like to re-write it in Python - ideally Python 2.7. What, if anything, is available? Stephen Tucker. From rosuav at gmail.com Mon Apr 26 03:38:59 2021 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 26 Apr 2021 17:38:59 +1000 Subject: Are there Python modules that allow a program to write to the screen? In-Reply-To: References: Message-ID: On Mon, Apr 26, 2021 at 4:40 PM Stephen Tucker wrote: > > Hi, > > I have old software written in GWBASIC that I use to plot diagrams on the > screen. > > In Windows 10, I have to resort to using the DOSBox emulator to run it. > "The screen" isn't really a viable target in a modern world, so it depends heavily on what you're trying to do. Plotting diagrams sounds like you might want matplotlib? > I would dearly like to re-write it in Python - ideally Python 2.7. > > What, if anything, is available? > Try Python 3 instead - don't go for something that's already reached the end of its life. There are quite a few libraries available, but my first guess would be matplotlib; and if you want something really fancy, manim can do incredible things. ChrisA From gisle.vanem at gmail.com Mon Apr 26 04:13:06 2021 From: gisle.vanem at gmail.com (Gisle Vanem) Date: Mon, 26 Apr 2021 10:13:06 +0200 Subject: "py.ini" question In-Reply-To: <21e5e21b-3294-baa9-b08c-2d8400f2404d@t-online.de> References: <9286A39C-9FB5-4BFF-9B41-AAE90934C88F@barrys-emacs.org> <21e5e21b-3294-baa9-b08c-2d8400f2404d@t-online.de> Message-ID: <0d5f606f-cbac-de2a-7d44-84088477fb59@gmail.com> Ralf M. wrote: > I think the problem / misunderstanding is that Gisle put in py.ini only > ?[defaults] > ?python=3.6 > > and expected this to make py -3 start 3.6. However py -3 looks for a key named 'python3' and, not finding it, uses > default behaviour (ignoring the 'python' key), i.e. starts the most modern stable 3.x. > > The py.ini documentation is a bit hard to find in the help file and hard to understand I totally agree with that. > I tried the (rather insane) py.ini > ?[defaults] > ?python=3.7 > ?python2=3.8 > ?python4=2.7 > and it works as documented (py -3 shows default behaviour as there is no 'python3' in py.ini): > > C:\>py > Python 3.7.4 (tags/v3.7.4:e09359112e, Jul? 8 2019, 20:34:20) [MSC v.1916 64 bit(AMD64)] on win32 > C:\>py -2 > Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32 > C:\>py -3 > Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32 > C:\>py -4 > Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:19:08) [MSC v.1500 32 bit (Intel)] on win32 Thank for confirming what I suspected. And as I wrote earlier: Since I'm on a 64-bit Python, a 'py -3' totally seems to ignore 'py.ini', unless it says: [defaults] python3=3.6 python3=3.6-32 ------- Except, I meant "Since I'm on a 64-bit Windows" and not "Since I'm on a 64-bit Python". From hjp-python at hjp.at Mon Apr 26 07:03:11 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Mon, 26 Apr 2021 13:03:11 +0200 Subject: Ad-hoc SQL query builder for Python3? In-Reply-To: References: <20210425210118.GA32467@hjp.at> Message-ID: <20210426110311.GA14952@hjp.at> On 2021-04-25 15:23:57 -0700, Rich Shepard wrote: > On Sun, 25 Apr 2021, Peter J. Holzer wrote: > > What should that sql query builder build the queries from? Or in other > > words what is the user supposed to input? > > Peter, > > From the dialog box offering tables, columns, and rows from which a SELECT > statement will be constructed. > > This is not a console application with a CLI; it has a GUI so there's no > direct access to the backend db from within the application. This is a non-sequitur. To present "tables, columns, and rows" the application needs access to the database whether the presentation is done via a graphical or text user interface. Unless these don't change, then they could be "embedded" in the application - but even then you would want to execute the the generated SQL queries at some point. It would have made sense if you had said that it is a web application, so there is no database connection from the uers's machine to the database server (only from the web server to the database server). Or that there is some middleware tier between the application and the database. But (to me at least) "an application with a GUI" does not imply either. 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 mal at europython.eu Mon Apr 26 08:32:54 2021 From: mal at europython.eu (M.-A. Lemburg) Date: Mon, 26 Apr 2021 14:32:54 +0200 Subject: EuroPython 2021: Call for Proposals Open Message-ID: We're happy to announce the EuroPython 2021 Call for Proposals (CFP) and are accepting proposals for talks, training sessions, workshops, panels, poster sessions, helpdesks and other interactive sessions at EuroPython 2021. * EuroPython 2021 Call for Proposals (CFP) * https://ep2021.europython.eu/events/call-for-proposals/ We will leave the CFP open from today until Sunday, May 9, 23:59:59 CEST. To submit a proposal, please log in to the site (or create an account first) and then proceed to the CFP page: Topics ------ We're looking for proposals on all aspects of Python from novice to advanced level, including but not limited to: applications, frameworks, Data Science, internals or topics which you're excited about, your experiences with Python and its ecosystem and creative or artistic things you've done with Python. EuroPython is a community conference and we're eager to hear about how you use Python in your professional and personal activities. Feedback has shown that attendees are interested in advanced topics, we would like to encourage more submissions with an advanced level scope for EuroPython 2021. Please also note that we have added back training and workshop submissions. We had to remove those last year due to lack of resources. Speaker Mentoring Program ------------------------- This year we are running a mentoring program to encourage more first time speakers to submit proposals, as well as provide training on delivering talks effectively. We are also looking for more mentors to help with the program. Please check the CFP page for details on the mentoring program. https://ep2021.europython.eu/events/call-for-proposals/#Speaker-Mentorship-Program Quick Summary ------------- EuroPython 2021 will be run online from July 26 - August 1: - Two workshop/training days (July 26 - 27) - Three conference days (July 28 - 30) - Two sprint days (July 31 - August 1) The sessions will be scheduled to ensure they are also accessible for those in the Asian and Americas time zones. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/europython-2021-call-for-proposals-open-cfp/ Tweet: https://twitter.com/europython/status/1386631947913400320 Enjoy, -- EuroPython 2021 Team https://www.europython-society.org/ From loris.bennett at fu-berlin.de Mon Apr 26 09:19:25 2021 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Mon, 26 Apr 2021 15:19:25 +0200 Subject: Problems deploying from poetry development environment Message-ID: <87o8e189pe.fsf@hornfels.zedat.fu-berlin.de> Hi, I am developing using poetry and deploying to a directory on an NFS server. The steps I have been using are 1. poetry build 2. poetry install 3. PYTHONUSERBASE=/my/nfs/dir pip3 install --user ~/git/funky_prog/dist/funky_prog-0.2.0-py3-none-any.whl --upgrade This worked. The programs got deployed and could be run by other users on the system. Now I notice the following problems: 1. The shebang in the deployed entry point script seems to have changed from the system python to the development venv. So where as one program has #!/usr/bin/python3 another, more recent one has #!/home/loris/.cache/pypoetry/virtualenvs/generate-publications-csv-tiuUP8_d-py3.6/bin/python3 This seems to have happened after a certain date. 2. Today Step 3 above failed in that the version printed by the deployed program stayed the same although a newer version had been installed. I deleted the program directory under 'site-packages' along with two 'dist-info' directories (which corresponded to the old version and the new version). Repeating Step 3 now installs just the program directory in 'site-packages', but not the 'dist-info' directory. The version number is not hard-coded in the program, but is only contained in the pyproject.toml and exported to METADATA on build. I have obviously somehow borked the environment. Does anyone have any idea how and what I can do to fix it? Cheers, Loris -- This signature is currently under construction. From rshepard at appl-ecosys.com Mon Apr 26 09:20:22 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Mon, 26 Apr 2021 06:20:22 -0700 (PDT) Subject: Ad-hoc SQL query builder for Python3? In-Reply-To: References: Message-ID: On Sat, 24 Apr 2021, Rich Shepard wrote: > My web searches are not finding what I need to include in an application I'm > building: an ad-hoc sql query builder. For those interested I've found a couple of possibilities: PyPika and SQLbuilder. I'll be looking deeply into them to learn their capabilities. My model is the query-by-example (QBE) used in Paradox for DOS in the 1980s and 1990s. Thanks for all your comments, Rich From loris.bennett at fu-berlin.de Mon Apr 26 09:49:18 2021 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Mon, 26 Apr 2021 15:49:18 +0200 Subject: Problems deploying from poetry development environment References: <87o8e189pe.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <87k0op88bl.fsf@hornfels.zedat.fu-berlin.de> "Loris Bennett" writes: > Hi, > > I am developing using poetry and deploying to a directory on an NFS > server. The steps I have been using are > > 1. poetry build > 2. poetry install > 3. PYTHONUSERBASE=/my/nfs/dir pip3 install --user ~/git/funky_prog/dist/funky_prog-0.2.0-py3-none-any.whl --upgrade > > This worked. The programs got deployed and could be run by other users > on the system. > > Now I notice the following problems: > > 1. The shebang in the deployed entry point script seems to have > changed from the system python to the development venv. So where > as one program has > > #!/usr/bin/python3 > > another, more recent one has > > #!/home/loris/.cache/pypoetry/virtualenvs/generate-publications-csv-tiuUP8_d-py3.6/bin/python3 > > This seems to have happened after a certain date. > > 2. Today Step 3 above failed in that the version printed by the > deployed program stayed the same although a newer version had been > installed. I deleted the program directory under 'site-packages' > along with two 'dist-info' directories (which corresponded to the > old version and the new version). Repeating Step 3 now installs > just the program directory in 'site-packages', but not the > 'dist-info' directory. > > The version number is not hard-coded in the program, but is only > contained in the pyproject.toml and exported to METADATA on build. > > I have obviously somehow borked the environment. Does anyone have any > idea how and what I can do to fix it? As often happens, writing down the problem for an ML posting helps clear my mind. Step 3 has to be carried out *outside* the virtual env used for the development. Not doing this leads to the issues above. Cheers, Loris -- This signature is currently under construction. From torriem at gmail.com Mon Apr 26 10:06:32 2021 From: torriem at gmail.com (Michael Torrie) Date: Mon, 26 Apr 2021 08:06:32 -0600 Subject: Are there Python modules that allow a program to write to the screen? In-Reply-To: References: Message-ID: <3a92586f-73f0-c45f-727e-01599b70a40c@gmail.com> On 4/26/21 12:38 AM, Stephen Tucker wrote: > Hi, > > I have old software written in GWBASIC that I use to plot diagrams on the > screen. > > In Windows 10, I have to resort to using the DOSBox emulator to run it. > > I would dearly like to re-write it in Python - ideally Python 2.7. > > What, if anything, is available? > > Stephen Tucker. > Probably this is off-topic for me to say on a Python list, but why not see if you can compile your GWBASIC program in FreeBASIC[1]. It supports all graphics commands and screen modes of yesterday and can do them in a window on modern operating systems. As for Python, you may find that something like SDL or PyGame provides primitives that are not far off of what you had in GWBASIC all those years ago. As ChrisA has said, Python 2.7 is *not* recommended for any new projects. [1] https://www.freebasic.net/ From mikehulluk at gmail.com Mon Apr 26 08:40:13 2021 From: mikehulluk at gmail.com (Michael Hull) Date: Mon, 26 Apr 2021 13:40:13 +0100 Subject: c-types Structure and equality with bytes/bytearray Message-ID: Hello everyone, I've been working with ctypes recently, and I've come across what seems to be some slightly confusing behaviour, when comparing ctype's Structure against `bytes` and `bytearray` objects import ctypes class Int(ctypes.Structure): _fields_ = [("first_16", ctypes.c_int8), ("second_16", ctypes.c_int8)] def serialise(self): return ctypes.string_at(ctypes.addressof(self), ctypes.sizeof(self)) i_obj= Int(first_16= 65, second_16=66) print(i_obj.first_16, i_obj.second_16) i_bytes = i_obj.serialise() print(list(i_bytes)) assert type(i_bytes) == bytes i_bytearray = bytearray(i_bytes) print("obj == bytes =>", i_obj==i_bytes) print("bytes == obj =>", i_bytes==i_obj) print("obj == bytearray =>", i_obj==i_bytearray) print("bytearray == obj =>", i_bytearray==i_obj) When I run this (Python 3.6, and Python2.7) , the final 4 print statements give the following: """ obj == bytes => False bytes == obj => False obj == bytearray => True bytearray == obj => True """ Is this a bit strange -- my understanding was that `bytes` and `bytearray` would normally be expected to work quite interchangeably with each other? It also means that: bytearray == obj => True bytes == bytearray => True bytes == obj => False If anyone has any experience in this area, and can let me know if I'm overlooking something silly, and guidance would be gratefully appreciated. Alternatively, I am happy to open up a bug-report if this looks like unexpected behaviour? Best wishes, Mike From grant.b.edwards at gmail.com Mon Apr 26 10:16:56 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 26 Apr 2021 14:16:56 -0000 (UTC) Subject: Are there Python modules that allow a program to write to the screen? References: Message-ID: On 2021-04-26, Stephen Tucker wrote: > I have old software written in GWBASIC that I use to plot diagrams on the > screen. Pygame is probably the closest thing to what you're describing. If you want to produce professional looking plots from data, then matplotlib or one of the Gnuplot wrappers (pyGnuplot, py-gnuplot, Gnuplot.py) are the most obvious choices. -- Grant From barry at barrys-emacs.org Mon Apr 26 13:48:28 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 26 Apr 2021 18:48:28 +0100 Subject: "py.ini" question In-Reply-To: References: <9286A39C-9FB5-4BFF-9B41-AAE90934C88F@barrys-emacs.org> Message-ID: <49DC9572-FA3F-43F8-9BD9-840501BB2285@barrys-emacs.org> > On 24 Apr 2021, at 20:56, Gisle Vanem wrote: > > On that, I'm getting: > Requested Python version (0) not installed > > Is that '-0' some 3.9+ feature? No its a lot older then 3.9 I cannot remember when -0 was first supported but I've been using -0 for a long long time. I using the explorer to find c:\windows\py.exe and checked its Properties. In the Details tar it says that the "Product version" is 3.10.0a5 I think that py.exe gets updated to the highest version. What does your py.exe show its version as? Also Are you sure that you are running c:\windows\py.exe? What happens if you try running c:\windows\py.exe -0? Barry From barry at barrys-emacs.org Mon Apr 26 13:53:45 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 26 Apr 2021 18:53:45 +0100 Subject: "py.ini" question In-Reply-To: <0d5f606f-cbac-de2a-7d44-84088477fb59@gmail.com> References: <9286A39C-9FB5-4BFF-9B41-AAE90934C88F@barrys-emacs.org> <21e5e21b-3294-baa9-b08c-2d8400f2404d@t-online.de> <0d5f606f-cbac-de2a-7d44-84088477fb59@gmail.com> Message-ID: <01A05E13-EA16-4F87-8FFB-F7F4DD854CCE@barrys-emacs.org> > On 26 Apr 2021, at 09:13, Gisle Vanem wrote: > > Thank for confirming what I suspected. And as I wrote earlier: > Since I'm on a 64-bit Python, a 'py -3' totally seems to ignore > 'py.ini', unless it says: > [defaults] > python3=3.6 > python3=3.6-32 You can prove that py.ini is ignored by using PYLAUNCH_DEBUG but I think its that you do not have the config in the py.ini that does what you want. As an example is here is the output I see: C:\Users\barry>set PYLAUNCH_DEBUG=1 C:\Users\barry>py.exe -3 launcher build: 32bit launcher executable: Console Using local configuration file 'C:\Users\barry\AppData\Local\py.ini' File 'C:\WINDOWS\py.ini' non-existent Called with command line: -3 locating Pythons in 64bit registry locate_pythons_for_key: C:\Python38.win64\python.exe is a 64bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python38.win32\python.exe is a 32bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python27.win64\python.exe is a 64bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python310.win64\python.exe is a 64bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python34.win64\python.exe is a 64bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python35.win64\python.exe is a 64bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python36.win64\python.exe is a 64bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python37.win64\python.exe is a 64bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. HKLM\SOFTWARE\Python\PythonCore\3.8\InstallPath: The system cannot find the file specified. locate_pythons_for_key: C:\Python39.win64\python.exe is a 64bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locating Pythons in native registry locate_pythons_for_key: C:\Python38.win64\python.exe: already found locate_pythons_for_key: C:\Python38.win64\python.exe: already found locate_pythons_for_key: C:\Python38.win64\python.exe: already found locate_pythons_for_key: C:\Python38.win64\python.exe: already found locate_pythons_for_key: C:\Python38.win32\python.exe: already found locate_pythons_for_key: C:\Python38.win32\python.exe: already found locate_pythons_for_key: C:\Python38.win32\python.exe: already found locate_pythons_for_key: C:\Python38.win32\python.exe: already found locate_pythons_for_key: C:\Python27.win32\python.exe is a 32bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python310.win32\python.exe is a 32bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python34.win32\python.exe is a 32bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python35.win32\python.exe is a 32bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python36.win32\python.exe is a 32bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python37.win32\python.exe is a 32bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: C:\Python39.win32\python.exe is a 32bit executable locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: : The system cannot find the path specified. locate_pythons_for_key: unable to open PythonCore key in HKLM found configured value 'python3=3.9-64' in C:\Users\barry\AppData\Local\py.ini search for Python version '3.9-64' found 'C:\Python39.win64\python.exe' run_child: about to run 'C:\Python39.win64\python.exe' Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> You can see in the output that it found my py.ini and use the python3=3.9-64 from it. Barry From barry at barrys-emacs.org Mon Apr 26 14:29:38 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 26 Apr 2021 19:29:38 +0100 Subject: async watch directory for new files In-Reply-To: <498567c7-6042-4d78-a33c-76599251768cn@googlegroups.com> References: <24708.19637.90744.100631@ixdm.fritz.box> <498567c7-6042-4d78-a33c-76599251768cn@googlegroups.com> Message-ID: <848351A6-009E-4CF0-BB61-4977D9E15AEC@barrys-emacs.org> > On 24 Apr 2021, at 21:12, Zoran wrote: > > As I can see https://pypi.org/project/inotify/ is not asyncio frendly. > Whatever I use, it should be asynchronous. > Final OS is linux (Centos 7), but I am doing development on Windows 10 machine, so it would be nice if I have something that works on both. In this case trying to develop the code on Windows will make your life very hard. Are you using Windows because you do not have easy access to Centos 7? If so why not run Centos 7 in a VM on your Windows machine as your dev environment? Barry From elasstiika at gmail.com Mon Apr 26 19:24:21 2021 From: elasstiika at gmail.com (elas tica) Date: Mon, 26 Apr 2021 16:24:21 -0700 (PDT) Subject: Not found in the documentation Message-ID: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> Python documentation doesn't seem to mention anywhere what is the str value of an int: is it right? the same for float, Fraction, complex, etc? Not worth to be documented? Perphaps str(42) returns "forty two" or "XLII" or "101010" ... From pbryan at anode.ca Mon Apr 26 19:43:46 2021 From: pbryan at anode.ca (Paul Bryan) Date: Mon, 26 Apr 2021 16:43:46 -0700 Subject: Not found in the documentation In-Reply-To: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> Message-ID: <8c974dcb717fef7a7a319d8ef708877eb8a38ec5.camel@anode.ca> From?https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy : > The string representations of the numeric classes, computed > by__repr__() and __str__(), have the following properties: > * They are valid numeric literals which, when passed to their > class constructor, produce an object having the value of the > original numeric. > * The representation is in base 10, when possible. > * Leading zeros, possibly excepting a single zero before a > decimal point, are not shown. > * Trailing zeros, possibly excepting a single zero after a > decimal point, are not shown. > * A sign is shown only when the number is negative. Paul On Mon, 2021-04-26 at 16:24 -0700, elas tica wrote: > > Python documentation doesn't seem to mention anywhere what is the str > value of an int: is it right?? the same for float, Fraction, complex, > etc? Not worth to be documented? Perphaps str(42) returns "forty two" > or "XLII" or "101010" ... From elasstiika at gmail.com Mon Apr 26 21:24:18 2021 From: elasstiika at gmail.com (elas tica) Date: Mon, 26 Apr 2021 18:24:18 -0700 (PDT) Subject: Not found in the documentation In-Reply-To: References: <8c974dcb717fef7a7a319d8ef708877eb8a38ec5.camel@anode.ca> <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> Message-ID: <08194446-d45a-41e8-8983-c816aad07b2dn@googlegroups.com> Le mardi 27 avril 2021 ? 01:44:04 UTC+2, Paul Bryan a ?crit?: > From https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy > : > Thanks for the reference. I was expecting to find this information in the Built-in Types section from the PSL documentation. The representation returned by str over a complex number is not stated. The same for fraction objects. All the docstrinds are meaningless, showing : __str__(self) str(self) (END) not very informative. From 2QdxY4RzWzUUiLuE at potatochowder.com Mon Apr 26 23:48:11 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Mon, 26 Apr 2021 20:48:11 -0700 Subject: Not found in the documentation In-Reply-To: <08194446-d45a-41e8-8983-c816aad07b2dn@googlegroups.com> References: <8c974dcb717fef7a7a319d8ef708877eb8a38ec5.camel@anode.ca> <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <08194446-d45a-41e8-8983-c816aad07b2dn@googlegroups.com> Message-ID: On 2021-04-26 at 18:24:18 -0700, elas tica wrote: > [...] I was expecting to find [a description of what str returns for > various types] in the Built-in Types section from the PSL > documentation. The representation returned by str over a complex > number is not stated. The same for fraction objects [...] Assuming that PSL is the Python Standard Library, https://docs.python.org/3/library/functions.html#func-str says: [...] str(object) returns object.__str__(), which is the ?informal? or nicely printable string representation of object [...] IMO, an exhaustive list of exactly what that means for every type, even the built in types, is unnecessary, and could create maintenance or compatibility issues. Is there a reason you need that information? What would you do with it if you had it? Completely speculatively on my part, would repr (https://docs.python.org/3/library/functions.html#repr) meet your need(s) better than str? From pbryan at anode.ca Tue Apr 27 00:23:15 2021 From: pbryan at anode.ca (Paul Bryan) Date: Mon, 26 Apr 2021 21:23:15 -0700 Subject: Not found in the documentation In-Reply-To: <08194446-d45a-41e8-8983-c816aad07b2dn@googlegroups.com> References: <8c974dcb717fef7a7a319d8ef708877eb8a38ec5.camel@anode.ca> <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <08194446-d45a-41e8-8983-c816aad07b2dn@googlegroups.com> Message-ID: <855e7240374b265d3ae70c560e047ab5ace45154.camel@anode.ca> I agree. I would be useful for it to be documented elsewhere, especially in docstrings. I wonder if this is/was a conscious decision to keep Python runtime smaller? Paul On Mon, 2021-04-26 at 18:24 -0700, elas tica wrote: > Le mardi 27 avril 2021 ? 01:44:04 UTC+2, Paul Bryan a ?crit?: > > From > > https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy > > ? > > : > > > > > Thanks for the reference. I was expecting to find this information in > the Built-in Types section from the PSL documentation. The > representation returned by str over a complex number is not stated. > The same for fraction objects. All the docstrinds are meaningless, > showing : > > __str__(self) > ??? str(self) > (END) > > not very informative. From boblatest at yahoo.com Tue Apr 27 02:30:10 2021 From: boblatest at yahoo.com (Robert Latest) Date: 27 Apr 2021 06:30:10 GMT Subject: Ad-hoc SQL query builder for Python3? References: Message-ID: Rich Shepard wrote: > For those interested I've found a couple of possibilities: PyPika and > SQLbuilder. I'll be looking deeply into them to learn their capabilities. In case nobody mentioned it before, don't forget to take a look at SQLAlchemy. The object-relational-mapper (ORM) creates a 1:1 mapping of Python objects to SQL table rows. -- robert From tjreedy at udel.edu Tue Apr 27 02:54:48 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 27 Apr 2021 02:54:48 -0400 Subject: Not found in the documentation In-Reply-To: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> Message-ID: On 4/26/2021 7:24 PM, elas tica wrote: > > Python documentation doesn't seem to mention anywhere what is the str value of an int: is it right? the same for float, Fraction, complex, etc? Not worth to be documented? Perphaps str(42) returns "forty two" or "XLII" or "101010" ... Python has this thing called interactive mode that makes it possible to discover answers even faster than looking in the docs (which can get out of date when things change, as they have for floats). str(12345) '12345' repr(12345) '12345' str(1+1*j) Traceback (most recent call last): File "", line 1, in if True: NameError: name 'j' is not defined str(1+1j) '(1+1j)' repr(1+1j) '(1+1j)' str(.9999999999999999999999999999999) '1.0' str(0xff34) '65332' -- Terry Jan Reedy From miked at dewhirst.com.au Tue Apr 27 03:46:04 2021 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Tue, 27 Apr 2021 17:46:04 +1000 Subject: Not found in the documentation In-Reply-To: <08194446-d45a-41e8-8983-c816aad07b2dn@googlegroups.com> References: <8c974dcb717fef7a7a319d8ef708877eb8a38ec5.camel@anode.ca> <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <08194446-d45a-41e8-8983-c816aad07b2dn@googlegroups.com> Message-ID: <21534bef-253e-1162-b14b-788925ef655f@dewhirst.com.au> On 27/04/2021 11:24 am, elas tica wrote: > Le mardi 27 avril 2021 ? 01:44:04 UTC+2, Paul Bryan a ?crit?: >> From https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy >> : >> > > Thanks for the reference. I was expecting to find this information in the Built-in Types section from the PSL documentation. The representation returned by str over a complex number is not stated. The same for fraction objects. All the docstrinds are meaningless, showing : Try ... >>> help(int) and any other built-in type > > __str__(self) > str(self) > (END) > > not very informative. -- Signed email is an absolute defence against phishing. This email has been signed with my private key. If you import my public key you can automatically decrypt my signature and be sure it came from me. Just ask and I'll send it to you. Your email software can handle signing. -------------- next part -------------- A non-text attachment was scrubbed... Name: OpenPGP_signature Type: application/pgp-signature Size: 495 bytes Desc: OpenPGP digital signature URL: From elasstiika at gmail.com Tue Apr 27 04:09:37 2021 From: elasstiika at gmail.com (elas tica) Date: Tue, 27 Apr 2021 01:09:37 -0700 (PDT) Subject: Not found in the documentation In-Reply-To: References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> Message-ID: <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> > Python has this thing called interactive mode that makes it possible to > discover answers even faster than looking in the docs To go further : Python has this thing called source code that makes it possible to discover answers even faster than looking in the docs From rosuav at gmail.com Tue Apr 27 04:18:40 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 Apr 2021 18:18:40 +1000 Subject: Not found in the documentation In-Reply-To: <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> Message-ID: On Tue, Apr 27, 2021 at 6:11 PM elas tica wrote: > > > > Python has this thing called interactive mode that makes it possible to > > discover answers even faster than looking in the docs > > To go further : > Python has this thing called source code that makes it possible to discover answers even faster than looking in the docs > Hmm, that's a bit of a trap. CPython has source code, but the Python language specification is not the CPython source code. There is definitely value in having certain behaviours documented, as it allows other Python implementations to know what's part of the language definition and what's an implementation detail of CPython. However, in this case, the general information in the docs is absolutely sufficient, and the basic principle that the repr should (where possible) be a valid literal should explain what's needed. ChrisA From elasstiika at gmail.com Tue Apr 27 07:45:20 2021 From: elasstiika at gmail.com (elas tica) Date: Tue, 27 Apr 2021 04:45:20 -0700 (PDT) Subject: Not found in the documentation In-Reply-To: References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> Message-ID: <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> > However, in this case, the general information in the docs is > absolutely sufficient, and the basic principle that the repr should > (where possible) be a valid literal should explain what's needed. This is a subjective statement. Recall: explicit is better implicit. Alas, many parts of the Python docs are written in a conversational style, full of implicit and fuzzy meanings. From rosuav at gmail.com Tue Apr 27 08:12:47 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 27 Apr 2021 22:12:47 +1000 Subject: Not found in the documentation In-Reply-To: <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> Message-ID: On Tue, Apr 27, 2021 at 9:51 PM elas tica wrote: > > > > However, in this case, the general information in the docs is > > absolutely sufficient, and the basic principle that the repr should > > (where possible) be a valid literal should explain what's needed. > > > This is a subjective statement. Recall: explicit is better implicit. Alas, many parts of the Python docs are written in a conversational style, full of implicit and fuzzy meanings. Is there an actual problem here, or are you just looking for something to pick a hole in? Are you asking if a hypothetical alternate Python implementation is allowed to have int(16) return "0x10" ? Common sense should be a thing. Use it. ChrisA From stestagg at gmail.com Tue Apr 27 08:14:43 2021 From: stestagg at gmail.com (Stestagg) Date: Tue, 27 Apr 2021 13:14:43 +0100 Subject: Not found in the documentation In-Reply-To: <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> Message-ID: On Tue, Apr 27, 2021 at 12:52 PM elas tica wrote: > > > However, in this case, the general information in the docs is > > absolutely sufficient, and the basic principle that the repr should > > (where possible) be a valid literal should explain what's needed. > > > This is a subjective statement. Recall: explicit is better implicit. Alas, > many parts of the Python docs are written in a conversational style, full > of implicit and fuzzy meanings. > The general rule of thumb that I use is: The *Library Reference* section of the Python docs contains info that cover 90% of use-cases and questions. (note built-in types are a section in the library reference, despite being built-in to the interpreter and not really part of the standard library, but this makes sense if you consider the library reference to be more 'friendly' documentation that tries to balance verbosity and covering every corner case explicitly against readability and approachability. This could be considered a 'conversational' style, but that style is generally considered a feature in the library reference section. The *Language Reference* is designed to be much more formally defined, and favors correctness and completeness over being easy to access by less technical readers. In this case, subjectively, I (and I think Chris agrees here) feel that python's behavior with calling str() is suitably non-surprising (especially when compared to almost every other modern language) that being described in the language reference seems entirely reasonable. There's an argument to be made that the description of the expected __str__() behavior of ints is not easy to find within section 3 of the language reference, and I imagine that a reasonable proposed change to this wording would be considered favourably. (python is accepting pull requests when they pass review :). Steve > -- > https://mail.python.org/mailman/listinfo/python-list > From rshepard at appl-ecosys.com Tue Apr 27 08:58:11 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 27 Apr 2021 05:58:11 -0700 (PDT) Subject: Ad-hoc SQL query builder for Python3? In-Reply-To: References: Message-ID: On Mon, 27 Apr 2021, Robert Latest via Python-list wrote: > In case nobody mentioned it before, don't forget to take a look at > SQLAlchemy. The object-relational-mapper (ORM) creates a 1:1 mapping of > Python objects to SQL table rows. Robert, Yes, I've known of SA for years. I want something that can be embedded in the application so the user doesn't need to install another dependentcy package and maintain it. Regards, Rich From elasstiika at gmail.com Tue Apr 27 09:42:38 2021 From: elasstiika at gmail.com (elas tica) Date: Tue, 27 Apr 2021 06:42:38 -0700 (PDT) Subject: Not found in the documentation In-Reply-To: References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> Message-ID: <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> > The *Language Reference* is designed to be much more formally defined, and > favors correctness and completeness over being easy to access by less > technical readers. > Not really my opinion. Language Reference (LR) style is still written in a conversational style, giving examples instead of definition. Typically consider this paragraph from the LR: ------------ begin excerpt ------- The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable. (The value of an immutable container object that contains a reference to a mutable object can change when the latter?s value is changed; however the container is still considered immutable, because the collection of objects it contains cannot be changed. So, immutability is not strictly the same as having an unchangeable value, it is more subtle.) An object?s mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable. ------------ end excerpt ------- The explanations inside the parenthensis is a by-the-way explanation, a mark of conversional style not to say tutorial style. Before parenthensis, we are talking about value of **any kind** of object and changeability in general. Now, the parenthensis is refering to immutable container as an illustration. The same for last sentence : "for instance ..." The problem is that the documentation doesn't define what the value of an object is, what means changing the value. The documentation doesn't explain **how** mutability is determined by the type of the object. By the way, how the docs define a container? Answer: "Some objects contain references to other objects; these are called containers". So to summarize : "a container contains", what a great definition! You said that LR is designed to be much more formally defined, and favors correctness and completeness. Good, so can you answer this question after reading the LR : what is a "token"? Did't find a definition. Is the "is not" operator a token? > There's an argument to be made that the description of the expected > __str__() behavior of ints is not easy to find within section 3 of the > language reference, and I imagine that a reasonable proposed change to this > wording would be considered favourably. (python is accepting pull requests > when they pass review :). > A drop in the ocean, sorry but Python docs are irrecoverable. From gazoo at workgroup.com Tue Apr 27 13:32:22 2021 From: gazoo at workgroup.com (Gazoo) Date: Tue, 27 Apr 2021 17:32:22 -0000 (UTC) Subject: Start Python programming Message-ID: I'd like to start learning Python programming. What sites/tutorials could you recommend for beginner, please. -- Gazoo From PythonList at DancesWithMice.info Tue Apr 27 14:21:42 2021 From: PythonList at DancesWithMice.info (dn) Date: Wed, 28 Apr 2021 06:21:42 +1200 Subject: Start Python programming In-Reply-To: References: Message-ID: On 28/04/2021 05.32, Gazoo wrote: > > > I'd like to start learning Python programming. What sites/tutorials > could you recommend for beginner, please. Start with the Python Tutorial (https://docs.python.org/3/tutorial/index.html), thereafter there are other 'docs' at the same site. There are plenty of books and both $free and paid courses available on-line, to suit many preferred ways of learning, and covering many specialised applications of the language. -- Regards, =dn From elasstiika at gmail.com Tue Apr 27 20:04:40 2021 From: elasstiika at gmail.com (elas tica) Date: Tue, 27 Apr 2021 17:04:40 -0700 (PDT) Subject: Not found in the documentation In-Reply-To: References: <8c974dcb717fef7a7a319d8ef708877eb8a38ec5.camel@anode.ca> <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> Message-ID: <72bb0743-968b-4298-83a8-00b1b01256dan@googlegroups.com> Le mardi 27 avril 2021 ? 01:44:04 UTC+2, Paul Bryan a ?crit?: > From https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy > : > > > The string representations of the numeric classes, computed > > by__repr__() and __str__(), have the following properties: > > * They are valid numeric literals which, when passed to their > > class constructor, produce an object having the value of the > > original numeric. > > * The representation is in base 10, when possible. I realize that these basic informations have been very recently added to the Language Reference document as they are missing from the 3.8.5 version (July 2020) as you can check here: https://docs.python.org/release/3.8.5/reference/datamodel.html#index-8 From abrantesasf at gmail.com Wed Apr 28 01:16:14 2021 From: abrantesasf at gmail.com (Abrantes Araujo Silva Filho) Date: Wed, 28 Apr 2021 05:16:14 GMT Subject: Start Python programming References: Message-ID: On Tue, 27 Apr 2021 17:32:22 +0000, Gazoo wrote: > I'd like to start learning Python programming. What sites/tutorials > could you recommend for beginner, please. Have you tried this book? https://greenteapress.com/wp/think-python-2e/ It is a good book, written by Allan B. Downey, which is available for free in HTML or PDF. If you wish, you can buy a copy on Amazon as well. - Abrantes From mal at europython.eu Wed Apr 28 03:55:08 2021 From: mal at europython.eu (M.-A. Lemburg) Date: Wed, 28 Apr 2021 09:55:08 +0200 Subject: EuroPython 2021: Speaker Mentorship Program Message-ID: <81512228-6a02-3898-dd52-b906e082555f@europython.eu> In the EuroPython community, diversity and inclusion are one of our core values. Therefore, we are launching a Speaker Mentorship Program in this year's edition. * EuroPython 2021 Speaker Mentorship Program * https://ep2021.europython.eu/events/call-for-proposals/ We know how tough it is to prepare for a talk, find & organize the right content around the topic and more so when it's the first time. So what could be better than getting guidance and support from within the community itself. By means of this program, we would like to bridge the gap between a developing and experienced speaker. Hence, we are looking for mentors and mentees to sign up. Please check our CFP page for full details: https://ep2021.europython.eu/events/call-for-proposals/ Applications are open until Friday, April 30, 2021. Quick Summary ------------- EuroPython 2021 will be run online from July 26 - August 1: - Two workshop/training days (July 26 - 27) - Three conference days (July 28 - 30) - Two sprint days (July 31 - August 1) The sessions will be scheduled to ensure they are also accessible for those in the Asian and Americas time zones. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/europython-2021-speaker-mentorship-program/ Tweet: https://twitter.com/europython/status/1387004298211602433 Enjoy, -- EuroPython 2021 Team https://www.europython-society.org/ From hjp-python at hjp.at Wed Apr 28 05:18:24 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 28 Apr 2021 11:18:24 +0200 Subject: Not found in the documentation In-Reply-To: <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> Message-ID: <20210428091824.GA4663@hjp.at> On 2021-04-27 06:42:38 -0700, elas tica wrote: > > The *Language Reference* is designed to be much more formally defined, and > > favors correctness and completeness over being easy to access by less > > technical readers. > > > > > Not really my opinion. Language Reference (LR) style is still written > in a conversational style, giving examples instead of definition. The style is certainly less formal that that of - for example - the C standard. However, every text written in a natural language is to some extent informal and open to interpretation. So the real question is: Is the text unambiguous enough so that the intended target audience can agree on the answer to any question? The fact that there exist several Python implementations seems to support that, although I don't know how compatible those actually are and the existence of a reference implementation certainly helps. Everything else is a matter of personal taste. > By the way, how the docs define a container? Answer: "Some objects > contain references to other objects; these are called containers". So > to summarize : "a container contains", what a great definition! That's why it's called a container. But it also says *what* an object must contain to be called a container. You could say that an int object contains an integer value and a str object contains a reference to a buffer containing the string - but those aren't references to other objects, so int and str are not containers. > You said that LR is designed to be much more formally defined, and > favors correctness and completeness. Good, so can you answer this > question after reading the LR : what is a "token"? Did't find a > definition. There is an indirect definition right at the start of chapter 3: "Input to the parser is a stream of tokens, generated by the lexical analyzer." So a token is what the unit of output of the lexer. This is the definition. The rest of the chapter defines the details. > Is the "is not" operator a token? Yes. See chapter 2.3.1. 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 rasigkoson at gmail.com Wed Apr 28 06:00:14 2021 From: rasigkoson at gmail.com (Rasig Kosonmontri) Date: Wed, 28 Apr 2021 17:00:14 +0700 Subject: cant use certain commands, leading to more problems Message-ID: Hi i was using python for a while and one day i decided to try out a module called "pyinstaller" i installed it with pip and try to run it as a cmdlet, still didnt work i then searched online for solutions and people tell me to try "python -m pyinstaller" to run it directly with python, still didnt work, i tried pip install it again but all requirements were already satisfied so i heard that the microsoft store's version of python tends to hide itself. and so i uninstalled it but when i typed in to a powershell it just directs me to the mircrosoft store's page i then disabled it from doing that and install python from python.org myself but for some weird reason this time it doesnt work at all, 'python' is somehow not recognized as a cmdlet, bash or command. this also happens with gitbash and cmd ive tried repairing python but still doesnt work if you guys have an idea or a solution to this please let me know or help me through Thanks From alan.gauld at yahoo.co.uk Wed Apr 28 08:49:15 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 28 Apr 2021 13:49:15 +0100 Subject: Start Python programming In-Reply-To: References: Message-ID: On 27/04/2021 18:32, Gazoo wrote: > I'd like to start learning Python programming. What sites/tutorials > could you recommend for beginner, please. There is a getting started page on the python web site with links to guide you to many listed suggestions - books, web tutorials, video courses etc. https://www.python.org/about/gettingstarted/ Which one suits you best depends on many factors both objective and subjective. -- 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 jorge.conforte at inpe.br Wed Apr 28 09:55:57 2021 From: jorge.conforte at inpe.br (Jorge Conforte) Date: Wed, 28 Apr 2021 10:55:57 -0300 Subject: Plot maps in 3D Message-ID: <3d142816-ba3c-d115-af45-741593d2db08@inpe.br> Hi, I would like know if it is posible to plot the south in north poles in 3D earth maps. I search in google and always all examples is for cylindric projection, like this: bm = Basemap(llcrnrlon=extent[0], llcrnrlat=extent[2], ???????????? urcrnrlon=extent[1], urcrnrlat=extent[3], ???????????? projection='cyl', resolution='l', fix_aspect=False, ax=ax) I try to use the spstere or npstere and I didn't have success. I would like know it is possible use these projections to plot 3D data. Thanks, Conrado From torriem at gmail.com Wed Apr 28 10:09:29 2021 From: torriem at gmail.com (Michael Torrie) Date: Wed, 28 Apr 2021 08:09:29 -0600 Subject: cant use certain commands, leading to more problems In-Reply-To: References: Message-ID: On 4/28/21 4:00 AM, Rasig Kosonmontri wrote: > so i heard that the microsoft store's version of python tends to hide > itself. and so i uninstalled it > but when i typed in to a powershell it just directs me to the > mircrosoft store's page > i then disabled it from doing that and install python from python.org > myself > but for some weird reason this time it doesnt work at all, 'python' is > somehow not recognized as a cmdlet, bash or command. this also happens with > gitbash and cmd If you installed Python from an installer from python.org, did you tell it to put itself into your system PATH? If not, try manually adding the bin folder where it installed to to your system path. As to gitbash, that's an issue with your PATH as well, probably. > ive tried repairing python but still doesnt work > if you guys have an idea or a solution to this please let me know or help > me through Definitely read through the installation documentation: https://docs.python.org/3/using/windows.html From elasstiika at gmail.com Wed Apr 28 11:16:19 2021 From: elasstiika at gmail.com (elas tica) Date: Wed, 28 Apr 2021 08:16:19 -0700 (PDT) Subject: Not found in the documentation In-Reply-To: References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> <20210428091824.GA4663@hjp.at> <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> Message-ID: Peter J. Holzer a ?crit?: > That's why it's called a container. But it also says *what* an object > must contain to be called a container. You could say that an int object > contains an integer value and a str object contains a reference to a > buffer containing the string - but those aren't references to other > objects, so int and str are not containers. This is not how I interpret the wording : a string is a container for containing a reference to the characters the string holds. Depends on what you mean by "reference" and "contain". With the definition given, I cannot decide if a string or a range object is a container or not. For instance, can we say that range(100) contains 42 ? PLR document *states* that tuples, lists, sets are containers but doesn't mention if a string is a container or not. Nevertheless, str has a __contains__ method so if a string is not a container what is the logic ? > > You said that LR is designed to be much more formally defined, and > > favors correctness and completeness. Good, so can you answer this > > question after reading the LR : what is a "token"? Did't find a > > definition. > There is an indirect definition right at the start of chapter 3: "Input > to the parser is a stream of tokens, generated by the lexical analyzer." > So a token is what the unit of output of the lexer. This is the > definition. The rest of the chapter defines the details. As you know, the devil is in the details ;) A bunch of properties doesn't make a definition. What do we need is a characteristic property (necessary and sufficient). > > Is the "is not" operator a token? > Yes. See chapter 2.3.1. > 2.3.1 is about keywords : https://docs.python.org/3/reference/lexical_analysis.html#keywords not tokens (keywords are tokens but this is not the problem here). >From 2.1.5 (Python 3.9 LR) ............... A line ending in a backslash cannot carry a comment. A backslash does not continue a comment. A backslash does not continue a token except for string literals (i.e., tokens other than string literals cannot be split across physical lines using a backslash). A backslash is illegal elsewhere on a line outside a string literal. ............... Giving the above, if "is not" were a token as you are explaining, the following code should be invalid syntax : # ------------ begin code ------------- 42 is\ not [42] # ------------ end code ------------- but this code compiles perfectly (there is a whitespace at the beginning of the second physical line). From rosuav at gmail.com Wed Apr 28 11:36:00 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Apr 2021 01:36:00 +1000 Subject: Not found in the documentation In-Reply-To: References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> <20210428091824.GA4663@hjp.at> <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> Message-ID: On Thu, Apr 29, 2021 at 1:21 AM elas tica wrote: > > Peter J. Holzer a ?crit : > > > That's why it's called a container. But it also says *what* an object > > must contain to be called a container. You could say that an int object > > contains an integer value and a str object contains a reference to a > > buffer containing the string - but those aren't references to other > > objects, so int and str are not containers. > > This is not how I interpret the wording : a string is a container for containing > a reference to the characters the string holds. Depends on what you mean > by "reference" and "contain". With the definition given, I cannot decide > if a string or a range object is a container or not. For instance, > can we say that range(100) contains 42 ? Not by that definition of container. There are two completely different concepts that you are conflating: the low level concept that some objects have references to other objects, and the high level concept that some objects support the "in" operator for containment checks. They are similar, in that many objects use "in" to check the exact same set that they refer to, but they are not the same (for instance, range(1, 10, 1000000) requires a reference to the "one million" integer, even though it is not actually part of the range). > PLR document *states* that tuples, lists, sets are containers but doesn't > mention if a string is a container or not. Nevertheless, str has a __contains__ > method so if a string is not a container what is the logic ? Same problem. A string would also return True if you ask if it contains any substring (for instance, "test" in "this is a test..." would be True), even though it doesn't show up if you iterate, and the string object most certainly doesn't have a reference to such a substring. > > > Is the "is not" operator a token? > > Yes. See chapter 2.3.1. > > > > 2.3.1 is about keywords : https://docs.python.org/3/reference/lexical_analysis.html#keywords > not tokens (keywords are tokens but this is not the problem here). > > From 2.1.5 (Python 3.9 LR) > > ............... > A line ending in a backslash cannot carry a comment. A backslash does not continue a comment. A backslash does > not continue a token except for string literals (i.e., tokens other than string literals cannot be split across physical lines > using a backslash). A backslash is illegal elsewhere on a line outside a string literal. > ............... > > Giving the above, if "is not" were a token as you are explaining, the following code should be invalid syntax : > > # ------------ begin code ------------- > > 42 is\ > not [42] > > # ------------ end code ------------- > > but this code compiles perfectly (there is a whitespace at the beginning of the second physical line). > In what sense of the word "token" are you asking? The parser? You can play around with the low-level tokenizer with the aptly-named tokenizer module. What are you actually trying to prove here? What problem are you solving? Or is this just nitpicking for the sake of it? If your goal is just to nitpick, please be up-front about it, so we can respond accordingly, with appropriate levels of fastidious precision. Also bear in mind: The language can be tokenized differently by different interpreters, so some of the precise details are not part of the language definition. CPython, for instance, is in process of completely rewriting its parser, and I'm not sure how much of that has affected the language definition yet. ChrisA From elasstiika at gmail.com Wed Apr 28 15:10:23 2021 From: elasstiika at gmail.com (elas tica) Date: Wed, 28 Apr 2021 12:10:23 -0700 (PDT) Subject: Not found in the documentation In-Reply-To: References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> <20210428091824.GA4663@hjp.at> <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> Message-ID: <0bc9f1ff-958e-4768-81d8-fc40be3b9790n@googlegroups.com> Le mercredi 28 avril 2021 ? 17:36:32 UTC+2, Chris Angelico a ?crit?: > > if a string or a range object is a container or not. For instance, > > can we say that range(100) contains 42 ? > Not by that definition of container. Which definition? ;) > some objects have references to other objects, and the high level > concept that some objects support the "in" operator for containment > checks. They are similar, in that many objects use "in" to check the > exact same set that they refer to, but they are not the same (for > instance, range(1, 10, 1000000) requires a reference to the "one > million" integer, even though it is not actually part of the range). The problem with range is different because we all know that a range object doesn't hold (= contain) the int's (except the endpoints and the step) we can iterate on, instead a range object computes on the fly the int's it holds. On the contrary, the string "2021" holds the digits, even "2021"*10**6 does. But this discussion is undecidable since the Python Language Reference doesn't provide a decent definition of a container. > What are you actually trying to prove here? What > problem are you solving? Or is this just nitpicking for the sake of > it? I was only looking for basic definitions, unfortunately the official docs are not able to provide : - what is the str value of an int? (we have to wait until Python 3.8.6 docs to get the response) - what is a container ? what does mean "contains references" ? is a string a container or not and where the docs explains the answer? - what is exactly a token? are "is not" or "not in " tokens? > the language definition. CPython, for instance, is in process of > completely rewriting its parser, and what about rewriting and *redesigning* the docs? Is there even a discussion about this? Nobody complains? From rosuav at gmail.com Wed Apr 28 17:11:09 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Apr 2021 07:11:09 +1000 Subject: Not found in the documentation In-Reply-To: <0bc9f1ff-958e-4768-81d8-fc40be3b9790n@googlegroups.com> References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> <20210428091824.GA4663@hjp.at> <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> <0bc9f1ff-958e-4768-81d8-fc40be3b9790n@googlegroups.com> Message-ID: On Thu, Apr 29, 2021 at 5:16 AM elas tica wrote: > > > Le mercredi 28 avril 2021 ? 17:36:32 UTC+2, Chris Angelico a ?crit : > > > > if a string or a range object is a container or not. For instance, > > > can we say that range(100) contains 42 ? > > Not by that definition of container. > > Which definition? ;) The one you were referring to. The one that was in the quoted text. The one that this subthread is about. Are you deliberately being obtuse? > > some objects have references to other objects, and the high level > > concept that some objects support the "in" operator for containment > > checks. They are similar, in that many objects use "in" to check the > > exact same set that they refer to, but they are not the same (for > > instance, range(1, 10, 1000000) requires a reference to the "one > > million" integer, even though it is not actually part of the range). > > The problem with range is different because we all know that a range object > doesn't hold (= contain) the int's (except the endpoints and the step) > we can iterate on, instead a range object computes on the fly the int's it holds. > On the contrary, the string "2021" holds the digits, even "2021"*10**6 does. And by the definition you quoted - that some objects contain references to other objects - the only containment is a range's endpoints. > But this discussion is undecidable since the Python Language Reference > doesn't provide a decent definition of a container. And yet, the definition you're complaining about is easily able to answer these exact questions. > > What are you actually trying to prove here? What > > problem are you solving? Or is this just nitpicking for the sake of > > it? > > I was only looking for basic definitions, unfortunately the official docs are not able to provide : > > - what is the str value of an int? (we have to wait until Python 3.8.6 docs to get the response) Before that, people had to use common sense, now there's a documented answer. I'm not seeing a huge problem, but to the extent that it was a problem, it has been solved. > - what is a container ? what does mean "contains references" ? is a string a container or not and where the docs explains the answer? Are you able to put an object reference inside a string? If not, it is not a container. Is a string object able to keep other objects alive by retaining references to them? No. It's right in the piece that you quoted: some objects contain references to *other objects*. > - what is exactly a token? are "is not" or "not in " tokens? I'm not sure, because it depends on the parser, and different language implementations can use different parsers. To what extent does it make a difference? Where in the docs does something refer to "token" in a way that needs to disambiguate this? > > the language definition. CPython, for instance, is in process of > > completely rewriting its parser, > > > and what about rewriting and *redesigning* the docs? Is there even a discussion about this? Nobody complains? > Ahhhh, now I get it. You're one of those people who hates on every change that happens, because some other change didn't happen. Good. Go post on Twitter, you'll fit in just fine. ChrisA From tjreedy at udel.edu Wed Apr 28 10:18:23 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 28 Apr 2021 10:18:23 -0400 Subject: cant use certain commands, leading to more problems In-Reply-To: References: Message-ID: On 4/28/2021 10:09 AM, Michael Torrie wrote: > On 4/28/21 4:00 AM, Rasig Kosonmontri wrote: >> so i heard that the microsoft store's version of python tends to hide >> itself. and so i uninstalled it >> but when i typed in to a powershell it just directs me to the >> mircrosoft store's page >> i then disabled it from doing that and install python from python.org >> myself >> but for some weird reason this time it doesnt work at all, 'python' is >> somehow not recognized as a cmdlet, bash or command. this also happens with >> gitbash and cmd > > If you installed Python from an installer from python.org, did you tell > it to put itself into your system PATH? If not, try manually adding the > bin folder where it installed to to your system path. Or check the option to install the py launcher and use that. No need to fuss with PATH. >py # run interactive python >py filename.py # run python with that file >py -m module # run module as a command -- Terry Jan Reedy From elasstiika at gmail.com Thu Apr 29 02:54:43 2021 From: elasstiika at gmail.com (elas tica) Date: Wed, 28 Apr 2021 23:54:43 -0700 (PDT) Subject: Not found in the documentation In-Reply-To: References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> <20210428091824.GA4663@hjp.at> <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> Message-ID: Le mercredi 28 avril 2021 ? 17:36:32 UTC+2, Chris Angelico a ?crit?: > In what sense of the word "token" are you asking? The parser? You can > play around with the low-level tokenizer with the aptly-named > tokenizer module. It was a good suggestion, and the PLR doesn't mention the tokeniser module. It should, this goes very well with the conversional style it has. # -------------- from tokenize import tokenize from io import BytesIO s="""42 not\ in [42]""" g = tokenize(BytesIO(s.encode('utf-8')).readline) print(*(g), sep='\n') # -------------- outputting: ...................................... TokenInfo(type=57 (ENCODING), string='utf-8', start=(0, 0), end=(0, 0), line='') TokenInfo(type=2 (NUMBER), string='42', start=(1, 0), end=(1, 2), line='42 not in [42]') TokenInfo(type=1 (NAME), string='not', start=(1, 3), end=(1, 6), line='42 not in [42]') TokenInfo(type=1 (NAME), string='in', start=(1, 7), end=(1, 9), line='42 not in [42]') TokenInfo(type=53 (OP), string='[', start=(1, 10), end=(1, 11), line='42 not in [42]') TokenInfo(type=2 (NUMBER), string='42', start=(1, 11), end=(1, 13), line='42 not in [42]') TokenInfo(type=53 (OP), string=']', start=(1, 13), end=(1, 14), line='42 not in [42]') TokenInfo(type=4 (NEWLINE), string='', start=(1, 14), end=(1, 15), line='') TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='') ...................................... So "not in" is not a token and the docs are wrong when they say: ...................................... using a backslash). A backslash is illegal elsewhere on a line outside a string literal. ...................................... From rosuav at gmail.com Thu Apr 29 03:22:45 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 29 Apr 2021 17:22:45 +1000 Subject: Not found in the documentation In-Reply-To: References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> <20210428091824.GA4663@hjp.at> <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> Message-ID: On Thu, Apr 29, 2021 at 4:56 PM elas tica wrote: > > Le mercredi 28 avril 2021 ? 17:36:32 UTC+2, Chris Angelico a ?crit : > > > In what sense of the word "token" are you asking? The parser? You can > > play around with the low-level tokenizer with the aptly-named > > tokenizer module. > > It was a good suggestion, and the PLR doesn't mention the tokeniser module. It should, this goes very well with the conversional style it has. > > > > # -------------- > from tokenize import tokenize > from io import BytesIO > > s="""42 not\ > in [42]""" > g = tokenize(BytesIO(s.encode('utf-8')).readline) > print(*(g), sep='\n') > # -------------- > > outputting: > > > ...................................... > TokenInfo(type=57 (ENCODING), string='utf-8', start=(0, 0), end=(0, 0), line='') > TokenInfo(type=2 (NUMBER), string='42', start=(1, 0), end=(1, 2), line='42 not in [42]') > TokenInfo(type=1 (NAME), string='not', start=(1, 3), end=(1, 6), line='42 not in [42]') > TokenInfo(type=1 (NAME), string='in', start=(1, 7), end=(1, 9), line='42 not in [42]') > TokenInfo(type=53 (OP), string='[', start=(1, 10), end=(1, 11), line='42 not in [42]') > TokenInfo(type=2 (NUMBER), string='42', start=(1, 11), end=(1, 13), line='42 not in [42]') > TokenInfo(type=53 (OP), string=']', start=(1, 13), end=(1, 14), line='42 not in [42]') > TokenInfo(type=4 (NEWLINE), string='', start=(1, 14), end=(1, 15), line='') > TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='') > ...................................... > > > So "not in" is not a token and the docs are wrong when they say: > > ...................................... > using a backslash). A backslash is illegal elsewhere on a line outside a string literal. > ...................................... > Are they really? Need more context here. The backslash escapes the newline, and then you have an additional space character after that, so it still ends the word. What's the bug here? ChrisA From m at funkyhat.org Thu Apr 29 13:36:55 2021 From: m at funkyhat.org (Matt Wheeler) Date: Thu, 29 Apr 2021 17:36:55 +0000 (UTC) Subject: Not found in the documentation In-Reply-To: References: <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> <20210428091824.GA4663@hjp.at> <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> Message-ID: On Wed, 28 Apr 2021 at 22:18, Dennis Lee Bieber wrote: > The old range() returned a list, and said list could (in your example) > contain 42. The current range() (equivalent to former xrange() ) is not a > container as retrieving values consumes them from the range. A nitpick -- retrieving values from a range doesn't consume them: ``` >>> r = range(10) >>> r range(0, 10) >>> list(r) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(r) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> r[0] 0 >>> r[3] 3 >>> list(r) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ``` range objects are iterables, not iterators. We can see the consuming behaviour I think you are referring to by calling iter(): ``` >>> i = iter(r) >>> next(i) 0 >>> list(i) [1, 2, 3, 4, 5, 6, 7, 8, 9] ``` -- Matt Wheeler http://funkyh.at From eryksun at gmail.com Thu Apr 29 17:56:14 2021 From: eryksun at gmail.com (Eryk Sun) Date: Thu, 29 Apr 2021 16:56:14 -0500 Subject: c-types Structure and equality with bytes/bytearray In-Reply-To: References: Message-ID: On 4/26/21, Michael Hull wrote: > > my understanding was that `bytes` and `bytearray` would normally > be expected to work quite interchangeably with each other? bytearray.__eq__() is more flexible: >>> i = Int16(first=65, second=66) >>> bytearray(i).__eq__(i) True >>> i.__eq__(bytearray(i)) NotImplemented >>> i.__eq__(bytes(i)) NotImplemented >>> bytes(i).__eq__(i) NotImplemented When in doubt, read the source code. In bytearray_richcompare() in Objects/bytearrayobject.c, the comparison begins by using the buffer protocol to get comparable byte strings. ctypes data types support the buffer protocol, so this works well. On the other hand, bytes_richcompare() in Objects/bytesobject.c does not use the buffer protocol but instead requires the other object to be a bytes object. In Python 3.3+, you can force the comparison to use the buffer protocol via memoryview(). For example: >>> memoryview(i).cast('B') == bytes(i) True >>> memoryview(i).cast('B') == bytearray(i) True The cast() to "B" (unsigned char) is required because views of ctypes data objects include their format: >>> memoryview(i).format 'T{>> memoryview(i).cast('B').format 'B' From sdoherty82 at gmail.com Thu Apr 29 20:59:06 2021 From: sdoherty82 at gmail.com (Sian Doherty) Date: Fri, 30 Apr 2021 10:59:06 +1000 Subject: uninstall Message-ID: <608b5659.1c69fb81.f933d.3bb2@mx.google.com> I?m trying to uninstall Python 3.8.5 on Windows 10 Pro 20H2 as I had multiple environments and as a result corrupted them. When I uninstall from control panel, it takes less than a second and says it uninstalled successfully but I can still access python through the command prompt by typing python. Is there a different way to uninstall that isn?t through the control panel? I would have thought I would do that and then clean out the registry separately and the %localappdata%\pip folder. Any thoughts? Thanks in advance Sian Doherty Sent from Mail for Windows 10 From auriocus at gmx.de Fri Apr 30 01:48:31 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 30 Apr 2021 07:48:31 +0200 Subject: Not found in the documentation In-Reply-To: References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> <20210428091824.GA4663@hjp.at> <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> Message-ID: Am 29.04.21 um 08:54 schrieb elas tica: > Le mercredi 28 avril 2021 ? 17:36:32 UTC+2, Chris Angelico a ?crit?: > >> In what sense of the word "token" are you asking? The parser? You can >> play around with the low-level tokenizer with the aptly-named >> tokenizer module. > > It was a good suggestion, and the PLR doesn't mention the tokeniser module. It should, this goes very well with the conversional style it has. > > > > # -------------- > from tokenize import tokenize > from io import BytesIO > > s="""42 not\ > in [42]""" > g = tokenize(BytesIO(s.encode('utf-8')).readline) > print(*(g), sep='\n') > # -------------- > > the docs are wrong when they say: > > ...................................... > using a backslash). A backslash is illegal elsewhere on a line outside a string literal. > ...................................... > You're not passing a backslash. Try print(s). It would be different with a raw string s=r"""42 not\ in [42]""" Christian From elasstiika at gmail.com Fri Apr 30 05:24:46 2021 From: elasstiika at gmail.com (elas tica) Date: Fri, 30 Apr 2021 02:24:46 -0700 (PDT) Subject: Not found in the documentation In-Reply-To: References: <96cd9078-89b0-45f7-a7fc-51e2e0878813n@googlegroups.com> <5c8c4b58-00f5-4b0e-a703-c656075a5532n@googlegroups.com> <80e00ec2-18cc-4dbf-a40f-4604063d0e6dn@googlegroups.com> <20210428091824.GA4663@hjp.at> <23ec934a-3a21-4ef2-81d4-9a05276a72adn@googlegroups.com> Message-ID: > > the docs are wrong when they say: > > > > ...................................... > > using a backslash). A backslash is illegal elsewhere on a line outside a string literal. > > ...................................... > > > You're not passing a backslash. Try print(s). > It would be different with a raw string > > s=r"""42 not\ > in [42]""" > Good catch Christian. Here the complete corrected code: # -------------- from tokenize import tokenize from io import BytesIO s = r"""42 not\ in [42]""" g = tokenize(BytesIO(s.encode('utf-8')).readline) print(*(g), sep='\n') # -------------- outputting now: ...................................... TokenInfo(type=57 (ENCODING), string='utf-8', start=(0, 0), end=(0, 0), line='') TokenInfo(type=2 (NUMBER), string='42', start=(1, 0), end=(1, 2), line='42 not in [42]') TokenInfo(type=1 (NAME), string='not', start=(1, 3), end=(1, 6), line='42 not in [42]') TokenInfo(type=1 (NAME), string='in', start=(1, 7), end=(1, 9), line='42 not in [42]') TokenInfo(type=53 (OP), string='[', start=(1, 10), end=(1, 11), line='42 not in [42]') TokenInfo(type=2 (NUMBER), string='42', start=(1, 11), end=(1, 13), line='42 not in [42]') TokenInfo(type=53 (OP), string=']', start=(1, 13), end=(1, 14), line='42 not in [42]') TokenInfo(type=4 (NEWLINE), string='', start=(1, 14), end=(1, 15), line='') TokenInfo(type=0 (ENDMARKER), string='', start=(2, 0), end=(2, 0), line='') ...................................... but this doesn't seem to change the conclusion. From qberz2005 at gmail.com Fri Apr 30 14:55:55 2021 From: qberz2005 at gmail.com (Quentin Bock) Date: Fri, 30 Apr 2021 14:55:55 -0400 Subject: text displays on screen only when I click to exit the program Message-ID: code with comments for context: #Create a text based game where the user must find 3 items before completing a level #imports and variables for game import pygame from pygame import mixer running = True #initializes pygame pygame.init() #creates the pygame window screen = pygame.display.set_mode((1200, 800)) #Title and Icon of window pygame.display.set_caption("3.02 Project") icon = pygame.image.load('3.02 icon.png') pygame.display.set_icon(icon) #setting up font pygame.font.init() font = pygame.font.Font('C:\Windows\Fonts\OCRAEXT.ttf', 16) font_x = 10 font_y = 40 items_picked_up = 0 items_left = 3 #functions to be called later in program def display_instruction(x, y): instructions = font.render("Each level contains 3 items you must pick up in each room." "When you have picked up 3 items, you will advance to the next room, there are 3 rooms.", True, (255, 255, 255)) screen.blit(instructions, (10, 40)) def main(): global running #Game Loop while running: #sets screen color to black screen.fill((0, 0, 0)) #checks if the user quits or exits the window for event in pygame.event.get(): if event.type == pygame.QUIT: running = False display_instruction(font_x, font_y) pygame.display.update() main() please excuse the def main() thing, this doesn't follow a tutorial this is all on my own, and I don't know why the text displays when I close the python window. I appreciate all help :) Virus-free. www.avast.com <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> From mirkok.lists at googlemail.com Fri Apr 30 15:11:42 2021 From: mirkok.lists at googlemail.com (Mirko) Date: Fri, 30 Apr 2021 21:11:42 +0200 Subject: text displays on screen only when I click to exit the program In-Reply-To: References: Message-ID: <608C566E.7000308@googlemail.com> Am 30.04.2021 um 20:55 schrieb Quentin Bock: > code with comments for context: > > #Create a text based game where the user must find 3 items before > completing a level > #imports and variables for game > import pygame > from pygame import mixer > running = True > #initializes pygame > pygame.init() > > #creates the pygame window > screen = pygame.display.set_mode((1200, 800)) > > #Title and Icon of window > pygame.display.set_caption("3.02 Project") > icon = pygame.image.load('3.02 icon.png') > pygame.display.set_icon(icon) > > #setting up font > pygame.font.init() > font = pygame.font.Font('C:\Windows\Fonts\OCRAEXT.ttf', 16) > font_x = 10 > font_y = 40 > items_picked_up = 0 > items_left = 3 > > #functions to be called later in program > def display_instruction(x, y): > instructions = font.render("Each level contains 3 items you must pick > up in each room." > "When you have picked up 3 items, you will > advance to the next room, there are 3 rooms.", True, (255, 255, 255)) > screen.blit(instructions, (10, 40)) > > def main(): > global running > > #Game Loop > while running: > #sets screen color to black > screen.fill((0, 0, 0)) > > #checks if the user quits or exits the window > for event in pygame.event.get(): > if event.type == pygame.QUIT: > running = False > > display_instruction(font_x, font_y) > pygame.display.update() > > > main() > > > > please excuse the def main() thing, this doesn't follow a tutorial this is > all on my own, and I don't know why the text displays when I close the > python window. > I appreciate all help :) Because you are calling display_instruction() and pygame.display.update() outside of the game loop. Try to indent those two lines one level more. From rustbuckett at pm.me Fri Apr 30 22:22:33 2021 From: rustbuckett at pm.me (Russell) Date: Sat, 1 May 2021 02:22:33 +0000 (UTC) Subject: Start Python programming References: Message-ID: Gazoo wrote: > > > I'd like to start learning Python programming. What sites/tutorials > could you recommend for beginner, please. > I liked the book found at https://automatetheboringstuff.com/ You can read the whole book online. I think you used to be able to download a copy too. It has lots of practical examples and is easy to read/follow. -- rust 0x68caecc97f6a90122e51c0692c88d9cb6b58a3dc From mjwilliams at gmail.com Fri Apr 30 22:54:53 2021 From: mjwilliams at gmail.com (Mike Lee Williams) Date: Fri, 30 Apr 2021 19:54:53 -0700 (PDT) Subject: Decoratored functions parsed differently by ast stdlib between 3.7 and 3.8 Message-ID: <607dcc99-fac7-436a-a4e3-4620e9cf2225n@googlegroups.com> This trivial bit of code is parsed differently by the ast module between python 3.7 and python 3.8. I'm trying to figure out what changed and why, and once I know that, if it's possible and desirable to retain the 3.7 behavior for my use case (which needs to give the same result for this input on 3.7 and 3.8). Here's the bit of python code: @hello def f(): pass And here's a script to parse it with ast from the standard library import ast code = "@hello\ndef f(): pass" p = ast.parse(code) for t in p.body: print(t.lineno) And here's the problem $ python3.8 parse.py 2 $ python3.7 parse.py 1 I don't understand why this output differs between 3.7 and 3.8. It seems 3.8 is ignoring the decorator somehow? The node has hello in decorator_list, so it's there in the ast. But it's counting lines differently. Passing the new passing feature_version=(3, 7) keyword argument introduced to 3.7 to ast.parse does not restore the 3.7 behavior in 3.8 so I'm assuming this is not a python language grammar change but rather an ast API change (or a bug?!) The release notes for 3.8 mention AST, but none of the changes look relevant as they all refer to typing https://docs.python.org/3/whatsnew/3.8.html#ast So: what changed? Why? Can I and should I try to get the old behavior back? Thanks! Mike Lee Williams From mjwilliams at gmail.com Fri Apr 30 23:07:50 2021 From: mjwilliams at gmail.com (Mike Lee Williams) Date: Fri, 30 Apr 2021 20:07:50 -0700 (PDT) Subject: Decoratored functions parsed differently by ast stdlib between 3.7 and 3.8 In-Reply-To: <607dcc99-fac7-436a-a4e3-4620e9cf2225n@googlegroups.com> References: <607dcc99-fac7-436a-a4e3-4620e9cf2225n@googlegroups.com> Message-ID: On Friday, April 30, 2021 at 7:55:10 PM UTC-7, Mike Lee Williams wrote: > This trivial bit of code is parsed differently by the ast module between python > 3.7 and python 3.8. I'm trying to figure out what changed and why, and once I > know that, if it's possible and desirable to retain the 3.7 behavior for my use > case (which needs to give the same result for this input on 3.7 and 3.8). Answering my own question: the behavior was changed by https://github.com/python/cpython/pull/9731.