From PythonList at DancesWithMice.info Sat Aug 1 02:26:54 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 1 Aug 2020 18:26:54 +1200 Subject: questions re: calendar module In-Reply-To: References: Message-ID: On 31/07/2020 02:52, o1bigtenor wrote: > I regularly work in planning through multiple years at once. > This means that I like to have a lot of stuff available in a calendar > function. > Python seems to be locked when I need to display more than 1 year at a > time. > I don't see a way to display something like 3 years worth of calendar > starting at a point 23 months from now. > (I see how to display 1 year at a time but not multiple years.) This question seems a little vague. How are you creating this "calendar function"? Are you using the Python Standard Library calendar, or perhaps talking about datetime calculations? Please copy-paste code showing this "lock". -- Regards =dn From o1bigtenor at gmail.com Sat Aug 1 07:36:12 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Sat, 1 Aug 2020 06:36:12 -0500 Subject: questions re: calendar module In-Reply-To: References: Message-ID: On Sat, Aug 1, 2020 at 1:29 AM dn via Python-list wrote: > On 31/07/2020 02:52, o1bigtenor wrote: > > I regularly work in planning through multiple years at once. > > This means that I like to have a lot of stuff available in a calendar > > function. > > Python seems to be locked when I need to display more than 1 year at a > > time. > > I don't see a way to display something like 3 years worth of calendar > > starting at a point 23 months from now. > > (I see how to display 1 year at a time but not multiple years.) > > This question seems a little vague. How are you creating this "calendar > function"? Are you using the Python Standard Library calendar, or > perhaps talking about datetime calculations? > > Please copy-paste code showing this "lock". > Maybe its not a lock - - - - but there seems to be no way to display a calendar starting from a date that is 3 years in time frame. python3 Python 3.7.7 (default, Apr 1 2020, 13:48:52) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import calendar >>> print (calendar.calendar(2024,1,1,2,8)) 2024 January February March April May June July August Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 1 2 3 4 1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 1 2 1 2 3 4 5 6 7 1 2 3 4 8 9 10 11 12 13 14 5 6 7 8 9 10 11 4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11 15 16 17 18 19 20 21 12 13 14 15 16 17 18 11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18 22 23 24 25 26 27 28 19 20 21 22 23 24 25 18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25 29 30 31 26 27 28 29 25 26 27 28 29 30 31 29 30 27 28 29 30 31 24 25 26 27 28 29 30 29 30 31 26 27 28 29 30 31 September October November December Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 1 2 3 4 5 6 1 2 3 1 2 3 4 5 6 7 8 7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15 16 17 18 19 20 21 22 21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22 23 24 25 26 27 28 29 28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29 30 30 31 I would like to show something like 2024 through the end of 2028. TIA From __peter__ at web.de Sat Aug 1 07:51:02 2020 From: __peter__ at web.de (Peter Otten) Date: Sat, 01 Aug 2020 13:51:02 +0200 Subject: questions re: calendar module References: Message-ID: o1bigtenor wrote: >>>> import calendar >>>> print (calendar.calendar(2024,1,1,2,8)) > I would like to show something like 2024 through the end of 2028. print("\n".join(cd.calendar(year) for year in range(2024, 2029))) From cl at isbd.net Sat Aug 1 08:32:54 2020 From: cl at isbd.net (Chris Green) Date: Sat, 1 Aug 2020 13:32:54 +0100 Subject: Pygobject style question Message-ID: Having (after lots of help from here, thank you) finally converted my Python 2, gtk 2 program to Python 3 and pygobject gtk 3 I'm left with a couple of what might be called style questions. I guess it's mostly down to what feels right to me but there may be good reasons for choosing one way over another and, if so, I'd like to know what they are. So, my original code had:- ... ... self.buffer = gtk.TextBuffer() self.view = gtk.TextView(self.buffer) ... ... This doesn't work in gtk+ 3 (or at least I don't think it does, the converter script changed it) and there seem to be several ways of doing it now:- ... ... self.buffer = Gtk.TextBuffer() self.view = Gtk.TextView(buffer = self.buffer) ... ... ... ... self.buffer = Gtk.TextBuffer() self.view = Gtk.TextView.new_with_buffer(self.buffer) ... ... ... ... self.view = Gtk.TextView() self.buffer = self.view.get_buffer() ... ... ... ... self.view = Gtk.TextView() self.buffer = Gtk.TextBuffer() self.view.set_buffer(self.buffer) ... ... Is there any reason to prefer any one of the above over the others? Obviously the last one is a line more but lends itself to using several Gtk.TextBuffer objects in on Gtk.TextView. -- Chris Green ? From doctor at doctor.nl2k.ab.ca Sat Aug 1 09:48:51 2020 From: doctor at doctor.nl2k.ab.ca (The Doctor) Date: Sat, 1 Aug 2020 13:48:51 -0000 (UTC) Subject: XanaNews Statistic for comp.lang.python. 8/1/2020 7:48:48 AM [2/2] Message-ID: 87 1 Mathiyazhagan S 88 1 Elias Fotinis Mozilla 89 1 ??? Gnus 90 1 Oscar Benjamin 91 1 Wasdeq68 92 1 Robin Becker Mozilla 93 1 dadmomsacct at gmail.com G2 94 1 namastu at gmail.com G2 95 1 Sarvesh Poddar WebService 96 1 Sumana Harihareswara Mozilla 97 1 mentificium at gmail.com G2 98 1 nhpython Open-Xchange Mailer 99 1 Bob7star Mozilla 100 1 David L Neil Mozilla 101 1 boB Stepp 102 1 Bart Mozilla 103 1 Tanmay Shah 104 1 R.Wieser Microsoft Outlook Express 105 1 Danilo Coccia Mozilla 106 1 Damian Johnson 107 1 Liste guru Mozilla 108 1 Stephen Carboni 109 1 Bolun Thompson 110 1 kyrohammy at gmail.com G2 111 1 hunter.hammond.dev at gmail.c G2 112 1 Raine Pretorius 113 1 Romulus Schilling 114 1 LUIGI BISIGNANI:MAI PIU' C G2 115 1 Wingware Postbox 116 1 artis.paintre at gmail.com G2 117 1 Nomen Nescio Unison 118 1 nhess97 at gmail.com G2 119 1 farabial25 at gmail.com G2 120 1 Jim Mozilla 121 1 Michio Suginoo 122 1 joserivera6614 at gmail.com G2 123 1 Vincent Davis 124 1 Chaitanya Patil 125 1 Ralf M. Mozilla 126 1 anisaqeelah56 at gmail.com G2 127 1 Shivam Dutt Sharma 128 1 Bob Gailer 129 1 Christman, Roger Graydon 130 1 Damilare 131 1 haris.7b1 at gmail.com G2 132 1 Bischoop slrn 133 1 Deepak Didmania 134 1 MICHELE CALZOLARI IGEA BAN G2 135 1 Ed Walser 136 1 vjp2.at at at.BioStrategist.d tin 137 1 rami.chowdhury at gmail.com geary 138 1 mahabub.cse.buet at gmail.com G2 139 1 Stephan Lukits iPhone Mail ( 140 1 ksikor14 at yahoo.com G2 141 1 Richard Damon Mozilla 142 1 kandolacherrydeepkaur at gmai G2 143 1 Stephen Rosen 144 1 Gazu slrn 145 1 Shanmika Sugavaneswaran 146 1 Bill Deegan 147 1 J Conrado Mozilla 148 1 CMCC Info Mozilla 149 1 Reto 150 1 Orges Leka 151 1 Abhiram R 152 1 xuanwu348 Coremail Webmail Server V Top Newsreaders Ranking Articles Newsreader Users ------- -------- -------------------------------------------- ----- 1 238 G2 34 2 134 51 3 121 Mozilla 32 4 29 slrn 5 5 20 ForteAgent 1 6 14 tin 2 7 11 Apple Mail ( 3 8 10 Mutt 3 9 8 Microsoft Outlook 2 10 7 Cyrus-JMAP 1 11 6 iPad Mail ( 2 12 3 Gnus 3 13 3 Claws Mail 1 14 3 VM 1 15 3 KNode 1 16 3 WebService 2 17 2 Pan 1 18 1 iPhone Mail ( 1 19 1 Microsoft Outlook Express 1 20 1 Open-Xchange Mailer 1 21 1 KMail 1 22 1 Unison 1 23 1 geary 1 24 1 Coremail Webmail Server Version XT 1 25 1 Postbox 1 -- This email has been checked for viruses by AVG. https://www.avg.com From doctor at doctor.nl2k.ab.ca Sat Aug 1 09:48:51 2020 From: doctor at doctor.nl2k.ab.ca (The Doctor) Date: Sat, 1 Aug 2020 13:48:51 -0000 (UTC) Subject: XanaNews Statistic for comp.lang.python. 8/1/2020 7:48:48 AM [1/2] Message-ID: XanaNews Statistic for comp.lang.python. 8/1/2020 7:48:48 AM >From article 581998 (7/1/2020 6:44:35 AM) to article 582636 (7/31/2020 8:24:06 PM) Number of threads ................... 318 Number of articles .................. 674 Average articles per thread ......... 2.12 Number of unanswered posts .......... 245 Number of posts from XanaNews users .. 0 Top Threads Ranking Articles Subject ------- -------- ---------------------------------- 1 37 Formal Question to Steering Council (re recent PEP8 changes) 2 28 Bulletproof json.dump? 3 16 Fwd: [BUG] missing ')' causes syntax error on next line 4 14 Iterators, iterables and special objects 5 12 frozendict: an experiment 6 11 Symlinks already present 7 10 Questioning the effects of multiple assignment 8 9 "1,+2,", but not "(1,)+2," 9 9 EuroPython 2020: Data Science Track 10 8 Installing Python 3.8.3 with tkinter 11 8 The speed of glob() 12 8 Python Program Help 13 8 Re: Friday Finking: Limiting parameters 14 8 Winreg 15 7 Request help w/pip install jq 16 7 True is True / False is False? 17 7 Confused about np.polyfit() 18 7 An I connected here? 19 6 Need to 'import gtk' on Ubuntu 20.04, what do I need? 20 6 Re: Dowloading package dependencies from locked down machine 21 6 RE: Local access to a file, How To ? 22 6 Fake news Detect 23 6 help 24 6 A rule for your twitlist/mailing list 25 6 Issues in downloading python 26 5 Python pandas Excel 27 5 python software foundation 28 5 Dowloading package dependencies from locked down machine 29 5 why is requests 2.24 behaving differently on different Win10Pro PCs? 30 5 How to diagnose import error when importing from .so file? 31 5 Access last element after iteration 32 5 trying to improve my knn algorithm 33 5 Iterating over dict is slower than iterating over iter(dict)? 34 5 New to python - Just a question 35 5 Friday Finking: Limiting parameters 36 5 Need a Dynamic vlookup using python 37 5 Winreg 38 4 Unable to login | fbchat.Client 39 4 Issues Download the Latest Version of Python Programming Language 40 4 Is sys.executable not supposed to follow symlinks? 41 4 Windows and Subclassing - 'OverflowError': int too long to convert 42 4 How to limit *length* of PrettyPrinter 43 4 Re: frozendict: an experiment 44 4 Facing problem while opening phython 45 4 Python Scripts 46 4 python installation help 47 4 Re: Assign Excel cell value from Datepicker widget Selection using Python 48 3 "OSError: [Errno 9] Bad file descriptor" When I try to Install the library in conda prompt 49 3 Equivalent of "make install" for Python on windows? 50 3 python software foundation 51 3 Upgrade from Python 3.6 to 3.8 and cx-freeze is not available more 52 3 Re: How to read barcoded value from PDF 53 3 execution timing of the method QWidget.show() 54 3 Typing modules 55 3 Re: How to limit *length* of PrettyPrinter 56 3 Support both asyncio and synchronous callers 57 3 Re: Solutions, Testbank for Labor Economics 8th Edition, 8e by George Borjas 58 3 Urgent 59 3 Re: solution manual for Operating System Concepts 9th Edition by Abraham 60 3 Very Simple (Rather Dumb) Question 61 3 PEP 622 62 3 What's the enum for a button press event in pygobject 3? 63 3 How to find code that causes a 'deprecated' warning? 64 3 Non IDE development strategy - what do others do that's fairly simple? 65 3 Issue with Python installation for a beginner Python coder. 66 3 App for Moto e6 using Python? 67 3 Re: Seeking to convert a py timer app for my Moto E6 68 3 Gtk.TextBuffer problem on converting from GTK+ 2 to GTK+ 3 69 2 excel (multiple sheets) to yml file for each sheet 70 2 Downloading Python 71 2 Re: FW: Pycharm Won't Do Long Underscore 72 2 questions re: calendar module 73 2 business analysis and valuation IFRS edition 5th edition by Palepu Solution manual Top Posters Ranking Articles Name Most Used Newsreader ------- -------- -------------------------- -------------------- 1 119 Vagrant G2 2 27 dn Mozilla 3 27 Chris Angelico 4 20 Dennis Lee Bieber ForteAgent 5 16 Jon Ribbens slrn 6 14 solutionsmanualteam at gmail. G2 7 13 Chris Green tin 8 12 Marco Sulla 9 12 abooks.s.m at gmail.com G2 10 11 solutions.for.student at gmai G2 11 11 books.solutions.s.m at gmail. G2 12 10 MRAB Mozilla 13 10 Stefan Ram 14 10 asolutionsbooks at gmail.com G2 15 8 Rhodri James Mozilla 16 7 Steve Microsoft Outlook 17 7 DL Neil Mozilla 18 7 narenchunduri at gmail.com G2 19 7 Mats Wichmann Mozilla 20 7 Random832 Cyrus-JMAP 21 6 Barry Scott Apple Mail ( 22 6 Michael Torrie Mozilla 23 6 Adam Funk slrn 24 6 Ethan Furman Mozilla 25 6 ineedsolutionsbook at gmail.c G2 26 6 trustsolutionsteam at gmail.c G2 27 6 solutionsbookteam at gmail.co G2 28 5 J. Pic 29 5 Frank Millman Mozilla 30 5 Inada Naoki 31 5 solutionsbook at gmail.com G2 32 5 M.-A. Lemburg Mozilla 33 5 Grant Edwards slrn 34 4 Barry iPad Mail ( 35 4 Christian Heimes 36 4 Dino Mozilla 37 4 Cameron Simpson Mutt 38 4 Terry Reedy Mozilla 39 4 Peter J. Holzer Mutt 40 4 Termoregolato Mozilla 41 4 get.solutionsbook at gmail.co G2 42 4 Peter Sl??ik 43 4 o1bigtenor 44 3 Klaus Jantzen 45 3 Dieter Maurer VM 46 3 R Pasco 47 3 2QdxY4RzWzUUiLuE at potatocho 48 3 Mike Dewhirst Mozilla 49 3 Gisle Vanem Mozilla 50 3 Tim Chase Claws Mail 51 3 Kyle Stanley 52 3 Lukasz Langa Apple Mail ( 53 3 Stavros Macrakis 54 3 Eryk Sun 55 3 Peter Otten KNode 56 2 Christian Gollwitzer Mozilla 57 2 Jeff Linahan 58 2 malikhunza565 at gmail.com G2 59 2 David Raymond 60 2 stack flow G2 61 2 Castillo, Herbert S 62 2 Andrew McLean Mozilla 63 2 Ned Deily Mozilla 64 2 damianleejob at gmail.com G2 65 2 Python Mozilla 66 2 Eko palypse 67 2 MARIA GRAZIA CRUPI. EX AMA G2 68 2 Gilmeh Serda Pan 69 2 duncan smith Mozilla 70 2 moi G2 71 2 David Lowry-Duda Mutt 72 2 Patrick Stinson Apple Mail ( 73 2 Igor Korot 74 2 Bev In TX iPad Mail ( 75 2 Jonathan Gossage 76 2 Daley Okuwa WebService 77 2 Jithesh Thirumaran 78 2 Souvik Dutta 79 1 Anssi Saari Gnus 80 1 Abdur-Rahmaan Janhangeer 81 1 Gene Heskett KMail 82 1 Ejiofor Chidinma Peace 83 1 Akkana Peck 84 1 Christian SCHEIBER / KLS G Microsoft Outlook 85 1 aysegulsayin6 at gmail.com G2 86 1 Joe Pfeiffer Gnus -- This email has been checked for viruses by AVG. https://www.avg.com From luuk34 at gmail.com Sat Aug 1 10:13:19 2020 From: luuk34 at gmail.com (Luuk) Date: Sat, 1 Aug 2020 16:13:19 +0200 Subject: Downloading Python In-Reply-To: References: Message-ID: On 31-7-2020 22:10, Tanmay Shah wrote: > Hello to whoever this may concern, > > After downloading Python 3.8.5 IDLE, an error message popped up, saying > the code execution cannot proceed because python38.dll was not found. What > should I do in order to use the Python interpreter? > > Thank you! It's WIndows, did you try to reboot ? It seems to solve a lot of problems, on Windows.... From o1bigtenor at gmail.com Sat Aug 1 10:29:24 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Sat, 1 Aug 2020 09:29:24 -0500 Subject: questions re: calendar module In-Reply-To: References: Message-ID: On Sat, Aug 1, 2020 at 6:58 AM Peter Otten <__peter__ at web.de> wrote: > > o1bigtenor wrote: > > >>>> import calendar > >>>> print (calendar.calendar(2024,1,1,2,8)) > > > I would like to show something like 2024 through the end of 2028. > > print("\n".join(cd.calendar(year) for year in range(2024, 2029))) Sorry - - - - 1st response was to only Mr Peter - - - hopefully this is useful to more than I so here is that to all. > > >>> print("\n".join(cd.calendar(year) for year in range(2024, 2029))) Traceback (most recent call last): File "", line 1, in File "", line 1, in NameError: name 'cd' is not defined so 'cd' seems to be a problem. Tried changing 'cd' to calendar and that gives the desired response. Except its a neat 3 months wide very very very many rows of calendar. I'm trying to figure out how to do something like this: November 2022 December 2022 January 2023 February 2023 March 2023 April 2023 May 2023 Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 123 1 2 3 4 5 127 1 2 3 132 1 2 3 4 5 6 7 136 1 2 3 4 140 1 2 3 4 144 1 149 1 2 3 4 5 6 124 6 7 8 9 10 11 12 128 4 5 6 7 8 9 10 133 8 9 10 11 12 13 14 137 5 6 7 8 9 10 11 141 5 6 7 8 9 10 11 145 2 3 4 5 6 7 8 150 7 8 9 10 11 12 13 125 13 14 15 16 17 18 19 129 11 12 13 14 15 16 17 134 15 16 17 18 19 20 21 138 12 13 14 15 16 17 18 142 12 13 14 15 16 17 18 146 9 10 11 12 13 14 15 151 14 15 16 17 18 19 20 126 20 21 22 23 24 25 26 130 18 19 20 21 22 23 24 135 22 23 24 25 26 27 28 139 19 20 21 22 23 24 25 143 19 20 21 22 23 24 25 147 16 17 18 19 20 21 22 152 21 22 23 24 25 26 27 127 27 28 29 30 131 25 26 27 28 29 30 31 136 29 30 31 140 26 27 28 144 26 27 28 29 30 31 148 23 24 25 26 27 28 29 153 28 29 30 31 149 30 June 2023 July 2023 August 2023 September 2023 October 2023 November 2023 December 2023 Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 153 1 2 3 157 1 162 1 2 3 4 5 166 1 2 171 1 2 3 4 5 6 7 175 1 2 3 4 179 1 2 The formatting here is a mess. The months are centered. The week numbers are consecutive from the starting date. The dates are centered under the weekday name. If you've ever used ncal its like that except that I can now have up to 7 months wide if the terminal is wide enough (>180 columns IIRC). A mentor was working on this in Perl but as he died some couple months ago its up to me to make what I want. Because it seems like there are a lot of disparate things happening its not very straight forward trying to replicate and extend my friend's efforts except in Python. (My friend preferred to work in Perl rather than Python and I'm wanting to learn Python. I understand that this is not perhaps the easiest way to learn something but it sure is interesting!) TIA From o1bigtenor at gmail.com Sat Aug 1 10:32:39 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Sat, 1 Aug 2020 09:32:39 -0500 Subject: questions re: calendar module In-Reply-To: References: Message-ID: On Sat, Aug 1, 2020 at 9:29 AM o1bigtenor wrote: > > On Sat, Aug 1, 2020 at 6:58 AM Peter Otten <__peter__ at web.de> wrote: > > > > o1bigtenor wrote: > > > > >>>> import calendar > > >>>> print (calendar.calendar(2024,1,1,2,8)) > > > > > I would like to show something like 2024 through the end of 2028. > > > > print("\n".join(cd.calendar(year) for year in range(2024, 2029))) > > > Sorry - - - - 1st response was to only Mr Peter - - - hopefully this is > useful to more than I so here is that to all. > > > > > > >>> print("\n".join(cd.calendar(year) for year in range(2024, 2029))) > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in > NameError: name 'cd' is not defined > > so 'cd' seems to be a problem. > > Tried changing 'cd' to calendar and that gives the desired response. > > Except its a neat 3 months wide very very very many rows of calendar. > > I'm trying to figure out how to do something like this: > > November 2022 December 2022 > January 2023 February 2023 > March 2023 April 2023 > May 2023 > Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu > We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa > Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa > 123 1 2 3 4 5 127 1 2 3 > 132 1 2 3 4 5 6 7 136 1 2 3 4 140 > 1 2 3 4 144 1 149 1 2 3 4 5 6 > 124 6 7 8 9 10 11 12 128 4 5 6 7 8 9 10 133 8 9 10 11 12 > 13 14 137 5 6 7 8 9 10 11 141 5 6 7 8 9 10 11 145 2 3 > 4 5 6 7 8 150 7 8 9 10 11 12 13 > 125 13 14 15 16 17 18 19 129 11 12 13 14 15 16 17 134 15 16 17 18 19 > 20 21 138 12 13 14 15 16 17 18 142 12 13 14 15 16 17 18 146 9 10 > 11 12 13 14 15 151 14 15 16 17 18 19 20 > 126 20 21 22 23 24 25 26 130 18 19 20 21 22 23 24 135 22 23 24 25 26 > 27 28 139 19 20 21 22 23 24 25 143 19 20 21 22 23 24 25 147 16 17 > 18 19 20 21 22 152 21 22 23 24 25 26 27 > 127 27 28 29 30 131 25 26 27 28 29 30 31 136 29 30 31 > 140 26 27 28 144 26 27 28 29 30 31 148 23 24 > 25 26 27 28 29 153 28 29 30 31 > > 149 30 > > June 2023 July 2023 August 2023 > September 2023 October 2023 > November 2023 December 2023 > Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th > Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo > Tu We Th Fr Sa Su Mo Tu We Th Fr Sa > 153 1 2 3 157 1 162 1 2 3 > 4 5 166 1 2 171 1 2 3 4 5 6 7 175 > 1 2 3 4 179 1 2 > > The formatting here is a mess. (Its an even bigger mess now when its truncated to 80 columns. Can't change the mess but I can tell you that it doesn't 'look that way'! Don't know how to include an example in the body and have it be even a bit accurate - - - please advise if there is a way.) > The months are centered. The week numbers are consecutive from the > starting date. > The dates are centered under the weekday name. If you've ever used > ncal its like that except > that I can now have up to 7 months wide if the terminal is wide enough > (>180 columns IIRC). > A mentor was working on this in Perl but as he died some couple months > ago its up to me > to make what I want. > Because it seems like there are a lot of disparate things happening > its not very straight > forward trying to replicate and extend my friend's efforts except in > Python. (My friend > preferred to work in Perl rather than Python and I'm wanting to learn > Python. I understand > that this is not perhaps the easiest way to learn something but it > sure is interesting!) > > TIA From Bischoop at vimart.net Sat Aug 1 11:59:18 2020 From: Bischoop at vimart.net (Bischoop) Date: Sat, 1 Aug 2020 15:59:18 -0000 (UTC) Subject: Downloading Python References: Message-ID: On 2020-07-31, Stefan Ram wrote: > > Don't download just IDLE in isolation. > > Instead download Python 3.8 from www.python.org/downloads > and properly install it following the installation > instructions for your operating system. > > This will then include IDLE. > > He's right. From barry at barrys-emacs.org Sat Aug 1 16:58:36 2020 From: barry at barrys-emacs.org (Barry) Date: Sat, 1 Aug 2020 21:58:36 +0100 Subject: Downloading Python In-Reply-To: References: Message-ID: > On 1 Aug 2020, at 15:16, Luuk wrote: > > ? >> On 31-7-2020 22:10, Tanmay Shah wrote: >> Hello to whoever this may concern, >> >> After downloading Python 3.8.5 IDLE, an error message popped up, saying >> the code execution cannot proceed because python38.dll was not found. What >> should I do in order to use the Python interpreter? I have never had to reboot windows when installing python. Was I lucky? Barry >> >> Thank you! > > > It's WIndows, did you try to reboot ? > > It seems to solve a lot of problems, on Windows.... > > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Sat Aug 1 17:25:41 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 1 Aug 2020 22:25:41 +0100 Subject: Downloading Python In-Reply-To: References: Message-ID: <53d761b5-1ac3-4dc8-1746-f8ec39e59624@mrabarnett.plus.com> On 2020-08-01 21:58, Barry wrote: > >> On 1 Aug 2020, at 15:16, Luuk wrote: >> >> ? >>> On 31-7-2020 22:10, Tanmay Shah wrote: >>> Hello to whoever this may concern, >>> >>> After downloading Python 3.8.5 IDLE, an error message popped up, saying >>> the code execution cannot proceed because python38.dll was not found. What >>> should I do in order to use the Python interpreter? > > I have never had to reboot windows when installing python. > Was I lucky? > No. I've never had a problem with it either. > >>> >>> Thank you! >> >> >> It's WIndows, did you try to reboot ? >> >> It seems to solve a lot of problems, on Windows.... >> From wrw at mac.com Sat Aug 1 18:48:46 2020 From: wrw at mac.com (William Ray Wing) Date: Sat, 1 Aug 2020 18:48:46 -0400 Subject: questions re: calendar module In-Reply-To: References: Message-ID: > On Aug 1, 2020, at 10:35 AM, o1bigtenor wrote: > > ?On Sat, Aug 1, 2020 at 9:29 AM o1bigtenor wrote: >> >>> On Sat, Aug 1, 2020 at 6:58 AM Peter Otten <__peter__ at web.de> wrote: >>> >>> o1bigtenor wrote: >>> >>>>>>> import calendar >>>>>>> print (calendar.calendar(2024,1,1,2,8)) >>> >>>> I would like to show something like 2024 through the end of 2028. >>> >>> print("\n".join(cd.calendar(year) for year in range(2024, 2029))) >> >> >> Sorry - - - - 1st response was to only Mr Peter - - - hopefully this is >> useful to more than I so here is that to all. >>> >>> >> >>>>> print("\n".join(cd.calendar(year) for year in range(2024, 2029))) >> Traceback (most recent call last): >> File "", line 1, in >> File "", line 1, in >> NameError: name 'cd' is not defined >> >> so 'cd' seems to be a problem. >> >> Tried changing 'cd' to calendar and that gives the desired response. >> >> Except its a neat 3 months wide very very very many rows of calendar. >> >> I'm trying to figure out how to do something like this: >> >> November 2022 December 2022 >> January 2023 February 2023 >> March 2023 April 2023 >> May 2023 >> Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu >> We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa >> Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa >> 123 1 2 3 4 5 127 1 2 3 >> 132 1 2 3 4 5 6 7 136 1 2 3 4 140 >> 1 2 3 4 144 1 149 1 2 3 4 5 6 >> 124 6 7 8 9 10 11 12 128 4 5 6 7 8 9 10 133 8 9 10 11 12 >> 13 14 137 5 6 7 8 9 10 11 141 5 6 7 8 9 10 11 145 2 3 >> 4 5 6 7 8 150 7 8 9 10 11 12 13 >> 125 13 14 15 16 17 18 19 129 11 12 13 14 15 16 17 134 15 16 17 18 19 >> 20 21 138 12 13 14 15 16 17 18 142 12 13 14 15 16 17 18 146 9 10 >> 11 12 13 14 15 151 14 15 16 17 18 19 20 >> 126 20 21 22 23 24 25 26 130 18 19 20 21 22 23 24 135 22 23 24 25 26 >> 27 28 139 19 20 21 22 23 24 25 143 19 20 21 22 23 24 25 147 16 17 >> 18 19 20 21 22 152 21 22 23 24 25 26 27 >> 127 27 28 29 30 131 25 26 27 28 29 30 31 136 29 30 31 >> 140 26 27 28 144 26 27 28 29 30 31 148 23 24 >> 25 26 27 28 29 153 28 29 30 31 >> >> 149 30 >> >> June 2023 July 2023 August 2023 >> September 2023 October 2023 >> November 2023 December 2023 >> Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th >> Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo >> Tu We Th Fr Sa Su Mo Tu We Th Fr Sa >> 153 1 2 3 157 1 162 1 2 3 >> 4 5 166 1 2 171 1 2 3 4 5 6 7 175 >> 1 2 3 4 179 1 2 >> >> The formatting here is a mess. > > (Its an even bigger mess now when its truncated to 80 columns. Can't change > the mess but I can tell you that it doesn't 'look that way'! Don't know how to > include an example in the body and have it be even a bit accurate - - - please > advise if there is a way.) > If you want us to see it in its exact form, print to PDF, post/share It on Dropbox. >> The months are centered. The week numbers are consecutive from the >> starting date. >> The dates are centered under the weekday name. If you've ever used >> ncal its like that except >> that I can now have up to 7 months wide if the terminal is wide enough >> (>180 columns IIRC). >> A mentor was working on this in Perl but as he died some couple months >> ago its up to me >> to make what I want. >> Because it seems like there are a lot of disparate things happening >> its not very straight >> forward trying to replicate and extend my friend's efforts except in >> Python. (My friend >> preferred to work in Perl rather than Python and I'm wanting to learn >> Python. I understand >> that this is not perhaps the easiest way to learn something but it >> sure is interesting!) >> >> TIA > -- > https://mail.python.org/mailman/listinfo/python-list From cs at cskk.id.au Sat Aug 1 19:08:04 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 2 Aug 2020 09:08:04 +1000 Subject: Non IDE development strategy - what do others do that's fairly simple? In-Reply-To: References: Message-ID: <20200801230804.GA7190@cskk.homeip.net> On 30Jul2020 21:15, Marco Sulla wrote: >What you want is a branch, I guess. > >https://www.mercurial-scm.org/wiki/Branch > >For simplicity, I suggest you have two different directories: one for the >development branch and the other for the production branch. Yes to this advice. And I am also an editor in one window and command line in another window person. Note that a Mercurial "named branch" is a more, um, "solid" thing than a git branch, which is much more like a mercurial bookmark. Basicly, you can't easily remove a mercurial named branch. Bookmarks you can make and discard freely. That said, I hardly ever use bookmarks. You also do not need a named branch - a cloned directory works as well. I use mercurial branches for long lived things, particularly development on theme. My personal library has a bunch of long term branches - they all get merged back into "default" frequently as things stabilise. So for your scenario I'd add a named branch for the development, particularly if it has a theme. But also as Marco suggests, clone your tree into another directory for the development. Look: [~]fleet2*> cd ~/hg /Users/cameron/hg [~/hg]fleet2*> ls -d css-* css-adzapper css-nodedb-nested-curly-syntax css-aws css-nodedb-proxyobjs css-beyonwiz css-persist css-calibre css-pilfer css-contractutils css-pt css-csbug css-py3 [...] Each of those trees is a clone of the main "css" tree. They do not all have named branches. [~/hg]fleet2*> cd css [~/hg/css(hg:default)]fleet2*> hg clone . ../css-newdev [~/hg/css(hg:default)]fleet2*> cd ../css-newdev [~/hg/css-newdev(hg:default)]fleet2*> hg branch newdev [~/hg/css-newdev(hg:newdev)]fleet2*> So now I've got a clone in css-newdev, for a new named branch "newdev" (obviously pick a better branch name). No need to make a named branch, unless this is long lived, in which case it helps you track where changes occurred - the branch name is recorded in commits. You can merge to or from "../css" as needed. I find this _much_ easier to deal with than the common git habit of switching branches in place (which you can also do). Cheers, Cameron Simpson From PythonList at DancesWithMice.info Sat Aug 1 19:26:46 2020 From: PythonList at DancesWithMice.info (dn) Date: Sun, 2 Aug 2020 11:26:46 +1200 Subject: questions re: calendar module In-Reply-To: References: Message-ID: On 01/08/2020 23:36, o1bigtenor wrote: > On Sat, Aug 1, 2020 at 1:29 AM dn via Python-list > > wrote: > > On 31/07/2020 02:52, o1bigtenor wrote: > > I regularly work in planning through multiple years at once. > > This means that I like to have a lot of stuff available in a calendar > > function. > > Python seems to be locked when I need to display more than 1 year > at a > > time. > > I don't see a way to display something like 3 years worth of calendar > > starting at a point 23 months from now. > > (I see how to display 1 year at a time but not multiple years.) > > This question seems a little vague. How are you creating this "calendar > function"? Are you using the Python Standard Library calendar, or > perhaps talking about datetime calculations? > > Please copy-paste code showing this "lock". > > > Maybe its not a lock - - - - but there seems to be no way to display a > calendar starting > from a date that is 3 years in?time frame. ... > I would like to show something like 2024 through the end of 2028. Let's start with the disappointing information:- - please read https://docs.python.org/3/library/calendar.html and the *function's* help: >>> help(cal.calendar) Help on method formatyear in module calendar: formatyear(theyear, w=2, l=1, c=6, m=3) method of calendar.TextCalendar instance Returns a year's calendar as a multi-line string. The word "year" is singular, and the parameters are all to do with the output-presentation. We can't even request 'the rest of the year from August onwards'! There are other helper functions. Also, we are invited to sub-class. Might it be possible to generate multiple year (or month) groups, split them by line, and then reassemble line-by-line to produce the width and temporal length required? What do you think? Further web.refs: Working with Python Calendar in Depth https://www.pythonpool.com/python-calendar/ Python CALENDAR Tutorial with Example https://www.guru99.com/calendar-in-python.html -- Regards =dn From o1bigtenor at gmail.com Sat Aug 1 20:24:41 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Sat, 1 Aug 2020 19:24:41 -0500 Subject: questions re: calendar module In-Reply-To: References: Message-ID: On Sat, Aug 1, 2020 at 6:29 PM dn via Python-list wrote: > > On 01/08/2020 23:36, o1bigtenor wrote: > > On Sat, Aug 1, 2020 at 1:29 AM dn via Python-list > > > wrote: > > > > On 31/07/2020 02:52, o1bigtenor wrote: > > > I regularly work in planning through multiple years at once. > > > This means that I like to have a lot of stuff available in a calendar > > > function. > > > Python seems to be locked when I need to display more than 1 year > > at a > > > time. > > > I don't see a way to display something like 3 years worth of calendar > > > starting at a point 23 months from now. > > > (I see how to display 1 year at a time but not multiple years.) > > > > This question seems a little vague. How are you creating this "calendar > > function"? Are you using the Python Standard Library calendar, or > > perhaps talking about datetime calculations? > > > > Please copy-paste code showing this "lock". > > > > > > Maybe its not a lock - - - - but there seems to be no way to display a > > calendar starting > > from a date that is 3 years in time frame. > ... > > > I would like to show something like 2024 through the end of 2028. > > > Let's start with the disappointing information:- > - please read https://docs.python.org/3/library/calendar.html and the > *function's* help: > > >>> help(cal.calendar) > Help on method formatyear in module calendar: > formatyear(theyear, w=2, l=1, c=6, m=3) method of calendar.TextCalendar > instance > Returns a year's calendar as a multi-line string. > > The word "year" is singular, and the parameters are all to do with the > output-presentation. We can't even request 'the rest of the year from > August onwards'! It is very disappointing - - - -suggests that thinking outside the space of one year is somehow deprecated. Frustrated when what you do demands that you think in longer periods of time (and yet have to function within the week as well). > > There are other helper functions. Also, we are invited to sub-class. Hmmmmmm - - - will have to investigate that. > > Might it be possible to generate multiple year (or month) groups, split > them by line, and then reassemble line-by-line to produce the width and > temporal length required? Likely work well if the months were considered as discrete blocks. Thinking that one could have something like January 20xx February 20xx Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 1 2 3 4 5 5 1 2 2 6 7 8 9 10 11 12 6 3 4 5 6 7 8 9 3 13 14 15 16 17 18 19 7 10 11 12 13 14 15 16 4 20 21 22 23 24 25 26 8 5 27 28 29 30 31 It is very useful for me to have the week numbers included. Have learned some fascinating things (some months have 6 weeks in them!) and the joys of formating (grin!). > > What do you think? I was starting from what I understood (how to print 'a' year) working to get closer to what I could use. Ncal allows me to display a calendar except I'm restricted to a display only 3 months wide. More than one month is relatively easy to display from present but not from some other point. It would seem that the 80 column display still rules supreme - - - - - and that's on a 1920 pixel wide monitor. Thanks for the ideas and suggestions! From o1bigtenor at gmail.com Sat Aug 1 20:42:09 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Sat, 1 Aug 2020 19:42:09 -0500 Subject: questions re: calendar module In-Reply-To: References: Message-ID: On Sat, Aug 1, 2020 at 7:24 PM o1bigtenor wrote: > > On Sat, Aug 1, 2020 at 6:29 PM dn via Python-list > wrote: > > > > On 01/08/2020 23:36, o1bigtenor wrote: > > > On Sat, Aug 1, 2020 at 1:29 AM dn via Python-list > > > > wrote: > > > > > > On 31/07/2020 02:52, o1bigtenor wrote: > > > > I regularly work in planning through multiple years at once. > > > > This means that I like to have a lot of stuff available in a calendar > > > > function. snip > > Let's start with the disappointing information:- > > - please read https://docs.python.org/3/library/calendar.html and the > > *function's* help: > > > > >>> help(cal.calendar) > > Help on method formatyear in module calendar: > > formatyear(theyear, w=2, l=1, c=6, m=3) method of calendar.TextCalendar > > instance > > Returns a year's calendar as a multi-line string. > > > > The word "year" is singular, and the parameters are all to do with the > > output-presentation. We can't even request 'the rest of the year from > > August onwards'! > > It is very disappointing - - - -suggests that thinking outside the space of > one year is somehow deprecated. Frustrated when what you do demands > that you think in longer periods of time (and yet have to function within > the week as well). > > > > > There are other helper functions. Also, we are invited to sub-class. > > Hmmmmmm - - - will have to investigate that. Doing some searching - - - - sub-class really doesn't have a lot of 'official' info. Perhaps an information source might be pointed out? > > > > Might it be possible to generate multiple year (or month) groups, split > > them by line, and then reassemble line-by-line to produce the width and > > temporal length required? > > Likely work well if the months were considered as discrete blocks. > Thinking that one could have something like > > It is very useful for me to have the week numbers included. Have > learned some fascinating things (some months have 6 weeks in > them!) and the joys of formating (grin!). > > > > What do you think? > > I was starting from what I understood (how to print 'a' year) working > to get closer to what I could use. Ncal allows me to display a > calendar except I'm restricted to a display only 3 months wide. More > than one month is relatively easy to display from present but not > from some other point. It would seem that the 80 column display > still rules supreme - - - - - and that's on a 1920 pixel wide monitor. > > Thanks for the ideas and suggestions! > January 20xx February 20xx > Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa > 1 1 2 3 4 5 5 1 2 > 2 6 7 8 9 10 11 12 6 3 4 5 6 7 8 9 > 3 13 14 15 16 17 18 19 7 10 11 12 13 14 15 16 > 4 20 21 22 23 24 25 26 8 > 5 27 28 29 30 31 > Reading through more docs there is a possibility of using the 'format' command. Would need to first come up with a way of describing the months (with their attendant week numbers) and then describe a formating system which would then enable a use of 'print' to achieve the desired goal. Is this perhaps a good way of doing this? TIA From harshmashru271 at gmail.com Sat Aug 1 08:59:46 2020 From: harshmashru271 at gmail.com (Harsh Mashru) Date: Sat, 1 Aug 2020 18:29:46 +0530 Subject: Python has stopped working Message-ID: Respected sir/ma'am I've been trying to execute the code which operates the camera. When it starts to open the camera it shows that python.exe has stopped working. Problem signature: Problem Event Name: APPCRASH Application Name: python.exe Application Version: 3.8.5150.1013 Application Timestamp: 5f15bf71 Fault Module Name: cv2.cp38-win_amd64.pyd Fault Module Version: 0.0.0.0 Fault Module Timestamp: 5f028477 Exception Code: c0000005 Exception Offset: 0000000002c6a90a OS Version: 6.1.7601.2.1.0.768.2 Locale ID: 16393 Additional Information 1: 221e Additional Information 2: 221ebc263cc5a862cc38c6e101bcabef Additional Information 3: 73ad Additional Information 4: 73ad4612db3d3535fc9083877169fc99 Read our privacy statement online: http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409 If the online privacy statement is not available, please read our privacy statement offline: C:\Windows\system32\en-US\erofflps.txt I look forward to hearing from you. Regards, Harsh Mashru From rosuav at gmail.com Sat Aug 1 23:04:15 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 2 Aug 2020 13:04:15 +1000 Subject: Python has stopped working In-Reply-To: References: Message-ID: On Sun, Aug 2, 2020 at 1:00 PM Harsh Mashru wrote: > > Respected sir/ma'am > > I've been trying to execute the code which operates the > camera. When it starts to open the camera it shows that python.exe has > stopped working. > > Problem signature: > Problem Event Name: APPCRASH > Application Name: python.exe > Fault Module Name: cv2.cp38-win_amd64.pyd The actual crash happened inside this module. I'm guessing that's some sort of camera handler. You may need to look into why *that* is crashing. ChrisA From PythonList at DancesWithMice.info Sun Aug 2 00:31:22 2020 From: PythonList at DancesWithMice.info (dn) Date: Sun, 2 Aug 2020 16:31:22 +1200 Subject: questions re: calendar module In-Reply-To: References: Message-ID: <1697f32a-8f3b-76ce-e10b-04e7ae11b448@DancesWithMice.info> On 02/08/2020 12:24, o1bigtenor wrote: > On Sat, Aug 1, 2020 at 6:29 PM dn via Python-list > wrote: >> On 01/08/2020 23:36, o1bigtenor wrote: >>> On Sat, Aug 1, 2020 at 1:29 AM dn via Python-list >>> > wrote: >>> On 31/07/2020 02:52, o1bigtenor wrote: >>> > I regularly work in planning through multiple years at once. ... >>> calendar starting >>> from a date that is 3 years in time frame. >> ... >> >>> I would like to show something like 2024 through the end of 2028. ... > It is very disappointing - - - -suggests that thinking outside the space of > one year is somehow deprecated. Frustrated when what you do demands > that you think in longer periods of time (and yet have to function within > the week as well). I agree - says he who tactically changes his 'events calendar' every half-year, to ensure that there is more than a six-month planning horizon. Sister-in-Law has just this morning blocked-out dates for family gatherings ("you are expected to attend!") for not just Christmas/December, but into Jan, Feb, and Easter holidays (Uni vacation) next year; because U.David is but a mere-male and needs lots of 'extra help'... (and because she knows 'the system', and has something similar at home!) >> There are other helper functions. Also, we are invited to sub-class. > > Hmmmmmm - - - will have to investigate that. I'm thinking that the month function/method might be a better way to go (than year-at-a-time). For visualisation (per next para), have you tried computing a month in the REPL and then str.split()-ting the output into separate week-strings? >> Might it be possible to generate multiple year (or month) groups, split >> them by line, and then reassemble line-by-line to produce the width and >> temporal length required? > > Likely work well if the months were considered as discrete blocks. > Thinking that one could have something like > > January 20xx February 20xx > Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa > 1 1 2 3 4 5 5 > 1 2 > 2 6 7 8 9 10 11 12 6 3 4 5 6 > 7 8 9 > 3 13 14 15 16 17 18 19 7 10 11 12 13 14 15 16 > 4 20 21 22 23 24 25 26 8 > 5 27 28 29 30 31 > > It is very useful for me to have the week numbers included. Have > learned some fascinating things (some months have 6 weeks in > them!) and the joys of formating (grin!). >> >> What do you think? I'm no expert with the calendar module, having used it as many times as (probably only) once before! However, skim-reading that page of the docs, I'd say that using the class to do the formatting is better than 'reinventing the wheel', and thus the question becomes: could the 'standard output' be post-processed into the form required? The outline above (ignoring month/year and day headings) is basically: weekNR gap weekNR ... as far across the page/screen as there is space/per the requirements. Given that a seems to be a fixed-length string, then you could indeed employ format() or f-strings with formatting. The fact that some months have fewer, or more, weeks to include, is largely irrelevant. The solution is a standard "merge" algorithm. (us 'silver surfers' cut our teeth on sorting, searching, and merging as the three pillars of "batch processing"). To print across the page/screen, we divide the available number of character-columns by the number of columns a single month's data requires (plus inter-month spacing) and this gives the maximum number of months the can be displayed 'across'. Dividing that number into the number of months within the period, will give the number of month-rows required to 'do the job'. A month-row could be defined as: 'as many lines as it takes to display every week of the month' (plus vertical separation/spacing). So, now the challenge is to print each output line, combining (laterally) all of the relevant data/dates, in such a manner that after every so-many output lines, the visual-blocks representing each individual month's dates will become apparent. The "merge" for line n (n:1-4~6) means to take the n-th from each month in the current month-row and format them into a single o/p line. If a month does not have an n-th week, then substitute the requisite number of spaces (unless handled by f-string/format() "width"). Print the o/p line... (yes, I omitted the weekNR-s, but adding them is trivial) > I was starting from what I understood (how to print 'a' year) working > to get closer to what I could use. Ncal allows me to display a > calendar except I'm restricted to a display only 3 months wide. More > than one month is relatively easy to display from present but not > from some other point. It would seem that the 80 column display > still rules supreme - - - - - and that's on a 1920 pixel wide monitor. It may be possible by sub-classing, to override this limit - or to re-implement the applicable method. I haven't looked! -- Regards =dn From PythonList at DancesWithMice.info Sun Aug 2 00:45:28 2020 From: PythonList at DancesWithMice.info (dn) Date: Sun, 2 Aug 2020 16:45:28 +1200 Subject: questions re: calendar module In-Reply-To: References: Message-ID: <9f8c6dd3-e4bb-de52-5d2f-9c33a9cf31f0@DancesWithMice.info> On 02/08/2020 12:42, o1bigtenor wrote: > On Sat, Aug 1, 2020 at 7:24 PM o1bigtenor wrote: >> On Sat, Aug 1, 2020 at 6:29 PM dn via Python-list >> wrote: >>> On 01/08/2020 23:36, o1bigtenor wrote: >>>> On Sat, Aug 1, 2020 at 1:29 AM dn via Python-list >>>> > wrote: >>>> On 31/07/2020 02:52, o1bigtenor wrote: >>>> > I regularly work in planning through multiple years at once. >>>> > This means that I like to have a lot of stuff available in a calendar >>>> > function. > Doing some searching - - - - sub-class really doesn't have a lot of 'official' > info. Perhaps an information source might be pointed out? You're further along that path than I! Sometimes the authors maintain an helpful web site/page, but I don't know. ... > Reading through more docs there is a possibility of using the 'format' > command. Would need to first come up with a way of describing the > months (with their attendant week numbers) and then describe a > formating system which would then enable a use of 'print' to achieve > the desired goal. > > Is this perhaps a good way of doing this? Outlined earlier. Question: what is the specification for 'first month' and 'last month' in the calendar? i) year-based: eg from 2020-2023, represents 48 months starting from Jan 2020 and continuing until Dec 2023 (inclusive). ii) month-based: there is no need to 'start' with January, or to finish in December, eg 2020-08 -> 2023-07 iii) week-based: (included because of evident import in your thinking), eg 2020-W26 -> 2023W25 - watch out for leap years! The last introduces the (very inconvenient) possibility of the first or last month being an incomplete 4~6 week 'block' and thus perhaps doubling the complexity of the "merge". However, it may be more convenient to translate weekNR into monthNR (and thus, name) than the reverse. (that's a question? not statement!) -- Regards =dn From cs at cskk.id.au Sun Aug 2 01:03:54 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 2 Aug 2020 15:03:54 +1000 Subject: Non IDE development strategy - what do others do that's fairly simple? In-Reply-To: References: Message-ID: <20200802050354.GA31104@cskk.homeip.net> On 29Jul2020 11:20, Chris Green wrote: >The existing code simply lives in ~/bin with a couple of modules in >~/bin/pymods (which directory is in my PYTHONPATH). > >I use mercurial for configuration management of the code, directly in >the ~/bin directory. This works fine for the sort of minor bug fixing >and updates that I do most of the time, I'm the only user so changing >the 'live' code isn't a major issue and I can always drop back to the >last working version using mercurial. Step 1 is to copy this sideways: keep the existing setup, but do the dev in a separate directory. The Mykefile in my personal dev directory has a "_home" target which installed the current state of play into my home directory. Once you have that, it is easy to make more clones to pursue things separately. >So, finally to the question, does anyone else have this command line >based sort of approach and, if so, what do they do to provide a >'development version' of a program in parallel with a working version? To that last part, I have a personal script "env-dev" (aliased as just "dev"), here: https://hg.sr.ht/~cameron-simpson/css/browse/bin/env-dev?rev=tip Feel free to copy it. Its purpose is to run the code from the current directory by prefixing various path environment variables, etc. Additionally it sources the file ".env.sh" in the current directory or ancestor for customisation beyond what it does automatically. It also utilises the venv if present. So to run the test code I go: $ dev the-programme ... and it uses the scripts and modules in my development directory. >I guess virtualenv (Python 2) and venv (Python 3) address this problem >but they do feel rather more complex than I actually need and I'm not >very clear how you move code from the virtual environment to 'live'. The nice thing about a virtualenv is that you can run specific Python versions with specific modules installed. It is easy to keep a few around. You utilise the virtualenv by invoking via the "python" executable within the virtualenv. That hooks up the virtualenv for the run. (Ignore "activate", it is a confusing source of pain IMO.) Moving to "production" is just a matter of maintaining a production virtualenv, using the python and modules you see fit for production. For example, I keep a virtualenv in the "venv" subdirectory of the development tree. I keep a personal, "production", virtualenv in ~/var/venv/3, and ~/var/venv/3/bin is towards the front of my $PATH. Typically you keep a "requirements.txt" file in your dev tree which specifies the modules you want. The filename is just a convention. The to update production you'd just go: ~/var/venv/3/bin/pip install -U -r requirements.txt where "~/var/venv/3/bin/pip" is _my_ production venv - adjust for your own, and "requirements.txt" is the reference file you want to use. >There's also the issue that I'm moving code from Python 2 to Python 3 >so which virtual environment should I use? Make one of each - that way it is easy to run your tests against either or both at once. So maybe (in your dev tree) make a "venv2" with a Python 2 virtualenv and a "venv3" with a Python 3 one, then you can run python out of each as required. Also, keep a make target to build the virtualenvs. Here's mine, which just does one based on "python3". dev = env-dev -d $. -x base_python = python3 venv_dir = $./venv venv_requirements = $./venv-requirements.txt venv_pip = $(venv_python) -m pip venv_python = $(venv_dir)/bin/python _venv: @[ -d '$(venv_dir)/' ] || set-x mkdir '$(venv_dir)' [ -x '$(venv_python)' ] || { \ set -xue \ rm -rf '$(venv_dir)' \ $(base_python) -m venv '$(venv_dir)' \ } $(dev) $(venv_pip) install -U wheel pip $(dev) $(venv_pip) install -U -r $(venv_requirements) Cheers, Cameron Simpson From sarvesh.poddar at yahoo.com Sun Aug 2 02:36:28 2020 From: sarvesh.poddar at yahoo.com (Sarvesh Poddar) Date: Sun, 2 Aug 2020 06:36:28 +0000 (UTC) Subject: Issue with Python module downloads from Library for a beginner Python coder. References: <1823668942.8336565.1596350188957.ref@mail.yahoo.com> Message-ID: <1823668942.8336565.1596350188957@mail.yahoo.com> Hi, I am currently using Python 3.8.5 with IDLE environment that comes pre-installed with the Python application. I am using the book "An Introduction to computer science" by John Zelle as my reference. The problem I am facing is "There is a python program named "graphics.py" that is used as reference in the book and I downloaded the python file from internet?(link to the file -?https://mcsp.wartburg.edu/zelle/python/graphics.py). I have kept this module in (C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32) and this is were my Python files also lie in C drive. The problem is that I am not able to import graphics.py file and when I try to do that following is the error I receive, Traceback (most recent call last): ? File "", line 1, in ? ? import graphics ? File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1 ? ? Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32? ? ? ? ? ?^SyntaxError: invalid syntax ?I have installed, uninstalled and then re-installed Python 3.8.5 multiple times but the problem remains. I did a thorough internet search and most of them suggested using sys path and following is the result, import sys>>> sys.path['', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\idlelib', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages'] When I write a different line -? (from import graphics *), this is the output: from graphics import *Traceback (most recent call last):? File "", line 1, in ? ? from graphics import *? File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1? ? Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32? ? ? ? ? ?^SyntaxError: invalid syntax Please do let me know if I am missing out something very basic. Thanks and I look forward. On Saturday, 1 August, 2020, 07:54:19 am IST, boB Stepp wrote: On Thu, Jul 30, 2020 at 9:24 AM Sarvesh Poddar via Python-list wrote: > I re-installed Python in my Windows system as the earlier one was not able to import modules... You do not provide much detail to diagnose what your problem(s) is(are).? By the "earlier one" is it the same version as the one you re-installed?? Were you able to run IDLE with the "earlier one"?? By not being able to import modules do you mean modules from Python's standard library?? Or do you mean installing third party libraries using pip? > ...But now I am not able to open IDLE after multiple tries. Have you looked in your start menu in the list of installed programs for Python?? If it is there did you expand it and see if there is an entry for IDLE?? How have you been trying (unsuccessfully) to open IDLE? -- boB From cs at cskk.id.au Sun Aug 2 05:38:30 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 2 Aug 2020 19:38:30 +1000 Subject: Issue with Python module downloads from Library for a beginner Python coder. In-Reply-To: <1823668942.8336565.1596350188957@mail.yahoo.com> References: <1823668942.8336565.1596350188957@mail.yahoo.com> Message-ID: <20200802093830.GA5785@cskk.homeip.net> Diverting replies to tutor at python.org, a better place for all this. It looks like the error is in graphics.py, not in your file. Your line: from graphics import * is syntacticly correct. Something has mangled the line breaks in your traceback, which here appears as: When I write a different line -? (from import graphics *), this is the output: from graphics import *Traceback (most recent call last):? File "", line 1, in ? ? from graphics import *? File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1? ? Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32? ? ? ? ? ?^SyntaxError: invalid syntax To me it appears that the syntax error in in graphics.py at line 1. I'd normally expect such a traceback to look more like this: File "", line 1, in ? ? from graphics import * File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1 ? Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32 ? ?^SyntaxError: invalid syntax In particular, the "^" would point to the place in the code where Python _noticed_ the syntax error. Is it possible that graphics.py contains that "Python 3.8.5 ...." text? So the traceback I've invented above says that _your_ import failed, but that was because of a failure in the file you were trying to import. BTW, it looks to me like your Python programmes (graphics.py and whatever other file you might be making) are inside the Python install. Normally you'd keep these elsewhere, for example in a folder such as: C:\Users\sarvesh\my-programmes Cheers, Cameron Simpson On 02Aug2020 06:36, Sarvesh Poddar wrote: >I am currently using Python 3.8.5 with IDLE environment that comes >pre-installed with the Python application. I am using the book "An >Introduction to computer science" by John Zelle as my reference. >The problem I am facing is "There is a python program named "graphics.py" that is used as reference in the book and I downloaded the python file from internet?(link to the file -?https://mcsp.wartburg.edu/zelle/python/graphics.py). I have kept this module in (C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32) and this is were my Python files also lie in C drive. The problem is that I am not able to import graphics.py file and when I try to do that following is the error I receive, >Traceback (most recent call last): >? File "", line 1, in ? ? import graphics >? File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1 >? ? Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32? ? ? ? ? ?^SyntaxError: invalid syntax >?I have installed, uninstalled and then re-installed Python 3.8.5 multiple times but the problem remains. I did a thorough internet search and most of them suggested using sys path and following is the result, > >import sys>>> sys.path['', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\idlelib', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages'] >When I write a different line -? (from import graphics *), this is the output: >from graphics import *Traceback (most recent call last):? File >"", line 1, in ? ? from graphics import *? File >"C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", >line 1? ? Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) >[MSC v.1926 32 bit (Intel)] on win32? ? ? ? ? ?^SyntaxError: invalid >syntax From cs at cskk.id.au Sun Aug 2 05:45:02 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 2 Aug 2020 19:45:02 +1000 Subject: Pygobject style question In-Reply-To: References: Message-ID: <20200802094502.GA55053@cskk.homeip.net> On 01Aug2020 13:32, Chris Green wrote: >Having (after lots of help from here, thank you) finally converted my >Python 2, gtk 2 program to Python 3 and pygobject gtk 3 I'm left with >a couple of what might be called style questions. > >I guess it's mostly down to what feels right to me but there may be >good reasons for choosing one way over another and, if so, I'd like to >know what they are. > >So, my original code had:- > ... > self.buffer = gtk.TextBuffer() > self.view = gtk.TextView(self.buffer) > >This doesn't work in gtk+ 3 (or at least I don't think it does, the >converter script changed it) and there seem to be several ways of >doing it now:- > > self.buffer = Gtk.TextBuffer() > self.view = Gtk.TextView(buffer = self.buffer) I like this first one. It is least verbose, and it makes the buffer before it makes the view, which I prefer. If they are all legal and all correct and equivalent, go with the one which is easiest to read. Cheers, Cameron Simpson From o1bigtenor at gmail.com Sun Aug 2 07:26:10 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Sun, 2 Aug 2020 06:26:10 -0500 Subject: questions re: calendar module In-Reply-To: <1697f32a-8f3b-76ce-e10b-04e7ae11b448@DancesWithMice.info> References: <1697f32a-8f3b-76ce-e10b-04e7ae11b448@DancesWithMice.info> Message-ID: On Sat, Aug 1, 2020 at 11:33 PM dn via Python-list wrote: > > On 02/08/2020 12:24, o1bigtenor wrote: > > On Sat, Aug 1, 2020 at 6:29 PM dn via Python-list > > wrote: > >> On 01/08/2020 23:36, o1bigtenor wrote: > >>> On Sat, Aug 1, 2020 at 1:29 AM dn via Python-list > >>> > wrote: > >>> On 31/07/2020 02:52, o1bigtenor wrote: > >>> > I regularly work in planning through multiple years at once. > ... > > >>> calendar starting > >>> from a date that is 3 years in time frame. > >> ... > >> > >>> I would like to show something like 2024 through the end of 2028. > ... > > It is very disappointing - - - -suggests that thinking outside the space of > > one year is somehow deprecated. Frustrated when what you do demands > > that you think in longer periods of time (and yet have to function within > > the week as well). > > I agree - says he who tactically changes his 'events calendar' every > half-year, to ensure that there is more than a six-month planning > horizon. Sister-in-Law has just this morning blocked-out dates for > family gatherings ("you are expected to attend!") for not just > Christmas/December, but into Jan, Feb, and Easter holidays (Uni > vacation) next year; because U.David is but a mere-male and needs lots > of 'extra help'... > (and because she knows 'the system', and has something similar at home!) > (LOL) something like that except what I'm working with also needs the to the day planning as well as the long term stuff. Did some 'counting' here. there are from 8 to 14 discrete event times for a group within a 'period' (presently a year but that may change) and there are multiple groups. The event timing (spacing) is mostly similar. There is also a need for multi-event (think year) planning as well. I could see a busy theater organisation doing a similar kind of planning. > > >> There are other helper functions. Also, we are invited to sub-class. > > > > Hmmmmmm - - - will have to investigate that. > > I'm thinking that the month function/method might be a better way to go > (than year-at-a-time). > > For visualisation (per next para), have you tried computing a month in > the REPL and then str.split()-ting the output into separate week-strings? > > > >> Might it be possible to generate multiple year (or month) groups, split > >> them by line, and then reassemble line-by-line to produce the width and > >> temporal length required? > > > > Likely work well if the months were considered as discrete blocks. > > Thinking that one could have something like > > > > January 20xx February 20xx > > Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa > > 1 1 2 3 4 5 5 > > 1 2 > > 2 6 7 8 9 10 11 12 6 3 4 5 6 > > 7 8 9 > > 3 13 14 15 16 17 18 19 7 10 11 12 13 14 15 16 > > 4 20 21 22 23 24 25 26 8 > > 5 27 28 29 30 31 > > > > It is very useful for me to have the week numbers included. Have > > learned some fascinating things (some months have 6 weeks in > > them!) and the joys of formating (grin!). > >> > >> What do you think? > > I'm no expert with the calendar module, having used it as many times as > (probably only) once before! > > However, skim-reading that page of the docs, I'd say that using the > class to do the formatting is better than 'reinventing the wheel', and > thus the question becomes: could the 'standard output' be post-processed > into the form required? > > The outline above (ignoring month/year and day headings) is basically: > > weekNR gap weekNR month> ... > > as far across the page/screen as there is space/per the requirements. > > Given that a seems to be a fixed-length string, then > you could indeed employ format() or f-strings with formatting. > > The fact that some months have fewer, or more, weeks to include, is > largely irrelevant. The solution is a standard "merge" algorithm. (us > 'silver surfers' cut our teeth on sorting, searching, and merging as the > three pillars of "batch processing"). The differences become very relevant for formatting. A month that has 4 weeks takes a different amount of vertical space than a month that has 6 weeks. > > To print across the page/screen, we divide the available number of > character-columns by the number of columns a single month's data > requires (plus inter-month spacing) and this gives the maximum number of > months the can be displayed 'across'. > > Dividing that number into the number of months within the period, will > give the number of month-rows required to 'do the job'. > > A month-row could be defined as: 'as many lines as it takes to display > every week of the month' (plus vertical separation/spacing). > > So, now the challenge is to print each output line, combining > (laterally) all of the relevant data/dates, in such a manner that after > every so-many output lines, the visual-blocks representing each > individual month's dates will become apparent. > > The "merge" for line n (n:1-4~6) means to take the n-th > from each month in the current month-row and format them into a single > o/p line. If a month does not have an n-th week, then substitute the > requisite number of spaces (unless handled by f-string/format() > "width"). Print the o/p line... > (yes, I omitted the weekNR-s, but adding them is trivial) > > > > I was starting from what I understood (how to print 'a' year) working > > to get closer to what I could use. Ncal allows me to display a > > calendar except I'm restricted to a display only 3 months wide. More > > than one month is relatively easy to display from present but not > > from some other point. It would seem that the 80 column display > > still rules supreme - - - - - and that's on a 1920 pixel wide monitor. > > It may be possible by sub-classing, to override this limit - or to > re-implement the applicable method. I haven't looked! Interesting ideas - - - - time for more digging! Thanks From 2QdxY4RzWzUUiLuE at potatochowder.com Sun Aug 2 08:04:06 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Sun, 2 Aug 2020 07:04:06 -0500 Subject: questions re: calendar module In-Reply-To: References: <1697f32a-8f3b-76ce-e10b-04e7ae11b448@DancesWithMice.info> Message-ID: <20200802120406.GB10878@scrozzle> On 2020-08-02 at 06:26:10 -0500, o1bigtenor wrote: > On Sat, Aug 1, 2020 at 11:33 PM dn via Python-list > wrote: > > The fact that some months have fewer, or more, weeks to include, is > > largely irrelevant. The solution is a standard "merge" algorithm. (us > > 'silver surfers' cut our teeth on sorting, searching, and merging as the > > three pillars of "batch processing"). > > The differences become very relevant for formatting. A month that has > 4 weeks takes a different amount of vertical space than a month that > has 6 weeks. Back in high school, we wrote a FORTRAN program to multiply matrixes, which wasn't too bad, because our FORTRAN library came with a matrix multiplier. The real problem was formatting the output. In FORTRAN. With crude "graphics" (made from plus signs, minus signs, and upper case "I"s) for the matrix brackets. And the multiplication and equality operators were supposed to be vertically centered in a horizontally oriented equation. Don't forget, matrix multiplication usually involves three differently shaped matrixes. The equation with the green check mark on https://www.mathsisfun.com/algebra/matrix-multiplying.html is a reasonable facsimile of what our output was supposed to look like. From Richard at Damon-Family.org Sun Aug 2 09:26:12 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 2 Aug 2020 09:26:12 -0400 Subject: questions re: calendar module In-Reply-To: References: <1697f32a-8f3b-76ce-e10b-04e7ae11b448@DancesWithMice.info> Message-ID: <040d5eff-f775-4112-416c-4617b29c16f8@Damon-Family.org> On 8/2/20 7:26 AM, o1bigtenor wrote: > The differences become very relevant for formatting. A month that has > 4 weeks takes a different amount of vertical space than a month that > has 6 weeks. The only month that has only 4 weeks would be Febuary, on non-lead years, that starts on Sunday (or whatever you consider the first day of your week). Yes, the 5 to 6 variation can cause formatting problems, especially since the 6 week months are rare enough (only 30 days months beginning on the last day of the week, or 31 day months beginning on the last 2 days, so around 1 in 5 or so) that you may want to trim them out when possible. I would likely just build the formatter to start by assuming 6 week months, and then near the end, after stacking the side by side months, see if it can be trimmed out (easier to remove at the end then add if needed) -- Richard Damon From __peter__ at web.de Sun Aug 2 10:42:19 2020 From: __peter__ at web.de (Peter Otten) Date: Sun, 02 Aug 2020 16:42:19 +0200 Subject: questions re: calendar module References: <1697f32a-8f3b-76ce-e10b-04e7ae11b448@DancesWithMice.info> <040d5eff-f775-4112-416c-4617b29c16f8@Damon-Family.org> Message-ID: Richard Damon wrote: > I would likely just build the formatter to start by assuming 6 week > months, and then near the end, after stacking the side by side months, > see if it can be trimmed out (easier to remove at the end then add if > needed) If you like some itertools gymnastics: you can format square boxes of text with two nested zip_longest(): import itertools def gen_lines(blurbs, columncount, columnwidth): first = True for row in itertools.zip_longest( *[iter(blurbs)] * columncount, fillvalue="" ): if first: first = False else: yield "" for columns in itertools.zip_longest( *[blurb for blurb in row], fillvalue="" ): yield " ".join( column.ljust(columnwidth) for column in columns ).rstrip() BLURBS = [ "aaa\aaaaaaaa\naaaaaaa", "bbbb\nbb\nbbbbbbb\nbb\nbbbbb", "ccc", "ddd\nddd" ] BLURBS = [blurb.splitlines() for blurb in BLURBS] for line in gen_lines(BLURBS, 2, 10): print(line) print("\n") for line in gen_lines(BLURBS, 3, 10): print(line) print("\n") As calendar provides formatted months with TextCalendar.formatmonth() you can easily feed that to gen_lines(): import calendar def monthrange(start, stop): y, m = start start = y * 12 + m - 1 y, m = stop stop = y * 12 + m - 1 for ym0 in range(start, stop): y, m0 = divmod(ym0, 12) yield y, m+1 tc = calendar.TextCalendar() months = ( tc.formatmonth(*month).splitlines() for month in monthrange((2020, 10), (2021, 3)) ) for line in gen_lines(months, 3, 21): print(line) However, I found reusing the building blocks from calendar to add week indices harder than expected. I ended up using brute force and am not really satisfied with the result. You can have a look: $ cat print_cal.py #!/usr/bin/python3 """Print a calendar with an arbitrary number of months in parallel columns. """ import calendar import datetime import functools import itertools SEP_WIDTH = 4 def get_weeknumber(year, month, day=1): """Week of year for date (year, month, day). """ return datetime.date(year, month, day).isocalendar()[1] class MyTextCalendar(calendar.TextCalendar): """Tweak TextCalendar to prepend weeks with week number. """ month_width = 24 def weeknumber(self, year, month, day=1): """Week of year or calendar-specific week index for a given date. """ return get_weeknumber(year, month, max(day, 1)) def formatmonthname(self, theyear, themonth, width, withyear=True): return " " + super().formatmonthname( theyear, themonth, width, withyear=withyear ) def formatweekheader(self, width): return " " + super().formatweekheader(width) def formatweek(self, theweek, width): week, theweek = theweek return "%2d " % week + ' '.join( self.formatday(d, wd, width) for (d, wd) in theweek ) def monthdays2calendar(self, year, month): return [ (self.weeknumber(year, month, week[0][0]), week) for week in super().monthdays2calendar(year, month) ] class MyIndexedTextCalendar(MyTextCalendar): """Replace week number with an index. """ def __init__(self, firstweekday=0): super().__init__(firstweekday) self.weekindices = itertools.count(1) @functools.lru_cache(maxsize=1) def get_index(self, weeknumber): """Convert the week number into an index. """ return next(self.weekindices) def weeknumber(self, year, month, day=1): return self.get_index(super().weeknumber(year, month, day)) def monthindex(year, month): """Convert year, month to a single integer. >>> monthindex(2020, 3) 24242 >>> t = 2021, 7 >>> t == monthtuple(monthindex(*t)) True """ return 12 * year + month - 1 def monthtuple(index): """Inverse of monthindex(). """ year, month0 = divmod(index, 12) return year, month0 + 1 def yearmonth(year_month): """Convert yyyy-mm to a (year, month) tuple. >>> yearmonth("2020-03") (2020, 3) """ return tuple(map(int, year_month.split("-"))) def months(first, last): """Closed interval of months. >>> list(months((2020, 3), (2020, 5))) [(2020, 3), (2020, 4), (2020, 5)] """ for monthnum in range(monthindex(*first), monthindex(*last)+1): yield monthtuple(monthnum) def dump_calendar(first, last, months_per_row, cal=MyTextCalendar()): """Print calendar from `first` month to and including `last` month. >>> dump_calendar((2020, 11), (2021, 1), 2) November 2020 December 2020 Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 44 1 49 1 2 3 4 5 6 45 2 3 4 5 6 7 8 50 7 8 9 10 11 12 13 46 9 10 11 12 13 14 15 51 14 15 16 17 18 19 20 47 16 17 18 19 20 21 22 52 21 22 23 24 25 26 27 48 23 24 25 26 27 28 29 53 28 29 30 31 49 30 January 2021 Mo Tu We Th Fr Sa Su 53 1 2 3 1 4 5 6 7 8 9 10 2 11 12 13 14 15 16 17 3 18 19 20 21 22 23 24 4 25 26 27 28 29 30 31 """ for line in gen_calendar(first, last, months_per_row, cal): print(line) def gen_calendar(first, last, months_per_row, cal, *, sep=" "*SEP_WIDTH): """Generate lines for calendar covering months from `first` including `last` with `months_per_row` in parallel. """ month_blurbs = (cal.formatmonth(*month) for month in months(first, last)) for month_row in itertools.zip_longest( *[month_blurbs] * months_per_row, fillvalue="" ): for columns in itertools.zip_longest( *[month.splitlines() for month in month_row], fillvalue=""): yield sep.join( column.ljust(cal.month_width) for column in columns ).rstrip() yield "" def main(): """Command line interface. """ import argparse import shutil parser = argparse.ArgumentParser() parser.add_argument( "first", type=yearmonth, help="First month (format yyyy-mm) in calendar" ) parser.add_argument( "last", type=yearmonth, help="Last month (format yyyy-mm) in calendar" ) parser.add_argument( "--weeknumber", choices=["none", "iso", "index"], default="iso" ) parser.add_argument("--months-per-row", type=int) args = parser.parse_args() if args.weeknumber == "none": cal = calendar.TextCalendar() cal.month_width = 21 elif args.weeknumber == "iso": cal = MyTextCalendar() elif args.weeknumber == "index": cal = MyIndexedTextCalendar() else: assert False months_per_row = args.months_per_row if months_per_row is None: size = shutil.get_terminal_size() months_per_row = size.columns // (cal.month_width + SEP_WIDTH) dump_calendar(args.first, args.last, months_per_row, cal) if __name__ == "__main__": main() $ ./print_cal.py 2020-10 2021-5 --weeknumber index October 2020 November 2020 December 2020 January 2021 Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 1 1 2 3 4 5 1 10 1 2 3 4 5 6 14 1 2 3 2 5 6 7 8 9 10 11 6 2 3 4 5 6 7 8 11 7 8 9 10 11 12 13 15 4 5 6 7 8 9 10 3 12 13 14 15 16 17 18 7 9 10 11 12 13 14 15 12 14 15 16 17 18 19 20 16 11 12 13 14 15 16 17 4 19 20 21 22 23 24 25 8 16 17 18 19 20 21 22 13 21 22 23 24 25 26 27 17 18 19 20 21 22 23 24 5 26 27 28 29 30 31 9 23 24 25 26 27 28 29 14 28 29 30 31 18 25 26 27 28 29 30 31 10 30 February 2021 March 2021 April 2021 May 2021 Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 19 1 2 3 4 5 6 7 23 1 2 3 4 5 6 7 27 1 2 3 4 31 1 2 20 8 9 10 11 12 13 14 24 8 9 10 11 12 13 14 28 5 6 7 8 9 10 11 32 3 4 5 6 7 8 9 21 15 16 17 18 19 20 21 25 15 16 17 18 19 20 21 29 12 13 14 15 16 17 18 33 10 11 12 13 14 15 16 22 22 23 24 25 26 27 28 26 22 23 24 25 26 27 28 30 19 20 21 22 23 24 25 34 17 18 19 20 21 22 23 27 29 30 31 31 26 27 28 29 30 35 24 25 26 27 28 29 30 36 31 $ From bob at mellowood.ca Sun Aug 2 12:59:47 2020 From: bob at mellowood.ca (Bob van der Poel) Date: Sun, 2 Aug 2020 09:59:47 -0700 Subject: Issue with Python module downloads from Library for a beginner Python coder. In-Reply-To: <1823668942.8336565.1596350188957@mail.yahoo.com> References: <1823668942.8336565.1596350188957.ref@mail.yahoo.com> <1823668942.8336565.1596350188957@mail.yahoo.com> Message-ID: Do you have tkinter installed? The graphics.py module needs it to run. On Sat, Aug 1, 2020 at 11:36 PM Sarvesh Poddar via Python-list < python-list at python.org> wrote: > Hi, > I am currently using Python 3.8.5 with IDLE environment that comes > pre-installed with the Python application. I am using the book "An > Introduction to computer science" by John Zelle as my reference. > The problem I am facing is "There is a python program named "graphics.py" > that is used as reference in the book and I downloaded the python file from > internet (link to the file - > https://mcsp.wartburg.edu/zelle/python/graphics.py). I have kept this > module in (C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32) and > this is were my Python files also lie in C drive. The problem is that I am > not able to import graphics.py file and when I try to do that following is > the error I receive, > Traceback (most recent call last): > File "", line 1, in import graphics > File > "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", > line 1 > Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 > 32 bit (Intel)] on win32 ^SyntaxError: invalid syntax > I have installed, uninstalled and then re-installed Python 3.8.5 multiple > times but the problem remains. I did a thorough internet search and most of > them suggested using sys path and following is the result, > > import sys>>> sys.path['', > 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\idlelib', > 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip', > 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs', > 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib', > 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32', > 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages'] > When I write a different line - (from import graphics *), this is the > output: > from graphics import *Traceback (most recent call last): File > "", line 1, in from graphics import * File > "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", > line 1 Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC > v.1926 32 bit (Intel)] on win32 ^SyntaxError: invalid syntax > Please do let me know if I am missing out something very basic. > Thanks and I look forward. On Saturday, 1 August, 2020, 07:54:19 am > IST, boB Stepp wrote: > > On Thu, Jul 30, 2020 at 9:24 AM Sarvesh Poddar via Python-list > wrote: > > > I re-installed Python in my Windows system as the earlier one was not > able to import modules... > > You do not provide much detail to diagnose what your problem(s) > is(are). By the "earlier one" is it the same version as the one you > re-installed? Were you able to run IDLE with the "earlier one"? By > not being able to import modules do you mean modules from Python's > standard library? Or do you mean installing third party libraries > using pip? > > > ...But now I am not able to open IDLE after multiple tries. > > Have you looked in your start menu in the list of installed programs > for Python? If it is there did you expand it and see if there is an > entry for IDLE? How have you been trying (unsuccessfully) to open > IDLE? > > > -- > boB > > -- > https://mail.python.org/mailman/listinfo/python-list > -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From cl at isbd.net Sun Aug 2 04:57:29 2020 From: cl at isbd.net (Chris Green) Date: Sun, 2 Aug 2020 09:57:29 +0100 Subject: Non IDE development strategy - what do others do that's fairly simple? References: <20200802050354.GA31104@cskk.homeip.net> Message-ID: Cameron Simpson wrote: [snip fantastic explanation] Cameron, thanks for that long and detailed explanation. -- Chris Green ? From tjreedy at udel.edu Sun Aug 2 14:44:15 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 2 Aug 2020 14:44:15 -0400 Subject: Issue with Python module downloads from Library for a beginner Python coder. In-Reply-To: <1823668942.8336565.1596350188957@mail.yahoo.com> References: <1823668942.8336565.1596350188957.ref@mail.yahoo.com> <1823668942.8336565.1596350188957@mail.yahoo.com> Message-ID: On 8/2/2020 2:36 AM, Sarvesh Poddar via Python-list wrote: [I downloaded] https://mcsp.wartburg.edu/zelle/python/graphics.py) I have unmangled the traceback and added explanations. > Traceback (most recent call last): > ?File "", line 1, in > ? ? import graphics You typed this in IDLE Shell in response to the >>> prompt. > ?File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1 This says that you put the file in the same directory as python.exe. It should better be in ".../Lib/site-packages" or in a directory in "/Users/". None the less, the import worked. > ? ?Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32 > ?? ? ? ? ?^ > SyntaxError: invalid syntax This says that the first line of graphics.py begins with "Python 3.8.5..." This is the startup message printed by python.exe when run in interactive mode, and by IDLE's interactive Shell. It is text, not python code. It is not the first line of the file at that link (I checked). Look at the file on your disk and check its first line. You may have to put '%appdata%' in the directory box if the /User//appdata directory is hidden on your machine. > ?I have installed, uninstalled and then re-installed Python 3.8.5 multiple times but the problem remains. > I did a thorough internet search and most of them suggested using sys path and following is the result, This suggestion is for when the import fails because the module is not found. In your case, it was found and the import process started. > import sys>>> sys.path['', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\idlelib', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages'] > When I write a different line -? (from import graphics *), this is the output: > from graphics import *Traceback (most recent call last):? File "", line 1, in ? ? from graphics import *? File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1? ? Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32? ? ? ? ? ?^SyntaxError: invalid syntax Same bad first line, same error. -- Terry Jan Reedy From eryksun at gmail.com Sun Aug 2 15:20:28 2020 From: eryksun at gmail.com (Eryk Sun) Date: Sun, 2 Aug 2020 14:20:28 -0500 Subject: Downloading Python In-Reply-To: <53d761b5-1ac3-4dc8-1746-f8ec39e59624@mrabarnett.plus.com> References: <53d761b5-1ac3-4dc8-1746-f8ec39e59624@mrabarnett.plus.com> Message-ID: On 8/1/20, MRAB wrote: > On 2020-08-01 21:58, Barry wrote: >> On 31-7-2020 22:10, Tanmay Shah wrote: >>> >>> After downloading Python 3.8.5 IDLE, an error message popped up, >>> saying the code execution cannot proceed because python38.dll was >>> not found. What should I do in order to use the Python interpreter? >> >> I have never had to reboot windows when installing python. >> Was I lucky? > > No. I've never had a problem with it either. I don't know what "[a]fter downloading Python 3.8.5 IDLE" means to the OP. For a successful installation of Python 3.8 using an "executable" or "web-based" installer from python.org [1], the file "python38.dll" will be installed in the same directory as python.exe and will thus always be found. [1] https://www.python.org/downloads/release/python-385 From Richard at Damon-Family.org Sun Aug 2 15:22:35 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 2 Aug 2020 15:22:35 -0400 Subject: questions re: calendar module In-Reply-To: References: Message-ID: <3058c966-2650-0ce9-65a4-63e7b350b608@Damon-Family.org> On 8/2/20 12:58 PM, Dennis Lee Bieber wrote: > Yet follows what most /print/ calendars contain (though some companies > put the last four months of the current year in a 4-up page, before doing > one month per page for the new year). "Daily planner" journals also tend to > cover just one year, from Jan 1 to Dec 31. Actually, now many calendars are 15 or 16 months, starting in September or October and go through the following December (maybe with a planning calendar page giving a compressed view of the next 4 or 12 months of the following year. There also are 'Academic' calendars that might start in July or August and go to maybe the following September -- Richard Damon From torque.india at gmail.com Sun Aug 2 16:06:47 2020 From: torque.india at gmail.com (OmPs) Date: Mon, 3 Aug 2020 01:36:47 +0530 Subject: Downloading Python In-Reply-To: References: <53d761b5-1ac3-4dc8-1746-f8ec39e59624@mrabarnett.plus.com> Message-ID: It's quite possible you have a version mismatch. Try installing python 3.8 first. BtW, before the would you like to check what version python command reports. Sorry for top post. I am sending from my phone and bottom post pretty confusing here. On Mon, Aug 3, 2020, 00:56 Eryk Sun wrote: > On 8/1/20, MRAB wrote: > > On 2020-08-01 21:58, Barry wrote: > >> On 31-7-2020 22:10, Tanmay Shah wrote: > >>> > >>> After downloading Python 3.8.5 IDLE, an error message popped up, > >>> saying the code execution cannot proceed because python38.dll was > >>> not found. What should I do in order to use the Python interpreter? > >> > >> I have never had to reboot windows when installing python. > >> Was I lucky? > > > > No. I've never had a problem with it either. > > I don't know what "[a]fter downloading Python 3.8.5 IDLE" means to the > OP. For a successful installation of Python 3.8 using an "executable" > or "web-based" installer from python.org [1], the file "python38.dll" > will be installed in the same directory as python.exe and will thus > always be found. > > [1] https://www.python.org/downloads/release/python-385 > -- > https://mail.python.org/mailman/listinfo/python-list > From o1bigtenor at gmail.com Sun Aug 2 17:16:10 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Sun, 2 Aug 2020 16:16:10 -0500 Subject: questions re: calendar module In-Reply-To: <3058c966-2650-0ce9-65a4-63e7b350b608@Damon-Family.org> References: <3058c966-2650-0ce9-65a4-63e7b350b608@Damon-Family.org> Message-ID: On Sun, Aug 2, 2020 at 2:28 PM Richard Damon wrote: > > On 8/2/20 12:58 PM, Dennis Lee Bieber wrote: > > Yet follows what most /print/ calendars contain (though some companies > > put the last four months of the current year in a 4-up page, before doing > > one month per page for the new year). "Daily planner" journals also tend to > > cover just one year, from Jan 1 to Dec 31. > > Actually, now many calendars are 15 or 16 months, starting in September > or October and go through the following December (maybe with a planning > calendar page giving a compressed view of the next 4 or 12 months of the > following year. > > There also are 'Academic' calendars that might start in July or August > and go to maybe the following September > Hmmmmmm - - - - one of the problems with slicing and dicing on quotes - - - - stuff gets lost. I had asked for at least 2.5 years worth of calendar - - - - preferable even more. A previous iteration of this project which I am using (until either I can find or make better) is at present sitting with some 60 months of time showing. Sorry - - - - even 18 months - - - - well its like stepping into a nuclear bomb argument with a water pistol. Regards From o1bigtenor at gmail.com Sun Aug 2 17:38:38 2020 From: o1bigtenor at gmail.com (o1bigtenor) Date: Sun, 2 Aug 2020 16:38:38 -0500 Subject: questions re: calendar module In-Reply-To: References: Message-ID: On Sun, Aug 2, 2020 at 2:08 PM Dennis Lee Bieber wrote: > > On Sat, 1 Aug 2020 19:24:41 -0500, o1bigtenor > declaimed the following: > > > > >It is very disappointing - - - -suggests that thinking outside the space of > >one year is somehow deprecated. Frustrated when what you do demands > >that you think in longer periods of time (and yet have to function within > >the week as well). > > Yet follows what most /print/ calendars contain (though some companies > put the last four months of the current year in a 4-up page, before doing > one month per page for the new year). "Daily planner" journals also tend to > cover just one year, from Jan 1 to Dec 31. > > If you are willing to view the calendar in a browser, using > calendar.HTMLCalendar() may be the fastest way toward what you intend. You > could start, perhaps, with generating full year calendars (setting the > width to 12 months), and then package them as rows into an outer table > (granted, you won't get week numbers this way, but it may be a starting > point). > -=-=-=- I understand that what I'm trying to do isn't 'normal'. I do understand that most businesses only work with any detail in one year at a time. I got it!!!! That doesn't work for my situation. I tried to do this planning using 'typical software'. I about went crazy when I was trying to work looking back at one year, working in the present year and needing to drop details into the next year. (I need to work more than one year forward as well!) I found some very old software (cal), from the days of Unix V, with its update that is itself (ncal) over 10 years old. This project started when I found that I could get cal to display a LARGE amount of months except I was limited to a 80 column display. I was moaning to a friendof mine one time looking into how I could change the display from an 80 column limit to some at least 160 if not 192 columns. One day he surprised me by sending me code which got this idea started. When he found out that week numbers were very useful - - - - they were included. He died about 3 months ago without ever finishing the project. He liked to write in Perl albeit was comfortable in lots of other languages. I had talked to him about learning Python. So this project morphed from being in Perl (5) to being in Python. This existing code already allows me to display lots of months at a time with enough months width so that my terminal is 'full'. What's not there is the possibility of specifying a starting point to this calendar. At present the calendar only works from today (both backward and forward). There are also a few small display things I would like to tweak but the bulk of the idea works very well. Maybe I should be learning Perl (7) instead so I could just extend his work but Python seems to have more other things that it 'works' on so even though this makes for more work I have chosen this direction. HTH From Richard at Damon-Family.org Sun Aug 2 19:14:39 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 2 Aug 2020 19:14:39 -0400 Subject: questions re: calendar module In-Reply-To: References: Message-ID: <7295f5b7-08a5-60ea-66f9-60a458103400@Damon-Family.org> On 8/2/20 5:38 PM, o1bigtenor wrote: > On Sun, Aug 2, 2020 at 2:08 PM Dennis Lee Bieber wrote: >> On Sat, 1 Aug 2020 19:24:41 -0500, o1bigtenor >> declaimed the following: >> >>> It is very disappointing - - - -suggests that thinking outside the space of >>> one year is somehow deprecated. Frustrated when what you do demands >>> that you think in longer periods of time (and yet have to function within >>> the week as well). >> Yet follows what most /print/ calendars contain (though some companies >> put the last four months of the current year in a 4-up page, before doing >> one month per page for the new year). "Daily planner" journals also tend to >> cover just one year, from Jan 1 to Dec 31. >> >> If you are willing to view the calendar in a browser, using >> calendar.HTMLCalendar() may be the fastest way toward what you intend. You >> could start, perhaps, with generating full year calendars (setting the >> width to 12 months), and then package them as rows into an outer table >> (granted, you won't get week numbers this way, but it may be a starting >> point). >> -=-=-=- > I understand that what I'm trying to do isn't 'normal'. > I do understand that most businesses only work with any detail in one year > at a time. > > I got it!!!! > > That doesn't work for my situation. > > I tried to do this planning using 'typical software'. I about went > crazy when I was > trying to work looking back at one year, working in the present year > and needing > to drop details into the next year. (I need to work more than one year forward > as well!) > > I found some very old software (cal), from the days of Unix V, with its update > that is itself (ncal) over 10 years old. > > This project started when I found that I could get cal to display a > LARGE amount > of months except I was limited to a 80 column display. I was moaning > to a friendof mine one time looking into how I could change the display from an > 80 column limit to some at least 160 if not 192 columns. One day he surprised > me by sending me code which got this idea started. When he found out that > week numbers were very useful - - - - they were included. He died about 3 > months ago without ever finishing the project. > > He liked to write in Perl albeit was comfortable in lots of other languages. > I had talked to him about learning Python. > So this project morphed from being in Perl (5) to being in Python. > > This existing code already allows me to display lots of months at a time > with enough months width so that my terminal is 'full'. What's not there is > the possibility of specifying a starting point to this calendar. At present > the calendar only works from today (both backward and forward). There > are also a few small display things I would like to tweak but the bulk of > the idea works very well. > > Maybe I should be learning Perl (7) instead so I could just extend his > work but Python seems to have more other things that it 'works' on so > even though this makes for more work I have chosen this direction. > > HTH If you don't need to produce these often, then the fastest method may be to just build up on a spread sheet, probably less than a half hour of work if you are at all familiar with what you are doing. The second method would be to write a program to do this. Maybe use the 'canned' routine as a base for the program, but accept that your actual desired output is unusual enough it won't be something you can get with a single call. Maybe accept you can't get exactly what you want, so be willing to accept something close. Maybe the chart goes from January of your start year to December of the final year if the library likes doing a full year at a time. -- Richard Damon From Gronicus at SGA.Ninja Sun Aug 2 21:52:03 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sun, 2 Aug 2020 21:52:03 -0400 Subject: Python running in the Command Prompt Window questions Message-ID: <000001d66938$b03f6cc0$10be4640$@SGA.Ninja> When I double click on a .py file, it executes at the command prompt with black background and small white font. Is there python code to change the font size and background color? ======================================= FootNote: Would it be ironic if Popeye?s chicken was fried in Olive Oil? From sarvesh.poddar at yahoo.com Mon Aug 3 01:00:12 2020 From: sarvesh.poddar at yahoo.com (Sarvesh Poddar) Date: Mon, 3 Aug 2020 05:00:12 +0000 (UTC) Subject: Issue with Python module downloads from Library for a beginner Python coder. In-Reply-To: References: <1823668942.8336565.1596350188957.ref@mail.yahoo.com> <1823668942.8336565.1596350188957@mail.yahoo.com> Message-ID: <1393966639.8513726.1596430812445@mail.yahoo.com> Hello Dennis, Sorry for my copy-paste error and thanks for highlighting the same. I will make sure that from next time I will maintain the line breaks. I tried opening it in CMD and it did open with the skewed triangle figure although I am still not able to use it in my IDLE environment. Unfortunately, I am not able to move ahead with my Python classes because of this, as it specifically asks to import the module before proceeding. I saved the file in tkinter folder now and receive the same problem, >>> import graphicsTraceback (most recent call last):? File "", line 1, in ? ? import graphicsModuleNotFoundError: No module named 'graphics' Location of the file - C:\Program Files (x86)\Lib\tkinter Didn't work out. On Monday, 3 August, 2020, 12:47:26 am IST, Dennis Lee Bieber wrote: On Sun, 2 Aug 2020 06:36:28 +0000 (UTC), Sarvesh Poddar via Python-list declaimed the following: > Hi, >I am currently using Python 3.8.5 with IDLE environment that comes pre-installed with the Python application. I am using the book "An Introduction to computer science" by John Zelle as my reference. >The problem I am facing is "There is a python program named "graphics.py" that is used as reference in the book and I downloaded the python file from internet?(link to the file -?https://mcsp.wartburg.edu/zelle/python/graphics.py). I have kept this module in (C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32) and this is were my Python files also lie in C drive. The problem is that I am not able to import graphics.py file and when I try to do that following is the error I receive, >Traceback (most recent call last): >? File "", line 1, in ? ? import graphics >? File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1 >? ? Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32? ? ? ? ? ?^SyntaxError: invalid syntax >?I have installed, uninstalled and then re-installed Python 3.8.5 multiple times but the problem remains. I did a thorough internet search and most of them suggested using sys path and following is the result, > ??? In future, you might want to ensure your cut&paste and/or posting client, maintains line breaks -- many of your pastes seem to "unwrap" stuff... >When I write a different line -? (from import graphics *), this is the output: >from graphics import *Traceback (most recent call last):? File "", line 1, in ? ? from graphics import *? File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1? ? Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32? ? ? ? ? ?^SyntaxError: invalid syntax ... such as the above, which appears to have turned something like 7 lines of output into one long string/paragraph. ??? My only suggestion is to drop OUT of IDLE or whatever, and open a Windows command shell... and try running a script from that shell. I note that this library makes use of Tkinter -- which is also used by IDLE. The two uses may be causing complications. Going to a command shell avoids that. -=-=- C:\Users\Wulfraed\Downloads>type testgraphics.py import graphics print(dir(graphics)) C:\Users\Wulfraed\Downloads>python testgraphics.py ['BAD_OPTION', 'Circle', 'DEFAULT_CONFIG', 'Entry', 'GraphWin', 'GraphicsError', 'GraphicsObject', 'Image', 'Line', 'OBJ_ALREADY_DRAWN', 'Oval', 'Point', 'Polygon', 'Rectangle', 'Text', 'Transform', 'UNSUPPORTED_METHOD', '_BBox', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '__version__', '_root', '_update_lasttime', 'color_rgb', 'os', 'sys', 'test', 'time', 'tk', 'update'] C:\Users\Wulfraed\Downloads> -=-=- ??? Heck... from the command shell, navigate to the directory in which you saved graphics.py and enter -=-=- C:\Users\Wulfraed\Downloads>python graphics.py -=-=- ??? On my system, that pops up a small window with skewed triangle, some text, and a grey input field. -- ??? Wulfraed? ? ? ? ? ? ? ? Dennis Lee Bieber? ? ? ? AF6VN ??? wlfraed at ix.netcom.com? ? http://wlfraed.microdiversity.freeddns.org/ -- https://mail.python.org/mailman/listinfo/python-list From sarvesh.poddar at yahoo.com Mon Aug 3 01:05:26 2020 From: sarvesh.poddar at yahoo.com (Sarvesh Poddar) Date: Mon, 3 Aug 2020 05:05:26 +0000 (UTC) Subject: (Issue resolved!) Issue with Python module downloads from Library for a beginner Python coder. References: <420522126.1382371.1596431126036.ref@mail.yahoo.com> Message-ID: <420522126.1382371.1596431126036@mail.yahoo.com> Hi terry, I am so happy to mention that your suggestion worked! I moved the file from Tkinter to Lib and I am suddenly able to import the file.? Thanks you so much @Bob, @Arjun, @Cameron for your suggestions. I can finally move forward. I hope to contribute to this community in future after gaining enough experience on the Python subject. Looking forward! On Monday, 3 August, 2020, 12:51:28 am IST, Terry Reedy wrote: On 8/2/2020 2:36 AM, Sarvesh Poddar via Python-list wrote: [I downloaded] https://mcsp.wartburg.edu/zelle/python/graphics.py) I have unmangled the traceback and added explanations. > Traceback (most recent call last): >? ?File "", line 1, in > ? ? import graphics You typed this in IDLE Shell in response to the >>> prompt. >? ?File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1 This says that you put the file in the same directory as python.exe.? It should better be in ".../Lib/site-packages" or in a directory in "/Users/".? None the less, the import worked. >? ? ?Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32 >? ?? ? ? ? ?^ > SyntaxError: invalid syntax This says that the first line of graphics.py begins with "Python 3.8.5..."? This is the startup message printed by python.exe when run in interactive mode, and by IDLE's interactive Shell.? It is text, not python code.? It is not the first line of the file at that link (I checked). Look at the file on your disk and check its first line.? You may have to put '%appdata%' in the directory box if the /User//appdata directory is hidden on your machine. >? ?I have installed, uninstalled and then re-installed Python 3.8.5 multiple times but the problem remains.? > I did a thorough internet search and most of them suggested using sys path and following is the result, This suggestion is for when the import fails because the module is not found.? In your case, it was found and the import process started. > import sys>>> sys.path['', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\Lib\\idlelib', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\python38.zip', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32', 'C:\\Users\\sarvesh\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages'] > When I write a different line -? (from import graphics *), this is the output: > from graphics import *Traceback (most recent call last):? File "", line 1, in ? ? from graphics import *? File "C:\Users\sarvesh\AppData\Local\Programs\Python\Python38-32\graphics.py", line 1? ? Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32? ? ? ? ? ?^SyntaxError: invalid syntax Same bad first line, same error. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list From PythonList at DancesWithMice.info Mon Aug 3 02:31:40 2020 From: PythonList at DancesWithMice.info (dn) Date: Mon, 3 Aug 2020 18:31:40 +1200 Subject: Python running in the Command Prompt Window questions In-Reply-To: <000001d66938$b03f6cc0$10be4640$@SGA.Ninja> References: <000001d66938$b03f6cc0$10be4640$@SGA.Ninja> Message-ID: <7c465485-ca55-f1c0-d3ec-57f846627232@DancesWithMice.info> On 03/08/2020 13:52, Steve wrote: > When I double click on a .py file, it executes at the command prompt with black background and small white font. > > Is there python code to change the font size and background color? Ctrl-Shift-+ ? > ======================================= > FootNote: > Would it be ironic if Popeye?s chicken was fried in Olive Oil? The irony was that the marketing drive behind Popeye eating spinach was based upon research that was in-error by at least a factor of ten. -- Regards =dn From halvard.tislavoll at haugnett.no Mon Aug 3 15:37:18 2020 From: halvard.tislavoll at haugnett.no (Halvard Tislavoll) Date: Mon, 03 Aug 2020 21:37:18 +0200 Subject: IDLE =?utf-8?q?3=2E8=2E3?= -- bug report Message-ID: <9856-5f286780-37-6abc590@121068892> I'am dealing with a bug My machine:???????? ????????????????????Type: Laptop ??????????????????? System: Hewlett-Packard ??????????????????? product: HP EliteBook 8770w ??????????????????? v: A1029D1102 ??????????????????? Prosessor: Intel? Core? i7-3720QM CPU @ 2.60GHz ? 4 ??????????????????? RAM: 15.6 GiB ??????????????????? Hd: 2577.6 GB ??????????????????? Graphic card: NVIDIA Corporation GK104GLM [Quadro K3000M] Operating system:?? Linux Mint 20 Cinnamon ??????????????????? Cinnamon version: 4.6.6 ??????????????????? Linux kernal: 5.4.0-42-generic pyenv 1.2.20 Python 3.8.4 (default, Jul 20 2020, 20:20:14) IDLE 3.8.4 I have been using IDLE for many years. But now I can not do it. Example: I write a heading for a python script in my text editor, xed and save as 'test.py'. .............................................................................................................................. ??? #! /usr/bin/env python ??? #? -*- coding: utf-8 -*- ??? # ... pandas-techniques-python-data-manipulation/ ??? import pandas as pd ??? import numpy as np ??? #----------------------------------------------------------- ............................................................................................................................... Then I open 'test.py' in IDLE. Everything looks normal. I am testing whether it is possible to save with the shortcut ctrl-s. OK. But then I write the following line: ??? print ("\ n # 1 - Boolean Indexing in Pandas \ n") Result: storage no longer works. And IDLE becomes useless! The problem is that print statement no longer support my sign "-" U + 2013 EN DASH but this sign goes well;? "-" U + 002D HYPHEN-MINUS Want to get this fixed Thank you in advance, Halvard Tislavoll ? ? From Gronicus at SGA.Ninja Mon Aug 3 17:57:05 2020 From: Gronicus at SGA.Ninja (Steve) Date: Mon, 3 Aug 2020 17:57:05 -0400 Subject: Problems with tool tips... Message-ID: <005501d669e1$09e8fb30$1dbaf190$@SGA.Ninja> Python/IDLE How do I get rid of the "suggestion" box tool tips that always blocks the work I need to see when writing code? Do they really have to cram it right up at the data entry point? Can't it be down in the border and out of the way? I don't use it as much as it is interfering with my work. Very distracting. ====================================================== Footnote: If 666 is considered evil, then technically, 25.8069758 is the root of all evil. -- From nad at python.org Tue Aug 4 00:34:53 2020 From: nad at python.org (Ned Deily) Date: Tue, 4 Aug 2020 00:34:53 -0400 Subject: IDLE 3.8.4 [was 3.8.3] -- bug report In-Reply-To: <9856-5f286780-37-6abc590@121068892> References: <9856-5f286780-37-6abc590@121068892> Message-ID: On 2020-08-03 15:37, Halvard Tislavoll wrote: > I'am dealing with a bug [...] > Python 3.8.4 (default, Jul 20 2020, 20:20:14) > IDLE 3.8.4 > > I have been using IDLE for many years. But now I can not do it. > > Example: > I write a heading for a python script in my text editor, xed and save as 'test.py'. > .............................................................................................................................. > ??? #! /usr/bin/env python > ??? #? -*- coding: utf-8 -*- > > ??? # ... pandas-techniques-python-data-manipulation/ > > ??? import pandas as pd > ??? import numpy as np > > ??? #----------------------------------------------------------- > ............................................................................................................................... > Then I open 'test.py' in IDLE. Everything looks normal. > > I am testing whether it is possible to save with the shortcut ctrl-s. OK. > > But then I write the following line: > > ??? print ("\ n # 1 - Boolean Indexing in Pandas \ n") > > Result: > storage no longer works. And IDLE becomes useless! > > The problem is that print statement no longer support my sign "-" U + 2013 EN DASH > > but this sign goes well;? "-" U + 002D HYPHEN-MINUS See https://bugs.python.org/issue41300 The problem was introduced in Python 3.8.4 (released 2020-07-13) and has been fixed in 3.8.5 which was released 2020-07-20. From Gronicus at SGA.Ninja Tue Aug 4 04:38:31 2020 From: Gronicus at SGA.Ninja (Steve) Date: Tue, 4 Aug 2020 04:38:31 -0400 Subject: Updating a variable problem. Message-ID: <00c801d66a3a$a2bb0020$e8310060$@SGA.Ninja> Why should line 6 fail until line 7 is commented out? Python complains that MSN is "referenced before assignment". def ReadTheEQfile(): global MSN MSN = ("1 Monitor") #This line works every time. def EditTheEQlist(): print("MSN2 = " + MSN) # Works if the next line is commented out. MSN = ("3 Monitor") # Main() ReadTheEQfile() print("MSN1 = " + MSN) # This line works every time EditTheEQlist() ===================================== Footnote: Genie: You have three wishes. Me: I wish I had more wishes. Genie: You cannot wish for more wishes. Me: I wish I could. From souvik.viksou at gmail.com Tue Aug 4 04:49:52 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Tue, 4 Aug 2020 14:19:52 +0530 Subject: Updating a variable problem. In-Reply-To: <00c801d66a3a$a2bb0020$e8310060$@SGA.Ninja> References: <00c801d66a3a$a2bb0020$e8310060$@SGA.Ninja> Message-ID: Probably because the MSN variable in the second function is not global. On Tue, Aug 4, 2020, 2:08 PM Steve wrote: > Why should line 6 fail until line 7 is commented out? > Python complains that MSN is "referenced before assignment". > > def ReadTheEQfile(): > global MSN > MSN = ("1 Monitor") #This line works every time. > > def EditTheEQlist(): > print("MSN2 = " + MSN) # Works if the next line is commented out. > MSN = ("3 Monitor") > > # Main() > ReadTheEQfile() > print("MSN1 = " + MSN) # This line works every time > EditTheEQlist() > > > > ===================================== > Footnote: > Genie: You have three wishes. > Me: I wish I had more wishes. > Genie: You cannot wish for more wishes. > Me: I wish I could. > > > -- > https://mail.python.org/mailman/listinfo/python-list > From Gronicus at SGA.Ninja Tue Aug 4 13:25:54 2020 From: Gronicus at SGA.Ninja (Steve) Date: Tue, 4 Aug 2020 13:25:54 -0400 Subject: Updating a variable problem. In-Reply-To: References: <00c801d66a3a$a2bb0020$e8310060$@SGA.Ninja> <000201d66a3d$bccb07a0$366116e0$@SGA.Ninja> Message-ID: <004501d66a84$4f6f2640$ee4d72c0$@SGA.Ninja> How is MSN a new variable? It is not intended to be. If line 8 is commented out, it is printable in all three locations. If line 8 is not commented out, then MSN in the previous line is determined to be undeclared. It looks as if I am not allowed to change the contents of the variable MSN. FootNote: If money does not grow on trees, then why do banks have branches? From: Souvik Dutta Sent: Tuesday, August 4, 2020 5:12 AM To: Steve Subject: Re: Updating a variable problem. I don't know your exact meaning of fail. But as much as I can say there is a new variable MSN being declared in the function that is only seen locally that is inside the function. Now python sees this and probably says variable used before assigning. You might try declaring a global msn in the function again. And then changing msn after the print statement. Also this error occurred because python first searches the variable in the local scope which is absent earlier and so it searches for the variable in the global scope where it is present and so no errors are raised. Souvik flutter dev On Tue, Aug 4, 2020, 2:30 PM Steve > wrote: The print statement works in the EditTheEQlist() therefore the variable is seen as having been declared. If I replace the value in the variable in the next line then the print statement fails. Is this still a matter of globality? If it is, how do I fix it? FootNote: If money does not grow on trees, then why do banks have branches? From: Souvik Dutta > Sent: Tuesday, August 4, 2020 4:50 AM To: Steve > Cc: Python List > Subject: Re: Updating a variable problem. Probably because the MSN variable in the second function is not global. On Tue, Aug 4, 2020, 2:08 PM Steve > wrote: Why should line 6 fail until line 7 is commented out? Python complains that MSN is "referenced before assignment". def ReadTheEQfile(): global MSN MSN = ("1 Monitor") #This line works every time. def EditTheEQlist(): print("MSN2 = " + MSN) # Works if the next line is commented out. MSN = ("3 Monitor") # Main() ReadTheEQfile() print("MSN1 = " + MSN) # This line works every time EditTheEQlist() ===================================== Footnote: Genie: You have three wishes. Me: I wish I had more wishes. Genie: You cannot wish for more wishes. Me: I wish I could. -- https://mail.python.org/mailman/listinfo/python-list From tjreedy at udel.edu Tue Aug 4 05:36:38 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 4 Aug 2020 05:36:38 -0400 Subject: Problems with tool tips... In-Reply-To: <005501d669e1$09e8fb30$1dbaf190$@SGA.Ninja> References: <005501d669e1$09e8fb30$1dbaf190$@SGA.Ninja> Message-ID: On 8/3/2020 5:57 PM, Steve wrote: > > Python/IDLE How do I get rid of the "suggestion" box tool tips AFAIK, you are the first person to request this, though perhaps not the first to think it. Escape closes the box. > that always blocks the work I need to see when writing code? AFAIK, the popup is always below the entry line, to avoid blocking the code above it, which defines the named arguments you might want to enter. If the entry line is the last visible line, the box starts on top of the status line. If you see a situation otherwise, please explain. When you enter code sequentially, so that the entry line is the last line, the box does not cover anythings. 'Always' is an exaggeration. When you enter a call in the middle of existing code, the most relevant code is above, not below. > Do they really have to cram it right up at the data entry point? Most of the time, this seems to be the most useful place ;-). > Can't it be down in the border and out of the way? Yes, could be, and it sometimes is, but that would generally be less useful. If one zooms the editor window to full window height (avoiding the toolbar), then 1-line status bar border allows only the first line of the tip. > I don't use it as much as it is interfering with my work. Very distracting. Since I do nearly all my python coding in IDLE, I find the box easy to ignore when I don't need it. - Terry Jan Reedy From python at mrabarnett.plus.com Tue Aug 4 13:46:16 2020 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 4 Aug 2020 18:46:16 +0100 Subject: Updating a variable problem. In-Reply-To: <004501d66a84$4f6f2640$ee4d72c0$@SGA.Ninja> References: <00c801d66a3a$a2bb0020$e8310060$@SGA.Ninja> <000201d66a3d$bccb07a0$366116e0$@SGA.Ninja> <004501d66a84$4f6f2640$ee4d72c0$@SGA.Ninja> Message-ID: <526fd7b8-5fa6-4516-3a39-d40c7e44d775@mrabarnett.plus.com> On 2020-08-04 18:25, Steve wrote: > How is MSN a new variable? It is not intended to be. > > If line 8 is commented out, it is printable in all three locations. > > If line 8 is not commented out, then MSN in the previous line is determined to be undeclared. > > It looks as if I am not allowed to change the contents of the variable MSN. > > If there's an assignment to a variable anywhere in a function, then that variable is assumed to be local to that function unless it's explicitly declared global. In 'EditTheEQlist', you're assigning to 'MSN' on the third line, and you're not declaring that it's global in that function, so it's assumed to be local. However, on the second line you're trying to use its value, but you haven't assigned to it yet. You declared that 'MSN' was global in 'ReadTheEQfile', but that's a different function. 'global' applies only to the function it's used in. > > From: Souvik Dutta > Sent: Tuesday, August 4, 2020 5:12 AM > To: Steve > Subject: Re: Updating a variable problem. > > > > I don't know your exact meaning of fail. But as much as I can say there is a new variable MSN being declared in the function that is only seen locally that is inside the function. Now python sees this and probably says variable used before assigning. You might try declaring a global msn in the function again. And then changing msn after the print statement. Also this error occurred because python first searches the variable in the local scope which is absent earlier and so it searches for the variable in the global scope where it is present and so no errors are raised. > > Souvik flutter dev > > > > On Tue, Aug 4, 2020, 2:30 PM Steve > wrote: > > The print statement works in the EditTheEQlist() therefore the variable is seen as having been declared. If I replace the value in the variable in the next line then the print statement fails. Is this still a matter of globality? > > If it is, how do I fix it? > > FootNote: > If money does not grow on trees, then why do banks have branches? > > From: Souvik Dutta > > Sent: Tuesday, August 4, 2020 4:50 AM > To: Steve > > Cc: Python List > > Subject: Re: Updating a variable problem. > > Probably because the MSN variable in the second function is not global. > > On Tue, Aug 4, 2020, 2:08 PM Steve > wrote: > > Why should line 6 fail until line 7 is commented out? > Python complains that MSN is "referenced before assignment". > > def ReadTheEQfile(): > global MSN > MSN = ("1 Monitor") #This line works every time. > > def EditTheEQlist(): > print("MSN2 = " + MSN) # Works if the next line is commented out. > MSN = ("3 Monitor") > > # Main() > ReadTheEQfile() > print("MSN1 = " + MSN) # This line works every time > EditTheEQlist() > From PythonList at DancesWithMice.info Tue Aug 4 19:14:07 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 5 Aug 2020 11:14:07 +1200 Subject: Updating a variable problem. In-Reply-To: <00c801d66a3a$a2bb0020$e8310060$@SGA.Ninja> References: <00c801d66a3a$a2bb0020$e8310060$@SGA.Ninja> Message-ID: On 04/08/2020 20:38, Steve wrote: > Why should line 6 fail until line 7 is commented out? > Python complains that MSN is "referenced before assignment". > > def ReadTheEQfile(): > global MSN > MSN = ("1 Monitor") #This line works every time. > > def EditTheEQlist(): > print("MSN2 = " + MSN) # Works if the next line is commented out. > MSN = ("3 Monitor") > > # Main() > ReadTheEQfile() > print("MSN1 = " + MSN) # This line works every time > EditTheEQlist() NB there are no lineNRs above! (added comment/guide == good job!) Others have answered the question. Here is some reading to consolidate your understanding:- What are the rules for local and global variables in Python? https://docs.python.org/3/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python Assignment is defined recursively depending on the form of the target (list). When a target is part of a mutable object (an attribute reference, subscription or slicing), the mutable object must ultimately perform the assignment and decide about its validity, and may raise an exception if the assignment is unacceptable. The rules observed by various types and the exceptions raised are given with the definition of the object types (see section The standard type hierarchy). ... If the target is an identifier (name): If the name does not occur in a global or nonlocal statement in the current code block: the name is bound to the object in the current local namespace. Otherwise: the name is bound to the object in the global namespace or the outer namespace determined by nonlocal, respectively. https://docs.python.org/3/reference/simple_stmts.html#assignment-statements ...we have the function modifying x. It may appear somewhat confusing since x is being used in multiple locations... https://pythonprogramming.net/global-local-variables/ "Scope", particularly in its applications to Classes and Namespaces: https://docs.python.org/3/tutorial/classes.html The "LEGB" 'rule' (NB not a term you'll find in the Python docs) ie Local, Enclosing, Global, and Built-in scopes: https://realpython.com/python-scope-legb-rule/ and more in: https://realpython.com/python-namespaces-scope/ -- Regards =dn From msuginoo at reversalpoint.com Wed Aug 5 18:21:14 2020 From: msuginoo at reversalpoint.com (Michio Suginoo) Date: Wed, 5 Aug 2020 19:21:14 -0300 Subject: .replace() to replace elements in a Pandas DataFrame Message-ID: Hi, I have trouble with .replace() method in a Pandas DataFrame. My code is something like this: correction_dic1 = {'?': 'a', '?': 'i', '?': 'u', '?': 'o'} df = df.replace({'Name' : correction_dic1}) Basically, what I am trying to do here is to replace bowels with Spanish accent with a plain set of English alphabet in all the entries in the column called 'Name' in the dataframe, df. A strange thing is that it worked perfectly in the same Jupyter notebook this morning. But all of a sudden, it started not doing the replacement any more. Could anyone tell what could be the problem? Thanks Best From python at mrabarnett.plus.com Wed Aug 5 18:56:17 2020 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 5 Aug 2020 23:56:17 +0100 Subject: .replace() to replace elements in a Pandas DataFrame In-Reply-To: References: Message-ID: On 2020-08-05 23:21, Michio Suginoo wrote: > Hi, > > I have trouble with .replace() method in a Pandas DataFrame. > My code is something like this: > correction_dic1 = {'?': 'a', '?': 'i', '?': 'u', '?': 'o'} > df = df.replace({'Name' : correction_dic1}) > Basically, what I am trying to do here is to replace bowels with Spanish > accent with a plain set of English alphabet in all the entries in the > column called 'Name' in the dataframe, df. > > A strange thing is that it worked perfectly in the same Jupyter notebook > this morning. > But all of a sudden, it started not doing the replacement any more. > > Could anyone tell what could be the problem? > Does that replace characters in strings, or does it replace one string with another, e.g. replace the string '?' with the string 'a'? From msuginoo at reversalpoint.com Wed Aug 5 19:06:02 2020 From: msuginoo at reversalpoint.com (Michio Suginoo) Date: Wed, 5 Aug 2020 20:06:02 -0300 Subject: .replace() to replace elements in a Pandas DataFrame In-Reply-To: References: Message-ID: Hi MRAB, Here is an example: In the original dataframe, I have something like, 'Agronom?a'. And I try to transform it to 'Agronomia'. In this case, I try to replace ? with i: the former with a Spanish accent, the latter without. Thanks Best On Wed, Aug 5, 2020 at 8:00 PM MRAB wrote: > On 2020-08-05 23:21, Michio Suginoo wrote: > > Hi, > > > > I have trouble with .replace() method in a Pandas DataFrame. > > My code is something like this: > > correction_dic1 = {'?': 'a', '?': 'i', '?': 'u', '?': 'o'} > > df = df.replace({'Name' : correction_dic1}) > > Basically, what I am trying to do here is to replace bowels with Spanish > > accent with a plain set of English alphabet in all the entries in the > > column called 'Name' in the dataframe, df. > > > > A strange thing is that it worked perfectly in the same Jupyter notebook > > this morning. > > But all of a sudden, it started not doing the replacement any more. > > > > Could anyone tell what could be the problem? > > > Does that replace characters in strings, or does it replace one string > with another, e.g. replace the string '?' with the string 'a'? > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Wed Aug 5 19:30:31 2020 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 6 Aug 2020 00:30:31 +0100 Subject: .replace() to replace elements in a Pandas DataFrame In-Reply-To: References: Message-ID: <601ba36f-f9e1-265d-3519-3a924e4dd48a@mrabarnett.plus.com> On 2020-08-06 00:06, Michio Suginoo wrote: > Hi MRAB, > > Here is an example: > In the original dataframe, I have something like, 'Agronom?a'. And I > try to transform it to 'Agronomia'. > In this case, I try to replace ? with i: the former with a Spanish > accent, the latter without. > That's what you want it to do, but what does it _actually_ do? Does it _actually_ replace characters in a string, or only match and replace entire strings? If you have a dataframe that contains the strings 'Agronom?a' and '?', does it leave 'Agronom?a' as-is but replace '?' with 'i'? On Wed, Aug 5, 2020 at 8:00 PM MRAB > wrote: > > On 2020-08-05 23:21, Michio Suginoo wrote: > > Hi, > > > > I have trouble with .replace() method in a Pandas DataFrame. > > My code is something like this: > > correction_dic1 = {'?': 'a', '?': 'i', '?': 'u', '?': 'o'} > > df = df.replace({'Name' : correction_dic1}) > > Basically, what I am trying to do here is to replace bowels with > Spanish > > accent with a plain set of English alphabet in all the entries > in the > > column called 'Name' in the dataframe, df. > > > > A strange thing is that it worked perfectly in the same Jupyter > notebook > > this morning. > > But all of a sudden, it started not doing the replacement any more. > > > > Could anyone tell what could be the problem? > > > Does that replace characters in strings, or does it replace one > string > with another, e.g. replace the string '?' with the string 'a'? > From msuginoo at reversalpoint.com Wed Aug 5 20:12:29 2020 From: msuginoo at reversalpoint.com (Michio Suginoo) Date: Wed, 5 Aug 2020 21:12:29 -0300 Subject: .replace() to replace elements in a Pandas DataFrame In-Reply-To: <601ba36f-f9e1-265d-3519-3a924e4dd48a@mrabarnett.plus.com> References: <601ba36f-f9e1-265d-3519-3a924e4dd48a@mrabarnett.plus.com> Message-ID: Hi MRAB, Sorry, I simply do not understand the intention of your statement. If .replace() does not do what I want to do: to replace all ' ? ' with 'i' in any form . Could you advise me other means to do it? I am still a learner, so I am not knowledgeable. But, I presume, this sort of needs--to replace parts of string, not an entire string--should be common. So, I would presume, there must be some popular way to do it. If you know, I would appreciate it if you could advise me. Thanks. Best On Wed, Aug 5, 2020 at 8:38 PM MRAB wrote: > On 2020-08-06 00:06, Michio Suginoo wrote: > > Hi MRAB, > > > > Here is an example: > > In the original dataframe, I have something like, 'Agronom?a'. And I > > try to transform it to 'Agronomia'. > > In this case, I try to replace ? with i: the former with a Spanish > > accent, the latter without. > > > That's what you want it to do, but what does it _actually_ do? Does it > _actually_ replace characters in a string, or only match and replace > entire strings? > > If you have a dataframe that contains the strings 'Agronom?a' and '?', > does it leave 'Agronom?a' as-is but replace '?' with 'i'? > > On Wed, Aug 5, 2020 at 8:00 PM MRAB > wrote: > > > > On 2020-08-05 23:21, Michio Suginoo wrote: > > > Hi, > > > > > > I have trouble with .replace() method in a Pandas DataFrame. > > > My code is something like this: > > > correction_dic1 = {'?': 'a', '?': 'i', '?': 'u', '?': 'o'} > > > df = df.replace({'Name' : correction_dic1}) > > > Basically, what I am trying to do here is to replace bowels with > > Spanish > > > accent with a plain set of English alphabet in all the entries > > in the > > > column called 'Name' in the dataframe, df. > > > > > > A strange thing is that it worked perfectly in the same Jupyter > > notebook > > > this morning. > > > But all of a sudden, it started not doing the replacement any more. > > > > > > Could anyone tell what could be the problem? > > > > > Does that replace characters in strings, or does it replace one > > string > > with another, e.g. replace the string '?' with the string 'a'? > > > -- > https://mail.python.org/mailman/listinfo/python-list > From msuginoo at reversalpoint.com Wed Aug 5 20:16:10 2020 From: msuginoo at reversalpoint.com (Michio Suginoo) Date: Wed, 5 Aug 2020 21:16:10 -0300 Subject: .replace() to replace elements in a Pandas DataFrame In-Reply-To: References: <601ba36f-f9e1-265d-3519-3a924e4dd48a@mrabarnett.plus.com> Message-ID: Hi MRAB, In addition,. I also found out the following does not work either in my Jupyter Notebook. correction_dic2={ "La Boca" : "BOCA", "La Paternal": "PATERNAL", "Villa General Mitre": "VILLA GRAL. MITRE"} df = df.replace({'Name' : correction_dic2}) This case, unlike the earlier case, is aiming at replacing entire strings. Thanks, Best On Wed, Aug 5, 2020 at 9:12 PM Michio Suginoo wrote: > Hi MRAB, > > Sorry, I simply do not understand the intention of your statement. > If .replace() does not do what I want to do: to replace all ' ? ' with > 'i' in any form . > Could you advise me other means to do it? > > I am still a learner, so I am not knowledgeable. But, I presume, this sort > of needs--to replace parts of string, not an entire string--should be > common. > So, I would presume, there must be some popular way to do it. > If you know, I would appreciate it if you could advise me. > > Thanks. > Best > > > On Wed, Aug 5, 2020 at 8:38 PM MRAB wrote: > >> On 2020-08-06 00:06, Michio Suginoo wrote: >> > Hi MRAB, >> > >> > Here is an example: >> > In the original dataframe, I have something like, 'Agronom?a'. And I >> > try to transform it to 'Agronomia'. >> > In this case, I try to replace ? with i: the former with a Spanish >> > accent, the latter without. >> > >> That's what you want it to do, but what does it _actually_ do? Does it >> _actually_ replace characters in a string, or only match and replace >> entire strings? >> >> If you have a dataframe that contains the strings 'Agronom?a' and '?', >> does it leave 'Agronom?a' as-is but replace '?' with 'i'? >> >> On Wed, Aug 5, 2020 at 8:00 PM MRAB > > wrote: >> > >> > On 2020-08-05 23:21, Michio Suginoo wrote: >> > > Hi, >> > > >> > > I have trouble with .replace() method in a Pandas DataFrame. >> > > My code is something like this: >> > > correction_dic1 = {'?': 'a', '?': 'i', '?': 'u', '?': 'o'} >> > > df = df.replace({'Name' : correction_dic1}) >> > > Basically, what I am trying to do here is to replace bowels with >> > Spanish >> > > accent with a plain set of English alphabet in all the entries >> > in the >> > > column called 'Name' in the dataframe, df. >> > > >> > > A strange thing is that it worked perfectly in the same Jupyter >> > notebook >> > > this morning. >> > > But all of a sudden, it started not doing the replacement any >> more. >> > > >> > > Could anyone tell what could be the problem? >> > > >> > Does that replace characters in strings, or does it replace one >> > string >> > with another, e.g. replace the string '?' with the string 'a'? >> > >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From bob at mellowood.ca Wed Aug 5 20:50:04 2020 From: bob at mellowood.ca (Bob van der Poel) Date: Wed, 5 Aug 2020 17:50:04 -0700 Subject: .replace() to replace elements in a Pandas DataFrame In-Reply-To: References: <601ba36f-f9e1-265d-3519-3a924e4dd48a@mrabarnett.plus.com> Message-ID: I don't think that string.replace() has an option for a dictionary of replacements ... mind you, it might be nice if it did. In the meantime, have you tried looping through the dictionary and changing each possible character? On Wed, Aug 5, 2020 at 5:12 PM Michio Suginoo wrote: > Hi MRAB, > > Sorry, I simply do not understand the intention of your statement. > If .replace() does not do what I want to do: to replace all ' ? ' with 'i' > in any form . > Could you advise me other means to do it? > > I am still a learner, so I am not knowledgeable. But, I presume, this sort > of needs--to replace parts of string, not an entire string--should be > common. > So, I would presume, there must be some popular way to do it. > If you know, I would appreciate it if you could advise me. > > Thanks. > Best > > > On Wed, Aug 5, 2020 at 8:38 PM MRAB wrote: > > > On 2020-08-06 00:06, Michio Suginoo wrote: > > > Hi MRAB, > > > > > > Here is an example: > > > In the original dataframe, I have something like, 'Agronom?a'. And I > > > try to transform it to 'Agronomia'. > > > In this case, I try to replace ? with i: the former with a Spanish > > > accent, the latter without. > > > > > That's what you want it to do, but what does it _actually_ do? Does it > > _actually_ replace characters in a string, or only match and replace > > entire strings? > > > > If you have a dataframe that contains the strings 'Agronom?a' and '?', > > does it leave 'Agronom?a' as-is but replace '?' with 'i'? > > > > On Wed, Aug 5, 2020 at 8:00 PM MRAB > > wrote: > > > > > > On 2020-08-05 23:21, Michio Suginoo wrote: > > > > Hi, > > > > > > > > I have trouble with .replace() method in a Pandas DataFrame. > > > > My code is something like this: > > > > correction_dic1 = {'?': 'a', '?': 'i', '?': 'u', '?': 'o'} > > > > df = df.replace({'Name' : correction_dic1}) > > > > Basically, what I am trying to do here is to replace bowels with > > > Spanish > > > > accent with a plain set of English alphabet in all the entries > > > in the > > > > column called 'Name' in the dataframe, df. > > > > > > > > A strange thing is that it worked perfectly in the same Jupyter > > > notebook > > > > this morning. > > > > But all of a sudden, it started not doing the replacement any > more. > > > > > > > > Could anyone tell what could be the problem? > > > > > > > Does that replace characters in strings, or does it replace one > > > string > > > with another, e.g. replace the string '?' with the string 'a'? > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From msuginoo at reversalpoint.com Wed Aug 5 21:15:55 2020 From: msuginoo at reversalpoint.com (Michio Suginoo) Date: Wed, 5 Aug 2020 22:15:55 -0300 Subject: .replace() to replace elements in a Pandas DataFrame In-Reply-To: References: <601ba36f-f9e1-265d-3519-3a924e4dd48a@mrabarnett.plus.com> Message-ID: Hi Bob and MRAB, Both of you, very kind. Thanks. I tried with DataFrame as my original code, but this time, I inserted regex=True and it worked. Thank you very much! Best On Wed, Aug 5, 2020 at 9:50 PM Bob van der Poel wrote: > I don't think that string.replace() has an option for a dictionary of > replacements ... mind you, it might be nice if it did. In the meantime, > have you tried looping through the dictionary and changing each possible > character? > > > On Wed, Aug 5, 2020 at 5:12 PM Michio Suginoo > wrote: > >> Hi MRAB, >> >> Sorry, I simply do not understand the intention of your statement. >> If .replace() does not do what I want to do: to replace all ' ? ' with >> 'i' >> in any form . >> Could you advise me other means to do it? >> >> I am still a learner, so I am not knowledgeable. But, I presume, this sort >> of needs--to replace parts of string, not an entire string--should be >> common. >> So, I would presume, there must be some popular way to do it. >> If you know, I would appreciate it if you could advise me. >> >> Thanks. >> Best >> >> >> On Wed, Aug 5, 2020 at 8:38 PM MRAB wrote: >> >> > On 2020-08-06 00:06, Michio Suginoo wrote: >> > > Hi MRAB, >> > > >> > > Here is an example: >> > > In the original dataframe, I have something like, 'Agronom?a'. And I >> > > try to transform it to 'Agronomia'. >> > > In this case, I try to replace ? with i: the former with a Spanish >> > > accent, the latter without. >> > > >> > That's what you want it to do, but what does it _actually_ do? Does it >> > _actually_ replace characters in a string, or only match and replace >> > entire strings? >> > >> > If you have a dataframe that contains the strings 'Agronom?a' and '?', >> > does it leave 'Agronom?a' as-is but replace '?' with 'i'? >> > >> > On Wed, Aug 5, 2020 at 8:00 PM MRAB > > > wrote: >> > > >> > > On 2020-08-05 23:21, Michio Suginoo wrote: >> > > > Hi, >> > > > >> > > > I have trouble with .replace() method in a Pandas DataFrame. >> > > > My code is something like this: >> > > > correction_dic1 = {'?': 'a', '?': 'i', '?': 'u', '?': 'o'} >> > > > df = df.replace({'Name' : correction_dic1}) >> > > > Basically, what I am trying to do here is to replace bowels with >> > > Spanish >> > > > accent with a plain set of English alphabet in all the entries >> > > in the >> > > > column called 'Name' in the dataframe, df. >> > > > >> > > > A strange thing is that it worked perfectly in the same Jupyter >> > > notebook >> > > > this morning. >> > > > But all of a sudden, it started not doing the replacement any >> more. >> > > > >> > > > Could anyone tell what could be the problem? >> > > > >> > > Does that replace characters in strings, or does it replace one >> > > string >> > > with another, e.g. replace the string '?' with the string 'a'? >> > > >> > -- >> > https://mail.python.org/mailman/listinfo/python-list >> > >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > -- > > **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** > Bob van der Poel ** Wynndel, British Columbia, CANADA ** > EMAIL: bob at mellowood.ca > WWW: http://www.mellowood.ca > From msuginoo at reversalpoint.com Wed Aug 5 21:17:35 2020 From: msuginoo at reversalpoint.com (Michio Suginoo) Date: Wed, 5 Aug 2020 22:17:35 -0300 Subject: .replace() to replace elements in a Pandas DataFrame In-Reply-To: References: <601ba36f-f9e1-265d-3519-3a924e4dd48a@mrabarnett.plus.com> Message-ID: That said, what remains mystery is why the original one worked this morning. Strange! On Wed, Aug 5, 2020 at 10:15 PM Michio Suginoo wrote: > Hi Bob and MRAB, > Both of you, very kind. > Thanks. > I tried with DataFrame as my original code, but this time, I inserted > regex=True and it worked. > Thank you very much! > Best > > > On Wed, Aug 5, 2020 at 9:50 PM Bob van der Poel wrote: > >> I don't think that string.replace() has an option for a dictionary of >> replacements ... mind you, it might be nice if it did. In the meantime, >> have you tried looping through the dictionary and changing each possible >> character? >> >> >> On Wed, Aug 5, 2020 at 5:12 PM Michio Suginoo >> wrote: >> >>> Hi MRAB, >>> >>> Sorry, I simply do not understand the intention of your statement. >>> If .replace() does not do what I want to do: to replace all ' ? ' with >>> 'i' >>> in any form . >>> Could you advise me other means to do it? >>> >>> I am still a learner, so I am not knowledgeable. But, I presume, this >>> sort >>> of needs--to replace parts of string, not an entire string--should be >>> common. >>> So, I would presume, there must be some popular way to do it. >>> If you know, I would appreciate it if you could advise me. >>> >>> Thanks. >>> Best >>> >>> >>> On Wed, Aug 5, 2020 at 8:38 PM MRAB wrote: >>> >>> > On 2020-08-06 00:06, Michio Suginoo wrote: >>> > > Hi MRAB, >>> > > >>> > > Here is an example: >>> > > In the original dataframe, I have something like, 'Agronom?a'. And I >>> > > try to transform it to 'Agronomia'. >>> > > In this case, I try to replace ? with i: the former with a Spanish >>> > > accent, the latter without. >>> > > >>> > That's what you want it to do, but what does it _actually_ do? Does it >>> > _actually_ replace characters in a string, or only match and replace >>> > entire strings? >>> > >>> > If you have a dataframe that contains the strings 'Agronom?a' and '?', >>> > does it leave 'Agronom?a' as-is but replace '?' with 'i'? >>> > >>> > On Wed, Aug 5, 2020 at 8:00 PM MRAB >> > > wrote: >>> > > >>> > > On 2020-08-05 23:21, Michio Suginoo wrote: >>> > > > Hi, >>> > > > >>> > > > I have trouble with .replace() method in a Pandas DataFrame. >>> > > > My code is something like this: >>> > > > correction_dic1 = {'?': 'a', '?': 'i', '?': 'u', '?': 'o'} >>> > > > df = df.replace({'Name' : correction_dic1}) >>> > > > Basically, what I am trying to do here is to replace bowels >>> with >>> > > Spanish >>> > > > accent with a plain set of English alphabet in all the entries >>> > > in the >>> > > > column called 'Name' in the dataframe, df. >>> > > > >>> > > > A strange thing is that it worked perfectly in the same Jupyter >>> > > notebook >>> > > > this morning. >>> > > > But all of a sudden, it started not doing the replacement any >>> more. >>> > > > >>> > > > Could anyone tell what could be the problem? >>> > > > >>> > > Does that replace characters in strings, or does it replace one >>> > > string >>> > > with another, e.g. replace the string '?' with the string 'a'? >>> > > >>> > -- >>> > https://mail.python.org/mailman/listinfo/python-list >>> > >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >> >> -- >> >> **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** >> Bob van der Poel ** Wynndel, British Columbia, CANADA ** >> EMAIL: bob at mellowood.ca >> WWW: http://www.mellowood.ca >> > From zhaowcheng at 163.com Thu Aug 6 00:17:17 2020 From: zhaowcheng at 163.com (ZHAOWANCHENG) Date: Thu, 6 Aug 2020 12:17:17 +0800 (CST) Subject: Are instances of user-defined classes mutable? Message-ID: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> the doc of dictionary said "if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key." i think a instance of user-defined class is mutable, but i found it can be placed into a tuple that as a key of a dict: >>> class mycls(object): ... a = 1 ... >>> me = mycls() >>> me.a = 2 # mutable? >>> {(1, me): 'mycls'} {(1, <__main__.mycls object at 0x0000022824DAD668>): 'mycls'} >>> So are instances of user-defined classes mutable or immutable? From yashvats8 at gmail.com Thu Aug 6 03:43:44 2020 From: yashvats8 at gmail.com (yashvats8 at gmail.com) Date: Thu, 6 Aug 2020 00:43:44 -0700 (PDT) Subject: Is this AI Message-ID: I have created a program in Python Is my Program Artificial Intelligent ? In this I train the program to answer my question Eg 1: Training 0,0,0,1 ----> Ans is 0 0,0,1,0------> Ans is 1 0,1,1,0------> Ans is 1 You can observe ans is 3rd Element Testing 0,0,1,0 ------> Ans ? It gives 1 Eg 2: Training 1,0,0,1 ----> Ans is 1 0,1,1,0------> Ans is 0 0,1,1,1------> Ans is 0 You can observe ans is 1st Element Testing 1,1,0,0 ------> Ans ? It gives 1 This is the program --------------------------------------- weight=[0,0,0,0] for i in range(0,3): quesfortraining=[] for k in range(0,4): quesfortraining.append(int(input("Enter Training Ques"+str(i+1)+" Element "+str(k+1)+"---> "))) ansfortraining=int(input("Enter Ans for Q"+str(i+1)+"---> ")) for j in range(0,50): for l in range(0,4): if quesfortraining[l]==ansfortraining: weight[l]=weight[l]+1 else: weight[l]=weight[l]-1 userques=[] for i in range(0,4): userques.append(int(input("Enter Your Real Question "+"Element "+str(i+1)+" ---> "))) print("Answer is") print(userques[weight.index(max(weight))]) --------------------------------------- From robin at reportlab.com Thu Aug 6 10:40:54 2020 From: robin at reportlab.com (Robin Becker) Date: Thu, 6 Aug 2020 15:40:54 +0100 Subject: Are instances of user-defined classes mutable? In-Reply-To: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> References: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> Message-ID: On 06/08/2020 05:17, ZHAOWANCHENG wrote: > the doc of dictionary said "if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key." > i think a instance of user-defined class is mutable, but i found it can be placed into a tuple that as a key of a dict: > >>> class mycls(object): > ... a = 1 > ... > >>> me = mycls() > >>> me.a = 2 # mutable? > >>> {(1, me): 'mycls'} > {(1, <__main__.mycls object at 0x0000022824DAD668>): 'mycls'} > >>> > > > So are instances of user-defined classes mutable or immutable? > user class instances are clearly mutable, and in my python 3.8 you can do horrid things like this >>>> class H: > ... a = 1 > ... def __hash__(self): > ... return hash(self.a) > ... >>>> h = H() >>>> hash(h) > 1 >>>> h.a =2 >>>> hash(h) > 2 >>>> t=(1,h) >>>> d={t:23} >>>> d > {(1, <__main__.H object at 0x7f5bf72021f0>): 23} >>>> hash(h) > 2 >>>> hash(list(d.keys())[0]) > -3550055125485641917 >>>> h.a=33 >>>> hash(list(d.keys())[0]) > -3656087029879219665 >>>> so the dict itself doesn't enforce immutability of its keys -- Robin Becker From Richard at Damon-Family.org Thu Aug 6 11:10:34 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 6 Aug 2020 11:10:34 -0400 Subject: Are instances of user-defined classes mutable? In-Reply-To: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> References: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> Message-ID: On 8/6/20 12:17 AM, ZHAOWANCHENG wrote: > the doc of dictionary said "if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key." > i think a instance of user-defined class is mutable, but i found it can be placed into a tuple that as a key of a dict: > >>> class mycls(object): > ... a = 1 > ... > >>> me = mycls() > >>> me.a = 2 # mutable? > >>> {(1, me): 'mycls'} > {(1, <__main__.mycls object at 0x0000022824DAD668>): 'mycls'} > >>> > > > So are instances of user-defined classes mutable or immutable? > That documentation isn't strictly correct. All the elements of the tuple need to be hashable. Generally imutable objects are hashable and mutable objects are non-hashable, but user defined classes can be hashable, and in fact are hashable if they don't define an __eq__ member. Classes without an __eq__ members, use comparison to id() for equality, so changing a property hasn't 'mutated' the object as far as the dictionary is concerned. Hashability is a key requirement for a dictionary, and for an object to be properly hashable, its hash must not change over the life of the object, and two objects that are equal, must have the same hash. Dictionaries actually need a bit more that just hashable to work right, dictionaries use the hash of the object to first determine where to store the item, but then uses the equality relationship. For the dictionary to work right, the set of other objects that it compares equal to shouldn't change over the life of the object. Since by default, user classes use their id() for equality, that meets that requirement. To find that element in the dictionary, you would need to build a tuple using that exact same me object, you couldn't create another object, and set it to the same 'value', as they won't compare equal. -- Richard Damon From cseberino at gmail.com Thu Aug 6 11:13:55 2020 From: cseberino at gmail.com (Christian Seberino) Date: Thu, 6 Aug 2020 08:13:55 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? Message-ID: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Python is my favorite language and the easiest to use in my opinion. Lisp has a far simpler grammar and syntax. A beginner I think could learn Lisp much faster than Python. Therefore, it seems like Lisp *should* be easier to work with and more readable. I don't feel like it is easier to use but I can't see *why* that is. My best guess..... Lisp pros: simpler syntax Lisp cons: prefix notation, lots more parentheses My hypothesis is that the cons slightly outweigh the pros of Lisp which is why Python is easier to work with and is more readable in the end? chris From ethan at stoneleaf.us Thu Aug 6 11:15:55 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 6 Aug 2020 08:15:55 -0700 Subject: Are instances of user-defined classes mutable? In-Reply-To: References: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> Message-ID: <993a2ef4-dc80-a1b3-8d22-05cbe2456d1d@stoneleaf.us> On 8/6/20 7:40 AM, Robin Becker wrote: > On 06/08/2020 05:17, ZHAOWANCHENG wrote: >> So are instances of user-defined classes mutable or immutable? > > user class instances are clearly mutable, and in my python 3.8 you can > do horrid things like this > > [snip buggy/incorrect uses of __hash__] You can do horrid things like that clear back in Python 2, but the fault lies with the programmer for misusing the __dunders__. -- ~Ethan~ From Richard at Damon-Family.org Thu Aug 6 11:17:57 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 6 Aug 2020 11:17:57 -0400 Subject: Are instances of user-defined classes mutable? In-Reply-To: References: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> Message-ID: On 8/6/20 10:40 AM, Robin Becker wrote: > On 06/08/2020 05:17, ZHAOWANCHENG wrote: >> the doc of dictionary said "if a tuple contains any mutable object >> either directly or indirectly, it cannot be used as a key." >> i think a instance of user-defined class is mutable, but i found it >> can be placed into a tuple that as a key of a dict: >> ???? >>> class mycls(object): >> ???? ...???? a = 1 >> ???? ... >> ???? >>> me = mycls() >> ???? >>> me.a = 2? # mutable? >> ???? >>> {(1, me): 'mycls'} >> ???? {(1, <__main__.mycls object at 0x0000022824DAD668>): 'mycls'} >> ???? >>> >> >> >> So are instances of user-defined classes mutable or immutable? >> > user class instances are clearly mutable, and in my python 3.8 you can > do horrid things like this But since the 'mutation' doesn't affect the hash or the equality tests on the object, is it really a mutation? > >>>>> class H: >> ...????? a = 1 >> ...????? def __hash__(self): >> ...????????? return hash(self.a) >> ... >>>>> h = H() >>>>> hash(h) >> 1 >>>>> h.a =2 >>>>> hash(h) >> 2 >>>>> t=(1,h) >>>>> d={t:23} >>>>> d >> {(1, <__main__.H object at 0x7f5bf72021f0>): 23} >>>>> hash(h) >> 2 >>>>> hash(list(d.keys())[0]) >> -3550055125485641917 >>>>> h.a=33 >>>>> hash(list(d.keys())[0]) >> -3656087029879219665 >>>>> > so the dict itself doesn't enforce immutability of its keys Yes, here you have defined a hash that violates the requirements of the Dictionary (and most things that use hashes) so your class is broken, and you can expect to get strangeness out of your dictionary. > -- > Robin Becker > -- Richard Damon From david at lowryduda.com Thu Aug 6 11:16:02 2020 From: david at lowryduda.com (David Lowry-Duda) Date: Thu, 6 Aug 2020 11:16:02 -0400 Subject: Are instances of user-defined classes mutable? In-Reply-To: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> References: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> Message-ID: <20200806151602.GB27738@icerm-dld> On Thu, Aug 06, 2020 at 12:17:17PM +0800, ZHAOWANCHENG wrote: > the doc of dictionary said "if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key." > i think a instance of user-defined class is mutable, but i found it can be placed into a tuple that as a key of a dict: > >>> class mycls(object): > ... a = 1 > ... > >>> me = mycls() > >>> me.a = 2 # mutable? > >>> {(1, me): 'mycls'} > {(1, <__main__.mycls object at 0x0000022824DAD668>): 'mycls'} > >>> > > > So are instances of user-defined classes mutable or immutable? A more specific description of objects that can be keys in a dictionary can be found on the documentation: https://docs.python.org/3/library/stdtypes.html#mapping-types-dict To be a key in a dictionary, an object must be *hashable*. The spec for hashable objects is also in the documentation: https://docs.python.org/3/glossary.html#term-hashable In short, if a class implements __hash__() (which should never change during an object's lifetime) and __eq__(), it can be hashable. Many python builtins are hashable, but mutable builtins aren't. For example lists aren't hashable. To investigate a bit further, we might examine a particular example more closely. In the code snippet that follows, we make two tuples with the same data and two instances of a user-defined class with the same data. We make a dictionary and see the difference between using tuples as keys and instances of a user-defined class as keys. ``` tup1 = (1, 2) tup2 = (1, 2) d = dict() d[tup1] = "one" print(d[tup2]) # prints "one" # Note that d "knows" tup1 and tup2 are "the same" class myclass: def __init__(self): self.data = [1, 2] myobj1 = myclass() myobj2 = myclass() print(myobj1.data == myobj2.data) # True d[myobj1] = "spam" print(d[myobj2]) # raises KeyError as myobj2 not in dictionary # d doesn't "know" that myobj1 and myobj2 are "the same" ``` This difference in behavior is due to the default __hash__ and __eq__ methods for myclass, which don't consider the attributes of each instance, whereas the hashing and comparison of tuples does consider the contents of the tuple. - DLD -- David Lowry-Duda From rosuav at gmail.com Thu Aug 6 11:51:32 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Aug 2020 01:51:32 +1000 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: On Fri, Aug 7, 2020 at 1:16 AM Christian Seberino wrote: > > Python is my favorite language and the easiest to use in my opinion. > > Lisp has a far simpler grammar and syntax. A beginner I think could > learn Lisp much faster than Python. > > Therefore, it seems like Lisp *should* be easier to work with and more readable. I don't feel like it is easier to use but I can't see *why* that is. > > My best guess..... > > Lisp pros: simpler syntax > Lisp cons: prefix notation, lots more parentheses > > My hypothesis is that the cons slightly outweigh the pros of Lisp > which is why Python is easier to work with and is more readable in the end? Ook has an even simpler syntax. It has just three syntactic elements: "Ook." "Ook?" "Ook!" The purpose of code is to represent a programmer's intentions in a way that can be understood by other programmers, and by the interpreter/compiler. Simpler syntax allows a simpler parser, but it doesn't create expressiveness. If your definition is based entirely on how quickly a beginner would be able to learn the details of how a language is run, then that's missing a lot of the point of readability. The point of learning a language isn't that you can take a piece of pre-existing code and figure out what it'll do, step by step; the point is to be able to encode your intentions in that language, and to read the code and understand the other programmer's intentions. That's why we have comments - the language would be (slightly) simpler without them, but we would lose an important aspect of that programmer-to-programmer communication. Ook is one of the least expressive and most simple languages there is. Python is far more expressive, far more detailed... and far FAR more useful. Lisp is elegant and simple, but it's also less expressive than Python is. That's why Python is (often) easier to work with. ChrisA From souvik.viksou at gmail.com Thu Aug 6 11:52:49 2020 From: souvik.viksou at gmail.com (Souvik Dutta) Date: Thu, 6 Aug 2020 21:22:49 +0530 Subject: Is this AI In-Reply-To: References: Message-ID: This is probably more ML then AI. On Thu, Aug 6, 2020, 7:57 PM wrote: > I have created a program in Python > > Is my Program Artificial Intelligent ? > > In this I train the program to answer my question > Eg 1: > > Training > 0,0,0,1 ----> Ans is 0 > 0,0,1,0------> Ans is 1 > 0,1,1,0------> Ans is 1 > > You can observe ans is 3rd Element > > Testing > > 0,0,1,0 ------> Ans ? > > It gives 1 > > Eg 2: > > Training > 1,0,0,1 ----> Ans is 1 > 0,1,1,0------> Ans is 0 > 0,1,1,1------> Ans is 0 > > You can observe ans is 1st Element > > Testing > > 1,1,0,0 ------> Ans ? > > It gives 1 > > > This is the program > --------------------------------------- > weight=[0,0,0,0] > > for i in range(0,3): > quesfortraining=[] > > for k in range(0,4): > quesfortraining.append(int(input("Enter Training Ques"+str(i+1)+" > Element "+str(k+1)+"---> "))) > > > ansfortraining=int(input("Enter Ans for Q"+str(i+1)+"---> ")) > > > for j in range(0,50): > for l in range(0,4): > > if quesfortraining[l]==ansfortraining: > > weight[l]=weight[l]+1 > else: > weight[l]=weight[l]-1 > > userques=[] > > > for i in range(0,4): > userques.append(int(input("Enter Your Real Question "+"Element > "+str(i+1)+" ---> "))) > > > print("Answer is") > print(userques[weight.index(max(weight))]) > > > --------------------------------------- > > -- > https://mail.python.org/mailman/listinfo/python-list > From cseberino at gmail.com Thu Aug 6 12:34:15 2020 From: cseberino at gmail.com (Christian Seberino) Date: Thu, 6 Aug 2020 09:34:15 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: <1d0a0139-1e00-40a3-bc14-75b3c0849bc4o@googlegroups.com> On Thursday, August 6, 2020 at 10:52:00 AM UTC-5, Chris Angelico wrote: > The point of learning a > language isn't that you can take a piece of pre-existing code and > figure out what it'll do, step by step; the point is to be able to > encode your intentions in that language, and to read the code and > understand the other programmer's intentions. Thanks for sharing your thoughts. How do you define "expressiveness"? Also, why is Python syntax able to more clearly communicate intentions? Both Python and Lisp have comments so that isn't it. cs From skip.montanaro at gmail.com Thu Aug 6 13:33:04 2020 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 6 Aug 2020 13:33:04 -0400 Subject: Explicit is better than Implicit Message-ID: Hmmm... Rename genes, fix Excel, or dump Excel in favor of Python? I know what my choice would have been. :-) https://www.theverge.com/2020/8/6/21355674/human-genes-rename-microsoft-excel-misreading-dates Skip From rosuav at gmail.com Thu Aug 6 14:00:34 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Aug 2020 04:00:34 +1000 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <1d0a0139-1e00-40a3-bc14-75b3c0849bc4o@googlegroups.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <1d0a0139-1e00-40a3-bc14-75b3c0849bc4o@googlegroups.com> Message-ID: On Fri, Aug 7, 2020 at 2:36 AM Christian Seberino wrote: > > On Thursday, August 6, 2020 at 10:52:00 AM UTC-5, Chris Angelico wrote: > > The point of learning a > > language isn't that you can take a piece of pre-existing code and > > figure out what it'll do, step by step; the point is to be able to > > encode your intentions in that language, and to read the code and > > understand the other programmer's intentions. > > Thanks for sharing your thoughts. How do you define "expressiveness"? > Also, why is Python syntax able to more clearly communicate intentions? > Both Python and Lisp have comments so that isn't it. > Expressiveness is about how well you can translate your ideas into code, and how well someone else can interpret your ideas by reading your code. It's hard to quantify, but it's in a way the most important thing about any language. ChrisA From akkana at shallowsky.com Thu Aug 6 14:39:47 2020 From: akkana at shallowsky.com (Akkana Peck) Date: Thu, 6 Aug 2020 12:39:47 -0600 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: <20200806183947.GG2129@shallowsky.com> Christian Seberino writes: > Python is my favorite language and the easiest to use in my opinion. > > Lisp has a far simpler grammar and syntax. A beginner I think could > learn Lisp much faster than Python. > > Therefore, it seems like Lisp *should* be easier to work with and more readable. I don't feel like it is easier to use but I can't see *why* that is. First, everybody's brain is different so be cautious of sweeping statements. What's true for one person isn't necessarily true for another. That said, for me, Lisp's simpler syntax arises from the fact that there's basically one data structure: a list. To do anything in Lisp, you have to think in lists, map everything to lists (including the program's own structure), build up list-based data structures in your head. It's also functional and recursive, which means that as you're programming, you have to maintain a stack (which is also a list) in your head of all the lists that aren't yet closed. Of course, you can use tricks like let and setq to hold intermediate variables and mitigate that a little, but that isn't really Lispish. Trying to maintain that recursive list of unclosed lists in your brain is fun. It stretches the brain in interesting ways. I was way into Lisp at one point, including writing several Lisp interpreters (that simple structure makes Lisp very easy to implement). But I never found Lisp code very maintainable, because any time you read a program, you have to build up that list in your head every time just to follow the logic structure and figure out what the return value will be. I suspect most people find that more difficult than reading an inherently procedural language like Python. I know I do. ...Akkana From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Aug 6 15:09:12 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 6 Aug 2020 14:09:12 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <1d0a0139-1e00-40a3-bc14-75b3c0849bc4o@googlegroups.com> Message-ID: <20200806190912.GA42295@scrozzle> On 2020-08-07 at 04:00:34 +1000, Regarding "Re: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax?," Chris Angelico wrote: > On Fri, Aug 7, 2020 at 2:36 AM Christian Seberino wrote: > > > > On Thursday, August 6, 2020 at 10:52:00 AM UTC-5, Chris Angelico wrote: > > > The point of learning a > > > language isn't that you can take a piece of pre-existing code and > > > figure out what it'll do, step by step; the point is to be able to > > > encode your intentions in that language, and to read the code and > > > understand the other programmer's intentions. > > > > Thanks for sharing your thoughts. How do you define "expressiveness"? > > Also, why is Python syntax able to more clearly communicate intentions? > > Both Python and Lisp have comments so that isn't it. > > > > Expressiveness is about how well you can translate your ideas into > code, and how well someone else can interpret your ideas by reading > your code. It's hard to quantify, but it's in a way the most important > thing about any language. I would say that expressiveness is how *directly* you can translate your ideas into code, and how *directly* some one else can see your original idea by reading your code. So when I say something like "create a new list in which each value is double the value in the current list," that translates to relatively idiomatic Python like so: new_list = [] for value in current_list: new_list.append(2 * value) # or maybe value + value; YMMV Or even: [ 2 * value for value in current_list ] In Lisp, it might look like this: (mapcar #'(lambda (value) (* 2 value)) current_list) Unless you're familiar with Lisp (or Lisp-like languages), and comfortable with high order functions (which many/most beginners aren't, although most Lispers are), it's a lot harder to see the idea in the code. Having written my share of both Python and Lisp, I appreciate the benefits of Lisp's syntax, but I also know that it still takes me a little longer to read and understand a big block of straightforward Lisp vs. a big block of straightforward Python. (Between dunders, properties, and other bits of magic that takes place far away from its invocation, Python code and the logic behind it can be *very* confusing to unravel. Lisp macros present the same problem.) From rosuav at gmail.com Thu Aug 6 15:22:53 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Aug 2020 05:22:53 +1000 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <20200806190912.GA42295@scrozzle> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <1d0a0139-1e00-40a3-bc14-75b3c0849bc4o@googlegroups.com> <20200806190912.GA42295@scrozzle> Message-ID: On Fri, Aug 7, 2020 at 5:10 AM <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > I would say that expressiveness is how *directly* you can translate your > ideas into code, and how *directly* some one else can see your original > idea by reading your code. Yep, how directly or how accurately. > So when I say something like "create a new list in which each value is > double the value in the current list," that translates to relatively > idiomatic Python like so: > > new_list = [] > for value in current_list: > new_list.append(2 * value) # or maybe value + value; YMMV > > Or even: > > [ 2 * value for value in current_list ] > > In Lisp, it might look like this: > > (mapcar #'(lambda (value) (* 2 value)) current_list) > > Unless you're familiar with Lisp (or Lisp-like languages), and > comfortable with high order functions (which many/most beginners aren't, > although most Lispers are), it's a lot harder to see the idea in the > code. One thing worth noting is that your mental pseudo-code is affected by the languages you're comfortable with. You said: > create a new list in which each value is double the value in the current list which clearly and obviously translates into a list comprehension. But what if you instead thought of it as: > double every value in this list ? That would translate far more obviously into an imperative construct that doesn't really work in Python, but imagine that we had reference variables: for &value in list: value *= 2 So the expressiveness of a language isn't a fixed quantity, but it depends on the programmer. And it can change as you learn and adjust, too. ChrisA From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Aug 6 16:07:55 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 6 Aug 2020 15:07:55 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <1d0a0139-1e00-40a3-bc14-75b3c0849bc4o@googlegroups.com> <20200806190912.GA42295@scrozzle> Message-ID: <20200806200755.GB42295@scrozzle> On 2020-08-07 at 05:22:53 +1000, Chris Angelico wrote: > On Fri, Aug 7, 2020 at 5:10 AM <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > One thing worth noting is that your mental pseudo-code is affected by > the languages you're comfortable with. You said: > > > create a new list in which each value is double the value in the current list > > which clearly and obviously translates into a list comprehension. But > what if you instead thought of it as: > > > double every value in this list > > ? That would translate far more obviously into an imperative construct > that doesn't really work in Python ... for (index, value) in enumerate(this_list): this_list[index] = 2 * value Or: for index in range(len(this_list)): this_list[index] *= 2 (But I tend to avoid that, though, because I can never remember exactly which mutations work inside a loop and which ones don't (or does enumerate remove some or all of those restrictions?). Which feeds right into what you said about being comfortable with certain languages or programming styles.) [Shared] Mutable Data will be the death of us all! ;-) > So the expressiveness of a language isn't a fixed quantity, but it > depends on the programmer. And it can change as you learn and adjust, > too. I think the expressiveness of the language remains fairly constant, new features notwithstanding. Unless you mean that a given programmer's usage of that expressiveness changes, in which case I absolutely agree. From Richard at Damon-Family.org Thu Aug 6 17:19:13 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 6 Aug 2020 17:19:13 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <20200806200755.GB42295@scrozzle> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <1d0a0139-1e00-40a3-bc14-75b3c0849bc4o@googlegroups.com> <20200806190912.GA42295@scrozzle> <20200806200755.GB42295@scrozzle> Message-ID: <1a94f5e1-7715-2436-1f25-fed43168e64e@Damon-Family.org> On 8/6/20 4:07 PM, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > for (index, value) in enumerate(this_list): > this_list[index] = 2 * value > > Or: > > for index in range(len(this_list)): > this_list[index] *= 2 > > (But I tend to avoid that, though, because I can never remember exactly > which mutations work inside a loop and which ones don't (or does > enumerate remove some or all of those restrictions?). Which feeds right > into what you said about being comfortable with certain languages or > programming styles.) Since you are not using an iterator of the list, changing it shouldn't cause any problems. You loop (for its control) looks at the loop once, before it starts, so as long as you don't delete any elements (which would cause the index to go to high) you can't have an issue mutating the list. -- Richard Damon From PythonList at DancesWithMice.info Thu Aug 6 17:40:15 2020 From: PythonList at DancesWithMice.info (dn) Date: Fri, 7 Aug 2020 09:40:15 +1200 Subject: Explicit is better than Implicit In-Reply-To: References: Message-ID: On 07/08/2020 05:33, Skip Montanaro wrote: > Hmmm... Rename genes, fix Excel, or dump Excel in favor of Python? I know > what my choice would have been. :-) > > https://www.theverge.com/2020/8/6/21355674/human-genes-rename-microsoft-excel-misreading-dates At the risk of screaming off-topic... The article does point-out that MS-Excel is attempting to be helpful in identifying data, and thus formatting it appropriately. The human-error is exposed: "opens the same spreadsheet in Excel without thinking, errors will be introduced". So, should the mistake be laid at the feet of the tool? (No matter that I/many of us here will agree with your preference/predilection!) The reason that a Python solution would not have this problem is less to do with Python, or even Gene nomenclature. It is because when we (professional projects) code a solution, we proceed through design-stages. We think about the data to be transformed, as well as the process of transformation itself. Of course, if we develop-by-prototype: adding a chunk of code 'here' and another chunk 'there', with no top-down view; the very same sort of problem could so-easily occur! - despite and/or because of Python's fast-and-loose dynamic typing, for example. I postulate that the issue really stems from MSFT's Training Approach. They start from the level of 'here is a column of numbers let's total them', and then run through every command on the menus/ribbon. Their material rarely talks about 'design' - and few individuals have the patience/are afforded the budget, for the 'advanced courses' that do! NB the same applies to MS-Word, etc. MS-Excel (or better: LibreOffice Calc, etc, from the F/LOSS stable) is a powerful tool with the additional virtue that it is easy to use. Thus, people are able to concentrate on the demands of their own speciality, and use of the tool becomes 'automatic' or 'muscle memory'. A mark of "success" if ever there was one! Unfortunately, this forms the mind-set of folk creating a worksheet in an organic (prototype-as-product/design-less) fashion, and certainly when picking-up someone else's spreadsheet (per quote, above). However, the article continues to describe the tool: ?It?s a widespread tool and if you are a bit computationally illiterate you will use it" and using any tool - particularly when also using someone else's data, without over-view thought, is a bit like the old prank of asking some 'innocent' to "format c:" - and ultimately, as fatal. If we started an MS-product solution from 'design', then we would commence with templates and styles - that column of the worksheet would be formatted as a string, eg "MARCH3", and not left to MS-Excel's 'intelligence'/tender mercies. So, is it an Excel-problem? Is it a human-laziness problem? Is it plain ignorance? Is it a training/learning issue? We expect people driving a car to know how to drive - without expecting them to be professional drivers (racers or truckies). Why don't we expect people manipulating statistics and other forms of information to be appropriately-able? That they would alter the jargon and thinking of an entire discipline to suit the sub-standard, overly-bossy, commonly-used tool is surely 'putting the cart before the horse'... That said, names do matter. How often do you search the web for some detail of/in Python and find an insinuation of snakes nestled amongst the results - or someone thinks that it is time for a joke about swallows or parrots? I don't have time to imagine how the folks who use C or R manage! PS programming languages also include 'danger zones'. Early in my career I found a similar embarrassment of 'infallible belief in the tool', with the same consequence of research papers containing erroneous numbers/bases/conclusions being published. A suite of programs declared storage 'arrays' and populated them with (knowingly) incomplete data (reasonably complete, not exactly "sparse") - but forgetting that this technology required the data-arrays to be zeroed first! So, random data from previous use of the same storage area, in random formats, threw all manner of 'spanners in the works'. When you take such news to your boss and colleagues, do NOT even try to convince yourself that they will not "shoot the messenger"! -- Regards =dn From cs at cskk.id.au Thu Aug 6 18:34:33 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 7 Aug 2020 08:34:33 +1000 Subject: Explicit is better than Implicit In-Reply-To: References: Message-ID: <20200806223433.GA98176@cskk.homeip.net> On 07Aug2020 09:40, DL Neil wrote: >On 07/08/2020 05:33, Skip Montanaro wrote: >>Hmmm... Rename genes, fix Excel, or dump Excel in favor of Python? I know >>what my choice would have been. :-) >> >>https://www.theverge.com/2020/8/6/21355674/human-genes-rename-microsoft-excel-misreading-dates > > >At the risk of screaming off-topic... > >The article does point-out that MS-Excel is attempting to be helpful >in identifying data, and thus formatting it appropriately. The >human-error is exposed: "opens the same spreadsheet in Excel without >thinking, errors will be introduced". So, should the mistake be laid at >the feet of the tool? The tool. Anything that reaches into my data and silently decides to misinterpret it is busted, particularly if if it is silent, unreversible, and untunable. When I read a CSV file, quoted strings are just strings. "8.1" is a string. And so forth. When Excel reads a file, it looks for stuff and decides to upgrade its type. Eg dates etc (particularly pernicious with US-style dates versus the rest of the planet). Mojibake for data ensues. As always, I am reminded of Heuer's Razor: If it can't be turned off, it's not a feature. - Karl Heuer Cheers, Cameron Simpson From cseberino at gmail.com Thu Aug 6 19:08:29 2020 From: cseberino at gmail.com (Christian Seberino) Date: Thu, 6 Aug 2020 16:08:29 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> Message-ID: <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> > Trying to maintain that recursive list of unclosed lists in your > brain is fun. It stretches the brain in interesting ways. I was > way into Lisp at one point, including writing several Lisp > interpreters (that simple structure makes Lisp very easy to > implement). But I never found Lisp code very maintainable, because > any time you read a program, you have to build up that list in your > head every time just to follow the logic structure and figure out > what the return value will be. So basically while recursion is easy to write it isn't so easy for other people to understand compared to iterative code. So maybe that is a big part of it....recursion is just harder on the brain than iteration. cs From skip.montanaro at gmail.com Thu Aug 6 20:19:01 2020 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 6 Aug 2020 19:19:01 -0500 Subject: Explicit is better than Implicit In-Reply-To: <20200806223433.GA98176@cskk.homeip.net> References: <20200806223433.GA98176@cskk.homeip.net> Message-ID: > > When Excel reads a file, it looks for stuff and decides to upgrade its > type. Eg dates etc (particularly pernicious with US-style dates versus > the rest of the planet). Mojibake for data ensues. > > As always, I am reminded of Heuer's Razor: > > If it can't be turned off, it's not a feature. - Karl Heuer > Good one. I always remember the start-up days (late 90s) when I developed and maintained an online concert calendar (Musi-Cal) written in Python. The technology got bought by another start-up (Mojam) who used Perl for their web stuff. Both front end systems talked to my Python-based back end (communication between both front ends and the one back end was via XML-RPC). I was sometimes frustrated by the stuff Perl did. The one which stuck with me all these years was its silent conversion of the band name " 311 " to the integer 311 on which my Python backend obligingly barfed. I eventually had to put in data type checks for all fields in my back end (my front end already had that sort of input validation) as I could no longer assume a sentient front end was handing it data. Skip From python at bladeshadow.org Thu Aug 6 20:46:25 2020 From: python at bladeshadow.org (Python) Date: Thu, 6 Aug 2020 19:46:25 -0500 Subject: Explicit is better than Implicit In-Reply-To: References: <20200806223433.GA98176@cskk.homeip.net> Message-ID: <20200807004625.GD8728@bladeshadow.org> On Thu, Aug 06, 2020 at 07:19:01PM -0500, Skip Montanaro wrote: > > > > When Excel reads a file, it looks for stuff and decides to upgrade its > > type. Eg dates etc (particularly pernicious with US-style dates versus > > the rest of the planet). Mojibake for data ensues. > > > > As always, I am reminded of Heuer's Razor: > > > > If it can't be turned off, it's not a feature. - Karl Heuer > > > > Good one. I always remember the start-up days (late 90s) when I developed > and maintained an online concert calendar (Musi-Cal) written in Python. The > technology got bought by another start-up (Mojam) who used Perl for their > web stuff. Both front end systems talked to my Python-based back end > (communication between both front ends and the one back end was via > XML-RPC). I was sometimes frustrated by the stuff Perl did. The one which > stuck with me all these years was its silent conversion of the band name " > 311 " to the integer 311 on which > my Python backend obligingly barfed. I eventually had to put in data type > checks for all fields in my back end (my front end already had that sort of > input validation) as I could no longer assume a sentient front end was > handing it data. 311 rocks. That Perl code, OTOH... =8^) Obviously, it's a bug. One that likely is not that hard to correct... FWIW this is what I've long hated about Perl: Yes, TIMTOWTDI, but nearly all of them are subtlely (or sometimes not-so-subtlely) wrong. You *can* write good Perl but it encourages the inexperienced to find one of the wrong ways, by providing the illusion that it is easy to work with. Python is *actually* easy to work with... most of the time. "If you want more things for you buck there's no luck..." =8^) From python at bladeshadow.org Thu Aug 6 20:35:43 2020 From: python at bladeshadow.org (Python) Date: Thu, 6 Aug 2020 19:35:43 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> Message-ID: <20200807003543.GC8728@bladeshadow.org> On Thu, Aug 06, 2020 at 04:08:29PM -0700, Christian Seberino wrote: > > Trying to maintain that recursive list of unclosed lists in your > > brain is fun. It stretches the brain in interesting ways. I was > > way into Lisp at one point, including writing several Lisp > > interpreters (that simple structure makes Lisp very easy to > > implement). But I never found Lisp code very maintainable, because > > any time you read a program, you have to build up that list in your > > head every time just to follow the logic structure and figure out > > what the return value will be. > > So basically while recursion is easy to write it isn't so easy for other > people to understand compared to iterative code. So maybe that is a > big part of it....recursion is just harder on the brain than iteration. Not necessarily. Some problems very naturally lend themselves to recursive solutions. Fibonacci's sequence is one. #!/usr/bin/python def fib(x): if x < 1: raise "arg must be >= 1" if x == 1: return 0 elif x == 2: return 1 else: return fib(x - 1) + fib(x - 2) Pretty straightforward. Now try yourself to write the iterative version. If you haven't done this recently, there's a pretty good chance you'll get it wrong on your first try. The recursive version is a bit simpler and more straightforward to understand, requiring less state to be preserved (and mentally retained, if you're trying to work through the algorithm mentally or on paper). It's also probably significantly slower, so you'd likely still want to use the iterative version, unless you're trying to illustrate how recursion works or care more about writing easily understood code than performance.. From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Aug 6 21:48:16 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 6 Aug 2020 20:48:16 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> Message-ID: <20200807014816.GC42295@scrozzle> On 2020-08-06 at 16:08:29 -0700, Christian Seberino wrote: > > Trying to maintain that recursive list of unclosed lists in your > > brain is fun. It stretches the brain in interesting ways. I was > > way into Lisp at one point, including writing several Lisp > > interpreters (that simple structure makes Lisp very easy to > > implement). But I never found Lisp code very maintainable, because > > any time you read a program, you have to build up that list in your > > head every time just to follow the logic structure and figure out > > what the return value will be. "[R]ecursive list of unclosed lists"? Can you (whoever you are) expand on that? Yes, if you eschew helper functions and local variables, then you can end up with depply nested code, but that's true in any language. Because of Lisp's simple syntax, text editors can nearly completely relieve the programmer from the tedium of indenting and formatting, and even closing parenthesis, which also highlights missing/extra/unbalanced parentheses pretty quickly. > So basically while recursion is easy to write it isn't so easy for other > people to understand compared to iterative code. So maybe that is a > big part of it....recursion is just harder on the brain than iteration. I don't know about that. Have you ever seen an iterative or imperative version of quicksort (or any divide-and-conquer algorithm, for that matter)? Yes, it's doable, but explicitly managing your own stack of unsorted data ranges can really obscure the idea(s) of quicksort. And it's hard to imagine any language being more straightforward than Haskell's recursive factorial function: factorial 0 = 1 factorial n = n * factorial (n - 1) (Yes, it fails for n < 0, but that's outside the scope of whether or not recursion is harder on the brain than iteration. Pattern matching is a beautiful thing, too.) From zhaowcheng at 163.com Thu Aug 6 22:53:10 2020 From: zhaowcheng at 163.com (ZHAOWANCHENG) Date: Fri, 7 Aug 2020 10:53:10 +0800 (CST) Subject: Are instances of user-defined classes mutable? In-Reply-To: References: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> Message-ID: <47a21a36.2e7f.173c6d62960.Coremail.zhaowcheng@163.com> At 2020-08-06 23:17:57, "Richard Damon" wrote: >On 8/6/20 10:40 AM, Robin Becker wrote: >> On 06/08/2020 05:17, ZHAOWANCHENG wrote: >>> the doc of dictionary said "if a tuple contains any mutable object >>> either directly or indirectly, it cannot be used as a key." >>> i think a instance of user-defined class is mutable, but i found it >>> can be placed into a tuple that as a key of a dict: >>> >>> class mycls(object): >>> ... a = 1 >>> ... >>> >>> me = mycls() >>> >>> me.a = 2 # mutable? >>> >>> {(1, me): 'mycls'} >>> {(1, <__main__.mycls object at 0x0000022824DAD668>): 'mycls'} >>> >>> >>> >>> >>> So are instances of user-defined classes mutable or immutable? >>> >> user class instances are clearly mutable, and in my python 3.8 you can >> do horrid things like this >But since the 'mutation' doesn't affect the hash or the equality tests >on the object, is it really a mutation? >> >>>>>> class H: >>> ... a = 1 >>> ... def __hash__(self): >>> ... return hash(self.a) >>> ... >>>>>> h = H() >>>>>> hash(h) >>> 1 >>>>>> h.a =2 >>>>>> hash(h) >>> 2 >>>>>> t=(1,h) >>>>>> d={t:23} >>>>>> d >>> {(1, <__main__.H object at 0x7f5bf72021f0>): 23} >>>>>> hash(h) >>> 2 >>>>>> hash(list(d.keys())[0]) >>> -3550055125485641917 >>>>>> h.a=33 >>>>>> hash(list(d.keys())[0]) >>> -3656087029879219665 >>>>>> >> so the dict itself doesn't enforce immutability of its keys >Yes, here you have defined a hash that violates the requirements of the >Dictionary (and most things that use hashes) so your class is broken, >and you can expect to get strangeness out of your dictionary. >> -- >> Robin Becker >> > >-- >Richard Damon > >-- >https://mail.python.org/mailman/listinfo/python-list So instances of user-defined classes are immutable by default? Or the description of "if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key." in the document is not completely correct? The description mentioned above comes from here: https://docs.python.org/3/tutorial/datastructures.html#dictionaries From cseberino at gmail.com Thu Aug 6 23:07:05 2020 From: cseberino at gmail.com (Christian Seberino) Date: Thu, 6 Aug 2020 20:07:05 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> Message-ID: Some problems are well suited to recursion but perhaps //most// problems are better suited to iteration? Maybe the spread is 10% vs 90%? Therefore in general more often the Python way seems simpler than Lisp? From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Aug 6 23:41:10 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 6 Aug 2020 22:41:10 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> Message-ID: <20200807034110.GD42295@scrozzle> On 2020-08-06 at 20:07:05 -0700, Christian Seberino wrote: > Some problems are well suited to recursion but perhaps //most// > problems are better suited to iteration? > Maybe the spread is 10% vs 90%? Citation needed? > Therefore in general more often the Python way seems simpler than Lisp? In general, the right tool is simpler than the wrong tool, regardless of the problems and tools. Both Python and Lisp supoprt recursion, iteration, and a number of other mindsets, paradigms, patterns, and styles. If "the Python way" seems simpler to you than "the Lisp way," or iteration seems simpler to you than recursion, then so be it. Other languages and other programmers are different. Consider focusing less on the language and more on solving problems. You, the problems you solve, and your solutions, will all grow over time, and you'll discover what you like, what you don't like, what you're good at, what you're not so good at, what works, and what doesn't. And things will change. Solve the same problem in a different language, preferably idiomatically rather than by transliteration. Go back and look at code you wrote a few months or a year ago, laugh at yourself for being so immature, and apply what you've learned since then. Sometimes, it takes me only hours to realize how much better I could have written a piece of code. From rosuav at gmail.com Fri Aug 7 02:23:42 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 7 Aug 2020 16:23:42 +1000 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <20200807003543.GC8728@bladeshadow.org> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> Message-ID: On Fri, Aug 7, 2020 at 11:11 AM Python wrote: > Not necessarily. Some problems very naturally lend themselves to > recursive solutions. Fibonacci's sequence is one. > > #!/usr/bin/python > > def fib(x): > if x < 1: > raise "arg must be >= 1" > if x == 1: > return 0 > elif x == 2: > return 1 > else: > return fib(x - 1) + fib(x - 2) > > Pretty straightforward. Now try yourself to write the iterative > version. It might look slightly better to a mathematician, but it's so abysmally inefficient (unless you add extra layers of indirection) that it's not really a good example. The iterative version seeds the algorithm and lets it run: def fib(x): if x < 1: raise ValueError last, cur = 0, 1 for _ in range(1, x): last, cur = cur, last + cur return cur It needs a way of remembering the previous as well as the current, whereas the recursive one needs to ask to calculate the previous and previous-by-two. I'll leave it to you whether that's better or worse. But if you want something that is massively more elegant when done recursively, the best place to look is an inherently recursive data structure. How do you process all files in a directory tree? def process(dir): for thing in dir: if is_file_we_want(thing): use_thing(thing) if is_dir(thing) process(thing) Now THAT is recursion at its best. Of course it's possible to do it iteratively, but it won't be anything like this clean. There's a reason that directory tree operations are usually called "recursive" (eg "rm -r" means "remove directories and their contents recursively", per the man page). Similarly, quick sort and merge sort are beautiful when written recursively: def mergesort(list): if len(list) < 2: return list mid = len(list) // 2 left = mergesort(list[:mid]) right = mergesort(right[mid:]) return merge(left, right) I think recursion looks best when it's doing multiple levels at once (eg "sort the left, sort the right"), rather than just a single one (factorial being "n * factorial(n - 1)"), since it's a lot harder to create an elegant iterative version of multiple recursion. The Fibonacci example is a bit of an outlier, as the recursive one is just *so bad* in performance that it loses some elegance points, but the other examples don't suffer from that, and they're still very clean. ChrisA From tjreedy at udel.edu Fri Aug 7 00:59:27 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Aug 2020 00:59:27 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: On 8/6/2020 11:13 AM, Christian Seberino wrote: > Python is my favorite language and the easiest to use in my opinion. > > Lisp has a far simpler grammar and syntax. A beginner I think could > learn Lisp much faster than Python. > > Therefore, it seems like Lisp *should* be easier to work with and more readable. I don't feel like it is easier to use but I can't see *why* that is. > > My best guess..... > > Lisp pros: simpler syntax > Lisp cons: prefix notation, lots more parentheses > > My hypothesis is that the cons slightly outweigh the pros of Lisp > which is why Python is easier to work with and is more readable in the end? Here is why *I* prefer Python. 1. Python mostly separates computation of values (expressions) from flow control and name binding (statements). When the latter are mixed with the former, most people restrict the mixing to a line or two. 2. Lisp code is one dimensional (though I presume there are now formatting conventions). Python makes direct use of two dimensional structuring. 3. Forcing everything into linked lists is 'cute', but it introduces irrelevant asymmetries, differential nesting, and boilerplate that obscures the problem relevant structure. A list of equal status items: (1,2,3) versus (1 (2 (3 NIL))) A complete binary tree of depth 2: ((LL, LR), (RL, RR)) Left and right branches have same form. versus # ((LL, (LR, NIL)), ((RL, (RR, NIL)), NIL)) ((LL (LR NIL)) ((RL (RR NIL)) NIL)) Left and right branches have different forms. I think I got the Lisp version right, but I had to initially include commas to do so. Anyway, the Python version was much easier to write and is much easier to read. -- Terry Jan Reedy From tjreedy at udel.edu Fri Aug 7 04:49:05 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Aug 2020 04:49:05 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <20200806183947.GG2129@shallowsky.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> Message-ID: On 8/6/2020 2:39 PM, Akkana Peck wrote: > Christian Seberino writes: >> Python is my favorite language and the easiest to use in my opinion. >> >> Lisp has a far simpler grammar and syntax. A beginner I think could >> learn Lisp much faster than Python. >> >> Therefore, it seems like Lisp *should* be easier to work with and more readable. I don't feel like it is easier to use but I can't see *why* that is. > > First, everybody's brain is different so be cautious of sweeping > statements. What's true for one person isn't necessarily true for another. > > That said, for me, Lisp's simpler syntax arises from the fact that > there's basically one data structure: a list. In general, the one data structure is a tree*, skewed by being smashed into a linked list. Replaced 'list' with 'skewed tree' in what you say below, and I think you explain well the problem many have with thinking in Lisp. * One can think of a flat list of n items as being a one level n-ary tree with a head node and n leafs. A linked list is a skewed binary tree. > To do anything in > Lisp, you have to think in lists, map everything to lists (including > the program's own structure), build up list-based data structures in > your head. It's also functional and recursive, which means that as > you're programming, you have to maintain a stack (which is also a > list) in your head of all the lists that aren't yet closed. Of > course, you can use tricks like let and setq to hold intermediate > variables and mitigate that a little, but that isn't really Lispish. > > Trying to maintain that recursive list of unclosed lists in your > brain is fun. It stretches the brain in interesting ways. I was > way into Lisp at one point, including writing several Lisp > interpreters (that simple structure makes Lisp very easy to > implement). But I never found Lisp code very maintainable, because > any time you read a program, you have to build up that list in your > head every time just to follow the logic structure and figure out > what the return value will be. I suspect most people find that more > difficult than reading an inherently procedural language like > Python. I know I do. Stephen Wolfram's Mathematica is also based on the idea that 'everything is a symbolic expression'. With a somewhat more standard syntax, it found a sufficiently substantial audience to be a commercial success. It obviously fit *his* brain well enough that he was able to do a hugh number of different computations for his 2002 book A New Kind of Science. It fits me less well. -- Terry Jan Reedy From mats at wichmann.us Fri Aug 7 10:08:45 2020 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 7 Aug 2020 08:08:45 -0600 Subject: Are instances of user-defined classes mutable? In-Reply-To: <47a21a36.2e7f.173c6d62960.Coremail.zhaowcheng@163.com> References: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> <47a21a36.2e7f.173c6d62960.Coremail.zhaowcheng@163.com> Message-ID: <3e00734d-92c3-c39d-f8ce-766e378c1559@wichmann.us> On 8/6/20 8:53 PM, ZHAOWANCHENG wrote: > So instances of user-defined classes are immutable by default? No, they're clealry mutable. > Or the description of "if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key." in the document is not completely correct? It's correct, but is not relevant to your case, as you're asking about an object different than a tuple. When defining a class, you get by default a hash that is consistent, no matter what you do to the contents of an instance, so instances are eligible to be used as dict keys. You can define the class in a way that instances cannot be used as keys, by ensuring there is no hash function. From cseberino at gmail.com Fri Aug 7 10:53:53 2020 From: cseberino at gmail.com (Christian Seberino) Date: Fri, 7 Aug 2020 07:53:53 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807034110.GD42295@scrozzle> Message-ID: <9ce6a791-1305-4fc8-a05a-100506e32257o@googlegroups.com> > If "the Python way" seems simpler to you than "the Lisp way," > or iteration seems simpler to you than recursion, then so be it. Other > languages and other programmers are different. I think this is so true. I've had similar conversations with Lisp fans and it has confused me at times why they don't see the wonderfulness of Python like I do. As you said, everyone's brain isn't the same. Just have to remember that and accept it. cs From Richard at Damon-Family.org Fri Aug 7 11:00:55 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 7 Aug 2020 11:00:55 -0400 Subject: Are instances of user-defined classes mutable? In-Reply-To: <47a21a36.2e7f.173c6d62960.Coremail.zhaowcheng@163.com> References: <36b09210.3e37.173c1fcd05d.Coremail.zhaowcheng@163.com> <47a21a36.2e7f.173c6d62960.Coremail.zhaowcheng@163.com> Message-ID: <7918b654-dfcb-9fb6-2612-f989a2cb1a79@Damon-Family.org> On 8/6/20 10:53 PM, ZHAOWANCHENG wrote: > So instances of user-defined classes are immutable by default? > Or the description of "if a tuple contains any mutable object either > directly or indirectly, it cannot be used as a key." in the document > is not completely correct? > The description mentioned above comes from here: > https://docs.python.org/3/tutorial/datastructures.html#dictionaries My answer was pointing out in a very abstract sense, it is perhaps tricky to define what is 'mutability' for a class as it affects its use in a dictionary. The key here is to ask what does using a class as a key (or part of a key with a tuple) means. You build the dictionary, use a key value, and then you can look up that entry by passing an equal value key, and it will find the term. So we need to look at what it means for class objects to be equal, and the default for that checks for equality of the id(), not any of the members. This means that doing something like: a = myclass(10) b = myclass(10) d = { a: 1} trying to do a d[b] will throw a KeyError exception, as there is no item in the dict with that key. and if we ask a == b we get false (even though all their values match) This comes to the point that, for a class with the default equality operator, so equality is identity, do changing a member of a class object REALLY mutate the object as far as the dictionary is concerned? Changing the member value does NOT change what the key represents. Note also, once you define the equality testing function __eq__, then python makes the class non-hashable (unless you also define a __hash__ function) so a class like that can't be used as a part of a key in a dictionary, because it now has the ability to 'change' the value it represents. Going back to the original issue. A tuple can normally be used as a dictionary key (but a list can not) because it can build its hash as a combination of the hash for all its elements (as long as they are hashable, and the 'immutable' objects are) and thus be usable as a key. Since a list, unlike a tuple, allows you to mutate? the sequence by modifying the list, it can't provide the unchangable hash by the same method. When you put a class object into the tuple, as long as it still has it __hash__ member, because you haven't defined a __eq__ member, is at least to the tuple, immutable, as the only part of it that matters is the value of id() which WILL be unchanging. -- Richard Damon From cseberino at gmail.com Fri Aug 7 11:01:06 2020 From: cseberino at gmail.com (Christian Seberino) Date: Fri, 7 Aug 2020 08:01:06 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> Message-ID: <0fdafae0-af8c-4d81-9860-1a2bdaf25501o@googlegroups.com> > ChrisA You're definitely an expert programmer. From python at bladeshadow.org Fri Aug 7 11:06:44 2020 From: python at bladeshadow.org (Python) Date: Fri, 7 Aug 2020 10:06:44 -0500 Subject: Explicit is better than Implicit In-Reply-To: <20200807004625.GD8728@bladeshadow.org> References: <20200806223433.GA98176@cskk.homeip.net> <20200807004625.GD8728@bladeshadow.org> Message-ID: <20200807150644.GF8728@bladeshadow.org> On Thu, Aug 06, 2020 at 07:46:25PM -0500, Python wrote: > On Thu, Aug 06, 2020 at 07:19:01PM -0500, Skip Montanaro wrote: > Python is *actually* easy to work with... most of the time. "If you > want more things for you buck there's no luck..." =8^) [And yes, I'm aware the line is "beats" not "things" but since Python usually doesn't have "beats" (though it can!) I paraphrased a bit...] From rosuav at gmail.com Fri Aug 7 11:07:57 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Aug 2020 01:07:57 +1000 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <0fdafae0-af8c-4d81-9860-1a2bdaf25501o@googlegroups.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <0fdafae0-af8c-4d81-9860-1a2bdaf25501o@googlegroups.com> Message-ID: On Sat, Aug 8, 2020 at 1:06 AM Christian Seberino wrote: > > > > ChrisA > > You're definitely an expert programmer. > Uhh.... thank you? I think? I'm not sure if you're complimenting me or making some sort of joke relating to the code I posted, or if it's actually nothing to do with me at all. All you quoted - the only context we have - is my scribbled signature at the bottom of the post. ChrisA From cseberino at gmail.com Fri Aug 7 11:06:04 2020 From: cseberino at gmail.com (Christian Seberino) Date: Fri, 7 Aug 2020 08:06:04 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: > 1. Python mostly separates computation of values (expressions) from flow > control and name binding (statements). When the latter are mixed with > the former, most people restrict the mixing to a line or two. This is an interesting observation. I've heard people say the fact that Python has both expressions and statements is a negative. (Lisp only has expressions.) It isn't clear to me what special Python syntax or forms you are referring to that separates expressions from flow control and assignments. From python at bladeshadow.org Fri Aug 7 11:36:15 2020 From: python at bladeshadow.org (Python) Date: Fri, 7 Aug 2020 10:36:15 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> Message-ID: <20200807153615.GG8728@bladeshadow.org> On Fri, Aug 07, 2020 at 04:23:42PM +1000, Chris Angelico wrote: > On Fri, Aug 7, 2020 at 11:11 AM Python wrote: > > Pretty straightforward. Now try yourself to write the iterative > > version. > > It might look slightly better to a mathematician, but it's so > abysmally inefficient (unless you add extra layers of indirection) > that it's not really a good example. Yes, I did say more or less that... but efficiency was not the point. Understanding was the point. > The iterative version seeds the algorithm and lets it run: Sure Chris, I fully expected YOU to get this on the first try, but the average programmer tends not to. My team uses it as an interview question fairly often, and I'd venture a guess that upward of 80% of candidates get it wrong on their first try. The recursive version is typically much easier to understand intuitively, not just for mathemeticians, because it more or less restates in simple, straightforward code what the natural language definition of the Fibonacci sequence is, rather efficiently (not efficiency of execution, efficiency of converting natural language to code). The iterative version requires a bit more thought to make sure you're seeding the state poperly, and maintaining it properly as the loop executes. I'd imagine most folks who hang around in this forum would consider that you are not an average programmer. Your example was also a fine example. From rosuav at gmail.com Fri Aug 7 11:46:28 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Aug 2020 01:46:28 +1000 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <20200807153615.GG8728@bladeshadow.org> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: On Sat, Aug 8, 2020 at 1:38 AM Python wrote: > > On Fri, Aug 07, 2020 at 04:23:42PM +1000, Chris Angelico wrote: > > On Fri, Aug 7, 2020 at 11:11 AM Python wrote: > > > Pretty straightforward. Now try yourself to write the iterative > > > version. > > > > It might look slightly better to a mathematician, but it's so > > abysmally inefficient (unless you add extra layers of indirection) > > that it's not really a good example. > > Yes, I did say more or less that... but efficiency was not the point. > Understanding was the point. > > > The iterative version seeds the algorithm and lets it run: > > Sure Chris, I fully expected YOU to get this on the first try, but the > average programmer tends not to. My team uses it as an interview > question fairly often, and I'd venture a guess that upward of 80% of > candidates get it wrong on their first try. The recursive version > is typically much easier to understand intuitively, not just for > mathemeticians, because it more or less restates in simple, > straightforward code what the natural language definition of the > Fibonacci sequence is, rather efficiently (not efficiency of > execution, efficiency of converting natural language to code). > My point is that doing Fibonacci recursively is arguably more elegant while being materially worse at performance, but there are other examples that are fundamentally recursive, are just as elegant (merge sort: "fracture the array in half, sort each half, then merge them"), and can't be done better iteratively. So IMO Fibonacci is a flawed demonstration of what is a very valid point ("recursion can be really elegant"), and other examples would serve the purpose better. TBH most people won't get the recursive version right the first time either. And that's not a problem. I actually didn't get the iterative version perfect right away (had an off-by-one on the loop counter), and tested it before posting. Every student I've worked with has had the same thing - something doesn't work the first time, even with the most brilliant students - so they test, they debug, and then they refine their code. I'm not some sort of coding deity that gets things right the first time; the medium of email lets me hide the testing/debugging step and just post working code :) ChrisA From Marco.Sulla.Python at gmail.com Fri Aug 7 11:55:45 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Fri, 7 Aug 2020 17:55:45 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: On Fri, 7 Aug 2020 at 17:14, Christian Seberino wrote: > This is an interesting observation. I've heard people say the fact that > Python has both expressions and statements is a negative. (Lisp only > has expressions.) Commonly, in imperative languages like C, you can write if (a = b) {...} This is allowed in C, even if a = b is not an expression, but an assignment statement. 99% of times you simply wrong and wanted: if (a == b) Python separates statements and expressions, so where you expect an expression, you can't write a statement. Maybe Lisp does not separate expressions and statements because it supports both functional and imperative programming, while Python is mainly an imperative language with some functional features. Not sure about this, since I never used any Lisp dialect and I've not yet used function programming in the real world. PS: Recently there's an exception: if you *really* want an assignment when an expression is expected, you can use the "walrus" := operator. IMO it renders the code less readable and I'm not sure about it's usefulness. @Chris: note that "real" recursion in Python is not possible, since there's no support for tail recursion. Maybe something similar can be done using async functions. From auriocus at gmx.de Fri Aug 7 11:59:47 2020 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 7 Aug 2020 17:59:47 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: Am 06.08.20 um 17:13 schrieb Christian Seberino: > Python is my favorite language and the easiest to use in my opinion. > > Lisp has a far simpler grammar and syntax. A beginner I think could > learn Lisp much faster than Python. > > Therefore, it seems like Lisp *should* be easier to work with and more readable. I don't feel like it is easier to use but I can't see *why* that is. > > My best guess..... > > Lisp pros: simpler syntax > Lisp cons: prefix notation, lots more parentheses > > My hypothesis is that the cons slightly outweigh the pros of Lisp > which is why Python is easier to work with and is more readable in the end? I concur with Chris Angelico there. The word "simple" is ambiguous. "Simpler" for the human is not the same as "simpler" for the computer In Lisp, the grammar is "simpler", meaining that the definition of the grammar is shorter; this makes it simpler for the compiler to parse, and to write a compiler for Lisp. In Python, the grammar is very complicated, writing a compiler for Python is a big task - still it is "simpler" to translate your ideas into Python It is related to the old saying "if all you have is hammer, then everything looks like a nail". In Lisp, your hammer is the list. So you are forced to map your problems onto list processing. For some things that works well, for others not so well (infix math....) . In, say, Java, your tool is classes and inheritance. There are big books on "design patterns" that teach you how to map your problem onto inheritance. For some things, that works well, for others not so well ("abstract factory", "visitor pattern", ....) In Python, you have an awfully complex of syntax, so your toolset includes list processing, lambda, inheritance, string interpolation, decorators.... This makes it possible to use the tool which best matches the language of your problem. Many problem domains have their own language, e.g. matrix math for linear algebra, pipes for sequential stream processing etc. The easier it is to translate the algorithm on paper into the runnable version, the Lisp is still impressive, because it is very good at metaprogramming. It shows how far you can get with so little syntax. Another point to consider is the ecosystem of your language. If you install Python, then you get basic math, I/O, a GUI toolkit, network libraries, ... In more "traditional" languages like C or Lisp, you get math and I/O, period. For everything else you need to hunt down a library. Therefore, solve the task "download the gimp installer from github via https" requires 2,3 lines in Python and installing a (possibly complex) library for the same task in Lisp or C. Christian From akkana at shallowsky.com Fri Aug 7 12:00:25 2020 From: akkana at shallowsky.com (Akkana Peck) Date: Fri, 7 Aug 2020 10:00:25 -0600 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <20200807014816.GC42295@scrozzle> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807014816.GC42295@scrozzle> Message-ID: <20200807160025.GA1974@shallowsky.com> I wrote: > > > Trying to maintain that recursive list of unclosed lists in your > > > brain is fun. It stretches the brain in interesting ways. > > > [ ... ] But I never found Lisp code very maintainable, [ ... ] 2QdxY4RzWzUUiLuE at potatochowder.com writes: > "[R]ecursive list of unclosed lists"? Can you (whoever you are) expand > on that? Yes, if you eschew helper functions and local variables, then > you can end up with depply nested code, but that's true in any language. To pick a function that I know is readily available in lots of languages, let's look at a couple implementations of the Haversine function (from http://rosettacode.org/wiki/Haversine_formula). Comments to illustrate language differences are mine. Here's the Common Lisp version. (defparameter *earth-radius* 6372.8) (defparameter *rad-conv* (/ pi 180)) ;; Minor complication right off: assignment of variables or constants ;; is completely different depending on whether you're ;; defining something in general, like here, or only for ;; a subsequent clause, like the let* functions later on. (defun deg->rad (x) (* x *rad-conv*)) ;; Prefix notation for arithmatic is unfamiliar to most people ;; since that's not what we learn in school, so that's a first ;; hurdle for readability. (defun haversine (x) (expt (sin (/ x 2)) 2)) ;; To grok this function you need to have four levels of ;; parentheses simultaneously open in your head. (defun dist-rad (lat1 lng1 lat2 lng2) (let* ((hlat (haversine (- lat2 lat1))) ;; Then there's the let vs. let* issue, ;; no big deal for experienced programmers ;; but not entirely easy to explain to a beginner. ;; On the other hand, Python has its own confusing points on ;; that issue, like when you need to specify "global". (hlng (haversine (- lng2 lng1))) (root (sqrt (+ hlat (* (cos lat1) (cos lat2) hlng))))) ;; for that expression you need 7 levels of mental parens open (* 2 *earth-radius* (asin root)))) (defun dist-deg (lat1 lng1 lat2 lng2) (dist-rad (deg->rad lat1) (deg->rad lng1) (deg->rad lat2) (deg->rad lng2))) ;; End Lisp example Seven levels of unclosed lists that you need to keep in your head in order to read and understand the program at its deepest point. Here's the same thing in Python: from math import radians, sin, cos, sqrt, asin def haversine(lat1, lon1, lat2, lon2): R = 6372.8 # Earth radius in kilometers dLat = radians(lat2 - lat1) dLon = radians(lon2 - lon1) lat1 = radians(lat1) lat2 = radians(lat2) a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 c = 2 * asin(sqrt(a)) return R * c # end Python example The equation is still the same equation, but it looks a lot more like the equation you'd see in a math textbook, or write on a homework assignment, modulo notational issues like ** instead of superscripts. The deepest level of parentheses you ever need to keep in your head is two, but the second level is just a very simple function call, sqrt(a). The indentation level (the program structure) never gets beyond one. On the other hand, your brain does need to keep track of more intermediate variables (dLat, dLon etc.) Perhaps some people might find that harder. And yes, you could write the Lisp to look more like the Python or vice versa. You're welcome to try that, but I predict you'll find that even if you use the same number of intermediate variables, Lisp will always require you to keep that larger mental stack of open parens. > Because of Lisp's simple syntax, text editors can nearly completely > relieve the programmer from the tedium of indenting and formatting, and > even closing parenthesis, which also highlights missing/extra/unbalanced > parentheses pretty quickly. I find that emacs mostly does a pretty good job of figuring out indentation, closing parentheses, highlighting syntax errors and similar boilerplate in Python. Maybe you need a smarter text editor? But my comment about levels of parens had nothing to do with editors. To understand the code, you need to build up that list/tree structure in your head, because that's what defines the program logic. Again, my point isn't that Python is a better or simpler language than Lisp. It's that it stretches the brain in different ways, and that I would guess (but it's just a guess) that most beginners will find the Python approach more intuitive and easier to learn, since it emphasizes things they've done before (simple declarative statements, equations written out in a familiar way) rather than new and unfamiliar concepts (prefix notation, deeply nested parentheses, tree structures). ...Akkana From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Aug 7 12:19:33 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 7 Aug 2020 11:19:33 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: <20200807161933.GE42295@scrozzle> On 2020-08-07 at 17:55:45 +0200, Marco Sulla wrote: > On Fri, 7 Aug 2020 at 17:14, Christian Seberino wrote: > Commonly, in imperative languages like C, you can write > > if (a = b) {...} > > This is allowed in C, even if a = b is not an expression ... In C, a = b *is* an expression. An assignment expression that uses the assignment operator. See . > ... 99% of times you simply wrong and wanted: > if (a == b) Where did 99% come from? > Python separates statements and expressions, so where you expect an > expression, you can't write a statement. Yes. > Maybe Lisp does not separate expressions and statements because it > supports both functional and imperative programming ... It's not a matter of separating expressions from statements. Lisp doesn't have statements. It only has expressions. If you choose to write imperative code in Lisp, all you're really doing is using the expressions for their side effects rather than their values. > PS: Recently there's an exception: if you *really* want an assignment > when an expression is expected, you can use the "walrus" := operator. > IMO it renders the code less readable and I'm not sure about it's > usefulness. It makes some code more concise. Readability is in the eye of the beholder. > @Chris: note that "real" recursion in Python is not possible, since > there's no support for tail recursion. Maybe something similar can be > done using async functions. Python has real recursion. Whether or not there's tail recursion on the inside is an implementation detail. From Richard at Damon-Family.org Fri Aug 7 12:24:25 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 7 Aug 2020 12:24:25 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: On 8/7/20 11:55 AM, Marco Sulla wrote: > Commonly, in imperative languages like C, you can write > > if (a = b) {...} > > This is allowed in C, even if a = b is not an expression, but an > assignment statement. 99% of times you simply wrong and wanted: But in C (and related languages) it IS an expression, and C doesn't have an 'assignment statement' but an 'expression statement', which is the source of the issue. = is just another operator, which happens to modify the value of its left operand. Python makes assignment a full top level type of statement, so = can't be misused in an expression thinking it means an equality test (and then added recently the := operator, so that for the cases you actually want to do assignments in the middle of an expression you can). -- Richard Damon From Richard at Damon-Family.org Fri Aug 7 12:43:02 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 7 Aug 2020 12:43:02 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: On 8/7/20 11:46 AM, Chris Angelico wrote: > My point is that doing Fibonacci recursively is arguably more elegant > while being materially worse at performance, but there are other > examples that are fundamentally recursive, are just as elegant (merge > sort: "fracture the array in half, sort each half, then merge them"), > and can't be done better iteratively. So IMO Fibonacci is a flawed > demonstration of what is a very valid point ("recursion can be really > elegant"), and other examples would serve the purpose better. I would say that doing the recursive Fibonacci version can be an important step (near the end) of the recursion unit as a learning experience on some of the dangers of recursion (like turning an O(N) problem into O(2**N). It perhaps can lead to discussions on optimization techniques (like caching results) that can alleviate some of the issues (at other costs). -- Richard Damon From rosuav at gmail.com Fri Aug 7 12:45:02 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Aug 2020 02:45:02 +1000 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <20200807161933.GE42295@scrozzle> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200807161933.GE42295@scrozzle> Message-ID: On Sat, Aug 8, 2020 at 2:21 AM <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > On 2020-08-07 at 17:55:45 +0200, > Marco Sulla wrote: > > @Chris: note that "real" recursion in Python is not possible, since > > there's no support for tail recursion. Maybe something similar can be > > done using async functions. > > Python has real recursion. Whether or not there's tail recursion on the > inside is an implementation detail. More specifically: Python has real recursion. Whether or not tail recursion is optimized away is an implementation detail. Tail call optimization (there's no reason to restrict it to recursion alone) is something a Python implementation could choose to do, but the trouble is that full optimization tends to destroy traceback information, so it's often not worth doing. And the cases where partial optimization is of value just aren't compelling enough for anyone to implement it into CPython, nor any other major implementation (to my knowledge). The biggest uses for TCO tend to be the situations where recursion is the wrong solution to the problem. But recursion? Recursion is definitely possible. ChrisA From rosuav at gmail.com Fri Aug 7 12:49:17 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Aug 2020 02:49:17 +1000 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: On Sat, Aug 8, 2020 at 2:44 AM Richard Damon wrote: > > On 8/7/20 11:46 AM, Chris Angelico wrote: > > My point is that doing Fibonacci recursively is arguably more elegant > > while being materially worse at performance, but there are other > > examples that are fundamentally recursive, are just as elegant (merge > > sort: "fracture the array in half, sort each half, then merge them"), > > and can't be done better iteratively. So IMO Fibonacci is a flawed > > demonstration of what is a very valid point ("recursion can be really > > elegant"), and other examples would serve the purpose better. > > I would say that doing the recursive Fibonacci version can be an > important step (near the end) of the recursion unit as a learning > experience on some of the dangers of recursion (like turning an O(N) > problem into O(2**N). It perhaps can lead to discussions on optimization > techniques (like caching results) that can alleviate some of the issues > (at other costs). Yes, I'd definitely agree. It's great to have some demonstrations of the advantages and disadvantages of recursion, and Fibonacci offers both in one tidy package :) Here's another really great example: triangle numbers. def tri(n): if n < 1: return 0 return n + tri(n - 1) def tri(n): tot = n for i in range(n): tot += i return tot def tri(n): return functools.reduce(operator.add, range(n + 1)) def tri(n): return n * (n + 1) // 2 A great demo of different ways to think about the same problem, with a nice O(1) reference at the end that you can validate them against :) ChrisA From Marco.Sulla.Python at gmail.com Fri Aug 7 12:52:48 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Fri, 7 Aug 2020 18:52:48 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: About statement vs expression: maybe you, Richard and 2QdxY4RzWzUUiLuE, are right, maybe not. This is hard to say, since the official C documentation is not public and you have to pay a small fee to obtain it. Anyway, I said "in C, the assignment is a statement that can be used in expression". You're saying "No, in C the assignment IS an expression". I don't see the difference. If the assignment is a statement that can be used as an expression, Python simply forbids that. If in C the assignment is an expression, Python on the contrary treats it as a statement. The only real difference is that Python not only clearly separated the concepts of statement and expression, but also _where_ you can use them, for practical reasons. From Marco.Sulla.Python at gmail.com Fri Aug 7 12:54:42 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Fri, 7 Aug 2020 18:54:42 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200807161933.GE42295@scrozzle> Message-ID: On Fri, 7 Aug 2020 at 18:48, Chris Angelico wrote: > Tail call optimization (there's no reason to restrict it to recursion > alone) is something a Python implementation could choose to do, but > the trouble is that full optimization tends to destroy traceback > information Indeed this is implemented in asyncio. From cseberino at gmail.com Fri Aug 7 13:19:11 2020 From: cseberino at gmail.com (Christian Seberino) Date: Fri, 7 Aug 2020 10:19:11 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <0fdafae0-af8c-4d81-9860-1a2bdaf25501o@googlegroups.com> Message-ID: Your iterative fib(x) code and comment was quite nice. From cseberino at gmail.com Fri Aug 7 13:35:50 2020 From: cseberino at gmail.com (Christian Seberino) Date: Fri, 7 Aug 2020 10:35:50 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: > Another point to consider is the ecosystem of your language. If you > install Python, then you get basic math, I/O, a GUI toolkit, network > libraries, ... In more "traditional" languages like C or Lisp, you get > math and I/O, period. For everything else you need to hunt down a > library. Therefore, solve the task "download the gimp installer from > github via https" requires 2,3 lines in Python and installing a > (possibly complex) library for the same task in Lisp or C. > > Christian I like this post so much I printed it. It seems you're saying Python has lots of syntax forms or "mini-languages" in it and *that* is a big reason why you can typically find syntax that makes an arbitrary problem more readable in Python. On the other hand, Lisp tries to everything with less syntax forms (paradigms) and hence it is less readable. A Lisp person would probably say that they can create domain specific languages (DSLs) for whatever they wish. However, many people like that Python has so many standardized "DSLs" ready to go for you from the start. I think this is really significant point why more syntax does necessarily mean less readability. I would just add that Clojure finally solved the ecosystem problem with Lisp by giving it access to the Java libraries. cs From Richard at Damon-Family.org Fri Aug 7 13:46:25 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 7 Aug 2020 13:46:25 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: On 8/7/20 12:52 PM, Marco Sulla wrote: > About statement vs expression: maybe you, Richard and > 2QdxY4RzWzUUiLuE, are right, maybe not. This is hard to say, since the > official C documentation is not public and you have to pay a small fee > to obtain it. > > Anyway, I said "in C, the assignment is a statement that can be used > in expression". You're saying "No, in C the assignment IS an > expression". > I don't see the difference. If the assignment is a statement that can > be used as an expression, Python simply forbids that. If in C the > assignment is an expression, Python on the contrary treats it as a > statement. > > The only real difference is that Python not only clearly separated the > concepts of statement and expression, but also _where_ you can use > them, for practical reasons. The difference is that the two languages define 'expression' differently. In Python, the = operation is not part of the general expression syntax, but is specifically allowed only in specific locations. In C, the = operator is exactly like all the other operators in how it is parsed, it just has some restrictions on the type that can be on the left side, and that it changes that value (but then, so do a few other operators like ++) In C, there is NO 'statement' called an assignment statement, because assignments are just parts of expressions, so the statement type 'expression statement' handles both. In Python, because assignment is NOT just part of an expression, it needs a separate statement type to handle assignments, to allow them. (BTW, while the official C Standards are only available at a price, the draft standards prepared during the development of the final are all available for free and the last published draft standard is almost always virtually identical to the final released standard, so most people will just use those. People who really need the official versions can pay the price for it, and for them, that price isn't that high to them). I keep the free downloads of all the major version of the C and C++ language available on my computer. -- Richard Damon From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Aug 7 13:56:00 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 7 Aug 2020 12:56:00 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <20200807160025.GA1974@shallowsky.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807014816.GC42295@scrozzle> <20200807160025.GA1974@shallowsky.com> Message-ID: <20200807175600.GF42295@scrozzle> On 2020-08-07 at 10:00:25 -0600, Akkana Peck wrote: > I wrote: > > > > Trying to maintain that recursive list of unclosed lists in your > > > > brain is fun. It stretches the brain in interesting ways. > > > > [ ... ] But I never found Lisp code very maintainable, [ ... ] > > 2QdxY4RzWzUUiLuE at potatochowder.com writes: > > "[R]ecursive list of unclosed lists"? Can you (whoever you are) expand > > on that? Yes, if you eschew helper functions and local variables, then > > you can end up with depply nested code, but that's true in any language. > > To pick a function that I know is readily available in lots > of languages, let's look at a couple implementations of the > Haversine function (from http://rosettacode.org/wiki/Haversine_formula). > Comments to illustrate language differences are mine. > > Here's the Common Lisp version. > > (defparameter *earth-radius* 6372.8) > (defparameter *rad-conv* (/ pi 180)) > ;; Minor complication right off: assignment of variables or constants > ;; is completely different depending on whether you're > ;; defining something in general, like here, or only for > ;; a subsequent clause, like the let* functions later on. > > (defun deg->rad (x) > (* x *rad-conv*)) > ;; Prefix notation for arithmatic is unfamiliar to most people > ;; since that's not what we learn in school, so that's a first > ;; hurdle for readability. My first calculator was RPN, so prefix wasn't really a hurdle. ;-) > (defun haversine (x) > (expt (sin (/ x 2)) 2)) > ;; To grok this function you need to have four levels of > ;; parentheses simultaneously open in your head. > > (defun dist-rad (lat1 lng1 lat2 lng2) > (let* ((hlat (haversine (- lat2 lat1))) > ;; Then there's the let vs. let* issue, > ;; no big deal for experienced programmers > ;; but not entirely easy to explain to a beginner. > ;; On the other hand, Python has its own confusing points on > ;; that issue, like when you need to specify "global". > (hlng (haversine (- lng2 lng1))) > (root (sqrt (+ hlat (* (cos lat1) (cos lat2) hlng))))) > ;; for that expression you need 7 levels of mental parens open > (* 2 *earth-radius* (asin root)))) > > (defun dist-deg (lat1 lng1 lat2 lng2) > (dist-rad (deg->rad lat1) > (deg->rad lng1) > (deg->rad lat2) > (deg->rad lng2))) > > ;; End Lisp example > > Seven levels of unclosed lists that you need to keep in your head > in order to read and understand the program at its deepest point. Seven? Oh, there it is, inside the calculation of root in dist-rad. > Here's the same thing in Python: It's equivalent. It's not the same. (For example, in Lisp, the parameters are clearly marked as such by the form defparameter, but in Python, the parameters and the temporary variables are created with the same syntax. When I read the Python code, how can I tell that R is a parameter rather than a temporary variable? But that's not related to the question of open parentheses. Also, the Lisp example separates the conversion to radians into a helper function, but the Python version doesn't.) > from math import radians, sin, cos, sqrt, asin > > def haversine(lat1, lon1, lat2, lon2): > R = 6372.8 # Earth radius in kilometers > > dLat = radians(lat2 - lat1) > dLon = radians(lon2 - lon1) > lat1 = radians(lat1) > lat2 = radians(lat2) > > a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2 > c = 2 * asin(sqrt(a)) > > return R * c > > # end Python example > > The equation is still the same equation, but it looks a lot more > like the equation you'd see in a math textbook, or write on a > homework assignment, modulo notational issues like ** instead of > superscripts. The deepest level of parentheses you ever need to > keep in your head is two, but the second level is just a very > simple function call, sqrt(a). The indentation level (the program > structure) never gets beyond one. > > On the other hand, your brain does need to keep track of more > intermediate variables (dLat, dLon etc.) Perhaps some people might > find that harder. On the other other hand, there's no confusing operator precedence rules in Lisp. We know the basic arithmetic operators from grade school, but who can remember whether & or and bind more tightly than or and | (sic)? Instead of memory, some programmers use *parentheses* to *clarify*. ;-) > And yes, you could write the Lisp to look more like the Python or > vice versa. You're welcome to try that, but I predict you'll find that > even if you use the same number of intermediate variables, Lisp will > always require you to keep that larger mental stack of open parens. A larger stack of *parentheses*, yes, but I don't think a larger stack. Python: def f(x): y = b + m * x return y Lisp: (defun f (x) (let ((y (+ b (* m x)))) y)) A function definition, a temporary variable, the familiar "point slope" artithmetic, and the result of the calculation/function. Now that I've seen enough Lisp, the parentheses disappear into the whitespace. > > Because of Lisp's simple syntax, text editors can nearly completely > > relieve the programmer from the tedium of indenting and formatting, and > > even closing parenthesis, which also highlights missing/extra/unbalanced > > parentheses pretty quickly. > > I find that emacs mostly does a pretty good job of figuring out > indentation, closing parentheses, highlighting syntax errors and > similar boilerplate in Python. Maybe you need a smarter text editor? Emacs... emacs... emacs... Oh, yeah! Emacs! I used to edit my own config.h file, before the great emacs/xemacs schism (and I'm using a more modern version to compose this email). ;-) > But my comment about levels of parens had nothing to do with editors. > To understand the code, you need to build up that list/tree > structure in your head, because that's what defines the program logic. > > Again, my point isn't that Python is a better or simpler language > than Lisp. It's that it stretches the brain in different ways, and that > I would guess (but it's just a guess) that most beginners will find > the Python approach more intuitive and easier to learn, since it > emphasizes things they've done before (simple declarative statements, > equations written out in a familiar way) rather than new and unfamiliar > concepts (prefix notation, deeply nested parentheses, tree structures). Aha. I think. In Python, different levels of logical nesting use different physical representations. Indentation, parentheses, operators (and operator precedence), keywords, colons. But in Lisp, the only tool you have is parentheses (humans use whitespace sometimes, but the compiler ignores it). The differences are likely real, and perhaps moreso to beginners, but if the nesting is too deep, in either case, refactor, and everyone has their own definition of "too deep." For completeness, let's not forget Greenspun's Tenth (which really isn't about the syntax) and Lisp's loop macro (which *is* entirely all about the syntax). ;-) From cseberino at gmail.com Fri Aug 7 14:02:50 2020 From: cseberino at gmail.com (Christian Seberino) Date: Fri, 7 Aug 2020 11:02:50 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: <52abf664-ddf9-4cb9-883f-a105dc864deeo@googlegroups.com> > In Lisp, your hammer is the list. > In, say, Java, your tool is classes and inheritance. And yet if Lisp or Java programmers were here they would say their languages //are// multi-paradigm too. For example, Lisp has the Common Lisp Object System (CLOS) and Java has the Vector class and so on. Maybe Python somehow gives more paradigms //better// syntax support whereas in Lisp and Java they are somewhat "bolted on" and not done as well? cs From wyatt.biggs at gmail.com Fri Aug 7 14:43:06 2020 From: wyatt.biggs at gmail.com (Wyatt Biggs) Date: Fri, 7 Aug 2020 13:43:06 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? Message-ID: > It's also probably significantly slower, so you'd likely still want to > use the iterative version Generalizing this to the majority of recursive functions/methods, are their iterative counterparts more efficient? (I say "majority of" because I've personally encountered one or two recursive functions/methods that were either very difficult for me to translate to iteration or just not possible with my skill level at the time) > It is related to the old saying "If all you have is a hammer, then > everything looks like a nail". Using this saying in the context of programming languages is extremely accurate! Because Python can be object oriented or data oriented, it is a large toolbox capable of tackling an even larger set of problems quite simply. I've never personally used Lisp, but I have used Java a bit. Even just the strict object-oriented nature of Java was fairly cumbersome. The freedom, fluidity, and the dynamic nature of Python are the reasons it's my preferred language. For just a moment, allow me to abstract this argument to include languages other than Lisp I'm better versed in. Older languages, like Java and C, required explicit typing for their variables, explicit output types for their methods, and semicolons and brackets instead of utilized whitespace. Please correct me if I'm wrong, but this system was primarily for saving memory because computers were far less powerful when these languages were born. Python, being a relatively young language, is free from these shackles and was built to run on more modern computers where bits and bytes are not a common constraint. That said, if I were to ever design a software I planned on sharing, I would write it in one of the more space-friendly languages. Thank y'all for the great reading about Lisp vs Python and letting me get very off-topic. Best, Wyatt Biggs From Marco.Sulla.Python at gmail.com Fri Aug 7 15:54:35 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Fri, 7 Aug 2020 21:54:35 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: On Fri, 7 Aug 2020 at 19:48, Richard Damon wrote: > The difference is that the two languages define 'expression' differently. [...] I don't know if this is interesting or pertinent to the topic. Christian Seberino just expressed a doubt about how a clear separation between a statement and an expression is quite desiderable in the "real" programming world. And I tried to explain it with the assignment operation, since a ton of programmers feel very frustrated about reading code of other programmers with assignment in an if statement. I'm quite sure that they thought, as I thought: "What do this?" Worse when their program failed and they discovered that they wrote `if (a=b)` instead of `if (a==b)`. I'm just more curious about why Lisp programmers think that it's better to not make a hard distinction between statements and expressions. From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Aug 7 16:04:26 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 7 Aug 2020 15:04:26 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <52abf664-ddf9-4cb9-883f-a105dc864deeo@googlegroups.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <52abf664-ddf9-4cb9-883f-a105dc864deeo@googlegroups.com> Message-ID: <20200807200426.GG42295@scrozzle> On 2020-08-07 at 11:02:50 -0700, Christian Seberino wrote: > > In Lisp, your hammer is the list. > > > In, say, Java, your tool is classes and inheritance. > > And yet if Lisp or Java programmers were here they would say their > languages //are// multi-paradigm too. For example, Lisp has the > Common Lisp Object System (CLOS) and Java has the Vector class and so on. Of what is "Java has the Vector class" an example? That the tools in Java are classes and inheritance? From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Aug 7 16:18:19 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 7 Aug 2020 15:18:19 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: <20200807201819.GH42295@scrozzle> On 2020-08-07 at 21:54:35 +0200, Marco Sulla wrote: > On Fri, 7 Aug 2020 at 19:48, Richard Damon wrote: > Christian Seberino just expressed a doubt about how a clear separation > between a statement and an expression is quite desiderable in the > "real" programming world. And I tried to explain it with the > assignment operation, since a ton of programmers feel very frustrated > about reading code of other programmers with assignment in an if > statement. I'm quite sure that they thought, as I thought: "What do > this?" > Worse when their program failed and they discovered that they wrote > `if (a=b)` instead of `if (a==b)`. Don't conflate the concept with the syntax. The fact that Python now has "the walrus operator" says that assignment expressions are useful. The issue with the C version is that the assignment and comparison operators look too much alike and using the wrong one can cause *silent* catastrophes (although modern C compilers can and do emit appropriate warnings or errors, if you ask them nicely). > I'm just more curious about why Lisp programmers think that it's > better to not make a hard distinction between statements and > expressions. Simplicity of syntax. Very few languages have a simpler syntax than Lisp (Ook, et al, notwithstanding). From tjreedy at udel.edu Fri Aug 7 16:08:06 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Aug 2020 16:08:06 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: On 8/7/2020 11:46 AM, Chris Angelico wrote: > My point is that doing Fibonacci recursively is arguably more elegant > while being materially worse at performance. This is a common misconception. Linear iteration and tail recursion are equivalent. The issue is calculating values once versus multiple times. Here is the fast recursion equivalent to the fast iteration. def fib(n, pair=(1,0)): previous, current = pair if n: return fib(n-1, (current, previous + current)) else: return current for i in range(10): print(fib(i), end=' ') # 0 1 1 2 3 5 8 13 21 34 One can also do the slow algorithm, with wasteful duplication, iteratively with one or two stacks of values instead of the hidden stack of execution frames. I don't remember the details right now without checking a text. -- Terry Jan Reedy From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Aug 7 16:40:37 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 7 Aug 2020 15:40:37 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: Message-ID: <20200807204037.GI42295@scrozzle> On 2020-08-07 at 13:43:06 -0500, Wyatt Biggs wrote: > > It's also probably significantly slower, so you'd likely still want to > > use the iterative version > > Generalizing this to the majority of recursive functions/methods, are > their iterative counterparts more efficient? (I say "majority of" > because I've personally encountered one or two recursive > functions/methods that were either very difficult for me to translate > to iteration or just not possible with my skill level at the time) As usual, it depends. :-) Often, a recursive algorithn in the *source* code is rewritten/optimized by a compiler into an iterative algorithm in the *object* code. And sometimes, iterative code is rewritten into straight line imperative code (i.e., loop unrolling, constant folding, etc.). At runtime, that stack of pending items has to be somewhere, and the hardware stack (where the CPU-level return addresses are stored) can be as good a place as any, which means that the recursive version *might* be as fast or faster than the iterative version, under certain circunstances. > For just a moment, allow me to abstract this argument to include > languages other than Lisp I'm better versed in. Older languages, like > Java and C, required explicit typing for their variables, explicit > output types for their methods, and semicolons and brackets instead of > utilized whitespace. Please correct me if I'm wrong, but this system > was primarily for saving memory because computers were far less > powerful when these languages were born. Python, being a relatively > young language, is free from these shackles and was built to run on > more modern computers where bits and bytes are not a common > constraint. Lisp is older than both C and Java (by decades), and there's still no explicit typing for variables. In Lisp, the data has a type, and the "variables" are just names for it (just like Python, or rather Python is just like Lisp). > That said, if I were to ever design a software I planned on sharing, I > would write it in one of the more space-friendly languages. Space-friendly? From Marco.Sulla.Python at gmail.com Fri Aug 7 16:42:35 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Fri, 7 Aug 2020 22:42:35 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: On Fri, 7 Aug 2020 at 19:41, Christian Seberino wrote: > I think this is really significant point why more syntax does necessarily mean less readability. I don't think so. Readability of programming languages was measured using an objective method, and Python was one of the most readable. The fact that a grammar is simpler does not mean it's more readable for human beings. It's surely most simple to optimize for compilers. For example, RISC instructions in CPUs were simpler than CISC. Even if Intel tried to defend CISC, modern Intel CPUs have reduced their set of instructions a lot. Furthermore, the majority of smartphone CPUs are ARM, that have RISC instructions. Think also about NAND. You can express the whole boolean logic using only NAND or NOR. In the beginning, only the Military and NASA constructed electrical circuits only with NAND or NOR gates. Now there are electronic circuits made for common people, using only or mainly NAND gates: they are, for example, pen cards and SSD drives. But they are not simpler to understand. For example, in math you *could* think a*b as a+a done b times. But what if a and b are imaginary numbers? There are many programmers that just feel Python much more simple to read and use. Google can tell you a lot about this. Also Rosetta code can show it to you clearly: http://www.rosettacode.org/wiki/Rosetta_Code It seems to me that you want to convince your colleagues that Python is better than Lisp. I think that: 1. there's not a "best". The "best" depends heavily on what you need. 2. the people you have to convince is only yourselves 3. to convince yourselves, you have to try. "Refuse the temptation to guess" :) From Marco.Sulla.Python at gmail.com Fri Aug 7 17:01:43 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Fri, 7 Aug 2020 23:01:43 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: On Fri, 7 Aug 2020 at 22:35, Terry Reedy wrote: > This is a common misconception. Linear iteration and tail recursion are > equivalent. The issue is calculating values once versus multiple times. > Here is the fast recursion equivalent to the fast iteration. > > def fib(n, pair=(1,0)): > previous, current = pair > if n: > return fib(n-1, (current, previous + current)) > else: > return current > > for i in range(10): print(fib(i), end=' ') > # 0 1 1 2 3 5 8 13 21 34 It seems to me a sort of not persistent caching. If you do: fib(very_large_number) without calculating any previous Fibonacci number before, it will be very slow and you could have a stack overflow. A language with tail call optimization will execute it faster and with less memory. Otherwise why asyncio de-facto implemented tail optimization? PS: it seems there's a module that implement tail call: https://github.com/baruchel/tco From rosuav at gmail.com Fri Aug 7 17:02:46 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 8 Aug 2020 07:02:46 +1000 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: On Sat, Aug 8, 2020 at 6:34 AM Terry Reedy wrote: > > On 8/7/2020 11:46 AM, Chris Angelico wrote: > > > My point is that doing Fibonacci recursively is arguably more elegant > > while being materially worse at performance. > > This is a common misconception. Linear iteration and tail recursion are > equivalent. The issue is calculating values once versus multiple times. > Here is the fast recursion equivalent to the fast iteration. > > def fib(n, pair=(1,0)): > previous, current = pair > if n: > return fib(n-1, (current, previous + current)) > else: > return current > > for i in range(10): print(fib(i), end=' ') > # 0 1 1 2 3 5 8 13 21 34 > > One can also do the slow algorithm, with wasteful duplication, > iteratively with one or two stacks of values instead of the hidden stack > of execution frames. I don't remember the details right now without > checking a text. I'm aware you can do recursion iteratively and iteration recursively, but why WOULD you ever do this? The version you've shown here isn't any more elegant than the purely iterative version, and all it's doing is implementing a for loop using recursive calls. (Also, it has one thing that rankles with me, and that's a function signature that is intentionally different for the recursive calls as for the main call. You should *never* pass the 'pair' parameter on the initial call, and it will *always* be passed on the recursive calls.) The idiomatic recursive version is not tail recursive. Same with the idiomatic recursive merge sort, which does forking recursion and then tail-calls the merge operation. (Or you can implement the merge inline, but whenever I'm explaining it, I prefer to write merge() as a separate function.) Knowing how to translate recursion into iteration and vice versa is a useful skill (picture this: you're trying to build some actual coded logic into an alias expansion system, where the only conditional you have is "execute this file" with text substitution in the file name, and the only looping you have is to re-execute the same file), but it's not the way to show off the beauty of recursion. ChrisA From Richard at Damon-Family.org Fri Aug 7 17:12:04 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 7 Aug 2020 17:12:04 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: <25fe43a4-c6ab-fc2a-1790-792d5983af91@Damon-Family.org> On 8/7/20 4:08 PM, Terry Reedy wrote: > On 8/7/2020 11:46 AM, Chris Angelico wrote: > >> My point is that doing Fibonacci recursively is arguably more elegant >> while being materially worse at performance. > > This is a common misconception.? Linear iteration and tail recursion > are equivalent.? The issue is calculating values once versus multiple > times. ?Here is the fast recursion equivalent to the fast iteration. > > def fib(n, pair=(1,0)): > ?? previous, current = pair > ?? if n: > ????? return fib(n-1, (current, previous + current)) > ?? else: > ????? return current > > for i in range(10): print(fib(i), end=' ') > # 0 1 1 2 3 5 8 13 21 34 > > One can also do the slow algorithm, with wasteful duplication, > iteratively with one or two stacks of values instead of the hidden > stack of execution frames.? I don't remember the details right now > without checking a text. > But your example breaks the 'problem' in the recursion that Fibonacci, when expressed 'naturally', the current value is based on two different earlier values. You have morphed the definition, using basically the iterative solution, so that the recursive call to fir(0, ...) doesn't actually calculate the fib(0) value, but fib(n). Yes, this shows that you can convert an iterative solution into a recursive solution with a bit of hand waving, but you still end up with a program based on the iterative algorithm, not the possibly natural recursive one. -- Richard Damon From python at bladeshadow.org Fri Aug 7 17:39:00 2020 From: python at bladeshadow.org (Python) Date: Fri, 7 Aug 2020 16:39:00 -0500 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: <20200807213900.GH8728@bladeshadow.org> On Sat, Aug 08, 2020 at 01:46:28AM +1000, Chris Angelico wrote: > On Sat, Aug 8, 2020 at 1:38 AM Python wrote: > TBH most people won't get the recursive version right the first time > either. So FWIW, I/my team don't find this to be true. I was originally going to mention this in my previous post but decided to leave it out for brevity (and in part because I assumed anyone familiar with the problem already expected it was so). In fact my team frequently uses Fibonacci as an interview question. We've been doing so for at least a decade, so we do have a not-insubstantial sample size. We find that candidates can much more easily implement the recursive version correctly, and do so on the first try roughly 70-80% of the time. Nearly all candidates choose to implement the recursive version for that reason. Those that don't are pretty familiar with the problem, and choose the iterative version so they can "show off" their knowledge of the performance benefits. They typically also implement the recursive version immediately after, because it's pretty trivial to do it in most programming languages, and because they assume the point of the question is to ascertain whether they grok recursion. Which is partly true, but only partly--we use it because it is a short problem that can be quickly implemented, and demonstrates a few different interesting concepts, one of which is recursion. When we do use it, we always follow up with "Can you implement this iteratively?" (assuming they didn't already). A small percentage insist that it is impossible. Most who try (again, roughly 70-80%) fail on the first try. Figuring out how to correctly prime the state is pretty much invariably the sticking point. These are not students, they are experienced programmers. This may explain why they usually can easily implement the recursive version, but it does not really address why most of them have trouble with the iterative version. :) From tjreedy at udel.edu Fri Aug 7 17:51:58 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 7 Aug 2020 17:51:58 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: On 8/7/2020 11:55 AM, Marco Sulla wrote: > @Chris: note that "real" recursion in Python is not possible, This is backwards. Python only does real recursion when one writes recursive calls. > since there's no support for tail recursion. I am pretty sure that what you mean by 'support' is to turn tail recursive syntax into iteration, making it fake recursion. -- Terry Jan Reedy From Marco.Sulla.Python at gmail.com Fri Aug 7 18:25:10 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sat, 8 Aug 2020 00:25:10 +0200 Subject: Any ideas for a new language inspired to Python? Message-ID: Let me first say that I don't know if my post is on topic with the mailing list. If so, please inform me. My idea seems to be very simple (so probably it's not simple at all): a language similar to Python, but statically compiled. (Yes, I know Cython, RPython, Julia, Rust...) Since I've not great skill in low-level programming, I'm trying first to define what I really want. My core ideas are: 1. Statically compiled (of course...). So if you write: var a = 1 the variable `a` is an integer and it's value can't be changed to anything that is not an integer 2. Use of smart pointers. Instead of having a refcount in every object, the language implementation will use a smart pointer as a sort of "proxy" to the "real" pointer. This could allow the language implementation to delete the object only when really necessary (lack of memory) and/or do JIT optimizations (move the object to a slower or a faster memory; compute and cache some object attributes, as hash; remove object duplicates...) 3. functional programming under-the-hood. Users can write also in imperative style, but in the language implementation only the functional style is really used. This way *maybe* it's more simple to write concurrent programs without a GIL. But I have a lot of doubts. The one that bothers me most is: compile to binary or to C? My idea at the beginning was to compile to C code without creating an AST. Virtually any system has its own C compiler. Maybe it *seems* more simple, but it's quite more difficult? From Richard at Damon-Family.org Fri Aug 7 18:26:21 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 7 Aug 2020 18:26:21 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: <2ff9f9c4-4be5-1fb5-fc86-2c408a667874@Damon-Family.org> On 8/7/20 3:54 PM, Marco Sulla wrote: > On Fri, 7 Aug 2020 at 19:48, Richard Damon wrote: >> The difference is that the two languages define 'expression' differently. [...] > I don't know if this is interesting or pertinent to the topic. > > Christian Seberino just expressed a doubt about how a clear separation > between a statement and an expression is quite desiderable in the > "real" programming world. And I tried to explain it with the > assignment operation, since a ton of programmers feel very frustrated > about reading code of other programmers with assignment in an if > statement. I'm quite sure that they thought, as I thought: "What do > this?" > Worse when their program failed and they discovered that they wrote > `if (a=b)` instead of `if (a==b)`. > > I'm just more curious about why Lisp programmers think that it's > better to not make a hard distinction between statements and > expressions. Actually, they might put a fairly hard distinction between statements and expressions, a statement is a list that begins with a programmatic atom, while an expression is a list that begins with an operator atom. The fact that EVERYTHING is a list, makes those not used to the idea see it as all the same (which I suppose in a way it is). One side effect of this is that a program isn't just a bunch of statements in sequence, but is actually a LIST of those statements, so the whole program becomes effectively a single list. The really interesting part is that since Lisp programs manipulate lists as data, and the program is just a list, Lisp programs have the theoretical ability to edit themselves (assuming the implementation give access to the list of the program to the program). Now for the general separation of expression from statement, which isn't really as applicable to Lisp, since (if I remember right) assignment doesn't use the = token, so you are less apt to make the mistake, there are several arguments. The confusion of assignment for equality comparison is likely on of the big issues. Some languages solve the problem by making assignments a special type of statement, so you can't make the mistake, some of these even make = be both, so the have to make the distinction. Some languages (like C) make assignment just a 'normal' operator,? and either just trust the programmer or use conventions to help generate warnings (either at compile time or a separate Lint phase). People using these languages will either like the additional power it give, or curse the language for the additional opportunities to make mistakes (or both). Some langagues make the mistake harder to make by using some symbol other than = for assignment, like Pythons new := symbol. One advantage of blurring the line between statements and expressions is power, putting assignments in the middle of an expression, can allow code to be more compact. Some extensions to C are even trying to take this farther, and letting the programmer embed a { } block into a statement as an expression, which is perhaps taking that idea to an extreme. -- Richard Damon From Marco.Sulla.Python at gmail.com Fri Aug 7 18:55:49 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sat, 8 Aug 2020 00:55:49 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <2ff9f9c4-4be5-1fb5-fc86-2c408a667874@Damon-Family.org> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <2ff9f9c4-4be5-1fb5-fc86-2c408a667874@Damon-Family.org> Message-ID: On Sat, 8 Aug 2020 at 00:28, Richard Damon wrote: > The really interesting part is that since Lisp programs manipulate lists > as data, and the program is just a list, Lisp programs have the > theoretical ability to edit themselves (assuming the implementation give > access to the list of the program to the program). This is a bit hard to understand for me. I know that code can be translated to an AST, that is a tree. It's quite difficult for me to imagine the code organized as a list. Do you have some links about it? On Sat, 8 Aug 2020 at 00:28, Richard Damon wrote: > One advantage of blurring the line between statements and expressions is > power, putting assignments in the middle of an expression, can allow > code to be more compact. I agree with you. I experimented a little with CPython code and I saw assignments inside if statements. The code without them was less readable. I also found this example: https://stackoverflow.com/a/151920/1763602 My only fear is the abuse. How many people really use the walrus operator to render the code more readable? My fear is that the majority of programmer will use it for laziness and because it's "cool" ^^ From Richard at Damon-Family.org Fri Aug 7 19:35:38 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 7 Aug 2020 19:35:38 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <2ff9f9c4-4be5-1fb5-fc86-2c408a667874@Damon-Family.org> Message-ID: <9c9d5325-875f-1ff8-5bc3-1e53ccb9559a@Damon-Family.org> On 8/7/20 6:55 PM, Marco Sulla wrote: > On Sat, 8 Aug 2020 at 00:28, Richard Damon wrote: >> The really interesting part is that since Lisp programs manipulate lists >> as data, and the program is just a list, Lisp programs have the >> theoretical ability to edit themselves (assuming the implementation give >> access to the list of the program to the program). > This is a bit hard to understand for me. > I know that code can be translated to an AST, that is a tree. It's > quite difficult for me to imagine the code organized as a list. Do you > have some links about it? Lisp is built on Nested list, Lists were some (many) of the nodes are other list. (Somewhat like you might build the AST in Python) Generally the first element of the list defines what the list is, type of statement or operation, and the rest are the parameters for it. Many of these will be lists for sub expressions or dependent statements. Perhaps the best option would be to search for the Lisp Language, and see how you write programs. > > On Sat, 8 Aug 2020 at 00:28, Richard Damon wrote: >> One advantage of blurring the line between statements and expressions is >> power, putting assignments in the middle of an expression, can allow >> code to be more compact. > I agree with you. I experimented a little with CPython code and I saw > assignments inside if statements. The code without them was less > readable. I also found this example: > https://stackoverflow.com/a/151920/1763602 > My only fear is the abuse. How many people really use the walrus > operator to render the code more readable? My fear is that the > majority of programmer will use it for laziness and because it's > "cool" ^^ There is always the danger, that as you give the programmer more expressive power, they can use it for 'good', or they can miss-use it to make code harder to read. The question comes how much are you willing to trust the programmer, or are you just going to give them enough rope so that can do themselves in.? -- Richard Damon From waste at is.invalid Fri Aug 7 19:58:13 2020 From: waste at is.invalid (Termoregolato) Date: Sat, 8 Aug 2020 01:58:13 +0200 Subject: Symlinks already present In-Reply-To: References: <5198cab4-4edc-29cc-c135-fb019abb9077@DancesWithMice.info> Message-ID: <9d6d3c59-bc50-311d-f6f6-471dc2403b59@is.invalid> Il 28/07/20 00:19, Grant Edwards ha scritto: > You err. I read it, I had to test. In effects, it was simple to test. me at debsrv:~/tmp/test$ ln -s /home/me/mydir aaa me at debsrv:~/tmp/test$ ln -s /home/me/mydir bbb me at debsrv:~/tmp/test$ ls aaa bbb me at debsrv:~/tmp/test$ stat --format=%i /home/me/mydir 18481153 me at debsrv:~/tmp/test$ stat --format=%i aaa 2364513 me at debsrv:~/tmp/test$ stat --format=%i bbb 2374065 Thanks -- Pastrano con un altro account From waste at is.invalid Fri Aug 7 19:59:41 2020 From: waste at is.invalid (Termoregolato) Date: Sat, 8 Aug 2020 01:59:41 +0200 Subject: Symlinks already present In-Reply-To: References: <5198cab4-4edc-29cc-c135-fb019abb9077@DancesWithMice.info> Message-ID: Il 28/07/20 02:50, Dennis Lee Bieber ha scritto: > inode numbers apply for HARD LINKS Thanks -- Pastrano con un altro account From waste at is.invalid Fri Aug 7 20:05:33 2020 From: waste at is.invalid (Termoregolato) Date: Sat, 8 Aug 2020 02:05:33 +0200 Subject: Symlinks already present In-Reply-To: References: <0oirhftpslnaqgpoaks0lsb4dj7rmugkl7@4ax.com> Message-ID: Il 27/07/20 20:37, Chris Angelico ha scritto: > Unfortunately there's no real way to shortcut this if you just want to > check one target directory. You'd still have to readlink() every > symlink to try to find them. Sorry for 10 days of delay (hardware problems at home). Yes, that is. It's a mode to order directories from their content, but due the first chars are always the same, and then I got a tree like finaldir/f/firstpart/secondpart [changing_values] and the test should be done only on a small list of links, so they're fast. -- Pastrano con un altro account From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Aug 7 21:37:16 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 7 Aug 2020 20:37:16 -0500 Subject: Symlinks already present In-Reply-To: <9d6d3c59-bc50-311d-f6f6-471dc2403b59@is.invalid> References: <5198cab4-4edc-29cc-c135-fb019abb9077@DancesWithMice.info> <9d6d3c59-bc50-311d-f6f6-471dc2403b59@is.invalid> Message-ID: <20200808013716.GJ42295@scrozzle> On 2020-08-08 at 01:58:13 +0200, Termoregolato wrote: > me at debsrv:~/tmp/test$ stat --format=%i /home/me/mydir > 18481153 Try ls -i. :-) From cseberino at gmail.com Fri Aug 7 21:44:57 2020 From: cseberino at gmail.com (Christian Seberino) Date: Fri, 7 Aug 2020 18:44:57 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: <6ed1456e-672f-4c8e-852b-cf50912abb60o@googlegroups.com> >> Readability of programming languages was measured >> using an objective method, and Python was one of >> the most readable. Do you have a source for this? From Marco.Sulla.Python at gmail.com Fri Aug 7 23:13:59 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sat, 8 Aug 2020 05:13:59 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <6ed1456e-672f-4c8e-852b-cf50912abb60o@googlegroups.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> <6ed1456e-672f-4c8e-852b-cf50912abb60o@googlegroups.com> Message-ID: On Sat, 8 Aug 2020 at 03:46, Christian Seberino wrote: > >> Readability of programming languages was measured > >> using an objective method, and Python was one of > >> the most readable. > > Do you have a source for this? This question means you have not read at all my suggestions :-D Anyway, this is one: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3933420/ I do not agree with the entire work, but generally speaking it seems to me they used a good approach. What really surprises me is the absence of languages like JS and PHP. From barry at barrys-emacs.org Sat Aug 8 08:10:50 2020 From: barry at barrys-emacs.org (Barry) Date: Sat, 8 Aug 2020 13:10:50 +0100 Subject: Any ideas for a new language inspired to Python? In-Reply-To: References: Message-ID: <919216B4-BB7C-407A-B61A-616F55A4DE56@barrys-emacs.org> >> On 7 Aug 2020, at 23:28, Marco Sulla wrote: > ?Let me first say that I don't know if my post is on topic with the > mailing list. If so, please inform me. > > My idea seems to be very simple (so probably it's not simple at all): > a language similar to Python, but statically compiled. > > (Yes, I know Cython, RPython, Julia, Rust...) Have a look at Apple?s Swift. It reminds me of python as I read it. I have not done more the read the language reference docs. Sadly it seems that it has not been ported to none Apple platforms. Barry > > Since I've not great skill in low-level programming, I'm trying first > to define what I really want. > > My core ideas are: > > 1. Statically compiled (of course...). So if you write: > > var a = 1 > > the variable `a` is an integer and it's value can't be changed to > anything that is not an integer > > 2. Use of smart pointers. Instead of having a refcount in every > object, the language implementation will use a smart pointer as a sort > of "proxy" to the "real" pointer. This could allow the language > implementation to delete the object only when really necessary (lack > of memory) and/or do JIT optimizations (move the object to a slower or > a faster memory; compute and cache some object attributes, as hash; > remove object duplicates...) > > 3. functional programming under-the-hood. Users can write also in > imperative style, but in the language implementation only the > functional style is really used. This way *maybe* it's more simple to > write concurrent programs without a GIL. > > But I have a lot of doubts. The one that bothers me most is: compile > to binary or to C? > > My idea at the beginning was to compile to C code without creating an > AST. Virtually any system has its own C compiler. Maybe it *seems* > more simple, but it's quite more difficult? > -- > https://mail.python.org/mailman/listinfo/python-list From mananaggarwal457 at gmail.com Sat Aug 8 08:55:14 2020 From: mananaggarwal457 at gmail.com (MANAN AGGARWAL) Date: Sat, 8 Aug 2020 05:55:14 -0700 (PDT) Subject: Encountering fatal error x80070643 while installing Python In-Reply-To: References: <000001d24190$8c3252d0$a496f870$@i-write.biz> Message-ID: <071da6c7-f7e2-4192-9906-218c3f76d013n@googlegroups.com> On Friday, November 18, 2016 at 6:58:23 PM UTC+5:30, Irene Venditti wrote: > Hi everybody, > > > > I've got a problem with the installation of Python. I am a translator and > currently I'm translating a book on programming Minecraft with Python, from > English to Dutch. > > > > My computer is a Windows 10 computer, 64-bits (Toshiba Qosmio all in one). > > I already had a 2.7 version of Python installed to C:\Program Files > (x86)\Python and stupidly forgot to uninstall this version when I downloaded > and installed version 3.5.1 (required for the book translation). > > This didn't seem to be a problem, since version 3.5.1 installed to my > C:\Users\username\appdata\local\... directory. But when I tried to install > Python 3.5.2 and uninstalled both previous versions, the problems began. > > Now I cannot install any version of Python anymore, not 3.5.0 or any later > versions. At the end of the procedure I get a fatal error message, with code > 0x80070643, saying an error was encountered and the installation couldn't be > completed. > > > > What do I do now? I desperately need my Python program for my book > translation. > > > > Thanks, Irene > > > > Kind regards, > > Irene Venditti > > i-write translations and texts > > > > in... at i-write.biz > > www.i-write.biz > > 0031 (0)6 220 760 73 I downloaded the python from microsoft store and it magically got installed without any error as it directly installed it I guess. So try this out and tell me it works. From sammy.jackson987 at gmail.com Sat Aug 8 10:29:18 2020 From: sammy.jackson987 at gmail.com (sammy.jackson987 at gmail.com) Date: Sat, 8 Aug 2020 07:29:18 -0700 (PDT) Subject: Including a Variable In the HTML Tags When Sending An Email Message-ID: Hello all I was hoping someone could help me with the following coding problem. I am trying to send an email where the body of the email is taken from a data frame, which i have managed to do. However i want to start the email by saying Hi Name, where Name is a variable that contains the person's name to whom i am sending the email to - This is the bit i cannot get working. The code i have so far is as follows:- [python] import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText mail=smtplib.SMTP('smtp.gmail.com', 123) mail.ehlo() mail.starttls() mail.login("Email","Pwd") From_Address = ["From_Email"] To_Address = [Report_Data_Frame.iloc[0,10]] CC_Address = ["CC_Email", "CC_Email", "CC_Email"] Subject_Email = "Email_Subject" Body = Email_Body_Data_Frame Name = "Tom" html = """\ Hi Name Goes HERE!!!

TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT

{0}
TEXT TEXT

TEXT TEXT

TEXT TEXT

TEXT TEXT
""".format(Body.to_html()) msg = MIMEMultipart() msg['From'] = ', '.join(From_Address) msg['To'] = ', '.join(To_Address) msg['Cc'] = ', '.join(CC_Address) msg['Subject'] = Subject_Email message = MIMEText(html,'html') msg.attach(message) mail.sendmail(From_Address, (To_Address + CC_Address), msg.as_string()) [/python] In this case the variable Name is Tom and i want to include Tom in the email. Can anyone help? Still a newbie; approx 3 weeks playing with Python (cut and past most of this code) Any help will be greatly appericated. Thank you. From Richard at Damon-Family.org Sat Aug 8 10:45:44 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 8 Aug 2020 10:45:44 -0400 Subject: Including a Variable In the HTML Tags When Sending An Email In-Reply-To: References: Message-ID: All the text that you want the user to see needs to be in the of the message. is for metadata and stuff to setup some formatting. You might want to study up a bit on HTML formatting too. Depending on what the data frame is like, you may need to enclose it in some sort of container, like a
On 8/8/20 10:29 AM, sammy.jackson987 at gmail.com wrote: > Hello all > > I was hoping someone could help me with the following coding problem. > > I am trying to send an email where the body of the email is taken from a data frame, which i have managed to do. > > However i want to start the email by saying Hi Name, where Name is a variable that contains the person's name to whom i am sending the email to - This is the bit i cannot get working. > > The code i have so far is as follows:- > > [python] > import smtplib > from email.mime.multipart import MIMEMultipart > from email.mime.text import MIMEText > > mail=smtplib.SMTP('smtp.gmail.com', 123) > mail.ehlo() > mail.starttls() > mail.login("Email","Pwd") > > From_Address = ["From_Email"] > To_Address = [Report_Data_Frame.iloc[0,10]] > CC_Address = ["CC_Email", "CC_Email", "CC_Email"] > Subject_Email = "Email_Subject" > Body = Email_Body_Data_Frame > Name = "Tom" > > > html = """\ > > > > Hi Name Goes HERE!!! >
>
> TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT

> > > > > {0} > > > >
> > TEXT TEXT

> TEXT TEXT

> TEXT TEXT

> TEXT TEXT
> > > > """.format(Body.to_html()) > > msg = MIMEMultipart() > msg['From'] = ', '.join(From_Address) > msg['To'] = ', '.join(To_Address) > msg['Cc'] = ', '.join(CC_Address) > msg['Subject'] = Subject_Email > > message = MIMEText(html,'html') > msg.attach(message) > mail.sendmail(From_Address, (To_Address + CC_Address), msg.as_string()) > [/python] > > In this case the variable Name is Tom and i want to include Tom in the email. > > Can anyone help? > > Still a newbie; approx 3 weeks playing with Python (cut and past most of this code) > > Any help will be greatly appericated. > > Thank you. -- Richard Damon From sammy.jackson987 at gmail.com Sat Aug 8 10:58:50 2020 From: sammy.jackson987 at gmail.com (sammy.jackson987 at gmail.com) Date: Sat, 8 Aug 2020 07:58:50 -0700 (PDT) Subject: Including a Variable In the HTML Tags When Sending An Email In-Reply-To: References: Message-ID: <61651de2-e6ab-4e80-b5ab-b678ee3ea36do@googlegroups.com> On Saturday, August 8, 2020 at 3:46:04 PM UTC+1, Richard Damon wrote: > All the text that you want the user to see needs to be in the of > the message. is for metadata and stuff to setup some formatting. > > You might want to study up a bit on HTML formatting too. Depending on > what the data frame is like, you may need to enclose it in some sort of > container, like a
> > On 8/8/20 10:29 AM, sammy.jackson987 at gmail.com wrote: > > Hello all > > > > I was hoping someone could help me with the following coding problem. > > > > I am trying to send an email where the body of the email is taken from a data frame, which i have managed to do. > > > > However i want to start the email by saying Hi Name, where Name is a variable that contains the person's name to whom i am sending the email to - This is the bit i cannot get working. > > > > The code i have so far is as follows:- > > > > [python] > > import smtplib > > from email.mime.multipart import MIMEMultipart > > from email.mime.text import MIMEText > > > > mail=smtplib.SMTP('smtp.gmail.com', 123) > > mail.ehlo() > > mail.starttls() > > mail.login("Email","Pwd") > > > > From_Address = ["From_Email"] > > To_Address = [Report_Data_Frame.iloc[0,10]] > > CC_Address = ["CC_Email", "CC_Email", "CC_Email"] > > Subject_Email = "Email_Subject" > > Body = Email_Body_Data_Frame > > Name = "Tom" > > > > > > html = """\ > > > > > > > > Hi Name Goes HERE!!! > >
> >
> > TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT

> > > > > > > > > > {0} > > > > > > > >
> > > > TEXT TEXT

> > TEXT TEXT

> > TEXT TEXT

> > TEXT TEXT
> > > > > > > > """.format(Body.to_html()) > > > > msg = MIMEMultipart() > > msg['From'] = ', '.join(From_Address) > > msg['To'] = ', '.join(To_Address) > > msg['Cc'] = ', '.join(CC_Address) > > msg['Subject'] = Subject_Email > > > > message = MIMEText(html,'html') > > msg.attach(message) > > mail.sendmail(From_Address, (To_Address + CC_Address), msg.as_string()) > > [/python] > > > > In this case the variable Name is Tom and i want to include Tom in the email. > > > > Can anyone help? > > > > Still a newbie; approx 3 weeks playing with Python (cut and past most of this code) > > > > Any help will be greatly appericated. > > > > Thank you. > > > -- > Richard Damon Thank you Richard for your response. I have moved all the text i want the user to see into the body of the email. I still cannot get my email to display the name. Name = "Tim" How would i include this variable in my HTML/Python code? Any ideas? Thank you. From Richard at Damon-Family.org Sat Aug 8 11:45:45 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 8 Aug 2020 11:45:45 -0400 Subject: Including a Variable In the HTML Tags When Sending An Email In-Reply-To: <61651de2-e6ab-4e80-b5ab-b678ee3ea36do@googlegroups.com> References: <61651de2-e6ab-4e80-b5ab-b678ee3ea36do@googlegroups.com> Message-ID: <00f8cd39-904a-9a12-d330-a886f5e8db06@Damon-Family.org> On 8/8/20 10:58 AM, sammy.jackson987 at gmail.com wrote: > Thank you Richard for your response. > > I have moved all the text i want the user to see into the body of the email. > > I still cannot get my email to display the name. > > Name = "Tim" > > How would i include this variable in my HTML/Python code? > > Any ideas? > > Thank you. Since you are already using .format to insert the message body, you might as well do something similar to insert the name, adding more placeholders for the format to insert into. -- Richard Damon From python at mrabarnett.plus.com Sat Aug 8 12:02:43 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 8 Aug 2020 17:02:43 +0100 Subject: Including a Variable In the HTML Tags When Sending An Email In-Reply-To: <61651de2-e6ab-4e80-b5ab-b678ee3ea36do@googlegroups.com> References: <61651de2-e6ab-4e80-b5ab-b678ee3ea36do@googlegroups.com> Message-ID: On 2020-08-08 15:58, sammy.jackson987 at gmail.com wrote: > On Saturday, August 8, 2020 at 3:46:04 PM UTC+1, Richard Damon wrote: >> All the text that you want the user to see needs to be in the of >> the message. is for metadata and stuff to setup some formatting. >> >> You might want to study up a bit on HTML formatting too. Depending on >> what the data frame is like, you may need to enclose it in some sort of >> container, like a
>> >> On 8/8/20 10:29 AM, sammy.jackson987 at gmail.com wrote: >> > Hello all >> > >> > I was hoping someone could help me with the following coding problem. >> > >> > I am trying to send an email where the body of the email is taken from a data frame, which i have managed to do. >> > >> > However i want to start the email by saying Hi Name, where Name is a variable that contains the person's name to whom i am sending the email to - This is the bit i cannot get working. >> > >> > The code i have so far is as follows:- >> > >> > [python] >> > import smtplib >> > from email.mime.multipart import MIMEMultipart >> > from email.mime.text import MIMEText >> > >> > mail=smtplib.SMTP('smtp.gmail.com', 123) >> > mail.ehlo() >> > mail.starttls() >> > mail.login("Email","Pwd") >> > >> > From_Address = ["From_Email"] >> > To_Address = [Report_Data_Frame.iloc[0,10]] >> > CC_Address = ["CC_Email", "CC_Email", "CC_Email"] >> > Subject_Email = "Email_Subject" >> > Body = Email_Body_Data_Frame >> > Name = "Tom" >> > >> > >> > html = """\ >> > >> > >> > >> > Hi Name Goes HERE!!! >> >
>> >
>> > TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT

>> > >> > >> > >> > >> > {0} >> > >> > >> > >> >
>> > >> > TEXT TEXT

>> > TEXT TEXT

>> > TEXT TEXT

>> > TEXT TEXT
>> > >> > >> > >> > """.format(Body.to_html()) >> > >> > msg = MIMEMultipart() >> > msg['From'] = ', '.join(From_Address) >> > msg['To'] = ', '.join(To_Address) >> > msg['Cc'] = ', '.join(CC_Address) >> > msg['Subject'] = Subject_Email >> > >> > message = MIMEText(html,'html') >> > msg.attach(message) >> > mail.sendmail(From_Address, (To_Address + CC_Address), msg.as_string()) >> > [/python] >> > >> > In this case the variable Name is Tom and i want to include Tom in the email. >> > >> > Can anyone help? >> > >> > Still a newbie; approx 3 weeks playing with Python (cut and past most of this code) >> > >> > Any help will be greatly appericated. >> > >> > Thank you. >> >> >> -- >> Richard Damon > > Thank you Richard for your response. > > I have moved all the text i want the user to see into the body of the email. > > I still cannot get my email to display the name. > > Name = "Tim" > > How would i include this variable in my HTML/Python code? > > Any ideas? > > Thank you. > I can't see why you're having a problem putting the name into the HTML when you're already managing to put the text of the dataframe into it... From Marco.Sulla.Python at gmail.com Sat Aug 8 13:18:13 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sat, 8 Aug 2020 19:18:13 +0200 Subject: Any ideas for a new language inspired to Python? In-Reply-To: <919216B4-BB7C-407A-B61A-616F55A4DE56@barrys-emacs.org> References: <919216B4-BB7C-407A-B61A-616F55A4DE56@barrys-emacs.org> Message-ID: On Sat, 8 Aug 2020 at 14:10, Barry wrote: > >> On 7 Aug 2020, at 23:28, Marco Sulla wrote: > > My idea seems to be very simple (so probably it's not simple at all): > > a language similar to Python, but statically compiled. > > Have a look at Apple?s Swift. It reminds me of python as I read it. Thank you, some features are interesting, even if I prefer the Python syntax. What about the compiler? Is it better to "compile" to C or to bytecode? How can I generate a bytecode that can be compiled by gcc? Can I skip the AST generation for now, or it will be a great problem later? From grant.b.edwards at gmail.com Sat Aug 8 14:26:11 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 8 Aug 2020 18:26:11 -0000 (UTC) Subject: Any ideas for a new language inspired to Python? References: Message-ID: On 2020-08-07, Marco Sulla wrote: > My core ideas are: > > 1. Statically compiled (of course...). So if you write: > > var a = 1 > > the variable `a` is an integer and it's value can't be changed to > anything that is not an integer That's "statically typed". It has nothing to do with whether it's statically compiled or not. -- Grant From Gronicus at SGA.Ninja Sat Aug 8 16:51:20 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sat, 8 Aug 2020 16:51:20 -0400 Subject: Save-to-file code not quite working completely Message-ID: <000701d66dc5$abe33f30$03a9bd90$@SGA.Ninja> I have a file containing specifications. My .py program can read and manipulate the data but I cannot seem to get it to update the original file properly. The code is simple and works except that the original line remains in the file after the new updated one has been added. My code: ======================================================= import fileinput import sys def ReplaceLine(file,searchExp,replaceExp): for line in fileinput.input(file, inplace=1): # if searchExp in line: line = line.replace(searchExp,replaceExp) #.rstrip() sys.stdout.write(line) NewLine = "MSN Monitor Serial Number: 111111111-T4464 ## \n " ReplaceLine("Specifications.txt","MSN", NewLine) print() PauseHere = input("Paused") ===================================== The text file: 1 MSN Monitor Serial Number: 111111111-T4464 ## Monitor Serial Number: 88888888-T4464 ## 2 TLN TestStrip Lot Number: 45001 82624 ## 3 SED Strip Expire Date: 2021-02-28 ## 4 SEC Sensor Sequence Code: 68 ## 5 SCN Sensor Code Number: F95 ## 6 SEN Sensor Serial Number: 0M000APJYWM ## 7 SDE Sensor Date to Expire: 2020-12-31 ## 8 SDN Sensor Day Number: 1 ## 9 DTD Data Time Date Fri Aug 07, 2020 21:30 ## ===================================== That second line shown was the original line for MSN. The replacement line should have replaced the original line not just get added to the file. It should have been replaced. What is in line 2, should have "1 MSN" at the beginning but that somehow disappeared. So close, so simple... How do I fix this? Steve P.S. I read to add ".rstrip()" but that messed things even more... (-: ======================================================= Footnote: ?logomachist?- someone given to disputes over words. logomach. controversialist, disputant, eristic - a person who disputes; who is good at or enjoys controversy. From python at mrabarnett.plus.com Sat Aug 8 18:02:26 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 8 Aug 2020 23:02:26 +0100 Subject: Save-to-file code not quite working completely In-Reply-To: <000701d66dc5$abe33f30$03a9bd90$@SGA.Ninja> References: <000701d66dc5$abe33f30$03a9bd90$@SGA.Ninja> Message-ID: <337a3217-2b98-a4a0-6b65-89600fa57570@mrabarnett.plus.com> On 2020-08-08 21:51, Steve wrote: > > I have a file containing specifications. My .py program can read and > manipulate the data but I cannot seem to get it to update the original file > properly. > > The code is simple and works except that the original line remains in the > file after the new updated one has been added. > > My code: > ======================================================= > > import fileinput > import sys > > def ReplaceLine(file,searchExp,replaceExp): > for line in fileinput.input(file, inplace=1): > # if searchExp in line: > line = line.replace(searchExp,replaceExp) #.rstrip() > sys.stdout.write(line) > > NewLine = "MSN Monitor Serial Number: 111111111-T4464 ## > \n " > ReplaceLine("Specifications.txt","MSN", NewLine) > print() > PauseHere = input("Paused") > ===================================== > The text file: > 1 MSN Monitor Serial Number: 111111111-T4464 ## > Monitor Serial Number: 88888888-T4464 ## > 2 TLN TestStrip Lot Number: 45001 82624 ## > 3 SED Strip Expire Date: 2021-02-28 ## > 4 SEC Sensor Sequence Code: 68 ## > 5 SCN Sensor Code Number: F95 ## > 6 SEN Sensor Serial Number: 0M000APJYWM ## > 7 SDE Sensor Date to Expire: 2020-12-31 ## > 8 SDN Sensor Day Number: 1 ## > 9 DTD Data Time Date Fri Aug 07, 2020 21:30 ## > ===================================== > That second line shown was the original line for MSN. The replacement line > should have replaced the original line not just get added to the file. It > should have been replaced. What is in line 2, should have "1 MSN" at the > beginning but that somehow disappeared. > > So close, so simple... > How do I fix this? > Steve > > P.S. I read to add ".rstrip()" but that messed things even more... (-: > In the .replace line you're asking it to replace any occurrence of "MSN" in the line with a new string. It's doing that. I'll add <<...>> around the replacement to make its position clearer: >>> line = " 1 MSN Monitor Serial Number: 111111111-T4464 ##\n" >>> line.replace("MSN", "<>") ' 1 <> Monitor Serial Number: 111111111-T4464 ##' From PythonList at DancesWithMice.info Sat Aug 8 19:50:51 2020 From: PythonList at DancesWithMice.info (dn) Date: Sun, 9 Aug 2020 11:50:51 +1200 Subject: Save-to-file code not quite working completely In-Reply-To: <000701d66dc5$abe33f30$03a9bd90$@SGA.Ninja> References: <000701d66dc5$abe33f30$03a9bd90$@SGA.Ninja> Message-ID: <1fb2f4ee-6c7e-8963-5b48-84f3c5cd14d2@DancesWithMice.info> On 09/08/2020 08:51, Steve wrote: > > I have a file containing specifications. My .py program can read and > manipulate the data but I cannot seem to get it to update the original file > properly. > > The code is simple and works except that the original line remains in the > file after the new updated one has been added. ... > That second line shown was the original line for MSN. The replacement line > should have replaced the original line not just get added to the file. It > should have been replaced. What is in line 2, should have "1 MSN" at the > beginning but that somehow disappeared. > > So close, so simple... > How do I fix this? To be a logomach, let's talk about "update":- May I advise that a 'good practice' would be to create a new file, and thus be able to (also) maintain the old version as a 'backup'. (also: advantage when debugging/testing logic!) The pattern is to read the 'old' file, line-by-line. If there is a key-match, ignore the read record, writing the new data in its stead. If there is not a match, copy the input-data into an output record. The major addition will be the need to rename the 'old file', ensuring logic to handle any "clash" (based upon whatever security requirements/numbers of generations - which it would appear don't currently exist). The above assumes that the program will either only ever update a single record per execution-run; or that the logic collects a list of changes to the file which will be saved to the file, as above. Further, databases have been designed for this sort of partial update scenario. If/when updates become too frequent, or the file becomes extensive, recommend you look at using an RDBMS instead of using this 'flat-file' approach... -- Regards =dn From sammy.jackson987 at gmail.com Sat Aug 8 20:03:33 2020 From: sammy.jackson987 at gmail.com (sammy.jackson987 at gmail.com) Date: Sat, 8 Aug 2020 17:03:33 -0700 (PDT) Subject: Including a Variable In the HTML Tags When Sending An Email In-Reply-To: References: <61651de2-e6ab-4e80-b5ab-b678ee3ea36do@googlegroups.com> Message-ID: <514f6299-5da6-4801-83b2-6b850ec21b77o@googlegroups.com> On Saturday, August 8, 2020 at 5:03:07 PM UTC+1, MRAB wrote: > On 2020-08-08 15:58, sammy.jackson987 at gmail.com wrote: > > On Saturday, August 8, 2020 at 3:46:04 PM UTC+1, Richard Damon wrote: > >> All the text that you want the user to see needs to be in the of > >> the message. is for metadata and stuff to setup some formatting. > >> > >> You might want to study up a bit on HTML formatting too. Depending on > >> what the data frame is like, you may need to enclose it in some sort of > >> container, like a
> >> > >> On 8/8/20 10:29 AM, sammy.jackson987 at gmail.com wrote: > >> > Hello all > >> > > >> > I was hoping someone could help me with the following coding problem. > >> > > >> > I am trying to send an email where the body of the email is taken from a data frame, which i have managed to do. > >> > > >> > However i want to start the email by saying Hi Name, where Name is a variable that contains the person's name to whom i am sending the email to - This is the bit i cannot get working. > >> > > >> > The code i have so far is as follows:- > >> > > >> > [python] > >> > import smtplib > >> > from email.mime.multipart import MIMEMultipart > >> > from email.mime.text import MIMEText > >> > > >> > mail=smtplib.SMTP('smtp.gmail.com', 123) > >> > mail.ehlo() > >> > mail.starttls() > >> > mail.login("Email","Pwd") > >> > > >> > From_Address = ["From_Email"] > >> > To_Address = [Report_Data_Frame.iloc[0,10]] > >> > CC_Address = ["CC_Email", "CC_Email", "CC_Email"] > >> > Subject_Email = "Email_Subject" > >> > Body = Email_Body_Data_Frame > >> > Name = "Tom" > >> > > >> > > >> > html = """\ > >> > > >> > > >> > > >> > Hi Name Goes HERE!!! > >> >
> >> >
> >> > TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT

> >> > > >> > > >> > > >> > > >> > {0} > >> > > >> > > >> > > >> >
> >> > > >> > TEXT TEXT

> >> > TEXT TEXT

> >> > TEXT TEXT

> >> > TEXT TEXT
> >> > > >> > > >> > > >> > """.format(Body.to_html()) > >> > > >> > msg = MIMEMultipart() > >> > msg['From'] = ', '.join(From_Address) > >> > msg['To'] = ', '.join(To_Address) > >> > msg['Cc'] = ', '.join(CC_Address) > >> > msg['Subject'] = Subject_Email > >> > > >> > message = MIMEText(html,'html') > >> > msg.attach(message) > >> > mail.sendmail(From_Address, (To_Address + CC_Address), msg.as_string()) > >> > [/python] > >> > > >> > In this case the variable Name is Tom and i want to include Tom in the email. > >> > > >> > Can anyone help? > >> > > >> > Still a newbie; approx 3 weeks playing with Python (cut and past most of this code) > >> > > >> > Any help will be greatly appericated. > >> > > >> > Thank you. > >> > >> > >> -- > >> Richard Damon > > > > Thank you Richard for your response. > > > > I have moved all the text i want the user to see into the body of the email. > > > > I still cannot get my email to display the name. > > > > Name = "Tim" > > > > How would i include this variable in my HTML/Python code? > > > > Any ideas? > > > > Thank you. > > > I can't see why you're having a problem putting the name into the HTML > when you're already managing to put the text of the dataframe into it... Hi Richard The issue i am am having is that the Name is a variable stored as a str and my data in my dataframe is stored as a variable of type dataframe. If i use place holders i.e. {0} and {1} where {0} is the name and {1} is the dataframe i get an error for the following line of code:- .format((Name,Body).to_html()) which states 'tuple' object has no attribute 'to_html'. My amended code look like:- import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText mail=smtplib.SMTP('smtp.gmail.com', 123) mail.ehlo() mail.starttls() mail.login("Email","Pwd") From_Address = ["From_Email"] To_Address = [Report_Data_Frame.iloc[0,10]] CC_Address = ["CC_Email", "CC_Email", "CC_Email"] Subject_Email = "Email_Subject" Name = "Tom" Body = Email_Body_Data_Frame html = """\ Hi {0}

TEXT TEXT TEXT TEXT TEXT

{1}
TEXT TEXT TEXT TEXT TEXT


""".format((Name,Body).to_html()) If i convert the dataframe to a string then it messes up all the columns. Any ideas? Thanks From Richard at Damon-Family.org Sat Aug 8 20:32:06 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 8 Aug 2020 20:32:06 -0400 Subject: Including a Variable In the HTML Tags When Sending An Email In-Reply-To: <514f6299-5da6-4801-83b2-6b850ec21b77o@googlegroups.com> References: <61651de2-e6ab-4e80-b5ab-b678ee3ea36do@googlegroups.com> <514f6299-5da6-4801-83b2-6b850ec21b77o@googlegroups.com> Message-ID: <39f80119-14b9-3dcd-825a-aa4031ffeb0c@Damon-Family.org> On 8/8/20 8:03 PM, sammy.jackson987 at gmail.com wrote: > If i use place holders i.e. {0} and {1} where {0} is the name and {1} is the dataframe i get an error for the following line of code:- > .format((Name,Body).to_html()) which states 'tuple' object has no attribute 'to_html'. I would do it as .format(Name, Body.to_html()) if your names really are just straight letters. If they might have some funny characters that need html handling, you could do: import html .format(html.escape(Name), Body.to_html()) Note that different types need to be treated differently to get them into clean html. -- Richard Damon From jsf80238 at gmail.com Sat Aug 8 23:23:28 2020 From: jsf80238 at gmail.com (Jason Friedman) Date: Sat, 8 Aug 2020 21:23:28 -0600 Subject: importlib: import X as Y; from A import B Message-ID: I have some code I'm going to share with my team, many of whom are not yet familiar with Python. They may not have 3rd-party libraries such as pandas or selenium installed. Yes I can instruct them how to install, but the path of least resistance is to have my code to check for missing dependencies and attempt to install for them. This code works as desired: import importlib import subprocess PIP_EXE = "/opt/python/bin/pip3" for module_name in ("module1", "module2", "module3"): try: importlib.import_module(module_name) except ModuleNotFoundError: install_command = f"{PIP_EXE} install {module_name}" status, output = subprocess.getstatusoutput(install_command) if not status: importlib.import_module(module_name) print(f"Successfully installed {module_name}.") else: print(f"Error when attempting to install {module_name}: {output}") The cherry-on-top would be to import with the "aliasing" and "from" they will most likely see on the web, so that my code matches what they see there. In other words, instead of: import pandas df = pandas.from_csv (...) import selenium browser = selenium.webdriver.Firefox() on the web they will typically see: import pandas as pd df = pd.from_csv (...) from selenium import webdriver browser = webdriver.Firefox() I don't see anything in the importlib module documentation that supports this. From Gronicus at SGA.Ninja Sat Aug 8 23:55:21 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sat, 8 Aug 2020 23:55:21 -0400 Subject: Mischief Managed: Save-to-file code not quite working completely Message-ID: <001c01d66e00$e80e8790$b82b96b0$@SGA.Ninja> A simple solution is to know better how the operation works. (-: I was thinking that the operation would search for the keyword (MSN) and replace the line. Instead of passing the key word, I passed the entire line to be replaced and it's correction.. def ReplaceLine(file,searchExp,replaceExp): for line in fileinput.input(file, inplace=1): #if searchExp in line: line = line.replace(searchExp,replaceExp) sys.stdout.write(line) ReplaceLine("Specifications.txt",OldLine, NewLine) Footnote: If 666 is evil then 25.8 is the root of all evil. -----Original Message----- From: MRAB Sent: Saturday, August 8, 2020 9:08 PM To: Steve Subject: Re: Save-to-file code not quite working completely On 2020-08-09 00:51, Steve wrote: > I don't see that. What I do see is that it placing the new string but > leaving most of the old one. That's how the .replace method works. It searches for matches and replaces any matched portion(s) with the replacement string. It leaves the rest of the string alone. You told it to replace all occurrences of "MSN" with something else. It did that. It didn't make any other changes. What do you want it to do? If you want it to replace the line that contains "MSN" with the new line, but retain the number, then you need to write code to do that. Something like this: if searchExp in line: # Retain the number from the line. line = line.split()[0] + ' ' + replaceExp > -----Original Message----- > From: Python-list > On Behalf Of MRAB > Sent: Saturday, August 8, 2020 6:02 PM > To: python-list at python.org > Subject: Re: Save-to-file code not quite working completely > > On 2020-08-08 21:51, Steve wrote: > > > > I have a file containing specifications. My .py program can read and > > manipulate the data but I cannot seem to get it to update the > > original file properly. > > > > The code is simple and works except that the original line remains > > in the file after the new updated one has been added. > > > > My code: > > ======================================================= > > > > import fileinput > > import sys > > > > def ReplaceLine(file,searchExp,replaceExp): > > for line in fileinput.input(file, inplace=1): > > # if searchExp in line: > > line = line.replace(searchExp,replaceExp) #.rstrip() > > sys.stdout.write(line) > > > > NewLine = "MSN Monitor Serial Number: 111111111-T4464 > ## > > \n " > > ReplaceLine("Specifications.txt","MSN", NewLine) > > print() > > PauseHere = input("Paused") > > ===================================== > > The text file: > > 1 MSN Monitor Serial Number: 111111111-T4464 ## > > Monitor Serial Number: 88888888-T4464 ## > > 2 TLN TestStrip Lot Number: 45001 82624 ## > > 3 SED Strip Expire Date: 2021-02-28 ## > > 4 SEC Sensor Sequence Code: 68 ## > > 5 SCN Sensor Code Number: F95 ## > > 6 SEN Sensor Serial Number: 0M000APJYWM ## > > 7 SDE Sensor Date to Expire: 2020-12-31 ## > > 8 SDN Sensor Day Number: 1 ## > > 9 DTD Data Time Date Fri Aug 07, 2020 21:30 ## > > ===================================== > > That second line shown was the original line for MSN. The > > replacement line should have replaced the original line not just get > > added to the file. It should have been replaced. What is in line 2, > > should have "1 MSN" at the beginning but that somehow disappeared. > > > > So close, so simple... > > How do I fix this? > > Steve > > > > P.S. I read to add ".rstrip()" but that messed things even more... (-: > > > In the .replace line you're asking it to replace any occurrence of "MSN" > in the line with a new string. > > It's doing that. > > I'll add <<...>> around the replacement to make its position clearer: > > >>> line = " 1 MSN Monitor Serial Number: 111111111-T4464 ##\n" > >>> line.replace("MSN", "< ##\n >>") > ' 1 < >> Monitor Serial Number: 111111111-T4464 ##' From PythonList at DancesWithMice.info Sun Aug 9 00:10:37 2020 From: PythonList at DancesWithMice.info (dn) Date: Sun, 9 Aug 2020 16:10:37 +1200 Subject: importlib: import X as Y; from A import B In-Reply-To: References: Message-ID: <1e05d414-672c-a3d7-4e80-2336af527e33@DancesWithMice.info> On 09/08/2020 15:23, Jason Friedman wrote: > I have some code I'm going to share with my team, many of whom are not yet > familiar with Python. They may not have 3rd-party libraries such as pandas > or selenium installed. Yes I can instruct them how to install, but the path > of least resistance is to have my code to check for missing dependencies > and attempt to install for them. This code works as desired: > > import importlib > import subprocess > > PIP_EXE = "/opt/python/bin/pip3" > > for module_name in ("module1", "module2", "module3"): > try: > importlib.import_module(module_name) > except ModuleNotFoundError: > install_command = f"{PIP_EXE} install {module_name}" > status, output = subprocess.getstatusoutput(install_command) > if not status: > importlib.import_module(module_name) > print(f"Successfully installed {module_name}.") > else: > print(f"Error when attempting to install {module_name}: > {output}") > > The cherry-on-top would be to import with the "aliasing" and "from" they > will most likely see on the web, so that my code matches what they see > there. In other words, instead of: > > import pandas > df = pandas.from_csv (...) > import selenium > browser = selenium.webdriver.Firefox() > > on the web they will typically see: > > import pandas as pd > df = pd.from_csv (...) > from selenium import webdriver > browser = webdriver.Firefox() > > I don't see anything in the importlib module documentation that supports > this. Try: The import system (https://docs.python.org/3/reference/import.html) and Simple Statements (https://docs.python.org/3/reference/simple_stmts.html?highlight=import#grammar-token-import-stmt) Remember that you can test to ensure a library is available, or take evasive-action if it is not: >>> import so Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'so' (there is a module called "os" though!) -- Regards =dn From rosuav at gmail.com Sun Aug 9 00:26:10 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 9 Aug 2020 14:26:10 +1000 Subject: importlib: import X as Y; from A import B In-Reply-To: References: Message-ID: On Sun, Aug 9, 2020 at 1:25 PM Jason Friedman wrote: > > I have some code I'm going to share with my team, many of whom are not yet > familiar with Python. They may not have 3rd-party libraries such as pandas > or selenium installed. Yes I can instruct them how to install, but the path > of least resistance is to have my code to check for missing dependencies > and attempt to install for them. This code works as desired: > I'd personally much prefer to ship a 'requirements.txt' alongside your code, and use that to govern all the installations. If you want, you could still do a startup check to figure out if everything's installed, but I'd recommend replacing all the pip commands with a single "pip install -r requirements.txt" to fetch everything. ChrisA From urbangabo at gmail.com Sun Aug 9 02:51:16 2020 From: urbangabo at gmail.com (Gabor Urban) Date: Sun, 9 Aug 2020 08:51:16 +0200 Subject: Module import question Message-ID: Hi guys, I have a quite simple question but I could not find the correct answer. I have twoo modules A and B. A imports B. If I import A in a script, Will be B imported automatically? I guess not, but f? not know exactly. Thanks for your answer ?n advance, G?bor From soyeomul at doraji.xyz Sun Aug 9 04:24:18 2020 From: soyeomul at doraji.xyz (=?utf-8?B?7Zmp67OR7Z2s?=) Date: Sun, 09 Aug 2020 17:24:18 +0900 Subject: Module import question References: Message-ID: Gabor Urban writes: > Hi guys, > > I have a quite simple question but I could not find the correct answer. > > I have twoo modules A and B. A imports B. If I import A in a script, Will > be B imported automatically? I guess not, but f? not know exactly. > > Thanks for your answer ?n advance, #+BEGIN_SRC: sh + python (bionic)soyeomul at localhost:~/222$ cat b.py name = "b" (bionic)soyeomul at localhost:~/222$ cat a.py import b name = "a" (bionic)soyeomul at localhost:~/222$ cat c.py import a print(a.name) # a.py's name print(a.b.name) # b.py's name (bionic)soyeomul at localhost:~/222$ python3 c.py a b (bionic)soyeomul at localhost:~/222$ #+END_SRC Sincerely, Byung-Hee -- ^????? _????_ ?????_^))// From barry at barrys-emacs.org Sun Aug 9 04:31:04 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Sun, 9 Aug 2020 09:31:04 +0100 Subject: Any ideas for a new language inspired to Python? In-Reply-To: References: <919216B4-BB7C-407A-B61A-616F55A4DE56@barrys-emacs.org> Message-ID: <332926AD-3A4F-472B-A18B-3588CA4FE624@barrys-emacs.org> > On 8 Aug 2020, at 18:18, Marco Sulla wrote: > > On Sat, 8 Aug 2020 at 14:10, Barry wrote: >>>> On 7 Aug 2020, at 23:28, Marco Sulla wrote: >>> My idea seems to be very simple (so probably it's not simple at all): >>> a language similar to Python, but statically compiled. >> >> Have a look at Apple?s Swift. It reminds me of python as I read it. > > Thank you, some features are interesting, even if I prefer the Python syntax. > > What about the compiler? Is it better to "compile" to C or to > bytecode? By going to C you are really saying you want to use the native instructions of your CPU. Contrast that with bytecode that needs an interpreter. > How can I generate a bytecode that can be compileed by gcc? Have a look at http://www.nuitka.net/ that compiles python into C. One part of its speed up is that the bytecode evel code is not needed. It can also spot optimisations that help, for example noticing that code is doing int math and write that as C avoiding the python objects. > Can I skip the AST generation for now, or it will be a great problem > later? You need a compiler person to explain better than I can. But the steps that you need are: 1. Parse the source into an intermediate form (AST for example) 2. Check that the code is valid 3. Compile into runnable code Barry From h.goebel at goebel-consult.de Sun Aug 9 08:06:08 2020 From: h.goebel at goebel-consult.de (Hartmut Goebel) Date: Sun, 9 Aug 2020 14:06:08 +0200 Subject: [ANN] PyInstaller 4.0 Message-ID: <2e6153c4-4e23-bd28-321d-0b620eed9456@goebel-consult.de> Hello, on behalf of the PyInstaller development team I'm happy to announce PyInstaller 4.0. http://www.pyinstaller.org Thanks for all those who contributed questions, bug-reports or pull-requests. PyInstaller is in urgent need of funding to make future security fixes happen, see for details. === Important Changes === Release 4.0 adds support for 3rd-party packages to provide PyInstaller hooks along with the package. This allows Maintainers of other Python packages to deliver up-to-date PyInstaller hooks as part of their package. See our sample project for more information. PyInstaller uses this option itself to provide updated hooks much faster: Many hooks are moved into the new package pyinstaller-hooks-contrib , which is updated monthly. This package is installed automatically when installing PyInstaller, but can also be updated independently. Finally, this version drops support for Python 2.7, which is end-of-life since January 2020.. The minimum required version is now Python 3.5. The last version supporting Python 2.7 was PyInstaller 3.6. The full changelog for this release can be found at: https://pyinstaller.readthedocs.io/en/v4.0/CHANGES.html === What it is === PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules. PyInstaller reads a Python script written by you. It analyzes your code to discover every other module and library your script needs in order to execute. Then it collects copies of all those files ? including the active Python interpreter! ? and puts them with your script in a single folder, or optionally in a single executable file. PyInstaller is tested against Windows, Mac OS X, and Linux. However, it is not a cross-compiler: to make a Windows app you run PyInstaller in Windows; to make a Linux app you run it in Linux, etc. PyInstaller has been used successfully with AIX, Solaris, and FreeBSD, but is not tested against them. === Help keeping PyInstaller alive === Maintaining PyInstaller is a huge amount of work. PyInstaller development can only continue if users and companies provide sustainable funding. Please consider recurring donations. See http://www.pyinstaller.org/funding.html for how to support PyInstaller. === Installation === PyInstaller can be installed from PyPi using pip install pyinstaller === Important Changes === The full changelog for this release can be found at: https://pyinstaller.readthedocs.io/en/v4.0/CHANGES.html === Feedback === We're eager to listen to your feedback on using PyInstaller: Bug tracker: https://github.com/pyinstaller/pyinstaller/issues Mailing list: http://groups.google.com/group/PyInstaller -- Sch?nen Gru? Hartmut Goebel Dipl.-Informatiker (univ), CISSP, CSSLP, ISO 27001 Lead Implementer Information Security Management, Security Governance, Secure Software Development Goebel Consult, Landshut http://www.goebel-consult.de Blog: http://www.goebel-consult.de/blog/warum-sie-nicht-perl-programmiern-sollten Kolumne: http://www.cissp-gefluester.de/2012-02-bring-your-own-life-glosse From info at tundraware.com Sun Aug 9 11:15:08 2020 From: info at tundraware.com (Tim Daneliuk) Date: Sun, 9 Aug 2020 10:15:08 -0500 Subject: 3.8.5 Failing To Install With pythonz Message-ID: I have a weird problem I could use a bit of help with ... I have successfully installed 3.8.5 using pew/pythonz on a BSD FreeBSD system. But when I attempt to install it on a Linux system I get the traceback below. In this case, pew/pythonz were installed locally in my own account using system native python 3.6: Installing CPython-3.8.5 into /home/tundra/.pythonz/pythons/CPython-3.8.5 Traceback (most recent call last): File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/installer/pythoninstaller.py", line 204, in install self.make() File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/installer/pythoninstaller.py", line 350, in make s.check_call(make) File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/util.py", line 294, in check_call returncode = self.call(cmd) File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/util.py", line 286, in call fp.write(line) UnicodeEncodeError: 'ascii' codec can't encode character '\u2018' in position 81: ordinal not in range(128) ERROR: Failed to install CPython-3.8.5. Check /home/tundra/.pythonz/log/build.log to see why. Traceback (most recent call last): File "/home/tundra/.local/bin/pew", line 11, in sys.exit(pew()) File "/home/tundra/.local/lib/python3.6/site-packages/pew/pew.py", line 809, in pew return command(sys.argv[2:]) File "/home/tundra/.local/lib/python3.6/site-packages/pew/pew.py", line 704, in install_cmd return actual_installer.install() File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/installer/pythoninstaller.py", line 204, in install self.make() File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/installer/pythoninstaller.py", line 350, in make s.check_call(make) File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/util.py", line 294, in check_call returncode = self.call(cmd) File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/util.py", line 286, in call fp.write(line) UnicodeEncodeError: 'ascii' codec can't encode character '\u2018' in position 81: ordinal not in range(128) Ideas anyone? From mats at python.org Sun Aug 9 11:40:51 2020 From: mats at python.org (Mats Wichmann) Date: Sun, 9 Aug 2020 09:40:51 -0600 Subject: Module import question In-Reply-To: References: Message-ID: <083e1249-3d7a-c26d-08e5-b3194f62a4ce@python.org> On 8/9/20 12:51 AM, Gabor Urban wrote: > Hi guys, > > I have a quite simple question but I could not find the correct answer. > > I have twoo modules A and B. A imports B. If I import A in a script, Will > be B imported automatically? I guess not, but f? not know exactly. > > Thanks for your answer ?n advance, Think of import as meaning "make available in namespace". If A simply imports B, then B is available in A's namespace as a name for module B's namespace, and you can access things inside B by qualifying the names: if Foo is in B, then B.Foo works, Foo does not. Different forms of the import statement change the way symbols are made available, e.g you can do from B import * # all the symbols from B are in A's global namespace, Foo works now import B as Baz # B is available through the name Baz, so use Baz.Foo etc. If you have a separate program, call it C, and it imports A, then A is available in C as a name for module A's namespace. That said nothing about B, so the symbol B is not available in C. But if C calls something in A that uses B, then that will work fine, because B exists in A's namespace. And you can access symbols from B by properly qualifying: A.B.Foo. Which is it you meant by "imported automatically"? See Byung-Hee's example to see this in action without all these messy words :) From python at mrabarnett.plus.com Sun Aug 9 12:00:48 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 9 Aug 2020 17:00:48 +0100 Subject: 3.8.5 Failing To Install With pythonz In-Reply-To: References: Message-ID: <07bbdbed-f8eb-0df3-257a-55b1dfc0e569@mrabarnett.plus.com> On 2020-08-09 16:15, Tim Daneliuk wrote: > I have a weird problem I could use a bit of help with ... > > I have successfully installed 3.8.5 using pew/pythonz on a BSD FreeBSD system. > But when I attempt to install it on a Linux system I get the traceback below. > In this case, pew/pythonz were installed locally in my own account using system > native python 3.6: > > Installing CPython-3.8.5 into /home/tundra/.pythonz/pythons/CPython-3.8.5 > Traceback (most recent call last): > File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/installer/pythoninstaller.py", line 204, in install > self.make() > File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/installer/pythoninstaller.py", line 350, in make > s.check_call(make) > File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/util.py", line 294, in check_call > returncode = self.call(cmd) > File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/util.py", line 286, in call > fp.write(line) > UnicodeEncodeError: 'ascii' codec can't encode character '\u2018' in position 81: ordinal not in range(128) > ERROR: Failed to install CPython-3.8.5. Check /home/tundra/.pythonz/log/build.log to see why. > Traceback (most recent call last): > File "/home/tundra/.local/bin/pew", line 11, in > sys.exit(pew()) > File "/home/tundra/.local/lib/python3.6/site-packages/pew/pew.py", line 809, in pew > return command(sys.argv[2:]) > File "/home/tundra/.local/lib/python3.6/site-packages/pew/pew.py", line 704, in install_cmd > return actual_installer.install() > File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/installer/pythoninstaller.py", line 204, in install > self.make() > File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/installer/pythoninstaller.py", line 350, in make > s.check_call(make) > File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/util.py", line 294, in check_call > returncode = self.call(cmd) > File "/home/tundra/.local/lib/python3.6/site-packages/pythonz/util.py", line 286, in call > fp.write(line) > UnicodeEncodeError: 'ascii' codec can't encode character '\u2018' in position 81: ordinal not in range(128) > > > Ideas anyone? > FTR, '\u2018' is the codepoint 'LEFT SINGLE QUOTATION MARK'. Try reporting it on the project's homepage. It looks like there have been similar problems before, but not this one. From Marco.Sulla.Python at gmail.com Sun Aug 9 12:44:20 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sun, 9 Aug 2020 18:44:20 +0200 Subject: Any ideas for a new language inspired to Python? In-Reply-To: References: Message-ID: On Sun, 9 Aug 2020 at 10:31, Barry Scott wrote: > By going to C you are really saying you want to use the native instructions of your CPU. > Contrast that with bytecode that needs an interpreter. This is also an answer for Grant Edwards: the idea was to generate bytecode and compile it to machine code. See gcj, for example, that translates the Java bytecode into machine code. Even if it's not needed by the "mainstream" implementation, it could be good if someone wants to implement its own interpreter. Currently I don't care if this will slow down the compilation: things can be accelerated or removed. My doubt is if the initial work is too much and if I can, eventually, add this extra step later without many troubles. On Sun, 9 Aug 2020 at 10:31, Barry Scott wrote: > Have a look at http://www.nuitka.net/ that compiles python into C. > It can also spot optimisations that help, for example noticing that > code is doing int math and write that as C avoiding the python objects. This is another big problem: everything is an object? It seems that in practice, using integers and floats as objects leads to great slowdowns. And personally I never saw people that created superclasses of int or float. Anyway, if they feel the urgence, they can use `numbers` ABCs. It seems to me that the Java separation between primitive types vs objects is quite practical. On Sun, 9 Aug 2020 at 10:31, Barry Scott wrote: > You need a compiler person to explain better than I can. > But the steps that you need are: > 1. Parse the source into an intermediate form (AST for example) > 2. Check that the code is valid > 3. Compile into runnable code I know this is not trivial... I read also about lexers and parsers. For example, it seems that Guido now uses a new parser, a PEG parser. Don't know if it uses a lexer or not and why. And it seems they exist generators of lexers and parsers. The more simple to use seems to be ANTLR: https://github.com/antlr/antlr4 but it does not generate a PEG parser. Do you think py devs will be greatly bored if I link this discussion in the python-dev mailing list? From dieter at handshake.de Sun Aug 9 13:00:54 2020 From: dieter at handshake.de (Dieter Maurer) Date: Sun, 9 Aug 2020 19:00:54 +0200 Subject: importlib: import X as Y; from A import B In-Reply-To: References: Message-ID: <24368.11206.803287.230564@ixdm.fritz.box> Jason Friedman wrote at 2020-8-8 21:23 -0600: > ... >The cherry-on-top would be to import with the "aliasing" and "from" they >will most likely see on the web, so that my code matches what they see >there. In other words, instead of: > >import pandas >df = pandas.from_csv (...) >import selenium >browser = selenium.webdriver.Firefox() > >on the web they will typically see: > >import pandas as pd import pandas; pd = pandas >df = pd.from_csv (...) >from selenium import webdriver import selenium.webdriver; webdriver = selenium.webdriver > >I don't see anything in the importlib module documentation that supports >this. From urbangabo at gmail.com Sun Aug 9 13:36:57 2020 From: urbangabo at gmail.com (Gabor Urban) Date: Sun, 9 Aug 2020 19:36:57 +0200 Subject: Module import question Message-ID: Hi guys, Thanks for the answers. IT is clear No?. G?bor From bgailer at gmail.com Sun Aug 9 14:04:22 2020 From: bgailer at gmail.com (Bob Gailer) Date: Sun, 9 Aug 2020 14:04:22 -0400 Subject: Module import question In-Reply-To: References: <083e1249-3d7a-c26d-08e5-b3194f62a4ce@python.org> Message-ID: On Aug 9, 2020 11:41 AM, "Mats Wichmann" wrote: > > On 8/9/20 12:51 AM, Gabor Urban wrote: > > Hi guys, > > > > I have a quite simple question but I could not find the correct answer. > > > > I have twoo modules A and B. A imports B. If I import A in a script, Will > > be B imported automatically? I guess not, but f? not know exactly. > > > > Thanks for your answer ?n advance, > > Think of import as meaning "make available in namespace". Well it's actually a little more involved than that. When python import a module it executes the module code. This is why you often see at the bottom of a module: if __name__ == '__main__': # code to execute when running the module as opposed to importing it. When importing a module __name__ is the module's name rather than '__main__'. What happens when module A Imports module B depends on whether or not the import B statement is actually executed. From tjreedy at udel.edu Sun Aug 9 13:55:31 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 9 Aug 2020 13:55:31 -0400 Subject: Any ideas for a new language inspired to Python? In-Reply-To: References: Message-ID: On 8/9/2020 12:44 PM, Marco Sulla wrote: > Do you think py devs will be greatly bored if I link this discussion > in the python-dev mailing list? Don't. This is neither about language development (and proposals initially go to python-ideas) nor about immediate cpython development -- Terry Jan Reedy From grant.b.edwards at gmail.com Sun Aug 9 14:27:01 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 9 Aug 2020 18:27:01 -0000 (UTC) Subject: Any ideas for a new language inspired to Python? References: Message-ID: On 2020-08-09, Marco Sulla wrote: > On Sun, 9 Aug 2020 at 10:31, Barry Scott wrote: >> By going to C you are really saying you want to use the native >> instructions of your CPU. Contrast that with bytecode that needs >> an interpreter. > > This is also an answer for Grant Edwards: the idea was to generate > bytecode and compile it to machine code. Right. I was just pointing out that you said you wanted to do "static compilation", and then provided an small example that demonstrated something unrelated[1] (static typing). If you want to design a language that has static typing, that's fine. If you want to implement that language using static compilation, that's fine. You can have both if you want. But, they are two independent concepts, and you're going to confuse people if you use them interchangeably. [1] Though in theory they are orthogonal, in practice certain combinations of static compilation vs. bytecode+VM and static vs. dynamic typing are harder to implement than others. -- Grant From 2QdxY4RzWzUUiLuE at potatochowder.com Sun Aug 9 15:00:45 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Sun, 9 Aug 2020 14:00:45 -0500 Subject: Any ideas for a new language inspired to Python? In-Reply-To: <6t70jf1pc9fclvrhue6gschoopmbj701pe@4ax.com> References: <919216B4-BB7C-407A-B61A-616F55A4DE56@barrys-emacs.org> <332926AD-3A4F-472B-A18B-3588CA4FE624@barrys-emacs.org> <6t70jf1pc9fclvrhue6gschoopmbj701pe@4ax.com> Message-ID: <20200809190045.GL42295@scrozzle> On 2020-08-09 at 13:07:03 -0400, Dennis Lee Bieber wrote: > On Sun, 9 Aug 2020 09:31:04 +0100, Barry Scott > declaimed the following: > > > > >By going to C you are really saying you want to use the native instructions of your CPU. > >Contrast that with bytecode that needs an interpreter. > > > > Unless one has located a C-compiler that generates byte-code for some > virtual machine. gcc compiles source code into different levels of virtual machines, and then those virtual machines into actual object code. Start at https://gcc.gnu.org/onlinedocs/gccint/index.html, and drill down into section 6.3.8 (Anatomy of a Language Front End) and chapter 9 (Passes and Files of the Compiler). Nothing stops you from translating your source code directly into, say, RTL. The Wikipedia page for LLVM tells me it's designed for this sort of thing. From adam.grant.hendry at gmail.com Sun Aug 9 15:00:02 2020 From: adam.grant.hendry at gmail.com (Adam Hendry) Date: Sun, 9 Aug 2020 12:00:02 -0700 (PDT) Subject: Python 3 Feature Request: `pathlib` Use Trailing Slash Flag Message-ID: <378f7e45-a2cd-4a84-aa82-7ea8c41ddf8bn@googlegroups.com> `pathlib` trims trailing slashes by default, but certain packages require trailing slashes. In particular, `cx_Freeze.bdist_msi` option "directories" is used to build the package directory structure of a program and requires trailing slashes. Does anyone think it would be a good idea to add a flag or argument to `pathlib.Path` to keep trailing slashes? For instance, I envision something like: ``` from pathlib import Path my_path = Path(r"foo/bar/", keep_trailing_slash=True) ``` The argument could be made `False` by default to maintain backwards compatibility. The only way I know to keep the backslash and maintain cross-compatibility is as follows: ``` import os from pathlib import Path my_path = f"{Path(r"foo/bar").resolve()}{os.sep}" ``` although this returns a string and the `Path` object is lost. Any thoughts? From sammy.jackson987 at gmail.com Sun Aug 9 18:22:08 2020 From: sammy.jackson987 at gmail.com (sammy.jackson987 at gmail.com) Date: Sun, 9 Aug 2020 15:22:08 -0700 (PDT) Subject: Including a Variable In the HTML Tags When Sending An Email In-Reply-To: References: <61651de2-e6ab-4e80-b5ab-b678ee3ea36do@googlegroups.com> <514f6299-5da6-4801-83b2-6b850ec21b77o@googlegroups.com> <39f80119-14b9-3dcd-825a-aa4031ffeb0c@Damon-Family.org> Message-ID: <00660cdd-137c-4e37-9016-d07db6e1e09ao@googlegroups.com> On Sunday, August 9, 2020 at 1:32:30 AM UTC+1, Richard Damon wrote: > On 8/8/20 8:03 PM, sammy.jackson987 at gmail.com wrote: > > If i use place holders i.e. {0} and {1} where {0} is the name and {1} is the dataframe i get an error for the following line of code:- > > .format((Name,Body).to_html()) which states 'tuple' object has no attribute 'to_html'. > > I would do it as > > .format(Name, Body.to_html()) if your names really are just straight > letters. > > If they might have some funny characters that need html handling, you > could do: > > import html > > > .format(html.escape(Name), Body.to_html()) > > > Note that different types need to be treated differently to get them > into clean html. > > > -- > Richard Damon Richard I love you. The following change you recommended worked. From rosuav at gmail.com Sun Aug 9 19:02:57 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 10 Aug 2020 09:02:57 +1000 Subject: Any ideas for a new language inspired to Python? In-Reply-To: References: Message-ID: On Mon, Aug 10, 2020 at 2:46 AM Marco Sulla wrote: > This is another big problem: everything is an object? > It seems that in practice, using integers and floats as objects leads > to great slowdowns. And personally I never saw people that created > superclasses of int or float. Anyway, if they feel the urgence, they > can use `numbers` ABCs. It seems to me that the Java separation > between primitive types vs objects is quite practical. That isn't a problem. It is, in fact, extremely practical. EVERY Python object has a repr, EVERY Python object has a type, etc, etc, etc. You can ask questions like "is this object an instance of (float,int)" and get back a useful answer. If you *really* want to get away from ints-as-objects, what I would recommend is emulating it. Some languages pretend that everything's an object, but for small integers (say, those less than 2**60), it doesn't store the object itself, it just stores the integer (with the low bit set, for example). It requires special-casing integers *everywhere* in the language executor (interpreter/compiler), and in return, you get to save about 20 bytes per integer compared to the way CPython does it. Is that worth it? ChrisA From Richard at Damon-Family.org Sun Aug 9 19:04:55 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 9 Aug 2020 19:04:55 -0400 Subject: Including a Variable In the HTML Tags When Sending An Email In-Reply-To: <00660cdd-137c-4e37-9016-d07db6e1e09ao@googlegroups.com> References: <61651de2-e6ab-4e80-b5ab-b678ee3ea36do@googlegroups.com> <514f6299-5da6-4801-83b2-6b850ec21b77o@googlegroups.com> <39f80119-14b9-3dcd-825a-aa4031ffeb0c@Damon-Family.org> <00660cdd-137c-4e37-9016-d07db6e1e09ao@googlegroups.com> Message-ID: On 8/9/20 6:22 PM, sammy.jackson987 at gmail.com wrote: > On Sunday, August 9, 2020 at 1:32:30 AM UTC+1, Richard Damon wrote: >> On 8/8/20 8:03 PM, sammy.jackson987 at gmail.com wrote: >>> If i use place holders i.e. {0} and {1} where {0} is the name and {1} is the dataframe i get an error for the following line of code:- >>> .format((Name,Body).to_html()) which states 'tuple' object has no attribute 'to_html'. >> I would do it as >> >> .format(Name, Body.to_html()) if your names really are just straight >> letters. >> >> If they might have some funny characters that need html handling, you >> could do: >> >> import html >> >> >> .format(html.escape(Name), Body.to_html()) >> >> >> Note that different types need to be treated differently to get them >> into clean html. >> >> >> -- >> Richard Damon > > Richard I love you. > > The following change you recommended worked. > > Now spend a bit of time understanding why that works, how it is different from what you did, and what you can learn from it so you can do other things than just follow a rote recipe. -- Richard Damon From Gronicus at SGA.Ninja Sun Aug 9 19:39:15 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sun, 9 Aug 2020 19:39:15 -0400 Subject: IDLE: New Feature? Message-ID: <000001d66ea6$4b943940$e2bcabc0$@SGA.Ninja> Where would the conversation have to happen to get the forces-that-be to install a pull-down/history menu for the Find option in IDLE? To have to retype the search option over and over when I am toggling between two or more searches gets tiresome. I would rather spend my brain cells and bandwidth thinking about coding. Steve ---------------------------------------------------------------------------- ---------------- Footnote: There's 99 bugs in the code, in the code. 99 bugs in the code. Take one down and patch it all around. Now there's 117 bugs in the code. From rosuav at gmail.com Sun Aug 9 19:44:31 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 10 Aug 2020 09:44:31 +1000 Subject: IDLE: New Feature? In-Reply-To: <000001d66ea6$4b943940$e2bcabc0$@SGA.Ninja> References: <000001d66ea6$4b943940$e2bcabc0$@SGA.Ninja> Message-ID: On Mon, Aug 10, 2020 at 9:40 AM Steve wrote: > > Where would the conversation have to happen to get the forces-that-be to > install a pull-down/history menu for the Find option in IDLE? To have to > retype the search option over and over when I am toggling between two or > more searches gets tiresome. I would rather spend my brain cells and > bandwidth thinking about coding. > You could raise that on python-ideas, but if you want to put some effort into making it really really easy for Terry, you could try implementing it - or at least the beginnings of it - as a pull request. Idle is written in Python, so you can tinker with it without writing any C code. ChrisA From tjreedy at udel.edu Sun Aug 9 21:50:39 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 9 Aug 2020 21:50:39 -0400 Subject: IDLE: New Feature? In-Reply-To: <000001d66ea6$4b943940$e2bcabc0$@SGA.Ninja> References: <000001d66ea6$4b943940$e2bcabc0$@SGA.Ninja> Message-ID: On 8/9/2020 7:39 PM, Steve wrote: > Where would the conversation have to happen to get the forces-that-be to > install a pull-down/history menu for the Find option in IDLE? To have to > retype the search option over and over when I am toggling between two or > more searches gets tiresome. I would rather spend my brain cells and > bandwidth thinking about coding. The IDLE-dev mail list https://mail.python.org/mailman/listinfo/idle-dev may or may not be active at any time. Simplest specification: one list for all 3 search boxes; start fresh each session If search boxes were non-modal, it might work to have two open for same editor (not sure). > Footnote: > There's 99 bugs in the code, in the code. > 99 bugs in the code. > Take one down and patch it all around. > Now there's 117 bugs in the code. Argh! I sometimes find a bug fixing a bug, but more often think of multiple possible improvement when implementing one. -- Terry Jan Reedy From 2QdxY4RzWzUUiLuE at potatochowder.com Sun Aug 9 22:19:14 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Sun, 9 Aug 2020 21:19:14 -0500 Subject: Any ideas for a new language inspired to Python? In-Reply-To: References: Message-ID: <20200810021914.GN42295@scrozzle> On 2020-08-10 at 09:02:57 +1000, Chris Angelico wrote: > If you *really* want to get away from ints-as-objects, what I would > recommend is emulating it. Some languages pretend that everything's an > object, but for small integers (say, those less than 2**60), it > doesn't store the object itself, it just stores the integer (with the > low bit set, for example). It requires special-casing integers > *everywhere* in the language executor (interpreter/compiler), and in > return, you get to save about 20 bytes per integer compared to the way > CPython does it. Is that worth it? As always, it depends. The special casing to which Chris referred is no worse than the special casing that has to happen for every arithmetic operation anyway. How does Python calculate a * b? Well, it depends on the type of a and the type of b, and then dispatching to a special case multiplication routine. All that boxing and unboxing (pulling the actual values out of the objects, creating new objects, memory management, etc.) can add up, too. If my application deals with arithmetic on millions or billions? of small integers (say, those less than 2**60), then it can make a big difference. ;-) ? whether a billion is 1e9 or 1e12 From ganesh1pal at gmail.com Mon Aug 10 14:35:48 2020 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Tue, 11 Aug 2020 00:05:48 +0530 Subject: How to remove "" from starting of a string if provided by the user Message-ID: How to remove " from the starting and ending of a string , before comparison . Here is an example and my solution wtih eval ( I am advised not to use this one) , please suggest an alternative . I am on linux and python 2.7 g1 at X1:/tmp$ cat file2.py #!/usr/bin/python # Case 1 - server2 file is "'/fileno_100.txt'" stat={} stat['server1'] = '/fileno_100.txt' stat['server2'] = "'/fileno_100.txt'" if stat['server1'] == eval(stat['server2']): print "OK" # Case 2 - server2 file is '/fileno_100.txt' stat['server2'] = "'/fileno_100.txt'" if stat['server1'] == eval(stat['server2']): print "OK" # Case 3 - server2 file can be in (a) '/fileno_100.txt' or (b) : "'/fileno_100.txt'" format g1 at X1:/tmp$ python file2.py OK OK From lele at metapensiero.it Mon Aug 10 14:42:38 2020 From: lele at metapensiero.it (Lele Gaifax) Date: Mon, 10 Aug 2020 20:42:38 +0200 Subject: Strange namespace issue Message-ID: <87k0y6gx5t.fsf@metapensiero.it> Hi all, today I faced an issue that, although very easy to fix, left me wondering about what causes it. The context is an application that execute small scripts coming from an external source (say, a database). The application first compile the script, then execute it passing it some values: in the script I wrote this morning I used a list comprehension, executing a method of an instance passed in in the local context. The following example illustrates the problem: class Test: def create_value(self, a): return a*2 script = """\ # This works cv = test.create_value x = [] for i in range(3): x.append(cv(i)) print(x) # This does not: NameError: name 'test' is not defined x = [test.create_value(i) for i in range(3)] print(x) # This neither: NameError: name 'cv' is not defined x = [cv(i) for i in range(3)] print(x) """ code = compile(script, 'script', 'exec') exec(code, {}, {'test': Test()}) I must be missing something, as I cannot understand why within the list comprehension the neither the name "test" nor the name "cv" are defined... Thanks in advance for any enlightenment! ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From roel at roelschroeven.net Mon Aug 10 15:15:16 2020 From: roel at roelschroeven.net (Roel Schroeven) Date: Mon, 10 Aug 2020 21:15:16 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: Terry Reedy schreef op 7/08/2020 om 22:08: > On 8/7/2020 11:46 AM, Chris Angelico wrote: > >> My point is that doing Fibonacci recursively is arguably more elegant >> while being materially worse at performance. > > This is a common misconception. Linear iteration and tail recursion are > equivalent. The issue is calculating values once versus multiple times. > Here is the fast recursion equivalent to the fast iteration. > > def fib(n, pair=(1,0)): > previous, current = pair > if n: > return fib(n-1, (current, previous + current)) > else: > return current Of course, but now you've lost the elegance of the recursive version being near-literal translation of the mathematical definition. It's a gripe I have with many introductory texts to functional programming. Recursion is super cool, they say, it lets you decompose problems in smaller problems in an elegant natural way. But then show examples like Fibonacci where the elegant natural way is a bad solution, so they introduce accumulators and stuff, and then Fibonacci does work much better indeed. But they fail to notice that the new solution is not elegant and natural at all anymore. It has just become iteration in a recursive disguise. I'm not saying there is nothing useful in functional programming and the use of recursion; there most certainly is. But the way many texts introduce it IMO doesn't help at all to understand the elegance that can be achieved. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From rosuav at gmail.com Mon Aug 10 16:09:00 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Aug 2020 06:09:00 +1000 Subject: Strange namespace issue In-Reply-To: <87k0y6gx5t.fsf@metapensiero.it> References: <87k0y6gx5t.fsf@metapensiero.it> Message-ID: On Tue, Aug 11, 2020 at 5:44 AM Lele Gaifax wrote: > > Hi all, > > today I faced an issue that, although very easy to fix, left me wondering > about what causes it. > > The context is an application that execute small scripts coming from an > external source (say, a database). The application first compile the script, > then execute it passing it some values: in the script I wrote this morning I > used a list comprehension, executing a method of an instance passed in in the > local context. > > The following example illustrates the problem: > > class Test: > def create_value(self, a): > return a*2 > > script = """\ > # This works > cv = test.create_value > x = [] > for i in range(3): > x.append(cv(i)) > print(x) > > # This does not: NameError: name 'test' is not defined > x = [test.create_value(i) for i in range(3)] > print(x) > > # This neither: NameError: name 'cv' is not defined > x = [cv(i) for i in range(3)] > print(x) > """ > > code = compile(script, 'script', 'exec') > exec(code, {}, {'test': Test()}) > > I must be missing something, as I cannot understand why within the list > comprehension the neither the name "test" nor the name "cv" are defined... > > Thanks in advance for any enlightenment! > Interesting. You're passing an empty globals and a non-empty locals (the second and third arguments to exec, respectively). Is that deliberate? By the look of this code, it's meant to be at global scope (as if it's the top level code in a module), which is best done by passing just a single dict to exec (it'll be both globals and locals). The reason your first block works but the comprehensions don't is that comprehensions act in a nested scope. I think you've hit on a curious edge case where empty globals results in strange behaviour. I tried your code with the empty dict removed and it appears to work, but if you had a good reason for having separate dicts, that might break. ChrisA From rosuav at gmail.com Mon Aug 10 16:14:52 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Aug 2020 06:14:52 +1000 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200806183947.GG2129@shallowsky.com> <170201f7-c7f0-44a4-8ec2-94e2c65aa935o@googlegroups.com> <20200807003543.GC8728@bladeshadow.org> <20200807153615.GG8728@bladeshadow.org> Message-ID: On Tue, Aug 11, 2020 at 5:48 AM Roel Schroeven wrote: > I'm not saying there is nothing useful in functional programming and the > use of recursion; there most certainly is. But the way many texts > introduce it IMO doesn't help at all to understand the elegance that can > be achieved. Indeed. When I'm talking to students about recursion, often the question "why bother" comes up... but when they finally 'get it', it's usually because of an example far more elegant than Fibonacci numbers. One of my favourites is: Given a binary tree, calculate its height. def height(tree): if not tree: return 0 return max(height(tree.left), height(tree.right)) + 1 THIS is the sort of thing that shows off the beauty of recursion. Convoluted code with accumulator parameters just shows off that you can write bad code in any style. (Though the accumulator parameter form does have its place. Ever written callback-based asynchronous code that needs to iterate over something? Such fun.) ChrisA From cs at cskk.id.au Mon Aug 10 17:06:23 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 11 Aug 2020 07:06:23 +1000 Subject: How to remove "" from starting of a string if provided by the user In-Reply-To: References: Message-ID: <20200810210623.GA73678@cskk.homeip.net> On 11Aug2020 00:05, Ganesh Pal wrote: >How to remove " from the starting and ending of a string , before >comparison . Here is an example and my solution wtih eval ( I am advised >not to use this one) , please suggest an alternative . I am on linux and >python 2.7 Indeed. Using eval is extremely dangerous - it can execute _any_ python code at all. Do not do that. I would look for the quote character (you say " above but all your examples actually use the ' character) at the start and end with .startswith and .endswith methods, and cut out the middle with a slice if they are both your target quote character (don't forget that Python supports negative indices, making this pretty easy). But I suspect that in the real world you'll find this approach simplistic. Normally quotes introduce a special syntax between them, such a \n to indicate a newline character and so forth, so _only_ stripping the quotes is not al that would be required. Cheers, Cameron Simpson From python at mrabarnett.plus.com Mon Aug 10 18:33:46 2020 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 10 Aug 2020 23:33:46 +0100 Subject: How to remove "" from starting of a string if provided by the user In-Reply-To: References: Message-ID: <5fca1bcc-3a49-55ef-5f7c-fa0fb0713df6@mrabarnett.plus.com> On 2020-08-10 19:35, Ganesh Pal wrote: > How to remove " from the starting and ending of a string , before > comparison . Here is an example and my solution wtih eval ( I am advised > not to use this one) , please suggest an alternative . I am on linux and > python 2.7 > > g1 at X1:/tmp$ cat file2.py > #!/usr/bin/python > > # Case 1 - server2 file is "'/fileno_100.txt'" > stat={} > stat['server1'] = '/fileno_100.txt' > stat['server2'] = "'/fileno_100.txt'" > > if stat['server1'] == eval(stat['server2']): > print "OK" > > # Case 2 - server2 file is '/fileno_100.txt' > stat['server2'] = "'/fileno_100.txt'" > > if stat['server1'] == eval(stat['server2']): > print "OK" > > > # Case 3 - server2 file can be in (a) '/fileno_100.txt' or (b) : > "'/fileno_100.txt'" format > > g1 at X1:/tmp$ python file2.py > OK > OK > You could strip off the quotes with the .strip method or use literal_eval from the ast module. From PythonList at DancesWithMice.info Mon Aug 10 20:49:33 2020 From: PythonList at DancesWithMice.info (dn) Date: Tue, 11 Aug 2020 12:49:33 +1200 Subject: Save-to-file code not quite working completely In-Reply-To: <92c0jfdn0sdtk9ci2ln35c3v3f1tmhoin2@4ax.com> References: <000701d66dc5$abe33f30$03a9bd90$@SGA.Ninja> <1fb2f4ee-6c7e-8963-5b48-84f3c5cd14d2@DancesWithMice.info> <92c0jfdn0sdtk9ci2ln35c3v3f1tmhoin2@4ax.com> Message-ID: <168b0899-e609-0500-39e3-285ad7f376c3@DancesWithMice.info> On 10/08/2020 05:23, Dennis Lee Bieber wrote: > On Sun, 9 Aug 2020 11:50:51 +1200, dn via Python-list > declaimed the following: >> To be a logomach, let's talk about "update":- >> May I advise that a 'good practice' would be to create a new file, and >> thus be able to (also) maintain the old version as a 'backup'. >> (also: advantage when debugging/testing logic!) > > Per the documentation, this is exactly what the "inplace=True" does! It > renames the original file, then writes the output under the original name. > Keeping the backup after processing requires providing an explicit > "backup=.ext" option, otherwise it uses .bak and deletes the file when > processing completes. Apologies for incomplete answer. I have finally remembered why I (have long) steer-clear of fileinput: a) criticism from Martijn Pieters https://www.zopatista.com/python/2013/11/26/inplace-file-rewriting/ b) I can't recall 'my' last application requiring/desiring a flat-file that wasn't JSON or YAML. The above article is (2013) old. I notice that whilst the github received a trivial update one month back, that the PyPI entry is almost two years old. I (am biased, admittedly) still maintain that for anything more than the trivial, a direct-access mechanism is the tool-for-the-job, and because I think they are 'easy', an RDBMS. YMMV! -- Regards =dn From ganesh1pal at gmail.com Mon Aug 10 21:20:27 2020 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Tue, 11 Aug 2020 06:50:27 +0530 Subject: How to remove "" from starting of a string if provided by the user In-Reply-To: <5fca1bcc-3a49-55ef-5f7c-fa0fb0713df6@mrabarnett.plus.com> References: <5fca1bcc-3a49-55ef-5f7c-fa0fb0713df6@mrabarnett.plus.com> Message-ID: The possible value of stat['server2'] can be either (a) "'/fileno_100.txt'" or (b) '/fileno_100.txt' . How do I check if it the value was (a) i.e string started and ended with a quote , so that I can use ast.literal_eval() >>> import ast >>> stat = {} >>> stat['server2'] = "'/fileno_100.txt'" >>> stat['server2'] = ast.literal_eval(stat['server2']) >>> print stat['server2'] /fileno_100.txt >>> >>> if stat['server2'].startswith("\"") and stat['server2'].endswith("\""): ... stat['server2'] = ast.literal_eval(stat['server2']) ... >>> I tried startswith() and endswith(), doesn't seem to work ?. Is there a simpler way ? Regards, Ganesh On Tue, Aug 11, 2020 at 4:06 AM MRAB wrote: > On 2020-08-10 19:35, Ganesh Pal wrote: > > How to remove " from the starting and ending of a string , before > > comparison . Here is an example and my solution wtih eval ( I am advised > > not to use this one) , please suggest an alternative . I am on linux and > > python 2.7 > > > > g1 at X1:/tmp$ cat file2.py > > #!/usr/bin/python > > > > # Case 1 - server2 file is "'/fileno_100.txt'" > > stat={} > > stat['server1'] = '/fileno_100.txt' > > stat['server2'] = "'/fileno_100.txt'" > > > > if stat['server1'] == eval(stat['server2']): > > print "OK" > > > > # Case 2 - server2 file is '/fileno_100.txt' > > stat['server2'] = "'/fileno_100.txt'" > > > > if stat['server1'] == eval(stat['server2']): > > print "OK" > > > > > > # Case 3 - server2 file can be in (a) '/fileno_100.txt' or (b) : > > "'/fileno_100.txt'" format > > > > g1 at X1:/tmp$ python file2.py > > OK > > OK > > > You could strip off the quotes with the .strip method or use > literal_eval from the ast module. > -- > https://mail.python.org/mailman/listinfo/python-list > From jsf80238 at gmail.com Mon Aug 10 22:36:52 2020 From: jsf80238 at gmail.com (Jason Friedman) Date: Mon, 10 Aug 2020 20:36:52 -0600 Subject: importlib: import X as Y; from A import B In-Reply-To: <24368.11206.803287.230564@ixdm.fritz.box> References: <24368.11206.803287.230564@ixdm.fritz.box> Message-ID: > > import pandas; pd = pandas > > >df = pd.from_csv (...) > >from selenium import webdriver > > import selenium.webdriver; webdriver = selenium.webdriver > Thank you, this works. From please at see.Web.for.e-mail.INVALID Tue Aug 11 00:35:43 2020 From: please at see.Web.for.e-mail.INVALID (Martin) Date: Mon, 10 Aug 2020 22:35:43 -0600 Subject: Any timeline for PIL for Python 3.4 Message-ID: Hi, I am running Python 3.4.4, and would like to use the Python Imaging Library (PIL). This is currently not available for Python Version 3. Does anybody know when it will become available? Plan B is to install Python 2.7.18. I just need an idea of how long I would need to wait for Plan A. -- Regards, Martin Leese E-mail: please at see.Web.for.e-mail.INVALID Web: http://members.tripod.com/martin_leese/ From miked at dewhirst.com.au Tue Aug 11 01:18:10 2020 From: miked at dewhirst.com.au (Mike Dewhirst) Date: Tue, 11 Aug 2020 15:18:10 +1000 Subject: Any timeline for PIL for Python 3.4 In-Reply-To: References: Message-ID: <4276d99c-1c05-46ca-13f3-cebef0aeeae5@dewhirst.com.au> On 11/08/2020 2:35 pm, Martin wrote: > Hi, > > I am running Python 3.4.4, and would like to > use the Python Imaging Library (PIL).? This > is currently not available for Python > Version 3.? Does anybody know when it will > become available? Try Pillow https://pillow.readthedocs.io/en/stable/installation.html > > Plan B is to install Python 2.7.18.? I just > need an idea of how long I would need to > wait for Plan A. > -- 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: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: OpenPGP digital signature URL: From PythonList at DancesWithMice.info Tue Aug 11 01:29:25 2020 From: PythonList at DancesWithMice.info (dn) Date: Tue, 11 Aug 2020 17:29:25 +1200 Subject: Any timeline for PIL for Python 3.4 In-Reply-To: References: Message-ID: <51001555-f9cc-603d-d402-83f615d9494e@DancesWithMice.info> On 11/08/2020 16:35, Martin wrote: > I am running Python 3.4.4, and would like to > use the Python Imaging Library (PIL).? This > is currently not available for Python > Version 3.? Does anybody know when it will > become available? > > Plan B is to install Python 2.7.18.? I just > need an idea of how long I would need to > wait for Plan A. 1 PIL was discontinued about a decade back. Please use "Pillow" (a fork - note first three letters), which is available from PyPI (pip3) 2 Bad news though, IIRC it requires Python 3.5+ 3 Don't degrade to Py2 if you can at all avoid doing-so! -- Regards =dn From jfong at ms4.hinet.net Tue Aug 11 01:49:57 2020 From: jfong at ms4.hinet.net (jfong at ms4.hinet.net) Date: Mon, 10 Aug 2020 22:49:57 -0700 (PDT) Subject: Any timeline for PIL for Python 3.4 In-Reply-To: References: <51001555-f9cc-603d-d402-83f615d9494e@DancesWithMice.info> Message-ID: <88773ccd-33cb-41af-a00e-6de9a9a12e14o@googlegroups.com> dn? 2020?8?11???? UTC+8??1?29?47???? > On 11/08/2020 16:35, Martin wrote: > > I am running Python 3.4.4, and would like to > > use the Python Imaging Library (PIL).? This > > is currently not available for Python > > Version 3.? Does anybody know when it will > > become available? > > > > Plan B is to install Python 2.7.18.? I just > > need an idea of how long I would need to > > wait for Plan A. > > > 1 PIL was discontinued about a decade back. Please use "Pillow" (a fork > - note first three letters), which is available from PyPI (pip3) > > 2 Bad news though, IIRC it requires Python 3.5+ > > 3 Don't degrade to Py2 if you can at all avoid doing-so! > -- > Regards =dn Pillow for Python 3.4 can be downloaded at this moment in time:-) https://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow --Jach From rosuav at gmail.com Tue Aug 11 02:37:12 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 11 Aug 2020 16:37:12 +1000 Subject: Any timeline for PIL for Python 3.4 In-Reply-To: References: Message-ID: On Tue, Aug 11, 2020 at 2:41 PM Martin wrote: > > Hi, > > I am running Python 3.4.4, and would like to > use the Python Imaging Library (PIL). This > is currently not available for Python > Version 3. Does anybody know when it will > become available? > > Plan B is to install Python 2.7.18. I just > need an idea of how long I would need to > wait for Plan A. > As others have said, Pillow is the way to go (it's API-compatible with original PIL). But you may want to consider a newer Python - 3.4 is now quite old. ChrisA From Gronicus at SGA.Ninja Tue Aug 11 04:26:41 2020 From: Gronicus at SGA.Ninja (Steve) Date: Tue, 11 Aug 2020 04:26:41 -0400 Subject: IDLE: New Feature? In-Reply-To: References: <000001d66ea6$4b943940$e2bcabc0$@SGA.Ninja> Message-ID: <000d01d66fb9$24170690$6c4513b0$@SGA.Ninja> << Simplest specification: << one list for all 3 search boxes; << start fresh each session I do not understand what this means... Footnote: The only time "incorrectly" is spelled incorrectly is when it is spelled "incorrectly". -----Original Message----- From: Python-list On Behalf Of Terry Reedy Sent: Sunday, August 9, 2020 9:51 PM To: python-list at python.org Subject: Re: IDLE: New Feature? On 8/9/2020 7:39 PM, Steve wrote: > Where would the conversation have to happen to get the forces-that-be > to install a pull-down/history menu for the Find option in IDLE? To > have to retype the search option over and over when I am toggling > between two or more searches gets tiresome. I would rather spend my > brain cells and bandwidth thinking about coding. The IDLE-dev mail list https://mail.python.org/mailman/listinfo/idle-dev may or may not be active at any time. Simplest specification: one list for all 3 search boxes; start fresh each session If search boxes were non-modal, it might work to have two open for same editor (not sure). > Footnote: > There's 99 bugs in the code, in the code. > 99 bugs in the code. > Take one down and patch it all around. > Now there's 117 bugs in the code. Argh! I sometimes find a bug fixing a bug, but more often think of multiple possible improvement when implementing one. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Tue Aug 11 12:24:50 2020 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 11 Aug 2020 17:24:50 +0100 Subject: How to remove "" from starting of a string if provided by the user In-Reply-To: References: <5fca1bcc-3a49-55ef-5f7c-fa0fb0713df6@mrabarnett.plus.com> Message-ID: On 2020-08-11 02:20, Ganesh Pal wrote: > The possible value of stat['server2'] can be either (a) "'/fileno_100.txt'" or (b) '/fileno_100.txt' . > How do I check if it the value was? (a) i.e string started and ended with a quote , so that I can use ast.literal_eval() > >>> import ast > >>> stat = {} > >>> stat['server2']? = "'/fileno_100.txt'" > >>> stat['server2'] = ast.literal_eval(stat['server2']) > >>> print? stat['server2'] > /fileno_100.txt > >>> > >>> if stat['server2'].startswith("\"") and stat['server2'].endswith("\""): > ...??? stat['server2'] = ast.literal_eval(stat['server2']) > ... > >>> > I tried startswith() and endswith(), doesn't seem to work ?. Is there a simpler way ? > I gave 2 possible solutions. Try the first one, which was to use the .strip method to remove the quotes. The reason that startswith and endwith don't seem to work is that you're checking for the presence of " (double quote) characters, but, according to what you've posted, the strings contain ' (single quote) characters. [snip] From joel.goldstick at gmail.com Tue Aug 11 14:17:39 2020 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Tue, 11 Aug 2020 14:17:39 -0400 Subject: How to remove "" from starting of a string if provided by the user In-Reply-To: References: <5fca1bcc-3a49-55ef-5f7c-fa0fb0713df6@mrabarnett.plus.com> Message-ID: On Tue, Aug 11, 2020 at 12:26 PM MRAB wrote: > > On 2020-08-11 02:20, Ganesh Pal wrote: > > The possible value of stat['server2'] can be either (a) > "'/fileno_100.txt'" or (b) '/fileno_100.txt' . > > How do I check if it the value was (a) i.e string started and ended > with a quote , so that I can use ast.literal_eval() > > >>> import ast > > >>> stat = {} > > >>> stat['server2'] = "'/fileno_100.txt'" > > >>> stat['server2'] = ast.literal_eval(stat['server2']) > > >>> print stat['server2'] > > /fileno_100.txt > > >>> > > >>> if stat['server2'].startswith("\"") and > stat['server2'].endswith("\""): > > ... stat['server2'] = ast.literal_eval(stat['server2']) > > ... > > >>> > > I tried startswith() and endswith(), doesn't seem to work ?. Is there > a simpler way ? > > > > I gave 2 possible solutions. Try the first one, which was to use the > .strip method to remove the quotes. > > The reason that startswith and endwith don't seem to work is that you're > checking for the presence of " (double quote) characters, but, according > to what you've posted, the strings contain ' (single quote) characters. > > [snip] > > -- > https://mail.python.org/mailman/listinfo/python-list I'm assuming that you don't want the string to start with single quote, doublequote, or the other way around. If you have that situation, strip the first and last characters: >>> s = "'Starts with double quote'" >>> s1 = '"Starts with single quote"' >>> if s[:1] == "'" or s[:1] == '"': ... s_stripped = s[1:-1] ... >>> s_stripped 'Starts with double quote' >>> if s1[:1] == "'" or s1[:1] == '"': ... s_stripped = s1[1:-1] ... >>> s_stripped 'Starts with single quote' >>> This assumes the quotes match at both ends of the string -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From bryan.gene.olson at gmail.com Tue Aug 11 14:16:22 2020 From: bryan.gene.olson at gmail.com (bryan.gene.olson at gmail.com) Date: Tue, 11 Aug 2020 11:16:22 -0700 (PDT) Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> Message-ID: Christian Seberino wrote: > A beginner I think could learn Lisp much faster than Python. For talented beginners, Lisp rocks much like Python, in that easy assignments are easy enough to implement. On the high end, Lisp rocks again: Lisp masters are astonishingly productive. In between, beyond pedagogical exercises but short of our Turing Award masterwork, Lisp's extreme flexibility has a significant down-side in violating the middle third of Python Zen (PEP 20) guiding principle: "There should be one -- and preferably only one -- obvious way to do it." Flexibility is good. In a programming language it's great, and Python is super flexible. Lisp is beyond. There are many Lisps, the big two of which are Common Lisp (CL) and Scheme. Common Lisp has been more industrially important, but Scheme out-Lisps CL. As we deal with Python's recent additions, such as "enum", the walrus operator, type hints, and async/await, I remain in awe of [call with current current continuation](https://en.wikipedia.org/wiki/Call-with-current-continuation), which in Scheme is abbreviated "call/cc". From akkana at shallowsky.com Tue Aug 11 15:31:43 2020 From: akkana at shallowsky.com (Akkana Peck) Date: Tue, 11 Aug 2020 13:31:43 -0600 Subject: How to remove "" from starting of a string if provided by the user In-Reply-To: References: <5fca1bcc-3a49-55ef-5f7c-fa0fb0713df6@mrabarnett.plus.com> Message-ID: <20200811193143.GA1922@shallowsky.com> > > On 2020-08-11 02:20, Ganesh Pal wrote: > > > How do I check if it the value was (a) i.e string started and ended > > > with a quote Of course the original question was simple and there have been lots of solutions given. But I find this comes up periodically, and I'm always leery of using something like line.replace("'", "").replace('"', '') because it gets not only quote pairs, but things like "unmatched quotes' or "it's a contraction". I was thinking shlex had something like this, but it doesn't (it can do the opposite, add quotation marks with appropriate escaping). So I did a little playing around with re.sub. At first I tried: line = re.sub('"([^"]*)"', "\\1", line) line = re.sub("'([^']*)'", "\\1", line) which works for simple cases, but it can't detect apostrophes properly, so it didn't work for one of my test strings, "This one's apostrophe is in a more 'difficult' place." (it sees the apostrophe as an open single quote, closes it before difficult, leaving the one after difficult as an apostrophe). Then I tried to use \b: line = re.sub('\\b"([^"]*)"\\b', "\\1", line) line = re.sub("\\b'([^']*)'\\b", "\\1", line) but punctuation isn't considered part of a word, so it didn't work right for strings like "some word." I decided that really, the important thing was that the open quote can't have an alphanumeric before it, and the end quote can't have an alphanumeric after it: line = re.sub('\W"([^"]*)"\W', "\\1", line) line = re.sub("\W'([^']*)'\W", "\\1", line) but no, that wasn't quite right since it didn't pick up quotes at the beginning or end, and it loses some spaces too. After some fiddling I ended up with line = re.sub('(^|\W)"([^"]*)"(\W|$)', "\\1\\2\\3", line) line = re.sub("(^|\W)'([^']*)'(\W|$)", "\\1\\2\\3", line) which seems to work pretty well. Any suggested improvements? I find this comes up now and then, so I'm going to keep this around in my library for times when I need it, and I'm sure there are cases I didn't think of. (And yes, I know this is overkill for the original poster's question, but when I need this I usually want something a little smarter.) I've appended my test program below. ...Akkana import re s = '''Here are some strings. "This string is quoted with double-quotes." "Same, except this time the end quote is inside the period". 'This one is quoted with singles.' "This has one of each and so shouldn't be changed. "This has 'single quotes' inside double quotes, and it's got an apostrophe too." "This one's apostrophe is in a more 'difficult' place." 'This has "double quotes" inside single quotes.' ''' def remquotes(line): """Remove pairs of single and/or double quotes from the string passed in. Try to preserve things that aren't quotes, like parentheses. """ line = re.sub('(^|\W)"([^"]*)"(\W|$)', "\\1\\2\\3", line) line = re.sub("(^|\W)'([^']*)'(\W|$)", "\\1\\2\\3", line) return line if __name__ == '__main__': for line in s.split('\n'): print(remquotes(line)) From bill at celestial.net Tue Aug 11 17:18:47 2020 From: bill at celestial.net (Bill Campbell) Date: Tue, 11 Aug 2020 14:18:47 -0700 Subject: How to remove "" from starting of a string if provided by the user In-Reply-To: References: <5fca1bcc-3a49-55ef-5f7c-fa0fb0713df6@mrabarnett.plus.com> Message-ID: <20200811211847.GA13352@hazlitt.celestial.com> On Tue, Aug 11, 2020, Ganesh Pal wrote: >The possible value of stat['server2'] can be either (a) >"'/fileno_100.txt'" or (b) '/fileno_100.txt' . def stripquotes(s): '''Strip leading single or double quotes to any depth''' import re pat = re.compile(r'^([\'"])(.*)(\1)$') slast = None while slast != s: slast = s s = pat.cub(r'\2', s) return s # end stripquotes(s) 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 Democracy is the theory that the common people know what they want and deserve to get it good and hard. == H.L. Mencken From lukasz at langa.pl Tue Aug 11 17:48:59 2020 From: lukasz at langa.pl (=?UTF-8?Q?=C5=81ukasz_Langa?=) Date: Tue, 11 Aug 2020 23:48:59 +0200 Subject: [RELEASE] Python 3.9.0rc1 is now available Message-ID: <77492cf8-0517-4598-9325-ea54ba558cc0@www.fastmail.com> Python 3.9.0 is *almost* ready. This release, *3.9.0rc1*, is the penultimate release preview. You can get it here: https://www.python.org/downloads/release/python-390rc1/ Entering the release candidate phase, only reviewed code changes which are clear bug fixes are allowed between this release candidate and the final release. The second candidate and the last planned release preview is currently planned for 2020-09-14. Please keep in mind that this is a preview release and its use is *not* recommended for production environments. Calls to action Core developers: all eyes on the docs now * Are all *your* changes properly documented? * Did you notice *other* changes you know of to have insufficient documentation? Community members We *strongly encourage* maintainers of third-party Python projects to prepare their projects for 3.9 compatibility during this phase. As always, report any issues to the Python bug tracker . Installer news This is the first version of Python to default to the 64-bit installer on Windows. The installer now also actively disallows installation on Windows 7. Python 3.9 is incompatible with this unsupported version of Windows. Major new features of the 3.9 series, compared to 3.8 Some of the new major new features and changes in Python 3.9 are: * PEP 584 , Union Operators in `dict` * PEP 585 , Type Hinting Generics In Standard Collections * PEP 593 , Flexible function and variable annotations * PEP 602 , Python adopts a stable annual release cadence * PEP 615 , Support for the IANA Time Zone Database in the Standard Library * PEP 616 , String methods to remove prefixes and suffixes * PEP 617 , New PEG parser for CPython * BPO 38379 , garbage collection does not block on resurrected objects; * BPO 38692 , os.pidfd_open added that allows process management without races and signals; * BPO 39926 , Unicode support updated to version 13.0.0; * BPO 1635741 , when Python is initialized multiple times in the same process, it does not leak memory anymore; * A number of Python builtins (range, tuple, set, frozenset, list, dict) are now sped up using PEP 590 vectorcall; * A number of Python modules (_abc, audioop, _bz2, _codecs, _contextvars, _crypt, _functools, _json, _locale, operator, resource, time, _weakref) now use multiphase initialization as defined by PEP 489 ; * A number of standard library modules (audioop, ast, grp, _hashlib, pwd, _posixsubprocess, random, select, struct, termios, zlib) are now using the stable ABI defined by PEP 384 . From tjreedy at udel.edu Tue Aug 11 15:50:58 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 11 Aug 2020 15:50:58 -0400 Subject: IDLE: New Feature? In-Reply-To: <000d01d66fb9$24170690$6c4513b0$@SGA.Ninja> References: <000001d66ea6$4b943940$e2bcabc0$@SGA.Ninja> <000d01d66fb9$24170690$6c4513b0$@SGA.Ninja> Message-ID: On 8/11/2020 4:26 AM, Steve wrote: > << Simplest specification: > << one list for all 3 search boxes; > << start fresh each session > > I do not understand what this means... A proposed feature needs a specification with sufficient details to code and review. Your proposal "a pull-down history list for Find' is too general." This is typical of proposals, especially for IDLE it seems. Should there be a list only for Find and not for Find/Replace and Find in Files? Makes no sense. A separate list for each? What if you start with Find and then realize you want to replace? Or find in the current file and realize that you want to find in multiple files. I would want one list so I could transfer search terms. (Another solution would be to link the boxes so one can transfer directly.) How long is history kept? Forever across sessions, or just for one session? The latter is much easier. -- Terry Jan Reedy From claytilvan at gmail.com Tue Aug 11 05:27:19 2020 From: claytilvan at gmail.com (Lim Clayton) Date: Tue, 11 Aug 2020 17:27:19 +0800 Subject: Unable to save any files Message-ID: Hi, I am a relatively new Python User. I recently downloaded Python on my desktop and I am unable to save anything when I use IDLE. I can run codes on the shell without any issue but running anything on the window which requires saving causes nothing to happen. I still get the prompt which says you need to save before the code can be run but nothing happens when I press Ok. I am using Windows 10 and I have tried uninstalling and reinstalling. Any advice? Yours Sincerely, Clay From lele at metapensiero.it Tue Aug 11 02:39:51 2020 From: lele at metapensiero.it (Lele Gaifax) Date: Tue, 11 Aug 2020 08:39:51 +0200 Subject: Strange namespace issue References: <87k0y6gx5t.fsf@metapensiero.it> Message-ID: <87h7t9n0so.fsf@metapensiero.it> Chris Angelico writes: > Interesting. You're passing an empty globals and a non-empty locals > (the second and third arguments to exec, respectively). Is that > deliberate? By the look of this code, it's meant to be at global scope > (as if it's the top level code in a module), which is best done by > passing just a single dict to exec (it'll be both globals and locals). > > The reason your first block works but the comprehensions don't is that > comprehensions act in a nested scope. I think you've hit on a curious > edge case where empty globals results in strange behaviour. > > I tried your code with the empty dict removed and it appears to work, > but if you had a good reason for having separate dicts, that might > break. Thank you Chris, yes, you are right and indeed passing the external context in the "globals" argument *AND* omitting the "locals" one I get the expected outcome, and yes, I'm surprised, the snake still bites sometime, after several dozens of years :) However, I'm still unclear on *when* it is safe & useful to pass the third argument to exec(): while in the particular case I was working it does not make any difference (passing the context in the second "globals" argument, that is), in at least one other case I am relying on the fact that passing the third argument the script "stores" there whatever it defines, and the caller examines that to make some further decision. In other words, something like this: script = """\ def function_a(): return ['a' * repetitions] def function_b(): return [['a'] * repetitions] precomputed = repetitions ** 10 def function_c(): return precomputed """ code = compile(script, 'script', 'exec') globs = {'repetitions': 3} locs = {} exec(code, globs, locs) for n in locs: print(f"Oh, you defined {n!r}...") v = locs[n] if callable(v): print(" a callable, returning", v()) else: print(" a value,", v) In this case, it would be less practical to determine what the script defined: by any chance this case is the first I wrote, and here the choice to pass the third argument was surely "deliberate". But I see this is somewhat fragile, and wonder about a proper fix, but isn't that a reasonable usage of the "locals" argument to exec()? Ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From rosuav at gmail.com Tue Aug 11 22:27:14 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 12 Aug 2020 12:27:14 +1000 Subject: Strange namespace issue In-Reply-To: <87h7t9n0so.fsf@metapensiero.it> References: <87k0y6gx5t.fsf@metapensiero.it> <87h7t9n0so.fsf@metapensiero.it> Message-ID: On Wed, Aug 12, 2020 at 12:03 PM Lele Gaifax wrote: > But I see this is somewhat fragile, and wonder about a proper fix, but isn't > that a reasonable usage of the "locals" argument to exec()? > I'm not sure. Passing a locals argument to eval() I have sometimes done, but never exec(). I've always exec'd code at top level and then extracted something from globals - it seems the easiest. ChrisA From PythonList at DancesWithMice.info Tue Aug 11 23:59:16 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 12 Aug 2020 15:59:16 +1200 Subject: Unable to save any files In-Reply-To: References: Message-ID: <69bb32a7-aed2-d885-4873-e27a71328582@DancesWithMice.info> On 11/08/2020 21:27, Lim Clayton wrote: > Hi, > > I am a relatively new Python User. I recently downloaded Python on my > desktop and I am unable to save anything when I use IDLE. I can run codes > on the shell without any issue but running anything on the window which > requires saving causes nothing to happen. I still get the prompt which says > you need to save before the code can be run but nothing happens when I > press Ok. I am using Windows 10 and I have tried uninstalling and > reinstalling. Any advice? When saving the code, which folder is being used? What does the File Explorer show? -- Regards =dn From tjreedy at udel.edu Tue Aug 11 22:35:11 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 11 Aug 2020 22:35:11 -0400 Subject: Unable to save any files In-Reply-To: References: Message-ID: On 8/11/2020 5:27 AM, Lim Clayton wrote: > I am a relatively new Python User. I recently downloaded Python on my > desktop and I am unable to save anything when I use IDLE. I can run codes > on the shell without any issue but running anything on the window which > requires saving causes nothing to happen. I still get the prompt which says > you need to save before the code can be run but nothing happens when I > press Ok. I am using Windows 10 and I have tried uninstalling and > reinstalling. Any advice? There are two possible reasons in 3.8.4 and 3.9.0b4 - non-ascii characters and files created outside of IDLE. Non-ascii chars was fixed in 3.8.5 and 3.9.0b5. Files created outside of IDLE work in 3.8.6, due in September and 3.9.0rc1, released today. If you do not need 3rd party modules, use the latter. If you do, create new files within IDLE with File=> New. -- Terry Jan Reedy From python at mrabarnett.plus.com Wed Aug 12 11:53:27 2020 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 12 Aug 2020 16:53:27 +0100 Subject: How to remove "" from starting of a string if provided by the user In-Reply-To: References: <5fca1bcc-3a49-55ef-5f7c-fa0fb0713df6@mrabarnett.plus.com> Message-ID: <852c7f02-f6a8-38b4-e919-cbc2d165f4fe@mrabarnett.plus.com> On 2020-08-11 20:43, Dennis Lee Bieber wrote: > On Tue, 11 Aug 2020 14:17:39 -0400, Joel Goldstick > declaimed the following: > [snip] > Warning -- it will fail if the input is just a pair of quotes or pair of > apostrophes -- improvement is > >>>> while s and s[0] in ['"', "'"]: > ... if s[0] == s[-1]: > ... s = s[1:-1] > If the 'if' condition is False, then 's' will remain unchanged, and it will loop forever. I would suggest: >>> while s[ : 1] in {'"', "'"} and s[ : 1] == s[-1 : ]: ... s = s[1 : -1] From m at funkyhat.org Wed Aug 12 21:38:48 2020 From: m at funkyhat.org (Matt Wheeler) Date: Thu, 13 Aug 2020 01:38:48 +0000 (UTC) Subject: How to remove "" from starting of a string if provided by the user In-Reply-To: References: <5fca1bcc-3a49-55ef-5f7c-fa0fb0713df6@mrabarnett.plus.com> Message-ID: On Tue, 11 Aug 2020, 02:20 Ganesh Pal, wrote: > The possible value of stat['server2'] can be either (a) > "'/fileno_100.txt'" or (b) '/fileno_100.txt' . > > How do I check if it the value was (a) i.e string started and ended > with a quote , so that I can use ast.literal_eval() > BAFP > def maybe_unquote(string): try: return ast.literal_eval(string) except ValueError: return string From storchaka at gmail.com Thu Aug 13 02:28:04 2020 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 13 Aug 2020 09:28:04 +0300 Subject: How to remove "" from starting of a string if provided by the user In-Reply-To: <852c7f02-f6a8-38b4-e919-cbc2d165f4fe@mrabarnett.plus.com> References: <5fca1bcc-3a49-55ef-5f7c-fa0fb0713df6@mrabarnett.plus.com> <852c7f02-f6a8-38b4-e919-cbc2d165f4fe@mrabarnett.plus.com> Message-ID: 12.08.20 18:53, MRAB ????: > I would suggest: > >>>> while s[ : 1] in {'"', "'"} and s[ : 1] == s[-1 : ]: > ...???? s = s[1 : -1] And the condition can be written as s[ : 1] == s[-1 : ] in {'"', "'"} or more efficiently as s and s[0] == s[-1] in '\'"' From rashtyda at gmail.com Thu Aug 13 03:04:32 2020 From: rashtyda at gmail.com (David Rashty) Date: Thu, 13 Aug 2020 00:04:32 -0700 (PDT) Subject: Proposal: SimpleNamespace "recursive" parameter Message-ID: <3d234ca2-e149-4502-9c98-d6284587e370n@googlegroups.com> It would be nice if you could do this to create a "nested" SimpleNamespace: >>> d = {"_meta": {"fields": ({"name": "field0"}, {"name": "field1"})}} >>> sns = SimpleNamespace(**d) >>> print(sns._meta.fields[0].name) # This is what I wish you could do 'field0' SimpleNamespace does this though: >>> d = {"_meta": {"fields": ({"name": "field0"}, {"name": "field1"})}} >>> sns = SimpleNamespace(**d) >>> print(sns._meta) # Python 3.8 {"fields": ({"name": "field0"}, {"name": "field1"})} I'd love to add a "recursive" parameter to SimpleNamespace to do as above i.e., >>> d = {"_meta": {"fields": ({"name": "field0"}, {"name": "field1"})}} >>> sns = SimpleNamespace(recursive=True, **d) >>> print(sns._meta.fields[0].name) # Proposal 'field0' My current use case is to mock out a Django model in a more straightforward fashion than using unittest.mock.Mock. Does anyone else here think this is a good idea? Refs: https://gist.github.com/pandichef/d3cc137036a7be0c29e9afb27bfbf55e https://stackoverflow.com/questions/38034377/object-like-attribute-access-for-nested-dictionary/63389458#63389458 https://greenash.net.au/thoughts/2017/08/using-pythons-namedtuple-for-mock-objects-in-tests/ From mal at europython.eu Thu Aug 13 09:44:41 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 13 Aug 2020 15:44:41 +0200 Subject: EuroPython 2020: Live Stream Recordings available Message-ID: We?re happy to announce the public availability of the live stream recordings from EuroPython 2020. They were already available to all conference attendees since the sprint days. * EuroPython YouTube Channel * http://europython.tv/ We have collected the videos in a EuroPython 2020 Live Stream playlist: https://www.youtube.com/playlist?list=PL8uoeex94UhG33fVP7GZEo06gOHlhb0hk Unedited Videos --------------- What we are releasing today are unedited videos recorded for the main track rooms and days. The poster track recordings will be added today or tomorrow. You can use the schedule to navigate the videos. Linking to a specific time in the videos can be done by right-clicking in the video to create a URL which points to the current position. Feel free to share interesting links on social media. Edited Videos ------------- Our video editing company is already busy creating the cut videos. Those should be ready in a month or two. 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/post/626322517228961792/europython-2020-live-stream-recordings-available Tweet: https://twitter.com/europython/status/1293828734143864833 Thanks, -- EuroPython 2020 Team https://ep2020.europython.eu/ https://www.europython-society.org/ From mal at europython.eu Thu Aug 13 10:38:39 2020 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 13 Aug 2020 16:38:39 +0200 Subject: Spam, bacon, sausage and Spam (was: EuroPython 2020: Data Science Track) In-Reply-To: References: <9d6bdb49-c416-67ae-0110-fe1b77269f59@europython.eu> Message-ID: On 22.07.2020 15:00, Christian Heimes wrote: > Hi MAL, > > would it be possible to reduce the amount of EuroPython spam on > @python.org mailing lists to a sensible level? This mailing list is a > general discussion list for the Python programming language. It's not a > conference advertisement list. > > Something between 1 to 3 mails per conference and year (!) sounds > sensible to me. You have posted 21 new threads about EP 2020 since > January on this list, thereof 5 threads this month. In comparison I > could only find two ads for other conferences in the last 12 month > (FlaskCon, PyCon TZ). Hi Christian, as you probably know, EuroPython is a community effort, run entirely by volunteers with no commercial interests. Since c.l.p, as well as other general purpose Python community lists, are places where we can reach out to the community we're working for, it's a natural target for our conference communication. We are perfectly aware that our emails are not necessarily interesting for everyone, but then you have the same problem with many topics on these general purpose mailing lists. The standard way to approach this is to simply ignore the postings, filter them out or silence them. It's obvious from your emails and tweets that you don't like our emails and that's fair. Everyone is entitled to their own opinion. However, we are running the conference for a large community and so have to compromise between people such as you who don't like getting our emails and the thousands of people who do. When you run community events, you have to learn that you can never make everyone happy - even though we try hard and I believe we have a good track record of at least making most people happy :-) Regarding filtering, almost all of our emails carry "EuroPython" in their subject line and we usually use a europython.eu email address as sender. In fact, most emails are sent by me, since I the one in charge of preparing and sending them, so you can easily filter them out. In terms of volume, I don't regard the 24 messages I have sent this year anywhere near a level which can be considered spam based on volume, given that the list has received 3300+ messages this year. Again, you may have a different opinion and that's perfectly fine. We can agree to disagree on this. FWIW: I would like to see a lot more conference communication from the many Python events around the world go to this and other lists. People new to Python generally have a hard time finding out what's going on in Python land - one of the reasons I started the Python events calendar project, for example: https://www.python.org/events/ https://wiki.python.org/moin/PythonEventsCalendar The Python conferences and meetups are a central part of the Python community and should get more awareness rather than less. Thanks, -- Marc-Andre Lemburg EuroPython Society Chair http://www.europython-society.org/ http://www.malemburg.com/ From Marco.Sulla.Python at gmail.com Thu Aug 13 17:19:18 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Thu, 13 Aug 2020 23:19:18 +0200 Subject: [Python-ideas] Universal set In-Reply-To: References: Message-ID: assert(The set that contains everything is God) Compile with -OO On Mon, 10 Aug 2020 at 13:23, haael wrote: > > > Forgive me if this has already been discussed. > > > Could we add the idea of "negative" sets to Python? That means sets that > contain EVERYTHING EXCEPT certain elements. > > > First, let's have a universal set that contains everything. > > assert element in set.UNIVERSAL > > The universal set is a superset of every other set. > > assert set.UNIVERSAL >= any_set > > Adding anything to universal set doesn't change anything. > > assert set.UNIVERSAL | element == set.UNIVERSAL > > However REMOVING an element from the set puts it on "negative list". > > myset = set.UNIVERSAL > myset.remove(element) > assert element not in myset > > Intersection of a "negative set" with a normal set gives again a normal > set. Union of two negative sets, or a negative set with a normal set, > gives a negative set. > > The main issue: negative sets would not be iterable, but you can > intersect them with the desired subdomain and iterate over. > _______________________________________________ > Python-ideas mailing list -- python-ideas at python.org > To unsubscribe send an email to python-ideas-leave at python.org > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at https://mail.python.org/archives/list/python-ideas at python.org/message/MY77JS226XWLV7FGTS4KRSWPI45VB64I/ > Code of Conduct: http://python.org/psf/codeofconduct/ From tjreedy at udel.edu Thu Aug 13 12:24:49 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 13 Aug 2020 12:24:49 -0400 Subject: EuroPython 2020: Live Stream Recordings available In-Reply-To: References: Message-ID: On 8/13/2020 9:44 AM, M.-A. Lemburg wrote: > We?re happy to announce the public availability of the live stream > recordings from EuroPython 2020. They were already available to all > conference attendees since the sprint days. > > * EuroPython YouTube Channel * > > http://europython.tv/ This http url, blocked by HTTPS Anywhere, just forwards to https://www.youtube.com/c/EuroPythonConference > We have collected the videos in a EuroPython 2020 Live Stream > playlist: > > https://www.youtube.com/playlist?list=PL8uoeex94UhG33fVP7GZEo06gOHlhb0hk A better (more useful) version of the listing. > Unedited Videos > --------------- > > What we are releasing today are unedited videos recorded for the main > track rooms and days. IE, each is a 2-12 hour recording with multiple sessions. So subtract session start time from talk time to get approximate time index, taking into account that cumulative overtimes increase actual start times. > The poster track recordings will be added today or > tomorrow. > You can use the schedule to navigate the videos. https://ep2020.europython.eu/schedule/ I look forward to the edited videos sliced into individual talks. But I already found and watched a talk that interested me. Thank you for making them available. -- Terry Jan Reedy From alexandra_mel.1981 at hotmail.es Thu Aug 13 16:31:48 2020 From: alexandra_mel.1981 at hotmail.es (=?iso-8859-1?Q?Alexa_O=F1a?=) Date: Thu, 13 Aug 2020 20:31:48 +0000 Subject: Support In-Reply-To: References: Message-ID: Helo, I am already subscribed. ________________________________ I De: Alexa O?a Enviado: jueves, 13 de agosto de 2020 18:51 Para: python-list at python.org Asunto: Support Hello, I am Alexa I have tried to install PYTHON 3.8.5, but could not install it on my computer. I would like to receive help since always when installing and opening, it indicates the same page. Thank you. [cid:3ec428e5-972d-4111-852c-acb78f40d91d][cid:d848c116-7d18-47e8-9b58-3ff3530038e2][cid:2317bb77-b7d9-4a20-8aaa-20d3aed62d7b] From PythonList at DancesWithMice.info Thu Aug 13 18:42:51 2020 From: PythonList at DancesWithMice.info (dn) Date: Fri, 14 Aug 2020 10:42:51 +1200 Subject: Support In-Reply-To: References: Message-ID: On 14/08/2020 08:31, Alexa O?a wrote: > Helo, I am already subscribed. > ________________________________ > I > De: Alexa O?a > Enviado: jueves, 13 de agosto de 2020 18:51 > Para: python-list at python.org > Asunto: Support > > Hello, I am Alexa > I have tried to install PYTHON 3.8.5, but could not install it on my computer. I would like to receive help since always when installing and opening, it indicates the same page. Hol?, Yes, your message has been received. Please advise which operating system is used on your computer, and the download source you have been using. -- Regards =dn From ikorot01 at gmail.com Thu Aug 13 19:11:33 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Thu, 13 Aug 2020 18:11:33 -0500 Subject: Support In-Reply-To: References: Message-ID: Hi, On Thu, Aug 13, 2020 at 5:46 PM dn via Python-list wrote: > > On 14/08/2020 08:31, Alexa O?a wrote: > > Helo, I am already subscribed. > > ________________________________ > > I > > De: Alexa O?a > > Enviado: jueves, 13 de agosto de 2020 18:51 > > Para: python-list at python.org > > Asunto: Support > > > > Hello, I am Alexa > > I have tried to install PYTHON 3.8.5, but could not install it on my computer. I would like to receive help since always when installing and opening, it indicates the same page. Also, please include the exact error message you are receiving during the install. Thank you. > > > Hol?, > > Yes, your message has been received. > > Please advise which operating system is used on your computer, and the > download source you have been using. > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list From PythonList at DancesWithMice.info Fri Aug 14 00:29:18 2020 From: PythonList at DancesWithMice.info (dn) Date: Fri, 14 Aug 2020 16:29:18 +1200 Subject: Whitespace not/required Message-ID: Although many new-comers are intrigued by the compulsory indentation rule, I have been surprised to discover that even though whitespace does not usually feature as a formatting-specification, nevertheless Python sometimes requires an absence of whitespace. Will this behavior/requirement continue when using (a pre-release version featuring) the new parser? Whitespace has meaning to us - when it comes to indentation defining (not merely illustrating) blocks of code. However, the rest of the time, it is ignored by Python. (yes, this discussion disdains comments!) For example, whitespace is no problem when it comes to defining a list: month_names = ['Januari', 'Februari', 'Maart', # These are the 'April', 'Mei', 'Juni', # Dutch names... Similarly, a totally blank line will be equally-totally ignored. As my eye-sight ages (it's older than my teeth!), I find code easier to read when there is more whitespace - and it becomes more difficult to parse when whitespace is omitted. For example, I receive regular comments/criticisms for writing an argument list with spaces inside the parentheses, eg def func( arg1, arg2, ): Whilst there are some 'standards' which decry such practice, I note that many IDEs will offer to add such spaces, auto-magically, as a config/option. So, apparently I'm not unique - just 'special'? I don't use 'back-slash continuity' very often (at the expense of more parens!), and was intrigued to discover in experiments; that not only is a space before the back-slash considered optional, but sometimes a space is not necessary at all, eg >>> if\ ... True: print( 'yes' ) ... yes >>> ifTrue: print( 'yes' ) yes although Python won't let me go-crazy: >>> if True andFalse: print( 'yes' ) File "", line 1 if True andFalse: print( 'yes' ) ^ SyntaxError: invalid syntax >>> if Tr\ ... ue: print( 'yes' ) File "", line 2 if Tr\ ue: print( 'yes' ) ^ SyntaxError: invalid syntax The legal statement: <<<2.1.9. Whitespace between tokens Except at the beginning of a logical line or in string literals, the whitespace characters space, tab and formfeed can be used interchangeably to separate tokens. Whitespace is needed between two tokens only if their concatenation could otherwise be interpreted as a different token (e.g., ab is one token, but a b is two tokens).>>> Thus, (a little later on the same page): <<>> Thus, it must be expressed as "b'bytes'" and not "b 'bytes'". Admittedly, such separation hadn't occurred to me, in much the same way that "print ()" doesn't seem correct, but... When we break the language-elements into "tokens" the 'bytes' and the argument-list's parentheses are separate from the preceding "b" or function-name, albeit semantically inseparable. For f-strings/formatted string literals, the most usual form is: "{" f_expression ["="] ["!" conversion] [":" format_spec] "}" Remembering that this is BNF, see the space separating the closing-brace from anything preceding it - how else would we separate the components to comprehend? Returning to Python: >>> one = 1 # is the loneliest number... >>> f'{ one }' '1' >>> f'{ one:03 }' Traceback (most recent call last): File "", line 1, in ValueError: Unknown format code '\x20' for object of type 'int' >>> f'{ one:03}' '001' Notice the presence/absence of the final space. >>> pi = 3.14159 # better to import math >>> f'{ pi!r:10 }' Traceback (most recent call last): File "", line 1, in ValueError: Unknown format code '\x20' for object of type 'str' >>> f'{ pi!r:10}' '3.14159 ' >>> f'{ pi!r }' File "", line 1 SyntaxError: f-string: expecting '}' >>> f'{ pi!r}' '3.14159' So, the f-string will work if the braces include only an expression surrounded by spaces. However, if one adds a conversion or format-specification, that final space becomes a no-no. Eh what! To be fair, the 'book of words' does say: "A replacement field ends with a closing curly bracket '}'.". No mention of whitespace. No mention that a replacement field consisting only of an f_expression, will be treated differently by allowing a space. Version 3.8 introduced the "=" short-cut: >>> f"{ foo = }" # preserves whitespace " foo = 'bar'" Note the comment! Yet, the manual's examples continue: >>> line = "The mill's closed" >>> f"{line = }" 'line = "The mill\'s closed"' >>> f"{line = :20}" "line = The mill's closed " Hey, why does this second example dispense with the braces-internal spaces? Sure enough, when I check it for myself: >>> line = "The mill's closed" >>> f'{line = :20 }' Traceback (most recent call last): File "", line 1, in ValueError: Unknown format code '\x20' for object of type 'str' >>> f'{ line = :20}' " line = The mill's closed " >>> f'{line = :20}' "line = The mill's closed " Should the closing brace be considered part of a conversion or format-specification? The space (I'd like to add) cannot be considered part of a conversion or format-specification (see BNF, see text of web.ref)! (when you compare how long it took me to (speed) type this message, and how long it took me to figure-out that my 'excess space' was causing a fault in an f-string, the time-cost was about the same. Grrr! (the relative frustrations-caused, somewhat different!) Will be interested in explanations, and improvements to understanding. (but not so much in 'corrections' to my (mis-)behavior - I already pay that price!) If you're operating at the 'bleeding edge', will be interested to hear how the 'new parser' handles same. Web.Ref: https://docs.python.org/3/reference/lexical_analysis.html -- Regards, =dn From Marco.Sulla.Python at gmail.com Fri Aug 14 00:39:58 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Fri, 14 Aug 2020 06:39:58 +0200 Subject: Proposal: SimpleNamespace "recursive" parameter In-Reply-To: <3d234ca2-e149-4502-9c98-d6284587e370n@googlegroups.com> References: <3d234ca2-e149-4502-9c98-d6284587e370n@googlegroups.com> Message-ID: This seems to work: from types import SimpleNamespace from collections.abc import Iterable def isIterableNotStr(arg): return isinstance(arg, Iterable) and not isinstance(arg, str) class DeepNamespace(SimpleNamespace): def namespacesFromIterable(self, arg): vals = [] changed = False for x in arg: not_iterable = True try: x.items value = type(self)(**x) changed = True not_iterable = False except AttributeError: if isIterableNotStr(x): value = self.namespacesFromIterable(x) changed = True not_iterable = False if not_iterable: value = x vals.append(value) if changed: return tuple(vals) return arg def __init__(self, **kwargs): super().__init__(**kwargs) for k, v in kwargs.items(): try: v.items except AttributeError: if isIterableNotStr(v): self.__setattr__(k, self.namespacesFromIterable(v)) else: self.__setattr__(k, type(self)(**v)) Notice that if the dict contains at any level an iterable that is not a string or a dict-like object, this is converted to a tuple. Probably there's a smarter way to maintain the original iterable type. From antoon.pardon at rece.vub.ac.be Fri Aug 14 06:32:27 2020 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Fri, 14 Aug 2020 12:32:27 +0200 Subject: How to install your personal module/package on site. Message-ID: <7bfe70aa-1a7f-c810-fc00-60b284ad7e72@rece.vub.ac.be> Well the question is in the subject. I have a number of modules/packages which were until recently personal use only. However python is getting more popular at work and some of my work was considered useful enough to install in a public available spot. How should I approach this? -- Antoon. From Marco.Sulla.Python at gmail.com Fri Aug 14 15:01:30 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Fri, 14 Aug 2020 21:01:30 +0200 Subject: How to install your personal module/package on site. In-Reply-To: <7bfe70aa-1a7f-c810-fc00-60b284ad7e72@rece.vub.ac.be> References: <7bfe70aa-1a7f-c810-fc00-60b284ad7e72@rece.vub.ac.be> Message-ID: https://www.google.com/search?channel=fs&client=ubuntu&q=publish+python+code First result. From PythonList at DancesWithMice.info Sat Aug 15 01:33:34 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 15 Aug 2020 17:33:34 +1200 Subject: How to install your personal module/package on site. In-Reply-To: <7bfe70aa-1a7f-c810-fc00-60b284ad7e72@rece.vub.ac.be> References: <7bfe70aa-1a7f-c810-fc00-60b284ad7e72@rece.vub.ac.be> Message-ID: <7987a5e5-167d-f49a-3f56-79542f979402@DancesWithMice.info> On 14/08/2020 22:32, Antoon Pardon wrote: > Well the question is in the subject. > > I have a number of modules/packages which were until recently > personal use only. However python is getting more popular > at work and some of my work was considered useful enough to > install in a public available spot. > > How should I approach this? Does the word "public" mean world-wide, or perhaps only amongst your work-colleagues? -- Regards =dn From ml_news at posteo.de Sat Aug 15 01:23:42 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Sat, 15 Aug 2020 07:23:42 +0200 Subject: try..except or type() or isinstance()? Message-ID: <20200815072342.143c8723@arcor.com> I have an object which I could initialize providind an int or a str. I am not sure which of the following is best to use - try/except - if type(int)... - if isinstance(v, int) Here a minimal example def get_id(fromname): # do something with `fromname` return 0 def get_name(fromid): # do something with `fromid` return "something" """ For O1, O2, O3: self.myid is int self.name is str """ class O1: def __init__(self, val): try: self.myid = int(val) self.name = get_name(self.myid) except: self.myid = get_id(val) self.name = val class O2: def __init__(self, val): if type(val) == int: self.myid = val self.name = get_name(self.myid) else: self.myid = get_id(val) self.name = val class O3: def __init__(self, val): if isinstance(val, int): self.myid = val self.name = get_name(self.myid) else: self.myid = get_id(val) self.name = val -- Manfred From rosuav at gmail.com Sat Aug 15 02:15:29 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 15 Aug 2020 16:15:29 +1000 Subject: try..except or type() or isinstance()? In-Reply-To: <20200815072342.143c8723@arcor.com> References: <20200815072342.143c8723@arcor.com> Message-ID: On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz wrote: > > I have an object which I could initialize providind an int or a str. > > I am not sure which of the following is best to use > - try/except > - if type(int)... > - if isinstance(v, int) > > Here a minimal example > > def get_id(fromname): > # do something with `fromname` > return 0 > > def get_name(fromid): > # do something with `fromid` > return "something" > > """ For O1, O2, O3: self.myid is int > self.name is str > """ > class O1: > def __init__(self, val): > try: > self.myid = int(val) > self.name = get_name(self.myid) > except: > self.myid = get_id(val) > self.name = val Don't use a bare "except" - use "except ValueError" instead. But otherwise, this is a perfectly reasonable way to say "anything that can be interpreted as an integer will be". > class O2: > def __init__(self, val): > if type(val) == int: > self.myid = val > self.name = get_name(self.myid) > else: > self.myid = get_id(val) > self.name = val Nope, don't do this. It's strictly worse than O3. > class O3: > def __init__(self, val): > if isinstance(val, int): > self.myid = val > self.name = get_name(self.myid) > else: > self.myid = get_id(val) > self.name = val This is a perfectly reasonable way to say "integers will be treated as IDs". Note that O1 and O3 are very different semantically; O1 will treat the string "7" as an ID, but O3 will treat it as a name. Here's an even better way: class O4: def __init__(self, id): self.myid = id self.name = get_name(id) @classmethod def from_name(cls, name): return cls(get_id(name)) This makes the ID the main way you'd do things, and a name lookup as an alternate constructor. Very good pattern, reliable, easy to use. ChrisA From __peter__ at web.de Sat Aug 15 02:33:58 2020 From: __peter__ at web.de (Peter Otten) Date: Sat, 15 Aug 2020 08:33:58 +0200 Subject: try..except or type() or isinstance()? References: <20200815072342.143c8723@arcor.com> Message-ID: Chris Angelico wrote: > On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz wrote: >> >> I have an object which I could initialize providind an int or a str. >> >> I am not sure which of the following is best to use >> - try/except >> - if type(int)... >> - if isinstance(v, int) >> >> Here a minimal example >> >> def get_id(fromname): >> # do something with `fromname` >> return 0 >> >> def get_name(fromid): >> # do something with `fromid` >> return "something" >> >> """ For O1, O2, O3: self.myid is int >> self.name is str >> """ >> class O1: >> def __init__(self, val): >> try: >> self.myid = int(val) >> self.name = get_name(self.myid) >> except: >> self.myid = get_id(val) >> self.name = val > > Don't use a bare "except" - use "except ValueError" instead. But > otherwise, this is a perfectly reasonable way to say "anything that > can be interpreted as an integer will be". > >> class O2: >> def __init__(self, val): >> if type(val) == int: >> self.myid = val >> self.name = get_name(self.myid) >> else: >> self.myid = get_id(val) >> self.name = val > > Nope, don't do this. It's strictly worse than O3. > >> class O3: >> def __init__(self, val): >> if isinstance(val, int): >> self.myid = val >> self.name = get_name(self.myid) >> else: >> self.myid = get_id(val) >> self.name = val > > This is a perfectly reasonable way to say "integers will be treated as > IDs". Note that O1 and O3 are very different semantically; O1 will > treat the string "7" as an ID, but O3 will treat it as a name. > > Here's an even better way: > > class O4: > def __init__(self, id): > self.myid = id > self.name = get_name(id) > @classmethod > def from_name(cls, name): > return cls(get_id(name)) > > This makes the ID the main way you'd do things, and a name lookup as > an alternate constructor. Very good pattern, reliable, easy to use. Yet another way: keyword arguments: class O5: def __init__(self, *, id=None, name=None): if name is None: assert id is not None name = get_name(id) else: assert id is None id = get_id(name) self.id = id self.name = name From ml_news at posteo.de Sat Aug 15 04:14:58 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Sat, 15 Aug 2020 10:14:58 +0200 Subject: try..except or type() or isinstance()? References: <20200815072342.143c8723@arcor.com> Message-ID: <20200815101458.7e4ead91@arcor.com> Hi Chris, Thanks a lot for you advice. On Sat, 15 Aug 2020 16:15:29 +1000 Chris Angelico wrote: > On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz > wrote: > > > > I have an object which I could initialize providind an int or a str. > > > > I am not sure which of the following is best to use > > - try/except > > - if type(int)... > > - if isinstance(v, int) > > > > Here a minimal example > > > > def get_id(fromname): > > # do something with `fromname` > > return 0 > > > > def get_name(fromid): > > # do something with `fromid` > > return "something" > > > > """ For O1, O2, O3: self.myid is int > > self.name is str > > """ > > class O1: > > def __init__(self, val): > > try: > > self.myid = int(val) > > self.name = get_name(self.myid) > > except: > > self.myid = get_id(val) > > self.name = val > > Don't use a bare "except" - use "except ValueError" instead. Oops, yes. You are right, of course. > But > otherwise, this is a perfectly reasonable way to say "anything that > can be interpreted as an integer will be". > > > class O2: > > def __init__(self, val): > > if type(val) == int: > > self.myid = val > > self.name = get_name(self.myid) > > else: > > self.myid = get_id(val) > > self.name = val > > Nope, don't do this. It's strictly worse than O3. > Aaa ok. I think in this particular case it would be ok but in general it might be bad if val would be a class object. So, I take your advice to avoid this in general as then I avoid errors in more complicated situations when using type(..). > > class O3: > > def __init__(self, val): > > if isinstance(val, int): > > self.myid = val > > self.name = get_name(self.myid) > > else: > > self.myid = get_id(val) > > self.name = val > > This is a perfectly reasonable way to say "integers will be treated as > IDs". Note that O1 and O3 are very different semantically; O1 will > treat the string "7" as an ID, but O3 will treat it as a name. > > Here's an even better way: > > class O4: > def __init__(self, id): > self.myid = id > self.name = get_name(id) > @classmethod > def from_name(cls, name): > return cls(get_id(name)) > > This makes the ID the main way you'd do things, and a name lookup as > an alternate constructor. Very good pattern, reliable, easy to use. > For my use case I don't like this solution as I get the value which could be an int or str from a file. Means I would have to check the type beforehand in order to know if I have to do O4(val) or O4.from_name(val). Otherwise, it is admittedly a very good pattern. -- Manfred From ml_news at posteo.de Sat Aug 15 04:16:32 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Sat, 15 Aug 2020 10:16:32 +0200 Subject: try..except or type() or isinstance()? References: <20200815072342.143c8723@arcor.com> Message-ID: <20200815101632.4c23cc48@arcor.com> On Sat, 15 Aug 2020 08:33:58 +0200 Peter Otten <__peter__ at web.de> wrote: > Chris Angelico wrote: > > > On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz > > wrote: > >> > >> I have an object which I could initialize providind an int or a > >> str. > >> > >> I am not sure which of the following is best to use > >> - try/except > >> - if type(int)... > >> - if isinstance(v, int) > >> > >> Here a minimal example > >> > >> def get_id(fromname): > >> # do something with `fromname` > >> return 0 > >> > >> def get_name(fromid): > >> # do something with `fromid` > >> return "something" > >> > >> """ For O1, O2, O3: self.myid is int > >> self.name is str > >> """ > >> class O1: > >> def __init__(self, val): > >> try: > >> self.myid = int(val) > >> self.name = get_name(self.myid) > >> except: > >> self.myid = get_id(val) > >> self.name = val > > > > Don't use a bare "except" - use "except ValueError" instead. But > > otherwise, this is a perfectly reasonable way to say "anything that > > can be interpreted as an integer will be". > > > >> class O2: > >> def __init__(self, val): > >> if type(val) == int: > >> self.myid = val > >> self.name = get_name(self.myid) > >> else: > >> self.myid = get_id(val) > >> self.name = val > > > > Nope, don't do this. It's strictly worse than O3. > > > >> class O3: > >> def __init__(self, val): > >> if isinstance(val, int): > >> self.myid = val > >> self.name = get_name(self.myid) > >> else: > >> self.myid = get_id(val) > >> self.name = val > > > > This is a perfectly reasonable way to say "integers will be treated > > as IDs". Note that O1 and O3 are very different semantically; O1 > > will treat the string "7" as an ID, but O3 will treat it as a name. > > > > Here's an even better way: > > > > class O4: > > def __init__(self, id): > > self.myid = id > > self.name = get_name(id) > > @classmethod > > def from_name(cls, name): > > return cls(get_id(name)) > > > > This makes the ID the main way you'd do things, and a name lookup as > > an alternate constructor. Very good pattern, reliable, easy to use. > > > > Yet another way: keyword arguments: > > class O5: > def __init__(self, *, id=None, name=None): > if name is None: > assert id is not None > name = get_name(id) > else: > assert id is None > id = get_id(name) > self.id = id > self.name = name > Thanks. Also a nice method. As said in my other reply it doesn't fit to my use case. -- Manfred From antoon.pardon at rece.vub.ac.be Sat Aug 15 05:28:12 2020 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sat, 15 Aug 2020 11:28:12 +0200 Subject: How to install your personal module/package on site. In-Reply-To: <7987a5e5-167d-f49a-3f56-79542f979402@DancesWithMice.info> References: <7bfe70aa-1a7f-c810-fc00-60b284ad7e72@rece.vub.ac.be> <7987a5e5-167d-f49a-3f56-79542f979402@DancesWithMice.info> Message-ID: <499dc551-7f3e-e281-2d32-ef42d0b6205c@rece.vub.ac.be> Op 15/08/20 om 07:33 schreef dn via Python-list: > On 14/08/2020 22:32, Antoon Pardon wrote: >> Well the question is in the subject. >> >> I have a number of modules/packages which were until recently >> personal use only. However python is getting more popular >> at work and some of my work was considered useful enough to >> install in a public available spot. >> >> How should I approach this? > > > Does the word "public" mean world-wide, or perhaps only amongst your work-colleagues? Only among work-colleagues. We only want that anyone writing and running python scripts on particular hosts, can easily import these modules/packages. -- Antoon From nulla.epistola at web.de Sat Aug 15 05:47:03 2020 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 15 Aug 2020 11:47:03 +0200 Subject: try..except or type() or isinstance()? In-Reply-To: <20200815101458.7e4ead91@arcor.com> References: <20200815072342.143c8723@arcor.com> <20200815101458.7e4ead91@arcor.com> Message-ID: <9b4c27fb-f495-d037-02e5-497e522b926e@web.de> Am 15.08.2020 um 10:14 schrieb Manfred Lotz: > Hi Chris, > Thanks a lot for you advice. > > On Sat, 15 Aug 2020 16:15:29 +1000 > Chris Angelico wrote: > >> On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz >> wrote: >>> >>> I have an object which I could initialize providind an int or a str. >>> ... > > For my use case I don't like this solution as I get the value which > could be an int or str from a file. Means I would have to check the > type beforehand in order to know if I have to do O4(val) or > O4.from_name(val). > > Otherwise, it is admittedly a very good pattern. > > Possibly silly question: if the value comes from a file, isn't it a string in any case? A string that may be convertible to int or not? Or what sort of file do I overlook? Curious, Sibylle From nulla.epistola at web.de Sat Aug 15 05:47:03 2020 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sat, 15 Aug 2020 11:47:03 +0200 Subject: try..except or type() or isinstance()? In-Reply-To: <20200815101458.7e4ead91@arcor.com> References: <20200815072342.143c8723@arcor.com> <20200815101458.7e4ead91@arcor.com> Message-ID: <9b4c27fb-f495-d037-02e5-497e522b926e@web.de> Am 15.08.2020 um 10:14 schrieb Manfred Lotz: > Hi Chris, > Thanks a lot for you advice. > > On Sat, 15 Aug 2020 16:15:29 +1000 > Chris Angelico wrote: > >> On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz >> wrote: >>> >>> I have an object which I could initialize providind an int or a str. >>> ... > > For my use case I don't like this solution as I get the value which > could be an int or str from a file. Means I would have to check the > type beforehand in order to know if I have to do O4(val) or > O4.from_name(val). > > Otherwise, it is admittedly a very good pattern. > > Possibly silly question: if the value comes from a file, isn't it a string in any case? A string that may be convertible to int or not? Or what sort of file do I overlook? Curious, Sibylle From antoon.pardon at rece.vub.ac.be Sat Aug 15 08:42:56 2020 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sat, 15 Aug 2020 14:42:56 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200807161933.GE42295@scrozzle> Message-ID: Op 7/08/20 om 18:45 schreef Chris Angelico: > On Sat, Aug 8, 2020 at 2:21 AM <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: >> >> On 2020-08-07 at 17:55:45 +0200, >> Marco Sulla wrote: >>> @Chris: note that "real" recursion in Python is not possible, since >>> there's no support for tail recursion. Maybe something similar can be >>> done using async functions. >> >> Python has real recursion. Whether or not there's tail recursion on the >> inside is an implementation detail. > > More specifically: Python has real recursion. Whether or not tail > recursion is optimized away is an implementation detail. > > Tail call optimization (there's no reason to restrict it to recursion > alone) is something a Python implementation could choose to do, but > the trouble is that full optimization tends to destroy traceback > information, so it's often not worth doing. I don't understand this argument. The trace back information that is destroyed with this optimization, is information that isn't available anyway if you write the code in an iterative fashion. So people are advised to rewrite tail recursive code in an iterative fashion, which results in less trace back information and the reason for not doing tail call optimization is, that it destroy the trace back information they don't have anyway by transforming the code to an iterative version. And the cases where > partial optimization is of value just aren't compelling enough for > anyone to implement it into CPython, nor any other major > implementation (to my knowledge). The biggest uses for TCO tend to be > the situations where recursion is the wrong solution to the problem. I think writing code that is at heart a state machine would be a lot more easy if python would have TCO. Then each state could be implemented by a function and transitioning from one state to the next would be just calling the next function. Sure you can resolve this by writing your state function trampoline style but it forces you into writing some boiler plate that otherwise wouldn't be necessary. -- Antoon Pardon. From rosuav at gmail.com Sat Aug 15 09:02:09 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 15 Aug 2020 23:02:09 +1000 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200807161933.GE42295@scrozzle> Message-ID: On Sat, Aug 15, 2020 at 10:45 PM Antoon Pardon wrote: > > Op 7/08/20 om 18:45 schreef Chris Angelico: > > On Sat, Aug 8, 2020 at 2:21 AM <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > >> > >> On 2020-08-07 at 17:55:45 +0200, > >> Marco Sulla wrote: > >>> @Chris: note that "real" recursion in Python is not possible, since > >>> there's no support for tail recursion. Maybe something similar can be > >>> done using async functions. > >> > >> Python has real recursion. Whether or not there's tail recursion on the > >> inside is an implementation detail. > > > > More specifically: Python has real recursion. Whether or not tail > > recursion is optimized away is an implementation detail. > > > > Tail call optimization (there's no reason to restrict it to recursion > > alone) is something a Python implementation could choose to do, but > > the trouble is that full optimization tends to destroy traceback > > information, so it's often not worth doing. > > I don't understand this argument. The trace back information that is > destroyed with this optimization, is information that isn't available > anyway if you write the code in an iterative fashion. Your counter-argument applies only to recursion, but TCO applies to *any* tail call. Consider this: @some_deco def spam(n): ... return spam(n // 2) Not a recursive tail call and cannot be rewritten as a loop, unless you know for sure that some_deco returns the original function. But TCO can still optimize this - by collapsing the stack frames. Which loses traceback info, unless you deliberately preserve it. > And the cases where > > partial optimization is of value just aren't compelling enough for > > anyone to implement it into CPython, nor any other major > > implementation (to my knowledge). The biggest uses for TCO tend to be > > the situations where recursion is the wrong solution to the problem. > > I think writing code that is at heart a state machine would be a lot more > easy if python would have TCO. Then each state could be implemented by > a function and transitioning from one state to the next would be just > calling the next function. I'm honestly not sure how much you'd gain by writing the transitions as additional calls. But then, I don't tend to write pure state machines in Python. If anything, they're "state machines with resumption" or something, and the additional wrinkles mean it's best to maintain state in a data structure and maintain code in a function, instead of trying to do both on the call stack. ISTM that everyone who begs for tail recursion optimization is trying to write loops as recursion. Maybe that's why Python has never bothered - because it's an optimization for an inferior way to write the same logic. Prove me wrong. Show me something where it actually couldn't be better written iteratively, yet it still benefits from the optimization. ChrisA From ml_news at posteo.de Sat Aug 15 09:31:56 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Sat, 15 Aug 2020 15:31:56 +0200 Subject: try..except or type() or isinstance()? References: <20200815072342.143c8723@arcor.com> <20200815101458.7e4ead91@arcor.com> <9b4c27fb-f495-d037-02e5-497e522b926e@web.de> Message-ID: <20200815153156.05859868@arcor.com> On Sat, 15 Aug 2020 11:47:03 +0200 Sibylle Koczian wrote: > Am 15.08.2020 um 10:14 schrieb Manfred Lotz: > > Hi Chris, > > Thanks a lot for you advice. > > > > On Sat, 15 Aug 2020 16:15:29 +1000 > > Chris Angelico wrote: > > > >> On Sat, Aug 15, 2020 at 3:36 PM Manfred Lotz > >> wrote: > >>> > >>> I have an object which I could initialize providind an int or a > >>> str. > ... > > > > For my use case I don't like this solution as I get the value which > > could be an int or str from a file. Means I would have to check the > > type beforehand in order to know if I have to do O4(val) or > > O4.from_name(val). > > > > Otherwise, it is admittedly a very good pattern. > > > > > Possibly silly question: No silly questions. There are at most stupid answers. :-) > if the value comes from a file, isn't it a > string in any case? A string that may be convertible to int or not? Or > what sort of file do I overlook? > In this case it is a TOML file. -- Manfred From Marco.Sulla.Python at gmail.com Sat Aug 15 10:03:40 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sat, 15 Aug 2020 16:03:40 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200807161933.GE42295@scrozzle> Message-ID: @Chris: you're very right, but, I repeat, you can't have a real TCO (asyncio apart): (venv_3_10) marco at buzz:~$ python Python 3.10.0a0 (heads/master-dirty:ba18c0b13b, Aug 14 2020, 17:52:45) [GCC 10.1.1 20200718] on linux Type "help", "copyright", "credits" or "license" for more information. >>> def factorial(n): ... if n in (1, 2): ... return n ... return n * factorial(n-1) ... >>> factorial(6) 720 >>> factorial(1000) Traceback (most recent call last): File "", line 1, in File "", line 4, in factorial File "", line 4, in factorial File "", line 4, in factorial [Previous line repeated 995 more times] File "", line 2, in factorial RecursionError: maximum recursion depth exceeded in comparison Anyway, tail call is introduced in Python, but only for asyncio: "If a Future.set_exception() is called but the Future object is never awaited on, the exception would never be propagated to the user code. Enable the debug mode to get the traceback where the task was created" https://docs.python.org/3.10/library/asyncio-dev.html#detect-never-retrieved-exceptions So, in theory, nothing prevents Python from having a Tail Call Optimization... because it already has it! The only problem is that it's applied to asyncio only. IMHO it's not a big problem to support generic TCO, and disable it for debugging purposes enabling the Python dev mode. From antoon.pardon at rece.vub.ac.be Sat Aug 15 10:17:03 2020 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Sat, 15 Aug 2020 16:17:03 +0200 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200807161933.GE42295@scrozzle> Message-ID: <51bbe27b-b4bd-16eb-0211-bd89ae60bc9e@rece.vub.ac.be> Op 15/08/20 om 15:02 schreef Chris Angelico: > On Sat, Aug 15, 2020 at 10:45 PM Antoon Pardon > wrote: >> >> >> I don't understand this argument. The trace back information that is >> destroyed with this optimization, is information that isn't available >> anyway if you write the code in an iterative fashion. > > Your counter-argument applies only to recursion, but TCO applies to > *any* tail call. Consider this: > > @some_deco > def spam(n): > ... > return spam(n // 2) > > Not a recursive tail call and cannot be rewritten as a loop, unless > you know for sure that some_deco returns the original function. But > TCO can still optimize this - by collapsing the stack frames. Which > loses traceback info, unless you deliberately preserve it. And how often does this kind of situation come up and destroy important trace back information? Sure you can come up with artificial examples like the above, but if the above code gets into trouble because you run into the recursion limit, you still will have to transform it into a loop somehow. >> I think writing code that is at heart a state machine would be a lot more >> easy if python would have TCO. Then each state could be implemented by >> a function and transitioning from one state to the next would be just >> calling the next function. > > I'm honestly not sure how much you'd gain by writing the transitions > as additional calls. But then, I don't tend to write pure state > machines in Python. If anything, they're "state machines with > resumption" or something, and the additional wrinkles mean it's best > to maintain state in a data structure and maintain code in a function, > instead of trying to do both on the call stack. Why are you talking about a stack? I don't know what best suits your code but my code often enough doesn't have enough wrinkles to bother with extra data structures. > > ISTM that everyone who begs for tail recursion optimization is trying > to write loops as recursion. Maybe that's why Python has never > bothered - because it's an optimization for an inferior way to write > the same logic. Prove me wrong. Show me something where it actually > couldn't be better written iteratively, yet it still benefits from the > optimization. What standard do you use to measure what is inferior of superior? Sometimes a state machines is easiest defined as a number of mutual recursive functions that just tail call each other. So with TCO I could just write it like the following. def state1(...): ... if ready_for_2: return state2(...) elif ready_for_7: return state7(...) elif finished: return result def state2(...): ... and you just call it like: result = state1(...) Without TCO I am forced to write it as follow: def state1(...): ... if ready_for_2: return state2, (...) # notice the comma between function and args. elif ready_for_7: return state7, (...) elif finished: return None, result def state2(...): ... and then call it like: state = state0 args = ... while state is not None: state, args = state(*args) result = args I realy don't see what I gain by having this loop or what I could gain by some extra data structure. -- Antoon Pardon. From Richard at Damon-Family.org Sat Aug 15 10:55:28 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 15 Aug 2020 10:55:28 -0400 Subject: How explain why Python is easier/nicer than Lisp which has a simpler grammar/syntax? In-Reply-To: <51bbe27b-b4bd-16eb-0211-bd89ae60bc9e@rece.vub.ac.be> References: <7c572252-8e59-4e8d-b10f-e08ecf8f38aeo@googlegroups.com> <20200807161933.GE42295@scrozzle> <51bbe27b-b4bd-16eb-0211-bd89ae60bc9e@rece.vub.ac.be> Message-ID: <0c6dca2c-6d9a-8950-8186-587213acfe89@Damon-Family.org> A few comments come to mind about this discussion about TCO. First, TCO, Tail Call Optimization, is talking about something that is an optimization. Optimizations, are generally some OPTIONAL improvement in the method of executing the code that doesn't alter its DEFINED meaning. First big point, they are optional. Yes, some languages may define certain circumstances where where there is a promise that a given optimization will be done, but this is unusual. Some things that might seem like optimizations, really aren't but are defined behaviors, like the short cutting operators 'and' and 'or' where the fact that the second operand isn't always evaluated could be though of as an optimization. Second, optimizations are generally only allow to be performed if it doesn't change any defined behavior of the program. I am not so sure that is possible for TCO to be done in python based on that. for example, given: def foo(x): ??? if x == 0: return 1 ??? else return foo(x-1) def bar(x) ??? if x == 0: return 2 ??? else return bar(x-1) t = foo foo = bar bar = t foo(1) By the twiddling done at the end, we have changed the self tail-recursive functions into mutually tail-recursive functions. The fact we can do this says that when compiling foo and bar into byte-code, the recursive call to foo can't just automatically go to the beginning of the current function, but needs to look up the name and enter with a possibly need operation, something like a tail-call which becomes more of a jump as it doesn't create a new stack frame but somehow replaces the current frame with what will be the new frame while binding the 'new x' with the old 'x-1' Second, because Python has defined things like traceback, the presence of TCO is observable, and thus violates one of the basic guidelines of an optimization, that it shouldn't change defined behavior. In my mid, this says that for Python to proper support TCO, it may need to do something to make it an explicit request, or at least defined specifically when it will do it and when not. Perhaps it could be defined that a return statement whose top level of the expression is a function call, becomes an optimized tail call, ALWAYS (at least with that version of Python), or maybe some sort of flag needs to also be on the statement to avoid making it a backwards breaking change. From msuginoo at reversalpoint.com Sat Aug 15 13:00:28 2020 From: msuginoo at reversalpoint.com (Michio Suginoo) Date: Sat, 15 Aug 2020 14:00:28 -0300 Subject: print the output of my code in Markdown using variable (not the value) Message-ID: Hi, I am still at an early stage of my personal Python evolution. I am coding Python3 in Jupyter Notebook (Anaconda environment). I want to print the output of my code in a 'markdown'. I want to use the variable in the 'markdown' rather than typing the output. This would save my time every time the value changes for whatever the reason might be. Please advise me how to do it. Thanks Best . From mats at python.org Sat Aug 15 14:58:23 2020 From: mats at python.org (Mats Wichmann) Date: Sat, 15 Aug 2020 12:58:23 -0600 Subject: print the output of my code in Markdown using variable (not the value) In-Reply-To: References: Message-ID: <8f450918-9988-0908-c0da-5cae4ae7b741@python.org> On 8/15/20 11:00 AM, Michio Suginoo wrote: > Hi, > > I am still at an early stage of my personal Python evolution. > > I am coding Python3 in Jupyter Notebook (Anaconda environment). > > I want to print the output of my code in a 'markdown'. > I want to use the variable in the 'markdown' rather than typing the output. > This would save my time every time the value changes for whatever the > reason might be. > > Please advise me how to do it. Just a gentle suggestion... show a sample of what you're trying to achieve, and if possible some code that you've tried. This might be a place to look: https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.Markdown From PythonList at DancesWithMice.info Sat Aug 15 20:06:53 2020 From: PythonList at DancesWithMice.info (dn) Date: Sun, 16 Aug 2020 12:06:53 +1200 Subject: Whitespace not/required In-Reply-To: References: Message-ID: <335fd748-c34d-0736-1f29-0da4babad50a@DancesWithMice.info> On 15/08/2020 08:01, Dennis Lee Bieber wrote: > On Fri, 14 Aug 2020 16:29:18 +1200, dn via Python-list > declaimed the following: > > >> it is ignored by Python. (yes, this discussion disdains comments!) For >> example, whitespace is no problem when it comes to defining a list: >> >> month_names = ['Januari', 'Februari', 'Maart', # These are the >> 'April', 'Mei', 'Juni', # Dutch names... >> > > Concepts: First, you have an open [ though ( and { behave the same. > Python takes anything in intervening lines to be included until the closing > ]/)/} is reached. Exactly! (BTW this taken from 'the manual') > Second, for things like lists, the only important (parsed content) are > the "words" [in your example] separated by commas. Agreed - and IMHO a positive attribute when coding in Python making a solid contribution to readability. > Whitespace in Python controls /scope/ of logic structures (function > definition, loop bodies, conditional bodies). Hence my surprise/how do we explain: >>> f'{ one:03 }' Traceback (most recent call last): File "", line 1, in ValueError: Unknown format code '\x20' for object of type 'int' where the final space does not act as a separator by terminating the format-specification. The err.msg is in itself confusing, because the format-specification 03 is NOT a (valid) Python integer: >>> i = 3 >>> i 3 >>> i = 03 File "", line 1 i = 03 ^ SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers Perhaps I'm mis-interpreting the err.msg? Otherwise let's march on City Hall: "white space just wants to be free!"... -- Regards =dn From PythonList at DancesWithMice.info Sun Aug 16 02:02:11 2020 From: PythonList at DancesWithMice.info (dn) Date: Sun, 16 Aug 2020 18:02:11 +1200 Subject: How to install your personal module/package on site. In-Reply-To: <499dc551-7f3e-e281-2d32-ef42d0b6205c@rece.vub.ac.be> References: <7bfe70aa-1a7f-c810-fc00-60b284ad7e72@rece.vub.ac.be> <7987a5e5-167d-f49a-3f56-79542f979402@DancesWithMice.info> <499dc551-7f3e-e281-2d32-ef42d0b6205c@rece.vub.ac.be> Message-ID: <457f6113-1e39-f084-8304-73995e9731a6@DancesWithMice.info> >> Does the word "public" mean world-wide, or perhaps only amongst your work-colleagues? > > Only among work-colleagues. > > We only want that anyone writing and running python scripts on particular hosts, can > easily import these modules/packages. Of possible interest:- Private Python package management https://stackoverflow.com/questions/63320653/private-python-package-management -- Regards =dn From Marco.Sulla.Python at gmail.com Sun Aug 16 02:32:25 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sun, 16 Aug 2020 08:32:25 +0200 Subject: How to install your personal module/package on site. In-Reply-To: <457f6113-1e39-f084-8304-73995e9731a6@DancesWithMice.info> References: <7bfe70aa-1a7f-c810-fc00-60b284ad7e72@rece.vub.ac.be> <7987a5e5-167d-f49a-3f56-79542f979402@DancesWithMice.info> <499dc551-7f3e-e281-2d32-ef42d0b6205c@rece.vub.ac.be> <457f6113-1e39-f084-8304-73995e9731a6@DancesWithMice.info> Message-ID: Sorry, didn't read well, Apart the other suggestion, you (or your sysop) can create a private Pypi: https://pypi.org/project/private-pypi/ From ml_news at posteo.de Sun Aug 16 03:40:12 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Sun, 16 Aug 2020 09:40:12 +0200 Subject: try..except or type() or isinstance()? References: <20200815072342.143c8723@arcor.com> <20200815101458.7e4ead91@arcor.com> <9b4c27fb-f495-d037-02e5-497e522b926e@web.de> <20200815153156.05859868@arcor.com> <632gjflpipc7r63jikuq7fbkoru20tnk8n@4ax.com> Message-ID: <20200816094012.30064f39@arcor.com> On Sat, 15 Aug 2020 12:20:48 -0400 Dennis Lee Bieber wrote: > On Sat, 15 Aug 2020 15:31:56 +0200, Manfred Lotz > declaimed the following: > > >On Sat, 15 Aug 2020 11:47:03 +0200 > >Sibylle Koczian wrote: > > > > >> if the value comes from a file, isn't it a > >> string in any case? A string that may be convertible to int or > >> not? Or what sort of file do I overlook? > >> > > > >In this case it is a TOML file. > > Based on https://en.wikipedia.org/wiki/TOML this means you > need a parser... > """ > In TOML the syntax determines the data types ("syntax typing") > """ > > String data is surrounded with " marks, numbers are not > (though the example doesn't show if integers are treated differently > from floating point), arrays/lists in [] with embedded comma ([] are > also overloaded for section headers, with subsections using > section.subsection naming), dates are some ugly creation, and looks > like true/false are reserved values. > > However, as pointed out -- all data read from the file will > be seen as a Python string data type. It is only after determining > the TOML data type -- by examining the string itself -- that one can > convert to internal format. > > Unfortunately, TOML is not compatible with INI -- for which > Python already has a read/write module. But there is > https://pypi.org/project/toml/ > (uses the same example file as Wikipedia) -- latest version was from > May. > > I use tomlkit as the toml package doesn't support quoted keys sufficiently. -- Manfred From ml_news at posteo.de Sun Aug 16 03:43:07 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Sun, 16 Aug 2020 09:43:07 +0200 Subject: try..except or type() or isinstance()? References: <20200815072342.143c8723@arcor.com> Message-ID: <20200816094307.0db56dc2@arcor.com> On 15 Aug 2020 14:49:48 GMT ram at zedat.fu-berlin.de (Stefan Ram) wrote: > Manfred Lotz writes: > >Here a minimal example > > main.py > > source=""" > sehr gut > 1 > """[ 1: -1 ].split( "\n" ) > > class grades: > names =[ "sehr gut" ] > @staticmethod > def is_numeric( text ): > return text.isdigit() > @staticmethod > def get_number( text ): > return grades.names.index( text )+ 1 > @staticmethod > def get_name( text ): > return grades.names[ int( text )- 1 ] > > class O1: > def init_from_number( self, text ): > self.myid = int( text ) > self.name = grades.get_name( text ) > def init_from_name( self, text ): > self.myid = grades.get_number( text ) > self.name = text > def __init__( self, text ): > if grades.is_numeric( text ): > self.init_from_number( text ) > else: > self.init_from_name( text ) > def __str__( self ): > return "O1( " + str( self.myid )+ ", " + str( self.name ) + " > )" > for line in source: > print( O1( line )) > > > transcript: > > O1( 1, sehr gut ) > O1( 1, sehr gut ) > > Thanks for this interesting variation. -- Manfred From ml_news at posteo.de Sun Aug 16 03:48:07 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Sun, 16 Aug 2020 09:48:07 +0200 Subject: try..except or type() or isinstance()? References: <20200815072342.143c8723@arcor.com> <20200815101458.7e4ead91@arcor.com> <9b4c27fb-f495-d037-02e5-497e522b926e@web.de> <20200815153156.05859868@arcor.com> <632gjflpipc7r63jikuq7fbkoru20tnk8n@4ax.com> <20200816094012.30064f39@arcor.com> Message-ID: <20200816094807.1fe48b68@arcor.com> On Sun, 16 Aug 2020 09:40:12 +0200 Manfred Lotz wrote: > On Sat, 15 Aug 2020 12:20:48 -0400 > Dennis Lee Bieber wrote: > > > On Sat, 15 Aug 2020 15:31:56 +0200, Manfred Lotz > > declaimed the following: > > > > >On Sat, 15 Aug 2020 11:47:03 +0200 > > >Sibylle Koczian wrote: > > > > > > > >> if the value comes from a file, isn't it a > > >> string in any case? A string that may be convertible to int or > > >> not? Or what sort of file do I overlook? > > >> > > > > > >In this case it is a TOML file. > > > > Based on https://en.wikipedia.org/wiki/TOML this means you > > need a parser... > > """ > > In TOML the syntax determines the data types ("syntax typing") > > """ > > > > String data is surrounded with " marks, numbers are not > > (though the example doesn't show if integers are treated differently > > from floating point), arrays/lists in [] with embedded comma ([] are > > also overloaded for section headers, with subsections using > > section.subsection naming), dates are some ugly creation, and looks > > like true/false are reserved values. > > > > However, as pointed out -- all data read from the file will > > be seen as a Python string data type. It is only after determining > > the TOML data type -- by examining the string itself -- that one can > > convert to internal format. > > > > Unfortunately, TOML is not compatible with INI -- for which > > Python already has a read/write module. But there is > > https://pypi.org/project/toml/ > > (uses the same example file as Wikipedia) -- latest version was from > > May. > > > > > > I use tomlkit as the toml package doesn't support quoted keys > sufficiently. > Just checked again. It seems I was wrong. Both toml and tomlkit do support quoted keys ok. -- Manfred From k.d.jantzen at mailbox.org Sun Aug 16 04:12:04 2020 From: k.d.jantzen at mailbox.org (Klaus Jantzen) Date: Sun, 16 Aug 2020 10:12:04 +0200 Subject: Syntax question Message-ID: <46048530-9e3a-6e40-2d27-600c2b52a38c@mailbox.org> Hi, the other day I came across the book "Classic Computer Science Problems in Python" by David Kopec. The function definitions in the examples? like ===== def fib2(n: int) -> int: ??? if n < 2:? # base case ??????? return n ??? return fib2(n - 2) + fib2(n - 1)? # recursive case if __name__ == "__main__": ??? print(fib2(5)) ??? print(fib2(10)) ===== use a syntax that I have never seen on this list or in other publications. My questions: Is that new? Is is 'recommended' to use this is the future? I can only see a certain advantage of using this type of function definition in resp. to the documentation, as it does not provide an automatic check of the type of the argument(s) or of the result as in Java. -- K.D.J. From PythonList at DancesWithMice.info Sun Aug 16 05:20:14 2020 From: PythonList at DancesWithMice.info (dn) Date: Sun, 16 Aug 2020 21:20:14 +1200 Subject: Syntax question In-Reply-To: <46048530-9e3a-6e40-2d27-600c2b52a38c@mailbox.org> References: <46048530-9e3a-6e40-2d27-600c2b52a38c@mailbox.org> Message-ID: <53a9b926-50c0-0b59-7267-ba64377490b8@DancesWithMice.info> On 16/08/2020 20:12, Klaus Jantzen wrote: > Hi, > > the other day I came across the book "Classic Computer Science Problems > in Python" by David Kopec. > > The function definitions in the examples? like > > ===== > def fib2(n: int) -> int: > ??? if n < 2:? # base case > ??????? return n > ??? return fib2(n - 2) + fib2(n - 1)? # recursive case > > > if __name__ == "__main__": > ??? print(fib2(5)) > ??? print(fib2(10)) > > ===== > > use a syntax that I have never seen on this list or in other publications. About which line of code are you asking? > def fib2(n: int) -> int: Please review: Type Hints: https://docs.python.org/3/library/typing.html > if __name__ == "__main__": https://docs.python.org/3/library/__main__.html https://docs.python.org/3/reference/import.html > My questions: > > Is that new? Typing: v3.5+ (IIRC) > Is is 'recommended' to use this is the future? Yes and no. The operative word is "Hints". Typing is not required by Python. However, you may find the extra error-checking helpful... > I can only see a certain advantage of using this type of function > definition in resp. to the documentation, as it does not provide an > automatic check of the type of the argument(s) or of the result as in Java. There are 'pros' and 'cons'! -- Regards =dn From ml_news at posteo.de Sun Aug 16 05:26:27 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Sun, 16 Aug 2020 11:26:27 +0200 Subject: Syntax question References: <46048530-9e3a-6e40-2d27-600c2b52a38c@mailbox.org> Message-ID: <20200816112627.57a43e63@arcor.com> On Sun, 16 Aug 2020 10:12:04 +0200 Klaus Jantzen wrote: > Hi, > > the other day I came across the book "Classic Computer Science > Problems in Python" by David Kopec. > > The function definitions in the examples? like > > ===== > def fib2(n: int) -> int: > ??? if n < 2:? # base case > ??????? return n > ??? return fib2(n - 2) + fib2(n - 1)? # recursive case > > > if __name__ == "__main__": > ??? print(fib2(5)) > ??? print(fib2(10)) > > ===== > > use a syntax that I have never seen on this list or in other > publications. > What do you mean? The 'n:int' and '-> int'? If yes, this is type hinting. See here: https://docs.python.org/3/library/typing.html -- Manfred From skip.montanaro at gmail.com Sun Aug 16 07:09:17 2020 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Sun, 16 Aug 2020 06:09:17 -0500 Subject: Syntax question In-Reply-To: <53a9b926-50c0-0b59-7267-ba64377490b8@DancesWithMice.info> References: <46048530-9e3a-6e40-2d27-600c2b52a38c@mailbox.org> <53a9b926-50c0-0b59-7267-ba64377490b8@DancesWithMice.info> Message-ID: > Typing is not required by > Python. However, you may find the extra error-checking helpful... I haven't used type hints much, if at all, but my understanding is that the "extra error-checking" of which you speak is gotten through other static checkers, correct? I know the syntax was developed with the MyPy folks (http://mypy-lang.org/), but I'm not sure what other tools currently make use of it. Any pointers? Skip From ml_news at posteo.de Sun Aug 16 07:21:01 2020 From: ml_news at posteo.de (Manfred Lotz) Date: Sun, 16 Aug 2020 13:21:01 +0200 Subject: Syntax question References: <46048530-9e3a-6e40-2d27-600c2b52a38c@mailbox.org> <53a9b926-50c0-0b59-7267-ba64377490b8@DancesWithMice.info> Message-ID: <20200816132101.5376a90e@arcor.com> On Sun, 16 Aug 2020 06:09:17 -0500 Skip Montanaro wrote: > > Typing is not required by > > Python. However, you may find the extra error-checking helpful... > > I haven't used type hints much, if at all, but my understanding is > that the "extra error-checking" of which you speak is gotten through > other static checkers, correct? Yes. > I know the syntax was developed with > the MyPy folks (http://mypy-lang.org/), but I'm not sure what other > tools currently make use of it. Any pointers? > I heard about the following (not tried all, though) - mypy (Dropbox) - pyre-check (Facebook) - pytype (Google) - pyright (Microsoft) -- Manfred From alexandra_mel.1981 at hotmail.es Sun Aug 16 10:08:11 2020 From: alexandra_mel.1981 at hotmail.es (=?Windows-1252?Q?Alexa_O=F1a?=) Date: Sun, 16 Aug 2020 14:08:11 +0000 Subject: try..except or type() or isinstance()? In-Reply-To: <20200816094807.1fe48b68@arcor.com> References: <20200815072342.143c8723@arcor.com> <20200815101458.7e4ead91@arcor.com> <9b4c27fb-f495-d037-02e5-497e522b926e@web.de> <20200815153156.05859868@arcor.com> <632gjflpipc7r63jikuq7fbkoru20tnk8n@4ax.com> <20200816094012.30064f39@arcor.com>,<20200816094807.1fe48b68@arcor.com> Message-ID: Sorry... i have received a lot of messages from python support and I still didn?t understand how to fix it Obtener Outlook para iOS ________________________________ De: Python-list en nombre de Manfred Lotz Enviado: Sunday, August 16, 2020 9:48:07 AM Para: python-list at python.org Asunto: Re: try..except or type() or isinstance()? On Sun, 16 Aug 2020 09:40:12 +0200 Manfred Lotz wrote: > On Sat, 15 Aug 2020 12:20:48 -0400 > Dennis Lee Bieber wrote: > > > On Sat, 15 Aug 2020 15:31:56 +0200, Manfred Lotz > > declaimed the following: > > > > >On Sat, 15 Aug 2020 11:47:03 +0200 > > >Sibylle Koczian wrote: > > > > > > > >> if the value comes from a file, isn't it a > > >> string in any case? A string that may be convertible to int or > > >> not? Or what sort of file do I overlook? > > >> > > > > > >In this case it is a TOML file. > > > > Based on https://en.wikipedia.org/wiki/TOML this means you > > need a parser... > > """ > > In TOML the syntax determines the data types ("syntax typing") > > """ > > > > String data is surrounded with " marks, numbers are not > > (though the example doesn't show if integers are treated differently > > from floating point), arrays/lists in [] with embedded comma ([] are > > also overloaded for section headers, with subsections using > > section.subsection naming), dates are some ugly creation, and looks > > like true/false are reserved values. > > > > However, as pointed out -- all data read from the file will > > be seen as a Python string data type. It is only after determining > > the TOML data type -- by examining the string itself -- that one can > > convert to internal format. > > > > Unfortunately, TOML is not compatible with INI -- for which > > Python already has a read/write module. But there is > > https://pypi.org/project/toml/ > > (uses the same example file as Wikipedia) -- latest version was from > > May. > > > > > > I use tomlkit as the toml package doesn't support quoted keys > sufficiently. > Just checked again. It seems I was wrong. Both toml and tomlkit do support quoted keys ok. -- Manfred -- https://mail.python.org/mailman/listinfo/python-list From ceo at teo-en-ming.com Sun Aug 16 05:41:56 2020 From: ceo at teo-en-ming.com (Turritopsis Dohrnii Teo En Ming) Date: Sun, 16 Aug 2020 17:41:56 +0800 Subject: I discovered a bug in the no-ip dynamic dns free hostname auto renewal/confirmation script written by loblab Message-ID: <3de7cd98e24dea4f2cebd65f9a16973a@teo-en-ming.com> Subject: I discovered a bug in the no-ip dynamic dns free hostname auto renewal/confirmation script written by loblab Good day from Singapore, Programming code troubleshooting person: Mr. Turritopsis Dohrnii Teo En Ming (Targeted Individual) Country: Singapore Date: 15 to 16 August 2020 Singapore Time (Saturday and Sunday) My IT consulting company in Singapore asked me to install a Linux virtual machine so that we can run no-ip dynamic dns free hostname auto renewal/confirmation script written by loblab. I am an IT consultant in Singapore, 42 years old as of 16 Aug 2020. I am not a Python or Java programmer or software developer. The last time I had formal training in structured C programming (not C++ objected oriented programming) was more than 20 years ago at Singapore Polytechnic (Diploma in Mechatronics Engineering course year 1995-1998). Although I am not a programmer or software developer, I can still more or less understand the flow of programming code. I chose Debian 10.5 64-bit Linux to install as my virtual machine/guest operating system because loblab mentioned that his scripts have been tested on Debian 9.x/10.x. But first I have to install VMware Workstation Pro 15.5.6 in my Ubuntu 18.04.3 LTS Linux desktop operating system. The iso file I downloaded is debian-10.5.0-amd64-netinst.iso. The virtual network adapter in my Debian 10.5 Linux virtual machine was configured to use Network Address Translation (NAT). You can verify the IP address of your VM with the following Linux commands: $ ip a $ ip route Give your Debian 10.5 Linux VM at least 2 GB of RAM. After installing Debian 10.5 Linux virtual machine (minimal installation with SSH server and standard system utilities), I need to do a few more things, as follows. # apt install sudo # usermod -aG sudo teo-en-ming # groups teo-en-ming So that I can sudo as a regular Linux user. # apt install git Then I downloaded the no-ip ddns free hostname auto renewal/confirmation script using git clone. Software: Script to auto renew/confirm noip.com free hosts Download link: https://github.com/loblab/noip-renew Programmer: loblab I believe programmer loblab is based in China. The version of the scripts I downloaded is 1.1 dated 18 May 2020. The composition of the software is 58.4% Python programming language, 36% Linux shell scripts, and 5.6% Dockerfile. I tried to run setup.sh Linux shell script and choose "Install/Repair Script". But I found out that nothing is being installed in /usr/local/bin after a few installation attempts. I thought the scripts/installation were being blocked by AppArmor, so I went to disable AppArmor using the following Linux commands. $ sudo mkdir -p /etc/default/grub.d $ echo 'GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT apparmor=0"' \ | sudo tee /etc/default/grub.d/apparmor.cfg $ sudo update-grub $ sudo reboot $ aa-enabled $ sudo aa-status But AppArmor is NOT the cause of the problem. I began to examine the Python programming code and Linux shell scripts. For the setup.sh script, when you choose "Install/Repair Script", it will call the installer() function. Inside the installer() function, it will call the following functions, in sequence: config(), install(), deploy() When the install() function was called, it tried to execute the following Linux command: $SUDO apt -y install chromium-browser # Update Chromium Browser or script won't work. Executing the above Linux command resulted in an ERROR because Debian 10.5 Linux does not have the chromium-browser software package. Instead it has the chromium package. When the above error is encountered, the installer script ABORTED PREMATURELY and could not continue running. The installer script could not run to completion. This is the bug. To fix the bug, I have to COMMENT OUT/DISABLE the following line in setup.sh script: $SUDO apt -y install chromium-browser # Update Chromium Browser or script won't work. And add the following line below the above-mentioned line: $SUDO apt -y install chromium It fixed the bug. I ran setup.sh script again, choose "Install/Repair Script", and the installer ran to completion. Finally the scripts are installed in /usr/local/bin. Please DO NOT add your no-ip account password to noip-renew.sh script manually in plain text because it has to be Base64 encoded/encrypted. If you add your no-ip account password directly to noip-renew.sh script, you will get an "Incorrect Padding" Python programming base64 error code. You need to supply the no-ip account password when you run the installer script. When the installer script calls the deploy() function, it will also call the noip() function. The noip() function is as follows: function noip() { echo "Enter your No-IP Account details..." read -p 'Username: ' uservar read -sp 'Password: ' passvar passvar=`echo -n $passvar | base64` echo $SUDO sed -i 's/USERNAME=".*"/USERNAME="'$uservar'"/1' $INSTEXE $SUDO sed -i 's/PASSWORD=".*"/PASSWORD="'$passvar'"/1' $INSTEXE } Observe that it will use base64 encoding to encrypt your supplied no-ip account password in /usr/local/bin/noip-renew-$USER. When you run the noip-renew.sh script, it will call the noip-renew.py python script. Inside the noip-renew.py python script, the code is as follows: def login(self): self.logger.log(f"Opening {Robot.LOGIN_URL}...") self.browser.get(Robot.LOGIN_URL) if self.debug > 1: self.browser.save_screenshot("debug1.png") self.logger.log("Logging in...") ele_usr = self.browser.find_element_by_name("username") ele_pwd = self.browser.find_element_by_name("password") ele_usr.send_keys(self.username) ele_pwd.send_keys(base64.b64decode(self.password).decode('utf-8')) self.browser.find_element_by_name("Login").click() if self.debug > 1: time.sleep(1) self.browser.save_screenshot("debug2.png") The python script will use base64 decoding to decode your encrypted no-ip account password when it tries to login to noip.com portal. When you run the setup.sh installer script, it will also install/copy the noip-renew.sh script as /usr/local/bin/noip-renew-$USER or /usr/local/bin/noip-renew-teo-en-ming in my case. The /usr/local/bin/noip-renew-$USER script is the script you should normally run. You should then install the following crontab (scheduled task) using crontab -e: 30 0 * * * /usr/local/bin/noip-renew-$USER /var/log/noip-renew/$USER You can verify your crontab (scheduled task) is installed by running $ crontab -l The scheduled task will run at 12.30 AM at midnight every day. You should also check the logs at /var/log/noip-renew/$USER This essay also serves as a tutorial on how to use the no-ip ddns free hostname auto renewal/confirmation script since there is a lack of detailed documentation. -- -----BEGIN EMAIL SIGNATURE----- The Gospel for all Targeted Individuals (TIs): [The New York Times] Microwave Weapons Are Prime Suspect in Ills of U.S. Embassy Workers Link: https://www.nytimes.com/2018/09/01/science/sonic-attack-cuba-microwave.html ******************************************************************************************** Singaporean Mr. Turritopsis Dohrnii Teo En Ming's Academic Qualifications as at 14 Feb 2019 and refugee seeking attempts at the United Nations Refugee Agency Bangkok (21 Mar 2017), in Taiwan (5 Aug 2019) and Australia (25 Dec 2019 to 9 Jan 2020): [1] https://tdtemcerts.wordpress.com/ [2] https://tdtemcerts.blogspot.sg/ [3] https://www.scribd.com/user/270125049/Teo-En-Ming -----END EMAIL SIGNATURE----- From cs at cskk.id.au Sun Aug 16 19:16:28 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 17 Aug 2020 09:16:28 +1000 Subject: I discovered a bug in the no-ip dynamic dns free hostname auto renewal/confirmation script written by loblab In-Reply-To: <3de7cd98e24dea4f2cebd65f9a16973a@teo-en-ming.com> References: <3de7cd98e24dea4f2cebd65f9a16973a@teo-en-ming.com> Message-ID: <20200816231628.GA98948@cskk.homeip.net> On 16Aug2020 17:41, Turritopsis Dohrnii Teo En Ming wrote: >Subject: I discovered a bug in the no-ip dynamic dns free hostname >auto renewal/confirmation script written by loblab The best thing to do here is to submit this as an issue here: https://github.com/loblab/noip-renew/issues Posting to the generic python-list won't help anyone, because the script authors likely will not see it and the python-list members haven't anything they can do with your bug report. Cheers, Cameron Simpson From ceo at teo-en-ming.com Sun Aug 16 22:10:58 2020 From: ceo at teo-en-ming.com (Turritopsis Dohrnii Teo En Ming) Date: Mon, 17 Aug 2020 10:10:58 +0800 Subject: I discovered a bug in the no-ip dynamic dns free hostname auto renewal/confirmation script written by loblab In-Reply-To: <20200816231628.GA98948@cskk.homeip.net> References: <3de7cd98e24dea4f2cebd65f9a16973a@teo-en-ming.com> <20200816231628.GA98948@cskk.homeip.net> Message-ID: <36ed658b2ae4b1cb5dde9c7ab51da19c@teo-en-ming.com> Noted with thanks. I will contact the script authors. On 2020-08-17 07:16, Cameron Simpson wrote: > On 16Aug2020 17:41, Turritopsis Dohrnii Teo En Ming > wrote: >> Subject: I discovered a bug in the no-ip dynamic dns free hostname >> auto renewal/confirmation script written by loblab > > The best thing to do here is to submit this as an issue here: > > https://github.com/loblab/noip-renew/issues > > Posting to the generic python-list won't help anyone, because the > script > authors likely will not see it and the python-list members haven't > anything they can do with your bug report. > > Cheers, > Cameron Simpson -- -----BEGIN EMAIL SIGNATURE----- The Gospel for all Targeted Individuals (TIs): [The New York Times] Microwave Weapons Are Prime Suspect in Ills of U.S. Embassy Workers Link: https://www.nytimes.com/2018/09/01/science/sonic-attack-cuba-microwave.html ******************************************************************************************** Singaporean Mr. Turritopsis Dohrnii Teo En Ming's Academic Qualifications as at 14 Feb 2019 and refugee seeking attempts at the United Nations Refugee Agency Bangkok (21 Mar 2017), in Taiwan (5 Aug 2019) and Australia (25 Dec 2019 to 9 Jan 2020): [1] https://tdtemcerts.wordpress.com/ [2] https://tdtemcerts.blogspot.sg/ [3] https://www.scribd.com/user/270125049/Teo-En-Ming -----END EMAIL SIGNATURE----- From xuanwu348 at 163.com Mon Aug 17 12:00:20 2020 From: xuanwu348 at 163.com (xuanwu348) Date: Tue, 18 Aug 2020 00:00:20 +0800 (CST) Subject: =?UTF-8?Q?why_the_connection_set_with_=E2=80=9Ckeep_live=E2=80=9D_in_u?= =?UTF-8?Q?rllib.request_always_set_to_be=E2=80=9Cclosed,_thanks?= In-Reply-To: <20200815153156.05859868@arcor.com> References: <20200815072342.143c8723@arcor.com> <20200815101458.7e4ead91@arcor.com> <9b4c27fb-f495-d037-02e5-497e522b926e@web.de> <20200815153156.05859868@arcor.com> Message-ID: <25cd9ee1.7f5a.173fd266bea.Coremail.xuanwu348@163.com> hi everyone Good day, the code as below, I try to make a long connection by set the connection to "keep-alive", but actually it's not as expected. Why? Thanks import urllib.request as req headers = {"authorization": "Bearer {}".format(self.token), "Content-Type": "multipart/form-data; boundary={}".format(self.boundary), "Connection": "keep-alive"} request = req.Request(event_uri, headers=headers, data=data.encode("utf-8")) Accept-Encoding: identity Content-Length: 705 Host: 10.10.1.114:9443 User-Agent: Python-urllib/3.8 Authorization: Bearer a1.BUiPZxxxxxxxxxxxxxxxxxxCQdH2c9uegml Content-Type: multipart/form-data; boundary=--testtest-- Connection: close Best Regards From rosuav at gmail.com Mon Aug 17 14:26:01 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Aug 2020 04:26:01 +1000 Subject: Final statement from Steering Council on politically-charged commit messages Message-ID: For context, see this commit: https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4 The commit message is highly politically charged and is now a permanent part of the Python commit history. The Python Steering Council has this to say: https://github.com/python/steering-council/issues/34#issuecomment-675028005 "The SC discussed this and ... we do not deplore the message." So now we know: go ahead and put all the political messages you like into the commit messages, just don't put anything inappropriate into the content. White supremacy has been mentioned; who wants to pick the next hot topic? ChrisA From interzone at gmail.com Mon Aug 17 14:33:24 2020 From: interzone at gmail.com (Dylan Distasio) Date: Mon, 17 Aug 2020 14:33:24 -0400 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: That's quite an interesting ruling by the SC. I'm not surprised to see them bend the knee to PC, but it is disheartening to see they're fine opening a can of political worms in a programming language. I suspect they will deplore messages outside of their bubble though. On Mon, Aug 17, 2020 at 2:30 PM Chris Angelico wrote: > For context, see this commit: > > > https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4 > > The commit message is highly politically charged and is now a > permanent part of the Python commit history. The Python Steering > Council has this to say: > > https://github.com/python/steering-council/issues/34#issuecomment-675028005 > > "The SC discussed this and ... we do not deplore the message." > > So now we know: go ahead and put all the political messages you like > into the commit messages, just don't put anything inappropriate into > the content. White supremacy has been mentioned; who wants to pick the > next hot topic? > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Mon Aug 17 14:37:07 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 18 Aug 2020 04:37:07 +1000 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: On Tue, Aug 18, 2020 at 4:34 AM Dylan Distasio wrote: > > That's quite an interesting ruling by the SC. I'm not surprised to see them bend the knee to PC, but it is disheartening to see they're fine opening a can of political worms in a programming language. I suspect they will deplore messages outside of their bubble though. > Yes. I was hoping for "we should rewrite that commit", and would have been content with "we won't rewrite it, but we don't want that repeated". But the SC said that it is absolutely fine to write commit messages like that. ChrisA From giaym.mail at gmail.com Mon Aug 17 15:23:04 2020 From: giaym.mail at gmail.com (gia) Date: Mon, 17 Aug 2020 14:23:04 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: Math should stop being standardized, as it could alienate people of other colors to it. Commit should be rewritten as "Remove book advert from comments". On Mon, Aug 17, 2020 at 1:39 PM Chris Angelico wrote: > On Tue, Aug 18, 2020 at 4:34 AM Dylan Distasio > wrote: > > > > That's quite an interesting ruling by the SC. I'm not surprised to see > them bend the knee to PC, but it is disheartening to see they're fine > opening a can of political worms in a programming language. I suspect they > will deplore messages outside of their bubble though. > > > > Yes. I was hoping for "we should rewrite that commit", and would have > been content with "we won't rewrite it, but we don't want that > repeated". But the SC said that it is absolutely fine to write commit > messages like that. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Mon Aug 17 16:51:03 2020 From: barry at barrys-emacs.org (Barry) Date: Mon, 17 Aug 2020 21:51:03 +0100 Subject: =?utf-8?Q?Re:_why_the_connection_set_with_=E2=80=9Ckeep_live?= =?utf-8?Q?=E2=80=9D_in_urllib.request_always_set_to_be=E2=80=9Cc?= =?utf-8?Q?losed,_thanks?= In-Reply-To: <25cd9ee1.7f5a.173fd266bea.Coremail.xuanwu348@163.com> References: <25cd9ee1.7f5a.173fd266bea.Coremail.xuanwu348@163.com> Message-ID: <852BD06A-E035-4C80-9398-509B83879DFE@barrys-emacs.org> > On 17 Aug 2020, at 18:23, xuanwu348 wrote: > > ?hi everyone > > > Good day, the code as below, I try to make a long connection by set the connection to "keep-alive", but actually it's not as expected. Why? Thanks What this means is. Please web server keep the connect alive if you can. The web server is allowed to close the connection if it wants too. Barry > > > import urllib.request as req > headers = {"authorization": "Bearer {}".format(self.token), > "Content-Type": "multipart/form-data; boundary={}".format(self.boundary), > "Connection": "keep-alive"} > request = req.Request(event_uri, headers=headers, data=data.encode("utf-8")) > > > > > > Accept-Encoding: identity > > Content-Length: 705 > > Host: 10.10.1.114:9443 > > User-Agent: Python-urllib/3.8 > > Authorization: Bearer a1.BUiPZxxxxxxxxxxxxxxxxxxCQdH2c9uegml > > Content-Type: multipart/form-data; boundary=--testtest-- > > Connection: close > > > > > > > > Best Regards > -- > https://mail.python.org/mailman/listinfo/python-list > From xuanwu348 at 163.com Mon Aug 17 21:16:05 2020 From: xuanwu348 at 163.com (xuanwu348) Date: Tue, 18 Aug 2020 09:16:05 +0800 (CST) Subject: =?UTF-8?Q?Re:Re:_why_the_connectio?= =?UTF-8?Q?n_set_with_=E2=80=9Ckeep_live=E2=80=9D_i?= =?UTF-8?Q?n_urllib.request_always_set_to_be=E2=80=9Cclosed,_thanks?= In-Reply-To: <852BD06A-E035-4C80-9398-509B83879DFE@barrys-emacs.org> References: <25cd9ee1.7f5a.173fd266bea.Coremail.xuanwu348@163.com> <852BD06A-E035-4C80-9398-509B83879DFE@barrys-emacs.org> Message-ID: <8531adf.14ff.173ff233995.Coremail.xuanwu348@163.com> This means I want to structure my request header with "Connection: keep alive" for the server which support connect alive, But I checked the requeset header send by myself, the connection still closed, no affect by set And I also found this in python document: ============================== urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=None, cadefault=False, context=None) Open the URL url, which can be either a string or a Request object. data must be an object specifying additional data to be sent to the server, or None if no such data is needed. See Request for details. urllib.request module uses HTTP/1.1 and includes Connection:close header in its HTTP requests. =============================== Does it mean urllib.request don't support 'keep alive'? Thanks ? 2020-08-18 04:51:03?"Barry" ??? > > >> On 17 Aug 2020, at 18:23, xuanwu348 wrote: >> >> ?hi everyone >> >> >> Good day, the code as below, I try to make a long connection by set the connection to "keep-alive", but actually it's not as expected. Why? Thanks > >What this means is. Please web server keep the connect alive if you can. >The web server is allowed to close the connection if it wants too. > >Barry > >> >> >> import urllib.request as req >> headers = {"authorization": "Bearer {}".format(self.token), >> "Content-Type": "multipart/form-data; boundary={}".format(self.boundary), >> "Connection": "keep-alive"} >> request = req.Request(event_uri, headers=headers, data=data.encode("utf-8")) >> >> >> >> >> >> Accept-Encoding: identity >> >> Content-Length: 705 >> >> Host: 10.10.1.114:9443 >> >> User-Agent: Python-urllib/3.8 >> >> Authorization: Bearer a1.BUiPZxxxxxxxxxxxxxxxxxxCQdH2c9uegml >> >> Content-Type: multipart/form-data; boundary=--testtest-- >> >> Connection: close >> >> >> >> >> >> >> >> Best Regards >> -- >> https://mail.python.org/mailman/listinfo/python-list >> From thien.nguyen0707 at hcmut.edu.vn Mon Aug 17 23:31:48 2020 From: thien.nguyen0707 at hcmut.edu.vn (=?UTF-8?B?VGhpw6puIE5ndXnhu4VuIFRoYW5o?=) Date: Tue, 18 Aug 2020 10:31:48 +0700 Subject: Error Message-ID: Hi, I'm just starting to learn python. I try to install a socketio library. I got the following error [image: image.png] Please answer me with a detailed guide on how to solve the above problem!! Thanks. From thronobulax at gmail.com Mon Aug 17 23:53:33 2020 From: thronobulax at gmail.com (thronobulax at gmail.com) Date: Mon, 17 Aug 2020 20:53:33 -0700 (PDT) Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: On Monday, August 17, 2020 at 1:26:33 PM UTC-5, Chris Angelico wrote: > For context, see this commit: > > https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4 > > The commit message is highly politically charged and is now a > permanent part of the Python commit history. The Python Steering > Council has this to say: > > https://github.com/python/steering-council/issues/34#issuecomment-675028005 > > "The SC discussed this and ... we do not deplore the message." > > So now we know: go ahead and put all the political messages you like > into the commit messages, just don't put anything inappropriate into > the content. White supremacy has been mentioned; who wants to pick the > next hot topic? > > ChrisA "All animals are equal, but some animals are more equal than others." "We welcome a breadth of ideas so long as they agree with our views." "Truth is a social construct." "Math is evidence of white oppression." Hopefully, there are some alt-right programmers that can put this new dalliance with politics to the test. I, for one, want to watch the absurd right and the even more absurd left eat each each other. From ikorot01 at gmail.com Mon Aug 17 23:59:26 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Mon, 17 Aug 2020 22:59:26 -0500 Subject: Error In-Reply-To: References: Message-ID: Hi, On Mon, Aug 17, 2020, 10:52 PM Thi?n Nguy?n Thanh < thien.nguyen0707 at hcmut.edu.vn> wrote: > Hi, > I'm just starting to learn python. > I try to install a socketio library. > I got the following error > [image: image.png] > Please answer me with a detailed guide on how to solve the above problem!! > Thanks. > Unfortunately we will not be able to see the error as images are not going to the list. Please copy and paste an error Thank you.. -- > https://mail.python.org/mailman/listinfo/python-list > From thronobulax at gmail.com Mon Aug 17 23:56:21 2020 From: thronobulax at gmail.com (thronobulax at gmail.com) Date: Mon, 17 Aug 2020 20:56:21 -0700 (PDT) Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: On Monday, August 17, 2020 at 1:26:33 PM UTC-5, Chris Angelico wrote: > For context, see this commit: > > https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4 > > The commit message is highly politically charged and is now a > permanent part of the Python commit history. The Python Steering > Council has this to say: > > https://github.com/python/steering-council/issues/34#issuecomment-675028005 > > "The SC discussed this and ... we do not deplore the message." > > So now we know: go ahead and put all the political messages you like > into the commit messages, just don't put anything inappropriate into > the content. White supremacy has been mentioned; who wants to pick the > next hot topic? > > ChrisA It should be noted that these Darlings Of Conspicuous Caring are still using that - gasp! - horrid "master' branch. The very idea ... From thien.nguyen0707 at hcmut.edu.vn Tue Aug 18 00:04:48 2020 From: thien.nguyen0707 at hcmut.edu.vn (=?UTF-8?B?VGhpw6puIE5ndXnhu4VuIFRoYW5o?=) Date: Tue, 18 Aug 2020 11:04:48 +0700 Subject: Error In-Reply-To: References: Message-ID: Thank you for your response. it's in this file. V?o Th 3, 18 thg 8, 2020 va?o lu?c 10:59 Igor Korot ?? vi?t: > Hi, > > > > On Mon, Aug 17, 2020, 10:52 PM Thi?n Nguy?n Thanh < > thien.nguyen0707 at hcmut.edu.vn> wrote: > >> Hi, >> I'm just starting to learn python. >> I try to install a socketio library. >> I got the following error >> [image: image.png] >> Please answer me with a detailed guide on how to solve the above problem!! >> Thanks. >> > > Unfortunately we will not be able to see the error as images are not going > to the list. > > Please copy and paste an error > > Thank you.. > > > > -- >> https://mail.python.org/mailman/listinfo/python-list >> > -------------- next part -------------- C:\Users\cuong>python -m pip install socketio Collecting socketio Downloading socketio-0.2.1.tar.gz (6.1 kB) Collecting setuptools==3.3 Downloading setuptools-3.3-py2.py3-none-any.whl (545 kB) |????????????????????????????????| 545 kB 1.3 MB/s Collecting netifaces==0.10.6 Downloading netifaces-0.10.6.tar.gz (25 kB) Using legacy setup.py install for socketio, since package 'wheel' is not installed. Using legacy setup.py install for netifaces, since package 'wheel' is not installed. Installing collected packages: setuptools, netifaces, socketio Attempting uninstall: setuptools Found existing installation: setuptools 47.1.0 Uninstalling setuptools-47.1.0: Successfully uninstalled setuptools-47.1.0 Running setup.py install for netifaces ... error ERROR: Command errored out with exit status 1: command: 'C:\Users\cuong\AppData\Local\Programs\Python\Python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\cuong\\AppData\\Local\\Temp\\pip-install-4vphk1cj\\netifaces\\setup.py'"'"'; __file__='"'"'C:\\Users\\cuong\\AppData\\Local\\Temp\\pip-install-4vphk1cj\\netifaces\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\cuong\AppData\Local\Temp\pip-record-j_2aa79c\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\cuong\AppData\Local\Programs\Python\Python37\Include\netifaces' cwd: C:\Users\cuong\AppData\Local\Temp\pip-install-4vphk1cj\netifaces\ Complete output (11 lines): Traceback (most recent call last): File "", line 1, in File "C:\Users\cuong\AppData\Local\Programs\Python\Python37\lib\site-packages\setuptools\__init__.py", line 12, in from setuptools.extension import Extension File "C:\Users\cuong\AppData\Local\Programs\Python\Python37\lib\site-packages\setuptools\extension.py", line 7, in from setuptools.dist import _get_unpatched File "C:\Users\cuong\AppData\Local\Programs\Python\Python37\lib\site-packages\setuptools\dist.py", line 16, in import pkg_resources File "C:\Users\cuong\AppData\Local\Programs\Python\Python37\lib\site-packages\pkg_resources.py", line 1479, in register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider) AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader' ---------------------------------------- ERROR: Command errored out with exit status 1: 'C:\Users\cuong\AppData\Local\Programs\Python\Python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\cuong\\AppData\\Local\\Temp\\pip-install-4vphk1cj\\netifaces\\setup.py'"'"'; __file__='"'"'C:\\Users\\cuong\\AppData\\Local\\Temp\\pip-install-4vphk1cj\\netifaces\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\cuong\AppData\Local\Temp\pip-record-j_2aa79c\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\cuong\AppData\Local\Programs\Python\Python37\Include\netifaces' Check the logs for full command output. From ikorot01 at gmail.com Tue Aug 18 01:00:47 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 18 Aug 2020 00:00:47 -0500 Subject: Error In-Reply-To: References: Message-ID: Hi, On Mon, Aug 17, 2020 at 11:05 PM Thi?n Nguy?n Thanh wrote: > > Thank you for your response. > it's in this file. Please don't send any attachments to the list. There are very knowledgeable people here who will be able to help. Unfortunately they have vision problems. So, what is the problem with "copy-and-paste" the error message? Are you that lazy? ;-) Thank you. > > V?o Th 3, 18 thg 8, 2020 va?o lu?c 10:59 Igor Korot ?? vi?t: >> >> Hi, >> >> >> >> On Mon, Aug 17, 2020, 10:52 PM Thi?n Nguy?n Thanh wrote: >>> >>> Hi, >>> I'm just starting to learn python. >>> I try to install a socketio library. >>> I got the following error >>> [image: image.png] >>> Please answer me with a detailed guide on how to solve the above problem!! >>> Thanks. >> >> >> Unfortunately we will not be able to see the error as images are not going to the list. >> >> Please copy and paste an error >> >> Thank you.. >> >> >> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Tue Aug 18 01:02:43 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 18 Aug 2020 00:02:43 -0500 Subject: Error In-Reply-To: References: Message-ID: On Tue, Aug 18, 2020 at 12:00 AM Igor Korot wrote: > > Hi, > > On Mon, Aug 17, 2020 at 11:05 PM Thi?n Nguy?n Thanh > wrote: > > > > Thank you for your response. > > it's in this file. > > Please don't send any attachments to the list. > > There are very knowledgeable people here who will be able to help. > > Unfortunately they have vision problems. > > So, what is the problem with "copy-and-paste" the error message? > Are you that lazy? ;-) Besides for security reasons most people will not open attachments from unknown source, even if they are on *nix/Mac... So could you please, do that? Thank you. > > Thank you. > > > > > V?o Th 3, 18 thg 8, 2020 va?o lu?c 10:59 Igor Korot ?? vi?t: > >> > >> Hi, > >> > >> > >> > >> On Mon, Aug 17, 2020, 10:52 PM Thi?n Nguy?n Thanh wrote: > >>> > >>> Hi, > >>> I'm just starting to learn python. > >>> I try to install a socketio library. > >>> I got the following error > >>> [image: image.png] > >>> Please answer me with a detailed guide on how to solve the above problem!! > >>> Thanks. > >> > >> > >> Unfortunately we will not be able to see the error as images are not going to the list. > >> > >> Please copy and paste an error > >> > >> Thank you.. > >> > >> > >> > >>> -- > >>> https://mail.python.org/mailman/listinfo/python-list From walters.justin01 at gmail.com Tue Aug 18 01:22:20 2020 From: walters.justin01 at gmail.com (justin walters) Date: Mon, 17 Aug 2020 22:22:20 -0700 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: I for one don't want to see politics involved in PL development. However, inclusivity isn't a political issue, it's a human rights issue. Do I agree with the PR, not exactly. However, I do think we as a community should be accommodating to people Whose use of the English language differs from the standard as long as the meaning is clear. This thread reads like a bunch of old fuddy duddies complaining about immigrants not speaking perfect English at a fast food restaurant. Feel free to ban me from the list if this doesn't meet your standards. On Mon, Aug 17, 2020, 9:03 PM wrote: > On Monday, August 17, 2020 at 1:26:33 PM UTC-5, Chris Angelico wrote: > > For context, see this commit: > > > > > https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4 > > > > The commit message is highly politically charged and is now a > > permanent part of the Python commit history. The Python Steering > > Council has this to say: > > > > > https://github.com/python/steering-council/issues/34#issuecomment-675028005 > > > > "The SC discussed this and ... we do not deplore the message." > > > > So now we know: go ahead and put all the political messages you like > > into the commit messages, just don't put anything inappropriate into > > the content. White supremacy has been mentioned; who wants to pick the > > next hot topic? > > > > ChrisA > > It should be noted that these Darlings Of Conspicuous Caring are still > using that - gasp! - horrid "master' branch. The very idea ... > -- > https://mail.python.org/mailman/listinfo/python-list > From David.Raymond at tomtom.com Tue Aug 18 08:51:20 2020 From: David.Raymond at tomtom.com (David Raymond) Date: Tue, 18 Aug 2020 12:51:20 +0000 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: > Do I agree with the PR, not exactly. However, I do think we as a community > should be accommodating to people > Whose use of the English language differs from the standard as long as the > meaning is clear. Remember that the problem isn't the change in wording of the PEP. That's all well and good and not an issue. We're on board with what you just said and on board with the wording change. It's the commit message at the top (on the linked page) that's the issue. The commit message was not "hey, we are now being more accommodating and aware." The commit message was "hey, you're a racist white supremacist if you pick a specific standard." From Richard at Damon-Family.org Tue Aug 18 09:10:40 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Tue, 18 Aug 2020 09:10:40 -0400 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: <4d4127e5-d79a-50de-50ae-50a791fd8b4b@Damon-Family.org> On 8/18/20 1:22 AM, justin walters wrote: > I for one don't want to see politics involved in PL development. However, > inclusivity isn't a political issue, it's a human rights issue. > > Do I agree with the PR, not exactly. However, I do think we as a community > should be accommodating to people > Whose use of the English language differs from the standard as long as the > meaning is clear. > > This thread reads like a bunch of old fuddy duddies complaining about > immigrants not speaking perfect English at a fast food restaurant. > > Feel free to ban me from the list if this doesn't meet your standards. > One comment on this. I think the focus on the words that have been used is very much a '1st world problem'. Most of the people actually suffering from the problems being discusses would very much LOVE to be in a position where the discussion of what words are the right way to say something was their biggest issue. The forces behind these issues very much love to see our focus go to debating our speech, as opposed to actually DOING something about the issue. This isn't an accusation that those bringing up the speech issues are part of the dark forces behind the problems, but maybe a call to them to think about what really is the important issue. This also doesn't mean that language doesn't matter. If our language makes a Human Rights issue seem to be 'normal', that is bad, and weakens our resolve against it. Sometimes though, the right use of a word can be powerful, and analogies are great teachers. For example, talking (to a techie) how in a master-slave network, the master node has very strong control over what the slave node does, and then comparing that to a person, asking how would it feel to be that 'slave node', maybe even needing to wait for your 'master' to ask before you went to the bathroom, or be considered to be 'malfunctioning'. -- Richard Damon From rosuav at gmail.com Tue Aug 18 10:47:08 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 19 Aug 2020 00:47:08 +1000 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: <4d4127e5-d79a-50de-50ae-50a791fd8b4b@Damon-Family.org> References: <4d4127e5-d79a-50de-50ae-50a791fd8b4b@Damon-Family.org> Message-ID: On Tue, Aug 18, 2020 at 11:12 PM Richard Damon wrote: > > On 8/18/20 1:22 AM, justin walters wrote: > > I for one don't want to see politics involved in PL development. However, > > inclusivity isn't a political issue, it's a human rights issue. > > > > Do I agree with the PR, not exactly. However, I do think we as a community > > should be accommodating to people > > Whose use of the English language differs from the standard as long as the > > meaning is clear. > > > > This thread reads like a bunch of old fuddy duddies complaining about > > immigrants not speaking perfect English at a fast food restaurant. > > > > Feel free to ban me from the list if this doesn't meet your standards. > > > One comment on this. I think the focus on the words that have been used > is very much a '1st world problem'. Most of the people actually > suffering from the problems being discusses would very much LOVE to be > in a position where the discussion of what words are the right way to > say something was their biggest issue. The forces behind these issues > very much love to see our focus go to debating our speech, as opposed to > actually DOING something about the issue. This isn't an accusation that > those bringing up the speech issues are part of the dark forces behind > the problems, but maybe a call to them to think about what really is the > important issue. This was raised. And the commit message clearly associates a language standard with "white supremacy", the notion that certain people are inherently better than others. Is it a first-world problem to consider that light-skinned people are better than others? (No you don't have to answer that.) Had the commit message simply said "specific standards of English are unnecessary in a global project", there could have been a perfectly reasonable debate as to whether it's better to say "Strunk & White" or to say "please write clearly at all times". (And on that debate there are MANY valid points, including whether simple rules restrict or enhance freedom.) But it said that having a standard *at all* is proof that we all believe that white people are better than others. > This also doesn't mean that language doesn't matter. If our language > makes a Human Rights issue seem to be 'normal', that is bad, and weakens > our resolve against it. Sometimes though, the right use of a word can be > powerful, and analogies are great teachers. For example, talking (to a > techie) how in a master-slave network, the master node has very strong > control over what the slave node does, and then comparing that to a > person, asking how would it feel to be that 'slave node', maybe even > needing to wait for your 'master' to ask before you went to the > bathroom, or be considered to be 'malfunctioning'. TBH I think that removing "slave" from technical vocabulary is an oversimplification and overreaction. If you have people who are being treated as slaves, that is a problem. If you have people who are being treated as machines, that is also a problem. Do we need to abolish all use of "computer" and "robot" and "drone" from our technical language too? Or do we keep those terms around, and recognize that these are forms of dominance that must not be used between one human and another? Simply abolishing the words doesn't prevent the practice, and it just makes them into "dirty words" that are hard to discuss in any context. The replacement of "master hard drive" and "slave hard drive" with "primary" and "secondary" isn't itself a major issue, although I'm a bit annoyed at the churn that comes with sweeping changes. But where next? How many other terms need to be reviewed just to see if they could be misapplied to people? Are we going to get a "Black Pixels Matter" movement among LCD manufacturers? And none of this justifies burying something in a commit message. Which the Python Steering Council doesn't even want to declare was wrong. They are quite happy for the behaviour to continue. ChrisA From info at wingware.com Tue Aug 18 11:21:00 2020 From: info at wingware.com (Wingware) Date: Tue, 18 Aug 2020 11:21:00 -0400 Subject: ANN: Wing Python IDE version 7.2.4 has been released Message-ID: <5F3BF1DC.6070103@wingware.com> Wing 7.2.4 introduces support for Python 3.9, adds a preference to set the size of white space indicators, and makes a number of usability improvements. Details: https://wingware.com/news/2020-08-17 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 robin at reportlab.com Tue Aug 18 11:23:00 2020 From: robin at reportlab.com (Robin Becker) Date: Tue, 18 Aug 2020 16:23:00 +0100 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: On 18/08/2020 04:53, thronobulax at gmail.com wrote: > "Truth is a social construct." much as I deplore the politicization of computers, logic, maths and other areas of human interest by particular interest groups, according to some physicists, reality might be an observer based construct https://www.sciencemag.org/news/2020/08/quantum-paradox-points-shaky-foundations-reality ReportLab has quite a lot of colour based words; so far I've only had a few related emails :) which mostly seem to end up in spam -hoping to escape victimhood-ly yrs- Robin Becker From jpic at yourlabs.org Tue Aug 18 11:18:55 2020 From: jpic at yourlabs.org (J. Pic) Date: Tue, 18 Aug 2020 17:18:55 +0200 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <4d4127e5-d79a-50de-50ae-50a791fd8b4b@Damon-Family.org> Message-ID: I think this commit message is not enough: we should take it further and demand that Elwyn Brooks White choose change their last name to something less supremacist. Also: I've been waiting long enough to see this drama hit the chess world by itself so I'm explicitly making the suggestion here. From ikorot01 at gmail.com Tue Aug 18 11:40:40 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 18 Aug 2020 10:40:40 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <4d4127e5-d79a-50de-50ae-50a791fd8b4b@Damon-Family.org> Message-ID: Hi, On Tue, Aug 18, 2020 at 10:27 AM J. Pic wrote: > > I think this commit message is not enough: we should take it further > and demand that Elwyn Brooks White choose change their last name to > something less supremacist. > > Also: I've been waiting long enough to see this drama hit the chess > world by itself so I'm explicitly making the suggestion here. How dare you use "x" in the word "explicit"? Mr. Malcolm will not be pleased... Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From jpic at yourlabs.org Tue Aug 18 12:06:05 2020 From: jpic at yourlabs.org (J. Pic) Date: Tue, 18 Aug 2020 18:06:05 +0200 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <4d4127e5-d79a-50de-50ae-50a791fd8b4b@Damon-Family.org> Message-ID: I'm sorry Igor, I didn't mean to ruin your "conspiracy theories just hit the commit log day" From info at tundraware.com Tue Aug 18 12:22:39 2020 From: info at tundraware.com (Tim Daneliuk) Date: Tue, 18 Aug 2020 11:22:39 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: On 8/17/20 1:26 PM, Chris Angelico wrote: > For context, see this commit: > > https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4 > > The commit message is highly politically charged and is now a > permanent part of the Python commit history. The Python Steering > Council has this to say: > > https://github.com/python/steering-council/issues/34#issuecomment-675028005 > > "The SC discussed this and ... we do not deplore the message." > > So now we know: go ahead and put all the political messages you like > into the commit messages, just don't put anything inappropriate into > the content. White supremacy has been mentioned; who wants to pick the > next hot topic? > > ChrisA > Just a few thoughts here ... - While languages evolve over time, _in any given moment_ there are better and worse ways to express ideas in a given language. "The Elements Of Style" remains relevant today because it provides guidance on improving written clarity. It is not some blind defence of the perfect English. - Precision of language and precision of thought go hand in hand. Much of the grousing about languages standards (in this case, hiding in drag as social consciousness) is little more than intellectual laziness. In actual fact, our discipline has burned a lot of intellectual fuel in trying to find ways to be _more precise_ for things like specifications, formal semantics, and the like. - It is my consistent experience when working with non-native English speakers, that they wish to _improve_ their use and precision of the language, not simplify it. - Why is English the only target of these social pieties? You never hear these demands to relax these linguistic standards for, say, French, German, or Spanish. Similarly, where is the outcry to make Mandarin, Bantu, Swahili, or Arabic more approachable for Westerners? Methinks there is an ideological skunk in the parlor ... From giaym.mail at gmail.com Tue Aug 18 13:18:11 2020 From: giaym.mail at gmail.com (gia) Date: Tue, 18 Aug 2020 12:18:11 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: That's why I picked Math, it is also universally accepted, it's very strict, and it leaves the reader to decide its color based on themselves (it's not white btw :) On Tue, Aug 18, 2020 at 11:36 AM Tim Daneliuk wrote: > On 8/17/20 1:26 PM, Chris Angelico wrote: > > For context, see this commit: > > > > > https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4 > > > > The commit message is highly politically charged and is now a > > permanent part of the Python commit history. The Python Steering > > Council has this to say: > > > > > https://github.com/python/steering-council/issues/34#issuecomment-675028005 > > > > "The SC discussed this and ... we do not deplore the message." > > > > So now we know: go ahead and put all the political messages you like > > into the commit messages, just don't put anything inappropriate into > > the content. White supremacy has been mentioned; who wants to pick the > > next hot topic? > > > > ChrisA > > > Just a few thoughts here ... > > - While languages evolve over time, _in any given moment_ there are better > and worse ways to express ideas in a given language. "The Elements Of > Style" > remains relevant today because it provides guidance on improving > written clarity. It is not some blind defence of the > perfect English. > > - Precision of language and precision of thought go hand in hand. Much > of the grousing about languages standards (in this case, hiding in > drag as social consciousness) is little more than intellectual laziness. > In actual fact, our discipline has burned a lot of intellectual > fuel in trying to find ways to be _more precise_ for things like > specifications, formal semantics, and the like. > > - It is my consistent experience when working with non-native English > speakers, that they wish to _improve_ their use and precision of the > language, not simplify it. > > - Why is English the only target of these social pieties? You never > hear these demands to relax these linguistic standards for, say, French, > German, or Spanish. Similarly, where is the outcry to make > Mandarin, Bantu, Swahili, or Arabic more approachable for > Westerners? > > Methinks there is an ideological skunk in the parlor ... > > > -- > https://mail.python.org/mailman/listinfo/python-list > From walters.justin01 at gmail.com Tue Aug 18 13:28:26 2020 From: walters.justin01 at gmail.com (justin walters) Date: Tue, 18 Aug 2020 10:28:26 -0700 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: I believe the commit message was written in bad faith. It reeks of virtue signaling. Commit messages should remain purely technical in nature. However, I do think the change itself is valid. I don't care about the style of comments as long as they are clear and communicate their message well. How is that determined? During the PR review process. If you are performing a review and a comment is so poorly written that you can't figure out what it means, request improvements. Non technical discussion should be left out of commit messages and issues. Instead, that sort of discussion should take place on mailing lists, forums, and in person. As a community, we need to be more open to discussing these sort of topics without resorting to condescending remarks. I apologize for being ageist earlier as well. That was out of line. On Tue, Aug 18, 2020, 9:36 AM Tim Daneliuk wrote: > On 8/17/20 1:26 PM, Chris Angelico wrote: > > For context, see this commit: > > > > > https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4 > > > > The commit message is highly politically charged and is now a > > permanent part of the Python commit history. The Python Steering > > Council has this to say: > > > > > https://github.com/python/steering-council/issues/34#issuecomment-675028005 > > > > "The SC discussed this and ... we do not deplore the message." > > > > So now we know: go ahead and put all the political messages you like > > into the commit messages, just don't put anything inappropriate into > > the content. White supremacy has been mentioned; who wants to pick the > > next hot topic? > > > > ChrisA > > > Just a few thoughts here ... > > - While languages evolve over time, _in any given moment_ there are better > and worse ways to express ideas in a given language. "The Elements Of > Style" > remains relevant today because it provides guidance on improving > written clarity. It is not some blind defence of the > perfect English. > > - Precision of language and precision of thought go hand in hand. Much > of the grousing about languages standards (in this case, hiding in > drag as social consciousness) is little more than intellectual laziness. > In actual fact, our discipline has burned a lot of intellectual > fuel in trying to find ways to be _more precise_ for things like > specifications, formal semantics, and the like. > > - It is my consistent experience when working with non-native English > speakers, that they wish to _improve_ their use and precision of the > language, not simplify it. > > - Why is English the only target of these social pieties? You never > hear these demands to relax these linguistic standards for, say, French, > German, or Spanish. Similarly, where is the outcry to make > Mandarin, Bantu, Swahili, or Arabic more approachable for > Westerners? > > Methinks there is an ideological skunk in the parlor ... > > > -- > https://mail.python.org/mailman/listinfo/python-list > From cl at isbd.net Tue Aug 18 13:22:09 2020 From: cl at isbd.net (Chris Green) Date: Tue, 18 Aug 2020 18:22:09 +0100 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 Message-ID: <1bft0h-53an.ln1@esprimo.zbmc.eu> I have a fairly simple Python program that I wrote a while ago in Python 2 that transfers images from my camera to a date ordered directory hierarchy on my computer. I am trying to get it to work on Python 3 as I have just upgraded to Ubuntu 20.04 and on that Python 3 is now the default version of Python. I seem to be descending into a horrible morass of dependencies (or failed dependencies) when I try to install pyexiv2 (pr py3exiv2) using pip3. Can anyone point me at anywhere that might have some documentation that will help? The first problem (it might be the whole problem, I'm not sure) is which 'pyexiv2' I should be installing, there seem to be several apparently competing versions and it's not at all clear which is the most likely to work. On pypi there's py3exiv2 and pyexiv2 both of which claim to be for Python 3. On the http://py3exiv2.tuxfamily.org/ page it states: "py3exiv2 is the Python 3 version of pyexiv2 written for Python 2, ...", really! no wonder I'm confused. Essentially I need the python-pyexiv2 package for Ubuntu 20.04 and it's only available up to 19.10. -- Chris Green ? From rosuav at gmail.com Tue Aug 18 14:06:03 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 19 Aug 2020 04:06:03 +1000 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: <1bft0h-53an.ln1@esprimo.zbmc.eu> References: <1bft0h-53an.ln1@esprimo.zbmc.eu> Message-ID: On Wed, Aug 19, 2020 at 3:36 AM Chris Green wrote: > > I have a fairly simple Python program that I wrote a while ago in > Python 2 that transfers images from my camera to a date ordered > directory hierarchy on my computer. > > I am trying to get it to work on Python 3 as I have just upgraded to > Ubuntu 20.04 and on that Python 3 is now the default version of Python. > > I seem to be descending into a horrible morass of dependencies (or > failed dependencies) when I try to install pyexiv2 (pr py3exiv2) using > pip3. > > Can anyone point me at anywhere that might have some documentation > that will help? > > The first problem (it might be the whole problem, I'm not sure) is > which 'pyexiv2' I should be installing, there seem to be several > apparently competing versions and it's not at all clear which is the > most likely to work. On pypi there's py3exiv2 and pyexiv2 both of > which claim to be for Python 3. On the http://py3exiv2.tuxfamily.org/ > page it states: "py3exiv2 is the Python 3 version of pyexiv2 written > for Python 2, ...", really! no wonder I'm confused. > > Essentially I need the python-pyexiv2 package for Ubuntu 20.04 and > it's only available up to 19.10. > You might be partly out of luck. I'm not seeing any pyexiv package for Python 3 either in Ubuntu or Debian. But there is another way: you might be able to just install it with pip. You mentioned that it's on PyPI, so try this: python3 -m pip install py3exiv2 (best inside a virtual environment, but otherwise you might need sudo) My reading of the PyPI pages is that the original Python 2 library was created by one person (Michael Vanslembrouck), and then someone else (VinsS) did the Python 3 port, which means it had to get a different name. You could agitate to get py3exiv2 added to the Ubuntu repositories, but in the meantime, if you can install it with pip, that should be viable. I install most things using pip, but then, I also tend to have versions of Python that aren't supported by upstream (*cough* currently running 3.10...) :) ChrisA From barry at barrys-emacs.org Tue Aug 18 14:35:42 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Tue, 18 Aug 2020 19:35:42 +0100 Subject: =?utf-8?Q?Re=3A_why_the_connection_set_with_=E2=80=9Ckeep_live?= =?utf-8?Q?=E2=80=9D_in_urllib=2Erequest_always_set_to_be=E2=80=9Cclosed?= =?utf-8?Q?=2C_thanks?= In-Reply-To: <8531adf.14ff.173ff233995.Coremail.xuanwu348@163.com> References: <25cd9ee1.7f5a.173fd266bea.Coremail.xuanwu348@163.com> <852BD06A-E035-4C80-9398-509B83879DFE@barrys-emacs.org> <8531adf.14ff.173ff233995.Coremail.xuanwu348@163.com> Message-ID: > On 18 Aug 2020, at 02:16, xuanwu348 wrote: > > > This means I want to structure my request header with "Connection: keep alive" for the server which support connect alive, > But I checked the requeset header send by myself, the connection still closed, no affect by set > > And I also found this in python document: > ============================== > urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=None, cadefault=False, context=None) > Open the URL url, which can be either a string or a Request object. > > data must be an object specifying additional data to be sent to the server, or None if no such data is needed. See Request for details. > > urllib.request module uses HTTP/1.1 and includes Connection:close header in its HTTP requests. > > =============================== > Does it mean urllib.request don't support 'keep alive'? The term in HTTP 1.1 is persistent connections. See https://tools.ietf.org/html/rfc2616#section-8.1 The server will assume persistent connections for the reasons documented. Since you have seen requests sending "Connection: close" that is saying to the server that persistent connection is not required. The server will send the response and close its end. Sounds like you need to use another library to allow you to use the persistent connection. If you know your way around TCP sockets and protocols this is not that hard to write the code to do persistent connections for a client. Maybe look at a library like twisted? Its got all the building blocks you need to handle persistent connections. Barry > > Thanks > > > > > ? 2020-08-18 04:51:03?"Barry" ??? > > > > > >> On 17 Aug 2020, at 18:23, xuanwu348 wrote: > >> > >> ?hi everyone > >> > >> > >> Good day, the code as below, I try to make a long connection by set the connection to "keep-alive", but actually it's not as expected. Why? Thanks > > > >What this means is. Please web server keep the connect alive if you can. > >The web server is allowed to close the connection if it wants too. > > > >Barry > > > >> > >> > >> import urllib.request as req > >> headers = {"authorization": "Bearer {}".format(self.token), > >> "Content-Type": "multipart/form-data; boundary={}".format(self.boundary), > >> "Connection": "keep-alive"} > >> request = req.Request(event_uri, headers=headers, data=data.encode("utf-8")) > >> > >> > >> > >> > >> > >> Accept-Encoding: identity > >> > >> Content-Length: 705 > >> > >> Host: 10.10.1.114:9443 > >> > >> User-Agent: Python-urllib/3.8 > >> > >> Authorization: Bearer a1.BUiPZxxxxxxxxxxxxxxxxxxCQdH2c9uegml > >> > >> Content-Type: multipart/form-data; boundary=--testtest-- > >> > >> Connection: close > >> > >> > >> > >> > >> > >> > >> > >> Best Regards > >> -- > >> https://mail.python.org/mailman/listinfo/python-list > >> > > > From info at tundraware.com Tue Aug 18 14:45:59 2020 From: info at tundraware.com (Tim Daneliuk) Date: Tue, 18 Aug 2020 13:45:59 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: <78kt0h-5si1.ln1@oceanview.tundraware.com> On 8/18/20 12:28 PM, justin walters wrote: > I apologize for being ageist earlier as well. That was out of line. I am likely older than you and there is no reason to apologise. Only the profoundly undeveloped psyche takes every opportunity to find offense when none is intended. It is the sign of a puerile mind, irrespective of actual chronological age. Feel free to be as "ageist" as you wish ... only make it funny or biting ... From vincent.vande.vyvre at telenet.be Tue Aug 18 15:05:20 2020 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Tue, 18 Aug 2020 21:05:20 +0200 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: <1bft0h-53an.ln1@esprimo.zbmc.eu> References: <1bft0h-53an.ln1@esprimo.zbmc.eu> Message-ID: <9728fe5d-7951-b434-7d9f-c34610ae54de@telenet.be> Le 18/08/20 ? 19:22, Chris Green a ?crit?: > I have a fairly simple Python program that I wrote a while ago in > Python 2 that transfers images from my camera to a date ordered > directory hierarchy on my computer. > > I am trying to get it to work on Python 3 as I have just upgraded to > Ubuntu 20.04 and on that Python 3 is now the default version of Python. > > I seem to be descending into a horrible morass of dependencies (or > failed dependencies) when I try to install pyexiv2 (pr py3exiv2) using > pip3. > > Can anyone point me at anywhere that might have some documentation > that will help? > > The first problem (it might be the whole problem, I'm not sure) is > which 'pyexiv2' I should be installing, there seem to be several > apparently competing versions and it's not at all clear which is the > most likely to work. On pypi there's py3exiv2 and pyexiv2 both of > which claim to be for Python 3. On the http://py3exiv2.tuxfamily.org/ > page it states: "py3exiv2 is the Python 3 version of pyexiv2 written > for Python 2, ...", really! no wonder I'm confused. > > Essentially I need the python-pyexiv2 package for Ubuntu 20.04 and > it's only available up to 19.10. > Hi, Two solutions: 1. Install exiv2-dev and py3exiv2 with pip ??? $ sudo apt-get install libexiv2-dev ??? $ sudo pip3 install py3exiv2 2. Install my ppa ??? $ sudo add-apt-repository ppa:vincent-vandevyvre/vvv ??? $ sudo apt-get update ??? $ sudo apt-get install python3-exiv2 Don't change your old code for pyexiv2, the names of the modules are unchanged, your old code should work as it. Off course old strings are now unicode. Vincent (AKA VinsS) From aeros167 at gmail.com Tue Aug 18 17:10:51 2020 From: aeros167 at gmail.com (Kyle Stanley) Date: Tue, 18 Aug 2020 17:10:51 -0400 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: On Mon, Aug 17, 2020 at 2:37 PM Chris Angelico wrote: > Yes. I was hoping for "we should rewrite that commit", and would have > been content with "we won't rewrite it, but we don't want that > repeated". But the SC said that it is absolutely fine to write commit > messages like that. > While I'm also not entirely content with the outcome (specifically that the commit message would have been left as-is, even if it was easy to edit post-merge) and would have liked to see a similar statement along the lines of the above, I don't consider the current statement by the SC to be saying that it's "absolutely fine" to write similar commit messages in the future. Instead, I interpret it as the SC collectively not being strongly against the commit message in question enough to make an amendment; e.g. they don't consider it egregious enough to take direct action or publicly condemn it, and possibly that doing so would not result in a net benefit to the Python development community. This interpretation may require a bit of reading between the lines because there was no explicit mention by the SC of the commit message being problematic. However, if they considered it to be perfectly fine and having no issues at all, I think it would have been said outright, and this issue would have ended a long time ago instead of them addressing it several times. Going forward, I think the drama from this situation alone will cause us core developers to more carefully assess commit messages before going forward with merging PRs to ensure they focus on the changes being made. When I find the spare cycles to do so, I'm also hoping that I can make a minor addition to the "Making Good Commits" section of the devguide , to guide future commit messages towards focusing on a technical summary of the changes made and avoiding unrelated commentary. In the meantime, I don't think there's anything productive we can gain from further discussion of this particular commit message. At the end of the day, I suspect it will become buried in the git history and forgotten about since it was associated with a minor change. If anything, further threads about it will just end up bringing more attention to the message than it would have otherwise received. Instead of exhausting more cycles on this, I'd just like to move past this issue and go back to what I actually care about - contributing to Python. From rosuav at gmail.com Tue Aug 18 17:39:57 2020 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 19 Aug 2020 07:39:57 +1000 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: On Wed, Aug 19, 2020 at 7:11 AM Kyle Stanley wrote: > > On Mon, Aug 17, 2020 at 2:37 PM Chris Angelico wrote: >> >> Yes. I was hoping for "we should rewrite that commit", and would have >> been content with "we won't rewrite it, but we don't want that >> repeated". But the SC said that it is absolutely fine to write commit >> messages like that. > > > While I'm also not entirely content with the outcome (specifically that the commit message would have been left as-is, even if it was easy to edit post-merge) and would have liked to see a similar statement along the lines of the above, I don't consider the current statement by the SC to be saying that it's "absolutely fine" to write similar commit messages in the future. Instead, I interpret it as the SC collectively not being strongly against the commit message in question enough to make an amendment; e.g. they don't consider it egregious enough to take direct action or publicly condemn it, and possibly that doing so would not result in a net benefit to the Python development community. > If you read the thread above the post in question, you'll find that the SC specifically decided NOT to speak out against the commit message. I was asking for them to make a statement saying that the message was unacceptable and should not be repeated, and they decided not to. In other words, it's not just that they aren't editing it, but they are actively refusing to reject future commits on the same lines. "Even if it was easy to edit post-merge we would still leave the message as-is". It's not "too much upheaval to edit it now, it's too late, leave it there". It's "even if it were easy we still wouldn't, because we don't dislike this commit message". If I'm misinterpreting that, please can a SC member explain in more detail what the statement actually means? Otherwise, I have to assume that the SC approves of it. ChrisA From dbsanznt at gmail.com Tue Aug 18 18:23:28 2020 From: dbsanznt at gmail.com (Jamelaumn) Date: Tue, 18 Aug 2020 22:23:28 +0000 Subject: LittleRookie References: Message-ID: i would say i'm new at programing i have a year of experience in python(but i'm tottaly a noob) i guess i'm starting to learn SQL now.What should i do to learn better and faster? From dbsanznt at gmail.com Tue Aug 18 18:26:09 2020 From: dbsanznt at gmail.com (Jamelaumn) Date: Tue, 18 Aug 2020 22:26:09 +0000 Subject: LittleRookie Message-ID: <68f53112b5f4f8644d0d5a4eb059d9b0$1@dkzerogt6z6ybhcj.onion> i would say i'm new at programing i have a year of experience in python(but i'm tottaly a noob) i guess i'm starting to learn SQL now.What should i do to learn better and faster? From ikorot01 at gmail.com Tue Aug 18 18:40:29 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 18 Aug 2020 17:40:29 -0500 Subject: LittleRookie In-Reply-To: <68f53112b5f4f8644d0d5a4eb059d9b0$1@dkzerogt6z6ybhcj.onion> References: <68f53112b5f4f8644d0d5a4eb059d9b0$1@dkzerogt6z6ybhcj.onion> Message-ID: Hi, On Tue, Aug 18, 2020, 5:32 PM Jamelaumn wrote: > i would say i'm new at programing i have a year of experience in > python(but i'm tottaly a noob) i guess i'm starting to learn SQL now.What > should i do to learn better and faster? > Enroll in the local college and start your journey there? Successfully finish it and get an internship. Follow with it, get to know people. Continue working in the area. Thank you. -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Tue Aug 18 19:06:54 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 19 Aug 2020 11:06:54 +1200 Subject: LittleRookie In-Reply-To: References: <68f53112b5f4f8644d0d5a4eb059d9b0$1@dkzerogt6z6ybhcj.onion> Message-ID: <25553f2a-0385-f220-4ad7-2efef08e0a62@DancesWithMice.info> >> i would say i'm new at programing i have a year of experience in >> python(but i'm tottaly a noob) i guess i'm starting to learn SQL now.What >> should i do to learn better and faster? >> > > Enroll in the local college and start your journey there? > Successfully finish it and get an internship. > Follow with it, get to know people. > Continue working in the area. +1, not only learning Python but making valuable contacts! However, if you are taking advantage of a COVID-19 'lock-down', and are happy to work from home; consider the Python offerings from Coursera.org and edX.org, eg U.Michigan's series. These start-from-scratch, so will give you the opportunity to review existing knowledge, as appropriate; and continue onwards-and-upwards. Alternately, you could jump-in at whichever level you feel comfortable. From memory(!?) there are specific courses on Python I/O, and Python i/a with DBs. BTW such courses are often available either for-free or $certification. Conversely, if you'd prefer to major on the SQL side (and use Python as the app-language!) there are plenty of courses covering that topic as well. Yesterday I was shown: Create a Database with the Modeling Tool in MySQL Workbench (https://www.coursera.org/projects/create-database-with-modeling-tool-mysql-workbench) - amongst other short-sharp offerings featuring the MySQL Workbench DBA tool (and possibly more). At a more general interest, please review Stanford's on-line offerings (they've recently/finally moved off their own platform to edX) at https://www.edx.org/school/stanfordonline (ignoring all 'the other stuff'). Personal recommendation: anything with Jennifer Widom is worth attending! -- Regards =dn Disclaimer: I use the edX platform, but not for Python training. From torriem at gmail.com Tue Aug 18 19:12:31 2020 From: torriem at gmail.com (Michael Torrie) Date: Tue, 18 Aug 2020 17:12:31 -0600 Subject: LittleRookie In-Reply-To: <68f53112b5f4f8644d0d5a4eb059d9b0$1@dkzerogt6z6ybhcj.onion> References: <68f53112b5f4f8644d0d5a4eb059d9b0$1@dkzerogt6z6ybhcj.onion> Message-ID: <24d9dd45-11bc-fd96-f5b3-66531909016b@gmail.com> On 8/18/20 4:26 PM, Jamelaumn wrote: > i would say i'm new at programing i have a year of experience in python(but i'm tottaly a noob) i guess i'm starting to learn SQL now.What should i do to learn better and faster? The only way is to build something with it. Solve a problem with Python. Make a web site with Django or another popular Python web framework. Write a script that processes some data you need. Could be anything. From rmlibre at riseup.net Tue Aug 18 19:34:23 2020 From: rmlibre at riseup.net (rmlibre at riseup.net) Date: Tue, 18 Aug 2020 16:34:23 -0700 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> There are many reasons Elements is a terrible English style guide: https://www.pure.ed.ac.uk/ws/files/8520953/PULLUM_2010_The_land_of_the_free_and_the_elements_of_style.pdf I would kindly recommend that folks just educate themselves on what white supremacy is & how it continues in both subtle & overt ways to this day. Sadly, getting extremely upset after being exposed to the accurate term white supremacy is a symptom of what's called 'white fragility' by psychologists who study the social pathologies of racism & its long-lasting, inter-generational impacts on society. You need serious help with processing your anger if you look at everything that's happening in the world & bubble in anger over a commit message that is simply acknowledging a social ill. One of countless many. I do hope you get the help you need. I would also caution against relying on the idea of human rights when defending against accusations of being political, since they too are political. Life is political. We continue to this day trying to redefine, as a society, what human rights are, & who is considered to deserve them. That process is politics. Some people think that being called white is racist. Other people think that having their land & children stolen because of their race & being forced to write in the language of their captors is racist. One group is deflecting blame for the worst atrocities in history, the other is acknowledging a real problem & seeking accountability in everyday life. Resources: A People's History of the United States: https://mvlindsey.files.wordpress.com/2015/08/peoples-history-zinn-1980.pdf The Invention of the White Race: Volume II: http://ouleft.org/wp-content/uploads/Invention-White-Race-Vol2-Allen.pdf > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. why the connection set with ?keep live? in urllib.request > always set to be?closed, thanks (xuanwu348) > 2. Final statement from Steering Council on politically-charged > commit messages (Chris Angelico) > 3. Re: Final statement from Steering Council on > politically-charged commit messages (Dylan Distasio) > 4. Re: Final statement from Steering Council on > politically-charged commit messages (Chris Angelico) > 5. Re: Final statement from Steering Council on > politically-charged commit messages (gia) > 6. Re: why the connection set with ?keep live? in urllib.request > always set to be?closed, thanks (Barry) > 7. Re:Re: why the connection set with ?keep live? in > urllib.request always set to be?closed, thanks (xuanwu348) > 8. Error (Thi?n Nguy?n Thanh) > 9. Re: Final statement from Steering Council on > politically-charged commit messages (thronobulax at gmail.com) > 10. Re: Error (Igor Korot) > 11. Re: Final statement from Steering Council on > politically-charged commit messages (thronobulax at gmail.com) > 12. Re: Error (Thi?n Nguy?n Thanh) > 13. Re: Error (Igor Korot) > 14. Re: Error (Igor Korot) > 15. Re: Final statement from Steering Council on > politically-charged commit messages (justin walters) > 16. RE: Final statement from Steering Council on > politically-charged commit messages (David Raymond) > 17. Re: Final statement from Steering Council on > politically-charged commit messages (Richard Damon) > 18. Re: Final statement from Steering Council on > politically-charged commit messages (Chris Angelico) > 19. ANN: Wing Python IDE version 7.2.4 has been released (Wingware) > 20. Re: Final statement from Steering Council on > politically-charged commit messages (Robin Becker) > 21. Re: Final statement from Steering Council on > politically-charged commit messages (J. Pic) > 22. Re: Final statement from Steering Council on > politically-charged commit messages (Igor Korot) From giaym.mail at gmail.com Tue Aug 18 20:47:47 2020 From: giaym.mail at gmail.com (gia) Date: Tue, 18 Aug 2020 19:47:47 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> Message-ID: Trafficking of people is a very current problem, and it is not a race issue, as people of all races are abducted by people of all races. Yes, right now. If you are so strong about ending that suffering, I suggest you focus on the present and stop wading in the past. On Tue, Aug 18, 2020 at 6:36 PM wrote: > There are many reasons Elements is a terrible English style guide: > > https://www.pure.ed.ac.uk/ws/files/8520953/PULLUM_2010_The_land_of_the_free_and_the_elements_of_style.pdf > > I would kindly recommend that folks just educate themselves on what > white supremacy is & how it continues in both subtle & overt ways to > this day. Sadly, getting extremely upset after being exposed to the > accurate term white supremacy is a symptom of what's called 'white > fragility' by psychologists who study the social pathologies of racism & > its long-lasting, inter-generational impacts on society. > > You need serious help with processing your anger if you look at > everything that's happening in the world & bubble in anger over a commit > message that is simply acknowledging a social ill. One of countless > many. I do hope you get the help you need. > > I would also caution against relying on the idea of human rights when > defending against accusations of being political, since they too are > political. Life is political. We continue to this day trying to > redefine, as a society, what human rights are, & who is considered to > deserve them. That process is politics. > > Some people think that being called white is racist. Other people think > that having their land & children stolen because of their race & being > forced to write in the language of their captors is racist. One group is > deflecting blame for the worst atrocities in history, the other is > acknowledging a real problem & seeking accountability in everyday life. > > > Resources: > A People's History of the United States: > https://mvlindsey.files.wordpress.com/2015/08/peoples-history-zinn-1980.pdf > The Invention of the White Race: Volume II: > http://ouleft.org/wp-content/uploads/Invention-White-Race-Vol2-Allen.pdf > > > > > python-list at python.org > > > > To subscribe or unsubscribe via the World Wide Web, visit > > https://mail.python.org/mailman/listinfo/python-list > > or, via email, send a message with subject or body 'help' to > > python-list-request at python.org > > > > You can reach the person managing the list at > > python-list-owner at python.org > > > > When replying, please edit your Subject line so it is more specific > > than "Re: Contents of Python-list digest..." > > > > Today's Topics: > > > > 1. why the connection set with ?keep live? in urllib.request > > always set to be?closed, thanks (xuanwu348) > > 2. Final statement from Steering Council on politically-charged > > commit messages (Chris Angelico) > > 3. Re: Final statement from Steering Council on > > politically-charged commit messages (Dylan Distasio) > > 4. Re: Final statement from Steering Council on > > politically-charged commit messages (Chris Angelico) > > 5. Re: Final statement from Steering Council on > > politically-charged commit messages (gia) > > 6. Re: why the connection set with ?keep live? in urllib.request > > always set to be?closed, thanks (Barry) > > 7. Re:Re: why the connection set with ?keep live? in > > urllib.request always set to be?closed, thanks (xuanwu348) > > 8. Error (Thi?n Nguy?n Thanh) > > 9. Re: Final statement from Steering Council on > > politically-charged commit messages (thronobulax at gmail.com) > > 10. Re: Error (Igor Korot) > > 11. Re: Final statement from Steering Council on > > politically-charged commit messages (thronobulax at gmail.com) > > 12. Re: Error (Thi?n Nguy?n Thanh) > > 13. Re: Error (Igor Korot) > > 14. Re: Error (Igor Korot) > > 15. Re: Final statement from Steering Council on > > politically-charged commit messages (justin walters) > > 16. RE: Final statement from Steering Council on > > politically-charged commit messages (David Raymond) > > 17. Re: Final statement from Steering Council on > > politically-charged commit messages (Richard Damon) > > 18. Re: Final statement from Steering Council on > > politically-charged commit messages (Chris Angelico) > > 19. ANN: Wing Python IDE version 7.2.4 has been released (Wingware) > > 20. Re: Final statement from Steering Council on > > politically-charged commit messages (Robin Becker) > > 21. Re: Final statement from Steering Council on > > politically-charged commit messages (J. Pic) > > 22. Re: Final statement from Steering Council on > > politically-charged commit messages (Igor Korot) > -- > https://mail.python.org/mailman/listinfo/python-list > From Richard at Damon-Family.org Tue Aug 18 21:13:42 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Tue, 18 Aug 2020 21:13:42 -0400 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> Message-ID: <55d3bdd0-30b1-0b01-ea75-a06e39b87aa4@Damon-Family.org> On 8/18/20 7:34 PM, rmlibre at riseup.net wrote: > I would also caution against relying on the idea of human rights when > defending against accusations of being political, since they too are > political. Life is political. We continue to this day trying to > redefine, as a society, what human rights are, & who is considered to > deserve them. That process is politics. I will challenge STRONGLY the believe that all right are political in nature. That attitude is the path of tyranny, for if rights only come by the will of the government, then the government is in its right to take them all away. The American Deceleration of Independence states it well (Yes, I know we are not all Americans): *We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness.* Without an ideal like this, that the basic rights come out of something bigger than ourselves, we have no basis to decide on what is a right. In fact, if we declare that rights are purely a political decision, we have no right to complain about past abuses that were within what the then society decide was right, or at the very least if we want to say they were wrong, we have to accept just as validly their concept that WE are just as wrong. Politics may be the process to hammer out the details, but if politics does not look to the ruling of the truly higher power, it has no authority, except might, to enforce it. If we accept might as the right and power to rule, we need to accept that it was and will be the right and power, and accept what it brought and will bring. -- Richard Damon From info at tundraware.com Tue Aug 18 21:03:36 2020 From: info at tundraware.com (Tim Daneliuk) Date: Tue, 18 Aug 2020 20:03:36 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> Message-ID: On 8/18/20 6:34 PM, rmlibre at riseup.net wrote: > I would kindly recommend that folks just educate themselves on what I would also like to help you become educated. Be sure to check out these literary treasures - they are the foundation of the worldview you are espousing: The_Origin of the Family, Private Property, and the State - Engels Das Kapital - Marx On Guerrilla Warfare - Mao Your claims to virtue are a fraud. From info at tundraware.com Tue Aug 18 21:06:39 2020 From: info at tundraware.com (Tim Daneliuk) Date: Tue, 18 Aug 2020 20:06:39 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> Message-ID: On 8/18/20 6:34 PM, rmlibre at riseup.net wrote: > I would kindly recommend that folks just educate themselves on what Speaking of being educated ... Could you please do an exposition for all us ignorant types on the books that really animate your worldview: The_Origin of the Family, Private Property, and the State - Engels Das Kapital - Marx On Guerrilla Warfare - Mao There are many noble causes for which to fight. Yours isn't one of them. From xuanwu348 at 163.com Tue Aug 18 21:33:08 2020 From: xuanwu348 at 163.com (xuanwu348) Date: Wed, 19 Aug 2020 09:33:08 +0800 (CST) Subject: =?UTF-8?Q?Re:Re:_why_the_connectio?= =?UTF-8?Q?n_set_with_=E2=80=9Ckeep_live=E2=80=9D_i?= =?UTF-8?Q?n_urllib.request_always_set_to_be=E2=80=9Cclosed,_thanks?= In-Reply-To: References: <25cd9ee1.7f5a.173fd266bea.Coremail.xuanwu348@163.com> <852BD06A-E035-4C80-9398-509B83879DFE@barrys-emacs.org> <8531adf.14ff.173ff233995.Coremail.xuanwu348@163.com> Message-ID: <701f81f5.1673.17404593176.Coremail.xuanwu348@163.com> Thanks all, I had met this problem was when I did restapi test. I send a request by python script and the time processed by server very short, and another request send by postman, the time seems normal, I compare the diff between these two request, obvious difference is the connection, which in postman request was keep-alive and in python script's was closed. So I try to found out if it was the cause. And at last we found that not the reason triggered this problem, and the really reason lead the problem is the parameter I transfered in json body. and thanks for the links you provid, I will read into them. Best Regards At 2020-08-19 02:35:42, "Barry Scott" wrote: On 18 Aug 2020, at 02:16, xuanwu348 wrote: This means I want to structure my request header with "Connection: keep alive" for the server which support connect alive, But I checked the requeset header send by myself, the connection still closed, no affect by set And I also found this in python document: ============================== urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=None, cadefault=False, context=None) Open the URL url, which can be either a string or a Request object. data must be an object specifying additional data to be sent to the server, or None if no such data is needed. See Request for details. urllib.request module uses HTTP/1.1 and includes Connection:close header in its HTTP requests. =============================== Does it mean urllib.request don't support 'keep alive'? The term in HTTP 1.1 is persistent connections. See https://tools.ietf.org/html/rfc2616#section-8.1 The server will assume persistent connections for the reasons documented. Since you have seen requests sending "Connection: close" that is saying to the server that persistent connection is not required. The server will send the response and close its end. Sounds like you need to use another library to allow you to use the persistent connection. If you know your way around TCP sockets and protocols this is not that hard to write the code to do persistent connections for a client. Maybe look at a library like twisted? Its got all the building blocks you need to handle persistent connections. Barry Thanks ? 2020-08-18 04:51:03?"Barry" ??? > > >> On 17 Aug 2020, at 18:23, xuanwu348 wrote: >> >> ?hi everyone >> >> >> Good day, the code as below, I try to make a long connection by set the connection to "keep-alive", but actually it's not as expected. Why? Thanks > >What this means is. Please web server keep the connect alive if you can. >The web server is allowed to close the connection if it wants too. > >Barry > >> >> >> import urllib.request as req >> headers = {"authorization": "Bearer {}".format(self.token), >> "Content-Type": "multipart/form-data; boundary={}".format(self.boundary), >> "Connection": "keep-alive"} >> request = req.Request(event_uri, headers=headers, data=data.encode("utf-8")) >> >> >> >> >> >> Accept-Encoding: identity >> >> Content-Length: 705 >> >> Host: 10.10.1.114:9443 >> >> User-Agent: Python-urllib/3.8 >> >> Authorization: Bearer a1.BUiPZxxxxxxxxxxxxxxxxxxCQdH2c9uegml >> >> Content-Type: multipart/form-data; boundary=--testtest-- >> >> Connection: close >> >> >> >> >> >> >> >> Best Regards >> -- >> https://mail.python.org/mailman/listinfo/python-list >> From dbsanznt at gmail.com Tue Aug 18 22:07:47 2020 From: dbsanznt at gmail.com (Jamelaumn) Date: Wed, 19 Aug 2020 02:07:47 +0000 Subject: LittleRookie References: <68f53112b5f4f8644d0d5a4eb059d9b0$1@dkzerogt6z6ybhcj.onion> <25553f2a-0385-f220-4ad7-2efef08e0a62@DancesWithMice.info> Message-ID: <83bab19780502663d8d0807a6a41bf14$1@dkzerogt6z6ybhcj.onion> <3 thank u guys i will try get better From dbsanznt at gmail.com Tue Aug 18 22:19:31 2020 From: dbsanznt at gmail.com (Jamelaumn) Date: Wed, 19 Aug 2020 02:19:31 +0000 Subject: LittleRookie References: <68f53112b5f4f8644d0d5a4eb059d9b0$1@dkzerogt6z6ybhcj.onion> <25553f2a-0385-f220-4ad7-2efef08e0a62@DancesWithMice.info> Message-ID: <562ffccc86982f6cc165c3b5f88a0e79$1@dkzerogt6z6ybhcj.onion> actually for me to sign for any online courses like stanford etc... if it's needed any document i couldnt get in because i have none i'm from brazil :v anyway thank u guys ;) i will try find something From klsshaeffer at icloud.com Wed Aug 19 00:14:28 2020 From: klsshaeffer at icloud.com (Karen Shaeffer) Date: Tue, 18 Aug 2020 21:14:28 -0700 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: <55d3bdd0-30b1-0b01-ea75-a06e39b87aa4@Damon-Family.org> References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> <55d3bdd0-30b1-0b01-ea75-a06e39b87aa4@Damon-Family.org> Message-ID: <15ADF74E-5223-4BF1-91F6-830FBEEA0BD7@icloud.com> > On Aug 18, 2020, at 6:13 PM, Richard Damon wrote: > > On 8/18/20 7:34 PM, rmlibre at riseup.net wrote: >> I would also caution against relying on the idea of human rights when >> defending against accusations of being political, since they too are >> political. Life is political. We continue to this day trying to >> redefine, as a society, what human rights are, & who is considered to >> deserve them. That process is politics. > > I will challenge STRONGLY the believe that all right are political in > nature. That attitude is the path of tyranny, for if rights only come by > the will of the government, then the government is in its right to take > them all away. > > The American Deceleration of Independence states it well (Yes, I know we > are not all Americans): > > *We hold these truths to be self-evident, that all men are created > equal, that they are endowed by their Creator with certain unalienable > Rights, that among these are Life, Liberty and the pursuit of Happiness.* > With all due respect: The American Declaration of Independence is a political document that had no power of authority. Soon afterwards, that same group of white, wealthy land-owning men wrote the US Constitution, which, in it?s original form, only protected the _God_ given rights of those same white, wealthy, land-owning folks, leaving all the other rights and protections to the states ? because the slave owning states would only join the union under those circumstances. This is the doctrine of State?s rights. Indeed, several of those white, wealthy, land-owning folks who contributed to the creation of the US Constitution were in fact slave owners. Imagine that ? slave owners created a document declaring all men are created equal! Of course, women had no rights either. And LGBTQ folks would be killed back in those days. Indeed, transgender folks continue to be at risk of death today ? just because of who they are. In practice, all rights are granted by political power. In the United States, untold thousands of men and women have fought and died to protect that political power. I hope you continue to learn and grow with experience and come to appreciate the nature of life on the ground in the flesh and blood. On the ground, only political power and the force behind it sustains the rights we enjoy in the United States. Democracy is an act. ? The late John Lewis humbly, kls From cl at isbd.net Wed Aug 19 03:53:58 2020 From: cl at isbd.net (Chris Green) Date: Wed, 19 Aug 2020 08:53:58 +0100 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 References: <1bft0h-53an.ln1@esprimo.zbmc.eu> Message-ID: Chris Angelico wrote: > On Wed, Aug 19, 2020 at 3:36 AM Chris Green wrote: > > > > I have a fairly simple Python program that I wrote a while ago in > > Python 2 that transfers images from my camera to a date ordered > > directory hierarchy on my computer. > > > > I am trying to get it to work on Python 3 as I have just upgraded to > > Ubuntu 20.04 and on that Python 3 is now the default version of Python. > > > > I seem to be descending into a horrible morass of dependencies (or > > failed dependencies) when I try to install pyexiv2 (pr py3exiv2) using > > pip3. > > > > Can anyone point me at anywhere that might have some documentation > > that will help? > > > > The first problem (it might be the whole problem, I'm not sure) is > > which 'pyexiv2' I should be installing, there seem to be several > > apparently competing versions and it's not at all clear which is the > > most likely to work. On pypi there's py3exiv2 and pyexiv2 both of > > which claim to be for Python 3. On the http://py3exiv2.tuxfamily.org/ > > page it states: "py3exiv2 is the Python 3 version of pyexiv2 written > > for Python 2, ...", really! no wonder I'm confused. > > > > Essentially I need the python-pyexiv2 package for Ubuntu 20.04 and > > it's only available up to 19.10. > > > > You might be partly out of luck. I'm not seeing any pyexiv package for > Python 3 either in Ubuntu or Debian. But there is another way: you > might be able to just install it with pip. You mentioned that it's on > PyPI, so try this: > > python3 -m pip install py3exiv2 > > (best inside a virtual environment, but otherwise you might need sudo) > > My reading of the PyPI pages is that the original Python 2 library was > created by one person (Michael Vanslembrouck), and then someone else > (VinsS) did the Python 3 port, which means it had to get a different > name. > Yes, but trying to install it with pip[3] was what took me down into dependency hell, maybe I should persevere. > You could agitate to get py3exiv2 added to the Ubuntu repositories, > but in the meantime, if you can install it with pip, that should be > viable. I install most things using pip, but then, I also tend to have > versions of Python that aren't supported by upstream (*cough* > currently running 3.10...) :) > I have quite a lot of things installed with pip, however I've never had this problem with dependencies before. Adding to the fun is that my system has still got Python 2 as the default Python so I have to run pip3 explicitly to get Python 3 code. Maybe I should bite the bullet and make Python 3 the default Python and see what falls over as a consequence. -- Chris Green ? From robin at reportlab.com Wed Aug 19 04:05:31 2020 From: robin at reportlab.com (Robin Becker) Date: Wed, 19 Aug 2020 09:05:31 +0100 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: <78kt0h-5si1.ln1@oceanview.tundraware.com> References: <78kt0h-5si1.ln1@oceanview.tundraware.com> Message-ID: <699bdada-eb35-83df-ba00-9a9b8224fc5d@everest.reportlab.co.uk> On 18/08/2020 19:45, Tim Daneliuk wrote: > On 8/18/20 12:28 PM, justin walters wrote: >> I apologize for being ageist earlier as well. That was out of line. > > I am likely older than you and there is no reason to apologise. > Only the profoundly undeveloped psyche takes every opportunity to > find offense when none is intended. It is the sign of a puerile > mind, irrespective of actual chronological age. Feel free to be > as "ageist" as you wish ... only make it funny or biting ... > +10 I too am of a previous generation that recited "sticks and stones .....". I find the hyper-sensitivity of the woken rather dispiriting. -aged-ly yrs- Robin Becker From robin at reportlab.com Wed Aug 19 04:15:01 2020 From: robin at reportlab.com (Robin Becker) Date: Wed, 19 Aug 2020 09:15:01 +0100 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: <9728fe5d-7951-b434-7d9f-c34610ae54de@telenet.be> References: <1bft0h-53an.ln1@esprimo.zbmc.eu> <9728fe5d-7951-b434-7d9f-c34610ae54de@telenet.be> Message-ID: <94ab800e-106b-5699-a565-706104f55727@everest.reportlab.co.uk> On 18/08/2020 20:05, Vincent Vande Vyvre wrote: ............. >> > Hi, > > Two solutions: > 1. Install exiv2-dev and py3exiv2 with pip > ??? $ sudo apt-get install libexiv2-dev > ??? $ sudo pip3 install py3exiv2 > > 2. Install my ppa > ??? $ sudo add-apt-repository ppa:vincent-vandevyvre/vvv > ??? $ sudo apt-get update > ??? $ sudo apt-get install python3-exiv2 > > Don't change your old code for pyexiv2, the names of the modules are > unchanged, your old code should work as it. > > Off course old strings are now unicode. > > Vincent (AKA VinsS) > I haven't tried #2 (I use Arch), but I did try 1) in a python 3.8 virtual env. I ended up getting into a problem with boost > src/exiv2wrapper.hpp:34:10: fatal error: boost/python.hpp: No such file or directory > 34 | #include "boost/python.hpp" > | ^~~~~~~~~~~~~~~~~~ > compilation terminated. > error: command 'gcc' failed with exit status 1 so obviously I need to install some version of boost libs or Boost.Python etc etc. Gave up :( -luddite-ly yrs- Robin Becker From cl at isbd.net Wed Aug 19 04:03:37 2020 From: cl at isbd.net (Chris Green) Date: Wed, 19 Aug 2020 09:03:37 +0100 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 References: <1bft0h-53an.ln1@esprimo.zbmc.eu> <9728fe5d-7951-b434-7d9f-c34610ae54de@telenet.be> Message-ID: Vincent Vande Vyvre wrote: > Le 18/08/20 ? 19:22, Chris Green a ?crit?: > > I have a fairly simple Python program that I wrote a while ago in > > Python 2 that transfers images from my camera to a date ordered > > directory hierarchy on my computer. > > > > I am trying to get it to work on Python 3 as I have just upgraded to > > Ubuntu 20.04 and on that Python 3 is now the default version of Python. > > > > I seem to be descending into a horrible morass of dependencies (or > > failed dependencies) when I try to install pyexiv2 (pr py3exiv2) using > > pip3. > > > > Can anyone point me at anywhere that might have some documentation > > that will help? > > > > The first problem (it might be the whole problem, I'm not sure) is > > which 'pyexiv2' I should be installing, there seem to be several > > apparently competing versions and it's not at all clear which is the > > most likely to work. On pypi there's py3exiv2 and pyexiv2 both of > > which claim to be for Python 3. On the http://py3exiv2.tuxfamily.org/ > > page it states: "py3exiv2 is the Python 3 version of pyexiv2 written > > for Python 2, ...", really! no wonder I'm confused. > > > > Essentially I need the python-pyexiv2 package for Ubuntu 20.04 and > > it's only available up to 19.10. > > > Hi, > > Two solutions: > 1. Install exiv2-dev and py3exiv2 with pip > ??? $ sudo apt-get install libexiv2-dev > ??? $ sudo pip3 install py3exiv2 > That's what I had tried but it required further libraries beyond libexiv2-dev and I gave up. > 2. Install my ppa > ??? $ sudo add-apt-repository ppa:vincent-vandevyvre/vvv > ??? $ sudo apt-get update > ??? $ sudo apt-get install python3-exiv2 > Ah! Thank you Vincent. I had your PPA installed before (a couple of versions ago) but of course it gets disabled when you upgrade to a new version of Ubuntu. > Don't change your old code for pyexiv2, the names of the modules are > unchanged, your old code should work as it. > > Off course old strings are now unicode. > > Vincent (AKA VinsS) > -- Chris Green ? From cl at isbd.net Wed Aug 19 04:21:59 2020 From: cl at isbd.net (Chris Green) Date: Wed, 19 Aug 2020 09:21:59 +0100 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 References: <1bft0h-53an.ln1@esprimo.zbmc.eu> <9728fe5d-7951-b434-7d9f-c34610ae54de@telenet.be> <94ab800e-106b-5699-a565-706104f55727@everest.reportlab.co.uk> Message-ID: <724v0h-thnq.ln1@esprimo.zbmc.eu> Robin Becker wrote: > On 18/08/2020 20:05, Vincent Vande Vyvre wrote: > ............. > >> > > Hi, > > > > Two solutions: > > 1. Install exiv2-dev and py3exiv2 with pip > > ??? $ sudo apt-get install libexiv2-dev > > ??? $ sudo pip3 install py3exiv2 > > > > 2. Install my ppa > > ??? $ sudo add-apt-repository ppa:vincent-vandevyvre/vvv > > ??? $ sudo apt-get update > > ??? $ sudo apt-get install python3-exiv2 > > > > Don't change your old code for pyexiv2, the names of the modules are > > unchanged, your old code should work as it. > > > > Off course old strings are now unicode. > > > > Vincent (AKA VinsS) > > > I haven't tried #2 (I use Arch), but I did try 1) in a python 3.8 virtual > env. I ended up getting into a problem with boost > > > src/exiv2wrapper.hpp:34:10: fatal error: boost/python.hpp: No such file or directory > > 34 | #include "boost/python.hpp" > > | ^~~~~~~~~~~~~~~~~~ > > compilation terminated. > > error: command 'gcc' failed with exit status 1 > > so obviously I need to install some version of boost libs or Boost.Python etc etc. Gave up :( > -luddite-ly yrs- OP here, yes, that's exactly where I got to as well! :-) I've used Vincent's PPA before so I took that route and it worked flawlessly, my code is now working again in 20.04 running Python 3. -- Chris Green ? From PythonList at DancesWithMice.info Wed Aug 19 05:12:34 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 19 Aug 2020 21:12:34 +1200 Subject: LittleRookie In-Reply-To: <562ffccc86982f6cc165c3b5f88a0e79$1@dkzerogt6z6ybhcj.onion> References: <68f53112b5f4f8644d0d5a4eb059d9b0$1@dkzerogt6z6ybhcj.onion> <25553f2a-0385-f220-4ad7-2efef08e0a62@DancesWithMice.info> <562ffccc86982f6cc165c3b5f88a0e79$1@dkzerogt6z6ybhcj.onion> Message-ID: <795947c8-ee06-6004-84e0-6a8c61b1c711@DancesWithMice.info> On 19/08/2020 14:19, Jamelaumn wrote: > actually for me to sign for any online courses like stanford etc... if > it's needed any document i couldnt? get in because i have none i'm from > brazil :v anyway thank u guys ;) i will try find something Did you try either of the two platforms mentioned previously? They are public access, and should be available to anyone, world-wide. If your country blocks access (which I doubt because I often assist Brazilian trainees) then I can't help, but if you find some personal obstruction, please contact me (off-list). Neither "Dr Chuck's" Programming for Everybody (Getting Started with Python) on edX, nor Paul Resnick's Python Basics on Coursera, even mention the need to provide documentation. Where did you look, that required such a formal application? A public-access course means that no pre-requisite qualifications are required. Some courses are $only (as I subsequently discovered with the MySQL-Workbench offering mentioned before), but most only require payment if you wish to attempt certification. The term "audit" is American-English for $free and (depending upon platform) this usually gives you full access to the training materials, but not to exams, grading, and similar. Admittedly, certain platforms make it very difficult to keep avoiding their requests for money, by making the 'audit' option/button/link very low-emphasis within the text - but such is unlikely to challenge someone with attention-to-detail! Finally, (and I do not know the answer!) if you prefer to study in Portuguese, then research a course aggregator, or 'search engine' for courses which will enable you to search for the combination of attributes desired. https://www.classcentral.com/ for example includes descriptions of courses available from all over the world... Web.Refs: https://www.edx.org/course/programming-for-everybody-getting-started-with-pyt https://www.coursera.org/learn/python-basics -- Regards =dn From jpic at yourlabs.org Wed Aug 19 05:55:33 2020 From: jpic at yourlabs.org (J. Pic) Date: Wed, 19 Aug 2020 11:55:33 +0200 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> Message-ID: My origins are Jewish Algerian which is just hated by just all parties you could think off, but can not be considered as white. Nonetheless, I'm not angry in any way, rather amused, but still, I don't understand how this sentence (changed by the patch): > When writing English, follow Strunk and White. Does "uphold relics of white supremacy" (as per the commit message). Does that mean that English teachers uphold "relics of white supremacy" when they ask to "follow Strunk and White" ? Because from a Z?t?tique point of view this looks like basic conspiracy theory. Thanks in advance for your simple explanation (I'm not a native english speaker). From jpic at yourlabs.org Wed Aug 19 06:12:47 2020 From: jpic at yourlabs.org (J. Pic) Date: Wed, 19 Aug 2020 12:12:47 +0200 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> Message-ID: On Wed, Aug 19, 2020 at 3:33 AM Tim Daneliuk wrote: > > I would also like to help you become educated. Be sure to check > out these literary treasures - they are the foundation of the > worldview you are espousing: > > > The_Origin of the Family, Private Property, and the State - Engels > > Das Kapital - Marx > > On Guerrilla Warfare - Mao > FYI, these are studied in the first year "General knowledge" course of the political science curriculum in France and are really hard to take seriously nowadays. They are just filled with contradictions that have been disproven literally thousands of times, just reading the text you'll see that it can't even hold up to its own promises even in theory. That said, I think you are going to have hard times demonstrating how these are the foundations of the worldview in question to people who haven't followed a serious polsci curriculum, we're mostly engineers here, we pay taxes that pay politicians with actual polsci curriculum to take care of this debates, I don't want to be forced to stand up against the demagogy here, extremes just feed one another, and this commit message operation is clearly pushing people to express their disagreement in the booth by voting right (not alt-right, not far-right, just right). -- ? From robin at reportlab.com Wed Aug 19 04:15:01 2020 From: robin at reportlab.com (Robin Becker) Date: Wed, 19 Aug 2020 09:15:01 +0100 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: <9728fe5d-7951-b434-7d9f-c34610ae54de@telenet.be> References: <1bft0h-53an.ln1@esprimo.zbmc.eu> <9728fe5d-7951-b434-7d9f-c34610ae54de@telenet.be> Message-ID: <94ab800e-106b-5699-a565-706104f55727@everest.reportlab.co.uk> On 18/08/2020 20:05, Vincent Vande Vyvre wrote: ............. >> > Hi, > > Two solutions: > 1. Install exiv2-dev and py3exiv2 with pip > ??? $ sudo apt-get install libexiv2-dev > ??? $ sudo pip3 install py3exiv2 > > 2. Install my ppa > ??? $ sudo add-apt-repository ppa:vincent-vandevyvre/vvv > ??? $ sudo apt-get update > ??? $ sudo apt-get install python3-exiv2 > > Don't change your old code for pyexiv2, the names of the modules are > unchanged, your old code should work as it. > > Off course old strings are now unicode. > > Vincent (AKA VinsS) > I haven't tried #2 (I use Arch), but I did try 1) in a python 3.8 virtual env. I ended up getting into a problem with boost > src/exiv2wrapper.hpp:34:10: fatal error: boost/python.hpp: No such file or directory > 34 | #include "boost/python.hpp" > | ^~~~~~~~~~~~~~~~~~ > compilation terminated. > error: command 'gcc' failed with exit status 1 so obviously I need to install some version of boost libs or Boost.Python etc etc. Gave up :( -luddite-ly yrs- Robin Becker From ethan at stoneleaf.us Wed Aug 19 10:02:46 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 19 Aug 2020 07:02:46 -0700 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> Message-ID: <3e3a8fe2-5d88-2874-6176-316b774b6228@stoneleaf.us> On 8/19/20 2:55 AM, J. Pic wrote: > [...] but still, I > don't understand how this sentence (changed by the patch): > >> When writing English, follow Strunk and White. > > Does "uphold relics of white supremacy" (as per the commit message). > > Thanks in advance for your simple explanation (I'm not a native > english speaker). The purported issue is that Strunk and White itself is doing the upholding. For example, on a slightly different topic, earlier versions of S&W were sexist: the examples of men used positive words, while the examples of women used negative and subservient words. I have not read S&W myself, and my requests for WS examples have gone unanswered, so I do not know about the WS aspect. -- ~Ethan~ From abrault at mapgears.com Wed Aug 19 09:35:11 2020 From: abrault at mapgears.com (Alexandre Brault) Date: Wed, 19 Aug 2020 09:35:11 -0400 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> Message-ID: <8a983eab-92b0-b206-364f-dd77dedc3e32@mapgears.com> On 2020-08-18 7:34 p.m., rmlibre at riseup.net wrote: > There are many reasons Elements is a terrible English style guide: > https://www.pure.ed.ac.uk/ws/files/8520953/PULLUM_2010_The_land_of_the_free_and_the_elements_of_style.pdf > > I would kindly recommend that folks just educate themselves on what > white supremacy is & how it continues in both subtle & overt ways to > this day. Sadly, getting extremely upset after being exposed to the > accurate term white supremacy is a symptom of what's called 'white > fragility' by psychologists who study the social pathologies of racism & > its long-lasting, inter-generational impacts on society. > > You need serious help with processing your anger if you look at > everything that's happening in the world & bubble in anger over a commit > message that is simply acknowledging a social ill. One of countless > many. I do hope you get the help you need. > > I would also caution against relying on the idea of human rights when > defending against accusations of being political, since they too are > political. Life is political. We continue to this day trying to > redefine, as a society, what human rights are, & who is considered to > deserve them. That process is politics. > > Some people think that being called white is racist. Other people think > that having their land & children stolen because of their race & being > forced to write in the language of their captors is racist. One group is > deflecting blame for the worst atrocities in history, the other is > acknowledging a real problem & seeking accountability in everyday life. > > > Resources: > A People's History of the United States: > https://mvlindsey.files.wordpress.com/2015/08/peoples-history-zinn-1980.pdf > The Invention of the White Race: Volume II: > http://ouleft.org/wp-content/uploads/Invention-White-Race-Vol2-Allen.pdf I've not seen anyone objecting to the idea of removing the reference to Strunk and White in favour of the underlying message of "be understandable by others who may read your comments" (there were at most a few philosophical "what is understandable") . In fact, that is how the topic was initially presented. What people *are* complaining about is the use of a commit message to stand on a soapbox and preach. The time to preach was when debating the change; commit messages, in many people's opinions, is not the time to espouse non-technical opinions From ethan at stoneleaf.us Wed Aug 19 10:34:00 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 19 Aug 2020 07:34:00 -0700 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: <8a983eab-92b0-b206-364f-dd77dedc3e32@mapgears.com> References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> <8a983eab-92b0-b206-364f-dd77dedc3e32@mapgears.com> Message-ID: <3d820674-e3d8-5078-084e-68642d4ef324@stoneleaf.us> On 8/19/20 6:35 AM, Alexandre Brault wrote: > What people *are* complaining about is the use of a commit message to > stand on a soapbox and preach. The time to preach was when debating the > change; commit messages, in many people's opinions, is not the time to > espouse non-technical opinions An excellent summary. Thank you. -- ~Ethan~ From jpic at yourlabs.org Wed Aug 19 10:40:14 2020 From: jpic at yourlabs.org (J. Pic) Date: Wed, 19 Aug 2020 16:40:14 +0200 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: <3e3a8fe2-5d88-2874-6176-316b774b6228@stoneleaf.us> References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> <3e3a8fe2-5d88-2874-6176-316b774b6228@stoneleaf.us> Message-ID: On Wed, Aug 19, 2020 at 4:06 PM Ethan Furman wrote: > The purported issue is that Strunk and White itself is doing the upholding. Still trying to find some actual evidence. -- ? From info at tundraware.com Wed Aug 19 11:47:57 2020 From: info at tundraware.com (Tim Daneliuk) Date: Wed, 19 Aug 2020 10:47:57 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> <8a983eab-92b0-b206-364f-dd77dedc3e32@mapgears.com> Message-ID: On 8/19/20 8:35 AM, Alexandre Brault wrote: > I've not seen anyone objecting to the idea of removing the reference to Strunk and White in favour of the underlying message of "be understandable by others who may read your comments" (there were at most a few philosophical "what is understandable") . In fact, that is how the topic?was?initially?presented. > > What people *are* complaining about is the use of a commit message to stand on a soapbox and preach. The time to preach was when debating the change; commit messages, in many people's opinions, is not the time to espouse?non-technical?opinions I would argue that these highly polarizing political discussions never have a place at any point in the lifecycle of technology improvement. Once you open this door in any way, no end of mischief ensues. You already see this in this very thread. People are determined to flog their particular political theory, virtue signal, and generally misappropriate a technical forum to their own ends. The right answer here is: No politics, no social commentary, no demands for redress of perceived historical inequities ... none of that. The sole relevant demand should be civility. From web at ushills.co.uk Wed Aug 19 11:01:31 2020 From: web at ushills.co.uk (Ian Hill) Date: Wed, 19 Aug 2020 16:01:31 +0100 Subject: LittleRookie In-Reply-To: References: Message-ID: You can access Dr.Chuck's Python for Everybody course here https://www.py4e.com/ or you need to be on the audit track on Coursera. R. ushills From ikorot01 at gmail.com Wed Aug 19 13:10:43 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 19 Aug 2020 12:10:43 -0500 Subject: LittleRookie In-Reply-To: References: Message-ID: Dennis, On Wed, Aug 19, 2020 at 11:26 AM Dennis Lee Bieber wrote: > > On Tue, 18 Aug 2020 22:23:28 +0000, dbsanznt at gmail.com (Jamelaumn) > declaimed the following: > > >i would say i'm new at programing i have a year of experience in python(but i'm tottaly a noob) i guess i'm starting to learn SQL now.What should i do to learn better and faster? > > You've had lots of answers, but there is one concept that seems to have > not been mentioned. > > SQL is a (relational) database QUERY language -- but knowing SQL does > not mean you can design a relational database structure. For design, you > should be familiar with at least 1st, 2nd, and 3rd Normal Forms > https://en.wikipedia.org/wiki/Database_normalization > https://www3.ntu.edu.sg/home/ehchua/programming/sql/Relational_Database_Design.html And the best way to LEARN is to go to school to understand the concept and get real-life training and not to read Wikipedia articles. Thank you. > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ > > -- > https://mail.python.org/mailman/listinfo/python-list From info at tundraware.com Wed Aug 19 13:01:09 2020 From: info at tundraware.com (Tim Daneliuk) Date: Wed, 19 Aug 2020 12:01:09 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: Message-ID: On 8/18/20 12:18 PM, gia wrote: > That's why I picked Math, it is also universally accepted, it's very > strict, and it leaves the reader to decide its color based on themselves > (it's not white btw :) Sorry, but when it comes to the demands of the woke, you are not immune. Reported widely earlier this month, seen here most recently: https://thejewishvoice.com/2020/08/brooklyn-college-education-prof-claims-math-is-white-supremacist-patriarchy/ From jorge.conforte at inpe.br Wed Aug 19 13:32:45 2020 From: jorge.conforte at inpe.br (J Conrado) Date: Wed, 19 Aug 2020 14:32:45 -0300 Subject: Python Pandas split Date in day month year and hour Message-ID: Hi, I'm satarting using Pandas to read excel. I have a meteorological synoptic data and I have for date: 0?? 2017-11-01 00:00:00 1?? 2017-11-01 03:00:00 2?? 2017-11-01 06:00:00 3?? 2017-11-01 09:00:00 4?? 2017-11-01 12:00:00 ..????????????????? ... 229 2017-11-30 09:00:00 230 2017-11-30 12:00:00 231 2017-11-30 15:00:00 232 2017-11-30 18:00:00 233 2017-11-30 21:00:00 I would like know how can I get for this array the values for day, month and hour: 2017-11-01 03:00:00?????? year = 2017????? month = 11??? day = 1??? and ?? hour = 3 Thanks, Conrado From rosuav at gmail.com Wed Aug 19 13:58:36 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 20 Aug 2020 03:58:36 +1000 Subject: LittleRookie In-Reply-To: References: Message-ID: On Thu, Aug 20, 2020 at 3:11 AM Igor Korot wrote: > > Dennis, > > On Wed, Aug 19, 2020 at 11:26 AM Dennis Lee Bieber > wrote: > > > > On Tue, 18 Aug 2020 22:23:28 +0000, dbsanznt at gmail.com (Jamelaumn) > > declaimed the following: > > > > >i would say i'm new at programing i have a year of experience in python(but i'm tottaly a noob) i guess i'm starting to learn SQL now.What should i do to learn better and faster? > > > > You've had lots of answers, but there is one concept that seems to have > > not been mentioned. > > > > SQL is a (relational) database QUERY language -- but knowing SQL does > > not mean you can design a relational database structure. For design, you > > should be familiar with at least 1st, 2nd, and 3rd Normal Forms > > https://en.wikipedia.org/wiki/Database_normalization > > https://www3.ntu.edu.sg/home/ehchua/programming/sql/Relational_Database_Design.html > > And the best way to LEARN is to go to school ... You can't learn at home? That's a great pity, given that that's how I learned basically everything I know about programming. If you're sufficiently motivated, you don't need a school/university/college. You just need the reference material, tutorials, guides, that sort of thing. ChrisA From brian.j.oney at googlemail.com Wed Aug 19 14:00:39 2020 From: brian.j.oney at googlemail.com (Brian Oney) Date: Wed, 19 Aug 2020 20:00:39 +0200 Subject: Python Pandas split Date in day month year and hour In-Reply-To: References: Message-ID: On August 19, 2020 7:32:45 PM GMT+02:00, J Conrado wrote: > > >Hi, > > >I'm satarting using Pandas to read excel. I have a meteorological >synoptic data and I have for date: > > >0?? 2017-11-01 00:00:00 >1?? 2017-11-01 03:00:00 >2?? 2017-11-01 06:00:00 >3?? 2017-11-01 09:00:00 >4?? 2017-11-01 12:00:00 >..????????????????? ... >229 2017-11-30 09:00:00 >230 2017-11-30 12:00:00 >231 2017-11-30 15:00:00 >232 2017-11-30 18:00:00 >233 2017-11-30 21:00:00 > > >I would like know how can I get for this array the values for day, month >and hour: > >2017-11-01 03:00:00?????? year = 2017????? month = 11??? day = 1??? and > ?? hour = 3 > From the hip, I would use the strptime function (in the time module?) time.strptime(string_value, '%F %T') If I recall correctly, the doc for the specific strings is in the strptime function's doc. This is just a starting point. Good luck! HTH From jpic at yourlabs.org Wed Aug 19 14:10:42 2020 From: jpic at yourlabs.org (J. Pic) Date: Wed, 19 Aug 2020 20:10:42 +0200 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> <8a983eab-92b0-b206-364f-dd77dedc3e32@mapgears.com> Message-ID: Tim, don't you also think that statements should be backed by evidence, even more if they are particularly accusatory ? We'll be lucky if S&W's editor doesn't sue the PSF for slandering for publishing that S&W "upholds white supremacy". From ikorot01 at gmail.com Wed Aug 19 14:39:48 2020 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 19 Aug 2020 13:39:48 -0500 Subject: LittleRookie In-Reply-To: References: Message-ID: Hi, Chris, On Wed, Aug 19, 2020 at 1:01 PM Chris Angelico wrote: > > On Thu, Aug 20, 2020 at 3:11 AM Igor Korot wrote: > > > > Dennis, > > > > On Wed, Aug 19, 2020 at 11:26 AM Dennis Lee Bieber > > wrote: > > > > > > On Tue, 18 Aug 2020 22:23:28 +0000, dbsanznt at gmail.com (Jamelaumn) > > > declaimed the following: > > > > > > >i would say i'm new at programing i have a year of experience in python(but i'm tottaly a noob) i guess i'm starting to learn SQL now.What should i do to learn better and faster? > > > > > > You've had lots of answers, but there is one concept that seems to have > > > not been mentioned. > > > > > > SQL is a (relational) database QUERY language -- but knowing SQL does > > > not mean you can design a relational database structure. For design, you > > > should be familiar with at least 1st, 2nd, and 3rd Normal Forms > > > https://en.wikipedia.org/wiki/Database_normalization > > > https://www3.ntu.edu.sg/home/ehchua/programming/sql/Relational_Database_Design.html > > > > And the best way to LEARN is to go to school ... > > You can't learn at home? That's a great pity, given that that's how I > learned basically everything I know about programming. > > If you're sufficiently motivated, you don't need a > school/university/college. You just need the reference material, > tutorials, guides, that sort of thing. While I understand that people are different and all have their preferences it is best to go to school to learn something (whether the school is online or not - doesn't matter). You will be ta;lking to teachers and peers, do the homework (which means easy exercises) to prove that you learnt something and finally acquire some connection which will help you along the way. And what can you learn by reading the WiKi article mentioned if you don't know how to use them properly (without practicing them)? BTW, I'm also a self-taught developer, but I did it a long time ago in school and there were people that helped me understand all those books we had and I did some exercises. Thank you. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From klsshaeffer at icloud.com Wed Aug 19 15:00:01 2020 From: klsshaeffer at icloud.com (Karen Shaeffer) Date: Wed, 19 Aug 2020 12:00:01 -0700 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> <8a983eab-92b0-b206-364f-dd77dedc3e32@mapgears.com> Message-ID: > On Aug 19, 2020, at 8:47 AM, Tim Daneliuk wrote: > > On 8/19/20 8:35 AM, Alexandre Brault wrote: >> I've not seen anyone objecting to the idea of removing the reference to Strunk and White in favour of the underlying message of "be understandable by others who may read your comments" (there were at most a few philosophical "what is understandable") . In fact, that is how the topic was initially presented. >> >> What people *are* complaining about is the use of a commit message to stand on a soapbox and preach. The time to preach was when debating the change; commit messages, in many people's opinions, is not the time to espouse non-technical opinions > > I would argue that these highly polarizing political discussions never have > a place at any point in the lifecycle of technology improvement. Once you > open this door in any way, no end of mischief ensues. > > You already see this in this very thread. People are determined to flog > their particular political theory, virtue signal, and generally misappropriate > a technical forum to their own ends. > > The right answer here is: No politics, no social commentary, no demands for > redress of perceived historical inequities ... none of that. The sole relevant > demand should be civility. I lurk on this list and rarely post. I tend to agree this thread should never have started here. IMHO, any discussion of this issue should have stayed on the platform where the issue arose. But I must say with all due respect to you Tim, in this thread, you have repeatedly engaged in the precise behavior you are now complaining about. Even further, you have, IMHO, been condescending and even arrogant in presuming you alone have perfect knowledge on these matters: https://mail.python.org/pipermail/python-list/2020-August/898274.html Where you conclude with: "Methinks there is an ideological skunk in the parlor ?? Considering all your posts on this thread, it is reasonable to infer you have some ideological motivations. https://mail.python.org/pipermail/python-list/2020-August/898314.html Which appears to be relatively safe and harmless, but you could have easily found clear evidence that refutes your stated point of view. In particular, this peer reviewed published research from Stanford University establishes the fact that racism and bias are alive and well in the STEM fields: https://www.pnas.org/content/pnas/117/17/9284.full.pdf https://mail.python.org/pipermail/python-list/2020-August/898280.html Here you encourage folks to discriminate, as long as they make it ?fun or biting? This is completely inconsistent with your complaint that I am responding to now. https://mail.python.org/pipermail/python-list/2020-August/898292.html https://mail.python.org/pipermail/python-list/2020-August/898293.html Those two posts are condescending, and presume you alone have perfect knowledge ? They also represent a classic bait and switch attempt. IMHO, your contributions to this thread have been inflammatory and likely precipitated others to continue the escalation of these issues. I?m only pointing this out to put your current complaint to the moderators of this list into its proper perspective. humbly, kls From jpic at yourlabs.org Wed Aug 19 15:29:49 2020 From: jpic at yourlabs.org (J. Pic) Date: Wed, 19 Aug 2020 21:29:49 +0200 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> Message-ID: On Wed, Aug 19, 2020 at 3:33 AM Tim Daneliuk wrote: > On 8/18/20 6:34 PM, rmlibre at riseup.net wrote: > > I would kindly recommend that folks just educate themselves on what > > ... > > Resources: > > The Invention of the White Race: Volume II: > http://ouleft.org/wp-content/uploads/Invention-White-Race-Vol2-Allen.pdf > > I would also like to help you become educated. Be sure to check > out these literary treasures - they are the foundation of the > worldview you are espousing: > > The_Origin of the Family, Private Property, and the State - Engels > Das Kapital - Marx > On Guerrilla Warfare - Mao I stand corrected, the PDF of "The invention of white race" shared by the OP *does* cite: - Marx, page 9 - Mao, page 103 - Marx, Capital Vol I, page 807 - Marx and Engels, page 828 - Marx and Engels, The Communist Manifesto, Karl Marx and Frederick Engels, Selected Works in Two Volumes, page 851 And it goes on ... -- ? From info at tundraware.com Wed Aug 19 15:40:31 2020 From: info at tundraware.com (Tim Daneliuk) Date: Wed, 19 Aug 2020 14:40:31 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> <8a983eab-92b0-b206-364f-dd77dedc3e32@mapgears.com> Message-ID: On 8/19/20 2:00 PM, Karen Shaeffer wrote: > Where you conclude with: "Methinks there is an ideological skunk in the parlor ?? > > Considering all your posts on this thread, it is reasonable to infer you have some ideological motivations. My motivation was to demonstrate that if people of your ilk are free to peddle their worldview, it invites people of my worldview to join the party and thereby wreak havoc. The only way to solve this is: No politics, no culture, no religion, or no sex. Period. Ever. Do take note that while I freely admit to having utter contempt for the en courant culture and its various warriors, I also have been careful to avoid flogging *my own* political/social view. They don't belong here. Neither do yours. Why don't we stick to discussing Python which ought to not be infected by these subjects. From info at tundraware.com Wed Aug 19 15:47:08 2020 From: info at tundraware.com (Tim Daneliuk) Date: Wed, 19 Aug 2020 14:47:08 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> <8a983eab-92b0-b206-364f-dd77dedc3e32@mapgears.com> Message-ID: On 8/19/20 1:10 PM, J. Pic wrote: > Tim, don't you also think that statements should be backed by > evidence, even more if they are particularly accusatory ? > > We'll be lucky if S&W's editor doesn't sue the PSF for slandering for > publishing that S&W "upholds white supremacy". > As a general matter, I agree: Claims should be supported by evidence. But that's not the problem here. The various cause crusaders are attempting to insert themselves into every single discipline. They do this claiming their attacks as some kind of moral virtue and that they are therefore above reproach or counterpoint. It is natural for people who disagree to punch back. My real point in commenting at all was that we open this one-sided door at our own peril. By allowing provocative commentary of the sort voice in this godforsaken commit message, we absolutely invite others to the party. Despite what the aforementioned cause crusaders think, they are not unassailable, nor are they the only- or dominant voice in these matters. Open this door and you get an absolute sewer of commentary (from many sides of these issues). Social media is full of many trenchant such examples. Best to leave it there. From skip.montanaro at gmail.com Wed Aug 19 16:05:53 2020 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 19 Aug 2020 15:05:53 -0500 Subject: Python Pandas split Date in day month year and hour In-Reply-To: References: Message-ID: > I would like know how can I get for this array the values for day, month > and hour: > > 2017-11-01 03:00:00 year = 2017 month = 11 day = 1 and > hour = 3 Pandas has a datetime type. You should probably be using it. It's been awhile (a year at least), but if your datetime column is filled with datetime types, you should be able to append columns to your DataFrame which correspond to individual components of the datetime instances. Don't be looking outside of Pandas to Python's time or datetime module. Skip From ethan at stoneleaf.us Wed Aug 19 16:29:20 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 19 Aug 2020 13:29:20 -0700 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> <8a983eab-92b0-b206-364f-dd77dedc3e32@mapgears.com> Message-ID: On 8/19/20 12:40 PM, Tim Daneliuk wrote: > On 8/19/20 2:00 PM, Karen Shaeffer wrote: >> Considering all your posts on this thread, it is reasonable to infer you have some ideological motivations. > > My motivation was to demonstrate that if people of your ilk are free to > peddle their worldview, Unless you know Karen personally, you don't know what her world view is. Poking holes in arguments or observing what is being said does not require an opposing world view. As you yourself said: > The sole relevant > demand should be civility. Let's make sure we stay that course. -- ~Ethan~ Python List Moderator From cspealma at redhat.com Wed Aug 19 16:32:39 2020 From: cspealma at redhat.com (Calvin Spealman) Date: Wed, 19 Aug 2020 16:32:39 -0400 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> <8a983eab-92b0-b206-364f-dd77dedc3e32@mapgears.com> Message-ID: Tim, Technology is political. Deal with it. Signed, Common Fucking Sense On Wed, Aug 19, 2020 at 4:02 PM Tim Daneliuk wrote: > On 8/19/20 1:10 PM, J. Pic wrote: > > Tim, don't you also think that statements should be backed by > > evidence, even more if they are particularly accusatory ? > > > > We'll be lucky if S&W's editor doesn't sue the PSF for slandering for > > publishing that S&W "upholds white supremacy". > > > > As a general matter, I agree: Claims should be supported by evidence. > But that's not the problem here. The various cause crusaders are > attempting to insert themselves into every single discipline. They > do this claiming their attacks as some kind of moral virtue and that > they are therefore above reproach or counterpoint. It is natural > for people who disagree to punch back. > > My real point in commenting at all was that we open this one-sided door > at our own peril. By allowing provocative commentary of the sort voice > in this godforsaken commit message, we absolutely invite others to the > party. > Despite what the aforementioned cause crusaders think, they are not > unassailable, nor are they the only- or dominant voice in these matters. > Open this door and you get an absolute sewer of commentary > (from many sides of these issues). Social media is full of many trenchant > such examples. Best to leave it there. > > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From ethan at stoneleaf.us Wed Aug 19 17:04:02 2020 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 19 Aug 2020 14:04:02 -0700 Subject: [closed] Final statement from Steering Council on politically-charged commit messages Message-ID: This thread is now closed. Thank you for your cooperation. -- ~Ethan~ Python List Moderator From info at tundraware.com Wed Aug 19 17:07:52 2020 From: info at tundraware.com (Tim Daneliuk) Date: Wed, 19 Aug 2020 16:07:52 -0500 Subject: Final statement from Steering Council on politically-charged commit messages In-Reply-To: References: <3b99695e1aeec7adce6c3e5470d3480d@riseup.net> <8a983eab-92b0-b206-364f-dd77dedc3e32@mapgears.com> Message-ID: <9ug01h-sb52.ln1@oceanview.tundraware.com> On 8/19/20 3:29 PM, Ethan Furman wrote: > On 8/19/20 12:40 PM, Tim Daneliuk wrote: >> On 8/19/20 2:00 PM, Karen Shaeffer wrote: > >>> Considering all your posts on this thread, it is reasonable to infer you have some ideological motivations. >> >> My motivation was to demonstrate that if people of your ilk are free to >> peddle their worldview, > > Unless you know Karen personally, you don't know what her world view is. ?Poking holes in arguments or observing what is being said does not require an opposing world view. I'd say this is at least a hint: >>> this peer reviewed published research from Stanford University establishes the fact that racism and bias are alive and well in the STEM fields: I have rather lengthy counterpoint to this "research". Ditto the claim that proper ordinarily use of English is prima facie evidence of "White Supremacy". Ditto the claim that any reference to age is inherently bigoted and cannot be taken in good spirit. But ... I don't think this is the place you'd like to see my disquisitions on the matter.* My larger point holds: You cannot allow one worldview in and then expect other worldviews to keeps still ... and that's true irrespective of WHICH worldview first got in the door. > As you yourself said: > >> The sole relevant >> demand should be civility. > > Let's make sure we stay that course. I have never been anything other than this in the entire thread. It is not uncivil to disagree. > > -- > ~Ethan~ > Python List Moderator * Is the use of the word "disquisition" a form of White Supermacy? Asking for a friend. From Gronicus at SGA.Ninja Wed Aug 19 16:38:33 2020 From: Gronicus at SGA.Ninja (Steve) Date: Wed, 19 Aug 2020 16:38:33 -0400 Subject: Python Pandas split Date in day month year and hour In-Reply-To: References: Message-ID: <000001d67668$b5654e80$202feb80$@SGA.Ninja> 0 2017-11-01 00:00:00 If you are reading it is as a line into python, then it is a tuple and can be parsed accordingly: Nb = YourdataLIne[0:1] #Line Number Yr = YourDataLine[3:7] #Year Da = YourDataLine[9:11] #Day Mo = YourDataLine[13:14] #Month Hr = YourDataLine[16:18] #hour Mn = YourDataLine[20:21] #minute Sc = YourDataLine[22:23] #second Use Print ("Year = " + Yr + ", Month = " + Mo + ", Day = " + Da + ", Hour = " + Hr) You may have to adjust the numbers depending on how the line is read. Is that what you want? FootNote: If money does not grow on trees, then why do banks have branches? -----Original Message----- From: Python-list On Behalf Of Brian Oney via Python-list Sent: Wednesday, August 19, 2020 2:01 PM To: python-list at python.org Subject: Re: Python Pandas split Date in day month year and hour On August 19, 2020 7:32:45 PM GMT+02:00, J Conrado wrote: > > >Hi, > > >I'm satarting using Pandas to read excel. I have a meteorological >synoptic data and I have for date: > > >0 2017-11-01 00:00:00 >1 2017-11-01 03:00:00 >2 2017-11-01 06:00:00 >3 2017-11-01 09:00:00 >4 2017-11-01 12:00:00 >.. ... >229 2017-11-30 09:00:00 >230 2017-11-30 12:00:00 >231 2017-11-30 15:00:00 >232 2017-11-30 18:00:00 >233 2017-11-30 21:00:00 > > >I would like know how can I get for this array the values for day, >month and hour: > >2017-11-01 03:00:00 year = 2017 month = 11 day = 1 and > hour = 3 > >From the hip, I would use the strptime function (in the time module?) time.strptime(string_value, '%F %T') If I recall correctly, the doc for the specific strings is in the strptime function's doc. This is just a starting point. Good luck! HTH -- https://mail.python.org/mailman/listinfo/python-list From vincent.vande.vyvre at telenet.be Wed Aug 19 18:29:02 2020 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Thu, 20 Aug 2020 00:29:02 +0200 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: <94ab800e-106b-5699-a565-706104f55727@everest.reportlab.co.uk> References: <1bft0h-53an.ln1@esprimo.zbmc.eu> <9728fe5d-7951-b434-7d9f-c34610ae54de@telenet.be> <94ab800e-106b-5699-a565-706104f55727@everest.reportlab.co.uk> Message-ID: <751ef123-1783-5732-1bdb-e934242e836b@telenet.be> Le 19/08/20 ? 10:15, Robin Becker a ?crit?: > On 18/08/2020 20:05, Vincent Vande Vyvre wrote: > ............. >>> >> Hi, >> >> Two solutions: >> 1. Install exiv2-dev and py3exiv2 with pip >> ???? $ sudo apt-get install libexiv2-dev >> ???? $ sudo pip3 install py3exiv2 >> >> 2. Install my ppa >> ???? $ sudo add-apt-repository ppa:vincent-vandevyvre/vvv >> ???? $ sudo apt-get update >> ???? $ sudo apt-get install python3-exiv2 >> >> Don't change your old code for pyexiv2, the names of the modules are >> unchanged, your old code should work as it. >> >> Off course old strings are now unicode. >> >> Vincent (AKA VinsS) >> > I haven't tried #2 (I use Arch), but I did try 1) in a python 3.8 > virtual env. I ended up getting into a problem with boost > >> ?? src/exiv2wrapper.hpp:34:10: fatal error: boost/python.hpp: No such >> file or directory >> ?????? 34 | #include "boost/python.hpp" >> ????????? |????????? ^~~~~~~~~~~~~~~~~~ >> ??? compilation terminated. >> ??? error: command 'gcc' failed with exit status 1 > > so obviously I need to install some version of boost libs or? > Boost.Python etc etc. Gave up :( > -luddite-ly yrs- > Robin Becker > The aur repository, no ? https://aur.archlinux.org/packages/python-exiv2/ Vincent From tjandacw at gmail.com Wed Aug 19 20:30:53 2020 From: tjandacw at gmail.com (Tim Williams) Date: Wed, 19 Aug 2020 20:30:53 -0400 Subject: Python Pandas split Date in day month year and hour In-Reply-To: References: Message-ID: On Wed, Aug 19, 2020 at 1:43 PM J Conrado wrote: > > > Hi, > > > I'm satarting using Pandas to read excel. I have a meteorological > synoptic data and I have for date: > > > 0 2017-11-01 00:00:00 > 1 2017-11-01 03:00:00 > 2 2017-11-01 06:00:00 > 3 2017-11-01 09:00:00 > 4 2017-11-01 12:00:00 > .. ... > 229 2017-11-30 09:00:00 > 230 2017-11-30 12:00:00 > 231 2017-11-30 15:00:00 > 232 2017-11-30 18:00:00 > 233 2017-11-30 21:00:00 > > > I would like know how can I get for this array the values for day, month > and hour: > > 2017-11-01 03:00:00 year = 2017 month = 11 day = 1 and > hour = 3 > > > > Thanks, > > > Conrado > > -- > https://mail.python.org/mailman/listinfo/python-list I'm also starting to learn pandas. A better place to ask a pandas question is StackOverflow. Here's a link that may answer your question. Convert timestamp to day, month, year and hour ---- Tim Williams From cs at cskk.id.au Wed Aug 19 17:59:33 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 20 Aug 2020 07:59:33 +1000 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: References: Message-ID: <20200819215933.GA86778@cskk.homeip.net> On 19Aug2020 08:53, Chris Green wrote: >I have quite a lot of things installed with pip, however I've never >had this problem with dependencies before. Adding to the fun is that >my system has still got Python 2 as the default Python so I have to >run pip3 explicitly to get Python 3 code. My approach to this is to have a personal venv based on a modern Python3 and put its bin near the front of my $PATH. The pip and python come from it. But I tend to type "pip3" anyway - still the pip from my venv. >Maybe I should bite the bullet and make Python 3 the default Python >and see what falls over as a consequence. Don't change the system default Python - many system scripts rely on that and may break. If an OS update changes it, it should also update all the dependent scripts and so be ok, but an ad hoc change of only part of the system is asking for trouble. Cheers, Cameron Simpson From robin at reportlab.com Thu Aug 20 03:07:25 2020 From: robin at reportlab.com (Robin Becker) Date: Thu, 20 Aug 2020 08:07:25 +0100 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: <751ef123-1783-5732-1bdb-e934242e836b@telenet.be> References: <1bft0h-53an.ln1@esprimo.zbmc.eu> <9728fe5d-7951-b434-7d9f-c34610ae54de@telenet.be> <94ab800e-106b-5699-a565-706104f55727@everest.reportlab.co.uk> <751ef123-1783-5732-1bdb-e934242e836b@telenet.be> Message-ID: ......... >> so obviously I need to install some version of boost libs or >> Boost.Python etc etc. Gave up :( >> -luddite-ly yrs- >> Robin Becker >> > The aur repository, no ? > > https://aur.archlinux.org/packages/python-exiv2/ > > Vincent > that would work (if I had thought hard about it), but not for a pip install which is where the fun started :), I was only trying to see what was going wrong. -- Robin Becker From vincent.vande.vyvre at telenet.be Thu Aug 20 03:27:09 2020 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Thu, 20 Aug 2020 09:27:09 +0200 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: References: <1bft0h-53an.ln1@esprimo.zbmc.eu> <9728fe5d-7951-b434-7d9f-c34610ae54de@telenet.be> <94ab800e-106b-5699-a565-706104f55727@everest.reportlab.co.uk> <751ef123-1783-5732-1bdb-e934242e836b@telenet.be> Message-ID: <837c4c37-9139-8a55-1931-87f15f6f7eb6@telenet.be> Le 20/08/20 ? 09:07, Robin Becker a ?crit?: > ......... >>> so obviously I need to install some version of boost libs or >>> Boost.Python etc etc. Gave up :( >>> -luddite-ly yrs- >>> Robin Becker >>> >> The aur repository, no ? >> >> https://aur.archlinux.org/packages/python-exiv2/ >> >> Vincent >> > > that would work (if I had thought hard about it), but not for a pip > install which is where the fun started :), I was only trying to see > what was going wrong. > -- > Robin Becker See the README for the compilation instructions: https://bazaar.launchpad.net/~vincent-vandevyvre/py3exiv2/trunk/view/head:/py3exiv2/README Vincent From cl at isbd.net Thu Aug 20 13:13:28 2020 From: cl at isbd.net (Chris Green) Date: Thu, 20 Aug 2020 18:13:28 +0100 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 References: <20200819215933.GA86778@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > On 19Aug2020 08:53, Chris Green wrote: > >I have quite a lot of things installed with pip, however I've never > >had this problem with dependencies before. Adding to the fun is that > >my system has still got Python 2 as the default Python so I have to > >run pip3 explicitly to get Python 3 code. > > My approach to this is to have a personal venv based on a modern Python3 > and put its bin near the front of my $PATH. The pip and python come from > it. But I tend to type "pip3" anyway - still the pip from my venv. > > >Maybe I should bite the bullet and make Python 3 the default Python > >and see what falls over as a consequence. > > Don't change the system default Python - many system scripts rely on > that and may break. If an OS update changes it, it should also update > all the dependent scripts and so be ok, but an ad hoc change of only > part of the system is asking for trouble. > It's actually more subtle and complicated than the OS changing or not changing the default Python version. There are quite a lot of questions about exactly this on the Ubuntu lists. All the OS python code in Ubuntu 20.04 is now Python 3 but there are some other things which I have installed (such as Mercurial) which still depend on Python 2. One can see what is affected by doing:- $ sudo apt remove python2 --simulate This shows a mixture of old (and no longer needed) libraries that would go with Python 2 but it also shows some things like Mercurial that I need. So Python 2 stays for the moment. -- Chris Green ? From rosuav at gmail.com Thu Aug 20 14:00:57 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Aug 2020 04:00:57 +1000 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: References: <20200819215933.GA86778@cskk.homeip.net> Message-ID: On Fri, Aug 21, 2020 at 3:21 AM Chris Green wrote: > It's actually more subtle and complicated than the OS changing or not > changing the default Python version. There are quite a lot of > questions about exactly this on the Ubuntu lists. All the OS python > code in Ubuntu 20.04 is now Python 3 but there are some other things > which I have installed (such as Mercurial) which still depend on > Python 2. One can see what is affected by doing:- > > $ sudo apt remove python2 --simulate > > This shows a mixture of old (and no longer needed) libraries that > would go with Python 2 but it also shows some things like Mercurial > that I need. That seems odd. According to packages.ubuntu.com, Focal (20.04) is shipping Mercurial 5.3.1, and since version 5.2, Mercurial has supported Python 2.7 or 3.5+. However, it seems that the dependencies for the mercurial package specify python2 and no reference to python3. https://packages.ubuntu.com/focal/mercurial Fortunately, the *next* release of Ubuntu fixes this: https://packages.ubuntu.com/groovy/mercurial It depends on Python 3.8 instead. No idea why the 20.04 release insists on 2.7. ChrisA From sreelakshmi1madhukumar at gmail.com Thu Aug 20 15:01:17 2020 From: sreelakshmi1madhukumar at gmail.com (Sreelakshmi Madhu) Date: Fri, 21 Aug 2020 00:31:17 +0530 Subject: Issue Message-ID: not able to open IDLE and also while running a program in cmd saved in notepad, it's showing not found such a python file. From cl at isbd.net Thu Aug 20 16:56:08 2020 From: cl at isbd.net (Chris Green) Date: Thu, 20 Aug 2020 21:56:08 +0100 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 References: <20200819215933.GA86778@cskk.homeip.net> Message-ID: <8k431h-3451.ln1@esprimo.zbmc.eu> Chris Angelico wrote: > On Fri, Aug 21, 2020 at 3:21 AM Chris Green wrote: > > It's actually more subtle and complicated than the OS changing or not > > changing the default Python version. There are quite a lot of > > questions about exactly this on the Ubuntu lists. All the OS python > > code in Ubuntu 20.04 is now Python 3 but there are some other things > > which I have installed (such as Mercurial) which still depend on > > Python 2. One can see what is affected by doing:- > > > > $ sudo apt remove python2 --simulate > > > > This shows a mixture of old (and no longer needed) libraries that > > would go with Python 2 but it also shows some things like Mercurial > > that I need. > > That seems odd. According to packages.ubuntu.com, Focal (20.04) is > shipping Mercurial 5.3.1, and since version 5.2, Mercurial has > supported Python 2.7 or 3.5+. However, it seems that the dependencies > for the mercurial package specify python2 and no reference to python3. > > https://packages.ubuntu.com/focal/mercurial > > Fortunately, the *next* release of Ubuntu fixes this: > > https://packages.ubuntu.com/groovy/mercurial > > It depends on Python 3.8 instead. No idea why the 20.04 release insists on 2.7. > OK, so that's one less thing needing Python 2, next release. :-) -- Chris Green ? From PythonList at DancesWithMice.info Thu Aug 20 18:07:58 2020 From: PythonList at DancesWithMice.info (dn) Date: Fri, 21 Aug 2020 10:07:58 +1200 Subject: Issue In-Reply-To: References: Message-ID: On 21/08/2020 07:01, Sreelakshmi Madhu wrote: > not able to open IDLE > and also while running a program in cmd saved in notepad, it's showing not > found such a python file. Please review the Python documentation (https://docs.python.org/3/), in particular the "Python Setup and Usage" notes relevant to your machine. If you need further information, please help us to help you: - refer to the archives of this Discussion List to see if the question has been asked previously - operating system and version - source and version of Python download - exactly what you typed/did - exactly what happened as a result - use a descriptive message title that will help other beginners with similar problems to benefit from answers-given -- Regards =dn From cs at cskk.id.au Thu Aug 20 19:16:50 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 21 Aug 2020 09:16:50 +1000 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: References: Message-ID: <20200820231650.GA67608@cskk.homeip.net> On 20Aug2020 18:13, Chris Green wrote: >Cameron Simpson wrote: >> On 19Aug2020 08:53, Chris Green wrote: >> >Maybe I should bite the bullet and make Python 3 the default Python >> >and see what falls over as a consequence. >> >> Don't change the system default Python - many system scripts rely on >> that and may break. If an OS update changes it, it should also update >> all the dependent scripts and so be ok, but an ad hoc change of only >> part of the system is asking for trouble. >> >It's actually more subtle and complicated than the OS changing or not >changing the default Python version. There are quite a lot of >questions about exactly this on the Ubuntu lists. All the OS python >code in Ubuntu 20.04 is now Python 3 but there are some other things >which I have installed (such as Mercurial) which still depend on >Python 2. I run Mercurial 5.5 with Python 3. Admittedly because I went "pip3 install mercurial" to put it in my personal py 3 venv. However I recommend this anyway! Uninstall the system mercurial if you don't need it elsewhere - it will remove a python 2 dependency. >One can see what is affected by doing:- > > $ sudo apt remove python2 --simulate > >This shows a mixture of old (and no longer needed) libraries that >would go with Python 2 but it also shows some things like Mercurial >that I need. % which hg /Users/cameron/var/venv/3/bin/hg >So Python 2 stays for the moment. I recommend putting a little more work to further reducing your py 2 dependence - it will help in the medium term. Cheers, Cameron Simpson From cs at cskk.id.au Thu Aug 20 19:19:49 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 21 Aug 2020 09:19:49 +1000 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: References: Message-ID: <20200820231949.GA81079@cskk.homeip.net> On 21Aug2020 04:00, Chris Angelico wrote: >Fortunately, the *next* release of Ubuntu fixes this: > >https://packages.ubuntu.com/groovy/mercurial > >It depends on Python 3.8 instead. No idea why the 20.04 release insists >on 2.7. I would guess they didn't have the resources to regression test the shift in time for 20.04. Moving to Python 3, _particularly_ with something like Mercurial which has a bunch of internal things which are in fact byte strings, risks subtle breakage. Cheers, Cameron Simpson From rosuav at gmail.com Thu Aug 20 19:37:21 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 21 Aug 2020 09:37:21 +1000 Subject: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3 In-Reply-To: <20200820231949.GA81079@cskk.homeip.net> References: <20200820231949.GA81079@cskk.homeip.net> Message-ID: On Fri, Aug 21, 2020 at 9:20 AM Cameron Simpson wrote: > > On 21Aug2020 04:00, Chris Angelico wrote: > >Fortunately, the *next* release of Ubuntu fixes this: > > > >https://packages.ubuntu.com/groovy/mercurial > > > >It depends on Python 3.8 instead. No idea why the 20.04 release insists > >on 2.7. > > I would guess they didn't have the resources to regression test the > shift in time for 20.04. Moving to Python 3, _particularly_ with > something like Mercurial which has a bunch of internal things which are > in fact byte strings, risks subtle breakage. > I guess so, but they're packaging something that had already been tested upstream since the *previous* minor version (at least - not sure exactly when Py3 support came in), so I'd have thought that the LTS Ubuntu would be the time to bring that in. It means that Ubuntu LTS has to continue to support Python 2 from 2020 (when Python 2 exited upstream support) until 2025 or even 2030, depending on which level of support you're looking at. In a sense, yes, the conservative thing is to avoid making changes like that; but ISTM that a release made in 2020 would be the correct time to make that change. But, I am not Canonical, I don't make these decisions. ChrisA From cs at cskk.id.au Thu Aug 20 19:49:52 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 21 Aug 2020 09:49:52 +1000 Subject: How to install your personal module/package on site. In-Reply-To: References: Message-ID: <20200820234952.GA68760@cskk.homeip.net> On 16Aug2020 08:32, Marco Sulla wrote: >Sorry, didn't read well, Apart the other suggestion, you (or your >sysop) can create a private Pypi: >https://pypi.org/project/private-pypi/ Even simpler, you can put a code repo path into your requirements.txt (or directly with pip via its "-e" option). Example from a project requirements.txt file: -e git+https://github.com/SpectraLogic/ds3_python3_sdk.git at v5.0.3#egg=ds3-sdk So if you've an work internal service for your revision control you can pull directly from that with pip. Note that the above example pulls a particular tagged release via the "@5.0.3" suffix. Cheers, Cameron Simpson (formerly cs at zip.com.au) From antoon.pardon at vub.be Fri Aug 21 05:05:39 2020 From: antoon.pardon at vub.be (Antoon Pardon) Date: Fri, 21 Aug 2020 11:05:39 +0200 Subject: How to install your personal module/package on site. In-Reply-To: <20200820234952.GA68760@cskk.homeip.net> References: <20200820234952.GA68760@cskk.homeip.net> Message-ID: <50fb90a3-5816-b64b-31f0-8190fea6ae8d@vub.be> Op 21/08/20 om 01:49 schreef Cameron Simpson: > On 16Aug2020 08:32, Marco Sulla wrote: >> Sorry, didn't read well, Apart the other suggestion, you (or your >> sysop) can create a private Pypi: >> https://pypi.org/project/private-pypi/ > > Even simpler, you can put a code repo path into your requirements.txt > (or directly with pip via its "-e" option). Example from a project > requirements.txt file: > > -e git+https://github.com/SpectraLogic/ds3_python3_sdk.git at v5.0.3#egg=ds3-sdk > > So if you've an work internal service for your revision control you can > pull directly from that with pip. Note that the above example pulls a > particular tagged release via the "@5.0.3" suffix. That is a nice feature. I will have a closer look at this. -- Antoon Pardon. From jorge.conforte at inpe.br Fri Aug 21 09:22:01 2020 From: jorge.conforte at inpe.br (J Conrado) Date: Fri, 21 Aug 2020 10:22:01 -0300 Subject: Python Pandas Message-ID: <8a7e5251-38fd-4587-21d0-5a6709596caf@inpe.br> HI, I'm using Pandas to read my .xls file and I used the command to read it: df = pd.read_excel(filexcel, parse_dates=[0], dayfirst=True) and I had the day, month, year and hour correctly But, if I? run the same script inside a virtual environment, I had this error message: ? File "xlsteste.py", line 16, in ??? df = pd.read_excel(filexcel, parse_dates=[0], dayfirst=True) ? File "/home/conrado/PENDRIVE_ASIEL/EXCEL/IMAGENS_ESTA??ES/env/lib/python3.8/site-packages/pandas/util/_decorators.py", line 296, in wrapper ??? return func(*args, **kwargs) TypeError: read_excel() got an unexpected keyword argument 'dayfirst' Please,could someone explain why my script doesn't run when I'm in the virtual environment. Thanks, Conrado From prshntaggrwl at gmail.com Fri Aug 21 08:01:25 2020 From: prshntaggrwl at gmail.com (Prashant Aggarwal) Date: Fri, 21 Aug 2020 05:01:25 -0700 (PDT) Subject: Temporary text for multiple entries Message-ID: <375d7850-b215-45cb-ba07-ed7f1d44ee67n@googlegroups.com> I am working to make a form where I have added multiple entries. I wish to add temporary text on all of them, as the text to be deleted when clicked and to inserted again when focused out. I have done with the single entry but not able to find a solution for multiple entries.Kindly suggest me a better way to do. From mkarkera98 at gmail.com Fri Aug 21 10:17:18 2020 From: mkarkera98 at gmail.com (Meghna Karkera) Date: Fri, 21 Aug 2020 19:47:18 +0530 Subject: Matrix of size 100*100- Meghna In-Reply-To: References: Message-ID: Dear Respected Sir I am Meghna, a PhD student. I have installed python in my ubuntu OS from your website recently and tried using spyder and jupyter. May I request you to help me with importing few matrices, each of size 100*100 in python from XLSX and perform operations on the matrices like addition, multiplication, finding matrix inverse, creating diagonal matrices each of size 100*100 from column vectors each of size 100*1, creating identity matrix of size 100*100. I have surfed in the internet, but unable to get answer for it. I would be grateful to you if you could help me in this regard. Thanking you Sincerely Meghna Raviraj Karkera PhD Student Department of Data Science Prasanna School of Public Health Manipal Academy of Higher Education Manipal 576104 Karnataka India From PythonList at DancesWithMice.info Fri Aug 21 15:56:47 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 22 Aug 2020 07:56:47 +1200 Subject: Temporary text for multiple entries In-Reply-To: <375d7850-b215-45cb-ba07-ed7f1d44ee67n@googlegroups.com> References: <375d7850-b215-45cb-ba07-ed7f1d44ee67n@googlegroups.com> Message-ID: On 22/08/2020 00:01, Ashanti Aggarwal wrote: > I am working to make a form where I have added multiple entries. I wish to add temporary text on all of them, as the text to be deleted when clicked and to inserted again when focused out. I have done with the single entry but not able to find a solution for multiple entries.Kindly suggest me a better way to do. In programming, the usual way to repeat a given set of steps is to write a function. In this case, a series of functions to handle the 'before' and 'after' behaviors might suit a "context manager". If you need further information, please help us to help you: - operating system and version - name and version of the GUI-library - more information about the full-location of this "text" - exactly what you typed/did - exactly what happened as a result - use a descriptive message title that will help other beginners with similar problems to benefit from answers-given -- Regards =dn From PythonList at DancesWithMice.info Fri Aug 21 16:14:00 2020 From: PythonList at DancesWithMice.info (dn) Date: Sat, 22 Aug 2020 08:14:00 +1200 Subject: Matrix of size 100*100- Meghna In-Reply-To: References: Message-ID: On 22/08/2020 02:17, Meghna Karkera wrote: > Dear Respected Sir > > I am Meghna, a PhD student. I have installed python in my ubuntu OS from > your website recently and tried using spyder and jupyter. > > May I request you to help me with importing few matrices, each of size > 100*100 in python from XLSX and perform operations on the matrices like > addition, multiplication, finding matrix inverse, creating diagonal > matrices each of size 100*100 from column vectors each of size 100*1, > creating identity matrix of size 100*100. I have surfed in the internet, > but unable to get answer for it. > > I would be grateful to you if you could help me in this regard. Dropping two of the key-words (above) into a search-engine produced an ideal suggestion (https://duckduckgo.com/?q=python+xlsx&t=brave&ia=web). There are code-libraries which can be added to Python for data analysis, eg numpy and pandas. Such should offer training and tutorial assistance to newcomers (in varying degrees) and be part of your choice-criteria. -- Regards =dn From joshua at azariah.com Fri Aug 21 18:27:40 2020 From: joshua at azariah.com (Joshua J. Kugler) Date: Fri, 21 Aug 2020 14:27:40 -0800 Subject: Having trouble with Mock and exception side effects Message-ID: <2910095.Wmvae1ZOTl@hosanna> Hello! I am using Mock to raise an exception in an function as a side effect. However, Mock is completely redefining the exception itself turning it in to a MagickMock object, which generates the Python exception TypeError: catching classes that do not inherit from BaseException is not allowed This is my minimal reproducible test case. # test_case.py #!/usr/bin/python3 from unittest.mock import patch import package.module print('Before patcher start:', package.module.MyException) patcher = patch('package.module') mock_hvac = patcher.start() print('After patcher start:', package.module.MyException) try: print('Right before raise:', package.module.MyException) raise package.module.MyException except package.module.MyException: print('Got the exception') package/__init__.py # Empty package/module.py class MyException(BaseException): pass Output: $ python3.6 --version Python 3.6.9 $ python3.6 test_case.py Before patcher start: After patcher start: Right before raise: Traceback (most recent call last): File "test_case.py", line 21, in raise package.module.MyException TypeError: exceptions must derive from BaseException During handling of the above exception, another exception occurred: Traceback (most recent call last): File "test_case.py", line 23, in except package.module.MyException: TypeError: catching classes that do not inherit from BaseException is not allowed This is also causing problems for Mock side effects. In this line of code in mock.py (line 997 for me): if effect is not None: if _is_exception(effect): raise effect The _is_exception() function checks for an exception via: return ( isinstance(obj, BaseExceptions) or isinstance(obj, type) and issubclass(obj, BaseExceptions) ) Which of course is false, because it's been replaced by a MagicMock object, so exception side effects aren't properly raised. According to https://docs.python.org/3.6/library/unittest.mock.html#calling calling a function after setting the side_effect should raise the Exception, not a MagicMock object. https://docs.python.org/3.6/library/unittest.mock.html#unittest.mock.Mock also says "Alternatively side_effect can be an exception class or instance. In this case the exception will be raised when the mock is called." So, this seems to be not behaving as design, or at least not as documented. This is creating some really serious problems for testing our code, as we want a function to have a side effect of an Exception, and catch that exception, but we can do neither when it has been replaced by a MagicMock object. Thanks for any tips, pointers, or "You're doing it wrong!" education. :) j -- Joshua J. Kugler - Fairbanks, Alaska - joshua at azariah.com Azariah Enterprises - Programming and Website Design PGP Key: http://pgp.mit.edu/ ID 0x68108cbb73b13b6a From larry at hastings.org Fri Aug 21 23:23:37 2020 From: larry at hastings.org (Larry Hastings) Date: Fri, 21 Aug 2020 20:23:37 -0700 Subject: [RELEASED] Python 3.5.10rc1 is released Message-ID: <18983414-ccc0-6216-23f7-89b3e1737d60@hastings.org> On behalf of the Python development community, I'm pleased to finally announce the availability of Python 3.5.10rc1. Python 3.5 is in "security fixes only" mode.? This new version only contains security fixes, not conventional bug fixes, and it is a source-only release. Important Notice: The latest releases of Linux (Ubuntu 20.04, Fedora 32) ship with a new version of OpenSSL.? New versions of OpenSSL often include upgraded configuration requirements to maintain network security; this new version no longer finds Python 3.5's OpenSSL configuration acceptable.? As a result, most or all secure-transport networking libraries are broken in this release on systems where this new version of OpenSSL is deployed.? This means, for example, that seven (7) of the regression tests in the test suite now regularly fail.? Older versions of Linux, with older versions of OpenSSL installed, are unaffected.? We're aware of the problem.? Unfortunately, as 3.5 is nearly completely out of support, it has become very low priority, and we've been unable to find the resources to get the problem fixed.? It's possible that these problems simply won't be fixed in 3.5 before it reaches its end-of-life.? As always we recommend upgrading to the latest Python release wherever possible. You can find Python 3.5.10rc1 here: https://www.python.org/downloads/release/python-3510rc1/ Cheers, //arry/ From Gronicus at SGA.Ninja Fri Aug 21 23:37:36 2020 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 21 Aug 2020 23:37:36 -0400 Subject: How do I use the data entered in a form? Message-ID: <000001d67835$9427bb80$bc773280$@SGA.Ninja> I have a simple form that I copied/modified from a python web site. A lot of it makes sense but I do not see how the form in activated. Is there some call in there that I am just not seeing? How do I use the information entered into the form. Everything works here except for line 30 where I get a "fetch not defined" error. I can send the entered information to the screen but I do not see how I can use the information outside the functions defined. Do I need a "return SR, TSR"? ================================ def Data_Entry(entries): SR = (entries['Sensor_Reading'].get()) print("SR: ", SR) #This line prints TSR = (entries['Test_Strip_Reading'].get()) print("TSR: ", TSR) #This line prints def SubmitForm(entries): print("Form Submitted") SR = entries['Sensor_Reading'].get() print("SR inside = " + SR) #This line prints def makeform(root, fields): entries = {} for field in fields: row = Frame(root) lab = Label(row, width=22, text=field+": ", anchor='w') ent = Entry(row) ent.insert(0,"0") row.pack(side = TOP, fill = X, padx = 5 , pady = 5) lab.pack(side = LEFT) ent.pack(side = RIGHT, expand = YES, fill = X) entries[field] = ent return entries if __name__ == '__main__': root = Tk() ents = makeform(root, fields) # root.bind('', (lambda event, e = ents: fetch(e))) #"fetch not defined" reported here b1 = Button(root, text = 'Submit', command=(lambda e = ents: SubmitForm(e))) b1.pack(side = LEFT, padx = 5, pady = 5) b2 = Button(root, text = 'Quit', command = root.quit) b2.pack(side = LEFT, padx = 5, pady = 5) root.mainloop() SR = (entries['Sensor_Reading'].get()) print ("SR Outside = " + SR) ================================== The last two lines were guesses but they still failed. Steve ====================================== Footnote: English speakers on a roller coaster: "Weeee" Spanish speakers on a rollercoaster: " Nosostros" From kushal at locationd.net Fri Aug 21 23:52:38 2020 From: kushal at locationd.net (Kushal Kumaran) Date: Fri, 21 Aug 2020 20:52:38 -0700 Subject: Having trouble with Mock and exception side effects In-Reply-To: <2910095.Wmvae1ZOTl@hosanna> (Joshua J. Kugler's message of "Fri, 21 Aug 2020 14:27:40 -0800") References: <2910095.Wmvae1ZOTl@hosanna> Message-ID: <87blj31gmx.fsf@copper.locationd.net> You could attempt something like what is mentioned in https://docs.python.org/3/library/unittest.mock-examples.html#partial-mocking See below. "Joshua J. Kugler" writes: > Hello! I am using Mock to raise an exception in an function as a side effect. > However, Mock is completely redefining the exception itself turning it in to a > MagickMock object, which generates the Python exception > > TypeError: catching classes that do not inherit from BaseException is not > allowed > > This is my minimal reproducible test case. > > # test_case.py > #!/usr/bin/python3 > > from unittest.mock import patch > > import package.module > > print('Before patcher start:', package.module.MyException) > orig_exception = package.module.MyException > patcher = patch('package.module') > mock_hvac = patcher.start() > > print('After patcher start:', package.module.MyException) package.module.MyException = orig_exception print('After exception restore:', package.module.MyException) > > try: > print('Right before raise:', package.module.MyException) > raise package.module.MyException > > except package.module.MyException: > print('Got the exception') > > package/__init__.py > # Empty > > package/module.py > class MyException(BaseException): > pass > > Output: > $ python3.6 --version > Python 3.6.9 > $ python3.6 test_case.py > Before patcher start: > After patcher start: id='140188666285696'> > Right before raise: > Traceback (most recent call last): > File "test_case.py", line 21, in > raise package.module.MyException > TypeError: exceptions must derive from BaseException > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "test_case.py", line 23, in > except package.module.MyException: > TypeError: catching classes that do not inherit from BaseException is not > allowed > > This is also causing problems for Mock side effects. In this line of code in > mock.py (line 997 for me): > > if effect is not None: > if _is_exception(effect): > raise effect > > The _is_exception() function checks for an exception via: > > return ( > isinstance(obj, BaseExceptions) or > isinstance(obj, type) and issubclass(obj, BaseExceptions) > ) > > Which of course is false, because it's been replaced by a MagicMock object, so > exception side effects aren't properly raised. > > According to https://docs.python.org/3.6/library/unittest.mock.html#calling > calling a function after setting the side_effect should raise the Exception, > not a MagicMock object. > It will raise what you tell it to raise. You have to maintain a reference to the original Exception object, so you can continue to use it after mocking. > https://docs.python.org/3.6/library/unittest.mock.html#unittest.mock.Mock also > says "Alternatively side_effect can be an exception class or instance. In this > case the exception will be raised when the mock is called." > > So, this seems to be not behaving as design, or at least not as documented. > This is creating some really serious problems for testing our code, as we want > a function to have a side effect of an Exception, and catch that exception, but > we can do neither when it has been replaced by a MagicMock object. > > Thanks for any tips, pointers, or "You're doing it wrong!" education. :) > Your problem is entirely described by the fact that you point out: the package.module.MyException name has been pointed to a MagicMock object. If you don't want that, you have to restore the name to what you want. -- regards, kushal From mkarkera98 at gmail.com Sat Aug 22 00:52:03 2020 From: mkarkera98 at gmail.com (Meghna Karkera) Date: Sat, 22 Aug 2020 10:22:03 +0530 Subject: Matrix of size 100*100- Meghna In-Reply-To: References: Message-ID: Dear Respected Sir, I will go through the links you provided and get back to you if there are doubts. Thanks Sincerely Meghna Raviraj Karkera On Sat, Aug 22, 2020, 01:45 dn via Python-list wrote: > On 22/08/2020 02:17, Meghna Karkera wrote: > > Dear Respected Sir > > > > I am Meghna, a PhD student. I have installed python in my ubuntu OS from > > your website recently and tried using spyder and jupyter. > > > > May I request you to help me with importing few matrices, each of size > > 100*100 in python from XLSX and perform operations on the matrices like > > addition, multiplication, finding matrix inverse, creating diagonal > > matrices each of size 100*100 from column vectors each of size 100*1, > > creating identity matrix of size 100*100. I have surfed in the internet, > > but unable to get answer for it. > > > > I would be grateful to you if you could help me in this regard. > > > Dropping two of the key-words (above) into a search-engine produced an > ideal suggestion (https://duckduckgo.com/?q=python+xlsx&t=brave&ia=web). > > There are code-libraries which can be added to Python for data analysis, > eg numpy and pandas. Such should offer training and tutorial assistance > to newcomers (in varying degrees) and be part of your choice-criteria. > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Sat Aug 22 02:25:32 2020 From: __peter__ at web.de (Peter Otten) Date: Sat, 22 Aug 2020 08:25:32 +0200 Subject: How do I use the data entered in a form? References: <000001d67835$9427bb80$bc773280$@SGA.Ninja> Message-ID: Steve wrote: > def makeform(root, fields): > entries = {} > for field in fields: ... > return entries > > if __name__ == '__main__': > root = Tk() > ents = makeform(root, fields) > > SR = (entries['Sensor_Reading'].get()) > print ("SR Outside = " + SR) > > ================================== > The last two lines were guesses but they still failed. [Always tell us how your code fails, please. If there's an exception include it and the complete traceback in your post.] In this case you probably get a NameError because 'entries' is a local variable in makeform(). In the global namespace the person you copied the code from used 'ents' -- so you have to either use ents, too, > if __name__ == '__main__': > root = Tk() ents = makeform(root, fields) ... SR = ents['Sensor_Reading'].get() or rename it > if __name__ == '__main__': > root = Tk() entries = makeform(root, fields) ... SR = entries['Sensor_Reading'].get() > # root.bind('', (lambda event, e = ents: fetch(e))) > #"fetch not defined" reported here Again, the author of the original code probably defined a fetch() function; if you want to use it you have to copy it into your script. From Gronicus at SGA.Ninja Sat Aug 22 04:16:01 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sat, 22 Aug 2020 04:16:01 -0400 Subject: How do I use the data entered in a form? In-Reply-To: References: <000001d67835$9427bb80$bc773280$@SGA.Ninja> Message-ID: <002701d6785c$797392b0$6c5ab810$@SGA.Ninja> The only thing I can add to that program as far as errors go is that "SR is Not Defined" after the program focus is outside of any def in the last line or two. Is there any location where I should place "return (SR)" or a "global SR"? I take it that "fetch" is not an inside command or reserved word. The code is everything what was posted. Nothing was indicated in the comments that any code or def was missing. I commented it out because it was causing the program to dump out preventing me from exploring the error or developing code for other purposes. Maybe I don't need it. Still the value for SR does not seem to be visible outside any of the def calls. The system reports that "SR is not defined" at the end of the file. ===================================== Footnote: If you double major in psychology and reverse psychology, to they cacel each other out? -----Original Message----- From: Python-list On Behalf Of Peter Otten Sent: Saturday, August 22, 2020 2:26 AM To: python-list at python.org Subject: Re: How do I use the data entered in a form? Steve wrote: > def makeform(root, fields): > entries = {} > for field in fields: ... > return entries > > if __name__ == '__main__': > root = Tk() > ents = makeform(root, fields) > > SR = (entries['Sensor_Reading'].get()) print ("SR Outside = " + SR) > > ================================== > The last two lines were guesses but they still failed. [Always tell us how your code fails, please. If there's an exception include it and the complete traceback in your post.] In this case you probably get a NameError because 'entries' is a local variable in makeform(). In the global namespace the person you copied the code from used 'ents' -- so you have to either use ents, too, > if __name__ == '__main__': > root = Tk() ents = makeform(root, fields) ... SR = ents['Sensor_Reading'].get() or rename it > if __name__ == '__main__': > root = Tk() entries = makeform(root, fields) ... SR = entries['Sensor_Reading'].get() > # root.bind('', (lambda event, e = ents: fetch(e))) > #"fetch not defined" reported here Again, the author of the original code probably defined a fetch() function; if you want to use it you have to copy it into your script. -- https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Sat Aug 22 06:49:37 2020 From: __peter__ at web.de (Peter Otten) Date: Sat, 22 Aug 2020 12:49:37 +0200 Subject: How do I use the data entered in a form? References: <000001d67835$9427bb80$bc773280$@SGA.Ninja> <002701d6785c$797392b0$6c5ab810$@SGA.Ninja> Message-ID: Steve wrote: > I take it that "fetch" is not an inside command or reserved word. The > code is everything what was posted. You don't say where you "found" the code. If you took it from https://www.python-course.eu/tkinter_entry_widgets.php you need to take another look. A fetch() function is provided. > The system reports that "SR is not defined" at the end of the file. After you applied the changes I suggested? From ekopalypse at gmail.com Sat Aug 22 15:48:01 2020 From: ekopalypse at gmail.com (Eko palypse) Date: Sat, 22 Aug 2020 12:48:01 -0700 (PDT) Subject: Embedded python: How to debug code in an isolated way Message-ID: Hello, background info first. On windows, python3.8.5 A cpp app has an embedded python interpreter which allows to modify/enhance the cpp app by providing objects to manipulate the cpp app and callbacks to act on certain events, like fileopen, fileclose, updateui ... which are send by the cpp app. The embedded python interpreter acts more or less like the standard python REPL. If you run a script with code like def test(i): print(i*2) test(4) then the test function is now globally available as long as the cpp app is alive. I've written a debugger based on bdb and encountered a situation which I haven't found out how to handle correctly yet. Let's assume I've registered a callback when something changes in the UI. In that case an object function gets called which highlights certain aspects in the UI. Now if I run a script via this debugger it works as long as I don't use the same object function. If I do use it, then the stack gets corrupted(?). For example it look like this stack: , 580 ', line 1, code >, 1 >, 8 now if I enter the function which call this object function this gets add , 5 I step through the code and suddenly the stack looks like this , 580 ', line 1, code >, 1 >, 8 >, 154 , 102)] EnhanceAnyLexer is neither part of the test_pydebugger script nor part of the debugger. It is used to register a callback on the updateui event. So the question is, what do I need to read/learn/understand in order to solve this issue? Or in other words, how can I debug my script in an isolated environment. I can't manipulate the __main__.dict as this seems to have general impact on registered callbacks as well. Any ideas? Thank you Eren From rosuav at gmail.com Sat Aug 22 16:57:53 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 23 Aug 2020 06:57:53 +1000 Subject: Embedded python: How to debug code in an isolated way In-Reply-To: References: Message-ID: On Sun, Aug 23, 2020 at 5:51 AM Eko palypse wrote: > So the question is, what do I need to read/learn/understand in order to solve this issue? > Or in other words, how can I debug my script in an isolated environment. I'd go for the old standby - IIDPIO: If In Doubt, Print It Out! Instead of trying to use a debug harness, just run your code normally, and print out whatever you think might be of interest. If you don't have a console, well, that would be the first thing to do - you *always* need a console. ChrisA From ekopalypse at gmail.com Sat Aug 22 17:20:19 2020 From: ekopalypse at gmail.com (Eko palypse) Date: Sat, 22 Aug 2020 23:20:19 +0200 Subject: Embedded python: How to debug code in an isolated way In-Reply-To: References: Message-ID: Thx for your tip/suggestion. > If In Doubt, Print It Out! That's the current situation and that's usually enough, but then there's this situation where it gets annoying because you realize that the print wouldn't make more sense at this point but at that point and that's where a debugger is just nicer, I think. Eren Am Sa., 22. Aug. 2020 um 22:59 Uhr schrieb Chris Angelico : > On Sun, Aug 23, 2020 at 5:51 AM Eko palypse wrote: > > So the question is, what do I need to read/learn/understand in order to > solve this issue? > > Or in other words, how can I debug my script in an isolated environment. > > I'd go for the old standby - IIDPIO: If In Doubt, Print It Out! > Instead of trying to use a debug harness, just run your code normally, > and print out whatever you think might be of interest. If you don't > have a console, well, that would be the first thing to do - you > *always* need a console. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From davedawson.co at gmail.com Sat Aug 22 22:36:13 2020 From: davedawson.co at gmail.com (Dave Dawson) Date: Sat, 22 Aug 2020 19:36:13 -0700 (PDT) Subject: Visualize dataframes in 2 lines Message-ID: <3db8eb75-1045-45de-8c22-6f40577c6e2bn@googlegroups.com> import sho sho.w(dataframe) Install : pip install sho Medium Article: https://medium.com/@davewd/sho-w-dataframe-my-first-package-b7242088b78f Github: https://github.com/davewd/sho From Gronicus at SGA.Ninja Sun Aug 23 04:40:42 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sun, 23 Aug 2020 04:40:42 -0400 Subject: How do I close a form without closing the entire program? Message-ID: <001901d67929$16ddc120$44994360$@SGA.Ninja> This program is fully operational with the exception of not being able to close the form when I have completed the data entry. If I have code for a second form, both remain visible. Thoughts appreciated.... ================================================================ from tkinter import * def ShowForm1(): fields1 = ('Sensor_Reading', 'Test_Strip_Reading', 'Dose', 'o2') def Data_Entry1(entries1): SR = (entries['Sensor_Reading'].get()) TSR = (entries['Test_Strip_Reading'].get()) Dose = (entries['Dose'].get()) o2 = (entries['o2'].get()) def SubmitForm(entries1): SR = entries1['Sensor_Reading'].get() TSR = entries1['Test_Strip_Reading'].get() Dose = (entries1['Dose'].get()) o2 = (entries1['o2'].get()) FormDataInfo=open("Form1Data.txt", "w") # Start a new file FormDataInfo.write("\n" + " SR = " + SR + "\n") FormDataInfo.write(" TSR = " + TSR + "\n") FormDataInfo.write(" Dose = " + Dose + "\n") FormDataInfo.write(" o2 = " + o2 + "\n") FormDataInfo.close() print("Line written to file1") def makeform1(root, fields1): entries1 = {} for field1 in fields1: row = Frame(root) lab = Label(row, width=22, text=field1+": ", anchor='w') ent = Entry(row) ent.insert(0,"0") row.pack(side = TOP, fill = X, padx = 5 , pady = 5) lab.pack(side = LEFT) ent.pack(side = RIGHT, expand = YES, fill = X) entries1[field1] = ent return entries1 if __name__ == '__main__': root1 = Tk() ents = makeform1(root1, fields1) b1 = Button(root1, text = 'Submit', command=(lambda e = ents: SubmitForm(e))) b1.pack(side = LEFT, padx = 5, pady = 5) b2 = Button(root1, text = 'Quit', command = root1.quit) b2.pack(side = LEFT, padx = 5, pady = 5) root1.mainloop() # ======================================================= ShowForm1() print(" End ") # ======================================================= Steve ---------------------------------------------------------------- Footnote: The human brain is one of the most complex things known to man. according to the human brain. From cl at isbd.net Sun Aug 23 05:00:50 2020 From: cl at isbd.net (Chris Green) Date: Sun, 23 Aug 2020 10:00:50 +0100 Subject: "dictionary changed size during iteration" error in Python 3 but not in Python 2 Message-ID: <2rn91h-skde.ln1@esprimo.zbmc.eu> I have a (fairly) simple little program that removes old mail messages from my junk folder. I have just tried to upgrade it from Python 2 to Python 3 and now, when it finds any message[s] to delete it produces the error:- RuntimeError: dictionary changed size during iteration I can sort of see why I'm getting the error but have two questions: 1 - Why doesn't it error in Python 2? 2 - How do I fix it? Here is the program:- #!/usr/bin/python3 # # # Remove old mail from mbox files # import email import mailbox import os import sys import time # # # Constants/configuration # junkdir = "/home/chris/Mail/Ju" # directory to clear old mail from days = 7 # remove mail older than this # # # # for f in os.listdir(junkdir): mbxPath = os.path.join(junkdir, f) mbx = mailbox.mbox(mbxPath, factory=None) try: mbx.lock() for k, msg in mbx.iteritems(): subject = msg['subject'] if msg['date'] is None: continue parsedDate = email.utils.parsedate(msg['date']) if parsedDate is None: print (subject + '\n - Bad date format:- "' + msg['date'] + '"') continue msgDate = time.mktime(parsedDate) if (time.time() - msgDate) / (24 * 60 * 60) > days: mbx.remove(k) mbx.flush() mbx.unlock() except mailbox.ExternalClashError: print ("Failed to lock: " + mbxPath) -- Chris Green ? From cs at cskk.id.au Sun Aug 23 05:43:34 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 23 Aug 2020 19:43:34 +1000 Subject: "dictionary changed size during iteration" error in Python 3 but not in Python 2 In-Reply-To: <2rn91h-skde.ln1@esprimo.zbmc.eu> References: <2rn91h-skde.ln1@esprimo.zbmc.eu> Message-ID: <20200823094334.GA86729@cskk.homeip.net> On 23Aug2020 10:00, Chris Green wrote: >I have a (fairly) simple little program that removes old mail messages >from my junk folder. I have just tried to upgrade it from Python 2 to >Python 3 and now, when it finds any message[s] to delete it produces >the error:- > > RuntimeError: dictionary changed size during iteration > >I can sort of see why I'm getting the error but have two questions: > >1 - Why doesn't it error in Python 2? The dict internal implementation has changed. I don't know the specifics, but it is now faster and maybe smaller and also now preserves insert order. >2 - How do I fix it? That standard way is to take a copy of what you're iterating over, usually just the keys (consumes less memory). BTW, this approach is standard for _any_ data structure you're iterating over and modifying. So: for k, v in d.iteritems(): ... d.remove(k) ... might become: for k, v in list(d.iteritems()): ... d.remove(k) ... or: for k in list(d): v = d[k] ... d.remove(k) ... The iterators from iteritems or iterkeys (and plain old items and keys in Python 3) walk over the internal structure, which is a hash table. A typical dynamic hash table will resize every so often if items are inserted or removed, which doesn't just rearrange things, it can reorder the keys because the distribution of the keys into buckets can change as the number of buckets changes. Cheers, Cameron Simpson From cl at isbd.net Sun Aug 23 10:43:13 2020 From: cl at isbd.net (Chris Green) Date: Sun, 23 Aug 2020 15:43:13 +0100 Subject: "dictionary changed size during iteration" error in Python 3 but not in Python 2 References: <2rn91h-skde.ln1@esprimo.zbmc.eu> <20200823094334.GA86729@cskk.homeip.net> Message-ID: <1tba1h-f6lf.ln1@esprimo.zbmc.eu> Cameron Simpson wrote: > On 23Aug2020 10:00, Chris Green wrote: > >I have a (fairly) simple little program that removes old mail messages > >from my junk folder. I have just tried to upgrade it from Python 2 to > >Python 3 and now, when it finds any message[s] to delete it produces > >the error:- > > > > RuntimeError: dictionary changed size during iteration > > > >I can sort of see why I'm getting the error but have two questions: > > > >1 - Why doesn't it error in Python 2? > > The dict internal implementation has changed. I don't know the > specifics, but it is now faster and maybe smaller and also now preserves > insert order. > Ah, that probably explains it then. > >2 - How do I fix it? > > That standard way is to take a copy of what you're iterating over, > usually just the keys (consumes less memory). > > BTW, this approach is standard for _any_ data structure you're iterating > over and modifying. > > So: > > for k, v in d.iteritems(): > ... d.remove(k) ... > > might become: > > for k, v in list(d.iteritems()): > ... d.remove(k) ... > I've been [not]understanding it the wrong way round! I was somehow trying to copy the iterator and then doing things to the copy, I now see that you make a copy to iterate over (that isn't modified) and you do what's necessary to the original. Obvious really! :-) -- Chris Green ? From __peter__ at web.de Sun Aug 23 11:40:13 2020 From: __peter__ at web.de (Peter Otten) Date: Sun, 23 Aug 2020 17:40:13 +0200 Subject: "dictionary changed size during iteration" error in Python 3 but not in Python 2 References: <2rn91h-skde.ln1@esprimo.zbmc.eu> <20200823094334.GA86729@cskk.homeip.net> <1tba1h-f6lf.ln1@esprimo.zbmc.eu> Message-ID: Chris Green wrote: >> >1 - Why doesn't it error in Python 2? >> >> The dict internal implementation has changed. I don't know the >> specifics, but it is now faster and maybe smaller and also now preserves >> insert order. >> > Ah, that probably explains it then. But if you try to modify a dict while you iterate over it in py2 you trigger the same error: $ python Python 2.7.6 (default, Nov 13 2018, 12:45:42) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> d = dict(a=1) >>> for k in d: del d["a"] ... Traceback (most recent call last): File "", line 1, in RuntimeError: dictionary changed size during iteration If you look at the 2.7 mailbox code you'll find that the iteritems() method delegates to iterkeys() which in turn uses keys(), not iterkeys() as one might expect, for key in self._toc.keys(): yield key of the underlying _toc dict, and in py2 keys() creates a list of keys. In py3 the above loop becomes yield from self._toc.keys() but in py3 the keys() method returns a view on the underlying dict. From rob.cliffe at btinternet.com Sun Aug 23 03:31:13 2020 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Sun, 23 Aug 2020 08:31:13 +0100 Subject: Program chaining on Windows Message-ID: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> On WIndows 10, running Python programs in a DOS box, I would like one Python program to chain to another.? I.e. the first program to be replaced by the second (*not* waiting for the second to finish, as with e.g. os.system).? This doesn't seem a lot to ask, but so far I have been unable to so this.? I am using Python 3.8.3.? Some attempts so far (may be nonsensical): ATTEMPT #1 ---------------- # File X1.py import os print("This is X1") os.execl('C:\\Python38\\python.exe', 'X2.py') # File X2.py print("This is X2") When I type "X1.py", it prints "This is X1", then starts the Python interactive interpreter.? Furthermore: ??? TLDR: Weird behaviour ??? Long version:? If I attempt to exit the interpreter with ctl-Z, this apparently succeeds (displaying the Windows command prompt), but in reality it is still in the interpreter, e.g. if I type "dir" it responds "" followed by the ">>>" interpreter prompt.? And this cycle (ctl-Z etc.) can be repeated ad nauseam.? If instead I try to exit from the interpreter with "exit()", the cursor moves to the next line and the interpreter waits for more input (but without displaying the prompt). If I try "exit()" again, the whole DOS box disappears. ATTEMPT #2 ----------------- # File X1.py import os print("This is X1") os.execl("C:\\Python38\\python.exe X2.py", '') This raises ValueError: execv() arg 2 first element cannot be empty ATTEMPT #3 ---------------- import os, sys print("This is X1") os.execl("%s X2.py" % sys.executable, "X2.py") This raises FileNotFoundError: [Errno 2] No such file or directory ATTEMPT #4 ---------------- # File X1.py import os, sys print("This is X1") os.execv(sys.executable, ['X2.py']) This behaves the same as, or similarly to, Attempt #1. ATTEMPT #5 ---------------- # File X1.py import os print("This is X1") os.popen('python X2.py') # File X2.py as previously ??? TLDR: Really weird behaviour! ??? Long version: If I type "X1.py", it displays "This is X1" followed by the DOS prompt.? If I type in a DOS command, it is executed, and the DOS prompt displayed.? However, if I type in another DOS command, nothing happens except that the cursor moves to the next line and waits for input (no prompt).? If I type in a further DOS command, it is executed.? If I type still another DOS command, I see Exception ignored in: OSError: [Errno 22] Invalid argument and the cursor moves to the next line (no prompt).? If I type in one more DOS command, it is executed, and we appear to be back to normal DOS operation. ATTEMPT #6 ----------------- # File X1.py import subprocess, sys print("This is X1") subprocess.Popen('X2.py', executable=sys.executable) This behaves the same as, or similarly to, Attempt #1. ATTEMPT #7 ----------------- # File X1.py import subprocess, sys print("This is X1") subprocess.Popen('-c X2.py', executable=sys.executable) ?? # added -c # File X2.py print("This is X2") Some progress (maybe).? This prints "This is X1", then the DOS prompt followed by "This is X2", then the cursor moves to the next line and sits waiting for input (no prompt).? If I then type something in, this is interpreted as a DOS command, and finally the DOS prompt is displayed.? To find out more about what is happening: ATTEMPT #8 ---------------- # File X1.py as above # File X2.py print("This is X2") input("Press Enter to continue X2") input("Press Enter to quit X2") If I type "X1.py", it displays: This is X1 C:\Python38>This is X2 Press Enter to continue X2 Now: ??? TLDR: More weird behaviour, as if Windows and X2.py were taking turns to collect lines from the console. ??? Long version: Now if I type something in and press Enter, it is interpreted as a *DOS command".? Then the DOS prompt is displayed. Now if I (type something and) hit Enter, I see Press Enter to quit X2 Now if I type something and hit Enter, it is interpreted as a DOS command, and the DOS prompt is displayed again.? Now if I type in a DOS command and press Enter, it is ignored but the cursor moves to the next line and waits for input (no prompt).? Now if I type another DOS command, it is executed.? Finally we appear to be done (the DOS prompt is displayed and we are back to normal DOS operation). Am I missing something?? Is there a way in Windows for one Python program to "chain" to another (or indeed to any executable) without waiting for the latter to finish? Thanks in advance Rob Cliffe From debchat1955 at gmail.com Sun Aug 23 12:39:58 2020 From: debchat1955 at gmail.com (Debasis Chatterjee) Date: Sun, 23 Aug 2020 11:39:58 -0500 Subject: Issue in installing Python (Windows 10) In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Debasis Chatterjee Date: Sun, Aug 23, 2020 at 11:06 AM Subject: Issue in installing Python (Windows 10) To: Hi I started off by using "python-3.8.5.exe". I use "Run as Administrator" option to click this (provide my local-admin username/pwd). After this, I see python shell available. But no IDLE. Not sure why? >From CMD, I can check "pip list". Surprisingly, it shows me packages that I installed earlier, before deinstalling and reinstalling. I am doing all these steps because earlier my program could not see installed packages although I could see using "pip list". Something is not right. Hence I am trying to make a fresh restart. One thing odd is that even after removing installed program (Python) from control panel, I still find that from "Start". Please help. Thank you Debasis Chatterjee From grant.b.edwards at gmail.com Sun Aug 23 12:58:52 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 23 Aug 2020 16:58:52 -0000 (UTC) Subject: Embedded python: How to debug code in an isolated way References: Message-ID: On 2020-08-22, Chris Angelico wrote: > On Sun, Aug 23, 2020 at 5:51 AM Eko palypse wrote: >> So the question is, what do I need to read/learn/understand in order to solve this issue? >> Or in other words, how can I debug my script in an isolated environment. > > I'd go for the old standby - IIDPIO: If In Doubt, Print It Out! > Instead of trying to use a debug harness, just run your code normally, > and print out whatever you think might be of interest. If you don't > have a console, well, that would be the first thing to do - you > *always* need a console. Yep. Even if you have to bit-bang a tx-only UART on a GPIO pin. I've had to do that many times, and the last time was only a couple years ago. Though I must admit I never had to do that _in_ Python or on a platform capable of running Python... -- Grant From rosuav at gmail.com Sun Aug 23 16:10:22 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Aug 2020 06:10:22 +1000 Subject: Embedded python: How to debug code in an isolated way In-Reply-To: References: Message-ID: On Mon, Aug 24, 2020 at 6:00 AM Grant Edwards wrote: > > On 2020-08-22, Chris Angelico wrote: > > On Sun, Aug 23, 2020 at 5:51 AM Eko palypse wrote: > >> So the question is, what do I need to read/learn/understand in order to solve this issue? > >> Or in other words, how can I debug my script in an isolated environment. > > > > I'd go for the old standby - IIDPIO: If In Doubt, Print It Out! > > Instead of trying to use a debug harness, just run your code normally, > > and print out whatever you think might be of interest. If you don't > > have a console, well, that would be the first thing to do - you > > *always* need a console. > > Yep. Even if you have to bit-bang a tx-only UART on a GPIO pin. > > I've had to do that many times, and the last time was only a couple > years ago. Though I must admit I never had to do that _in_ Python or > on a platform capable of running Python... > Haha, yep. That's also why the first "hello world" on any embedded system is also an important tool in itself - if you can make an LED flicker on and off in response to your code, then you have the most rudimentary of print functionality that you can use to debug everything else... ChrisA From PythonList at DancesWithMice.info Sun Aug 23 16:37:33 2020 From: PythonList at DancesWithMice.info (dn) Date: Mon, 24 Aug 2020 08:37:33 +1200 Subject: Program chaining on Windows In-Reply-To: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> Message-ID: <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> On 23/08/2020 19:31, Rob Cliffe via Python-list wrote: > On WIndows 10, running Python programs in a DOS box, I would like one > Python program to chain to another.? I.e. the first program to be > replaced by the second (*not* waiting for the second to finish, as with > e.g. os.system).? This doesn't seem a lot to ask, but so far I have been > unable to so this.? I am using Python 3.8.3.? Some attempts so far (may > be nonsensical): What is the definition of "finish" in the first program? Not sure if have understood <<<(*not* waiting for the second to finish, as with e.g. os.system)>>>. In Python, the easiest way to chain two "modules" is to use import. This gives full control to the 'import-er'. > ATTEMPT #1 > ---------------- > # File X1.py > import os > print("This is X1") > os.execl('C:\\Python38\\python.exe', 'X2.py') > > # File X2.py > print("This is X2") # File X1.py import os def fn(): print("This is X1") os.execl('C:\\Python38\\python.exe', 'X2.py') # !!!!! # File X2.py def fn(): print("This is X2") # File x3.py import x1 import x2 x1.fn() x2.fn() print( "x3 terminating" ) -- Regards =dn From rosuav at gmail.com Sun Aug 23 17:04:33 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Aug 2020 07:04:33 +1000 Subject: Program chaining on Windows In-Reply-To: <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: On Mon, Aug 24, 2020 at 6:39 AM dn via Python-list wrote: > > On 23/08/2020 19:31, Rob Cliffe via Python-list wrote: > > On WIndows 10, running Python programs in a DOS box, I would like one > > Python program to chain to another. I.e. the first program to be > > replaced by the second (*not* waiting for the second to finish, as with > > e.g. os.system). This doesn't seem a lot to ask, but so far I have been > > unable to so this. I am using Python 3.8.3. Some attempts so far (may > > be nonsensical): > > What is the definition of "finish" in the first program? > Not sure if have understood <<<(*not* waiting for the second to finish, > as with e.g. os.system)>>>. > In Python, the easiest way to chain two "modules" is to use import. This > gives full control to the 'import-er'. > With exec, the intention is to *replace* the current program, not to invoke it and wait till it's done. The current program will not continue after a successful exec. ChrisA From barry at barrys-emacs.org Sun Aug 23 16:47:34 2020 From: barry at barrys-emacs.org (Barry) Date: Sun, 23 Aug 2020 21:47:34 +0100 Subject: Program chaining on Windows In-Reply-To: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> Message-ID: <42FC378B-3AC1-402D-AAF2-E4CBC23709BE@barrys-emacs.org> > On 23 Aug 2020, at 20:58, Rob Cliffe via Python-list wrote: > > ?On WIndows 10, running Python programs in a DOS box, I would like one Python program to chain to another. I.e. the first program to be replaced by the second (*not* waiting for the second to finish, as with e.g. os.system). This doesn't seem a lot to ask, but so far I have been unable to so this. I am using Python 3.8.3. Some attempts so far (may be nonsensical): > > ATTEMPT #1 > ---------------- > # File X1.py > import os > print("This is X1") > os.execl('C:\\Python38\\python.exe', 'X2.py') I think you need to have this (untested): os.execl('C:\\Python38\\python.exe', 'C:\\Python38\\python.exe', 'X2.py') You must put the path as the first arg, it is not done for you. You version ran python without an arg so it thinks you want a interactive session. Barry > > # File X2.py > print("This is X2") > > When I type "X1.py", it prints "This is X1", then starts the Python interactive interpreter. Furthermore: > TLDR: Weird behaviour > Long version: If I attempt to exit the interpreter with ctl-Z, this apparently succeeds (displaying the Windows command prompt), but in reality it is still in the interpreter, e.g. if I type "dir" it responds "" followed by the ">>>" interpreter prompt. And this cycle (ctl-Z etc.) can be repeated ad nauseam. If instead I try to exit from the interpreter with "exit()", the cursor moves to the next line and the interpreter waits for more input (but without displaying the prompt). If I try "exit()" again, the whole DOS box disappears. > > ATTEMPT #2 > ----------------- > # File X1.py > import os > print("This is X1") > os.execl("C:\\Python38\\python.exe X2.py", '') Arg 1 is a path to a program, not a command line. So?python.exe? or maybe ?X2.py?. > > This raises ValueError: execv() arg 2 first element cannot be empty > > ATTEMPT #3 > ---------------- > > import os, sys > print("This is X1") > os.execl("%s X2.py" % sys.executable, "X2.py") > > This raises FileNotFoundError: [Errno 2] No such file or directory > > ATTEMPT #4 > ---------------- > # File X1.py > import os, sys > print("This is X1") > os.execv(sys.executable, ['X2.py']) > > This behaves the same as, or similarly to, Attempt #1. > > ATTEMPT #5 > ---------------- > # File X1.py > import os > print("This is X1") > os.popen('python X2.py') > > # File X2.py as previously > > TLDR: Really weird behaviour! > Long version: If I type "X1.py", it displays "This is X1" followed by the DOS prompt. If I type in a DOS command, it is executed, and the DOS prompt displayed. However, if I type in another DOS command, nothing happens except that the cursor moves to the next line and waits for input (no prompt). If I type in a further DOS command, it is executed. If I type still another DOS command, I see > > Exception ignored in: > OSError: [Errno 22] Invalid argument > > and the cursor moves to the next line (no prompt). If I type in one more DOS command, it is executed, and we appear to be back to normal DOS operation. > > ATTEMPT #6 > ----------------- > # File X1.py > import subprocess, sys > print("This is X1") > subprocess.Popen('X2.py', executable=sys.executable) > > This behaves the same as, or similarly to, Attempt #1. > > ATTEMPT #7 > ----------------- > # File X1.py > import subprocess, sys > print("This is X1") > subprocess.Popen('-c X2.py', executable=sys.executable) # added -c > > # File X2.py > print("This is X2") > > Some progress (maybe). This prints "This is X1", then the DOS prompt followed by "This is X2", then the cursor moves to the next line and sits waiting for input (no prompt). If I then type something in, this is interpreted as a DOS command, and finally the DOS prompt is displayed. To find out more about what is happening: > > ATTEMPT #8 > ---------------- > # File X1.py as above > > # File X2.py > print("This is X2") > input("Press Enter to continue X2") > input("Press Enter to quit X2") > > If I type "X1.py", it displays: > > This is X1 > C:\Python38>This is X2 > Press Enter to continue X2 > > Now: > TLDR: More weird behaviour, as if Windows and X2.py were taking turns to collect lines from the console. > Long version: Now if I type something in and press Enter, it is interpreted as a *DOS command". Then the DOS prompt is displayed. Now if I (type something and) hit Enter, I see > > Press Enter to quit X2 > > Now if I type something and hit Enter, it is interpreted as a DOS command, and the DOS prompt is displayed again. Now if I type in a DOS command and press Enter, it is ignored but the cursor moves to the next line and waits for input (no prompt). Now if I type another DOS command, it is executed. Finally we appear to be done (the DOS prompt is displayed and we are back to normal DOS operation). > > > Am I missing something? Is there a way in Windows for one Python program to "chain" to another (or indeed to any executable) without waiting for the latter to finish? > Thanks in advance > Rob Cliffe > > -- > https://mail.python.org/mailman/listinfo/python-list From eryksun at gmail.com Sun Aug 23 17:27:39 2020 From: eryksun at gmail.com (Eryk Sun) Date: Sun, 23 Aug 2020 16:27:39 -0500 Subject: Program chaining on Windows In-Reply-To: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> Message-ID: On 8/23/20, Rob Cliffe via Python-list wrote: > > Am I missing something? Is there a way in Windows for one Python > program to "chain" to another (or indeed to any executable) without > waiting for the latter to finish? Windows does not implement anything equivalent to the POSIX exec family of system calls. The C runtime library implements exec functions by spawning a new process and exiting the current process. So a parent process, such as a shell, that's waiting on the current process will resume, including its console I/O. If it had been up to me, I would have ignored the C runtime exec functions in Windows Python. They only lead to problems with cross-platform code that assumes they work like the POSIX exec functions. Cross-platform code needs to spawn, wait, and proxy the child's exit code. From barry at barrys-emacs.org Sun Aug 23 16:55:02 2020 From: barry at barrys-emacs.org (Barry) Date: Sun, 23 Aug 2020 21:55:02 +0100 Subject: Embedded python: How to debug code in an isolated way In-Reply-To: References: Message-ID: > On 22 Aug 2020, at 20:53, Eko palypse wrote: > > ?Hello, > > background info first. On windows, python3.8.5 > > A cpp app has an embedded python interpreter which allows to modify/enhance the cpp app > by providing objects to manipulate the cpp app and callbacks to act on certain events, > like fileopen, fileclose, updateui ... which are send by the cpp app. > The embedded python interpreter acts more or less like the standard python REPL. > If you run a script with code like > > def test(i): > print(i*2) > > test(4) > > then the test function is now globally available as long as the cpp app is alive. > > I've written a debugger based on bdb and encountered a situation which I haven't found out how to handle correctly yet. > > Let's assume I've registered a callback when something changes in the UI. > In that case an object function gets called which highlights certain aspects in the UI. > > Now if I run a script via this debugger it works as long as I don't use the same object function. > If I do use it, then the stack gets corrupted(?). When the app calls into python does the event loop of the gui block? When you print does that trigger the event loop to run in a nested call back into the cpp? Maybe you need to run python in its own thread and Marshall in and out of the gui main thread with the event loop? Barry > For example it look like this > > stack: > , 580 > ', line 1, code >, 1 > >, 8 > > now if I enter the function which call this object function this gets add > > , 5 > > I step through the code and suddenly the stack looks like this > > , 580 > ', line 1, code >, 1 > >, 8 > >, 154 > , 102)] > > EnhanceAnyLexer is neither part of the test_pydebugger script nor part of the debugger. > It is used to register a callback on the updateui event. > > So the question is, what do I need to read/learn/understand in order to solve this issue? > Or in other words, how can I debug my script in an isolated environment. > I can't manipulate the __main__.dict as this seems to have general impact on registered callbacks as well. > Any ideas? > > Thank you > Eren > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Sun Aug 23 17:38:57 2020 From: PythonList at DancesWithMice.info (dn) Date: Mon, 24 Aug 2020 09:38:57 +1200 Subject: Program chaining on Windows In-Reply-To: References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: On 24/08/2020 09:04, Chris Angelico wrote: > On Mon, Aug 24, 2020 at 6:39 AM dn via Python-list > wrote: >> >> On 23/08/2020 19:31, Rob Cliffe via Python-list wrote: >>> On WIndows 10, running Python programs in a DOS box, I would like one >>> Python program to chain to another. I.e. the first program to be >>> replaced by the second (*not* waiting for the second to finish, as with >>> e.g. os.system). This doesn't seem a lot to ask, but so far I have been >>> unable to so this. I am using Python 3.8.3. Some attempts so far (may >>> be nonsensical): >> >> What is the definition of "finish" in the first program? >> Not sure if have understood <<<(*not* waiting for the second to finish, >> as with e.g. os.system)>>>. >> In Python, the easiest way to chain two "modules" is to use import. This >> gives full control to the 'import-er'. >> > > With exec, the intention is to *replace* the current program, not to > invoke it and wait till it's done. The current program will not > continue after a successful exec. As a 'general rule', isn't exec() something to be avoided? With an appropriate conditional control between the three modules, and bearing @Eryk's observations in-mind (and the lack of specifics in the OP), won't the import option succeed and won't all of file1's attributes be garbage-collected? Same effect, or something missing? -- Regards =dn From rosuav at gmail.com Sun Aug 23 18:16:48 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Aug 2020 08:16:48 +1000 Subject: Program chaining on Windows In-Reply-To: References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: On Mon, Aug 24, 2020 at 7:40 AM dn via Python-list wrote: > > On 24/08/2020 09:04, Chris Angelico wrote: > > On Mon, Aug 24, 2020 at 6:39 AM dn via Python-list > > wrote: > >> > >> On 23/08/2020 19:31, Rob Cliffe via Python-list wrote: > >>> On WIndows 10, running Python programs in a DOS box, I would like one > >>> Python program to chain to another. I.e. the first program to be > >>> replaced by the second (*not* waiting for the second to finish, as with > >>> e.g. os.system). This doesn't seem a lot to ask, but so far I have been > >>> unable to so this. I am using Python 3.8.3. Some attempts so far (may > >>> be nonsensical): > >> > >> What is the definition of "finish" in the first program? > >> Not sure if have understood <<<(*not* waiting for the second to finish, > >> as with e.g. os.system)>>>. > >> In Python, the easiest way to chain two "modules" is to use import. This > >> gives full control to the 'import-er'. > >> > > > > With exec, the intention is to *replace* the current program, not to > > invoke it and wait till it's done. The current program will not > > continue after a successful exec. > > > As a 'general rule', isn't exec() something to be avoided? > Nope, it's a very important tool. Not for every situation, of course, but there are plenty of times when it's the right thing to do. ChrisA From eryksun at gmail.com Sun Aug 23 19:08:27 2020 From: eryksun at gmail.com (Eryk Sun) Date: Sun, 23 Aug 2020 18:08:27 -0500 Subject: Program chaining on Windows In-Reply-To: References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: On 8/23/20, Chris Angelico wrote: > On Mon, Aug 24, 2020 at 7:40 AM dn via Python-list > >> As a 'general rule', isn't exec() something to be avoided? > > Nope, it's a very important tool. Not for every situation, of course, > but there are plenty of times when it's the right thing to do. In POSIX, yes, but the faked implementation in Windows is almost always the wrong choice. Since the exec functions in Windows simply spawn a new process and exit the current process instead of replacing the executable image of the current process, they result in broken semantics for a waiting parent process, both in terms of getting the correct exit status and waiting for the process to exit. The result of the latter is an unworkable mess with console applications, since both the parent and child will compete for console I/O. For Windows, we need to spawn, wait, and proxy the exit status. If possible, the spawned child process should also be added to a kill-on-close job object, like the py.exe launcher does. That way if the waiting parent crashes or gets terminated, the spawned child will be terminated as well. From rob.cliffe at btinternet.com Sun Aug 23 19:49:44 2020 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 24 Aug 2020 00:49:44 +0100 Subject: Program chaining on Windows In-Reply-To: <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: Thanks for everyone who replied so far, it is appreciated.? (I don't particularly like asking for help and taking up other peoples' time, but I really ran out of ideas.) Chris, thanks for your explanation: With exec, the intention is to*replace* the current program, not to invoke it and wait till it's done. The current program will not continue after a successful exec. That describes exactly what I want to do, but haven't succeeded in doing so far.? It's a bit frustrating that I can't do what I have been doing routinely for decades in another language. dn asked ??? What is the definition of "finish" in the first program? ??? Not sure if have understood <<<(*not* waiting for the second to finish, as with e.g. os.system)>>>. My definition of "finish" is that the program exits (sys.exit()? and friends), without waiting for the second program to finish. So if I were "chaining" say to a .exe file, the Python interpreter would shut down immediately. In Chris' words, I want the second program to *replace* the first one. Barry, thanks for your suggestion: os.execl('C:\\Python38\\python.exe', 'C:\\Python38\\python.exe', 'X2.py') but I'm afraid it didn't help.? I tried it and got the same behaviour (Python and Windows alternately grabbing console input lines) as my "ATTEMPT #8" which used ??? subprocess.Popen('-c X2.py', executable=sys.executable) Anything dubious about exec (or whatever) doesn't worry me as this is development, not live installation. Let me describe my actual use case.? I am developing a large Python program (in Windows, working in DOS boxes) and I constantly want to modify it and re-run it.? What I have been doing is to make it respond to a hotkey by calling itself via os.system.? The problem is that if I do this 50 times I am left with 51 instances still running, each one waiting for the next to finish.? That's actually OK, except that when I finally shut it down, it takes a long time (about 2.5 sec per instance). I have found a workaround: a small shell program which calls the main program (wth os.system), then when the latter exits, calls it again (if required).? Starting the main program is slightly slower, but acceptably so; shutting it down becomes constant time. But I would still like to be able to do it as I originally planned, if possible.? Not least because I may have other uses for program "chaining" in future. Best wishes Rob Cliffe On 23/08/2020 21:37, dn via Python-list wrote: > On 23/08/2020 19:31, Rob Cliffe via Python-list wrote: >> On WIndows 10, running Python programs in a DOS box, I would like one >> Python program to chain to another. I.e. the first program to be >> replaced by the second (*not* waiting for the second to finish, as >> with e.g. os.system).? This doesn't seem a lot to ask, but so far I >> have been unable to so this.? I am using Python 3.8.3.? Some attempts >> so far (may be nonsensical): > > What is the definition of "finish" in the first program? > Not sure if have understood <<<(*not* waiting for the second to > finish, as with e.g. os.system)>>>. > In Python, the easiest way to chain two "modules" is to use import. > This gives full control to the 'import-er'. > > >> ATTEMPT #1 >> ---------------- >> # File X1.py >> import os >> print("This is X1") >> os.execl('C:\\Python38\\python.exe', 'X2.py') >> >> # File X2.py >> print("This is X2") > > > # File X1.py > import os > def fn(): > ??? print("This is X1") > ??? os.execl('C:\\Python38\\python.exe', 'X2.py') > ??? #? !!!!! > > # File X2.py > def fn(): > ??? print("This is X2") > > # File x3.py > import x1 > import x2 > x1.fn() > x2.fn() > print( "x3 terminating" ) > > From rosuav at gmail.com Sun Aug 23 19:57:44 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Aug 2020 09:57:44 +1000 Subject: Program chaining on Windows In-Reply-To: References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: On Mon, Aug 24, 2020 at 9:51 AM Rob Cliffe via Python-list wrote: > Let me describe my actual use case. I am developing a large Python > program (in Windows, working in DOS boxes) and I constantly want to > modify it and re-run it. What I have been doing is to make it respond > to a hotkey by calling itself via os.system. The problem is that if I > do this 50 times I am left with 51 instances still running, each one > waiting for the next to finish. That's actually OK, except that when I > finally shut it down, it takes a long time (about 2.5 sec per instance). > > I have found a workaround: a small shell program which calls the main > program (wth os.system), then when the latter exits, calls it again (if > required). Starting the main program is slightly slower, but acceptably > so; shutting it down becomes constant time. > > But I would still like to be able to do it as I originally planned, if > possible. Not least because I may have other uses for program > "chaining" in future. > Hmm. Python isn't really set up to make this sort of thing easy. My recommendations, in order of priority, would be: 1) What you're doing, but with a dedicated exit code that means "changed, please restart me" 2) The same thing but entirely within Python. Instead of importing modules, manually load them and exec the source code. (No relation to the process-level exec - I'm talking about the exec function.) Updating is way WAY faster, but it isn't the same thing as restarting. Your code has to be built with this in mind. 3) Similar to #2 but using a language that's designed with that kind of thing in mind. Off topic for this list but it's something I've done on a number of occasions, so I'd be happy to discuss that with you. 4) Any other option available 5) Messing with exec on Windows ChrisA From soyeomul at doraji.xyz Sun Aug 23 22:54:13 2020 From: soyeomul at doraji.xyz (=?utf-8?B?7Zmp67OR7Z2s?=) Date: Mon, 24 Aug 2020 11:54:13 +0900 Subject: There is LTS? Message-ID: Hi, just i am curious. There is LTS for *Python*? If so, i am very thank you for Python Project. Yesterday, by chance, i heard that there is LTS for Linux Kernel. The idea seems so beautiful!!! Sincerely, Byung-Hee -- ^????? _????_ ?????_^))// From grant.b.edwards at gmail.com Sun Aug 23 21:41:55 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 24 Aug 2020 01:41:55 -0000 (UTC) Subject: Embedded python: How to debug code in an isolated way References: Message-ID: On 2020-08-23, Chris Angelico wrote: > On Mon, Aug 24, 2020 at 6:00 AM Grant Edwards wrote: >> >> On 2020-08-22, Chris Angelico wrote: >> > On Sun, Aug 23, 2020 at 5:51 AM Eko palypse wrote: >> >> So the question is, what do I need to read/learn/understand in order to solve this issue? >> >> Or in other words, how can I debug my script in an isolated environment. >> > >> > I'd go for the old standby - IIDPIO: If In Doubt, Print It Out! >> > Instead of trying to use a debug harness, just run your code normally, >> > and print out whatever you think might be of interest. If you don't >> > have a console, well, that would be the first thing to do - you >> > *always* need a console. >> >> Yep. Even if you have to bit-bang a tx-only UART on a GPIO pin. >> >> I've had to do that many times, and the last time was only a couple >> years ago. Though I must admit I never had to do that _in_ Python or >> on a platform capable of running Python... > > Haha, yep. That's also why the first "hello world" on any embedded > system is also an important tool in itself - if you can make an LED > flicker on and off in response to your code, then you have the most > rudimentary of print functionality that you can use to debug > everything else... Yep, you can send morse code, or a simple "one flash when I get here", "two flashes when I get here", etc. Turn it on here off there, and now you can profile performance. -- Grant From leo at superlel.me Mon Aug 24 03:08:44 2020 From: leo at superlel.me (=?UTF-8?Q?L=c3=a9o_El_Amri?=) Date: Mon, 24 Aug 2020 09:08:44 +0200 Subject: There is LTS? In-Reply-To: References: Message-ID: <850a0414-6810-830b-a6f8-5df3904ffc32@superlel.me> On 24/08/2020 04:54, ??? wrote: > Hi, just i am curious. There is LTS for *Python*? If so, i am very thank > you for Python Project. Hi Byung-Hee, Does the "LTS" acronym you are using here stands for "Long Term Support" ? If so, then the short answer is: Yes, kind of. There is a 5 years maintenance for each major version of Python 3. You can find information on how Python is released and maintained at PEP 101 [1] and on the developers documentation [2]. Each major Python release typically have a PEP associated with it where past minor releases dates and future plans are recorded. For example: PEP 494 [3] for Python 3.6, PEP 537 [4] for Python 3.7 and PEP 569 [5] for Python 3.8. [1] https://www.python.org/dev/peps/pep-0101/ [2] https://devguide.python.org/devcycle/ [3] https://www.python.org/dev/peps/pep-0494/ [4] https://www.python.org/dev/peps/pep-0537/ [5] https://www.python.org/dev/peps/pep-0569/ From rosuav at gmail.com Mon Aug 24 04:20:56 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 24 Aug 2020 18:20:56 +1000 Subject: Program chaining on Windows In-Reply-To: References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: On Mon, Aug 24, 2020 at 5:30 PM Rob Cliffe wrote: > > On 24/08/2020 00:57, Chris Angelico wrote: > > 2) The same thing but entirely within Python. Instead of importing > > modules, manually load them and exec the source code. (No relation to > > the process-level exec - I'm talking about the exec function.) > > Updating is way WAY faster, but it isn't the same thing as restarting. > > Your code has to be built with this in mind. > Ah, there's the rub. This program will be run stand-alone at client > sites and I need to test it "as is". As I see it I can't responsibly > rewrite the way it works (if I'm understanding you more or less correctly). Yeah, makes sense. If you'd built it from the ground up to handle fast code reloads, the client site wouldn't know or care about that difference, and you wouldn't lose much performance (probably not lose any at all, in fact), but recoding it to that model now would possibly be a big change, so it's not really worth it. Stick to what you have, I think. It's better than trying to exec. ChrisA From rob.cliffe at btinternet.com Mon Aug 24 03:16:10 2020 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 24 Aug 2020 08:16:10 +0100 Subject: Program chaining on Windows In-Reply-To: References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: On 24/08/2020 00:08, Eryk Sun wrote: > > For Windows, we need to spawn, wait, and proxy the exit status. Sorry, I understand very little of this.? Here's where I get stuck: ??? (1) "*spawn*": I see that there are some os.spawn* functions.? I tried this: ??? # File X1.py ??? import os, sys ??? print("This is X1") ??? pid = os.spawnl(os.P_NOWAIT, "C:\\Python38\\python.exe", "C:\\Python38\\X2.py") ??? print(f"X1 got {pid=}") ??? sys.exit() but when I ran it, it displayed ??? This is X1 ??? X1 got pid=... and then apparently started the Python interactive interpreter, although in reality things were in one of the confused states that I described in my first post. (FWIW If I type ??? "C:\\Python38\\python.exe" "C:\\Python38\\X2.py" from the DOS prompt, it works as expected.) ??? (2) "*wait*": Wait for what?? How? ??? (3) "*proxy the exit status*": Sorry, I have no idea what this means. Are you suggesting something I could do in Python that would achieve my aim of *replacing* one program by another (or merely e.g. describing something you could do in C)? If so, is there any chance you could give me some toy code? As you can see, I'm pretty well lost. Thanks again Rob Cliffe From rob.cliffe at btinternet.com Mon Aug 24 03:30:06 2020 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 24 Aug 2020 08:30:06 +0100 Subject: Program chaining on Windows In-Reply-To: References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: On 24/08/2020 00:57, Chris Angelico wrote: > On Mon, Aug 24, 2020 at 9:51 AM Rob Cliffe via Python-list > wrote: >> Let me describe my actual use case. I am developing a large Python >> program (in Windows, working in DOS boxes) and I constantly want to >> modify it and re-run it. What I have been doing is to make it respond >> to a hotkey by calling itself via os.system. The problem is that if I >> do this 50 times I am left with 51 instances still running, each one >> waiting for the next to finish. That's actually OK, except that when I >> finally shut it down, it takes a long time (about 2.5 sec per instance). >> >> I have found a workaround: a small shell program which calls the main >> program (wth os.system), then when the latter exits, calls it again (if >> required). Starting the main program is slightly slower, but acceptably >> so; shutting it down becomes constant time. >> >> But I would still like to be able to do it as I originally planned, if >> possible. Not least because I may have other uses for program >> "chaining" in future. >> > Hmm. Python isn't really set up to make this sort of thing easy. I guess this sentence pretty well answers my whole post. :-( > My > recommendations, in order of priority, would be: > > 1) What you're doing, but with a dedicated exit code that means > "changed, please restart me" That is pretty much what I am now doing.? I return (to a shell program) exit codes which mean "such-and-such a hotkey was hit, please restart me". > > 2) The same thing but entirely within Python. Instead of importing > modules, manually load them and exec the source code. (No relation to > the process-level exec - I'm talking about the exec function.) > Updating is way WAY faster, but it isn't the same thing as restarting. > Your code has to be built with this in mind. Ah, there's the rub.? This program will be run stand-alone at client sites and I need to test it "as is".? As I see it I can't responsibly rewrite the way it works (if I'm understanding you more or less correctly). > > 3) Similar to #2 but using a language that's designed with that kind > of thing in mind. Off topic for this list but it's something I've done > on a number of occasions, so I'd be happy to discuss that with you. No, no, no, Python is for me!? (Seriously: rewriting in another language would be far too time-consuming and *error-prone*.? Not to mention unenjoyable.) > > 4) Any other option available > > 5) Messing with exec on Windows Which I've been doing, but without success. Thanks again, Chris. Rob > > ChrisA From ekopalypse at gmail.com Mon Aug 24 07:52:34 2020 From: ekopalypse at gmail.com (Eko palypse) Date: Mon, 24 Aug 2020 13:52:34 +0200 Subject: Embedded python: How to debug code in an isolated way In-Reply-To: References: Message-ID: Thank you very much for your interest in my little problem. > When the app calls into python does the event loop of the gui block? Yes, the cpp app calls a callback function from the embedded python interpreter synchronously. > When you print does that trigger the event loop to run in a nested call back into the cpp? I can't say for sure but I don't think so. At least my script or the embedded interpreter doesn't do that. > Maybe you need to run python in its own thread and Marshall in and out of the gui main thread with the event loop? I've checked by using GetCurrentThreadId that the registered callback function and debugger run in the same thread but it is different to the UI thread. Do you think I have to run the debugger in its own thread? I'll give it a try anyways. :-) Thx Eren Am So., 23. Aug. 2020 um 22:55 Uhr schrieb Barry : > > > > On 22 Aug 2020, at 20:53, Eko palypse wrote: > > > > ?Hello, > > > > background info first. On windows, python3.8.5 > > > > A cpp app has an embedded python interpreter which allows to > modify/enhance the cpp app > > by providing objects to manipulate the cpp app and callbacks to act on > certain events, > > like fileopen, fileclose, updateui ... which are send by the cpp app. > > The embedded python interpreter acts more or less like the standard > python REPL. > > If you run a script with code like > > > > def test(i): > > print(i*2) > > > > test(4) > > > > then the test function is now globally available as long as the cpp app > is alive. > > > > I've written a debugger based on bdb and encountered a situation which I > haven't found out how to handle correctly yet. > > > > Let's assume I've registered a callback when something changes in the UI. > > In that case an object function gets called which highlights certain > aspects in the UI. > > > > Now if I run a script via this debugger it works as long as I don't use > the same object function. > > If I do use it, then the stack gets corrupted(?). > > When the app calls into python does the event loop of the gui block? > When you print does that trigger the event loop to run in a nested call > back into the cpp? > > Maybe you need to run python in its own thread and Marshall in and out of > the gui main thread with the event loop? > > Barry > > > For example it look like this > > > > stack: > > , > 580 > > ', line 1, code >, 1 > > code >, 8 > > > > now if I enter the function which call this object function this gets add > > > > add_match>, 5 > > > > I step through the code and suddenly the stack looks like this > > > > , > 580 > > ', line 1, code >, 1 > > code >, 8 > > code >, 154 > > code paint_it>, 102)] > > > > EnhanceAnyLexer is neither part of the test_pydebugger script nor part > of the debugger. > > It is used to register a callback on the updateui event. > > > > So the question is, what do I need to read/learn/understand in order to > solve this issue? > > Or in other words, how can I debug my script in an isolated environment. > > I can't manipulate the __main__.dict as this seems to have general > impact on registered callbacks as well. > > Any ideas? > > > > Thank you > > Eren > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > From eryksun at gmail.com Mon Aug 24 08:20:15 2020 From: eryksun at gmail.com (Eryk Sun) Date: Mon, 24 Aug 2020 07:20:15 -0500 Subject: Program chaining on Windows In-Reply-To: References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: On 8/24/20, Rob Cliffe wrote: > > Are you suggesting something I could do in Python that would achieve my > aim of *replacing* one program by another No, it's not possible with the Windows API. Implementing POSIX exec would require extensive use of undocumented NT runtime library functions, system calls, and PEB data in order to reset the address space and handle table and reinitialize the process, and it would probably also require the help of a kernel driver to modify the _EPROCESS record in kernel space. > (1) "*spawn*": I see that there are some os.spawn* functions. The POSIX way to create a new process is fork (clone), which is optionally followed by exec (image overlay). Cloning the current process is fast and efficient. The Windows way to create a new process is spawn, as implemented by WinAPI CreateProcessW, which is relatively slow and laborious. In Python, the preferred way to call the latter is with subprocess.Popen, or helper functions such as subprocess.run. Spawing a Windows process is a lot of work. It involves creating a new process object (a large _EPROCESS record in the kernel) and address space (a VAD tree and page tables); allocating and initializing a process environment block (PEB; a large block of memory that includes process flags, parameters, environment variables, loader data, activation contexts, and much more); optionally inheriting handles for kernel objects from the parent process; mapping an executable file as the process image; and creating an initial thread that starts at the OS entrypoint function (a queued APC that calls LdrInitializeThunk, which resumes at RtlUserThreadStart). The latter initializes the process; registers with the session server csrss.exe via its LPC port; loads and initializes dependent DLLs, which may require multiple activation contexts and LPC message transactions with the SxS fusion loader in the session server; possibly (if it's a console app) connects to or spawns the console-session host conhost.exe; and calls the image entrypoint such as __wmainCRTStartup. The latter initializes the C runtime before calling the application's entrypoint (e.g. wmain). For Python, the latter calls Py_Main, which initializes the interpreter before compiling and executing the main script. > (2) "*wait*": Wait for what? How? Functions such as os.system and subprocess.run wait on (i.e. synchronize on) the process via WinAPI WaitForSingleObject[Ex], which waits for the process to terminate. If the child process uses console I/O and inherits the parent's console, then it's important for the parent to wait before resuming its own interactive console UI. Otherwise both parent and child will compete for the console. > (3) "*proxy the exit status*": Sorry, I have no idea what this means. Generally the parent process needs to know whether the child process succeeded or failed. Typically the exit status (aka exit code) for success is 0, and all other values indicate failure. Commonly an exit status of 1 is used for failure. In Windows, the exit status for a process is returned by GetExitCodeProcess. By "proxy the exit status", I mean that a program that spawns and waits for another program will usually return the exit status from the spawned child as its own exit status. Consider the following snippet from the source code for the py.exe launcher, which spawns python.exe for the selected version of Python: ok = CreateProcessW(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); if (!ok) error(RC_CREATE_PROCESS, L"Unable to create process using '%ls'", cmdline); AssignProcessToJobObject(job, pi.hProcess); CloseHandle(pi.hThread); WaitForSingleObjectEx(pi.hProcess, INFINITE, FALSE); ok = GetExitCodeProcess(pi.hProcess, &rc); if (!ok) error(RC_CREATE_PROCESS, L"Failed to get exit code of process"); debug(L"child process exit code: %d\n", rc); exit(rc); This C code includes the steps that I discussed: CreateProcessW, WaitForSingleObjectEx, GetExitCodeProcess, and finally exit(rc), where rc is the exit status from the spawned python.exe process. The launcher also creates a kill-on-close, silent-breakaway job object and assigns the child process to it. That way if the launcher is terminated or crashes, the python.exe process will also be terminated, so there's a tight coupling between py.exe and python.exe. The silent-breakaway setting means processes spawned by python.exe are not assigned to the job. You can work with job objects via ctypes or PyWin32's win32job module. I can provide example code for either approach. > from the DOS prompt, it works as expected. You're not running DOS. Most likely the shell you're running is CMD or PowerShell, attached to a console session that's hosted by either conhost.exe (default) or openconsole.exe (an open-source build of conhost.exe that's used by the new Windows Terminal). These are Windows applications. From vinay_sajip at yahoo.co.uk Mon Aug 24 09:52:37 2020 From: vinay_sajip at yahoo.co.uk (Vinay Sajip) Date: Mon, 24 Aug 2020 13:52:37 +0000 (UTC) Subject: ANN: Version 0.1.6 of sarge (a subprocess wrapper library) has been released. References: <490557445.7945964.1598277157066.ref@mail.yahoo.com> Message-ID: <490557445.7945964.1598277157066@mail.yahoo.com> Version 0.1.6 of Sarge, a cross-platform library which wraps the subprocess module in the standard library, has been released. What changed? ------------- - Fixed #44: Added an optional timeout to Command.wait() and Pipeline.wait(), which ? only takes effect on Python >= 3.3. - Fixed #47: Added the ``replace_env`` keyword argument which allows a complete ? replacement for ``os.environ`` to be passed. - Fixed #51: Improved error handling around a Popen call. What does Sarge do? ------------------- Sarge tries to make interfacing with external programs from your Python applications easier than just using subprocess alone. Sarge offers the following features: * A simple way to run command lines which allows a rich subset of Bash- style shell command syntax, but parsed and run by sarge so that you can run on Windows without cygwin (subject to having those commands available): >>> from sarge import capture_stdout >>> p = capture_stdout('echo foo | cat; echo bar') >>> for line in p.stdout: print(repr(line)) ... 'foo\n' 'bar\n' * The ability to format shell commands with placeholders, such that variables are quoted to prevent shell injection attacks. * The ability to capture output streams without requiring you to program your own threads. You just use a Capture object and then you can read from it as and when you want. * The ability to look for patterns in captured output and to interact accordingly with the child process. Advantages over subprocess --------------------------- Sarge offers the following benefits compared to using subprocess: * The API is very simple. * It's easier to use command pipelines - using subprocess out of the box often leads to deadlocks because pipe buffers get filled up. * It would be nice to use Bash-style pipe syntax on Windows, but Windows shells don't support some of the syntax which is useful, like &&, ||, |& and so on. Sarge gives you that functionality on Windows, without cygwin. * Sometimes, subprocess.Popen.communicate() is not flexible enough for one's needs - for example, when one needs to process output a line at a time without buffering the entire output in memory. * It's desirable to avoid shell injection problems by having the ability to quote command arguments safely. * subprocess allows you to let stderr be the same as stdout, but not the other way around - and sometimes, you need to do that. Python version and platform compatibility ----------------------------------------- Sarge is intended to be used on any Python version >= 2.6 and is tested on Python versions 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, 3.7 and 3.8 on Linux, Windows, and Mac OS X (not all versions are tested on all platforms, but sarge is expected to work correctly on all these versions on all these platforms). Finding out more ---------------- You can read the documentation at http://sarge.readthedocs.org/ There's a lot more information, with examples, than I can put into this post. You can install Sarge using "pip install sarge" to try it out. The project is hosted on BitBucket at https://bitbucket.org/vinay.sajip/sarge/ And you can leave feedback on the issue tracker there. I hope you find Sarge useful! Regards, Vinay Sajip From torriem at gmail.com Mon Aug 24 14:37:19 2020 From: torriem at gmail.com (Michael Torrie) Date: Mon, 24 Aug 2020 12:37:19 -0600 Subject: Program chaining on Windows In-Reply-To: References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: <9b6d076c-d59c-d093-3857-c521c667f9c4@gmail.com> On 8/24/20 1:30 AM, Rob Cliffe via Python-list wrote: >> Hmm. Python isn't really set up to make this sort of thing easy. > I guess this sentence pretty well answers my whole post. :-( After reading Eryk Sun's posts, it doesn't appear that Python is the issue here, but rather Windows does not make it possible to do what you want to do. But his suggestions for emulating the behavior you seek are good ones. From tjreedy at udel.edu Mon Aug 24 14:32:07 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 24 Aug 2020 14:32:07 -0400 Subject: Issue in installing Python (Windows 10) In-Reply-To: References: Message-ID: On 8/23/2020 12:39 PM, Debasis Chatterjee wrote: > I started off by using "python-3.8.5.exe". 32-bit Windows installer? Windows version might be relevant. > I use "Run as Administrator" option to click this (provide my local-admin > username/pwd). > After this, I see python shell available. But no IDLE. Not sure why? You mean no IDLE entry on Python 3.8 directory on Start menu? Installer has a checkbox for tkinter and IDLE. It is on by default for a fresh install but I expect it defaults to previous install for reinstalls. On a command line, run 'python -c "import tkinter' to see if you have tkinter. 'python -m idlelib' starts IDLE if present. > From CMD, I can check "pip list". Surprisingly, it shows me packages that I > installed earlier, before deinstalling and reinstalling. De-installing does not remove pythonxy directory if you add anything to it. > Something is not right. Hence I am trying to make a fresh restart. > > One thing odd is that even after removing installed program (Python) from > control panel, I still find that from "Start". Have you installed more than one version of Python? Or both 32 and 64 bit variation of same Python version? -- Terry Jan Reedy From tjreedy at udel.edu Mon Aug 24 14:54:48 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 24 Aug 2020 14:54:48 -0400 Subject: Program chaining on Windows In-Reply-To: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> Message-ID: On 8/23/2020 3:31 AM, Rob Cliffe via Python-list wrote: > On WIndows 10, running Python programs in a DOS box, Please don't use 'DOS box' for Windows Command Prompt or other Windows consoles for running Windows programs from a command line. DOSBox is program for running (old) DOS programs written for the IBM PC. One use is running old games, such as some distributed by GOG. Note that interactive command line interpreters existed long before MS/PC DOS. > I would like one > Python program to chain to another.? I.e. the first program to be > replaced by the second (*not* waiting for the second to finish, as with > e.g. os.system). For reasons explained especially well by Eryk Sun, you should probably use one python program as a master program to run others in succession. -- Terry Jan Reedy From samuelmarks at gmail.com Mon Aug 24 04:24:23 2020 From: samuelmarks at gmail.com (Samuel Marks) Date: Mon, 24 Aug 2020 18:24:23 +1000 Subject: ABC with abstractmethod: kwargs on Base, explicit names on implementation Message-ID: After a discussion on #python on Freenode, I'm here. The gist of it is: > Falc - Signature of method 'Pharm.foo()' does not match signature of base method in class 'Base' What's the right way of specialising the children and leaving the Base pretty much empty? Specifically I want: ? All implementers to be forced to implement Base's method ? Base to be able to do very basic things with kwargs, namely log it (to a file like stdout or a db) ? Support for [at least] Python 3.6?3.9 (I don't think `Protocol` has been backported?) ? Implementors to have access to the proper name, rather than having to unpack kwargs Should I be using a Base class? - Metaclass? - Something else entirely? - I know giving `b` a default value would resolve the [PyCharm] linter error? but I want it to be a required argument. Full example: from abc import ABC, abstractmethod class Base(ABC): @abstractmethod def foo(self, a, **kwargs): """ :param a: var :type a: ```int``` :param **kwargs: keyword args :type **kwargs: ``dict`` """ print(a) class Pharm(Base): def foo(self, a, b): """ :param a: var :type a: ```int``` :param b: var :type b: ```int``` """ super(Pharm, self).foo(a=a) Thanks, Samuel Marks Charity | consultancy | open-source | LinkedIn From pynoob76 at gmail.com Mon Aug 24 09:12:11 2020 From: pynoob76 at gmail.com (Py Noob) Date: Mon, 24 Aug 2020 06:12:11 -0700 Subject: Output showing "None" in Terminal Message-ID: Hi! i'm new to python and would like some help with something i was working on from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below is my code and the terminal is showing the word "None" everytime I execute my code. Many thanks! print("Conversion") def km_mi(): return answer selection = input("Type mi for miles or km for kilometers: ") if selection == "mi": n = int(input(print("Please enter distance in miles: "))) answer = (1.6*n) print("%.2f" % answer, "miles") else: n = float(input(print("Please enter distance in kilometers: "))) answer = (n/1.6) print("%.2f" % answer, "kilometers") answer = km_mi From Joseph.Schachner at Teledyne.com Mon Aug 24 16:27:28 2020 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Mon, 24 Aug 2020 20:27:28 +0000 Subject: Embedded python: How to debug code in an isolated way In-Reply-To: References: Message-ID: Another suggestion: If your Python code only references few things outside of itself, make a simulated environment in Python on your PC, so that you can run your embedded code after importing your simulated environment, which should supply the functions it expects to call and variables it expects to access. Then you can use any PC based debugger (PyScripter, Jetbrains' PyCharm, Visual Studio with Python support, etc) to debug in the simulated environment. --- Joseph S. -----Original Message----- From: Grant Edwards Sent: Sunday, August 23, 2020 12:59 PM To: python-list at python.org Subject: Re: Embedded python: How to debug code in an isolated way On 2020-08-22, Chris Angelico wrote: > On Sun, Aug 23, 2020 at 5:51 AM Eko palypse wrote: >> So the question is, what do I need to read/learn/understand in order to solve this issue? >> Or in other words, how can I debug my script in an isolated environment. > > I'd go for the old standby - IIDPIO: If In Doubt, Print It Out! > Instead of trying to use a debug harness, just run your code normally, > and print out whatever you think might be of interest. If you don't > have a console, well, that would be the first thing to do - you > *always* need a console. Yep. Even if you have to bit-bang a tx-only UART on a GPIO pin. I've had to do that many times, and the last time was only a couple years ago. Though I must admit I never had to do that _in_ Python or on a platform capable of running Python... -- Grant From rosuav at gmail.com Mon Aug 24 16:32:30 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 25 Aug 2020 06:32:30 +1000 Subject: Embedded python: How to debug code in an isolated way In-Reply-To: References: Message-ID: On Tue, Aug 25, 2020 at 6:30 AM Schachner, Joseph wrote: > > Another suggestion: If your Python code only references few things outside of itself, make a simulated environment in Python on your PC, so that you can run your embedded code after importing your simulated environment, which should supply the functions it expects to call and variables it expects to access. > > Then you can use any PC based debugger (PyScripter, Jetbrains' PyCharm, Visual Studio with Python support, etc) to debug in the simulated environment. > That seldom works very well. since most of the point of running code on embedded devices is to use the features of those devices. My brother built a network-attached doorbell on an RPi, and all the debugging work revolved around the exact electrical signals on the GPIO pins. ChrisA From cspealma at redhat.com Mon Aug 24 16:41:34 2020 From: cspealma at redhat.com (Calvin Spealman) Date: Mon, 24 Aug 2020 16:41:34 -0400 Subject: Output showing "None" in Terminal In-Reply-To: References: Message-ID: How are you actually running your code? "None" is the default return value of all functions in Python. But, the interpreter is supposed to suppress it as a displayed result. As a side note, both your km_mi() function and the line "answer = km_mi" are certainly wrong, but it is not clear what you intend to do. On Mon, Aug 24, 2020 at 4:25 PM Py Noob wrote: > Hi! > > i'm new to python and would like some help with something i was working on > from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below is > my code and the terminal is showing the word "None" everytime I execute my > code. > > Many thanks! > > print("Conversion") > > def km_mi(): > return answer > > selection = input("Type mi for miles or km for kilometers: ") > > if selection == "mi": > n = int(input(print("Please enter distance in miles: "))) > answer = (1.6*n) > print("%.2f" % answer, "miles") > > else: > n = float(input(print("Please enter distance in kilometers: "))) > answer = (n/1.6) > print("%.2f" % answer, "kilometers") > > answer = km_mi > -- > https://mail.python.org/mailman/listinfo/python-list > > -- CALVIN SPEALMAN SENIOR QUALITY ENGINEER cspealma at redhat.com M: +1.336.210.5107 [image: https://red.ht/sig] TRIED. TESTED. TRUSTED. From random832 at fastmail.com Mon Aug 24 16:50:09 2020 From: random832 at fastmail.com (Random832) Date: Mon, 24 Aug 2020 16:50:09 -0400 Subject: Output showing "None" in Terminal In-Reply-To: References: Message-ID: <373d304b-e4aa-40a0-9f2e-1ee96929e6e1@www.fastmail.com> On Mon, Aug 24, 2020, at 09:12, Py Noob wrote: > Hi! > > i'm new to python and would like some help with something i was working on > from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below is > my code and the terminal is showing the word "None" everytime I execute my > code. The reason it is displaying None is because print() returns none, and you are sending that into input(). Either do: print("Please enter distance in miles: ") n = int(input()) # this will wait for input on the next line or n = int(input("Please enter distance in miles: ")) # this will wait for input on the same line as the text The km_mi function doesn't seem to have any purpose and you can delete it and the other line further down referencing it. If this is for something like a school assignment that requires you to write a km_mi function, it's not clear from your code what the requirement is for this function. From rob.cliffe at btinternet.com Mon Aug 24 12:27:06 2020 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 24 Aug 2020 17:27:06 +0100 Subject: Program chaining on Windows In-Reply-To: References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> <58354519-aad0-ae71-5d25-25cb2f5af25c@DancesWithMice.info> Message-ID: <101a79bb-91ef-c1f0-8339-ab7fe4fd0e70@btinternet.com> On 24/08/2020 13:20, Eryk Sun wrote: > > You can work with job objects via ctypes or PyWin32's win32job module. > I can provide example code for either approach. No need, I'm already convinced that this is not the way for me to go. > >> from the DOS prompt, it works as expected. > You're not running DOS. Most likely the shell you're running is CMD or > PowerShell, attached to a console session that's hosted by either > conhost.exe (default) or openconsole.exe (an open-source build of > conhost.exe that's used by the new Windows Terminal). These are > Windows applications. I'm running CMD.exe.? Sorry, I didn't realise I was using sloppy language. Thanks for your very detailed repy, Eryk. Best wishes Rob Cliffe From 2QdxY4RzWzUUiLuE at potatochowder.com Mon Aug 24 16:53:02 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Mon, 24 Aug 2020 15:53:02 -0500 Subject: Output showing "None" in Terminal In-Reply-To: References: Message-ID: <20200824205302.GD3788@scrozzle> On 2020-08-24 at 06:12:11 -0700, Py Noob wrote: > i'm new to python and would like some help with something i was working on > from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below is > my code and the terminal is showing the word "None" everytime I execute my > code. > if selection == "mi": > n = int(input(print("Please enter distance in miles: "))) You've got a couple of lines like that: input(print(...)). The print function prints the string and None, and then the input function prints the None. > answer = km_mi As Calvin pointed out, this is likely not what you want, either. -- ?Whoever undertakes to set himself up as a judge of Truth and Knowledge is shipwrecked by the laughter of the gods.? ? Albert Einstein Dan Sommers, http://www.tombstonezero.net/dan From rob.cliffe at btinternet.com Mon Aug 24 17:11:23 2020 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 24 Aug 2020 22:11:23 +0100 Subject: Program chaining on Windows In-Reply-To: References: <3d5f699c-f9b0-f260-1881-dec8144dc326@btinternet.com> Message-ID: <9a56a384-696a-bcd8-c92d-d1efa6e8402d@btinternet.com> On 24/08/2020 19:54, Terry Reedy wrote: > On 8/23/2020 3:31 AM, Rob Cliffe via Python-list wrote: >> On WIndows 10, running Python programs in a DOS box, > > Please don't use 'DOS box' for Windows Command Prompt or other Windows > consoles for running Windows programs from a command line.? DOSBox is > program for running (old) DOS programs written for the IBM PC.? One > use is running old games, such as some distributed by GOG.? Note that > interactive command line interpreters existed long before MS/PC DOS. Sorry, I was unintentionally using misleading terminology.? I was running programs in a cmd.exe window. > >> I would like one Python program to chain to another.? I.e. the first >> program to be replaced by the second (*not* waiting for the second to >> finish, as with e.g. os.system). > > For reasons explained especially well by Eryk Sun, you should probably > use one python program as a master program to run others in succession. Yes, thats's what I'm doing now. Thanks Rob Cliffe From soyeomul at doraji.xyz Mon Aug 24 20:54:08 2020 From: soyeomul at doraji.xyz (=?utf-8?B?7Zmp67OR7Z2s?=) Date: Tue, 25 Aug 2020 09:54:08 +0900 Subject: There is LTS? References: <850a0414-6810-830b-a6f8-5df3904ffc32@superlel.me> Message-ID: L?o El Amri writes: > On 24/08/2020 04:54, ??? wrote: >> Hi, just i am curious. There is LTS for *Python*? If so, i am very thank >> you for Python Project. > > Hi Byung-Hee, > > Does the "LTS" acronym you are using here stands for "Long Term Support" ? > > If so, then the short answer is: Yes, kind of. There is a 5 years > maintenance for each major version of Python 3. > > You can find information on how Python is released and maintained at PEP > 101 [1] and on the developers documentation [2]. > > Each major Python release typically have a PEP associated with it where > past minor releases dates and future plans are recorded. > For example: PEP 494 [3] for Python 3.6, PEP 537 [4] for Python 3.7 and > PEP 569 [5] for Python 3.8. > > [1] https://www.python.org/dev/peps/pep-0101/ > [2] https://devguide.python.org/devcycle/ > [3] https://www.python.org/dev/peps/pep-0494/ > [4] https://www.python.org/dev/peps/pep-0537/ > [5] https://www.python.org/dev/peps/pep-0569/ Wow L?o you nice guy!!! Thank You!!! Sincerely, Byung-Hee -- ^????? _????_ ?????_^))// From PythonList at DancesWithMice.info Mon Aug 24 21:17:39 2020 From: PythonList at DancesWithMice.info (dn) Date: Tue, 25 Aug 2020 13:17:39 +1200 Subject: Training Review: Computational Thinking for Problem Solving Message-ID: Many of us learn Python by memorising code-constructs and their use. Even over-coming this learning-curve is but a small portion of becoming a competent coder or programmer. The challenges of learning how to construct an algorithm, and/or how to analyse a real-world problem to produce a solution, are not to be found in the Python Tutorial. However, such higher-order problems often surface on the Python-Tutor and Python Discussion Lists. For newcomers (and anyone in the field who would like to fill-in topics 'missing' in his/her basic understanding), Coursera offer a "Computational Thinking for Problem Solving" course (free* or $certified) from "Penn" (University of Pennsylvania, USA). I have occupied various 'spare' moments during the last week or so, to review the course, and am recommend it to you/yours. Aside from coders, you might also mention it to any friends who want to learn 'problem-solving' (an increasingly important skill in these modern-times where the only constant is 'change') because this is not a 'computer course'. Starting at higher-level thinking, gradually more detail is added, before arriving at the level of implementing computer-based solutions in Python. It offers a (rather brief) introduction to Python. Thus could be used as a 'taster', before moving to Python-for-the-sake-of-Python course. Throughout the course reference is made to case-studies drawn from the university's wider operations. There is also an interesting topic in linguistic analysis (ie the stuff of grammar-checkers, search engines, etc) which trainees can gradually develop, stage-by-stage. Here is their introduction:- <<< Computational thinking is the process of approaching a problem in a systematic manner and creating and expressing a solution such that it can be carried out by a computer. But you don't need to be a computer scientist to think like a computer scientist! In fact, we encourage students from any field of study to take this course. Many quantitative and data-centric problems can be solved using computational thinking and an understanding of computational thinking will give you a foundation for solving problems that have real-world, social impact. In this course, you will learn about the pillars of computational thinking, how computer scientists develop and analyze algorithms, and how solutions can be realized on a computer using the Python programming language. By the end of the course, you will be able to develop an algorithm and express it to the computer by writing a simple Python program. This course will introduce you to people from diverse professions who use computational thinking to solve problems. You will engage with a unique community of analytical thinkers and be encouraged to consider how you can make a positive social impact through computational thinking. >>> 100% online Flexible deadlines Beginner Level Approx. 17 hours to complete Four 'weeks' or sessions: Pillars of Computational Thinking Expressing and Analyzing Algorithms Fundamental Operations of a Modern Computer Applied Computational Thinking Using Python https://www.coursera.org/learn/computational-thinking-problem-solving#syllabus They did conclude by uttering heresy: that graduates might like to move to "more advanced languages like Java ... JavaScript", but let's not hold that lapse of judgement against them (they are after-all, a school of Engineering)! * the $free option allows access to quizzes, tests, and assignments but not to any grading process. That said, any 'problems', phrased with at a Python background, could likely be discussed/corrected in posts to the Python-Tutor List (don't forget to declare the course and notify which session/component). Disclaimer: I use the ('competing') edX training/education platform - but for non-Python courses. -- Regards, =dn From pynoob76 at gmail.com Tue Aug 25 00:16:18 2020 From: pynoob76 at gmail.com (Py Noob) Date: Mon, 24 Aug 2020 21:16:18 -0700 Subject: Output showing "None" in Terminal In-Reply-To: References: Message-ID: Thank you for the clarification. What I'm trying to achieve here are: User be able to choose miles or kilometers to convert. When selected (mi/km), prints out the user input and the answer. km to mi = km/1.609 mi to km = mi*1.609 Thank you again! On Mon, Aug 24, 2020 at 1:41 PM Calvin Spealman wrote: > How are you actually running your code? > > "None" is the default return value of all functions in Python. But, the > interpreter is supposed to suppress it as a displayed result. > > As a side note, both your km_mi() function and the line "answer = km_mi" > are certainly wrong, but it is not clear what you intend to do. > > On Mon, Aug 24, 2020 at 4:25 PM Py Noob wrote: > >> Hi! >> >> i'm new to python and would like some help with something i was working on >> from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below >> is >> my code and the terminal is showing the word "None" everytime I execute my >> code. >> >> Many thanks! >> >> print("Conversion") >> >> def km_mi(): >> return answer >> >> selection = input("Type mi for miles or km for kilometers: ") >> >> if selection == "mi": >> n = int(input(print("Please enter distance in miles: "))) >> answer = (1.6*n) >> print("%.2f" % answer, "miles") >> >> else: >> n = float(input(print("Please enter distance in kilometers: "))) >> answer = (n/1.6) >> print("%.2f" % answer, "kilometers") >> >> answer = km_mi >> -- >> https://mail.python.org/mailman/listinfo/python-list >> >> > > -- > > CALVIN SPEALMAN > > SENIOR QUALITY ENGINEER > > cspealma at redhat.com M: +1.336.210.5107 > [image: https://red.ht/sig] > TRIED. TESTED. TRUSTED. > From PythonList at DancesWithMice.info Tue Aug 25 05:11:06 2020 From: PythonList at DancesWithMice.info (dn) Date: Tue, 25 Aug 2020 21:11:06 +1200 Subject: Output showing "None" in Terminal In-Reply-To: References: Message-ID: <7f0b3328-f88f-801c-c8d0-fde4291e3aa5@DancesWithMice.info> On 25/08/2020 01:12, Py Noob wrote: > Hi! > > i'm new to python and would like some help with something i was working on > from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below is > my code and the terminal is showing the word "None" everytime I execute my > code. > > Many thanks! > > print("Conversion") > > def km_mi(): > return answer > > selection = input("Type mi for miles or km for kilometers: ") > > if selection == "mi": > n = int(input(print("Please enter distance in miles: "))) > answer = (1.6*n) > print("%.2f" % answer, "miles") > > else: > n = float(input(print("Please enter distance in kilometers: "))) > answer = (n/1.6) > print("%.2f" % answer, "kilometers") > > answer = km_mi Without claiming to speak for @Calvin, I think the original question was reasonably clear (albeit incomplete), but the code-answer doesn't seem to fit together and thus invites the question about 'intention'. Here's a question or two: is this a course-assignment? If so, which course and is the full question and course-content leading to this point available on-line? A bunch of people here could write the code. However, that won't help you learn Python! Let's look at the code and the email text: - does the term "None" mean that even the "Conversion" heading/intro does not appear? - what is the purpose of the function? - if the two branches of the if statement each print a result, what is the purpose of the last line? - is the specification that the program computes (exactly) one result, or is it expected to repeat an input-calculate-output cycle? - by "terminal" are you referring to the one built-in to VS-Code, or something else? Please be advised that everyone here is volunteering his/her assistance, so the more you help us, the better we can help you! Also, are you aware that there is a Python-Tutor list specifically for Python trainers and trainees? -- Regards =dn From dieter at handshake.de Tue Aug 25 13:21:54 2020 From: dieter at handshake.de (Dieter Maurer) Date: Tue, 25 Aug 2020 19:21:54 +0200 Subject: ABC with abstractmethod: kwargs on Base, explicit names on implementation In-Reply-To: References: Message-ID: <24389.18610.262010.115997@ixdm.fritz.box> Samuel Marks wrote at 2020-8-24 18:24 +1000: >After a discussion on #python on Freenode, I'm here. > >The gist of it is: >> Falc - Signature of method 'Pharm.foo()' does not match signature of base method in class 'Base' > >What's the right way of specialising the children and leaving the Base >pretty much empty? > >Specifically I want: >? All implementers to be forced to implement Base's method >? Base to be able to do very basic things with kwargs, namely log it >(to a file like stdout or a db) >? Support for [at least] Python 3.6?3.9 (I don't think `Protocol` has >been backported?) >? Implementors to have access to the proper name, rather than having >to unpack kwargs > >Should I be using a Base class? - Metaclass? - Something else >entirely? - I know giving `b` a default value would resolve the >[PyCharm] linter error? but I want it to be a required argument. > >Full example: > >from abc import ABC, abstractmethod > > >class Base(ABC): > @abstractmethod > def foo(self, a, **kwargs): > ... >class Pharm(Base): > def foo(self, a, b): > ... Python make a distinction between positional and keyword arguments. A positional argument is identified by its position in the parameter list; a keyword argument is identified by its name. `**` introduces arbitrary keyword arguments. In a call, all those arguments must be passed as "name=value". In your case above, `b` is not a keyword argument and thus is not matched by `**kwargs`. The error you observe is justified. You can try: class Base(ABC): @abstractmethod def foo(self, a, *args, **kwargs): ... class Pharm(Base): def foo(self, a, b, *args, **kwargs): ... Note that the base method signature allows arbitrary positional and keyword arguments. As a consequence, derived methods must do the same. If this is not what you want, you might want to explore the use of a decorator or a meta class rather than a base class. From hjp-python at hjp.at Tue Aug 25 13:53:46 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 25 Aug 2020 19:53:46 +0200 Subject: Whitespace not/required In-Reply-To: References: Message-ID: <20200825175346.GA9582@hjp.at> On 2020-08-14 16:29:18 +1200, dn via Python-list wrote: > For f-strings/formatted string literals, the most usual form is: > > "{" f_expression ["="] ["!" conversion] [":" format_spec] "}" > > Remembering that this is BNF, see the space separating the closing-brace > from anything preceding it No. I see a space before the quote before the closing brace. > - how else would we separate the components to > comprehend? > > Returning to Python: > > >>> one = 1 # is the loneliest number... > >>> f'{ one }' > '1' > >>> f'{ one:03 }' > Traceback (most recent call last): > File "", line 1, in > ValueError: Unknown format code '\x20' for object of type 'int' > >>> f'{ one:03}' > '001' > > Notice the presence/absence of the final space. > > >>> pi = 3.14159 # better to import math > >>> f'{ pi!r:10 }' > Traceback (most recent call last): > File "", line 1, in > ValueError: Unknown format code '\x20' for object of type 'str' > >>> f'{ pi!r:10}' > '3.14159 ' > >>> f'{ pi!r }' > File "", line 1 > SyntaxError: f-string: expecting '}' > >>> f'{ pi!r}' > '3.14159' > > So, the f-string will work if the braces include only an expression > surrounded by spaces. However, if one adds a conversion or > format-specification, that final space becomes a no-no. Eh what! That doesn't surprise me. The "!" and ":" split the replacement field into three parts. The f_expression is just a subset of normal python expressions, which allow whitespace, so f"{pi+1}" f"{pi + 1}" f"{ pi + 1 }" f"{ pi + 1 !r}" f"{ pi + 1 :f}" are all valid. The conversion consists only of a single character ("a", "r", or "s"), anything else is invalid. The format_spec is everything between the colon and the closing brace. Syntactically, that can contain spaces. However, that is passed to the object's __format__() method, and for builtin objects that method doesn't know what to do with a space (you could implement it for your own objects, though). > To be fair, the 'book of words' does say: "A replacement field ends with a > closing curly bracket '}'.". No mention of whitespace. No mention that a > replacement field consisting only of an f_expression, will be treated > differently by allowing a space. > > Version 3.8 introduced the "=" short-cut: > > >>> f"{ foo = }" # preserves whitespace > " foo = 'bar'" > > Note the comment! Yet, the manual's examples continue: > > >>> line = "The mill's closed" > >>> f"{line = }" > 'line = "The mill\'s closed"' > >>> f"{line = :20}" > "line = The mill's closed " > > Hey, why does this second example dispense with the braces-internal spaces? It doesn't. The space is still there - before the colon. > Should the closing brace be considered part of a conversion or > format-specification? No. > The space (I'd like to add) cannot be considered part of a conversion > or format-specification (see BNF, see text of web.ref)! But it is part of the format specification: format_spec ::= (literal_char | NULL | replacement_field)* literal_char ::= Note: *any* code point except "{", "}" or NULL. So that includes space. (BTW, what is NULL? U+0000 doesn't make much sense here (and is usually written NUL (with one L) and an empty string is not a code point.) 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 Joseph.Schachner at Teledyne.com Tue Aug 25 19:31:24 2020 From: Joseph.Schachner at Teledyne.com (Schachner, Joseph) Date: Tue, 25 Aug 2020 23:31:24 +0000 Subject: Output showing "None" in Terminal In-Reply-To: References: Message-ID: The very first line of your function km_mi(): ends it: def km_mi(): return answer answer has not been assigned, so it returns None. Advice: remove that "return" line from there. Also get rid of the last line, answer = km_mi which makes answer refer to the function km_mi(). Put the "return answer" line at the end, where the "answer=km_mi" used to be. That should help. The code calculates "answer". It prints "answer". You should return "answer" at the end, after it has been calculated. --- Joseph S. -----Original Message----- From: Py Noob Sent: Monday, August 24, 2020 9:12 AM To: python-list at python.org Subject: Output showing "None" in Terminal Hi! i'm new to python and would like some help with something i was working on from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below is my code and the terminal is showing the word "None" everytime I execute my code. Many thanks! print("Conversion") def km_mi(): return answer selection = input("Type mi for miles or km for kilometers: ") if selection == "mi": n = int(input(print("Please enter distance in miles: "))) answer = (1.6*n) print("%.2f" % answer, "miles") else: n = float(input(print("Please enter distance in kilometers: "))) answer = (n/1.6) print("%.2f" % answer, "kilometers") answer = km_mi From barry at barrys-emacs.org Wed Aug 26 03:21:10 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 26 Aug 2020 08:21:10 +0100 Subject: Embedded python: How to debug code in an isolated way In-Reply-To: References: Message-ID: <7A92BCAA-8A37-4538-94A5-F4D70BD1C60A@barrys-emacs.org> > On 24 Aug 2020, at 12:52, Eko palypse wrote: > > Thank you very much for your interest in my little problem. > >> When the app calls into python does the event loop of the gui block? > > Yes, the cpp app calls a callback function from the embedded python > interpreter synchronously. > >> When you print does that trigger the event loop to run in a nested call > back into the cpp? > > I can't say for sure but I don't think so. At least my script or the > embedded interpreter doesn't do that. > > >> Maybe you need to run python in its own thread and Marshall in and out > of the gui main thread with the event loop? > > I've checked by using GetCurrentThreadId > > that the registered callback function and debugger run in the same thread > but it is different to the UI thread. > Do you think I have to run the debugger in its own thread? I'll give it a > try anyways. :-) No I doubt that can will work. What I was thinking is that your life was made more complex by multi threads and GUI event loops. I think that you should not attempt to use a debugger at all. Add code to put the information you need to find the bug into a log file. You might want to build a feature into the GUI that will show the log file to you if it not easy to get at a log file on disk. As an aside I have never used a python debugger to fix python code. I have always relied on logging key information to allow me to fix bugs. I have used gdb to debug C/C++ and python. All the non-trivial projects I work on have multi stream logging builtin. I tend to design the logging with the aim of debugging and maintaining code from the outset these days. When a new bug turns up I just switch on the appropriate stream of logs to help me fix it, add new logs as necessary. Barry From __peter__ at web.de Wed Aug 26 03:32:31 2020 From: __peter__ at web.de (Peter Otten) Date: Wed, 26 Aug 2020 09:32:31 +0200 Subject: "filterwarnings" References: Message-ID: Stefan Ram wrote: > I'm not sure I understand "filterwarnings" correctly. > It does not suppress the warning within the "with" statement below. > Outside of the "with" statement, it does work, but according > to sources it also should work within the "with" statement. > > Console transcript: > > |Python 3.9.... > |Type "help", "copyright", "credits" or "license" for more information. > |>>> import warnings > |>>> with warnings.catch_warnings(): > |... warnings.filterwarnings("ignore", category=SyntaxWarning) > |... print( 1 is 1 ) > |... > |:3: SyntaxWarning: "is" with a literal. Did you mean "=="? > |True > |>>> warnings.filterwarnings("ignore", category=SyntaxWarning) > |>>> print( 1 is 1 ) > |True > > How could I make "filterwarnings" work inside the "with" statement? > TIA! It does work already: >>> with warnings.catch_warnings(): ... warnings.filterwarnings("ignore", category=UserWarning) ... warnings.warn("yadda") ... >>> warnings.warn("yadda") :1: UserWarning: yadda The problem is that you picked the wrong category. As SyntaxWarnings are issued during compilation you need to trigger a compilation to see the effect: >>> with warnings.catch_warnings(): ... warnings.filterwarnings("ignore", category=SyntaxWarning) ... exec("1 is 1") ... >>> exec("1 is 1") :1: SyntaxWarning: "is" with a literal. Did you mean "=="? From tjreedy at udel.edu Tue Aug 25 21:06:51 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 25 Aug 2020 21:06:51 -0400 Subject: Output showing "None" in Terminal In-Reply-To: References: Message-ID: On 8/24/2020 4:41 PM, Calvin Spealman wrote: > "None" is the default return value of all functions in Python. But, the > interpreter is supposed to suppress it as a displayed result. In batch mode, expressions are not echoed. In interactive move, expression values other than None are echoed. The string 'None' is not suppressed. Type "help", "copyright", "credits" or "license()" for more information. >>> None # Not echoed. >>> str(None) # Not echoed in batch mode. 'None' >>> repr(None) # Ditto. 'None' >>> print(None) # Always printed to valid sys.stdout. None -- Terry Jan Reedy From andyfaff at gmail.com Tue Aug 25 20:20:02 2020 From: andyfaff at gmail.com (Andrew Nelson) Date: Wed, 26 Aug 2020 10:20:02 +1000 Subject: stat_result.st_ino from os.stat isn't constant on a network drive. Message-ID: OS: windows 7 Python: 3.8 I am trying to track which files have been modified in a directory on a network mount. When I call the os.stat function for a given file in that directory the stat_result.st_ino changes every time I call it: ``` >>> os.stat('U:\data\current\myfile') os.stat_result(st_mode=33206, st_ino=18446735965107825360, st_dev=33674366, st_nlink=1, st_uid=0, st_gid=0, st_size=433874, st_atime=1598333128, st_mtime=1598330233, st_ctime=1598329773) >>> os.stat('U:\data\current\myfile') os.stat_result(st_mode=33206, st_ino=18446735965183676432, st_dev=33674366, st_nlink=1, st_uid=0, st_gid=0, st_size=433874, st_atime=1598333128, st_mtime=1598330233, st_ctime=1598329773) ``` It's the same file, why on earth does the st_ino field change everytime? st_ino is supposed to "uniquely identify the file for a given value of st_dev." If I do the same thing on a local file instead of on a network mount st_ino is constant and doesn't change. Is this a Python bug, or is it an issue with the way Windows deals with network mounts? Andrew. From gautam.goari123 at gmail.com Tue Aug 25 22:39:21 2020 From: gautam.goari123 at gmail.com (ADITYA) Date: Wed, 26 Aug 2020 08:09:21 +0530 Subject: About float/double type number in range. Message-ID: <5f45cb6d.1c69fb81.d8a4d.2c81@mx.google.com> Dear Sir/Ma?am I am requesting you to satisfy me about float number in Range function, because in the argument of range we can take integer but not double or float whenever double as well as float are integer in nature but when we use double/float in, it gives error that- ?'float' object cannot be interpreted as an integer.? If we want to increment the number by half or quarter what can I do. For ex- Range(1,3,0.5) I want it gives Output as [1 1.5 2 2.5 3) ? I am requesting to change the nature of increment number nature in above example so that we can increase the number with half or quarter any point value. ? Your Sincerely Aditya Gautam Saharsa (Bihar) India Postal Code- 852201 ? ? ? ? ? Sent from [1]Mail for Windows 10 ? [2][IMG] Virus-free. [3]www.avg.com References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 2. http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient 3. http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient From joel.goldstick at gmail.com Wed Aug 26 03:58:50 2020 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 26 Aug 2020 03:58:50 -0400 Subject: About float/double type number in range. In-Reply-To: <5f45cb6d.1c69fb81.d8a4d.2c81@mx.google.com> References: <5f45cb6d.1c69fb81.d8a4d.2c81@mx.google.com> Message-ID: On Wed, Aug 26, 2020 at 3:43 AM ADITYA wrote: > > Dear Sir/Ma?am > > I am requesting you to satisfy me about float number in Range function, > because in the argument of range we can take integer but not double or > float whenever double as well as float are integer in nature but when we > use double/float in, it gives error that- ?'float' object cannot be > interpreted as an integer.? If we want to increment the number by half or > quarter what can I do. > > For ex- Range(1,3,0.5) I want it gives Output as [1 1.5 2 2.5 3) > Take a look at this: >>> l = [i/2 for i in range(2,7)] >>> l [1.0, 1.5, 2.0, 2.5, 3.0] >>> The first line is a list comprehension which is a convenient way to produce a list by performing an operation on each element in range. In your code, you set the end of the range to 3 which will not include 3. It stops at 2. > > > I am requesting to change the nature of increment number nature in above > example so that we can increase the number with half or quarter any point > value. > if you want to increase by 1/4, use a range that is 4 times normal integers. and divide each element by 4 > > Your Sincerely > > Aditya Gautam > > Saharsa (Bihar) > > India > > Postal Code- 852201 > > > > > > > > > > > > Sent from [1]Mail for Windows 10 > > > > [2][IMG] Virus-free. [3]www.avg.com > > References > > Visible links > 1. https://go.microsoft.com/fwlink/?LinkId=550986 > 2. http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient > 3. http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From eryksun at gmail.com Wed Aug 26 05:14:10 2020 From: eryksun at gmail.com (Eryk Sun) Date: Wed, 26 Aug 2020 04:14:10 -0500 Subject: stat_result.st_ino from os.stat isn't constant on a network drive. In-Reply-To: References: Message-ID: On 8/25/20, Andrew Nelson wrote: > > st_ino is supposed to "uniquely identify the file for a given value of > st_dev." That assurance only applies to POSIX systems, not Windows. st_ino is the file ID in Windows. Some filesystems do not support reliable file IDs, if any at all. I would only rely on the st_ino value if the filesystem flags include FILE_SUPPORTS_OPEN_BY_FILE_ID. You can get the filesystem flags via GetVolumeInformationByHandleW, using a handle for any file in the filesystem. For example, FAT filesystems use a semi-stable file ID, which is based on a file's byte offset in the parent directory. This offset can can change if the filesystem is defragmented, so FAT file IDs are unreliable. This is probably why FAT filesystems do not support opening by file ID. Another example is the WebDAV filesystem, which doesn't support file IDs at all, so the value is 0 for all files. st_dev is the volume serial number (VSN) in Windows. Like the file ID, filesystems are not required to support a VSN, in which case it may be 0 (e.g. it's 0 for WebDAV). Even if the VSN is supported, Windows does not guarantee that the value is unique. It's a random 32-bit number, so it's unlikely that a non-zero value isn't unique, but there's no hard guarantee. From PythonList at DancesWithMice.info Wed Aug 26 06:40:36 2020 From: PythonList at DancesWithMice.info (dn) Date: Wed, 26 Aug 2020 22:40:36 +1200 Subject: About float/double type number in range. In-Reply-To: References: <5f45cb6d.1c69fb81.d8a4d.2c81@mx.google.com> Message-ID: <632dd529-6891-a3a8-4ad7-3e8d04d88be1@DancesWithMice.info> On 26/08/2020 19:58, Joel Goldstick wrote: > On Wed, Aug 26, 2020 at 3:43 AM ADITYA wrote: >> >> Dear Sir/Ma?am >> >> I am requesting you to satisfy me about float number in Range function, >> because in the argument of range we can take integer but not double or >> float whenever double as well as float are integer in nature but when we >> use double/float in, it gives error that- ?'float' object cannot be >> interpreted as an integer.? If we want to increment the number by half or >> quarter what can I do. >> >> For ex- Range(1,3,0.5) I want it gives Output as [1 1.5 2 2.5 3) >> > > Take a look at this: >>>> l = [i/2 for i in range(2,7)] >>>> l > [1.0, 1.5, 2.0, 2.5, 3.0] This is a neat solution! To make it more user-friendly, the above needs to be wrapped in a convenience function that the user can call using arguments like "(1,3,0.5)" and not have to think about the 'multiplies' and 'divides'. The problem with constructing such a list is that it is 'expensive', ie if the range is large, more storage-space will be required. In the same way that range() moved to a storage-averse model in Python3, herewith a pair of generator solutions - it might be quite fun to compare the performances (PSL's time library). My first thought was that the count() from the itertools library enables one to step using a floating-point number. So, herewith two generator-based solutions:- <<< Code NB Python v3.8 >>> def fp_range( start:float, stop:float, step:float=1.0 )->float: """Generate a range of floating-point numbers.""" if stop <= start: raise OverflowError( "RangeError: start must be less than stop" ) x = start while x < stop: yield x x += step try: for fp_number in fp_range( 1, 3, 0.5 ): print( fp_number ) except OverflowError as e: print( e ) print( "*"*12 ) try: for fp_number in fp_range( 1, 3, 0.25 ): print( fp_number ) except OverflowError as e: print( e ) print( "+"*12 ) import itertools def fp_iter( start:float, stop:float, step:float=1.0 )->float: """Generate a range of floating-point numbers using itertools.count().""" if stop <= start: raise OverflowError( "RangeError: start must be less than stop" ) for x in itertools.count( start, step ): if x >= stop: break yield x for fp_number in fp_iter( 1, 3, 0.5 ): print( fp_number ) print( "*"*12 ) for fp_number in fp_iter( 1, 3, 0.25 ): print( fp_number ) print( "*"*12 ) try: for fp_number in fp_iter( 3, 1, 0.5 ): print( fp_number ) except OverflowError as e: print( e ) <<< Console.out >>> 1 1.5 2.0 2.5 ************ 1 1.25 1.5 1.75 2.0 2.25 2.5 2.75 ++++++++++++ 1 1.5 2.0 2.5 ************ 1 1.25 1.5 1.75 2.0 2.25 2.5 2.75 ************ RangeError: start must be less than stop -- Regards =dn From hjp-python at hjp.at Wed Aug 26 07:02:55 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 26 Aug 2020 13:02:55 +0200 Subject: About float/double type number in range. In-Reply-To: <632dd529-6891-a3a8-4ad7-3e8d04d88be1@DancesWithMice.info> References: <5f45cb6d.1c69fb81.d8a4d.2c81@mx.google.com> <632dd529-6891-a3a8-4ad7-3e8d04d88be1@DancesWithMice.info> Message-ID: <20200826110255.GA14437@hjp.at> On 2020-08-26 22:40:36 +1200, dn via Python-list wrote: > On 26/08/2020 19:58, Joel Goldstick wrote: > > On Wed, Aug 26, 2020 at 3:43 AM ADITYA wrote: > > > Dear Sir/Ma?am > > > > > > I am requesting you to satisfy me about float number in Range > > > function, because in the argument of range we can take integer > > > but not double or float whenever double as well as float are > > > integer in nature but when we use double/float in, it gives > > > error that- ?'float' object cannot be interpreted as an > > > integer.? If we want to increment the number by half or > > > quarter what can I do. > > > > > > For ex- Range(1,3,0.5) I want it gives Output as [1 1.5 2 2.5 3) > > > > > > > Take a look at this: > > > > > l = [i/2 for i in range(2,7)] > > > > > l > > [1.0, 1.5, 2.0, 2.5, 3.0] > > > This is a neat solution! To make it more user-friendly, the above needs to > be wrapped in a convenience function that the user can call using arguments > like "(1,3,0.5)" and not have to think about the 'multiplies' and 'divides'. > [...] > <<< Code NB Python v3.8 >>> > def fp_range( start:float, stop:float, step:float=1.0 )->float: > """Generate a range of floating-point numbers.""" > if stop <= start: > raise OverflowError( "RangeError: start must be less than stop" ) > x = start > while x < stop: > yield x > x += step This is almost the same solution as I came up with, but note that this is not quote the same as what Joel proposed. Repeated addition is not the same as multiplication with floating point numbers. A generator based on Joel's idea would look like this: def fp_range(start, end, step): v = start n = int(math.ceil((end - start) / step)) for i in range(n): yield start + i * step (I omitted the OverflowError: range() doesn't raise one, 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 Richard at Damon-Family.org Wed Aug 26 07:48:37 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Wed, 26 Aug 2020 07:48:37 -0400 Subject: About float/double type number in range. In-Reply-To: <5f45cb6d.1c69fb81.d8a4d.2c81@mx.google.com> References: <5f45cb6d.1c69fb81.d8a4d.2c81@mx.google.com> Message-ID: On 8/25/20 10:39 PM, ADITYA wrote: > Dear Sir/Ma?am > > I am requesting you to satisfy me about float number in Range function, > because in the argument of range we can take integer but not double or > float whenever double as well as float are integer in nature but when we > use double/float in, it gives error that- ?'float' object cannot be > interpreted as an integer.? If we want to increment the number by half or > quarter what can I do. > > For ex- Range(1,3,0.5) I want it gives Output as [1 1.5 2 2.5 3) > > I am requesting to change the nature of increment number nature in above > example so that we can increase the number with half or quarter any point > value. > > Your Sincerely > > Aditya Gautam > Saharsa (Bihar) > India > Postal Code- 852201 As was indicated, Range(1, 3, 0.5) if legal would generate ([1, 1.5, 2, 2.5] because range excludes the top value. This case happens to work in the sense that if Python allowed it, this is the result that would come out. On the other hand, the very similar Range(1, 3, 0.4) would be need very detailed knowledge to predict, it could return [1, 1.4, 1.8, 2.2, 2.6] as expected or [1, 1.4, 1.8, 2.2, 2.6, 3.0]. The issue is that there is no such exact number in binary floating point as 0.4, (it is like trying to write out exactly 1/3), so the actual value used for 0.4 will be either slightly higher (where you get the expected value) or slightly lower (where you would get the top 'excluded' value listed). This sort of unpredictability is part of the difficulty dealing with floating point. As was pointed out, you can scale the range, or build your own generator to get what you want. -- Richard Damon From cl at isbd.net Wed Aug 26 09:22:10 2020 From: cl at isbd.net (Chris Green) Date: Wed, 26 Aug 2020 14:22:10 +0100 Subject: How do I do this in Python 3 (string.join())? Message-ID: <294i1h-v95v.ln1@esprimo.zbmc.eu> I have the following line in Python 2:- msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list containing the lines of the message ... so I changed it to:- s = "\n" msgstr = s.join(popmsg[1]) # popmsg[1] is a list containing the lines of the message However this still doesn't work because popmsg[1] isn't a list of strings, I get the error:- TypeError: sequence item 0: expected str instance, bytes found So how do I do this? I can see clumsy ways by a loop working through the list in popmsg[1] but surely there must be a way that's as neat and elegant as the Python 2 way was? -- Chris Green ? From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Aug 26 09:44:25 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Wed, 26 Aug 2020 08:44:25 -0500 Subject: How do I do this in Python 3 (string.join())? In-Reply-To: <294i1h-v95v.ln1@esprimo.zbmc.eu> References: <294i1h-v95v.ln1@esprimo.zbmc.eu> Message-ID: <20200826134425.GG3788@scrozzle> On 2020-08-26 at 14:22:10 +0100, Chris Green wrote: > I have the following line in Python 2:- > > msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list containing the lines of the message > > ... so I changed it to:- > > s = "\n" > msgstr = s.join(popmsg[1]) # popmsg[1] is a list containing the lines of the message > > However this still doesn't work because popmsg[1] isn't a list of > strings, I get the error:- > > TypeError: sequence item 0: expected str instance, bytes found > > So how do I do this? I can see clumsy ways by a loop working through > the list in popmsg[1] but surely there must be a way that's as neat > and elegant as the Python 2 way was? Join bytes objects with a byte object: b"\n".join(popmsg[1]) From darcy at VybeNetworks.com Wed Aug 26 09:53:36 2020 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Wed, 26 Aug 2020 09:53:36 -0400 Subject: How do I do this in Python 3 (string.join())? In-Reply-To: <294i1h-v95v.ln1@esprimo.zbmc.eu> References: <294i1h-v95v.ln1@esprimo.zbmc.eu> Message-ID: <574198cc-b5a5-3418-ed44-673d4f4fcec9@VybeNetworks.com> On 2020-08-26 09:22, Chris Green wrote: > I have the following line in Python 2:- > > msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list containing the lines of the message > > ... so I changed it to:- > > s = "\n" > msgstr = s.join(popmsg[1]) # popmsg[1] is a list containing the lines of the message > > However this still doesn't work because popmsg[1] isn't a list of > strings, I get the error:- > > TypeError: sequence item 0: expected str instance, bytes found > > So how do I do this? I can see clumsy ways by a loop working through > the list in popmsg[1] but surely there must be a way that's as neat > and elegant as the Python 2 way was? Well, the simple fix is to set s to b"\n" but that may not solve all of your problems. The issue is that popmsg[1] is a list of bytes. You probably want a list of strings. I would look further back and think about getting a list of strings in the first place. Without knowing how popmsg was created we can't tell you how to do that. Of course, if a bytes object is what you want then the above will work. You can also convert to string after the join. Cheers. -- D'Arcy J.M. Cain Vybe Networks Inc. A unit of Excelsior Solutions Corporation - Propelling Business Forward http://www.VybeNetworks.com/ IM:darcy at VybeNetworks.com VoIP: sip:darcy at VybeNetworks.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 228 bytes Desc: OpenPGP digital signature URL: From python at mrabarnett.plus.com Wed Aug 26 10:00:27 2020 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 26 Aug 2020 15:00:27 +0100 Subject: How do I do this in Python 3 (string.join())? In-Reply-To: <294i1h-v95v.ln1@esprimo.zbmc.eu> References: <294i1h-v95v.ln1@esprimo.zbmc.eu> Message-ID: On 2020-08-26 14:22, Chris Green wrote: > I have the following line in Python 2:- > > msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list containing the lines of the message > > ... so I changed it to:- > > s = "\n" > msgstr = s.join(popmsg[1]) # popmsg[1] is a list containing the lines of the message > > However this still doesn't work because popmsg[1] isn't a list of > strings, I get the error:- > > TypeError: sequence item 0: expected str instance, bytes found > > So how do I do this? I can see clumsy ways by a loop working through > the list in popmsg[1] but surely there must be a way that's as neat > and elegant as the Python 2 way was? > In Python 3, bytestring literals require the 'b' prefix: msgstr = b"\n".join(popmsg[1]) From cl at isbd.net Wed Aug 26 10:09:16 2020 From: cl at isbd.net (Chris Green) Date: Wed, 26 Aug 2020 15:09:16 +0100 Subject: How do I do this in Python 3 (string.join())? References: <294i1h-v95v.ln1@esprimo.zbmc.eu> <20200826134425.GG3788@scrozzle> Message-ID: 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > On 2020-08-26 at 14:22:10 +0100, > Chris Green wrote: > > > I have the following line in Python 2:- > > > > msgstr = string.join(popmsg[1], "\n") # popmsg[1] is a list containing > the lines of the message > > > > ... so I changed it to:- > > > > s = "\n" > > msgstr = s.join(popmsg[1]) # popmsg[1] is a list containing the lines of the message > > > > However this still doesn't work because popmsg[1] isn't a list of > > strings, I get the error:- > > > > TypeError: sequence item 0: expected str instance, bytes found > > > > So how do I do this? I can see clumsy ways by a loop working through > > the list in popmsg[1] but surely there must be a way that's as neat > > and elegant as the Python 2 way was? > > Join bytes objects with a byte object: > > b"\n".join(popmsg[1]) Aaahhh! Thank you (and the other reply). -- Chris Green ? From cl at isbd.net Wed Aug 26 11:10:35 2020 From: cl at isbd.net (Chris Green) Date: Wed, 26 Aug 2020 16:10:35 +0100 Subject: Another 2 to 3 mail encoding problem Message-ID: I'm unearthing a few issues here trying to convert my mail filter and delivery programs from 2 to 3! I have a simple[ish] local mbox mail delivery module as follows:- import mailbox import logging import logging.handlers import os import time # # # Class derived from mailbox.mbox so we can override _pre_message_hook() # to do nothing instead of appending a blank line # class mymbox(mailbox.mbox): def _pre_message_hook(self, f): """Don't write the blank line before the 'From '""" pass # # # log a message # def initLog(name): log = logging.getLogger(name) log.setLevel(logging.DEBUG) f = logging.handlers.RotatingFileHandler("/home/chris/tmp/mail.log", 'a', 1000000, 4) f.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') f.setFormatter(formatter) log.addHandler(f) return log # # # Deliver a message to a local mbox # def deliverMboxMsg(dest, msg, log): # # # Create the destination mbox instance # mbx = mymbox(dest, factory=None) log.info("From: " + msg.get("From", "unknown")) log.info("Destination is: " + dest) # # # Lock the mbox while we append to it # for tries in range(3): try: mbx.lock() # # # Append the incoming message to the appropriate mbox # mbx.add(msg) # # # now set the modified time later than the access time (which is 'now') so # that mutt will see new mail in the mbox. # os.utime(dest, ((time.time()), (time.time() + 5))) mbx.unlock() break except mailbox.ExternalClashError: log.info("Destination locked, try " + str(tries)) time.sleep(1) else: # get here if we ran out of tries log.warn("Failed to lock destination after 3 attempts, giving up") return It has run faultlessly for many years under Python 2. I've now changed the calling program to Python 3 and while it handles most E-Mail OK I have just got the following error:- Traceback (most recent call last): File "/home/chris/.mutt/bin/filter.py", line 102, in mailLib.deliverMboxMsg(dest, msg, log) File "/home/chris/.mutt/bin/mailLib.py", line 52, in deliverMboxMsg mbx.add(msg) File "/usr/lib/python3.8/mailbox.py", line 603, in add self._toc[self._next_key] = self._append_message(message) File "/usr/lib/python3.8/mailbox.py", line 758, in _append_message offsets = self._install_message(message) File "/usr/lib/python3.8/mailbox.py", line 830, in _install_message self._dump_message(message, self._file, self._mangle_from_) File "/usr/lib/python3.8/mailbox.py", line 215, in _dump_message gen.flatten(message) File "/usr/lib/python3.8/email/generator.py", line 116, in flatten self._write(msg) File "/usr/lib/python3.8/email/generator.py", line 181, in _write self._dispatch(msg) File "/usr/lib/python3.8/email/generator.py", line 214, in _dispatch meth(msg) File "/usr/lib/python3.8/email/generator.py", line 432, in _handle_text super(BytesGenerator,self)._handle_text(msg) File "/usr/lib/python3.8/email/generator.py", line 249, in _handle_text self._write_lines(payload) File "/usr/lib/python3.8/email/generator.py", line 155, in _write_lines self.write(line) File "/usr/lib/python3.8/email/generator.py", line 406, in write self._fp.write(s.encode('ascii', 'surrogateescape')) UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in position 4: ordinal not in range(128) So what do I need to do to the message I'm adding with mbx.add(msg) to fix this? (I assume that's what I need to do). -- Chris Green ? From alexandra_mel.1981 at hotmail.es Wed Aug 26 11:27:52 2020 From: alexandra_mel.1981 at hotmail.es (=?Windows-1252?Q?Alexa_O=F1a?=) Date: Wed, 26 Aug 2020 15:27:52 +0000 Subject: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: Don?t send me more emails Obtener Outlook para iOS ________________________________ De: Python-list en nombre de Chris Green Enviado: Wednesday, August 26, 2020 5:10:35 PM Para: python-list at python.org Asunto: Another 2 to 3 mail encoding problem I'm unearthing a few issues here trying to convert my mail filter and delivery programs from 2 to 3! I have a simple[ish] local mbox mail delivery module as follows:- import mailbox import logging import logging.handlers import os import time # # # Class derived from mailbox.mbox so we can override _pre_message_hook() # to do nothing instead of appending a blank line # class mymbox(mailbox.mbox): def _pre_message_hook(self, f): """Don't write the blank line before the 'From '""" pass # # # log a message # def initLog(name): log = logging.getLogger(name) log.setLevel(logging.DEBUG) f = logging.handlers.RotatingFileHandler("/home/chris/tmp/mail.log", 'a', 1000000, 4) f.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') f.setFormatter(formatter) log.addHandler(f) return log # # # Deliver a message to a local mbox # def deliverMboxMsg(dest, msg, log): # # # Create the destination mbox instance # mbx = mymbox(dest, factory=None) log.info("From: " + msg.get("From", "unknown")) log.info("Destination is: " + dest) # # # Lock the mbox while we append to it # for tries in range(3): try: mbx.lock() # # # Append the incoming message to the appropriate mbox # mbx.add(msg) # # # now set the modified time later than the access time (which is 'now') so # that mutt will see new mail in the mbox. # os.utime(dest, ((time.time()), (time.time() + 5))) mbx.unlock() break except mailbox.ExternalClashError: log.info("Destination locked, try " + str(tries)) time.sleep(1) else: # get here if we ran out of tries log.warn("Failed to lock destination after 3 attempts, giving up") return It has run faultlessly for many years under Python 2. I've now changed the calling program to Python 3 and while it handles most E-Mail OK I have just got the following error:- Traceback (most recent call last): File "/home/chris/.mutt/bin/filter.py", line 102, in mailLib.deliverMboxMsg(dest, msg, log) File "/home/chris/.mutt/bin/mailLib.py", line 52, in deliverMboxMsg mbx.add(msg) File "/usr/lib/python3.8/mailbox.py", line 603, in add self._toc[self._next_key] = self._append_message(message) File "/usr/lib/python3.8/mailbox.py", line 758, in _append_message offsets = self._install_message(message) File "/usr/lib/python3.8/mailbox.py", line 830, in _install_message self._dump_message(message, self._file, self._mangle_from_) File "/usr/lib/python3.8/mailbox.py", line 215, in _dump_message gen.flatten(message) File "/usr/lib/python3.8/email/generator.py", line 116, in flatten self._write(msg) File "/usr/lib/python3.8/email/generator.py", line 181, in _write self._dispatch(msg) File "/usr/lib/python3.8/email/generator.py", line 214, in _dispatch meth(msg) File "/usr/lib/python3.8/email/generator.py", line 432, in _handle_text super(BytesGenerator,self)._handle_text(msg) File "/usr/lib/python3.8/email/generator.py", line 249, in _handle_text self._write_lines(payload) File "/usr/lib/python3.8/email/generator.py", line 155, in _write_lines self.write(line) File "/usr/lib/python3.8/email/generator.py", line 406, in write self._fp.write(s.encode('ascii', 'surrogateescape')) UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in position 4: ordinal not in range(128) So what do I need to do to the message I'm adding with mbx.add(msg) to fix this? (I assume that's what I need to do). -- Chris Green ? -- https://mail.python.org/mailman/listinfo/python-list From cl at isbd.net Wed Aug 26 13:12:31 2020 From: cl at isbd.net (Chris Green) Date: Wed, 26 Aug 2020 18:12:31 +0100 Subject: Another 2 to 3 mail encoding problem References: Message-ID: To add a little to this, the problem is definitely when I receive a message with UTF8 (or at least non-ascci) characters in it. My code is basically very simple, the main program reads an E-Mail message received from .forward on its standard input and makes it into an mbox message as follows:- msg = mailbox.mboxMessage(sys.stdin.read()) it then does various tests (but doesn't change msg at all) and at the end delivers the message to my local mbox with:- mbx.add(msg) where mbx is an instance of mailbox.mbox. So, how is one supposed to handle this, should I encode the incoming message somewhere? -- Chris Green ? From python at invalid Wed Aug 26 13:55:49 2020 From: python at invalid (Python) Date: Wed, 26 Aug 2020 19:55:49 +0200 Subject: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: <5f46a225$0$6478$426a74cc@news.free.fr> Alexa O?a wrote: > Don?t send me more emails > > Obtener Outlook para iOS You are the one spamming the mailing list with unrelated posts. STOP. From hjp-python at hjp.at Wed Aug 26 14:06:48 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 26 Aug 2020 20:06:48 +0200 Subject: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: <20200826180648.GA19793@hjp.at> On 2020-08-26 16:10:35 +0100, Chris Green wrote: > I'm unearthing a few issues here trying to convert my mail filter and > delivery programs from 2 to 3! > > I have a simple[ish] local mbox mail delivery module as follows:- > [...] > class mymbox(mailbox.mbox): > def _pre_message_hook(self, f): > """Don't write the blank line before the 'From '""" > pass [...] > def deliverMboxMsg(dest, msg, log): [...] > mbx = mymbox(dest, factory=None) [...] > mbx.add(msg) [...] > > > It has run faultlessly for many years under Python 2. I've now > changed the calling program to Python 3 and while it handles most > E-Mail OK I have just got the following error:- > > Traceback (most recent call last): > File "/home/chris/.mutt/bin/filter.py", line 102, in > mailLib.deliverMboxMsg(dest, msg, log) > File "/home/chris/.mutt/bin/mailLib.py", line 52, in deliverMboxMsg > mbx.add(msg) > File "/usr/lib/python3.8/mailbox.py", line 603, in add > self._toc[self._next_key] = self._append_message(message) > File "/usr/lib/python3.8/mailbox.py", line 758, in _append_message > offsets = self._install_message(message) > File "/usr/lib/python3.8/mailbox.py", line 830, in _install_message > self._dump_message(message, self._file, self._mangle_from_) > File "/usr/lib/python3.8/mailbox.py", line 215, in _dump_message > gen.flatten(message) > File "/usr/lib/python3.8/email/generator.py", line 116, in flatten > self._write(msg) > File "/usr/lib/python3.8/email/generator.py", line 181, in _write > self._dispatch(msg) > File "/usr/lib/python3.8/email/generator.py", line 214, in _dispatch > meth(msg) > File "/usr/lib/python3.8/email/generator.py", line 432, in _handle_text > super(BytesGenerator,self)._handle_text(msg) > File "/usr/lib/python3.8/email/generator.py", line 249, in _handle_text > self._write_lines(payload) > File "/usr/lib/python3.8/email/generator.py", line 155, in _write_lines > self.write(line) > File "/usr/lib/python3.8/email/generator.py", line 406, in write > self._fp.write(s.encode('ascii', 'surrogateescape')) > UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in position 4: ordinal not in range(128) The problem is that the message contains a '\ufeff' character (byte order mark) where email/generator.py expects only ASCII characters. I see two possible reasons for this: * The mbox writing code assumes that all messages with non-ascii characters are QP or base64 encoded, and some higher layer uses 8bit instead. * A mime-part is declared as charset=us-ascii but contains really Unicode characters. Both reasons are weird. The first would be an unreasonable assumption (8bit encoding has been common since the mid-1990s), but even if the code made that assumption, one would expect that other code from the same library honors it. The second shouldn't be possible: If a message is mis-declared (that happens) one would expect that the error happens during parsing, not when trying to serialize the already parsed message. But then you haven't shown where msg comes from. How do you parse the message to get "msg"? Can you construct a minimal test message which triggers the bug? 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 torriem at gmail.com Wed Aug 26 14:27:31 2020 From: torriem at gmail.com (Michael Torrie) Date: Wed, 26 Aug 2020 12:27:31 -0600 Subject: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: On 8/26/20 9:27 AM, Alexa O?a wrote: > Don?t send me more emails > > https://mail.python.org/mailman/listinfo/python-list ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Please unsubscribe from the mailing list. Click on the link above. Thank you. From tjreedy at udel.edu Wed Aug 26 13:38:48 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 26 Aug 2020 13:38:48 -0400 Subject: About float/double type number in range. In-Reply-To: <632dd529-6891-a3a8-4ad7-3e8d04d88be1@DancesWithMice.info> References: <5f45cb6d.1c69fb81.d8a4d.2c81@mx.google.com> <632dd529-6891-a3a8-4ad7-3e8d04d88be1@DancesWithMice.info> Message-ID: On 8/26/2020 6:40 AM, dn via Python-list wrote: > def fp_range( start:float, stop:float, step:float=1.0 )->float: > ??? """Generate a range of floating-point numbers.""" > ??? if stop <= start: > ??????? raise OverflowError( "RangeError: start must be less than stop" ) > ??? x = start > ??? while x < stop: > ??????? yield x > ??????? x += step This only works exactly as expected for fraction steps of k/2**n give exactly. Your only tests used .5 and .25. print(list(fp_range(0.0, 2.01, .1))) produces [0.0, 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999, 1.0999999999999999, 1.2, 1.3, 1.4000000000000001, 1.5000000000000002, 1.6000000000000003, 1.7000000000000004, 1.8000000000000005, 1.9000000000000006, 2.0000000000000004] For exact fractional steps, one should use fractions or multiply and divide by the denominator, as shown by Joel, after stepping by the numerator. -- Terry Jan Reedy From tjreedy at udel.edu Wed Aug 26 13:43:41 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 26 Aug 2020 13:43:41 -0400 Subject: Unsubscrip (Re: Another 2 to 3 mail encoding problem) In-Reply-To: References: Message-ID: On 8/26/2020 11:27 AM, Alexa O?a wrote: > Don?t send me more emails > -- > https://mail.python.org/mailman/listinfo/python-list Unsubscribe yourself by going to the indicated url. -- Terry Jan Reedy From tjreedy at udel.edu Wed Aug 26 13:58:49 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 26 Aug 2020 13:58:49 -0400 Subject: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: On 8/26/2020 11:10 AM, Chris Green wrote: > I have a simple[ish] local mbox mail delivery module as follows:- ... > It has run faultlessly for many years under Python 2. I've now > changed the calling program to Python 3 and while it handles most > E-Mail OK I have just got the following error:- > > Traceback (most recent call last): > File "/home/chris/.mutt/bin/filter.py", line 102, in > mailLib.deliverMboxMsg(dest, msg, log) ... > File "/usr/lib/python3.8/email/generator.py", line 406, in write > self._fp.write(s.encode('ascii', 'surrogateescape')) > UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in position 4: ordinal not in range(128) '\ufeff' is the Unicode byte-order mark. It should not be present in an ascii-only 3.x string and would not normally be present in general unicode except in messages like this that talk about it. Read about it, for instance, at https://en.wikipedia.org/wiki/Byte_order_mark I would catch the error and print part or all of string s to see what is going on with this particular message. Does it have other non-ascii chars? -- Terry Jan Reedy From Marco.Sulla.Python at gmail.com Wed Aug 26 16:10:26 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Wed, 26 Aug 2020 22:10:26 +0200 Subject: Why __hash__() does not return an UUID4? In-Reply-To: References: Message-ID: As title. The reasons that came in my mind are: 1. speed 2. security From Richard at Damon-Family.org Wed Aug 26 17:12:09 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Wed, 26 Aug 2020 17:12:09 -0400 Subject: Why __hash__() does not return an UUID4? In-Reply-To: References: Message-ID: <5d56cf42-c8f4-eb23-4ff3-770e64c3009c@Damon-Family.org> On 8/26/20 4:10 PM, Marco Sulla wrote: > As title. The reasons that came in my mind are: > > 1. speed > 2. security My guess is that the typical use of the value for __hash__() doesn't need that level of guarantee of uniqueness, so requiring it would be unnecessarily expensive. Since the typical use of hash will be followed by a real equality test if the hashes match, we don't need the level of a UUID -- Richard Damon From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Aug 26 17:13:50 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Wed, 26 Aug 2020 16:13:50 -0500 Subject: Why __hash__() does not return an UUID4? In-Reply-To: References: Message-ID: <20200826211350.GH3788@scrozzle> On 2020-08-26 at 22:10:26 +0200, Marco Sulla wrote: > As title ... Assuming that the title appears prominently with the content of your email. For the rest of us: Why __hash__() does not return an UUID4? > ... The reasons that came in my mind are: > > 1. speed > 2. security Correctness? Why would __hash__() return a random number? An important property of hashes is that if x == y, then hash(x) == hash(y). If hash(x) and hash(y) were random numbers, then how would this property be maintained? Or do UUID4 mean something else to you than a random number? From Richard at Damon-Family.org Wed Aug 26 17:50:36 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Wed, 26 Aug 2020 17:50:36 -0400 Subject: Why __hash__() does not return an UUID4? In-Reply-To: <20200826211350.GH3788@scrozzle> References: <20200826211350.GH3788@scrozzle> Message-ID: <8d8f8f9a-88cf-cf1c-0fc9-eca7c1d3755a@Damon-Family.org> On 8/26/20 5:13 PM, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > On 2020-08-26 at 22:10:26 +0200, > Marco Sulla wrote: > >> As title ... > Assuming that the title appears prominently with the content of your > email. For the rest of us: > > Why __hash__() does not return an UUID4? > >> ... The reasons that came in my mind are: >> >> 1. speed >> 2. security > Correctness? > > Why would __hash__() return a random number? An important property of > hashes is that if x == y, then hash(x) == hash(y). If hash(x) and > hash(y) were random numbers, then how would this property be maintained? > > Or do UUID4 mean something else to you than a random number? Looking up which UUID type 4 is, yes it is a random number, so could only be applicable for objects that currently return id(), which could instead make id() be a UUID4 (and save it in the object, increasing its side) -- Richard Damon From rosuav at gmail.com Wed Aug 26 17:56:02 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Aug 2020 07:56:02 +1000 Subject: Why __hash__() does not return an UUID4? In-Reply-To: <8d8f8f9a-88cf-cf1c-0fc9-eca7c1d3755a@Damon-Family.org> References: <20200826211350.GH3788@scrozzle> <8d8f8f9a-88cf-cf1c-0fc9-eca7c1d3755a@Damon-Family.org> Message-ID: On Thu, Aug 27, 2020 at 7:52 AM Richard Damon wrote: > > On 8/26/20 5:13 PM, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > > On 2020-08-26 at 22:10:26 +0200, > > Marco Sulla wrote: > > > >> As title ... > > Assuming that the title appears prominently with the content of your > > email. For the rest of us: > > > > Why __hash__() does not return an UUID4? > > > >> ... The reasons that came in my mind are: > >> > >> 1. speed > >> 2. security > > Correctness? > > > > Why would __hash__() return a random number? An important property of > > hashes is that if x == y, then hash(x) == hash(y). If hash(x) and > > hash(y) were random numbers, then how would this property be maintained? > > > > Or do UUID4 mean something else to you than a random number? > > Looking up which UUID type 4 is, yes it is a random number, so could > only be applicable for objects that currently return id(), which could > instead make id() be a UUID4 (and save it in the object, increasing its > side) > I can't see how this is any benefit over any other definition, but if someone wants to propose that id() return a UUID4, then that would be entirely separate from anything regarding hash. As long as there's an absolute guarantee that the same ID will never be used for two objects at once, it's fine to generate them any way you like. ChrisA From rob.cliffe at btinternet.com Wed Aug 26 07:53:02 2020 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Wed, 26 Aug 2020 12:53:02 +0100 Subject: About float/double type number in range. In-Reply-To: <20200826110255.GA14437@hjp.at> References: <5f45cb6d.1c69fb81.d8a4d.2c81@mx.google.com> <632dd529-6891-a3a8-4ad7-3e8d04d88be1@DancesWithMice.info> <20200826110255.GA14437@hjp.at> Message-ID: <7696247a-5008-92f4-af9f-de3e75e11ca6@btinternet.com> On 26/08/2020 12:02, Peter J. Holzer wrote: > On 2020-08-26 22:40:36 +1200, dn via Python-list wrote: >> On 26/08/2020 19:58, Joel Goldstick wrote: >> > [...] >> <<< Code NB Python v3.8 >>> >> def fp_range( start:float, stop:float, step:float=1.0 )->float: >> """Generate a range of floating-point numbers.""" >> if stop <= start: >> raise OverflowError( "RangeError: start must be less than stop" ) >> x = start >> while x < stop: >> yield x >> x += step > This is almost the same solution as I came up with, but note that this > is not quote the same as what Joel proposed. Repeated addition is not > the same as multiplication with floating point numbers. To expand on this: it is because floating point numbers cannot represent all real numbers exactly. Repeated addition of a number represented inexactly will drift away from the mathematical value. Example: fp_range(0, 70, 0.07) as written above will yield 1001 numbers ending with 69.99999999999966 (i.e. approximately, but not quite, 70). Whereas Peter's version (below) will correctly yield 1000 numbers ending with 69.93. (Even then some numbers are not represented exactly, e.g. the last-but-one is 69.86000000000001.) > > > A generator based on Joel's idea would look like this: > > def fp_range(start, end, step): > v = start > n = int(math.ceil((end - start) / step)) > for i in range(n): > yield start + i * step > From cs at cskk.id.au Wed Aug 26 22:57:52 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 27 Aug 2020 12:57:52 +1000 Subject: Why __hash__() does not return an UUID4? In-Reply-To: References: Message-ID: <20200827025752.GA87188@cskk.homeip.net> On 26Aug2020 22:10, Marco Sulla wrote: >As title. The reasons that came in my mind are: >1. speed >2. security Various reasons come to mind: - it is overkill for what __hash__ has to do (computational and feature overkill) - requires importing the uuid module (overkill again) - speed - the hash must be the same each time it is called for a given object, so you'd need to waste space saving a UUID The requirements for a hash are that: - it be stable for a given object - for use in dicts, objects of equal value (via ==) have the same hash That second is actually a problem for UUID4. Suppose we have 2 independent objects with the same value - how are you to ensure they have the same UUID? Think through how a hash is used in a hash table - the hash is used to distribute values into buckets in a statisticly even fashion, so that all the values which are "equal" land in the _same_ bucket. That requires coordination of the hash values. Where that matters, you compute the hash from the value. UUID4s are not like that. Cheers, Cameron Simpson From cs at cskk.id.au Wed Aug 26 22:53:06 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 27 Aug 2020 12:53:06 +1000 Subject: How do I do this in Python 3 (string.join())? In-Reply-To: References: Message-ID: <20200827025306.GA11341@cskk.homeip.net> On 26Aug2020 15:09, Chris Green wrote: >2QdxY4RzWzUUiLuE at potatochowder.com wrote: >> Join bytes objects with a byte object: >> >> b"\n".join(popmsg[1]) > >Aaahhh! Thank you (and the other reply). But note: joining bytes like strings is uncommon, and may indicate that you should be working in strings to start with. Eg you may want to convert popmsg from bytes to str and do a str.join anyway. It depends on exactly what you're dealing with: are you doing text work, or are you doing "binary data" work? I know many network protocols are "bytes-as-text, but that is accomplished by implying an encoding of the text, eg as ASCII, where characters all fit in single bytes/octets. Cheers, Cameron Simpson From samuelmarks at gmail.com Thu Aug 27 01:58:11 2020 From: samuelmarks at gmail.com (Samuel Marks) Date: Thu, 27 Aug 2020 15:58:11 +1000 Subject: ABC with abstractmethod: kwargs on Base, explicit names on implementation In-Reply-To: References: Message-ID: The main thing I want is type safety. I want Python to complain if the callee uses the wrong argument types, and to provide suggestions on what's needed and info about it. Without a base class I can just have docstrings and type annotations to achieve that. What can I use that will require all implementers to have a minimum of the same properties and arguments, but also allow them to add new properties and arguments? Preferably I would like this all to happen before compile/interpret time. This also opens it up to AST driven stub generation; as can be found in various IDEs (and also a little project I wrote that `import ast`). What are my options here? - It doesn't seem like the metaclass or decorator approaches will help here? Samuel Marks Charity | consultancy | open-source | LinkedIn Samuel Marks wrote at 2020-8-24 18:24 +1000: >After a discussion on #python on Freenode, I'm here. > >The gist of it is: >> Falc - Signature of method 'Pharm.foo()' does not match signature of base method in class 'Base' > >What's the right way of specialising the children and leaving the Base >pretty much empty? > >Specifically I want: >? All implementers to be forced to implement Base's method >? Base to be able to do very basic things with kwargs, namely log it >(to a file like stdout or a db) >? Support for [at least] Python 3.6?3.9 (I don't think `Protocol` has >been backported?) >? Implementors to have access to the proper name, rather than having >to unpack kwargs > >Should I be using a Base class? - Metaclass? - Something else >entirely? - I know giving `b` a default value would resolve the >[PyCharm] linter error? but I want it to be a required argument. > >Full example: > >from abc import ABC, abstractmethod > > >class Base(ABC): > @abstractmethod > def foo(self, a, **kwargs): > ... >class Pharm(Base): > def foo(self, a, b): > ... Python make a distinction between positional and keyword arguments. A positional argument is identified by its position in the parameter list; a keyword argument is identified by its name. `**` introduces arbitrary keyword arguments. In a call, all those arguments must be passed as "name=value". In your case above, `b` is not a keyword argument and thus is not matched by `**kwargs`. The error you observe is justified. You can try: class Base(ABC): @abstractmethod def foo(self, a, *args, **kwargs): ... class Pharm(Base): def foo(self, a, b, *args, **kwargs): ... Note that the base method signature allows arbitrary positional and keyword arguments. As a consequence, derived methods must do the same. If this is not what you want, you might want to explore the use of a decorator or a meta class rather than a base class. From greg.ewing at canterbury.ac.nz Thu Aug 27 02:48:38 2020 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 27 Aug 2020 18:48:38 +1200 Subject: Fwd: [BUG] missing ')' causes syntax error on next line In-Reply-To: References: <71aad8e9-b157-4ebf-f7bc-77fc33d67d8a@stoneleaf.us> Message-ID: On 23/07/20 12:23 pm, dn wrote: > You be sure to have a nice day, now! How do you feel about you be sure to have a nice day, now? -- Greg From __peter__ at web.de Thu Aug 27 03:28:30 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 27 Aug 2020 09:28:30 +0200 Subject: ABC with abstractmethod: kwargs on Base, explicit names on implementation References: Message-ID: Samuel Marks wrote: > The main thing I want is type safety. I want Python to complain if the > callee uses the wrong argument types, and to provide suggestions on > what's needed and info about it. > > Without a base class I can just have docstrings and type annotations > to achieve that. > > What can I use that will require all implementers to have a minimum of > the same properties and arguments, but also allow them to add new > properties and arguments? The clean way would be to give the variants with a different signature a different name. From cl at isbd.net Thu Aug 27 04:16:21 2020 From: cl at isbd.net (Chris Green) Date: Thu, 27 Aug 2020 09:16:21 +0100 Subject: How do I do this in Python 3 (string.join())? References: <20200827025306.GA11341@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > On 26Aug2020 15:09, Chris Green wrote: > >2QdxY4RzWzUUiLuE at potatochowder.com wrote: > >> Join bytes objects with a byte object: > >> > >> b"\n".join(popmsg[1]) > > > >Aaahhh! Thank you (and the other reply). > > But note: joining bytes like strings is uncommon, and may indicate that > you should be working in strings to start with. Eg you may want to > convert popmsg from bytes to str and do a str.join anyway. It depends on > exactly what you're dealing with: are you doing text work, or are you > doing "binary data" work? > > I know many network protocols are "bytes-as-text, but that is > accomplished by implying an encoding of the text, eg as ASCII, where > characters all fit in single bytes/octets. > Yes, I realise that making everything a string before I start might be the 'right' way to do things but one is a bit limited by what the mail handling modules in Python provide. E.g. in this case the only (well the only ready made) way to get a POP3 message is using poplib and this just gives you a list of lines made up of "bytes as text" :- popmsg = pop3.retr(i+1) I join the lines to feed them into mailbox.mbox() to create a mbox I can analyse and also a message which can be sent using SMTP. Should I be converting to string somewhere? I guess the POP3 and SMTP libraries will cope with strings as input. Can I convert to string after the join for example? If so, how? Can I just do:- msgbytes = b'\n'.join(popmsg[1]) msgstr = str(mshbytes) (Yes, I know it can be one line, I was just being explicit). ... or do I need to stringify the lines returned by popmsg() before joining them together? Thank you for all your help and comments! (I'm a C programmer at heart, preceded by being an assembler programmer. I started programming way back in the 1970s, I'm retired now and Python is for relaxation (?) in my dotage) -- Chris Green ? From cl at isbd.net Thu Aug 27 04:31:44 2020 From: cl at isbd.net (Chris Green) Date: Thu, 27 Aug 2020 09:31:44 +0100 Subject: Another 2 to 3 mail encoding problem References: Message-ID: Terry Reedy wrote: > On 8/26/2020 11:10 AM, Chris Green wrote: > > > I have a simple[ish] local mbox mail delivery module as follows:- > ... > > It has run faultlessly for many years under Python 2. I've now > > changed the calling program to Python 3 and while it handles most > > E-Mail OK I have just got the following error:- > > > > Traceback (most recent call last): > > File "/home/chris/.mutt/bin/filter.py", line 102, in > > mailLib.deliverMboxMsg(dest, msg, log) > ... > > File "/usr/lib/python3.8/email/generator.py", line 406, in write > > self._fp.write(s.encode('ascii', 'surrogateescape')) > > UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in > position 4: ordinal not in range(128) > > '\ufeff' is the Unicode byte-order mark. It should not be present in an > ascii-only 3.x string and would not normally be present in general > unicode except in messages like this that talk about it. Read about it, > for instance, at > https://en.wikipedia.org/wiki/Byte_order_mark > > I would catch the error and print part or all of string s to see what is > going on with this particular message. Does it have other non-ascii chars? > I can provoke the error simply by sending myself an E-Mail with accented characters in it. I'm pretty sure my Linux system is set up correctly for UTF8 characters, I certainly seem to be able to send and receive these to others and I even get to see messages in other scripts such as arabic, chinese, etc. The code above works perfectly in Python 2 delivering messages with accented (and other extended) characters with no problems at all. Sending myself E-Mails with accented characters works OK with the code running under Python 2. While an E-Mail body possibly *shouldn't* have non-ASCII characters in it one must be able to handle them without errors. In fact haven't the RFCs changed such that the message body should be 8-bit clean? Anyway I think the Python 3 mail handling libraries need to be able to pass extended characters through without errors. -- Chris Green ? From cl at isbd.net Thu Aug 27 04:34:47 2020 From: cl at isbd.net (Chris Green) Date: Thu, 27 Aug 2020 09:34:47 +0100 Subject: Another 2 to 3 mail encoding problem References: <20200826180648.GA19793@hjp.at> Message-ID: <7q7k1h-vap31.ln1@esprimo.zbmc.eu> Peter J. Holzer wrote: > The problem is that the message contains a '\ufeff' character (byte > order mark) where email/generator.py expects only ASCII characters. > > I see two possible reasons for this: > > * The mbox writing code assumes that all messages with non-ascii > characters are QP or base64 encoded, and some higher layer uses 8bit > instead. > > * A mime-part is declared as charset=us-ascii but contains really > Unicode characters. > > Both reasons are weird. > > The first would be an unreasonable assumption (8bit encoding has been > common since the mid-1990s), but even if the code made that assumption, > one would expect that other code from the same library honors it. > > The second shouldn't be possible: If a message is mis-declared (that > happens) one would expect that the error happens during parsing, not > when trying to serialize the already parsed message. > > But then you haven't shown where msg comes from. How do you parse the > message to get "msg"? > > Can you construct a minimal test message which triggers the bug? > Yes, simply sending myself an E-Mail with (for example) accented characters triggers the error. I'm pretty certain my system (and E-Mail in and out, and Usenet news) handle these correctly as UTF8. E.g.:- ???? It's *only* when I switch the mail delivery to Python 3 that the error appears. -- Chris Green ? From Karsten.Hilbert at gmx.net Thu Aug 27 04:52:49 2020 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 27 Aug 2020 10:52:49 +0200 Subject: Aw: Re: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: > Terry Reedy wrote: > > On 8/26/2020 11:10 AM, Chris Green wrote: > > > > > I have a simple[ish] local mbox mail delivery module as follows:- > > ... > > > It has run faultlessly for many years under Python 2. I've now > > > changed the calling program to Python 3 and while it handles most > > > E-Mail OK I have just got the following error:- > > > > > > Traceback (most recent call last): > > > File "/home/chris/.mutt/bin/filter.py", line 102, in > > > mailLib.deliverMboxMsg(dest, msg, log) > > ... > > > File "/usr/lib/python3.8/email/generator.py", line 406, in write > > > self._fp.write(s.encode('ascii', 'surrogateescape')) > > > UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in > > position 4: ordinal not in range(128) > > > > '\ufeff' is the Unicode byte-order mark. It should not be present in an > > ascii-only 3.x string and would not normally be present in general > > unicode except in messages like this that talk about it. Read about it, > > for instance, at > > https://en.wikipedia.org/wiki/Byte_order_mark > > > > I would catch the error and print part or all of string s to see what is > > going on with this particular message. Does it have other non-ascii chars? > > > I can provoke the error simply by sending myself an E-Mail with > accented characters in it. I'm pretty sure my Linux system is set up > correctly for UTF8 characters, I certainly seem to be able to send and > receive these to others and I even get to see messages in other > scripts such as arabic, chinese, etc. > > The code above works perfectly in Python 2 delivering messages with > accented (and other extended) characters with no problems at all. > Sending myself E-Mails with accented characters works OK with the code > running under Python 2. > > While an E-Mail body possibly *shouldn't* have non-ASCII characters in > it one must be able to handle them without errors. In fact haven't > the RFCs changed such that the message body should be 8-bit clean? > Anyway I think the Python 3 mail handling libraries need to be able to > pass extended characters through without errors. Well, '\ufeff' is not a *character* at all in much of any sense of that word in unicode. It's a marker. Whatever puts it into the stream is wrong. I guess the best one can (and should) do is to catch the exception and dump the offending stream somewhere binary-capable and pass on a notice. What you are receiving there very much isn't a (well-formed) e-mail message. I would then attempt to backwards-crawl the delivery chain to find out where it came from. Or so is my current understanding. Karsten From __peter__ at web.de Thu Aug 27 05:12:04 2020 From: __peter__ at web.de (Peter Otten) Date: Thu, 27 Aug 2020 11:12:04 +0200 Subject: Another 2 to 3 mail encoding problem References: Message-ID: Chris Green wrote: > To add a little to this, the problem is definitely when I receive a > message with UTF8 (or at least non-ascci) characters in it. My code > is basically very simple, the main program reads an E-Mail message > received from .forward on its standard input and makes it into an mbox > message as follows:- > > msg = mailbox.mboxMessage(sys.stdin.read()) > > it then does various tests (but doesn't change msg at all) and at the > end delivers the message to my local mbox with:- > > mbx.add(msg) > > where mbx is an instance of mailbox.mbox. > > > So, how is one supposed to handle this, should I encode the incoming > message somewhere? > This is what I'd try. Or just read the raw bytes: data = sys.stdin.detach().read() msg = mailbox.mboxMessage(data) From cs at cskk.id.au Thu Aug 27 05:16:47 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 27 Aug 2020 19:16:47 +1000 Subject: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: <20200827091647.GA3338@cskk.homeip.net> On 27Aug2020 09:31, Chris Green wrote: >I can provoke the error simply by sending myself an E-Mail with >accented characters in it. I'm pretty sure my Linux system is set up >correctly for UTF8 characters, I certainly seem to be able to send and >receive these to others and I even get to see messages in other >scripts such as arabic, chinese, etc. See: https://docs.python.org/3/library/email.generator.html#module-email.generator While is conservatively writes ASCII (and email has extensive support for encoding other character sets into ASCII), you might profit by looking at the BytesGenerator in that module using the policy parameter, which looks like it tunes the behaviour of the flatten method. I have a mailfiler of my own, which copes just fine. It loads messages with email.parser.Parser, whose .parse() method returns a Message, and Message.as_string() seems to write happily into a text file for me. I run _all_ my messages through this stuff. Cheers, Cameron Simpson From cl at isbd.net Thu Aug 27 05:27:31 2020 From: cl at isbd.net (Chris Green) Date: Thu, 27 Aug 2020 10:27:31 +0100 Subject: Another 2 to 3 mail encoding problem References: Message-ID: <3tak1h-vi041.ln1@esprimo.zbmc.eu> Karsten Hilbert wrote: > > Terry Reedy wrote: > > > On 8/26/2020 11:10 AM, Chris Green wrote: > > > > > > > I have a simple[ish] local mbox mail delivery module as follows:- > > > ... > > > > It has run faultlessly for many years under Python 2. I've now > > > > changed the calling program to Python 3 and while it handles most > > > > E-Mail OK I have just got the following error:- > > > > > > > > Traceback (most recent call last): > > > > File "/home/chris/.mutt/bin/filter.py", line 102, in > > > > mailLib.deliverMboxMsg(dest, msg, log) > > > ... > > > > File "/usr/lib/python3.8/email/generator.py", line 406, in write > > > > self._fp.write(s.encode('ascii', 'surrogateescape')) > > > > UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in > > > position 4: ordinal not in range(128) > > > > > > '\ufeff' is the Unicode byte-order mark. It should not be present in an > > > ascii-only 3.x string and would not normally be present in general > > > unicode except in messages like this that talk about it. Read about it, > > > for instance, at > > > https://en.wikipedia.org/wiki/Byte_order_mark > > > > > > I would catch the error and print part or all of string s to see what is > > > going on with this particular message. Does it have other non-ascii chars? > > > > > I can provoke the error simply by sending myself an E-Mail with > > accented characters in it. I'm pretty sure my Linux system is set up > > correctly for UTF8 characters, I certainly seem to be able to send and > > receive these to others and I even get to see messages in other > > scripts such as arabic, chinese, etc. > > > > The code above works perfectly in Python 2 delivering messages with > > accented (and other extended) characters with no problems at all. > > Sending myself E-Mails with accented characters works OK with the code > > running under Python 2. > > > > While an E-Mail body possibly *shouldn't* have non-ASCII characters in > > it one must be able to handle them without errors. In fact haven't > > the RFCs changed such that the message body should be 8-bit clean? > > Anyway I think the Python 3 mail handling libraries need to be able to > > pass extended characters through without errors. > > Well, '\ufeff' is not a *character* at all in much of any > sense of that word in unicode. > > It's a marker. Whatever puts it into the stream is wrong. I guess the > best one can (and should) do is to catch the exception and dump > the offending stream somewhere binary-capable and pass on a notice. What > you are receiving there very much isn't a (well-formed) e-mail message. > > I would then attempt to backwards-crawl the delivery chain to > find out where it came from. > The error seems to occur with any non-7-bit-ASCII, e.g. my accented characters gave:- File "/usr/lib/python3.8/email/generator.py", line 406, in write self._fp.write(s.encode('ascii', 'surrogateescape')) UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 34: ordinal not in range(128) It just happened that the first example was an escape. -- Chris Green ? From cs at cskk.id.au Thu Aug 27 05:30:15 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 27 Aug 2020 19:30:15 +1000 Subject: How do I do this in Python 3 (string.join())? In-Reply-To: References: Message-ID: <20200827093015.GA45672@cskk.homeip.net> On 27Aug2020 09:16, Chris Green wrote: >Cameron Simpson wrote: >> But note: joining bytes like strings is uncommon, and may indicate >> that >> you should be working in strings to start with. Eg you may want to >> convert popmsg from bytes to str and do a str.join anyway. It depends on >> exactly what you're dealing with: are you doing text work, or are you >> doing "binary data" work? >> >> I know many network protocols are "bytes-as-text, but that is >> accomplished by implying an encoding of the text, eg as ASCII, where >> characters all fit in single bytes/octets. >> >Yes, I realise that making everything a string before I start might be >the 'right' way to do things but one is a bit limited by what the mail >handling modules in Python provide. I do ok, though most of my message processing happens to messages already landed in my "spool" Maildir by getmail. My setup uses getmail to get messages with POP into a single Maildir, and then I process the message files from there. >E.g. in this case the only (well the only ready made) way to get a >POP3 message is using poplib and this just gives you a list of lines >made up of "bytes as text" :- > > popmsg = pop3.retr(i+1) Ok, so you have bytes? You need to know. >I join the lines to feed them into mailbox.mbox() to create a mbox I >can analyse and also a message which can be sent using SMTP. > >Should I be converting to string somewhere? I have not used poplib, but the Python email modules have a BytesParser, which gets you a Message object; I would feed the poplib bytes to that to parse the received message. A Message object can then be transcribed as text via its .as_string method. Or you can do other things with it. I think my main points are: - know whether you're using bytes (uninterpreted data) or text (strings of _characters_); treating bytes _as_ text implies an encoding, and when that assumption is incorrect you get mojibake[1] - look at the email modules' parsers, which return Messages, a representation of the message in a structure (so that MIME subparts etc are correctly broken out, and the character sets are _known_, post parse) [1] https://en.wikipedia.org/wiki/Mojibake Cheers, Cameron Simpson From Richard at Damon-Family.org Thu Aug 27 09:01:11 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Thu, 27 Aug 2020 09:01:11 -0400 Subject: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: On 8/27/20 4:31 AM, Chris Green wrote: > While an E-Mail body possibly *shouldn't* have non-ASCII characters in > it one must be able to handle them without errors. In fact haven't > the RFCs changed such that the message body should be 8-bit clean? > Anyway I think the Python 3 mail handling libraries need to be able to > pass extended characters through without errors. Email message a fully allowed to use non-ASCII characters in them as long as the headers indicate this. They can be encoded either as raw 8 bit bytes on systems that are 8-bit clean, or for systems that are not, they will need to be encoded either as base-64 or using quote-printable encoding. These characters are to interpreted in the character set defined (or presumed) in the header, or even some other binary object like and image or executable if the content type isn't text. Because of this, the Python 3 str type is not suitable to store an email message, since it insists on the string being Unicode encoded, but the Python 2 str class could hold it. -- Richard Damon From miroslaw.kowalinski at gmail.com Thu Aug 27 09:00:25 2020 From: miroslaw.kowalinski at gmail.com (mikkow34ify) Date: Thu, 27 Aug 2020 06:00:25 -0700 (PDT) Subject: Python installer hangs in Windows 7 In-Reply-To: <4937231c-f798-4ee5-852e-d22d3f6c8ef3@googlegroups.com> References: <765703485.1601081.1486357381135.ref@mail.yahoo.com> <765703485.1601081.1486357381135@mail.yahoo.com> <4937231c-f798-4ee5-852e-d22d3f6c8ef3@googlegroups.com> Message-ID: <1a034565-eb33-41f0-88df-90f22821af83n@googlegroups.com> poniedzia?ek, 16 kwietnia 2018 o?10:51:37 UTC+2 jtsh... at gmail.com napisa?(a): > On Monday, February 6, 2017 at 10:46:24 AM UTC+5:30, Jean-Claude Roy wrote: > > I am trying to install Python 3.6.0 on a Windows 7 computer. > > The download of 29.1 MB is successful and I get the nextwindow. I choose the "install now" selection and thatopens the Setup Program window. > > Now the trouble starts:I get "Installing:" and the Initialization progress...and nothing else. > > There is no additional disk activity, no progress on initialization, andeverything appears dead. Even after 20 minutes there is zero progress. > > I've repeated this as both a user and the administrator of this Windowscomputer. I get the same results in either case. > > If I go to the task manager it shows that Python 3.6.0 (32-bit) setup is running. If I try to end the task Iget the message that the program is not responding. > > Do you have any suggestions as to how I can get past this? > > Thank you. > Uncheck the install for all users part and it will work and log into each user individually and then install. Unchecking works also for 3.8.5 version. Thanks From Karsten.Hilbert at gmx.net Thu Aug 27 09:07:21 2020 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 27 Aug 2020 15:07:21 +0200 Subject: Aw: Re: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: > Because of this, the Python 3 str type is not suitable to store an email > message, since it insists on the string being Unicode encoded, I should greatly appreciate to be enlightened as to what a "string being Unicode encoded" is intended to say ? Thanks, Karsten From rosuav at gmail.com Thu Aug 27 09:13:22 2020 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 27 Aug 2020 23:13:22 +1000 Subject: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: On Thu, Aug 27, 2020 at 11:10 PM Karsten Hilbert wrote: > > > Because of this, the Python 3 str type is not suitable to store an email > > message, since it insists on the string being Unicode encoded, > > I should greatly appreciate to be enlightened as to what > a "string being Unicode encoded" is intended to say ? > A Python 3 "str" or a Python 2 "unicode" is an abstract sequence of Unicode codepoints. As such, it's not suitable for transparently round-tripping an email, as it would lose information about the way that things were encoded. However, it is excellent for building and processing emails - you deal with character encodings at the same point where you deal with the RFC 822 header format. In the abstract, your headers might be stored in a dict, but then you encode them to a flat sequence of bytes by putting "Header: value", wrapping correctly - and also encode the text into bytes at the same time. ChrisA From Karsten.Hilbert at gmx.net Thu Aug 27 09:42:29 2020 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Thu, 27 Aug 2020 15:42:29 +0200 Subject: Aw: Re: Re: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: > > > Because of this, the Python 3 str type is not suitable to store an email > > > message, since it insists on the string being Unicode encoded, > > > > I should greatly appreciate to be enlightened as to what > > a "string being Unicode encoded" is intended to say ? > > > > A Python 3 "str" or a Python 2 "unicode" is an abstract sequence of > Unicode codepoints. OK, I figured that much. So it was the "encoded" that threw me off. Being a sequence of Unicode codepoints makes it en-Uni-coded at a technically abstract level while I assumed the "encoded" is meant to somehow reference ''.encode() and friends. Karsten From cl at isbd.net Thu Aug 27 09:36:01 2020 From: cl at isbd.net (Chris Green) Date: Thu, 27 Aug 2020 14:36:01 +0100 Subject: How do I do this in Python 3 (string.join())? References: <20200827093015.GA45672@cskk.homeip.net> Message-ID: <1fpk1h-neu41.ln1@esprimo.zbmc.eu> Cameron Simpson wrote: > On 27Aug2020 09:16, Chris Green wrote: > >Cameron Simpson wrote: > >> But note: joining bytes like strings is uncommon, and may indicate > >> that > >> you should be working in strings to start with. Eg you may want to > >> convert popmsg from bytes to str and do a str.join anyway. It depends on > >> exactly what you're dealing with: are you doing text work, or are you > >> doing "binary data" work? > >> > >> I know many network protocols are "bytes-as-text, but that is > >> accomplished by implying an encoding of the text, eg as ASCII, where > >> characters all fit in single bytes/octets. > >> > >Yes, I realise that making everything a string before I start might be > >the 'right' way to do things but one is a bit limited by what the mail > >handling modules in Python provide. > > I do ok, though most of my message processing happens to messages > already landed in my "spool" Maildir by getmail. My setup uses getmail > to get messages with POP into a single Maildir, and then I process the > message files from there. > Most of my mail is delivered by SMTP, I run a Postfix SMTP *serever* on my desktop machine which stays on permanently. The POP3 processing is solely to collect E-Mail that ends up in the 'catchall' mailbox on my hosting provider. It empties the POP3 catchall mailbox, checks for anything that *might* be for me or other family members then just deletes the rest. > >E.g. in this case the only (well the only ready made) way to get a > >POP3 message is using poplib and this just gives you a list of lines > >made up of "bytes as text" :- > > > > popmsg = pop3.retr(i+1) > > Ok, so you have bytes? You need to know. > The documentation says (and it's exactly the same for Python 2 and Python 3):- POP3.retr(which) Retrieve whole message number which, and set its seen flag. Result is in form (response, ['line', ...], octets). Which isn't amazingly explicit unless 'line' implies a string. > >I join the lines to feed them into mailbox.mbox() to create a mbox I > >can analyse and also a message which can be sent using SMTP. > > > >Should I be converting to string somewhere? > > I have not used poplib, but the Python email modules have a BytesParser, > which gets you a Message object; I would feed the poplib bytes to that > to parse the received message. A Message object can then be transcribed > as text via its .as_string method. Or you can do other things with it. > > I think my main points are: > > - know whether you're using bytes (uninterpreted data) or text (strings > of _characters_); treating bytes _as_ text implies an encoding, and > when that assumption is incorrect you get mojibake[1] > > - look at the email modules' parsers, which return Messages, a > representation of the message in a structure (so that MIME subparts > etc are correctly broken out, and the character sets are _known_, post > parse) OK, thanks Cameron. -- Chris Green ? From cl at isbd.net Thu Aug 27 09:48:48 2020 From: cl at isbd.net (Chris Green) Date: Thu, 27 Aug 2020 14:48:48 +0100 Subject: Another 2 to 3 mail encoding problem References: Message-ID: <07qk1h-neu41.ln1@esprimo.zbmc.eu> Richard Damon wrote: > On 8/27/20 4:31 AM, Chris Green wrote: > > While an E-Mail body possibly *shouldn't* have non-ASCII characters in > > it one must be able to handle them without errors. In fact haven't > > the RFCs changed such that the message body should be 8-bit clean? > > Anyway I think the Python 3 mail handling libraries need to be able to > > pass extended characters through without errors. > > Email message a fully allowed to use non-ASCII characters in them as > long as the headers indicate this. They can be encoded either as raw 8 > bit bytes on systems that are 8-bit clean, or for systems that are not, > they will need to be encoded either as base-64 or using quote-printable > encoding. These characters are to interpreted in the character set > defined (or presumed) in the header, or even some other binary object > like and image or executable if the content type isn't text. > > Because of this, the Python 3 str type is not suitable to store an email > message, since it insists on the string being Unicode encoded, but the > Python 2 str class could hold it. > Which sounds like the core of my problem[s]! :-) As I said my system (ignoring the Python issues) is all UTF8 and all seems to work well so I think it's pretty much correctly configured. When I send mail that has accented and other extended characters in it the E-Mail headers have:- Content-Type: text/plain; charset=utf-8 If I save a message like the above sent to myself it's stored using the UTF8 characters directly, I can open it with my text editor (which is also UTF8 aware) and see the characters as I entered them, there's no encoding because my system is 8-bit clean and I'm talking to myself as it were. The above is using Python 2 to handle and filter my incoming mail which, as you say, works fine. However when I try switching to Python 3 I get the errors I've been asking about, even though this is 'talking to myself' and the E-Mail message is just UTF8. -- Chris Green ? From barry at barrys-emacs.org Thu Aug 27 12:16:51 2020 From: barry at barrys-emacs.org (Barry) Date: Thu, 27 Aug 2020 17:16:51 +0100 Subject: Another 2 to 3 mail encoding problem In-Reply-To: <3tak1h-vi041.ln1@esprimo.zbmc.eu> References: <3tak1h-vi041.ln1@esprimo.zbmc.eu> Message-ID: > On 27 Aug 2020, at 10:40, Chris Green wrote: > > ?Karsten Hilbert wrote: >>> Terry Reedy wrote: >>>>> On 8/26/2020 11:10 AM, Chris Green wrote: >>>>> >>>>>> I have a simple[ish] local mbox mail delivery module as follows:- >>>>> ... >>>>>> It has run faultlessly for many years under Python 2. I've now >>>>>> changed the calling program to Python 3 and while it handles most >>>>>> E-Mail OK I have just got the following error:- >>>>>> >>>>>> Traceback (most recent call last): >>>>>> File "/home/chris/.mutt/bin/filter.py", line 102, in >>>>>> mailLib.deliverMboxMsg(dest, msg, log) >>>>> ... >>>>>> File "/usr/lib/python3.8/email/generator.py", line 406, in write >>>>>> self._fp.write(s.encode('ascii', 'surrogateescape')) >>>>>> UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in >>>>> position 4: ordinal not in range(128) I would guess the fix is do s.encode(?utf-8?). You might need to add a header to say that you are using utf-8 to the email/mime-part. If you do that does your code work? Barry >>>>> >>>>> '\ufeff' is the Unicode byte-order mark. It should not be present in an >>>>> ascii-only 3.x string and would not normally be present in general >>>>> unicode except in messages like this that talk about it. Read about it, >>>>> for instance, at >>>>> https://en.wikipedia.org/wiki/Byte_order_mark >>>>> >>>>> I would catch the error and print part or all of string s to see what is >>>>> going on with this particular message. Does it have other non-ascii chars? >>>>> >>> I can provoke the error simply by sending myself an E-Mail with >>> accented characters in it. I'm pretty sure my Linux system is set up >>> correctly for UTF8 characters, I certainly seem to be able to send and >>> receive these to others and I even get to see messages in other >>> scripts such as arabic, chinese, etc. >>> >>> The code above works perfectly in Python 2 delivering messages with >>> accented (and other extended) characters with no problems at all. >>> Sending myself E-Mails with accented characters works OK with the code >>> running under Python 2. >>> >>> While an E-Mail body possibly *shouldn't* have non-ASCII characters in >>> it one must be able to handle them without errors. In fact haven't >>> the RFCs changed such that the message body should be 8-bit clean? >>> Anyway I think the Python 3 mail handling libraries need to be able to >>> pass extended characters through without errors. >> >> Well, '\ufeff' is not a *character* at all in much of any >> sense of that word in unicode. >> >> It's a marker. Whatever puts it into the stream is wrong. I guess the >> best one can (and should) do is to catch the exception and dump >> the offending stream somewhere binary-capable and pass on a notice. What >> you are receiving there very much isn't a (well-formed) e-mail message. >> >> I would then attempt to backwards-crawl the delivery chain to >> find out where it came from. >> > The error seems to occur with any non-7-bit-ASCII, e.g. my accented > characters gave:- > > File "/usr/lib/python3.8/email/generator.py", line 406, in write > self._fp.write(s.encode('ascii', 'surrogateescape')) > UnicodeEncodeError: 'ascii' codec can't encode character > '\u2019' in position 34: ordinal not in > range(128) > > It just happened that the first example was an escape. > > -- > Chris Green > ? > -- > https://mail.python.org/mailman/listinfo/python-list From barry at barrys-emacs.org Thu Aug 27 12:29:54 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 27 Aug 2020 17:29:54 +0100 Subject: Another 2 to 3 mail encoding problem In-Reply-To: References: Message-ID: <9227C0F7-8807-4DB6-BA94-B78230115057@barrys-emacs.org> > On 26 Aug 2020, at 16:10, Chris Green wrote: > > UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in position 4: ordinal not in range(128) > > So what do I need to do to the message I'm adding with mbx.add(msg) to > fix this? (I assume that's what I need to do). >>> import unicodedata >>> unicodedata.name('\ufeff') 'ZERO WIDTH NO-BREAK SPACE' I guess the editor you use to compose the text is adding that to your message. Barry From muskansanghai at gmail.com Thu Aug 27 13:00:16 2020 From: muskansanghai at gmail.com (Muskan Sanghai) Date: Thu, 27 Aug 2020 10:00:16 -0700 (PDT) Subject: Video file to subtitles file Message-ID: <4d9971ca-85bb-453b-80ad-0ad25c761906n@googlegroups.com> I would be really thankful if someone can suggest me how can I generate subtitles file (srt format) from a video or audio without using Google cloud and AWS. From dieter at handshake.de Thu Aug 27 13:51:13 2020 From: dieter at handshake.de (Dieter Maurer) Date: Thu, 27 Aug 2020 19:51:13 +0200 Subject: ABC with abstractmethod: kwargs on Base, explicit names on implementation In-Reply-To: References: Message-ID: <24391.62097.692494.25140@ixdm.fritz.box> Samuel Marks wrote at 2020-8-27 15:58 +1000: >The main thing I want is type safety. I want Python to complain if the >callee uses the wrong argument types, and to provide suggestions on >what's needed and info about it. > >Without a base class I can just have docstrings and type annotations >to achieve that. > >What can I use that will require all implementers to have a minimum of >the same properties and arguments, but also allow them to add new >properties and arguments? A main paradigm of object oriented programming is the ability to use a derived class instance with knowledge only about the base class. This implies that in many cases, you need not know the concrete class because any instance of a derived class must have the essential behavior of the base class instances. This paradigm imposes limitations on the allowable signature changes. An overriding method may add further parameters but all those must have default values - otherwise, the use with base class knowledge only would cause errors. > Preferably I would like this all to happen before compile/interpret time. Use a "lint" version to check compatibilty. From barry at barrys-emacs.org Thu Aug 27 14:57:09 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 27 Aug 2020 19:57:09 +0100 Subject: Video file to subtitles file In-Reply-To: <4d9971ca-85bb-453b-80ad-0ad25c761906n@googlegroups.com> References: <4d9971ca-85bb-453b-80ad-0ad25c761906n@googlegroups.com> Message-ID: > On 27 Aug 2020, at 18:00, Muskan Sanghai wrote: > > I would be really thankful if someone can suggest me how can I generate subtitles file (srt format) from a video or audio without using Google cloud and AWS. What do you know about how subtitles work with video? Do you mean you want to extract the bitmap subtitle data from a MPEG video? Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Thu Aug 27 16:02:32 2020 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 27 Aug 2020 21:02:32 +0100 Subject: Another 2 to 3 mail encoding problem In-Reply-To: <9227C0F7-8807-4DB6-BA94-B78230115057@barrys-emacs.org> References: <9227C0F7-8807-4DB6-BA94-B78230115057@barrys-emacs.org> Message-ID: <2e8e3e77-81ef-8b12-6f50-376804ca09bc@mrabarnett.plus.com> On 2020-08-27 17:29, Barry Scott wrote: > > >> On 26 Aug 2020, at 16:10, Chris Green wrote: >> >> UnicodeEncodeError: 'ascii' codec can't encode character '\ufeff' in position 4: ordinal not in range(128) >> >> So what do I need to do to the message I'm adding with mbx.add(msg) to >> fix this? (I assume that's what I need to do). > >>>> import unicodedata >>>> unicodedata.name('\ufeff') > 'ZERO WIDTH NO-BREAK SPACE' > > I guess the editor you use to compose the text is adding that to your message. > That's used as a BOM (Byte-Order Marker) at the start of UTF16-BE. It's also used at the start of UTF-8-SIG. From cl at isbd.net Thu Aug 27 16:20:28 2020 From: cl at isbd.net (Chris Green) Date: Thu, 27 Aug 2020 21:20:28 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? Message-ID: This sounds quite an easy thing to do but I can't find how to do it elegantly. I have a list of bytes class objects (i.e. a list containing sequences of bytes, which are basically text) and I want to convert it to a list of string objects. One of the difficulties of finding out how to do this is that 'list of bytes' tends to mean a bytes object with a sequence of bytes in it which is *not* what I'm after converting. :-) Obviously I can do:- bbb = [b'aaa', b'bbb', b'ccc'] sss = [] for i in range(0, 2): sss.append(str(bbb[i]) but that does seem a bit clumsy. Is there a better way? -- Chris Green ? From rosuav at gmail.com Thu Aug 27 16:41:25 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Aug 2020 06:41:25 +1000 Subject: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: Message-ID: On Fri, Aug 28, 2020 at 6:36 AM Chris Green wrote: > > This sounds quite an easy thing to do but I can't find how to do it > elegantly. > > I have a list of bytes class objects (i.e. a list containing sequences > of bytes, which are basically text) and I want to convert it to a list > of string objects. > > One of the difficulties of finding out how to do this is that 'list of > bytes' tends to mean a bytes object with a sequence of bytes in it > which is *not* what I'm after converting. :-) > > Obviously I can do:- > > bbb = [b'aaa', b'bbb', b'ccc'] > sss = [] > for i in range(0, 2): > sss.append(str(bbb[i]) > > but that does seem a bit clumsy. Is there a better way? > Firstly, you shouldn't iterate over the range, but over the items themselves: for word in bbb: But this is a really good job for a list comprehension: sss = [str(word) for word in bbb] ChrisA From Marco.Sulla.Python at gmail.com Thu Aug 27 17:54:29 2020 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Thu, 27 Aug 2020 23:54:29 +0200 Subject: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: Message-ID: Are you sure you want `str()`? >>> str(b'aaa') "b'aaa'" Probably you want: map(lambda x: x.decode(), bbb) From cs at cskk.id.au Thu Aug 27 18:09:27 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 28 Aug 2020 08:09:27 +1000 Subject: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: Message-ID: <20200827220927.GA39165@cskk.homeip.net> On 27Aug2020 23:54, Marco Sulla wrote: >Are you sure you want `str()`? > >>>> str(b'aaa') >"b'aaa'" > >Probably you want: > >map(lambda x: x.decode(), bbb) _And_ you need to know the encoding of the text in the bytes. The above _assumes_ UTF-8 because that is the default for bytes.decode, and if that is _not_ what is in the bytes objects you will get mojibake. Because a lot of stuff is "mostly ASCII", this is the kind of bug which can lurk until much later when you have less usual data. Cheers, Cameron Simpson From cs at cskk.id.au Thu Aug 27 18:26:45 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 28 Aug 2020 08:26:45 +1000 Subject: How do I do this in Python 3 (string.join())? In-Reply-To: <1fpk1h-neu41.ln1@esprimo.zbmc.eu> References: <1fpk1h-neu41.ln1@esprimo.zbmc.eu> Message-ID: <20200827222645.GA57785@cskk.homeip.net> On 27Aug2020 14:36, Chris Green wrote: >Cameron Simpson wrote: >> I do ok, though most of my message processing happens to messages >> already landed in my "spool" Maildir by getmail. My setup uses getmail >> to get messages with POP into a single Maildir, and then I process the >> message files from there. >> >Most of my mail is delivered by SMTP, I run a Postfix SMTP *serever* >on my desktop machine which stays on permanently. I run postfix on my machines too, including my laptop, but mostly for sending - it means I can queue messages while offline, and they'll go out later. I don't receive SMTP on my laptop (which is where my mail lives); I receive elsewhere such as the machine hosting my email domain (which also runs postfix), and the various external addresses I have (one for each ISP of course, and a couple of external email addresses such as a GMail one (largely to interact with stuff like Google Groups, which is pretty parochial). So I use getmail to fetch from most of these (GMail just forwards a copy of everything "personal" to my primary address) and deliver to a spool Maildir on my laptop, and the mailfiler processes the spool Maildir. >The POP3 processing is solely to collect E-Mail that ends up in the >'catchall' mailbox on my hosting provider. It empties the POP3 >catchall mailbox, checks for anything that *might* be for me or other >family members then just deletes the rest. Very strong email policy, that one. Personally I fear data loss, and process everything; anything which doesn't match a rule lands in my "UNKNOWN" mail folder for manual consideration when I'm bored. It is largely spam, but sometimes has a message wanting a new filing rule. >> >E.g. in this case the only (well the only ready made) way to get a >> >POP3 message is using poplib and this just gives you a list of lines >> >made up of "bytes as text" :- >> > >> > popmsg = pop3.retr(i+1) >> >> Ok, so you have bytes? You need to know. >> >The documentation says (and it's exactly the same for Python 2 and >Python 3):- > > POP3.retr(which) > Retrieve whole message number which, and set its seen flag. Result > is in form (response, ['line', ...], octets). > >Which isn't amazingly explicit unless 'line' implies a string. Aye. But "print(repr(a_pop_line))" will tell you. Almost certainly a string-of-bytes, so I would expect bytes. The docs are probably unchanged during the Python2->3 move. >> >I join the lines to feed them into mailbox.mbox() to create a mbox I >> >can analyse and also a message which can be sent using SMTP. Ah. I like Maildirs for analysis; every message has its own file, which makes adding and removing messages easy, and avoids contention with other things using the Maildir. My mailfiler can process Maildirs (scan, add, remove) and add to Maildirs and mboxes. Cheers, Cameron Simpson From pynoob76 at gmail.com Thu Aug 27 23:47:20 2020 From: pynoob76 at gmail.com (Py Noob) Date: Thu, 27 Aug 2020 20:47:20 -0700 Subject: Output showing "None" in Terminal In-Reply-To: References: Message-ID: Thank you so much for the help. I'm self-studying and watching tutorials on youTube. The problem was given as an exercise after the tutorial. I did modify my code based on the suggestions here and it helps. Thank you! On Tue, Aug 25, 2020 at 4:31 PM Schachner, Joseph < Joseph.Schachner at teledyne.com> wrote: > The very first line of your function km_mi(): ends it: > def km_mi(): > return answer > > answer has not been assigned, so it returns None. > > Advice: remove that "return" line from there. Also get rid of the last > line, answer = km_mi which makes answer refer to the function km_mi(). > Put the "return answer" line at the end, where the "answer=km_mi" used to > be. > > That should help. The code calculates "answer". It prints "answer". > You should return "answer" at the end, after it has been calculated. > > --- Joseph S. > > -----Original Message----- > From: Py Noob > Sent: Monday, August 24, 2020 9:12 AM > To: python-list at python.org > Subject: Output showing "None" in Terminal > > Hi! > > i'm new to python and would like some help with something i was working on > from a tutorial. I'm using VScode with 3.7.0 version on Windows 7. Below is > my code and the terminal is showing the word "None" everytime I execute my > code. > > Many thanks! > > print("Conversion") > > def km_mi(): > return answer > > selection = input("Type mi for miles or km for kilometers: ") > > if selection == "mi": > n = int(input(print("Please enter distance in miles: "))) > answer = (1.6*n) > print("%.2f" % answer, "miles") > > else: > n = float(input(print("Please enter distance in kilometers: "))) > answer = (n/1.6) > print("%.2f" % answer, "kilometers") > > answer = km_mi > > From Karsten.Hilbert at gmx.net Fri Aug 28 03:25:00 2020 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Fri, 28 Aug 2020 09:25:00 +0200 Subject: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: <20200827220927.GA39165@cskk.homeip.net> References: <20200827220927.GA39165@cskk.homeip.net> Message-ID: > >Are you sure you want `str()`? > > > >>>> str(b'aaa') > >"b'aaa'" > > > >Probably you want: > > > >map(lambda x: x.decode(), bbb) > > _And_ you need to know the encoding of the text in the bytes. The above > _assumes_ UTF-8 because that is the default for bytes.decode, and if > that is _not_ what is in the bytes objects you will get mojibake. > > Because a lot of stuff is "mostly ASCII", this is the kind of bug which > can lurk until much later when you have less usual data. As I said, crawl the delivery chain looking for where things come from (and what they are). Karsten From cl at isbd.net Fri Aug 28 03:52:14 2020 From: cl at isbd.net (Chris Green) Date: Fri, 28 Aug 2020 08:52:14 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: Message-ID: Chris Angelico wrote: > On Fri, Aug 28, 2020 at 6:36 AM Chris Green wrote: > > > > This sounds quite an easy thing to do but I can't find how to do it > > elegantly. > > > > I have a list of bytes class objects (i.e. a list containing sequences > > of bytes, which are basically text) and I want to convert it to a list > > of string objects. > > > > One of the difficulties of finding out how to do this is that 'list of > > bytes' tends to mean a bytes object with a sequence of bytes in it > > which is *not* what I'm after converting. :-) > > > > Obviously I can do:- > > > > bbb = [b'aaa', b'bbb', b'ccc'] > > sss = [] > > for i in range(0, 2): > > sss.append(str(bbb[i]) > > > > but that does seem a bit clumsy. Is there a better way? > > > > Firstly, you shouldn't iterate over the range, but over the items themselves: > > for word in bbb: > Yes, of course, it was just a 'quick and dirty' to make the point. > But this is a really good job for a list comprehension: > > sss = [str(word) for word in bbb] > That seems the way to do it, thanks. -- Chris Green ? From cl at isbd.net Fri Aug 28 03:50:10 2020 From: cl at isbd.net (Chris Green) Date: Fri, 28 Aug 2020 08:50:10 +0100 Subject: How do I do this in Python 3 (string.join())? References: <1fpk1h-neu41.ln1@esprimo.zbmc.eu> <20200827222645.GA57785@cskk.homeip.net> Message-ID: Cameron Simpson wrote: [snip] > > >The POP3 processing is solely to collect E-Mail that ends up in the > >'catchall' mailbox on my hosting provider. It empties the POP3 > >catchall mailbox, checks for anything that *might* be for me or other > >family members then just deletes the rest. > > Very strong email policy, that one. Personally I fear data loss, and > process everything; anything which doesn't match a rule lands in my > "UNKNOWN" mail folder for manual consideration when I'm bored. It is > largely spam, but sometimes has a message wanting a new filing rule. > It's not *that* strong, the catchall is for *anything* that is addressed to either of the two domains hosted there. I.e. mail for xhghjhwd at isbd.net will arrive in the catchall mailbox. So I just search the To: address for anything that might be a typo for one of our names or anything else that might be of interest. I have an associated configuration file that specifies the patterns to look for so I can change things on the fly as it were. One of the scripts that I'm having trouble converting to Python 3 is the one that does this catchall management. > >> >E.g. in this case the only (well the only ready made) way to get a > >> >POP3 message is using poplib and this just gives you a list of lines > >> >made up of "bytes as text" :- > >> > > >> > popmsg = pop3.retr(i+1) > >> > >> Ok, so you have bytes? You need to know. > >> > >The documentation says (and it's exactly the same for Python 2 and > >Python 3):- > > > > POP3.retr(which) > > Retrieve whole message number which, and set its seen flag. Result > > is in form (response, ['line', ...], octets). > > > >Which isn't amazingly explicit unless 'line' implies a string. > > Aye. But "print(repr(a_pop_line))" will tell you. Almost certainly a > string-of-bytes, so I would expect bytes. The docs are probably > unchanged during the Python2->3 move. > Yes, I added some print statments to my catchall script to find out and, yes, the returned value is a list of 'byte strings'. It's a pity there isn't a less ambiguous name for 'string-of-bytes'! :-) > >> >I join the lines to feed them into mailbox.mbox() to create a mbox I > >> >can analyse and also a message which can be sent using SMTP. > > Ah. I like Maildirs for analysis; every message has its own file, which > makes adding and removing messages easy, and avoids contention with > other things using the Maildir. > > My mailfiler can process Maildirs (scan, add, remove) and add to > Maildirs and mboxes. > I've switched to maildir several times in the past and have always switched back because they have so many 'standards'. I use mutt as my MUA and that does handle maildir as well as anything but still doesn't do it for me. :-) -- Chris Green ? From cl at isbd.net Fri Aug 28 04:02:09 2020 From: cl at isbd.net (Chris Green) Date: Fri, 28 Aug 2020 09:02:09 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: <20200827220927.GA39165@cskk.homeip.net> Message-ID: <19qm1h-51591.ln1@esprimo.zbmc.eu> Cameron Simpson wrote: > On 27Aug2020 23:54, Marco Sulla wrote: > >Are you sure you want `str()`? > > > >>>> str(b'aaa') > >"b'aaa'" > > > >Probably you want: > > > >map(lambda x: x.decode(), bbb) > > _And_ you need to know the encoding of the text in the bytes. The above > _assumes_ UTF-8 because that is the default for bytes.decode, and if > that is _not_ what is in the bytes objects you will get mojibake. > > Because a lot of stuff is "mostly ASCII", this is the kind of bug which > can lurk until much later when you have less usual data. > If there's an encoding given in the header of the incoming E-Mail then one (hopefully) knows what the encoding is. However you have to be able to handle the more general case where either the encoding isn't given or it's wrong. In the real world E-Mail survives having an incorrect encoding in the header, what you see is either missing or garbled characters with the remainder being OK. Garbling the whole lot isn't a good approach. -- Chris Green ? From cl at isbd.net Fri Aug 28 03:56:26 2020 From: cl at isbd.net (Chris Green) Date: Fri, 28 Aug 2020 08:56:26 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: Message-ID: Stefan Ram wrote: > Chris Angelico writes: > >But this is a really good job for a list comprehension: > >sss = [str(word) for word in bbb] > > Are you all sure that "str" is really what you all want? > Not absolutely, you no doubt have been following other threads related to this one. :-) > |>>> b = b"b" > |>>> str( b ) > |"b'b'" > > Maybe try to /decode/ the bytes? > > |>>> b.decode( "ASCII" ) > |'b' > > Therein lies the problem, the incoming byte stream *isn't* ASCII, it's an E-Mail message which may, for example, have UTF-8 or other encoded characters in it. Hopefully it will have an encoding given in the header but that's only if the sender is 'well behaved', one needs to be able to handle almost anything and it must be done without 'manual' interaction. -- Chris Green ? From Gronicus at SGA.Ninja Fri Aug 28 06:03:15 2020 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 28 Aug 2020 06:03:15 -0400 Subject: How do I place a preset into the text box? Message-ID: <013101d67d22$72e55300$58aff900$@SGA.Ninja> The following program compiles but does not quite do what I would like it to do. Line 19 is the preset information but I do not seem to be able to get it into the form by code. My purpose is to let the user make changes without having to re-enter the entire code. Suggestions welcome. Steve #=========================================================== import tkinter as tk from tkinter import ttk import sys window = tk.Tk() window.title("Python Tkinter Text Box") window.minsize(600,400) def Submit(): label.configure(text= 'The new code is: ' + NewCode.get()) def ClickExit(): #This exit closes the program but the form remains and is still active. # I want only to close the form. print("Exiting") sys.exit() OldCode = ("1234-abcd") label = ttk.Label(window, text = "Enter the new code") label.grid(column = 1, row = 1) NewCode = tk.StringVar() CodeEntered = ttk.Entry(window, width = 15, textvariable = NewCode) CodeEntered.grid(column = 2, row = 3) button = ttk.Button(window, text = "Submit", command = Submit) button.grid(column= 2, row = 5) button = ttk.Button(window, text = "Quit", command = ClickExit) button.grid(column= 2, row = 7) window.mainloop() x = (NewCode.get()) print("The new code entered is: " + x) #================================================= Footnote: Mars is the only known planet in our solar system solely inhabited by functioning robots. From cs at cskk.id.au Fri Aug 28 05:09:22 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 28 Aug 2020 19:09:22 +1000 Subject: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: Message-ID: <20200828090922.GA67165@cskk.homeip.net> On 28Aug2020 08:56, Chris Green wrote: >Stefan Ram wrote: >> Chris Angelico writes: >> >But this is a really good job for a list comprehension: >> >sss = [str(word) for word in bbb] >> >> Are you all sure that "str" is really what you all want? >> >Not absolutely, you no doubt have been following other threads related >to this one. :-) It is almost certainly not what you want. You want some flavour of bytes.decode. If the BytesParser doesn't cope, you may need to parse the headers as some kind of text (eg ISO8859-1) until you find a content-transfer-encoding header (which still applies only to the body, not the headers). >> |>>> b = b"b" >> |>>> str( b ) >> |"b'b'" >> >> Maybe try to /decode/ the bytes? >> >> |>>> b.decode( "ASCII" ) >> |'b' >> >> >Therein lies the problem, the incoming byte stream *isn't* ASCII, it's >an E-Mail message which may, for example, have UTF-8 or other encoded >characters in it. Hopefully it will have an encoding given in the >header but that's only if the sender is 'well behaved', one needs to >be able to handle almost anything and it must be done without 'manual' >interaction. POP3 is presumably handing you bytes containing a message. If the Python email.BytesParser doesn't handle it, stash the raw bytes _elsewhere_ in a distinct file in some directory. with open('evil_msg_bytes', 'wb') as f: for bs in bbb: f.write(bs) No interpreation requires, since parsing failed. Then you can start dealing with these exceptions. _Do not_ write unparsable messages into an mbox! Cheers, Cameron Simpson From cl at isbd.net Fri Aug 28 07:26:07 2020 From: cl at isbd.net (Chris Green) Date: Fri, 28 Aug 2020 12:26:07 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > On 28Aug2020 08:56, Chris Green wrote: > >Stefan Ram wrote: > >> Chris Angelico writes: > >> >But this is a really good job for a list comprehension: > >> >sss = [str(word) for word in bbb] > >> > >> Are you all sure that "str" is really what you all want? > >> > >Not absolutely, you no doubt have been following other threads related > >to this one. :-) > > It is almost certainly not what you want. You want some flavour of > bytes.decode. If the BytesParser doesn't cope, you may need to parse the > headers as some kind of text (eg ISO8859-1) until you find a > content-transfer-encoding header (which still applies only to the body, > not the headers). > > >> |>>> b = b"b" > >> |>>> str( b ) > >> |"b'b'" > >> > >> Maybe try to /decode/ the bytes? > >> > >> |>>> b.decode( "ASCII" ) > >> |'b' > >> > >> > >Therein lies the problem, the incoming byte stream *isn't* ASCII, it's > >an E-Mail message which may, for example, have UTF-8 or other encoded > >characters in it. Hopefully it will have an encoding given in the > >header but that's only if the sender is 'well behaved', one needs to > >be able to handle almost anything and it must be done without 'manual' > >interaction. > > POP3 is presumably handing you bytes containing a message. If the Python > email.BytesParser doesn't handle it, stash the raw bytes _elsewhere_ in > a distinct file in some directory. > > with open('evil_msg_bytes', 'wb') as f: > for bs in bbb: > f.write(bs) > > No interpreation requires, since parsing failed. Then you can start > dealing with these exceptions. _Do not_ write unparsable messages into > an mbox! > Maybe I shouldn't but Python 2 has been managing to do so for several years without any issues. I know I *could* put the exceptions in a bucket somewhere and deal with them separately but I'd really rather not. At prsent (with the Python 2 code still installed) it all 'just works' and the absolute worst corruption I ever see in an E-Mail is things like accented characters missing altogether or ? signs coming out as a funny looking string. Either of these don't really make the message unintelligible. Are we saying that Python 3 really can't be made to handle things 'tolerantly' like Python 2 used to? -- Chris Green ? From colin.mcphail at mac.com Fri Aug 28 07:46:25 2020 From: colin.mcphail at mac.com (Colin McPhail) Date: Fri, 28 Aug 2020 12:46:25 +0100 Subject: How do I place a preset into the text box? In-Reply-To: <013101d67d22$72e55300$58aff900$@SGA.Ninja> References: <013101d67d22$72e55300$58aff900$@SGA.Ninja> Message-ID: <5A3B8770-20C2-47E0-B0E7-0FF493AA4262@mac.com> Hi Steve, > On 28 Aug 2020, at 11:03, Steve wrote: > > > The following program compiles but does not quite do what I would like it to > do. Line 19 is the preset information but I do not seem to be able to get it > into the form by code. My purpose is to let the user make changes without > having to re-enter the entire code. I'm no Tk expert but does the following do what you want? (Strictly speaking, the parentheses in ("1234-abcd") are not wrong just unnecessary.) #=========================================================== import tkinter as tk from tkinter import ttk import sys window = tk.Tk() window.title("Python Tkinter Text Box") window.minsize(600,400) def Submit(): label.configure(text= 'The new code is: ' + NewCode.get()) def ClickExit(): #This exit closes the program but the form remains and is still active. # I want only to close the form. print("Exiting") #sys.exit() window.destroy() #OldCode = ("1234-abcd") OldCode = "1234-abcd" label = ttk.Label(window, text = "Enter the new code") label.grid(column = 1, row = 1) #NewCode = tk.StringVar() NewCode = tk.StringVar(value=OldCode) CodeEntered = ttk.Entry(window, width = 15, textvariable = NewCode) CodeEntered.grid(column = 2, row = 3) button = ttk.Button(window, text = "Submit", command = Submit) button.grid(column= 2, row = 5) button = ttk.Button(window, text = "Quit", command = ClickExit) button.grid(column= 2, row = 7) window.mainloop() x = (NewCode.get()) print("The new code entered is: " + x) #================================================= Regards, Colin From HooDunnit at didly42KahZidly.net Fri Aug 28 07:46:31 2020 From: HooDunnit at didly42KahZidly.net (Cousin Stanley) Date: Fri, 28 Aug 2020 04:46:31 -0700 Subject: How do I place a preset into the text box? References: <013101d67d22$72e55300$58aff900$@SGA.Ninja> Message-ID: Steve wrote: > The following program compiles but does not quite do what I would like it to > do. Line 19 is the preset information but I do not seem to be able to get it > into the form by code. My purpose is to let the user make changes without > having to re-enter the entire code. > .... You might consider moving the entry get() function into the Submit() call back .... def Submit() : label.configure( text = 'The new code is : ' + NewCode.get() ) x = ( NewCode.get() ) print( "\n The new code entered is : " + x ) The following insert function will show the OldCode in the entry box .... OldCode = ( "1234-abcd" ) # .... CodeEntered = ttk.Entry( window , width = 15 , textvariable = NewCode ) CodeEntered.grid( column = 2 , row = 3 , pady = 10 ) CodeEntered.insert( 0 , OldCode ) -- Stanley C. Kitching Human Being Phoenix, Arizona From Karsten.Hilbert at gmx.net Fri Aug 28 07:50:07 2020 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Fri, 28 Aug 2020 13:50:07 +0200 Subject: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: > > No interpreation requires, since parsing failed. Then you can start > > dealing with these exceptions. _Do not_ write unparsable messages into > > an mbox! > > > Maybe I shouldn't but Python 2 has been managing to do so for several > years without any issues. I am inclined to congratulate you on that sheer amount of luck. I don't believe there were no issues because everything worked just right under py2 but rather because py2 cared less than py3 does now. > Are we saying that Python 3 really can't be made to handle things > 'tolerantly' like Python 2 used to? It sure should be possible but it will require *explicit* en/decode()s in more places than before because AFAICT there's less impliciteness as to which encoding to apply (regardless of whether it applies). Karsten From Richard at Damon-Family.org Fri Aug 28 08:21:09 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 28 Aug 2020 08:21:09 -0400 Subject: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: On 8/28/20 7:50 AM, Karsten Hilbert wrote: >>> No interpreation requires, since parsing failed. Then you can start >>> dealing with these exceptions. _Do not_ write unparsable messages into >>> an mbox! >>> >> Maybe I shouldn't but Python 2 has been managing to do so for several >> years without any issues. > I am inclined to congratulate you on that sheer amount of luck. I don't > believe there were no issues because everything worked just right under > py2 but rather because py2 cared less than py3 does now. > >> Are we saying that Python 3 really can't be made to handle things >> 'tolerantly' like Python 2 used to? > It sure should be possible but it will require *explicit* en/decode()s in > more places than before because AFAICT there's less impliciteness as to > which encoding to apply (regardless of whether it applies). > > Karsten > > > -- Richard Damon From Richard at Damon-Family.org Fri Aug 28 08:30:53 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 28 Aug 2020 08:30:53 -0400 Subject: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: <9baec6d4-e2bd-0b89-1cc6-56104daa21c3@Damon-Family.org> On 8/28/20 7:50 AM, Karsten Hilbert wrote: >>> No interpreation requires, since parsing failed. Then you can start >>> dealing with these exceptions. _Do not_ write unparsable messages into >>> an mbox! >>> >> Maybe I shouldn't but Python 2 has been managing to do so for several >> years without any issues. > I am inclined to congratulate you on that sheer amount of luck. I don't > believe there were no issues because everything worked just right under > py2 but rather because py2 cared less than py3 does now. > >> Are we saying that Python 3 really can't be made to handle things >> 'tolerantly' like Python 2 used to? > It sure should be possible but it will require *explicit* en/decode()s in > more places than before because AFAICT there's less impliciteness as to > which encoding to apply (regardless of whether it applies). > > Karsten > > > This might be one of the cases where Python 2's lack handling of string vs bytes was an advantage. If he was just scanning the message for specific ASCII strings, then not getting the full message decoded write is unlikely to have been causing problems. Python2 handled that sort of case quite easily. Python 3 on the other hand, will have issue converting the byte message to a string, since there isn't a single encoding that you could use for all of it all the time. This being 'fussier' does make sure that the program is handling all the text 'properly', and would be helpful if some of the patterns being checked for contained 'extended' (non-ASCII) characters. One possible solution in Python3 is to decode the byte string using an encoding that allows all 256 byte values, so it won't raise any encoding errors, just give your possibly non-sense characters for non-ASCII text. -- Richard Damon From rosuav at gmail.com Fri Aug 28 08:34:48 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Aug 2020 22:34:48 +1000 Subject: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: <9baec6d4-e2bd-0b89-1cc6-56104daa21c3@Damon-Family.org> References: <20200828090922.GA67165@cskk.homeip.net> <9baec6d4-e2bd-0b89-1cc6-56104daa21c3@Damon-Family.org> Message-ID: On Fri, Aug 28, 2020 at 10:32 PM Richard Damon wrote: > > This might be one of the cases where Python 2's lack handling of string > vs bytes was an advantage. > > If he was just scanning the message for specific ASCII strings, then not > getting the full message decoded write is unlikely to have been causing > problems. > > Python2 handled that sort of case quite easily. Python 3 on the other > hand, will have issue converting the byte message to a string, since > there isn't a single encoding that you could use for all of it all the > time. This being 'fussier' does make sure that the program is handling > all the text 'properly', and would be helpful if some of the patterns > being checked for contained 'extended' (non-ASCII) characters. > > One possible solution in Python3 is to decode the byte string using an > encoding that allows all 256 byte values, so it won't raise any encoding > errors, just give your possibly non-sense characters for non-ASCII text. Why? If you want to work with bytes, work with bytes. There's no reason to decode in a meaningless way. Python 3 can handle the job of searching a bytestring for ASCII text just fine. Also, if you're parsing an email message, you can and should be doing so with respect to the encoding(s) stipulated in the headers, after which you will have valid Unicode text. Please don't spread misinformation like this. ChrisA From cl at isbd.net Fri Aug 28 08:39:32 2020 From: cl at isbd.net (Chris Green) Date: Fri, 28 Aug 2020 13:39:32 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: <20200828090922.GA67165@cskk.homeip.net> <9baec6d4-e2bd-0b89-1cc6-56104daa21c3@Damon-Family.org> Message-ID: <4han1h-q06a1.ln1@esprimo.zbmc.eu> Richard Damon wrote: > On 8/28/20 7:50 AM, Karsten Hilbert wrote: > >>> No interpreation requires, since parsing failed. Then you can start > >>> dealing with these exceptions. _Do not_ write unparsable messages into > >>> an mbox! > >>> > >> Maybe I shouldn't but Python 2 has been managing to do so for several > >> years without any issues. > > I am inclined to congratulate you on that sheer amount of luck. I don't > > believe there were no issues because everything worked just right under > > py2 but rather because py2 cared less than py3 does now. > > > >> Are we saying that Python 3 really can't be made to handle things > >> 'tolerantly' like Python 2 used to? > > It sure should be possible but it will require *explicit* en/decode()s in > > more places than before because AFAICT there's less impliciteness as to > > which encoding to apply (regardless of whether it applies). > > > > Karsten > > > > > > > This might be one of the cases where Python 2's lack handling of string > vs bytes was an advantage. > > If he was just scanning the message for specific ASCII strings, then not > getting the full message decoded write is unlikely to have been causing > problems. > > Python2 handled that sort of case quite easily. Python 3 on the other > hand, will have issue converting the byte message to a string, since > there isn't a single encoding that you could use for all of it all the > time. This being 'fussier' does make sure that the program is handling > all the text 'properly', and would be helpful if some of the patterns > being checked for contained 'extended' (non-ASCII) characters. > > One possible solution in Python3 is to decode the byte string using an > encoding that allows all 256 byte values, so it won't raise any encoding > errors, just give your possibly non-sense characters for non-ASCII text. > But this will simply get some things quite wrong and produce garbage won't it? Whereas Python 2 would simply scramble the odd character. -- Chris Green ? From cl at isbd.net Fri Aug 28 08:44:54 2020 From: cl at isbd.net (Chris Green) Date: Fri, 28 Aug 2020 13:44:54 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: Message-ID: <6ran1h-q06a1.ln1@esprimo.zbmc.eu> Stefan Ram wrote: > Chris Green writes: > >Therein lies the problem, the incoming byte stream *isn't* ASCII, it's > >an E-Mail message which may, for example, have UTF-8 or other encoded > >characters in it. Hopefully it will have an encoding given in the > >header but that's only if the sender is 'well behaved', one needs to > >be able to handle almost anything and it must be done without 'manual' > >interaction. > > I would make a difference between "scoring" and "transport": > > To transfer a message into an mbox it can be transferred as it is. > Just the bytes from the POP3 server. Let mutt deal with them. > That's what I do at present in Python 2, the problem is that Python 3 complains when I use the standard library to put the message into the mbox. I want to transport the message into my mbox and Python 3 won't do it without knowing how it's encoded whereas Python 2 just stuffed it in there 'as is'. I want Python 3's mailbox class to juyst put what I tell it (even if mis-formatted or mis-encoded) into the mbox. -- Chris Green ? From rosuav at gmail.com Fri Aug 28 08:54:05 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Aug 2020 22:54:05 +1000 Subject: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: <4han1h-q06a1.ln1@esprimo.zbmc.eu> References: <20200828090922.GA67165@cskk.homeip.net> <9baec6d4-e2bd-0b89-1cc6-56104daa21c3@Damon-Family.org> <4han1h-q06a1.ln1@esprimo.zbmc.eu> Message-ID: On Fri, Aug 28, 2020 at 10:51 PM Chris Green wrote: > > > One possible solution in Python3 is to decode the byte string using an > > encoding that allows all 256 byte values, so it won't raise any encoding > > errors, just give your possibly non-sense characters for non-ASCII text. > > > But this will simply get some things quite wrong and produce garbage > won't it? Whereas Python 2 would simply scramble the odd character. > It would. Don't do that. Either keep it as bytes, or decode it using the correct encoding. ChrisA From Richard at Damon-Family.org Fri Aug 28 09:15:19 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 28 Aug 2020 09:15:19 -0400 Subject: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: <4han1h-q06a1.ln1@esprimo.zbmc.eu> References: <20200828090922.GA67165@cskk.homeip.net> <9baec6d4-e2bd-0b89-1cc6-56104daa21c3@Damon-Family.org> <4han1h-q06a1.ln1@esprimo.zbmc.eu> Message-ID: On 8/28/20 8:39 AM, Chris Green wrote: > Richard Damon wrote: >> On 8/28/20 7:50 AM, Karsten Hilbert wrote: >>>>> No interpreation requires, since parsing failed. Then you can start >>>>> dealing with these exceptions. _Do not_ write unparsable messages into >>>>> an mbox! >>>>> >>>> Maybe I shouldn't but Python 2 has been managing to do so for several >>>> years without any issues. >>> I am inclined to congratulate you on that sheer amount of luck. I don't >>> believe there were no issues because everything worked just right under >>> py2 but rather because py2 cared less than py3 does now. >>> >>>> Are we saying that Python 3 really can't be made to handle things >>>> 'tolerantly' like Python 2 used to? >>> It sure should be possible but it will require *explicit* en/decode()s in >>> more places than before because AFAICT there's less impliciteness as to >>> which encoding to apply (regardless of whether it applies). >>> >>> Karsten >>> >>> >>> >> This might be one of the cases where Python 2's lack handling of string >> vs bytes was an advantage. >> >> If he was just scanning the message for specific ASCII strings, then not >> getting the full message decoded write is unlikely to have been causing >> problems. >> >> Python2 handled that sort of case quite easily. Python 3 on the other >> hand, will have issue converting the byte message to a string, since >> there isn't a single encoding that you could use for all of it all the >> time. This being 'fussier' does make sure that the program is handling >> all the text 'properly', and would be helpful if some of the patterns >> being checked for contained 'extended' (non-ASCII) characters. >> >> One possible solution in Python3 is to decode the byte string using an >> encoding that allows all 256 byte values, so it won't raise any encoding >> errors, just give your possibly non-sense characters for non-ASCII text. >> > But this will simply get some things quite wrong and produce garbage > won't it? Whereas Python 2 would simply scramble the odd character. > Yes, when the message has extended characters, it will put the 'wrong' characters into the message, but if you are only looking for a fixed set of ASCII strings, especially in the headers of the message, that doesn't matter, those will still be there. It is a pragmatic short cut, something that is 'good enough' to get the job done, even if not 100% correct. As was elsewhere mentioned, you could also do at least most of the processing as bytes (this may need converting some of the strings being uses to bytes), but I don't know exactly what they are doing, so don't know if there is something that really needs a string. Basically, mail messages are complicated, and to 'properly' convert a message into a format for proper analysis would be significant work (and the result would NOT be a simple string), but it sounds like they didn't need that level of work with the messages. Particually if they only need to process the headers, and are working to try to 'whitelist' files to get them, being close and simple is likely good enough, -- Richard Damon From Karsten.Hilbert at gmx.net Fri Aug 28 09:19:18 2020 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Fri, 28 Aug 2020 15:19:18 +0200 Subject: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: <6ran1h-q06a1.ln1@esprimo.zbmc.eu> References: <6ran1h-q06a1.ln1@esprimo.zbmc.eu> Message-ID: > I want to transport the message into my mbox and Python 3 won't do it > without knowing how it's encoded whereas Python 2 just stuffed it in > there 'as is'. > > I want Python 3's mailbox class to juyst put what I tell it (even if > mis-formatted or mis-encoded) into the mbox. I guess using the mailbox class already implies that you do _not_ want to "simply put the msgs into an mbox file" but rather want the class to do what it was designed for: "put proper msgs properly into an mbox file". We can't have it both ways I fear. If we simply want to stuff a file with bytes and call that mbox we should do so: drop the bytes into a file and call it an mbox file. Karsten From cl at isbd.net Fri Aug 28 09:05:58 2020 From: cl at isbd.net (Chris Green) Date: Fri, 28 Aug 2020 14:05:58 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: <20200828090922.GA67165@cskk.homeip.net> <9baec6d4-e2bd-0b89-1cc6-56104daa21c3@Damon-Family.org> Message-ID: Chris Angelico wrote: > > Also, if you're parsing an email message, you can and should be doing > so with respect to the encoding(s) stipulated in the headers, after > which you will have valid Unicode text. > But not all E-Mail messages are 'well behaved', the above works fine if the headers specify the correct text encoding but quite often one will get messages with no encoding specified and also one gets messages with the wrong encoding specified. One needs a way to handle these 'rogue' messages such that most of the characters come out right. -- Chris Green ? From darcy at VybeNetworks.com Fri Aug 28 09:36:50 2020 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 28 Aug 2020 09:36:50 -0400 Subject: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: <9baec6d4-e2bd-0b89-1cc6-56104daa21c3@Damon-Family.org> References: <20200828090922.GA67165@cskk.homeip.net> <9baec6d4-e2bd-0b89-1cc6-56104daa21c3@Damon-Family.org> Message-ID: On 2020-08-28 08:30, Richard Damon wrote: > This might be one of the cases where Python 2's lack handling of string > vs bytes was an advantage. For English speaking Americans. > Python2 handled that sort of case quite easily. Python 3 on the other > hand, will have issue converting the byte message to a string, since > there isn't a single encoding that you could use for all of it all the > time. This being 'fussier' does make sure that the program is handling > all the text 'properly', and would be helpful if some of the patterns > being checked for contained 'extended' (non-ASCII) characters. > > One possible solution in Python3 is to decode the byte string using an > encoding that allows all 256 byte values, so it won't raise any encoding > errors, just give your possibly non-sense characters for non-ASCII text. Or simply handle the errors in the way that makes sense for your requirements. Check the section on error handling here: https://www.askpython.com/python/string/python-encode-and-decode-functions -- D'Arcy J.M. Cain Vybe Networks Inc. A unit of Excelsior Solutions Corporation - Propelling Business Forward http://www.VybeNetworks.com/ IM:darcy at VybeNetworks.com VoIP: sip:darcy at VybeNetworks.com -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 228 bytes Desc: OpenPGP digital signature URL: From rosuav at gmail.com Fri Aug 28 09:44:34 2020 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 28 Aug 2020 23:44:34 +1000 Subject: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: <20200828090922.GA67165@cskk.homeip.net> <9baec6d4-e2bd-0b89-1cc6-56104daa21c3@Damon-Family.org> Message-ID: On Fri, Aug 28, 2020 at 11:24 PM Chris Green wrote: > > Chris Angelico wrote: > > > > Also, if you're parsing an email message, you can and should be doing > > so with respect to the encoding(s) stipulated in the headers, after > > which you will have valid Unicode text. > > > But not all E-Mail messages are 'well behaved', the above works fine > if the headers specify the correct text encoding but quite often one > will get messages with no encoding specified and also one gets > messages with the wrong encoding specified. One needs a way to handle > these 'rogue' messages such that most of the characters come out right. > As D'Arcy posted, this is what the error handling is for. If you want to decode in a "sloppy" way such that mis-encoded text can be partially decoded, then that's what you want to do - decode with a sloppy error handler. Don't abuse arbitrary eight bit encodings in the hope that it'll do a better job just because it doesn't spit out any exceptions. ChrisA From Richard at Damon-Family.org Fri Aug 28 10:09:18 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 28 Aug 2020 10:09:18 -0400 Subject: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: <6ran1h-q06a1.ln1@esprimo.zbmc.eu> References: <6ran1h-q06a1.ln1@esprimo.zbmc.eu> Message-ID: On 8/28/20 8:44 AM, Chris Green wrote: > Stefan Ram wrote: >> Chris Green writes: >>> Therein lies the problem, the incoming byte stream *isn't* ASCII, it's >>> an E-Mail message which may, for example, have UTF-8 or other encoded >>> characters in it. Hopefully it will have an encoding given in the >>> header but that's only if the sender is 'well behaved', one needs to >>> be able to handle almost anything and it must be done without 'manual' >>> interaction. >> I would make a difference between "scoring" and "transport": >> >> To transfer a message into an mbox it can be transferred as it is. >> Just the bytes from the POP3 server. Let mutt deal with them. >> > That's what I do at present in Python 2, the problem is that Python 3 > complains when I use the standard library to put the message into the > mbox. > > I want to transport the message into my mbox and Python 3 won't do it > without knowing how it's encoded whereas Python 2 just stuffed it in > there 'as is'. > > I want Python 3's mailbox class to juyst put what I tell it (even if > mis-formatted or mis-encoded) into the mbox. > It looks like the mailbox class has gotten 'pickier' in Python 3, and won't accept a message as a byte string, just as either a email message or a real string. My guess would be that 'simplest' path would be to convert your message into a parsed Message class, and add that. -- Richard Damon From sshivlal9601 at gmail.com Fri Aug 28 10:06:22 2020 From: sshivlal9601 at gmail.com (Shivlal Sharma) Date: Fri, 28 Aug 2020 07:06:22 -0700 (PDT) Subject: Didn't understand the output of the following Python 3 code with reduce function? Message-ID: <36482fd7-f1c2-4ded-89f1-a949bcbbc83an@googlegroups.com> I have seen this code on one of competative programming site but I didn't get it, Why output is 9? from functools import * def ADDS(a,b): return a+1 nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] add = reduce(ADDS, nums) print(add) output: 9 From David.Raymond at tomtom.com Fri Aug 28 10:25:49 2020 From: David.Raymond at tomtom.com (David Raymond) Date: Fri, 28 Aug 2020 14:25:49 +0000 Subject: Didn't understand the output of the following Python 3 code with reduce function? In-Reply-To: <36482fd7-f1c2-4ded-89f1-a949bcbbc83an@googlegroups.com> References: <36482fd7-f1c2-4ded-89f1-a949bcbbc83an@googlegroups.com> Message-ID: All the numbers in the nums list don't matter and aren't used. Only the first number, and how many there are. https://docs.python.org/3.8/library/functools.html#functools.reduce Basically it's doing ADDS(1, 2) which returns 2 that 2 gets fed back into ADDS(2, 3) which returns 3 that 3 gets fed back into ADDS(3, 4) which returns 4 ... ADDS(8, 9) which returns 9 > I have seen this code on one of competative programming site but I didn't get it, Why output is 9? > > from functools import * > > def ADDS(a,b): > return a+1 > nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > add = reduce(ADDS, nums) > print(add) > > output: 9 From __peter__ at web.de Fri Aug 28 10:44:04 2020 From: __peter__ at web.de (Peter Otten) Date: Fri, 28 Aug 2020 16:44:04 +0200 Subject: Didn't understand the output of the following Python 3 code with reduce function? References: <36482fd7-f1c2-4ded-89f1-a949bcbbc83an@googlegroups.com> Message-ID: Shivlal Sharma wrote: > I have seen this code on one of competative programming site but I didn't > get it, Why output is 9? > > from functools import * > > def ADDS(a,b): > return a+1 > nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > add = reduce(ADDS, nums) > print(add) > > output: 9 Rewrite the ADDS() function like so >>> def ADDS(a, b): ... result = a + 1 ... print(f"ADDS({a}, {b}) --> {result}") ... return result ... to see what's going on: >>> reduce(ADDS, [1,2,3,4,5,6,7,8,9]) ADDS(1, 2) --> 2 ADDS(2, 3) --> 3 ADDS(3, 4) --> 4 ADDS(4, 5) --> 5 ADDS(5, 6) --> 6 ADDS(6, 7) --> 7 ADDS(7, 8) --> 8 ADDS(8, 9) --> 9 9 ADDS is called with the first two values, then with the first result (first value + 1) and the third value then the second result ((first value + 1) + 1) and the fourth value... This can be written recursively as ADDS(ADDS(ADDS(ADDS(ADDS(ADDS(ADDS(ADDS(1, 2), 3), 4), 5), 6), 7), 8), 9) As the second argument is always discarded we get the first a=1 eight times incremented by one, i.e 9. To drive the point home that we always get first item + (len(items) -1): >>> reduce(ADDS, [42,"a","b","c","d"]) ADDS(42, a) --> 43 ADDS(43, b) --> 44 ADDS(44, c) --> 45 ADDS(45, d) --> 46 46 From muskansanghai at gmail.com Fri Aug 28 12:30:01 2020 From: muskansanghai at gmail.com (Muskan Sanghai) Date: Fri, 28 Aug 2020 09:30:01 -0700 (PDT) Subject: Video file to subtitles file In-Reply-To: References: <4d9971ca-85bb-453b-80ad-0ad25c761906n@googlegroups.com> Message-ID: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> On Friday, August 28, 2020 at 12:27:25 AM UTC+5:30, Barry Scott wrote: > > On 27 Aug 2020, at 18:00, Muskan Sanghai wrote: > > > > I would be really thankful if someone can suggest me how can I generate subtitles file (srt format) from a video or audio without using Google cloud and AWS. > What do you know about how subtitles work with video? Do you mean you want to extract the bitmap subtitle data from a MPEG video? > > Barry > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Thank you Barry for your reply, I just know the basics and I want to extract subtitles from a MPEG video and then put the subtitles in that same video. Subtitles can be of any format but it should be convenient for the entire procedure. From barry at barrys-emacs.org Fri Aug 28 13:07:14 2020 From: barry at barrys-emacs.org (Barry) Date: Fri, 28 Aug 2020 18:07:14 +0100 Subject: Video file to subtitles file In-Reply-To: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> Message-ID: > On 28 Aug 2020, at 17:37, Muskan Sanghai wrote: > > ?On Friday, August 28, 2020 at 12:27:25 AM UTC+5:30, Barry Scott wrote: >>>> On 27 Aug 2020, at 18:00, Muskan Sanghai wrote: >>> >>> I would be really thankful if someone can suggest me how can I generate subtitles file (srt format) from a video or audio without using Google cloud and AWS. >> What do you know about how subtitles work with video? Do you mean you want to extract the bitmap subtitle data from a MPEG video? >> >> Barry >> >> >> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> > > Thank you Barry for your reply, > I just know the basics and I want to extract subtitles from a MPEG video and then put the subtitles in that same video. Subtitles can be of any format but it should be convenient for the entire procedure. It seems you are looking for an App to do this work? I searched the web and saw this. https://www.openshot.org/ I have not used this app, maybe it?s a starting point for you. Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Fri Aug 28 13:29:02 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Aug 2020 03:29:02 +1000 Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> Message-ID: On Sat, Aug 29, 2020 at 3:24 AM Barry wrote: > > > > > On 28 Aug 2020, at 17:37, Muskan Sanghai wrote: > > > > ?On Friday, August 28, 2020 at 12:27:25 AM UTC+5:30, Barry Scott wrote: > >>>> On 27 Aug 2020, at 18:00, Muskan Sanghai wrote: > >>> > >>> I would be really thankful if someone can suggest me how can I generate subtitles file (srt format) from a video or audio without using Google cloud and AWS. > >> What do you know about how subtitles work with video? Do you mean you want to extract the bitmap subtitle data from a MPEG video? > >> > >> Barry > >> > >> > >> > >>> -- > >>> https://mail.python.org/mailman/listinfo/python-list > >>> > > > > Thank you Barry for your reply, > > I just know the basics and I want to extract subtitles from a MPEG video and then put the subtitles in that same video. Subtitles can be of any format but it should be convenient for the entire procedure. > > It seems you are looking for an App to do this work? > I searched the web and saw this. > > https://www.openshot.org/ > > I have not used this app, maybe it?s a starting point for you. > > Barry > Not familiar with Openshot, but it's worth looking into. Alternatively, I'd definitely recommend ffmpeg for anything like this sort of job. But if you actually need to OCR something, then you may need to do some scripting work. I don't have code to offer you, but it would involve FFMPEG to lift the images, something like Tesseract to do the actual OCRing, and then you'd write the rest of it yourself in Python. Other than that, this probably is something best done with a dedicated movie editing tool, not Python. Use what exists. ChrisA From Gronicus at SGA.Ninja Fri Aug 28 15:51:34 2020 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 28 Aug 2020 15:51:34 -0400 Subject: How do I place a preset into the text box? In-Reply-To: References: <013101d67d22$72e55300$58aff900$@SGA.Ninja> Message-ID: <017d01d67d74$a2b11180$e8133480$@SGA.Ninja> Works like a charm, special thanks. Steve ===================================================== Footnote: He called his wife to see if he should pick up Fish and Chips on the way home. She hung up on him. She is still fuming over letting him name the kids. -----Original Message----- From: Python-list On Behalf Of Cousin Stanley Sent: Friday, August 28, 2020 7:47 AM To: python-list at python.org Subject: Re: How do I place a preset into the text box? Steve wrote: > The following program compiles but does not quite do what I would like > it to do. Line 19 is the preset information but I do not seem to be > able to get it into the form by code. My purpose is to let the user > make changes without having to re-enter the entire code. > .... You might consider moving the entry get() function into the Submit() call back .... def Submit() : label.configure( text = 'The new code is : ' + NewCode.get() ) x = ( NewCode.get() ) print( "\n The new code entered is : " + x ) The following insert function will show the OldCode in the entry box .... OldCode = ( "1234-abcd" ) # .... CodeEntered = ttk.Entry( window , width = 15 , textvariable = NewCode ) CodeEntered.grid( column = 2 , row = 3 , pady = 10 ) CodeEntered.insert( 0 , OldCode ) -- Stanley C. Kitching Human Being Phoenix, Arizona -- https://mail.python.org/mailman/listinfo/python-list From Gronicus at SGA.Ninja Fri Aug 28 15:51:34 2020 From: Gronicus at SGA.Ninja (Steve) Date: Fri, 28 Aug 2020 15:51:34 -0400 Subject: How do I place a preset into the text box? In-Reply-To: <5A3B8770-20C2-47E0-B0E7-0FF493AA4262@mac.com> References: <013101d67d22$72e55300$58aff900$@SGA.Ninja> <5A3B8770-20C2-47E0-B0E7-0FF493AA4262@mac.com> Message-ID: <017801d67d74$a28d0ec0$e7a72c40$@SGA.Ninja> Yes, the form/window now closes properly. Removal of sys.exit() and inserting window.destroy() cleared up the exiting problem. Thanks. I saw several variations on that but I guess I just never twerked it enough. Footnote: "What rhymes with orange?" "No it doesn't.." From: Colin McPhail Sent: Friday, August 28, 2020 7:46 AM To: Chris Narkiewicz via Python-list Cc: Steve Subject: Re: How do I place a preset into the text box? Hi Steve, On 28 Aug 2020, at 11:03, Steve > wrote: The following program compiles but does not quite do what I would like it to do. Line 19 is the preset information but I do not seem to be able to get it into the form by code. My purpose is to let the user make changes without having to re-enter the entire code. I'm no Tk expert but does the following do what you want? (Strictly speaking, the parentheses in ("1234-abcd") are not wrong just unnecessary.) #=========================================================== import tkinter as tk from tkinter import ttk import sys window = tk.Tk() window.title("Python Tkinter Text Box") window.minsize(600,400) def Submit(): label.configure(text= 'The new code is: ' + NewCode.get()) def ClickExit(): #This exit closes the program but the form remains and is still active. # I want only to close the form. print("Exiting") #sys.exit() window.destroy() #OldCode = ("1234-abcd") OldCode = "1234-abcd" label = ttk.Label(window, text = "Enter the new code") label.grid(column = 1, row = 1) #NewCode = tk.StringVar() NewCode = tk.StringVar(value=OldCode) CodeEntered = ttk.Entry(window, width = 15, textvariable = NewCode) CodeEntered.grid(column = 2, row = 3) button = ttk.Button(window, text = "Submit", command = Submit) button.grid(column= 2, row = 5) button = ttk.Button(window, text = "Quit", command = ClickExit) button.grid(column= 2, row = 7) window.mainloop() x = (NewCode.get()) print("The new code entered is: " + x) #================================================= Regards, Colin From cs at cskk.id.au Fri Aug 28 16:39:54 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 29 Aug 2020 06:39:54 +1000 Subject: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: Message-ID: <20200828203954.GA90277@cskk.homeip.net> On 28Aug2020 12:26, Chris Green wrote: >Cameron Simpson wrote: >> POP3 is presumably handing you bytes containing a message. If the >> Python >> email.BytesParser doesn't handle it, stash the raw bytes _elsewhere_ in >> a distinct file in some directory. >> >> with open('evil_msg_bytes', 'wb') as f: >> for bs in bbb: >> f.write(bs) >> >> No interpreation requires, since parsing failed. Then you can start >> dealing with these exceptions. _Do not_ write unparsable messages into >> an mbox! >> >Maybe I shouldn't but Python 2 has been managing to do so for several >years without any issues. I know I *could* put the exceptions in a >bucket somewhere and deal with them separately but I'd really rather >not. > >At prsent (with the Python 2 code still installed) it all 'just works' >and the absolute worst corruption I ever see in an E-Mail is things >like accented characters missing altogether or ? signs coming out as a >funny looking string. Either of these don't really make the message >unintelligible. > >Are we saying that Python 3 really can't be made to handle things >'tolerantly' like Python 2 used to? It can, but if you're decoding bytes to strings without the correct encoding then rubbish will be happening. In Python 2 also, it just isn't being flagged. One approach would be to break your parser process up: - collect bytes from POP3 - parse headers for filtering purposes - those you keep, append to the mbox _as bytes_ It sounds like your filter is uninterested in the message body, so you don't need to decode it at all. Just ensure the bod has no embedded lines with b'From ' at the start, and ensure the last line ends in a newline b'\n' or that you append one, so that the b'From ' of the next message is recognised. So: collect bytes, decode ehaders and parse/filter, save _bytes_. Cheers, Cameron Simpson From ben.usenet at bsb.me.uk Fri Aug 28 17:17:36 2020 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Fri, 28 Aug 2020 22:17:36 +0100 Subject: Didn't understand the output of the following Python 3 code with reduce function? References: <36482fd7-f1c2-4ded-89f1-a949bcbbc83an@googlegroups.com> Message-ID: <87y2lyv5an.fsf@bsb.me.uk> Shivlal Sharma writes: > I have seen this code on one of competative programming site but I > didn't get it, Why output is 9? > > from functools import * > > def ADDS(a,b): > return a+1 > nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > add = reduce(ADDS, nums) > print(add) > > output: 9 Hint: reduce(f, [e1, e2]) is f(e1, e2) reduce(f, [e1, e2, e3]) is f(f(e1, e2), e3) reduce(f, [e1, e2, e3, e4]) is f(f(f(e1, e2), e3), e4) Replace f with a function that adds one to its first argument. Does that help? -- Ben. From debchat1955 at gmail.com Fri Aug 28 19:38:03 2020 From: debchat1955 at gmail.com (Debasis Chatterjee) Date: Fri, 28 Aug 2020 18:38:03 -0500 Subject: Fwd: Issue in installing Python (Windows 10) In-Reply-To: References: Message-ID: ---------- Forwarded message --------- From: Debasis Chatterjee Date: Fri, Aug 28, 2020 at 3:41 AM Subject: Re: Issue in installing Python (Windows 10) To: Terry Reedy Hi Terry, OK. I think the issue is now solved. I used "pip uninstall" and then "pip install". With that I can run Python programs that use the installed packages. By the way, is there a site where I can login to see such mails and also manage mail notification options? The same as https://python-forum.io/member.php ? Or another one? Thank you Debasis On Wed, Aug 26, 2020 at 5:03 PM Debasis Chatterjee wrote: > Hi Terry, > > I still have the issue. I took help from my company's IT Admin and > deinstalled everything and then made fresh installation. > > Still have issues the packages. > > Such as we need SEGYIO in the program. Program fails to find that. > > When I try to add using "pip" then I get this message. > > C:\Users\debasisc>pip install segyio > Defaulting to user installation because normal site-packages is not > writeable > Requirement already satisfied: segyio in > c:\users\debasisc\appdata\roaming\python\python38\site-packages (1.9.1) > Requirement already satisfied: numpy>=1.10 in > c:\users\debasisc\appdata\roaming\python\python38\site-packages (from > segyio) (1.19.1) > WARNING: You are using pip version 20.1.1; however, version 20.2.2 is > available. > You should consider upgrading via the 'c:\program files > (x86)\python38-32\python.exe -m pip install --upgrade pip' command. > > What do you suggest for troubleshooting? > > Thank you > > Debasis > > On Mon, Aug 24, 2020 at 3:19 PM Terry Reedy wrote: > >> On 8/23/2020 12:39 PM, Debasis Chatterjee wrote: >> >> > I started off by using "python-3.8.5.exe". >> >> 32-bit Windows installer? Windows version might be relevant. >> >> > I use "Run as Administrator" option to click this (provide my >> local-admin >> > username/pwd). >> >> > After this, I see python shell available. But no IDLE. Not sure why? >> >> You mean no IDLE entry on Python 3.8 directory on Start menu? >> >> Installer has a checkbox for tkinter and IDLE. It is on by default for >> a fresh install but I expect it defaults to previous install for >> reinstalls. >> >> On a command line, run 'python -c "import tkinter' to see if you have >> tkinter. 'python -m idlelib' starts IDLE if present. >> >> > From CMD, I can check "pip list". Surprisingly, it shows me packages >> that I >> > installed earlier, before deinstalling and reinstalling. >> >> De-installing does not remove pythonxy directory if you add anything to >> it. >> >> > Something is not right. Hence I am trying to make a fresh restart. >> > >> > One thing odd is that even after removing installed program (Python) >> from >> > control panel, I still find that from "Start". >> >> Have you installed more than one version of Python? Or both 32 and 64 >> bit variation of same Python version? >> >> >> -- >> Terry Jan Reedy >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Aug 28 23:10:29 2020 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 28 Aug 2020 22:10:29 -0500 Subject: Fwd: Issue in installing Python (Windows 10) In-Reply-To: References: Message-ID: <20200829031029.GK3788@scrozzle> On 2020-08-28 at 18:38:03 -0500, Debasis Chatterjee wrote: > By the way, is there a site where I can login to see such mails and > also manage mail notification options? Better than that, you can have the emails themselves delivered directly to your inbox: https://mail.python.org/mailman/listinfo/python-list From sshivlal9601 at gmail.com Sat Aug 29 03:55:56 2020 From: sshivlal9601 at gmail.com (Shivlal Sharma) Date: Sat, 29 Aug 2020 00:55:56 -0700 (PDT) Subject: Didn't understand the output of the following Python 3 code with reduce function? In-Reply-To: <87y2lyv5an.fsf@bsb.me.uk> References: <36482fd7-f1c2-4ded-89f1-a949bcbbc83an@googlegroups.com> <87y2lyv5an.fsf@bsb.me.uk> Message-ID: <13ee5a57-58fd-47fd-b666-30c9829df91en@googlegroups.com> On Saturday, 29 August 2020 at 02:47:56 UTC+5:30, Ben Bacarisse wrote: Thanks you all, I was really confused in this code. > Shivlal Sharma writes: > > > I have seen this code on one of competative programming site but I > > didn't get it, Why output is 9? > > > > from functools import * > > > > def ADDS(a,b): > > return a+1 > > nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > > add = reduce(ADDS, nums) > > print(add) > > > > output: 9 > Hint: > > reduce(f, [e1, e2]) is f(e1, e2) > reduce(f, [e1, e2, e3]) is f(f(e1, e2), e3) > reduce(f, [e1, e2, e3, e4]) is f(f(f(e1, e2), e3), e4) > > Replace f with a function that adds one to its first argument. Does > that help? > > -- > Ben. From sshivlal9601 at gmail.com Sat Aug 29 03:58:32 2020 From: sshivlal9601 at gmail.com (Shivlal Sharma) Date: Sat, 29 Aug 2020 00:58:32 -0700 (PDT) Subject: Error in lambda function..! Message-ID: from functools import* nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] add = reduce(lambda a : a + 1, nums) print(add) error: - TypeError Traceback (most recent call last) in () 1 from functools import* 2 nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] ----> 3 add = reduce(lambda a : a + 1, nums) 4 print(add) TypeError: () takes 1 positional argument but 2 were given From __peter__ at web.de Sat Aug 29 04:59:12 2020 From: __peter__ at web.de (Peter Otten) Date: Sat, 29 Aug 2020 10:59:12 +0200 Subject: Error in lambda function..! References: Message-ID: Shivlal Sharma wrote: > from functools import* > nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > add = reduce(lambda a : a + 1, nums) > print(add) > > error: - > TypeError Traceback (most recent call > last) in () > 1 from functools import* > 2 nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > ----> 3 add = reduce(lambda a : a + 1, nums) > 4 print(add) > > TypeError: () takes 1 positional argument but 2 were given Read the error message: your lambda accepts ony one argument, but reduce tries to pass two to it. That you don't need the second argument doesn't mean that you can it omit it, so: >>> from functools import reduce >>> reduce(lambda a, b: a + 1, range(1, 10)) 9 From rob.cliffe at btinternet.com Sat Aug 29 05:02:30 2020 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Sat, 29 Aug 2020 10:02:30 +0100 Subject: Error in lambda function..! In-Reply-To: References: Message-ID: <38e78497-cf5d-d3ff-06f4-3dffd9e1563c@btinternet.com> On 29/08/2020 08:58, Shivlal Sharma wrote: > from functools import* > nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > add = reduce(lambda a : a + 1, nums) > print(add) > > error: - > TypeError Traceback (most recent call last) > in () > 1 from functools import* > 2 nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] > ----> 3 add = reduce(lambda a : a + 1, nums) > 4 print(add) > > TypeError: () takes 1 positional argument but 2 were given When you write ??? lambda a : you are defining a function that takes **one** argument, viz. a. It's the same as if you wrote: ??? def myfunc(a): return a+1 and then ??? add = reduce(myfunc, nums) But reduce always calls your supplied function with **two** arguments.? Hence the error. I don't know exactly what you are trying to do, but if you wrote ??? add = reduce(lambda a,b: a+1, nums) or equivalently ??? def myfunc(a,b): return a+1 ??? add = reduce(myfunc, nums) reduce would call your lambda function succesively with arguments ??? (1,2)??? # which would return 1+1 i.e. 2 ??? (2,3) ?? # use previous result (2) and next number in the sequence (3); returns 2+1 i.e. 3 ??? (3,4) ?? # use previous result (3) and next number in the sequence (4) ??? ..... ? ? (8,9)??? # returns 8+! i.e. 9 and finally 9 would be printed. If you want to watch what is happening try ??? def myfunc(a,b): ??? ??? print(f"Myfunc({a},{b})") ??? ??? return a+1 ??? add = reduce(myfunc, nums) Try ??? from functools import * ??? help(reduce) for an explanation of how reduce works.? Note that the first sentence starts "Apply a function of two arguments" Best wishes Rob Cliffe From samuelmarks at gmail.com Sat Aug 29 05:14:54 2020 From: samuelmarks at gmail.com (Samuel Marks) Date: Sat, 29 Aug 2020 19:14:54 +1000 Subject: ABC with abstractmethod: kwargs on Base, explicit names on implementation In-Reply-To: <24391.62097.692494.25140@ixdm.fritz.box> References: <24391.62097.692494.25140@ixdm.fritz.box> Message-ID: So there is no way to get a AOT error when the two functions aren't implemented, if the two functions have different required arguments on implementors? To paint this picture for why I need this, say the first is: class Base(ABC): @abstractclass def train(self, epochs): asset epochs is not None and epochs > 0 ?and the implementation is: class TensorFlow(Base): def train(self, learning_rate, epochs, callbacks, metrics, loss, optimizer): super(Base, self).__init__(epochs=epochs) [+ docstrings and PEP484 types; excluded here for concision] So how do I enable this use-case? - Obviously it doesn't make sense to include these on the base class, and giving them default values probably doesn't make sense either. You're saying I shouldn't be using ABC for this. So what should I be using? The requirement I'm trying to enforce is that each implementor has a `train` callable attached. Preferably with one required field (but this is just a nice-to-have). BTW: I have enabled an argument inheritance use-case through creating a library with the builtin `ast` module. So now you can have `def train_c(self, config)` with config referring to an instance of a class which inherits from a base config class. See here for the implementation https://github.com/SamuelMarks/doctrans However if I only have functions which accept an instance of a class as the argument, then that will make it less user-friendly to the API caller. So I really am looking for handling both interfaces in a straightforward manner. Thanks for your suggestions, Samuel Marks Charity | consultancy | open-source | LinkedIn On Fri, Aug 28, 2020 at 3:51 AM Dieter Maurer wrote: > > Samuel Marks wrote at 2020-8-27 15:58 +1000: > >The main thing I want is type safety. I want Python to complain if the > >callee uses the wrong argument types, and to provide suggestions on > >what's needed and info about it. > > > >Without a base class I can just have docstrings and type annotations > >to achieve that. > > > >What can I use that will require all implementers to have a minimum of > >the same properties and arguments, but also allow them to add new > >properties and arguments? > > A main paradigm of object oriented programming is the > ability to use a derived class instance with knowledge only > about the base class. This implies that in many cases, you > need not know the concrete class because any instance of a derived > class must have the essential behavior of the base class instances. > > This paradigm imposes limitations on the allowable signature changes. > An overriding method may add further parameters but all those > must have default values - otherwise, the use with base class knowledge > only would cause errors. > > > Preferably I would like this all to happen before compile/interpret > time. > > Use a "lint" version to check compatibilty. From dieter at handshake.de Sat Aug 29 06:24:30 2020 From: dieter at handshake.de (Dieter Maurer) Date: Sat, 29 Aug 2020 12:24:30 +0200 Subject: ABC with abstractmethod: kwargs on Base, explicit names on implementation In-Reply-To: References: <24391.62097.692494.25140@ixdm.fritz.box> Message-ID: <24394.11486.102386.8586@ixdm.fritz.box> Samuel Marks wrote at 2020-8-29 19:14 +1000: >So there is no way to get a AOT error when the two functions aren't >implemented, if the two functions have different required arguments on >implementors? > >To paint this picture for why I need this, say the first is: > >class Base(ABC): > @abstractclass > def train(self, epochs): > asset epochs is not None and epochs > 0 > >?and the implementation is: > >class TensorFlow(Base): > def train(self, learning_rate, epochs, callbacks, metrics, loss, optimizer): > super(Base, self).__init__(epochs=epochs) > >[+ docstrings and PEP484 types; excluded here for concision] > >So how do I enable this use-case? - Obviously it doesn't make sense to >include these on the base class, and giving them default values >probably doesn't make sense either. > >You're saying I shouldn't be using ABC for this. So what should I be using? What is your purpose to use a base class in the first place -- and especially one where `train` has this signature? You signal with this base class, that it makes sense to call `train` with a single positional argument. But `train` in the derived class cannot be called in this way. Base classes are there to capture common features of several related classes. In your example above, this is not the case. Do not use base classes in this way. >The requirement I'm trying to enforce is that each implementor has a >`train` callable attached. >Preferably with one required field (but this is just a nice-to-have). Read the Python documentation about metaclasses and the special methods related to class derivation. Both approaches would allow you to check whatever you want. > ... >However if I only have functions which accept an instance of a class >as the argument, then that will make it less user-friendly to the API >caller. So I really am looking for handling both interfaces in a >straightforward manner. Any system makes some things easy and other things difficult. Try to stay with the essential paradigms underlaying the system -- in order to use the easy things whenever possible. In your case, this means that the signature of an overriding method must be quite similar to that of the overridden method. From samuelmarks at gmail.com Sat Aug 29 06:46:19 2020 From: samuelmarks at gmail.com (Samuel Marks) Date: Sat, 29 Aug 2020 20:46:19 +1000 Subject: ABC with abstractmethod: kwargs on Base, explicit names on implementation In-Reply-To: <24394.11486.102386.8586@ixdm.fritz.box> References: <24391.62097.692494.25140@ixdm.fritz.box> <24394.11486.102386.8586@ixdm.fritz.box> Message-ID: Putting Liskov substitution principal to one side, I had a suggestion to follow PEP3102, and do `def train(self, *, epochs):`? It's a rather simple suggestion that I just might take aboard. In response to Dieter: My purpose for using a base class is so that the highest level interface?say a CLI, GUI, REST and RPC API?can all be configured in one place, but enable the greatest possible divergence from a parameter standpoint. An alternative here [in this domain] would be to create a new Keras/scikit.learn. I.e., one consistent interface that is to be implemented in full by each framework. The reason I don't want to take this alternative is manyfold, that I don't need to get in here (happy to start a new thread if you're interested). Two major advantages of this approach are: 0. Implementers can be [pretty much] as divergent as they want, with different default and required parameters; and even semantics [though I do have `assert`s to force `method0` to be executed before `method1`]; 1. Implementers don't need to create their own CLIs, GUIs, REST and RPC APIs Two major disadvantages: 0. Parameters aren't known ahead of time, so you can do the whole `Animal` [duck type] trick where `Animal` could actually be `Dog` or `Horse` [making the obvious Base `ABC` & `abstractmethod` approach 'wrong'] 1. Each implementer framework can maintain wildly different internal APIs, making more hardcore integrations?in a multi-ML sense?far more difficult Samuel Marks Charity | consultancy | open-source | LinkedIn On Sat, Aug 29, 2020 at 8:24 PM Dieter Maurer wrote: > > Samuel Marks wrote at 2020-8-29 19:14 +1000: > >So there is no way to get a AOT error when the two functions aren't > >implemented, if the two functions have different required arguments on > >implementors? > > > >To paint this picture for why I need this, say the first is: > > > >class Base(ABC): > > @abstractclass > > def train(self, epochs): > > asset epochs is not None and epochs > 0 > > > >?and the implementation is: > > > >class TensorFlow(Base): > > def train(self, learning_rate, epochs, callbacks, metrics, loss, optimizer): > > super(Base, self).__init__(epochs=epochs) > > > >[+ docstrings and PEP484 types; excluded here for concision] > > > >So how do I enable this use-case? - Obviously it doesn't make sense to > >include these on the base class, and giving them default values > >probably doesn't make sense either. > > > >You're saying I shouldn't be using ABC for this. So what should I be using? > > What is your purpose to use a base class in the first place -- > and especially one where `train` has this signature? > > You signal with this base class, that it makes sense to > call `train` with a single positional argument. > But `train` in the derived class cannot be called in this way. > > Base classes are there to capture common features of several > related classes. In your example above, this is not the case. > Do not use base classes in this way. > > >The requirement I'm trying to enforce is that each implementor has a > >`train` callable attached. > >Preferably with one required field (but this is just a nice-to-have). > > Read the Python documentation about metaclasses and the special methods > related to class derivation. Both approaches would allow you > to check whatever you want. > > > ... > >However if I only have functions which accept an instance of a class > >as the argument, then that will make it less user-friendly to the API > >caller. So I really am looking for handling both interfaces in a > >straightforward manner. > > Any system makes some things easy and other things difficult. > Try to stay with the essential paradigms underlaying the system -- > in order to use the easy things whenever possible. > > In your case, this means that the signature of an overriding > method must be quite similar to that of the overridden method. From muskansanghai at gmail.com Sat Aug 29 07:02:27 2020 From: muskansanghai at gmail.com (Muskan Sanghai) Date: Sat, 29 Aug 2020 04:02:27 -0700 (PDT) Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> Message-ID: On Friday, August 28, 2020 at 10:52:57 PM UTC+5:30, Barry wrote: > > On 28 Aug 2020, at 17:37, Muskan Sanghai wrote: > > > > On Friday, August 28, 2020 at 12:27:25 AM UTC+5:30, Barry Scott wrote: > >>>> On 27 Aug 2020, at 18:00, Muskan Sanghai wrote: > >>> > >>> I would be really thankful if someone can suggest me how can I generate subtitles file (srt format) from a video or audio without using Google cloud and AWS. > >> What do you know about how subtitles work with video? Do you mean you want to extract the bitmap subtitle data from a MPEG video? > >> > >> Barry > >> > >> > >> > >>> -- > >>> https://mail.python.org/mailman/listinfo/python-list > >>> > > > > Thank you Barry for your reply, > > I just know the basics and I want to extract subtitles from a MPEG video and then put the subtitles in that same video. Subtitles can be of any format but it should be convenient for the entire procedure. > It seems you are looking for an App to do this work? > I searched the web and saw this. > > https://www.openshot.org/ > > I have not used this app, maybe it?s a starting point for you. > > Barry > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > I actually want to create an app or website which can do this. From muskansanghai at gmail.com Sat Aug 29 07:51:20 2020 From: muskansanghai at gmail.com (Muskan Sanghai) Date: Sat, 29 Aug 2020 04:51:20 -0700 (PDT) Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> Message-ID: <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> On Friday, August 28, 2020 at 10:59:29 PM UTC+5:30, Chris Angelico wrote: > On Sat, Aug 29, 2020 at 3:24 AM Barry wrote: > > > > > > > > > On 28 Aug 2020, at 17:37, Muskan Sanghai wrote: > > > > > > On Friday, August 28, 2020 at 12:27:25 AM UTC+5:30, Barry Scott wrote: > > >>>> On 27 Aug 2020, at 18:00, Muskan Sanghai wrote: > > >>> > > >>> I would be really thankful if someone can suggest me how can I generate subtitles file (srt format) from a video or audio without using Google cloud and AWS. > > >> What do you know about how subtitles work with video? Do you mean you want to extract the bitmap subtitle data from a MPEG video? > > >> > > >> Barry > > >> > > >> > > >> > > >>> -- > > >>> https://mail.python.org/mailman/listinfo/python-list > > >>> > > > > > > Thank you Barry for your reply, > > > I just know the basics and I want to extract subtitles from a MPEG video and then put the subtitles in that same video. Subtitles can be of any format but it should be convenient for the entire procedure. > > > > It seems you are looking for an App to do this work? > > I searched the web and saw this. > > > > https://www.openshot.org/ > > > > I have not used this app, maybe it?s a starting point for you. > > > > Barry > > > Not familiar with Openshot, but it's worth looking into. > Alternatively, I'd definitely recommend ffmpeg for anything like this > sort of job. But if you actually need to OCR something, then you may > need to do some scripting work. I don't have code to offer you, but it > would involve FFMPEG to lift the images, something like Tesseract to > do the actual OCRing, and then you'd write the rest of it yourself in > Python. > > Other than that, this probably is something best done with a dedicated > movie editing tool, not Python. Use what exists. > > ChrisA I want to extract subtitles from a MPEG video (which does not have any previous subtitles) and then add them to the same video . So is it possible to do it with some scripting. Actually I tried to find the same features in FFMPEG but couldn't. From barry at barrys-emacs.org Sat Aug 29 09:14:11 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Sat, 29 Aug 2020 14:14:11 +0100 Subject: Video file to subtitles file In-Reply-To: <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> Message-ID: <6C814672-0C80-4AB8-8AEF-3D8F9463F585@barrys-emacs.org> > On 29 Aug 2020, at 12:51, Muskan Sanghai wrote: > > On Friday, August 28, 2020 at 10:59:29 PM UTC+5:30, Chris Angelico wrote: >> On Sat, Aug 29, 2020 at 3:24 AM Barry > wrote: >>> >>> >>> >>>> On 28 Aug 2020, at 17:37, Muskan Sanghai wrote: >>>> >>>> On Friday, August 28, 2020 at 12:27:25 AM UTC+5:30, Barry Scott wrote: >>>>>>> On 27 Aug 2020, at 18:00, Muskan Sanghai wrote: >>>>>> >>>>>> I would be really thankful if someone can suggest me how can I generate subtitles file (srt format) from a video or audio without using Google cloud and AWS. >>>>> What do you know about how subtitles work with video? Do you mean you want to extract the bitmap subtitle data from a MPEG video? >>>>> >>>>> Barry >>>>> >>>>> >>>>> >>>>>> -- >>>>>> https://mail.python.org/mailman/listinfo/python-list >>>>>> >>>> >>>> Thank you Barry for your reply, >>>> I just know the basics and I want to extract subtitles from a MPEG video and then put the subtitles in that same video. Subtitles can be of any format but it should be convenient for the entire procedure. >>> >>> It seems you are looking for an App to do this work? >>> I searched the web and saw this. >>> >>> https://www.openshot.org/ >>> >>> I have not used this app, maybe it?s a starting point for you. >>> >>> Barry >>> >> Not familiar with Openshot, but it's worth looking into. >> Alternatively, I'd definitely recommend ffmpeg for anything like this >> sort of job. But if you actually need to OCR something, then you may >> need to do some scripting work. I don't have code to offer you, but it >> would involve FFMPEG to lift the images, something like Tesseract to >> do the actual OCRing, and then you'd write the rest of it yourself in >> Python. >> >> Other than that, this probably is something best done with a dedicated >> movie editing tool, not Python. Use what exists. >> >> ChrisA > I want to extract subtitles from a MPEG video (which does not have any previous subtitles) If it has no subtitles there is nothing to extract? > and then add them to the same video . > So is it possible to do it with some scripting. Actually I tried to find the same features in FFMPEG but couldn't. ffmpreg I doubt has the APIs you need for this. Have a look at GStreamer, which has pytohn APIs. I know it can handle subtitles because the company I used to work for paid for subtitle support to be added to GStreamer for a product I worked on a few years ago. I recall that in MPEG subtitles are RLE encoded bitmaps with timing and position data. Which allows the player to show this bitmap at position X, Y starting at T0 and remove at t1 etc. You have to track multiple subtitles at the same time. You should be able to extract the subtitle bit maps and timing data with modest work. You could use OCR technology to turn the subtitles into text. Barry > -- > https://mail.python.org/mailman/listinfo/python-list From muskansanghai at gmail.com Sat Aug 29 09:27:14 2020 From: muskansanghai at gmail.com (Muskan Sanghai) Date: Sat, 29 Aug 2020 06:27:14 -0700 (PDT) Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <6C814672-0C80-4AB8-8AEF-3D8F9463F585@barrys-emacs.org> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> Message-ID: <7a991bb5-70bf-453b-8ec3-dbf1ba8416aan@googlegroups.com> On Saturday, August 29, 2020 at 6:44:34 PM UTC+5:30, Barry Scott wrote: > > On 29 Aug 2020, at 12:51, Muskan Sanghai wrote: > > > > On Friday, August 28, 2020 at 10:59:29 PM UTC+5:30, Chris Angelico wrote: > >> On Sat, Aug 29, 2020 at 3:24 AM Barry > wrote: > >>> > >>> > >>> > >>>> On 28 Aug 2020, at 17:37, Muskan Sanghai wrote: > >>>> > >>>> On Friday, August 28, 2020 at 12:27:25 AM UTC+5:30, Barry Scott wrote: > >>>>>>> On 27 Aug 2020, at 18:00, Muskan Sanghai wrote: > >>>>>> > >>>>>> I would be really thankful if someone can suggest me how can I generate subtitles file (srt format) from a video or audio without using Google cloud and AWS. > >>>>> What do you know about how subtitles work with video? Do you mean you want to extract the bitmap subtitle data from a MPEG video? > >>>>> > >>>>> Barry > >>>>> > >>>>> > >>>>> > >>>>>> -- > >>>>>> https://mail.python.org/mailman/listinfo/python-list > >>>>>> > >>>> > >>>> Thank you Barry for your reply, > >>>> I just know the basics and I want to extract subtitles from a MPEG video and then put the subtitles in that same video. Subtitles can be of any format but it should be convenient for the entire procedure. > >>> > >>> It seems you are looking for an App to do this work? > >>> I searched the web and saw this. > >>> > >>> https://www.openshot.org/ > >>> > >>> I have not used this app, maybe it?s a starting point for you. > >>> > >>> Barry > >>> > >> Not familiar with Openshot, but it's worth looking into. > >> Alternatively, I'd definitely recommend ffmpeg for anything like this > >> sort of job. But if you actually need to OCR something, then you may > >> need to do some scripting work. I don't have code to offer you, but it > >> would involve FFMPEG to lift the images, something like Tesseract to > >> do the actual OCRing, and then you'd write the rest of it yourself in > >> Python. > >> > >> Other than that, this probably is something best done with a dedicated > >> movie editing tool, not Python. Use what exists. > >> > >> ChrisA > > I want to extract subtitles from a MPEG video (which does not have any previous subtitles) > If it has no subtitles there is nothing to extract? > > and then add them to the same video . > > So is it possible to do it with some scripting. Actually I tried to find the same features in FFMPEG but couldn't. > ffmpreg I doubt has the APIs you need for this. > > Have a look at GStreamer, which has pytohn APIs. I know it can handle subtitles because the company > I used to work for paid for subtitle support to be added to GStreamer for a product > I worked on a few years ago. > > I recall that in MPEG subtitles are RLE encoded bitmaps with timing and position data. > Which allows the player to show this bitmap at position X, Y starting at T0 and remove at t1 etc. > You have to track multiple subtitles at the same time. > > You should be able to extract the subtitle bit maps and timing data with modest work. > You could use OCR technology to turn the subtitles into text. > > Barry > > > > -- > > https://mail.python.org/mailman/listinfo/python-list Actually the video is in MP4 format and does not have subtitles in it. But I will surely try to use GStreamer as you have suggested. From rosuav at gmail.com Sat Aug 29 09:36:51 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 29 Aug 2020 23:36:51 +1000 Subject: Video file to subtitles file In-Reply-To: <6C814672-0C80-4AB8-8AEF-3D8F9463F585@barrys-emacs.org> References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> <6C814672-0C80-4AB8-8AEF-3D8F9463F585@barrys-emacs.org> Message-ID: On Sat, Aug 29, 2020 at 11:15 PM Barry Scott wrote: > > On 29 Aug 2020, at 12:51, Muskan Sanghai wrote: > > On Friday, August 28, 2020 at 10:59:29 PM UTC+5:30, Chris Angelico wrote: > >> Not familiar with Openshot, but it's worth looking into. > >> Alternatively, I'd definitely recommend ffmpeg for anything like this > >> sort of job. But if you actually need to OCR something, then you may > >> need to do some scripting work. I don't have code to offer you, but it > >> would involve FFMPEG to lift the images, something like Tesseract to > >> do the actual OCRing, and then you'd write the rest of it yourself in > >> Python. > >> > >> Other than that, this probably is something best done with a dedicated > >> movie editing tool, not Python. Use what exists. > >> > >> ChrisA > > I want to extract subtitles from a MPEG video (which does not have any previous subtitles) > > If it has no subtitles there is nothing to extract? > > I recall that in MPEG subtitles are RLE encoded bitmaps with timing and position data. > Which allows the player to show this bitmap at position X, Y starting at T0 and remove at t1 etc. > You have to track multiple subtitles at the same time. > > You should be able to extract the subtitle bit maps and timing data with modest work. > You could use OCR technology to turn the subtitles into text. That's what I was thinking of. I have a separate project that involves grabbing image frames from the subtitles track, running them through Tesseract (for OCR), and attempting to intelligently parse two concurrent tracks of subtitles. Probably more complicated than needed here though. I don't understand the OP's request though. Extract subtitles when there aren't any? ChrisA From grant.b.edwards at gmail.com Thu Aug 27 16:37:46 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 27 Aug 2020 20:37:46 -0000 (UTC) Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: Message-ID: On 2020-08-27, Chris Green wrote: > bbb = [b'aaa', b'bbb', b'ccc'] > sss = [] > for i in range(0, 2): > sss.append(str(bbb[i]) > > but that does seem a bit clumsy. Is there a better way? sss = [str(s) for s in bbb] -- Grant From grant.b.edwards at gmail.com Thu Aug 27 23:41:42 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 28 Aug 2020 03:41:42 -0000 (UTC) Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: Message-ID: On 2020-08-27, Marco Sulla wrote: > Are you sure you want `str()`? > >>>> str(b'aaa') > "b'aaa'" > > Probably you want: > > map(lambda x: x.decode(), bbb) If you're an old Scheme or Lisp programmer. :) This is probably the more usual way to spell it: sss = [x.decode() for x in bbb] From grant.b.edwards at gmail.com Fri Aug 28 09:56:38 2020 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 28 Aug 2020 13:56:38 -0000 (UTC) Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: On 2020-08-28, Chris Green wrote: > Maybe I shouldn't but Python 2 has been managing to do so for several > years without any issues. I know I *could* put the exceptions in a > bucket somewhere and deal with them separately but I'd really rather > not. Then just leave it as bytes and do whatever processing you used to do on the bytes instead of trying to converting it to a string. What is it you're doing that you think requires it be converted to a string? -- Grant From gpostle500 at gmail.com Thu Aug 27 16:18:27 2020 From: gpostle500 at gmail.com (gpostle500) Date: Thu, 27 Aug 2020 13:18:27 -0700 Subject: FW: pip not recognized In-Reply-To: <5f480491.1c69fb81.b62f.b8f7@mx.google.com> Message-ID: <5f481515.1c69fb81.8fb04.a8c8@mx.google.com> Sent from my Verizon, Samsung Galaxy smartphone -------- Original message --------From: geoff postle Date: 8/27/20 12:08 PM (GMT-08:00) To: python-list at python.org Subject: pip not recognized Hey just downloaded the 3.8.5 and when I search for pip in cmd it doesn?t show up and says not recognized. Trying to figure out why that is since I didn?t change the default selection and left the box with pip checked??Sent from Mail for Windows 10? From dwheeler at dwheeler.com Thu Aug 27 19:33:13 2020 From: dwheeler at dwheeler.com (David A. Wheeler) Date: Thu, 27 Aug 2020 19:33:13 -0400 (EDT) Subject: Proposal: Ignore all empty entries within $PYTHONPATH Message-ID: All: I propose that all empty entries with $PYTHONPATH be ignored. This would eliminate some accidents that can lead to security problems. I thought it'd be easiest to explain by drafting a PEP, so please see this first draft below. Thanks! Comments welcome. --- David A. Wheeler ============================= PEP: 9999 Title: Ignore all empty entries within ``$PYTHONPATH`` Author: David A. Wheeler Status: Draft Type: Standards Track Content-Type: text/x-rst Created: 27-Aug-2020 Python-Version: 3.7.10 Post-History: 27-Aug-2020 Abstract ======== Currently, common ways to set ``$PYTHONPATH`` also unexpectedly add the current directory as an entry. As a result, users have an increased risk of unintentionally running malicious code. This PEP proposes that all empty entries within ``$PYTHONPATH`` be ignored, instead of being treated as the current directory. In the rare cases where the current directory is intended, "." (or even better its absolute path) can continue to be used instead. This small change eliminates an easily-made and subtle mistake that can lead to a security vulnerability. Motivation ========== The essay "Never Run 'python' In Your Downloads Folder" by Glyph `Never Run`_ points out that the way Python currently implements ``$PYTHONPATH`` easily leads to users unintentionally running malicioous code. The problem is that "most places that [recommend using] PYTHONPATH recommend adding things to it like so": ``export PYTHONPATH="/new/useful/stuff:$PYTHONPATH"`` As the essay notes, "this idiom has a critical flaw: the first time it's invoked, if ``$PYTHONPATH`` was previously either empty or un-set, this then includes an empty string, which resolves to the current directory..." As a result, someone who executed this line above will quietly execute Python libraries in whatever their current directory happens to be, and that could quickly lead to running malicious code. It could be argued that this is fine, because the shell's ``$PATH`` does the same thing. After all, the current documentation for ``$PYTHONPATH`` says that it augments "the default search path for module files. The format is the same as the shell?s PATH: one or more directory pathnames separated by os.pathsep (e.g. colons on Unix or semicolons on Windows)." `Cmdline`_ But this argument ignores a key difference: the shell's ``$PATH`` practically *always* has an initial non-empty value, while ``$PYTHONPATH`` typically starts with an *empty* value. This means that the same patterns that are normally safe with ``$PATH`` (because ``$PATH`` is non-empty) are *dangerous* with ``$PYTHONPATH`` `Hacker News`_. Once ``$PYTHONPATH`` is set with a dangerous value, it is likely to stay dangerous after having other values appended. A far safer approach is for Python to simply skip all empty entries within ``$PYTHONPATH``. In this situation, a ``$PYTHONPATH`` with the value "``:spam::eggs:``" would be treated the same as "``spam:eggs``". Empty entries are almost never intended. They are also widely confusing, in part because they are not obvious. Users who truly want to include the runtime current directory can use "." instead, but in almost all cases they will want the absolute path to the current directory anyway. By ignoring all empty entries, Python users will be quietly protected from this mistake, making Python just a little easier to use securely. Setting ``$PYTHONPATH`` is less common (due to virtualenvs), but it's still in use and is a useful mechanism. It'd be best to quietly interpret empty entries in ``$PYTHONPATH`` as unintentional mistakes and ignore them, instead of quietly enabling security vulnerabilities. Implementing this is trivial. I have created this PEP because this is technically a behavioral change in a long-present mechanism. References ========== .. _Never Run: https://glyph.twistedmatrix.com/2020/08/never-run-python-in-your-downloads-folder.html by Glyph .. _Cmdline: https://docs.python.org/3/using/cmdline.html .. _Hacker News: https://news.ycombinator.com/item?id=24250418 Copyright ========= This document is placed in the public domain or under the CC0-1.0-Universal license, whichever is more permissive. .. Local Variables: mode: indented-text indent-tabs-mode: nil sentence-end-double-space: t fill-column: 70 coding: utf-8 End: From survivor9901 at gmail.com Fri Aug 28 07:02:42 2020 From: survivor9901 at gmail.com (Joshua Sharma) Date: Fri, 28 Aug 2020 16:32:42 +0530 Subject: Can't use interpreter Message-ID: I have downloaded python 3.7.6, but I can't seem to use it in PyCharm. I have subscribed. From research at johnohagan.com Sat Aug 29 04:24:10 2020 From: research at johnohagan.com (John O'Hagan) Date: Sat, 29 Aug 2020 18:24:10 +1000 Subject: Threading plus multiprocessing plus cv2 error Message-ID: <20200829182410.4d3633f1@e7240.home> Dear list Thanks to this list, I haven't needed to ask a question for a very long time, but this one has me stumped. Here's the minimal 3.8 code, on Debian testing: ----- from multiprocessing import Process from threading import Thread from time import sleep import cv2 def show(im, title, location): cv2.startWindowThread() cv2.namedWindow(title) cv2.moveWindow(title, *location) cv2.imshow(title, im) sleep(2) #just to keep window open im1 = cv2.imread('/path/to/image1') im2 = cv2.imread('/path/to/image2') Thread(target=show, args=(im1, 'im1', (600,0))).start() sleep(1) Process(target=show, args=(im2, 'im2', (0, 0))).start() ----- Here's the error: ----- [xcb] Unknown sequence number while processing queue [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called [xcb] Aborting, sorry about that. python3: ../../src/xcb_io.c:260: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed. ----- There's no error without the sleep(1), nor if the Process is started before the Thread, nor if two Processes are used instead, nor if two Threads are used instead. IOW the error only occurs if a Thread is started first, and a Process is started a little later. Any ideas what might be causing the error? Thanks. -- John From cl at isbd.net Sat Aug 29 11:20:27 2020 From: cl at isbd.net (Chris Green) Date: Sat, 29 Aug 2020 16:20:27 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: Dennis Lee Bieber wrote: > On Fri, 28 Aug 2020 12:26:07 +0100, Chris Green declaimed the > following: > > > > >Maybe I shouldn't but Python 2 has been managing to do so for several > >years without any issues. I know I *could* put the exceptions in a > >bucket somewhere and deal with them separately but I'd really rather > >not. > > > > In Python2 "string" IS BYTE-STRING. It is never UNICODE, and ignores > any encoding. > > So, for Python3, the SAME processing requires NOT USING "string" (which > is now Unicode) and ensuring that all literals are b"stuff", and using the > methods of the bytes data type. > Now I'm beginning to realise that *this* may well be what I need to do, after going round in several convoluted circles! :-) Thank you! -- Chris Green ? From cl at isbd.net Sat Aug 29 11:50:09 2020 From: cl at isbd.net (Chris Green) Date: Sat, 29 Aug 2020 16:50:09 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: Chris Green wrote: > Dennis Lee Bieber wrote: > > On Fri, 28 Aug 2020 12:26:07 +0100, Chris Green declaimed the > > following: > > > > > > > > >Maybe I shouldn't but Python 2 has been managing to do so for several > > >years without any issues. I know I *could* put the exceptions in a > > >bucket somewhere and deal with them separately but I'd really rather > > >not. > > > > > > > In Python2 "string" IS BYTE-STRING. It is never UNICODE, and ignores > > any encoding. > > > > So, for Python3, the SAME processing requires NOT USING "string" (which > > is now Unicode) and ensuring that all literals are b"stuff", and using the > > methods of the bytes data type. > > > Now I'm beginning to realise that *this* may well be what I need to > do, after going round in several convoluted circles! :-) > However the problem appears to be that internally in Python 3 mailbox class there is an assumption that it's being given 'ascii'. Here's the error (and I'm doing no processing of the message at all):- Traceback (most recent call last): File "/home/chris/.mutt/bin/filter.py", line 102, in mailLib.deliverMboxMsg(dest, msg, log) File "/home/chris/.mutt/bin/mailLib.py", line 52, in deliverMboxMsg mbx.add(msg) File "/usr/lib/python3.8/mailbox.py", line 603, in add self._toc[self._next_key] = self._append_message(message) File "/usr/lib/python3.8/mailbox.py", line 758, in _append_message offsets = self._install_message(message) File "/usr/lib/python3.8/mailbox.py", line 830, in _install_message self._dump_message(message, self._file, self._mangle_from_) File "/usr/lib/python3.8/mailbox.py", line 215, in _dump_message gen.flatten(message) File "/usr/lib/python3.8/email/generator.py", line 116, in flatten self._write(msg) File "/usr/lib/python3.8/email/generator.py", line 181, in _write self._dispatch(msg) File "/usr/lib/python3.8/email/generator.py", line 214, in _dispatch meth(msg) File "/usr/lib/python3.8/email/generator.py", line 432, in _handle_text super(BytesGenerator,self)._handle_text(msg) File "/usr/lib/python3.8/email/generator.py", line 249, in _handle_text self._write_lines(payload) File "/usr/lib/python3.8/email/generator.py", line 155, in _write_lines self.write(line) File "/usr/lib/python3.8/email/generator.py", line 406, in write self._fp.write(s.encode('ascii', 'surrogateescape')) UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128) Any message with other than ASCII in it is going to have bytes >128 unless it's encoded some way to make it 7-bit and that's not going to happen in the general case. -- Chris Green ? From cl at isbd.net Sat Aug 29 12:18:02 2020 From: cl at isbd.net (Chris Green) Date: Sat, 29 Aug 2020 17:18:02 +0100 Subject: Silly question, where is read() documented? Message-ID: Well it sounds a silly question but I can't find the documentation for read(). It's not a built-in function and it's not documented with (for example) the file type object sys.stdin. So where is it documented? :-) -- Chris Green ? From hobson42 at gmail.com Sat Aug 29 12:33:40 2020 From: hobson42 at gmail.com (Ian Hobson) Date: Sat, 29 Aug 2020 17:33:40 +0100 Subject: Silly question, where is read() documented? In-Reply-To: References: Message-ID: https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects (It is in the top result returned by Google, searching for Python read documentation) On 29/08/2020 17:18, Chris Green wrote: > Well it sounds a silly question but I can't find the documentation for > read(). It's not a built-in function and it's not documented with > (for example) the file type object sys.stdin. > > So where is it documented? :-) > -- Ian Hobson -- This email has been checked for viruses by AVG. https://www.avg.com From mats at python.org Sat Aug 29 12:53:41 2020 From: mats at python.org (Mats Wichmann) Date: Sat, 29 Aug 2020 10:53:41 -0600 Subject: Can't use interpreter In-Reply-To: References: Message-ID: <4c0b3118-d6ad-de15-0a9e-a4335568e8ab@python.org> On 8/28/20 5:02 AM, Joshua Sharma wrote: > I have downloaded python 3.7.6, but I can't seem to use it in PyCharm. I > have subscribed. > See the PyCharm instructions for setting an interpreter, which can be default, and per-project. Unless there was more to this question that you didn't ask... From mats at python.org Sat Aug 29 12:58:18 2020 From: mats at python.org (Mats Wichmann) Date: Sat, 29 Aug 2020 10:58:18 -0600 Subject: FW: pip not recognized In-Reply-To: <5f481515.1c69fb81.8fb04.a8c8@mx.google.com> References: <5f481515.1c69fb81.8fb04.a8c8@mx.google.com> Message-ID: <4acf9470-3813-cbe8-32b2-71cc924cb68d@python.org> On 8/27/20 2:18 PM, gpostle500 wrote: > > Sent from my Verizon, Samsung Galaxy smartphone > -------- Original message --------From: geoff postle Date: 8/27/20 12:08 PM (GMT-08:00) To: python-list at python.org Subject: pip not recognized Hey just downloaded the 3.8.5 and when I search for pip in cmd it doesn?t show up and says not recognized. Trying to figure out why that is since I didn?t change the default selection and left the box with pip checked??Sent from Mail for Windows 10? > Use py -m pip pip-the-command goes in a different directory on Windows, which probably didn't get added to your PATH - but you probably don't want to do that anyway. e.g. if Python was in \Users\geoff\AppData\Local\Progrms\Python38 then the pip command will be in \Users\geoff\AppData\Local\Progrms\Python38\Scripts But use it as a module - you have a better chance of package installs staying in sync with the version of Python you use, eventually there will probably be several of those.... From cl at isbd.net Sat Aug 29 12:48:21 2020 From: cl at isbd.net (Chris Green) Date: Sat, 29 Aug 2020 17:48:21 +0100 Subject: Where read() is documented References: Message-ID: Stefan Ram wrote: > Chris Green writes: I can't find the documentation for > >read(). It's not a built-in function and it's not documented with > >(for example) the file type object sys.stdin. > > |read() (asyncio.StreamReader method), 894 > |read() (chunk.Chunk method), 1385 > |read() (codecs.StreamReader method), 164 > |read() (configparser.ConfigParser method), 537 > |read() (http.client.HTTPResponse method), 1276 > |read() (imaplib.IMAP4 method), 1291 > |read() (in module os), 578 > |read() (io.BufferedIOBase method), 622 > |read() (io.BufferedReader method), 625 > |read() (io.RawIOBase method), 621 > |read() (io.TextIOBase method), 626 > |read() (mimetypes.MimeTypes method), 1146 > |read() (mmap.mmap method), 1053 > |read() (ossaudiodev.oss_audio_device method), 1388 > |read() (ssl.MemoryBIO method), 1024 > |read() (ssl.SSLSocket method), 1005 > |read() (urllib.robotparser.RobotFileParser method), 1268 > |read() (zipfile.ZipFile method), 499 > Index of "The Python Library Reference, Release 3.9.0a3" > > But none of those is the documentation for read(), they're just places that refer to read(). -- Chris Green ? From cl at isbd.net Sat Aug 29 13:02:33 2020 From: cl at isbd.net (Chris Green) Date: Sat, 29 Aug 2020 18:02:33 +0100 Subject: Finally fixed my Python 2 to Python 3 e-mail problem Message-ID: <9aeq1h-5vo5.ln1@esprimo.zbmc.eu> I've started a new thread because this relates to two or three threads I started here over the past few days. First, thank you everyone for all the help and suggestions. I've finally fixed the problem, it was due to sys.stdin.read() returning a string object in Python 3 as opposed to bytes in Python 2. So, the code that reads an incoming message was:- msg = mailbox.mboxMessage(sys.stdin.read()) ... and msg eventually gets passed into mailbox.mbox.add(msg) This works fine in Python 2 but fails with a "can't encode" error in Python 3 (deep down in the mailbox code). The cause of the problem is that Python 3's sys.stdin.read() returns a string, so changing the above line to:- msg = mailbox.mboxMessage(sys.stdin.buffer.read()) fixes the problem. It took me quite a while to find the answer, mainly because I was thinking the wrong way round, trying to make my message into a string, whereas what I needed to do was keep it as a 'byte string' (I still think there should be a better name for that!). Again, thank you everyone for all the help, it did get me there in the end! -- Chris Green ? From Richard at Damon-Family.org Sat Aug 29 13:37:33 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 29 Aug 2020 13:37:33 -0400 Subject: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: On 8/29/20 11:50 AM, Chris Green wrote: > Chris Green wrote: >> Dennis Lee Bieber wrote: >>> On Fri, 28 Aug 2020 12:26:07 +0100, Chris Green declaimed the >>> following: >>> >>> >>> >>>> Maybe I shouldn't but Python 2 has been managing to do so for several >>>> years without any issues. I know I *could* put the exceptions in a >>>> bucket somewhere and deal with them separately but I'd really rather >>>> not. >>>> >>> In Python2 "string" IS BYTE-STRING. It is never UNICODE, and ignores >>> any encoding. >>> >>> So, for Python3, the SAME processing requires NOT USING "string" (which >>> is now Unicode) and ensuring that all literals are b"stuff", and using the >>> methods of the bytes data type. >>> >> Now I'm beginning to realise that *this* may well be what I need to >> do, after going round in several convoluted circles! :-) >> > However the problem appears to be that internally in Python 3 mailbox > class there is an assumption that it's being given 'ascii'. Here's > the error (and I'm doing no processing of the message at all):- > > Traceback (most recent call last): > File "/home/chris/.mutt/bin/filter.py", line 102, in > mailLib.deliverMboxMsg(dest, msg, log) > File "/home/chris/.mutt/bin/mailLib.py", line 52, in deliverMboxMsg > mbx.add(msg) > File "/usr/lib/python3.8/mailbox.py", line 603, in add > self._toc[self._next_key] = self._append_message(message) > File "/usr/lib/python3.8/mailbox.py", line 758, in _append_message > offsets = self._install_message(message) > File "/usr/lib/python3.8/mailbox.py", line 830, in _install_message > self._dump_message(message, self._file, self._mangle_from_) > File "/usr/lib/python3.8/mailbox.py", line 215, in _dump_message > gen.flatten(message) > File "/usr/lib/python3.8/email/generator.py", line 116, in flatten > self._write(msg) > File "/usr/lib/python3.8/email/generator.py", line 181, in _write > self._dispatch(msg) > File "/usr/lib/python3.8/email/generator.py", line 214, in _dispatch > meth(msg) > File "/usr/lib/python3.8/email/generator.py", line 432, in > _handle_text > super(BytesGenerator,self)._handle_text(msg) > File "/usr/lib/python3.8/email/generator.py", line 249, in > _handle_text > self._write_lines(payload) > File "/usr/lib/python3.8/email/generator.py", line 155, in > _write_lines > self.write(line) > File "/usr/lib/python3.8/email/generator.py", line 406, in write > self._fp.write(s.encode('ascii', 'surrogateescape')) > UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3: ordinal not in range(128) > > Any message with other than ASCII in it is going to have bytes >128 > unless it's encoded some way to make it 7-bit and that's not going to > happen in the general case. > When I took a quick look at the mailbox class, it said it could take a 'string', or a 'message'. It may well be that the string option assumes ASCII. You may need to use the message parsing options of message to convert messages with extended characters into the right format. This is one of the cases where Python 2's non-strictness made things easier, but also much easier to get wrong if not careful. Python 3 is basically making you do more work to make sure you are doing it right. -- Richard Damon From python at mrabarnett.plus.com Sat Aug 29 13:50:35 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 29 Aug 2020 18:50:35 +0100 Subject: Where read() is documented In-Reply-To: References: Message-ID: On 2020-08-29 17:48, Chris Green wrote: > Stefan Ram wrote: >> Chris Green writes: I can't find the documentation for >> >read(). It's not a built-in function and it's not documented with >> >(for example) the file type object sys.stdin. >> >> |read() (asyncio.StreamReader method), 894 >> |read() (chunk.Chunk method), 1385 >> |read() (codecs.StreamReader method), 164 >> |read() (configparser.ConfigParser method), 537 >> |read() (http.client.HTTPResponse method), 1276 >> |read() (imaplib.IMAP4 method), 1291 >> |read() (in module os), 578 >> |read() (io.BufferedIOBase method), 622 >> |read() (io.BufferedReader method), 625 >> |read() (io.RawIOBase method), 621 >> |read() (io.TextIOBase method), 626 >> |read() (mimetypes.MimeTypes method), 1146 >> |read() (mmap.mmap method), 1053 >> |read() (ossaudiodev.oss_audio_device method), 1388 >> |read() (ssl.MemoryBIO method), 1024 >> |read() (ssl.SSLSocket method), 1005 >> |read() (urllib.robotparser.RobotFileParser method), 1268 >> |read() (zipfile.ZipFile method), 499 >> Index of "The Python Library Reference, Release 3.9.0a3" >> >> > But none of those is the documentation for read(), they're just places > that refer to read(). > There's no read() function. What you're referring to are the 'read' methods of various classes. If you open a file in text mode, you'll get an instance of TextIOWrapper, which inherits .read from TextIOBase. If you open a file in binary mode, you'll get an instance of BufferedReader, which has a .read method. Multiple classes, each with its own 'read' method. sys.stdin is an instance of TextIOWrapper, so for that you should look at the methods of TextIOWrapper. From Karsten.Hilbert at gmx.net Sat Aug 29 15:31:54 2020 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sat, 29 Aug 2020 21:31:54 +0200 Subject: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: > However the problem appears to be that internally in Python 3 mailbox > class there is an assumption that it's being given 'ascii'. Do you really _need_ the mailbox class ? From what you've written so far my understanding was that you receive data (bytes) and want to append that to a file (which happens to be an mbox). Can't you "just do that" ? IOW, read the bytes, open the file, dump the bytes, close the file ? Karsten From Karsten.Hilbert at gmx.net Sat Aug 29 15:34:24 2020 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sat, 29 Aug 2020 21:34:24 +0200 Subject: Aw: Re: Video file to subtitles file In-Reply-To: <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> Message-ID: > I want to extract subtitles from a MPEG video (which does not have any previous subtitles) and then add them to the same video . I am not sure I parse the above: You want to *extract* subtitles from a video which *does not have* subtitles ? I have a feeling you will need to rephrase your objective to get better help. Karsten From Richard at Damon-Family.org Sat Aug 29 15:52:50 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Sat, 29 Aug 2020 15:52:50 -0400 Subject: Aw: Re: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: On 8/29/20 3:31 PM, Karsten Hilbert wrote: >> However the problem appears to be that internally in Python 3 mailbox >> class there is an assumption that it's being given 'ascii'. > Do you really _need_ the mailbox class ? From what you've > written so far my understanding was that you receive data > (bytes) and want to append that to a file (which happens > to be an mbox). > > Can't you "just do that" ? > > IOW, read the bytes, open the file, dump the bytes, close the file ? > > Karsten Just appending a message as a raw file to a mailbox, doesn't properly add it as a new message. You need to add a From: line to the front, and then go through the message and alter any line that begins as "From:" (and possibly any line that begins with something like ">From:" or ">>From:" depending on which mailbox format is being used. There may be a few other small details that needs to happen to. -- Richard Damon From Karsten.Hilbert at gmx.net Sat Aug 29 16:01:07 2020 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sat, 29 Aug 2020 22:01:07 +0200 Subject: Aw: Re: Re: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: > Just appending a message as a raw file to a mailbox, doesn't properly > add it as a new message. You need to add a From: line to the front, and > then go through the message and alter any line that begins as "From:" > (and possibly any line that begins with something like ">From:" or > ">>From:" depending on which mailbox format is being used. There may be > a few other small details that needs to happen to. I see, thanks. Karsten From cs at cskk.id.au Sat Aug 29 17:59:40 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 30 Aug 2020 07:59:40 +1000 Subject: Python 3 how to convert a list of bytes objects to a list of strings? In-Reply-To: References: Message-ID: <20200829215940.GA25836@cskk.homeip.net> On 29Aug2020 16:50, Chris Green wrote: >However the problem appears to be that internally in Python 3 mailbox >class there is an assumption that it's being given 'ascii'. Here's >the error (and I'm doing no processing of the message at all):- > > Traceback (most recent call last): > File "/home/chris/.mutt/bin/filter.py", line 102, in > mailLib.deliverMboxMsg(dest, msg, log) > File "/home/chris/.mutt/bin/mailLib.py", line 52, in deliverMboxMsg > mbx.add(msg) [...] Here is the entire save-to-mbox code form my own mailfiler: text = M.as_string(True).replace('\nFrom ', '\n>From ') with open(folderpath, "a") as mboxfp: mboxfp.write(text) where M is the current message, a Message object. Note that this does _not_ assume ASCII output. The process here is: - transcribe the message to a Python 3 str (so Unicode code points) - replace embedded "From " to protect the mbox format - open the mbox for append - the _default_ encoding is utf-8 - write the message in utf-8 because of the open mode This sidesteps the library you're using which may well do something ASCII based. And it has _never_ failed for me. Cheers, Cameron Simpson From pfeiffer at cs.nmsu.edu Sat Aug 29 19:21:46 2020 From: pfeiffer at cs.nmsu.edu (Joe Pfeiffer) Date: Sat, 29 Aug 2020 17:21:46 -0600 Subject: Where read() is documented References: Message-ID: <1ba6ydf379.fsf@pfeifferfamily.net> Chris Green writes: > Stefan Ram wrote: >> Chris Green writes: I can't find the documentation for >> >read(). It's not a built-in function and it's not documented with >> >(for example) the file type object sys.stdin. >> >> |read() (asyncio.StreamReader method), 894 >> |read() (chunk.Chunk method), 1385 >> |read() (codecs.StreamReader method), 164 >> |read() (configparser.ConfigParser method), 537 >> |read() (http.client.HTTPResponse method), 1276 >> |read() (imaplib.IMAP4 method), 1291 >> |read() (in module os), 578 >> |read() (io.BufferedIOBase method), 622 >> |read() (io.BufferedReader method), 625 >> |read() (io.RawIOBase method), 621 >> |read() (io.TextIOBase method), 626 >> |read() (mimetypes.MimeTypes method), 1146 >> |read() (mmap.mmap method), 1053 >> |read() (ossaudiodev.oss_audio_device method), 1388 >> |read() (ssl.MemoryBIO method), 1024 >> |read() (ssl.SSLSocket method), 1005 >> |read() (urllib.robotparser.RobotFileParser method), 1268 >> |read() (zipfile.ZipFile method), 499 >> Index of "The Python Library Reference, Release 3.9.0a3" >> >> > But none of those is the documentation for read(), they're just places > that refer to read(). There is no single read() method, so there can be no single place to find its documentation. To take one of Stefan's examples, https://docs.python.org/3/library/io.html?highlight=io%20bufferedreader#io.BufferedReader.read says read([size]) Read and return size bytes, or if size is not given or negative, until EOF or if the read call would block in non-blocking mode. That's the documentation. From cs at cskk.id.au Sat Aug 29 21:52:40 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 30 Aug 2020 11:52:40 +1000 Subject: Silly question, where is read() documented? In-Reply-To: References: Message-ID: <20200830015240.GA99897@cskk.homeip.net> Also: https://docs.python.org/3/library/io.html#io.TextIOBase.read https://docs.python.org/3/library/io.html#io.BufferedIOBase.read Found by going to: https://docs.python.org/3/ https://docs.python.org/3/genindex.html https://docs.python.org/3/genindex-R.html and finding the links to "read". Personally, I fetch the Python docs every so often from: https://docs.python.org/3/download.html I fetch the "HTML" version, unpack it on my machine, and put a link to the "index.html" file on my Desktop. Instant, offline-ready, Python docs on my machine. Really snappy, because my browser's pulling from the local filesystem. Cheers, Cameron Simpson On 29Aug2020 17:33, Ian Hobson wrote: >https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects > >(It is in the top result returned by Google, searching for >Python read documentation) > >On 29/08/2020 17:18, Chris Green wrote: >>Well it sounds a silly question but I can't find the documentation for >>read(). It's not a built-in function and it's not documented with >>(for example) the file type object sys.stdin. >> >>So where is it documented? :-) > >-- Ian Hobson From tjreedy at udel.edu Sat Aug 29 21:29:20 2020 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 29 Aug 2020 21:29:20 -0400 Subject: Silly question, where is read() documented? In-Reply-To: References: Message-ID: On 8/29/2020 12:18 PM, Chris Green wrote: > Well it sounds a silly question but I can't find the documentation for > read(). It's not a built-in function and it's not documented with > (for example) the file type object sys.stdin. sys.stdin is of no particular type, but must at least have a .read method. > So where is it documented? :-) >>> import sys; sys.stdin should give a hint. In the standard REPL, <_io.TextIOWrapper name='' mode='r' encoding='utf-8'> As others said, actually look in the io module doc. You might spend some time reading the doc to get an idea of what is going on. If you run from IDLE, you currently get (I should make that more like the REPL answer.) -- Terry Jan Reedy From auriocus at gmx.de Sun Aug 30 01:26:47 2020 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 30 Aug 2020 07:26:47 +0200 Subject: Video file to subtitles file In-Reply-To: <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> Message-ID: Am 29.08.20 um 13:51 schrieb Muskan Sanghai: > I want to extract subtitles from a MPEG video (which does not have any previous subtitles) I'm still not sure I get it. "Extract" subtitles, when they are NOT there? Can it be, by any chance, that you are talking about speech recognition? I.e., you want a software which understands the spoken word in the movie sound and turns that into text, which can be shown as subtitles? Like the "auto-generated" subtitles which youtube offers for some videos. If so, it is a complex task and will not work overly well. I defer to the experts if there are any usable speech recognitino engines for this task. Christian From stephane at sdf.org Sun Aug 30 01:12:31 2020 From: stephane at sdf.org (Stephane Tougard) Date: Sun, 30 Aug 2020 13:12:31 +0800 Subject: Threading plus multiprocessing plus cv2 error References: <20200829182410.4d3633f1@e7240.home> <5f1lkf9343bqu3u0ius28rh63o255d433a@4ax.com> Message-ID: On 2020-08-29, Dennis Lee Bieber wrote: > Under Linux, multiprocessing creates processes using fork(). That means > that, for some fraction of time, you have TWO processes sharing the same > thread and all that entails (if it doesn't overlay the forked process with > a new executable, they are sharing the thread until the thread exits). > same error condition even with the sleep(1) in place. I'm not even that makes sense, how 2 processes can share a thread ? From rosuav at gmail.com Sun Aug 30 02:03:32 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Aug 2020 16:03:32 +1000 Subject: Threading plus multiprocessing plus cv2 error In-Reply-To: References: <20200829182410.4d3633f1@e7240.home> <5f1lkf9343bqu3u0ius28rh63o255d433a@4ax.com> Message-ID: On Sun, Aug 30, 2020 at 4:01 PM Stephane Tougard via Python-list wrote: > > On 2020-08-29, Dennis Lee Bieber wrote: > > Under Linux, multiprocessing creates processes using fork(). That means > > that, for some fraction of time, you have TWO processes sharing the same > > thread and all that entails (if it doesn't overlay the forked process with > > a new executable, they are sharing the thread until the thread exits). > > same error condition even with the sleep(1) in place. > > I'm not even that makes sense, how 2 processes can share a thread ? > They can't. However, they can share a Thread object, which is the Python representation of a thread. That can lead to confusion, and possibly the OP's error (I don't know for sure, I'm just positing). ChrisA From muskansanghai at gmail.com Sun Aug 30 02:08:02 2020 From: muskansanghai at gmail.com (Muskan Sanghai) Date: Sat, 29 Aug 2020 23:08:02 -0700 (PDT) Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> Message-ID: <88f95135-c790-40ff-ad0e-b8dd77070993n@googlegroups.com> On Sunday, August 30, 2020 at 10:57:00 AM UTC+5:30, Christian Gollwitzer wrote: > Am 29.08.20 um 13:51 schrieb Muskan Sanghai: > > I want to extract subtitles from a MPEG video (which does not have any previous subtitles) > I'm still not sure I get it. "Extract" subtitles, when they are NOT > there? Can it be, by any chance, that you are talking about speech > recognition? I.e., you want a software which understands the spoken word > in the movie sound and turns that into text, which can be shown as > subtitles? Like the "auto-generated" subtitles which youtube offers for > some videos. > > If so, it is a complex task and will not work overly well. I defer to > the experts if there are any usable speech recognitino engines for this > task. > > Christian Yes, this is what I exactly want to do. I want to create a software which understands the spoken word in the movie sound and turns that into text. From rosuav at gmail.com Sun Aug 30 02:15:49 2020 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 30 Aug 2020 16:15:49 +1000 Subject: Video file to subtitles file In-Reply-To: <88f95135-c790-40ff-ad0e-b8dd77070993n@googlegroups.com> References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> <88f95135-c790-40ff-ad0e-b8dd77070993n@googlegroups.com> Message-ID: On Sun, Aug 30, 2020 at 4:11 PM Muskan Sanghai wrote: > > On Sunday, August 30, 2020 at 10:57:00 AM UTC+5:30, Christian Gollwitzer wrote: > > Am 29.08.20 um 13:51 schrieb Muskan Sanghai: > > > I want to extract subtitles from a MPEG video (which does not have any previous subtitles) > > I'm still not sure I get it. "Extract" subtitles, when they are NOT > > there? Can it be, by any chance, that you are talking about speech > > recognition? I.e., you want a software which understands the spoken word > > in the movie sound and turns that into text, which can be shown as > > subtitles? Like the "auto-generated" subtitles which youtube offers for > > some videos. > > > > If so, it is a complex task and will not work overly well. I defer to > > the experts if there are any usable speech recognitino engines for this > > task. > > > > Christian > Yes, this is what I exactly want to do. I want to create a software which understands the spoken word in the movie sound and turns that into text. > I recommend looking into CMU Sphinx then. I've used that from Python. The results are highly entertaining. ChrisA From muskansanghai at gmail.com Sun Aug 30 02:23:49 2020 From: muskansanghai at gmail.com (Muskan Sanghai) Date: Sat, 29 Aug 2020 23:23:49 -0700 (PDT) Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> <88f95135-c790-40ff-ad0e-b8dd77070993n@googlegroups.com> Message-ID: <0f089fb8-8a2d-4739-960c-8a3d34dfb735n@googlegroups.com> On Sunday, August 30, 2020 at 11:46:15 AM UTC+5:30, Chris Angelico wrote: > On Sun, Aug 30, 2020 at 4:11 PM Muskan Sanghai wrote: > > > > On Sunday, August 30, 2020 at 10:57:00 AM UTC+5:30, Christian Gollwitzer wrote: > > > Am 29.08.20 um 13:51 schrieb Muskan Sanghai: > > > > I want to extract subtitles from a MPEG video (which does not have any previous subtitles) > > > I'm still not sure I get it. "Extract" subtitles, when they are NOT > > > there? Can it be, by any chance, that you are talking about speech > > > recognition? I.e., you want a software which understands the spoken word > > > in the movie sound and turns that into text, which can be shown as > > > subtitles? Like the "auto-generated" subtitles which youtube offers for > > > some videos. > > > > > > If so, it is a complex task and will not work overly well. I defer to > > > the experts if there are any usable speech recognitino engines for this > > > task. > > > > > > Christian > > Yes, this is what I exactly want to do. I want to create a software which understands the spoken word in the movie sound and turns that into text. > > > I recommend looking into CMU Sphinx then. I've used that from Python. > > The results are highly entertaining. > > ChrisA Okay I will try it, thank you. From klsshaeffer at icloud.com Sun Aug 30 03:54:19 2020 From: klsshaeffer at icloud.com (Karen Shaeffer) Date: Sun, 30 Aug 2020 00:54:19 -0700 Subject: Threading plus multiprocessing plus cv2 error In-Reply-To: References: <20200829182410.4d3633f1@e7240.home> <5f1lkf9343bqu3u0ius28rh63o255d433a@4ax.com> Message-ID: <4A96FEE7-C785-47AE-A4A9-ADFEEE056A2B@icloud.com> > On Aug 29, 2020, at 10:12 PM, Stephane Tougard via Python-list wrote: > > On 2020-08-29, Dennis Lee Bieber wrote: >> Under Linux, multiprocessing creates processes using fork(). That means >> that, for some fraction of time, you have TWO processes sharing the same >> thread and all that entails (if it doesn't overlay the forked process with >> a new executable, they are sharing the thread until the thread exits). >> same error condition even with the sleep(1) in place. > > I'm not even that makes sense, how 2 processes can share a thread ? > Hello, On linux, fork is a kernel system call. The linux kernel creates two identical processes running in separate memory spaces. At the time of creation, these memory spaces have the same content. There are some issues to be aware of. Just type ?man fork? on the command line of a linux system, and you can read about the issues of concern, presuming you have installed the manual pages for the linux kernel system calls. If the forked process doesn?t overlay onto a separate memory space, then the fork system call fails, returning a failure code to the parent process. When the linux kernel is executing the fork system call, the parent (forking process) is blocked on the system call. The linux kernel actually takes over the parent process during execution of the system call, running that process in kernel mode during the execution of the fork process. The parent (forking) process only restarts, after the kernel returns. On linux, within a given process, threads share the same memory space. If that process is the python interpreter, then the Global lock ensures only one thread is running when the fork happens. After the fork, then you have two distinct processes running in two separate memory spaces. And the fork man page discusses the details of concern with regards to specific kernel resources that could be referenced by those two distinct processes. The thread context is just a detail in that respect. All the threads of the parent process that forked the new process all share the same parent memory space. humbly, kls From cl at isbd.net Sun Aug 30 04:00:59 2020 From: cl at isbd.net (Chris Green) Date: Sun, 30 Aug 2020 09:00:59 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: <20200829215940.GA25836@cskk.homeip.net> Message-ID: Cameron Simpson wrote: > On 29Aug2020 16:50, Chris Green wrote: > >However the problem appears to be that internally in Python 3 mailbox > >class there is an assumption that it's being given 'ascii'. Here's > >the error (and I'm doing no processing of the message at all):- > > > > Traceback (most recent call last): > > File "/home/chris/.mutt/bin/filter.py", line 102, in > > mailLib.deliverMboxMsg(dest, msg, log) > > File "/home/chris/.mutt/bin/mailLib.py", line 52, in deliverMboxMsg > > mbx.add(msg) > [...] > > Here is the entire save-to-mbox code form my own mailfiler: > > text = M.as_string(True).replace('\nFrom ', '\n>From ') > with open(folderpath, "a") as mboxfp: > mboxfp.write(text) > > where M is the current message, a Message object. > > Note that this does _not_ assume ASCII output. The process here is: > > - transcribe the message to a Python 3 str (so Unicode code points) > - replace embedded "From " to protect the mbox format > - open the mbox for append - the _default_ encoding is utf-8 > - write the message in utf-8 because of the open mode > > This sidesteps the library you're using which may well do something > ASCII based. And it has _never_ failed for me. > Thanks Caneron, but I have now finally fixed my problem, see the new thread. -- Chris Green ? From cl at isbd.net Sun Aug 30 03:58:58 2020 From: cl at isbd.net (Chris Green) Date: Sun, 30 Aug 2020 08:58:58 +0100 Subject: Python 3 how to convert a list of bytes objects to a list of strings? References: <20200828090922.GA67165@cskk.homeip.net> Message-ID: <2r2s1h-ch59.ln1@esprimo.zbmc.eu> Karsten Hilbert wrote: > > However the problem appears to be that internally in Python 3 mailbox > > class there is an assumption that it's being given 'ascii'. > > Do you really _need_ the mailbox class ? From what you've > written so far my understanding was that you receive data > (bytes) and want to append that to a file (which happens > to be an mbox). > > Can't you "just do that" ? > > IOW, read the bytes, open the file, dump the bytes, close the file ? > This would have been my next approach but see the new thread I've started about this. The fis was to change the read from stdin so that it produced bytes instead of a string. The bytes are fed into the mailbox class and it no longer tries to decode them. -- Chris Green ? From cl at isbd.net Sun Aug 30 04:10:40 2020 From: cl at isbd.net (Chris Green) Date: Sun, 30 Aug 2020 09:10:40 +0100 Subject: Silly question, where is read() documented? References: Message-ID: <0h3s1h-ch59.ln1@esprimo.zbmc.eu> Terry Reedy wrote: > On 8/29/2020 12:18 PM, Chris Green wrote: > > Well it sounds a silly question but I can't find the documentation for > > read(). It's not a built-in function and it's not documented with > > (for example) the file type object sys.stdin. > > sys.stdin is of no particular type, but must at least have a .read method. > > > So where is it documented? :-) > > >>> import sys; sys.stdin > should give a hint. In the standard REPL, > > <_io.TextIOWrapper name='' mode='r' encoding='utf-8'> > > As others said, actually look in the io module doc. You might spend > some time reading the doc to get an idea of what is going on. If you > run from IDLE, you currently get > > > (I should make that more like the REPL answer.) > Yes, quite! :-) All I actually wanted to find out was the difference between what is returned by sys.stdin.read() in Python 2 and Python 3 as that turned out to be the fundamental cause of the mail handling problem I have been airing in other threads here. -- Chris Green ? From cl at isbd.net Sun Aug 30 04:04:35 2020 From: cl at isbd.net (Chris Green) Date: Sun, 30 Aug 2020 09:04:35 +0100 Subject: Where read() is documented References: Message-ID: MRAB wrote: > On 2020-08-29 17:48, Chris Green wrote: > > Stefan Ram wrote: > >> Chris Green writes: I can't find the documentation for > >> >read(). It's not a built-in function and it's not documented with > >> >(for example) the file type object sys.stdin. > >> > >> |read() (asyncio.StreamReader method), 894 > >> |read() (chunk.Chunk method), 1385 > >> |read() (codecs.StreamReader method), 164 > >> |read() (configparser.ConfigParser method), 537 > >> |read() (http.client.HTTPResponse method), 1276 > >> |read() (imaplib.IMAP4 method), 1291 > >> |read() (in module os), 578 > >> |read() (io.BufferedIOBase method), 622 > >> |read() (io.BufferedReader method), 625 > >> |read() (io.RawIOBase method), 621 > >> |read() (io.TextIOBase method), 626 > >> |read() (mimetypes.MimeTypes method), 1146 > >> |read() (mmap.mmap method), 1053 > >> |read() (ossaudiodev.oss_audio_device method), 1388 > >> |read() (ssl.MemoryBIO method), 1024 > >> |read() (ssl.SSLSocket method), 1005 > >> |read() (urllib.robotparser.RobotFileParser method), 1268 > >> |read() (zipfile.ZipFile method), 499 > >> Index of "The Python Library Reference, Release 3.9.0a3" > >> > >> > > But none of those is the documentation for read(), they're just places > > that refer to read(). > > > There's no read() function. What you're referring to are the 'read' > methods of various classes. > Yes, OK, method rather than function. > If you open a file in text mode, you'll get an instance of > TextIOWrapper, which inherits .read from TextIOBase. > > If you open a file in binary mode, you'll get an instance of > BufferedReader, which has a .read method. > > Multiple classes, each with its own 'read' method. > > sys.stdin is an instance of TextIOWrapper, so for that you should look > at the methods of TextIOWrapper. I went to sys.stdin but it didn't really lead me easily to the read() method. All I actually wanted to know was what was the type of the return value of the read() method which is different in Python 2 and 3. -- Chris Green ? From research at johnohagan.com Sun Aug 30 04:30:34 2020 From: research at johnohagan.com (John O'Hagan) Date: Sun, 30 Aug 2020 18:30:34 +1000 Subject: Threading plus multiprocessing plus cv2 error In-Reply-To: <5f1lkf9343bqu3u0ius28rh63o255d433a@4ax.com> References: <20200829182410.4d3633f1@e7240.home> <5f1lkf9343bqu3u0ius28rh63o255d433a@4ax.com> Message-ID: <20200830183034.0d504408@e7240.home> On Sat, 29 Aug 2020 13:01:12 -0400 Dennis Lee Bieber wrote: > On Sat, 29 Aug 2020 18:24:10 +1000, John O'Hagan > declaimed the following: > > >There's no error without the sleep(1), nor if the Process is started > >before the Thread, nor if two Processes are used instead, nor if two > >Threads are used instead. IOW the error only occurs if a Thread is > >started first, and a Process is started a little later. > > > >Any ideas what might be causing the error? > > > > Under Linux, multiprocessing creates processes using fork(). > That means that, for some fraction of time, you have TWO processes > sharing the same thread and all that entails (if it doesn't overlay > the forked process with a new executable, they are sharing the thread > until the thread exits). > > https://stackoverflow.com/questions/54466572/how-to-properly-multithread-in-opencv-in-2019 > (which points to) > https://answers.opencv.org/question/32415/thread-safe/?answer=32452#post-id-32452 > """ > The library itself is thread safe in that you can have multiple calls > into the library at the same time, however the data is not always > thread safe. """ > > The sleep(1), when compounded with the overhead of starting > the thread, and then starting the process, likely means the thread > had exited before the process actually is started. Try replacing the > sleep(2) in the work code with something like sleep(30) -- I > hypothesize that you'll get the same error condition even with the > sleep(1) in place. > > Thanks for the reply. You're right, the error also happens with a longer sleep, or no sleep at all, inside the function. That sleep is only there in the example to keep the windows open long enough to see the images if they are successfully displayed. I could well be wrong as I'm not fully across multiprocessing, but I think the Stackoverflow question and answer you linked above relate to a different situation, with multithreaded cv2 operations on shared image data. In my example, AFAIK (which is not very far) it shouldn't matter whether the new process is sharing the thread, or whether the thread has exited, because the thread and the process aren't using the same data. Or (as is quite likely) am I misunderstanding your point? Cheers John From Gronicus at SGA.Ninja Sun Aug 30 04:55:49 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sun, 30 Aug 2020 04:55:49 -0400 Subject: Problem running a FOR loop Message-ID: <000001d67eab$5bca72b0$135f5810$@SGA.Ninja> Compiles, no syntax errors however, line 82 seems to run only once when the FOR loop has completed. Why is that? All fields are to contain the specifications, not just the last one. Steve ---------------------------------------------------------------------------- ------------------------------ ThisList = ["start"] #=============================================================== def FillTheList(): x=0 ThisList = [] with open("Specifications.txt", 'r') as infile: for lineEQN in infile: # loop to find each line in the file for that dose if lineEQN[0:1] == "-": ListItem = lineEQN[1:6].strip() ThisList.append(ListItem) return(ThisList) #==================================================================== def EditDataByForm(): import tkinter as tk from tkinter import ttk import sys window = tk.Tk() window.title("Python Tkinter Text Box") window.minsize(700,700) #height, width #=============================================================== def GetLineByItem(DataType): #get line by item in column 3 - 5 #print("DataType = " + DataType) DataLetter = DataType[0:1] if DataLetter.isupper(): # == "Specs": FileToBeEdited = "Specifications.txt" else: FileToBeEdited = "DataSpecifications.txt" with open(FileToBeEdited, 'r') as infile: for lineEQN in infile: # loop to find each line in the file for that dose if ((lineEQN[1:2]== DataLetter)): A = lineEQN[1:46] # Whole Line a = lineEQN[34:46].strip() # Just the Data # print("A = " + A ) # print("a = " + a) return(A, a) #=============================================================== def ClickSubmit(): window.destroy() #=============================================================== label = ttk.Label(window, text = "Enter the new readings") label.grid(column = 1, row = 1) ThisList = FillTheList() x = 3 # Allows for two rows at the top of the form used for headers y = 0 # Scans the datafile to fill the list for lineItem in range(len(ThisList)): SpecLine, Spec = GetLineByItem(ThisList[y]) OldSpec = Spec #print("OldSpec = " + OldSpec) NewSpec = " " SVRlabel = ttk.Label(window, text = SpecLine + " "*5) SVRlabel.grid(column = 1, row = x) NewSpec = tk.StringVar() SVRCodeEntered = ttk.Entry(window, width = 15, textvariable = NewSpec) SVRCodeEntered.grid(column = 2, row = x, pady = 15) print("x , y = " + str(x) + ", " + str(y)) print("OldSpec2 = <" + OldSpec + "> ") #Use of <> show spaces if any #81 The next line seems to run only once at the end of the FOR loop <<<<<<<<<<<<<< SVRCodeEntered.insert(0, OldSpec) SVRCodeEntered.focus_set() x += 1 y += 1 #=============================================================== button = ttk.Button(window, text = "Submit", command = ClickSubmit) button.grid(column= 2, row = 15) window.mainloop() ------------------------------------------------------ Specifications.txt. This will align when using Notepad++. A LTD Last Time Date 2020-08-29 00:55:18.610102 ## B LDL Last Dose Line 2020-08-29 00:55:18.610102 ## C LLL Last LTD line 2020-08-29 00:55:18.610102 ## D LTD Last Time Date 2020-08-29 00:55:18.610102 ## - -E MSN Monitor Serial Number JNGY263-T4464 ## - -F TSL TestStrip Lot Number 45001 82990 ## -G SED Strip Expire Date 2021-05-31 ## - -H SSC Sensor Sequence Code 71 ## -I SCN Sensor Code Number G03 ## -J SSN Sensor Serial Number 2021-01-31 ## -K SDE Sensor Date to Expire 2021-01-31 ## -L SDN Sensor Day Number 12 ## -M FDS First Date for Sensor Fri Aug 17, 2020 09:34 ## - -N IDT Insulin Dose Total 450 ## O DTD Data Time Date Fri Aug 07, 2020 21:30 ## P PTD Previous Time Date Thu Nov 27, 1952 14:30 ## - Q HL1 Half Life 1 1 ## R HL2 Half LIfe 2 2 ## S HL3 Half Life 3 3 ## T TIL Total Insulin Layer 25 ## ---------------------------------------------------------------------------- ------------------- Footnote: The power company in Utah has built the Sisyphus train. When there is a surplus of available energy from their massive collection of solar cells, they use it to drive a train up a hill. At night when the need power, they ease the train down to generate energy to fill the gap. - From barry at barrys-emacs.org Sun Aug 30 04:59:15 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Sun, 30 Aug 2020 09:59:15 +0100 Subject: Threading plus multiprocessing plus cv2 error In-Reply-To: <5f1lkf9343bqu3u0ius28rh63o255d433a@4ax.com> References: <20200829182410.4d3633f1@e7240.home> <5f1lkf9343bqu3u0ius28rh63o255d433a@4ax.com> Message-ID: <0A169682-FF32-45E0-923F-B6AE1A566062@barrys-emacs.org> > On 29 Aug 2020, at 18:01, Dennis Lee Bieber wrote: > > On Sat, 29 Aug 2020 18:24:10 +1000, John O'Hagan > declaimed the following: > >> There's no error without the sleep(1), nor if the Process is started >> before the Thread, nor if two Processes are used instead, nor if two >> Threads are used instead. IOW the error only occurs if a Thread is >> started first, and a Process is started a little later. >> >> Any ideas what might be causing the error? >> > > Under Linux, multiprocessing creates processes using fork(). That means > that, for some fraction of time, you have TWO processes sharing the same > thread and all that entails (if it doesn't overlay the forked process with > a new executable, they are sharing the thread until the thread exits). In the parent you have 1 or more threads. After fork the new process has 1 thread, which is not shared with the parent. Any extra threads are not in the new process. But the memory in the new process will have data structures from the parents other threads. So no you never have two processes sharing an threads. This leads to problems with locks. Barry > > https://stackoverflow.com/questions/54466572/how-to-properly-multithread-in-opencv-in-2019 > (which points to) > https://answers.opencv.org/question/32415/thread-safe/?answer=32452#post-id-32452 > """ > The library itself is thread safe in that you can have multiple calls into > the library at the same time, however the data is not always thread safe. > """ > > The sleep(1), when compounded with the overhead of starting the thread, > and then starting the process, likely means the thread had exited before > the process actually is started. Try replacing the sleep(2) in the work > code with something like sleep(30) -- I hypothesize that you'll get the > same error condition even with the sleep(1) in place. > > > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/ > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Sun Aug 30 05:29:05 2020 From: __peter__ at web.de (Peter Otten) Date: Sun, 30 Aug 2020 11:29:05 +0200 Subject: Problem running a FOR loop References: <000001d67eab$5bca72b0$135f5810$@SGA.Ninja> Message-ID: Steve wrote: > Compiles, no syntax errors however, line 82 seems to run only once when > the FOR loop has completed. > Why is that? All fields are to contain the specifications, not just the > last one. It seems that passing the StringVar to the Entry widget is not sufficient to keep it alive. > for lineItem in range(len(ThisList)): > NewSpec = tk.StringVar() > SVRCodeEntered = ttk.Entry(window, width = 15, textvariable = > NewSpec) When the previous NewSpec is overwritten with the current one the previous gets garbage-collected and its value is lost. The straight-forward fix is to introduce a list: new_specs = [] > for lineItem in range(len(ThisList)): > NewSpec = tk.StringVar() new_specs.append(NewSpec) > SVRCodeEntered = ttk.Entry(window, width = 15, textvariable = > NewSpec) Another option is to store the StringVar as an attribute of the Entry: > for lineItem in range(len(ThisList)): > NewSpec = tk.StringVar() > SVRCodeEntered = ttk.Entry(window, width = 15, textvariable = > NewSpec) SVRCodeEntered.new_spec = NewSpec From stephane at sdf.org Sun Aug 30 05:08:07 2020 From: stephane at sdf.org (Stephane Tougard) Date: Sun, 30 Aug 2020 17:08:07 +0800 Subject: Threading plus multiprocessing plus cv2 error References: <20200829182410.4d3633f1@e7240.home> <5f1lkf9343bqu3u0ius28rh63o255d433a@4ax.com> Message-ID: On 2020-08-30, Chris Angelico wrote: >> I'm not even that makes sense, how 2 processes can share a thread ? >> > They can't. However, they can share a Thread object, which is the > Python representation of a thread. That can lead to confusion, and > possibly the OP's error (I don't know for sure, I'm just positing). A fork() is a copy of a process in a new process. If this process has a thread (or several), they are part of the copy and the new process has those threads as well. Unless there is a memory sharing between those processes, what happens on one thread in the first process is totally independant of what happens in the copy of this thread in the other process. I'm not specialist on multi-threading in Python, but it should not change anything. Both processes (father and child) don't share the same thread, each one has its own copy of the thread. From Gronicus at SGA.Ninja Sun Aug 30 06:07:23 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sun, 30 Aug 2020 06:07:23 -0400 Subject: Problem running a FOR loop In-Reply-To: References: <000001d67eab$5bca72b0$135f5810$@SGA.Ninja> Message-ID: <000001d67eb5$5b9b40d0$12d1c270$@SGA.Ninja> Yes, that first option worked. Special thanks... Steve =============================== Footnote: If 666 is considered evil, then technically, 25.8069758 is the root of all evil. -----Original Message----- From: Python-list On Behalf Of Peter Otten Sent: Sunday, August 30, 2020 5:29 AM To: python-list at python.org Subject: Re: Problem running a FOR loop Steve wrote: > Compiles, no syntax errors however, line 82 seems to run only once > when the FOR loop has completed. > Why is that? All fields are to contain the specifications, not just > the last one. It seems that passing the StringVar to the Entry widget is not sufficient to keep it alive. > for lineItem in range(len(ThisList)): > NewSpec = tk.StringVar() > SVRCodeEntered = ttk.Entry(window, width = 15, textvariable = > NewSpec) When the previous NewSpec is overwritten with the current one the previous gets garbage-collected and its value is lost. The straight-forward fix is to introduce a list: new_specs = [] > for lineItem in range(len(ThisList)): > NewSpec = tk.StringVar() new_specs.append(NewSpec) > SVRCodeEntered = ttk.Entry(window, width = 15, textvariable = > NewSpec) Another option is to store the StringVar as an attribute of the Entry: > for lineItem in range(len(ThisList)): > NewSpec = tk.StringVar() > SVRCodeEntered = ttk.Entry(window, width = 15, textvariable = > NewSpec) SVRCodeEntered.new_spec = NewSpec -- https://mail.python.org/mailman/listinfo/python-list From Gronicus at SGA.Ninja Sun Aug 30 07:28:54 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sun, 30 Aug 2020 07:28:54 -0400 Subject: How do I left-justify the information in the labels? Message-ID: <000501d67ec0$bef50e80$3cdf2b80$@SGA.Ninja> for lineItem in range(len(ThisList)): SpecLine, Spec = GetLineByItem(ThisList[y]) OldSpec = Spec NewSpec = " " SVRlabel = ttk.Label(window, text = SpecLine + " "*5) SVRlabel.grid(column = 1, row = x) NewSpec = tk.StringVar() New_Specs.append(NewSpec) SVRCodeEntered = ttk.Entry(window, width = 15, textvariable = NewSpec) SVRCodeEntered.grid(column = 2, row = x, pady = 15) SVRCodeEntered.insert(0, OldSpec) x += 1 y += 1 Steve ============================================================ Footnote: Some mornings it just isn't worth chewing through the leather straps. - From cl at isbd.net Sun Aug 30 10:08:34 2020 From: cl at isbd.net (Chris Green) Date: Sun, 30 Aug 2020 15:08:34 +0100 Subject: Where read() is documented References: Message-ID: <2gos1h-s1ha.ln1@esprimo.zbmc.eu> Stefan Ram wrote: > Chris Green writes: > >I went to sys.stdin but it didn't really lead me easily to the read() > >method. All I actually wanted to know was what was the type of the > >return value of the read() method which is different in Python 2 and 3. > > |>>> import sys > |>>> >>> sys.stdin.read > > |>>> help(sys.stdin.read) > |Help on built-in function read: > | > |read(size=-1, /) method of _io.TextIOWrapper instance > | Read at most n characters from stream. > | > | Read from underlying buffer until we have n characters or we hit EOF. > | If n is negative or omitted, read until EOF. > | > |>>> type(sys.stdin.read()) > |^Z > | > > Note that above it's called a "method" twice and once > a "function". > > (If I would have written the body of the documentation, > I'd use "size" instead of "n" and clearly separate > effects and results, e.g., > > |EFFECTS > | > |If is not negative, read from underlying buffer until > | characters are read or until EOF was read. If > |is negative or omitted, read until EOF. > | > |RESULT > | > |The string read, type str, excluding a possible EOF read. > Yes, I must admit I tend to forget about the 'built-in' documentation that Python has. Coming from assembler, C and C++ one doesn't expect it, so I'm afraid I tend to search the on-line Python documentation. Usually I find what I want but in this particular case I didn't. I must remember the interactive prompt! Thanks. -- Chris Green ? From barry at barrys-emacs.org Sun Aug 30 10:31:55 2020 From: barry at barrys-emacs.org (Barry) Date: Sun, 30 Aug 2020 15:31:55 +0100 Subject: Threading plus multiprocessing plus cv2 error In-Reply-To: References: Message-ID: <35C85C05-1C1A-48B6-9CCA-333CD0704DE2@barrys-emacs.org> > On 30 Aug 2020, at 11:03, Stephane Tougard via Python-list wrote: > > ?On 2020-08-30, Chris Angelico wrote: >>> I'm not even that makes sense, how 2 processes can share a thread ? >>> >> They can't. However, they can share a Thread object, which is the >> Python representation of a thread. That can lead to confusion, and >> possibly the OP's error (I don't know for sure, I'm just positing). > > A fork() is a copy of a process in a new process. If this process has a > thread (or several), they are part of the copy and the new process has > those threads as well. No. See https://www.man7.org/linux/man-pages/man2/fork.2.html which says: ? Note the following further points: * The child process is created with a single thread?the one that called fork(). The entire virtual address space of the parent is replicated in the child, including the states of mutexes, condition variables, and other pthreads objects; the use of pthread_atfork(3) may be helpful for dealing with problems that this can cause.? Barry > > Unless there is a memory sharing between those processes, what happens > on one thread in the first process is totally independant of what > happens in the copy of this thread in the other process. > > I'm not specialist on multi-threading in Python, but it should not > change anything. Both processes (father and child) don't share the same > thread, each one has its own copy of the thread. > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Sun Aug 30 10:32:10 2020 From: __peter__ at web.de (Peter Otten) Date: Sun, 30 Aug 2020 16:32:10 +0200 Subject: How do I left-justify the information in the labels? References: <000501d67ec0$bef50e80$3cdf2b80$@SGA.Ninja> Message-ID: Steve wrote: > How do I left-justify the information in the labels? > SVRlabel = ttk.Label(window, text = SpecLine + " "*5) > SVRlabel.grid(column = 1, row = x) The text in the labels already is left-justified -- but the labels themselves are centered inside the grid cells. You can change that with label = ttk.Label(window, text=SpecLine) label.grid(column=1, row=x, sticky=tkinter.W) # W for "west" See https://tkdocs.com/shipman/grid.html. From Gronicus at SGA.Ninja Sun Aug 30 11:24:37 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sun, 30 Aug 2020 11:24:37 -0400 Subject: How do I left-justify the information in the labels? In-Reply-To: References: <000501d67ec0$bef50e80$3cdf2b80$@SGA.Ninja> Message-ID: <003001d67ee1$ad049b70$070dd250$@SGA.Ninja> It turned out to be "sticky=tk.W" instead of "sticky=tkinter.w" Probably because I have "import tkinter as tk" It does work though. Mischief Managed.... Steve FootNote: If money does not grow on trees, then why do banks have branches? -----Original Message----- From: Python-list On Behalf Of Peter Otten Sent: Sunday, August 30, 2020 10:32 AM To: python-list at python.org Subject: Re: How do I left-justify the information in the labels? Steve wrote: > How do I left-justify the information in the labels? > SVRlabel = ttk.Label(window, text = SpecLine + " "*5) > SVRlabel.grid(column = 1, row = x) The text in the labels already is left-justified -- but the labels themselves are centered inside the grid cells. You can change that with label = ttk.Label(window, text=SpecLine) label.grid(column=1, row=x, sticky=tkinter.W) # W for "west" See https://tkdocs.com/shipman/grid.html. -- https://mail.python.org/mailman/listinfo/python-list From python at mrabarnett.plus.com Sun Aug 30 11:25:44 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 30 Aug 2020 16:25:44 +0100 Subject: Video file to subtitles file In-Reply-To: <0f089fb8-8a2d-4739-960c-8a3d34dfb735n@googlegroups.com> References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> <88f95135-c790-40ff-ad0e-b8dd77070993n@googlegroups.com> <0f089fb8-8a2d-4739-960c-8a3d34dfb735n@googlegroups.com> Message-ID: <2b43517b-072f-70be-0461-2683dfd58710@mrabarnett.plus.com> On 2020-08-30 07:23, Muskan Sanghai wrote: > On Sunday, August 30, 2020 at 11:46:15 AM UTC+5:30, Chris Angelico wrote: >> On Sun, Aug 30, 2020 at 4:11 PM Muskan Sanghai wrote: >> > >> > On Sunday, August 30, 2020 at 10:57:00 AM UTC+5:30, Christian Gollwitzer wrote: >> > > Am 29.08.20 um 13:51 schrieb Muskan Sanghai: >> > > > I want to extract subtitles from a MPEG video (which does not have any previous subtitles) >> > > I'm still not sure I get it. "Extract" subtitles, when they are NOT >> > > there? Can it be, by any chance, that you are talking about speech >> > > recognition? I.e., you want a software which understands the spoken word >> > > in the movie sound and turns that into text, which can be shown as >> > > subtitles? Like the "auto-generated" subtitles which youtube offers for >> > > some videos. >> > > >> > > If so, it is a complex task and will not work overly well. I defer to >> > > the experts if there are any usable speech recognitino engines for this >> > > task. >> > > >> > > Christian >> > Yes, this is what I exactly want to do. I want to create a software which understands the spoken word in the movie sound and turns that into text. >> > >> I recommend looking into CMU Sphinx then. I've used that from Python. >> >> The results are highly entertaining. >> >> ChrisA > Okay I will try it, thank you. > Speech recognition works best when there's a single voice, speaking clearly, with little or no background noise. Movies tend not to be like that. Which is why the results are "highly entertaining"... From auriocus at gmx.de Sun Aug 30 13:10:35 2020 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 30 Aug 2020 19:10:35 +0200 Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> <88f95135-c790-40ff-ad0e-b8dd77070993n@googlegroups.com> <0f089fb8-8a2d-4739-960c-8a3d34dfb735n@googlegroups.com> <2b43517b-072f-70be-0461-2683dfd58710@mrabarnett.plus.com> Message-ID: Am 30.08.20 um 17:25 schrieb MRAB: > On 2020-08-30 07:23, Muskan Sanghai wrote: >> On Sunday, August 30, 2020 at 11:46:15 AM UTC+5:30, Chris Angelico wrote: >>> I recommend looking into CMU Sphinx then. I've used that from Python. >>> The results are highly entertaining. >>> ChrisA >> Okay I will try it, thank you. >> > Speech recognition works best when there's a single voice, speaking > clearly, with little or no background noise. Movies tend not to be like > that. > > Which is why the results are "highly entertaining"... Well, with enough effort it is possible to build a system that is more useful than "entertaining". Google did that, English youtube videos can be annotated with subtitles from speech recognition. For example, try this video: https://www.youtube.com/watch?v=lYVLpC_8SQE Go to the settings thing (the little gear icon in the nav bar) and switch on subtitles, English autogenerated. You'll see a word-by-word transcription of the text, and most of it is accurate. There are strong arguments that anything one can build with open source tools will be inferior. 1) They'll probably have a bunch of highly qualified KI experts working on this thing 2) They have an enormous corpus of training data. Many videos already have user-provided subtitles. They can feed all of this into the training. I'm waiting to be disproven on this point ;) Christian From Gronicus at SGA.Ninja Sun Aug 30 13:15:15 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sun, 30 Aug 2020 13:15:15 -0400 Subject: How do I pull the updated information from a tkinter form? Message-ID: <004b01d67ef1$216eb590$644c20b0$@SGA.Ninja> # With this program, I can read the information from # Specifications.txt file and display it on a form. # The user can then update/modify the fields. This is # all working fine and beeautifully... # # I now need to reverse the process and replace the # adjusted lines of data back into the Specifications.txt # file. Fortunately, that code has already been # written . # What I cannot seem to do is to pull the adjusted # information from the form into variables, or a # list/array, so that can be used for the update to the file. # Suggestions for what to look up to study this # through will help. # # Thank you # Steve # --------------------------------------------------------------- import tkinter as tk from tkinter import ttk import sys ThisList = ["start"] #=============================================================== def FillTheList(): x=0 ThisList = [] with open("Specifications.txt", 'r') as infile: for lineEQN in infile: # loop to find each line in the file for that dose if lineEQN[0:1] == "-": # Lines with "-" in space 1 have special recognition for this form ListItem = lineEQN[1:6].strip() # Remove any spaces before and after ThisList.append(ListItem) #Add the ListItem to ThisList return(ThisList) #==================================================================== def EditDataByForm(): window = tk.Tk() window.title("Python Tkinter Text Box") window.minsize(700,700) #height, width #=============================================================== def GetLineByItem(DataType): #get line by item in column 3 - 5 #print("DataType = " + DataType) DataLetter = DataType[0:1] #Capture item letter ID for file check if DataLetter.isupper(): # == "Specs": FileToBeEdited = "Specifications.txt" else: FileToBeEdited = "DataSpecifications.txt" with open(FileToBeEdited, 'r') as infile: for lineEQN in infile: # loop to find each line in the file for that dose if ((lineEQN[1:2]== DataLetter)): A = lineEQN[1:46] # Whole Line a = lineEQN[34:46].strip() # Just the Data # print("A = " + A ) # print("a = " + a) return(A, a) #Return the line and Data separately #=============================================================== def ClickSubmit(): window.destroy() #=============================================================== label = ttk.Label(window, text = "Enter the new readings") label.grid(column = 1, row = 1) ThisList = FillTheList() x = 3 # Allows for two rows at the top of the form used for headers y = 0 # Scans the datafile to fill the list New_Specs = [] #SpecsToUpdate = [] for lineItem in range(len(ThisList)): SpecLine, Spec = GetLineByItem(ThisList[y]) OldSpec = Spec NewSpec = " " SVRlabel = ttk.Label(window, text = SpecLine + " "*5) SVRlabel.grid(column = 1, row = x, sticky=tk.W) NewSpec = tk.StringVar() New_Specs.append(NewSpec) SVRCodeEntered = ttk.Entry(window, width = 15, textvariable = NewSpec) SVRCodeEntered.grid(column = 2, row = x, pady = 15, sticky=tk.W) SVRCodeEntered.insert(0, OldSpec) x += 1 y += 1 #=============================================================== button = ttk.Button(window, text = "Submit", command = ClickSubmit) button.grid(column= 2, row = 15) window.mainloop() #=============================================================== EditDataByForm() print ("Done") # Code needed to pull the updated fields from the form # as variables or in a list/array. Once I have that, the code to replace # code in the specifications.txt file has already been written. # Here is a sample of the Specifications.txt file: ---------------------------------------------------------------------------- --------------------------------------- -E MSN Monitor Serial Number JNGY263-T4464 ## - -F TSL TestStrip Lot Number 45001 82990 ## -G SED Strip Expire Date 2021-05-31 ## - -H SSC Sensor Sequence Code 71 ## -I SCN Sensor Code Number G03 ## -J SSN Sensor Serial Number 2021-01-31 ## -K SDE Sensor Date to Expire 2021-01-31 ## -L SDN Sensor Day Number 12 ## -M FDS First Date for Sensor Fri Aug 17, 2020 09:34 ## - -N IDT Insulin Dose Total 450 ## ---------------------------------------------------------------------------- ---------------------------- Footnote: Some mornings it just isn't worth chewing through the leather straps. From __peter__ at web.de Sun Aug 30 13:55:05 2020 From: __peter__ at web.de (Peter Otten) Date: Sun, 30 Aug 2020 19:55:05 +0200 Subject: How do I pull the updated information from a tkinter form? References: <004b01d67ef1$216eb590$644c20b0$@SGA.Ninja> Message-ID: Steve wrote: > #What I cannot seem to do is to pull the adjusted > #information from the form into variables, or a > #list/array, so that can be used for the update to the file. The updated data is in the StringVar-s, which, fortunately, you have available in a list ;) So: > def EditDataByForm(): [...] > window.mainloop() return [spec.get() for spec in New_Specs] print(EditDataByForm()) > print ("Done") From Gronicus at SGA.Ninja Sun Aug 30 14:20:22 2020 From: Gronicus at SGA.Ninja (Steve) Date: Sun, 30 Aug 2020 14:20:22 -0400 Subject: How do I pull the updated information from a tkinter form? In-Reply-To: References: <004b01d67ef1$216eb590$644c20b0$@SGA.Ninja> Message-ID: <005601d67efa$3a439640$aecac2c0$@SGA.Ninja> OK, I was closer than I thought. Two weeks ago, the concept of tkinter and these forms were totally new to me as well as, about two days ago, python list was totally new too. I somehow thought that "window.mainloop()" was supposed to be the last entry in the function, silly me... I did not think of returning the list. Thank you, now it is back for another 30 hours of continuous programming... (: Steve Footnote: "What rhymes with orange?" "No it doesn't.." -----Original Message----- From: Python-list On Behalf Of Peter Otten Sent: Sunday, August 30, 2020 1:55 PM To: python-list at python.org Subject: Re: How do I pull the updated information from a tkinter form? Steve wrote: > #What I cannot seem to do is to pull the adjusted #information from > the form into variables, or a #list/array, so that can be used for the > update to the file. The updated data is in the StringVar-s, which, fortunately, you have available in a list ;) So: > def EditDataByForm(): [...] > window.mainloop() return [spec.get() for spec in New_Specs] print(EditDataByForm()) > print ("Done") -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sun Aug 30 15:26:27 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 31 Aug 2020 05:26:27 +1000 Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> <88f95135-c790-40ff-ad0e-b8dd77070993n@googlegroups.com> <0f089fb8-8a2d-4739-960c-8a3d34dfb735n@googlegroups.com> <2b43517b-072f-70be-0461-2683dfd58710@mrabarnett.plus.com> Message-ID: On Mon, Aug 31, 2020 at 3:16 AM Christian Gollwitzer wrote: > > Am 30.08.20 um 17:25 schrieb MRAB: > > On 2020-08-30 07:23, Muskan Sanghai wrote: > >> On Sunday, August 30, 2020 at 11:46:15 AM UTC+5:30, Chris Angelico wrote: > >>> I recommend looking into CMU Sphinx then. I've used that from Python. > >>> The results are highly entertaining. > >>> ChrisA > >> Okay I will try it, thank you. > >> > > Speech recognition works best when there's a single voice, speaking > > clearly, with little or no background noise. Movies tend not to be like > > that. > > > > Which is why the results are "highly entertaining"... > > > Well, with enough effort it is possible to build a system that is more > useful than "entertaining". Google did that, English youtube videos can > be annotated with subtitles from speech recognition. For example, try > this video: > https://www.youtube.com/watch?v=lYVLpC_8SQE > > Go to the settings thing (the little gear icon in the nav bar) and > switch on subtitles, English autogenerated. You'll see a word-by-word > transcription of the text, and most of it is accurate. > > There are strong arguments that anything one can build with open source > tools will be inferior. 1) They'll probably have a bunch of highly > qualified KI experts working on this thing 2) They have an enormous > corpus of training data. Many videos already have user-provided > subtitles. They can feed all of this into the training. > > I'm waiting to be disproven on this point ;) > The OP doesn't want to use Google's services for this. That doesn't disprove your point, but....... :) ChrisA From python at mrabarnett.plus.com Sun Aug 30 15:43:05 2020 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 30 Aug 2020 20:43:05 +0100 Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> <88f95135-c790-40ff-ad0e-b8dd77070993n@googlegroups.com> <0f089fb8-8a2d-4739-960c-8a3d34dfb735n@googlegroups.com> <2b43517b-072f-70be-0461-2683dfd58710@mrabarnett.plus.com> Message-ID: <090f6bf9-8b73-9e63-3be1-1d3369d50d77@mrabarnett.plus.com> On 2020-08-30 18:10, Christian Gollwitzer wrote: > Am 30.08.20 um 17:25 schrieb MRAB: >> On 2020-08-30 07:23, Muskan Sanghai wrote: >>> On Sunday, August 30, 2020 at 11:46:15 AM UTC+5:30, Chris Angelico wrote: >>>> I recommend looking into CMU Sphinx then. I've used that from Python. >>>> The results are highly entertaining. >>>> ChrisA >>> Okay I will try it, thank you. >>> >> Speech recognition works best when there's a single voice, speaking >> clearly, with little or no background noise. Movies tend not to be like >> that. >> >> Which is why the results are "highly entertaining"... > > > Well, with enough effort it is possible to build a system that is more > useful than "entertaining". Google did that, English youtube videos can > be annotated with subtitles from speech recognition. For example, try > this video: > https://www.youtube.com/watch?v=lYVLpC_8SQE > > Go to the settings thing (the little gear icon in the nav bar) and > switch on subtitles, English autogenerated. You'll see a word-by-word > transcription of the text, and most of it is accurate. > There's not much background noise there; it takes place in a quiet room. > There are strong arguments that anything one can build with open source > tools will be inferior. 1) They'll probably have a bunch of highly > qualified KI experts working on this thing 2) They have an enormous > corpus of training data. Many videos already have user-provided > subtitles. They can feed all of this into the training. > > I'm waiting to be disproven on this point ;) > From stephane at sdf.org Sun Aug 30 17:37:45 2020 From: stephane at sdf.org (Stephane Tougard) Date: Mon, 31 Aug 2020 05:37:45 +0800 Subject: Threading plus multiprocessing plus cv2 error References: <35C85C05-1C1A-48B6-9CCA-333CD0704DE2@barrys-emacs.org> Message-ID: <9qit1h-a5o.ln1@superman.unices.org> On 2020-08-30, Barry wrote: > * The child process is created with a single thread?the one that > called fork(). The entire virtual address space of the parent is > replicated in the child, including the states of mutexes, > condition variables, and other pthreads objects; the use of > pthread_atfork(3) may be helpful for dealing with problems that Indeed, I have a similar entry on my NetBSD: In case of a threaded program, only the thread calling fork() is still running in the child processes. Very interesting. From cs at cskk.id.au Sun Aug 30 22:32:50 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 31 Aug 2020 12:32:50 +1000 Subject: Symlinks already present In-Reply-To: References: Message-ID: <20200831023250.GA70105@cskk.homeip.net> On 27Jul2020 22:19, Grant Edwards wrote: >On 2020-07-27, Termoregolato wrote: >> Il 26/07/20 22:47, dn ha scritto: >>> Thus, compare the results of the two calls to detect a difference. >> >> I will try also another way, If I don't err symlinks and original >> directory have the same inode number (I talk about Linux, where I'm >> using the application). > >You err. Symlinks are distinct i-nodes which are not the same i-node >as the destination. A symlink is basically a file containing a string >that is read and then used a path to another file. We need to be careful with terminology (just for clarity). Each "source" symlink has its own inode. But if you os.stat() the symlink it follows the symlink and you get the inode for the "target" directory - two symlinks which point at the same directory will return the same inode and thus (st_dev,st_ino) in that stat result. That can be used for comparison, and you don't need to readlink or anything like that - let the OS do it all for you during the os.stat() call. >If you create a "hard" link (ln without the '-s') then you end up a single >i-node that has entries in multiple directories. Aye. >[old-Unix-guy story: Way back when, SunOS used to allow you (if root) >to create a hard link to a directory. It's not something you did a >second time.] It's a well defined operation. There are some policy choices an OS can make about some of the side effects (how does pwd work? how you got there? or some underlying "real" path - this spills over into "what does ".." mean?), etc. But having made those choices, the idea is just fine. As a counter example, many rsync based backup systems have the following underlying approach: - make a new directory tree with every file hardlinked from the previous backup tree - rsync into the new tree, because rsync unlinks and replaces changed files By contrast, MacOS Time Machine utilitises hardlinking directories on HFS volumes: instead of making a new directory tree full of hardlinks you just hardlink the top directory itself if nothing inside it has been changed. Cheers, Cameron Simpson From cs at cskk.id.au Sun Aug 30 22:23:31 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 31 Aug 2020 12:23:31 +1000 Subject: Symlinks already present In-Reply-To: References: Message-ID: <20200831022331.GA55530@cskk.homeip.net> On 27Jul2020 20:20, Termoregolato wrote: >Il 26/07/20 20:39, Dennis Lee Bieber ha scritto: >>Since symbolic links are essentially just short files containing the >>path to the eventual target file/directory, with an OS flag that the file >>is a link > >Yes, I use them massively to give to a lot of directories a kind of >order, depending on their contents. It's simple to see if link is >broken, but not if they're duplicate Hmm. If you're scanning them all, you can at least cache the (dev,ino) of the link target. So broken is stat-failed. Duplicate is seen-this-(dev,ino)-before. You only need the stat, not to (for example) resolve the path the symlink becomes. You've probably thought of this already of cource. Cheers, Cameron Simpson From rosuav at gmail.com Mon Aug 31 00:20:17 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 31 Aug 2020 14:20:17 +1000 Subject: Symlinks already present In-Reply-To: <20200831023250.GA70105@cskk.homeip.net> References: <20200831023250.GA70105@cskk.homeip.net> Message-ID: On Mon, Aug 31, 2020 at 1:17 PM Cameron Simpson wrote: > Each "source" symlink has its own inode. But if you os.stat() the > symlink it follows the symlink and you get the inode for the "target" > directory - two symlinks which point at the same directory will return the same > inode and thus (st_dev,st_ino) in that stat result. > > That can be used for comparison, and you don't need to readlink or > anything like that - let the OS do it all for you during the os.stat() > call. Note that this is only the case if os.stat is called with follow_symlinks=True, which is the default, but isn't the only way to do things. And if you get stat results while you're iterating over a directory, you don't follow symlinks. > >[old-Unix-guy story: Way back when, SunOS used to allow you (if root) > >to create a hard link to a directory. It's not something you did a > >second time.] > > It's a well defined operation. There are some policy choices an OS can > make about some of the side effects (how does pwd work? how you got > there? or some underlying "real" path - this spills over into "what does > ".." mean?), etc. But having made those choices, the idea is just fine. Is it well defined? Because of the ".." issue, it's not going to be as symmetric as hardlinking files is. You can move a file by hardlinking it and then unlinking the original name. If you do that with a directory, at what point do you update its parent pointer? What happens if you create TWO more hardlinks, and then unlink the original name? Can you even *have* a single concept of a "real path" without it basically just being symlinks in disguise? BTW, the pwd issue actually isn't an issue, since it really *will* be "how you got there". You can see that with modern systems if you have symlinks in the path, or rename a directory: rosuav at sikorsky:~/tmp$ mkdir -p a/b/c/d/e rosuav at sikorsky:~/tmp$ cd a/b/c/d/e rosuav at sikorsky:~/tmp/a/b/c/d/e$ mv ~/tmp/a/{b,q} rosuav at sikorsky:~/tmp/a/b/c/d/e$ pwd /home/rosuav/tmp/a/b/c/d/e rosuav at sikorsky:~/tmp/a/b/c/d/e$ cd `pwd` bash: cd: /home/rosuav/tmp/a/b/c/d/e: No such file or directory rosuav at sikorsky:~/tmp/a/b/c/d/e$ ls -al total 8 drwxr-xr-x 2 rosuav rosuav 4096 Aug 31 14:17 . drwxr-xr-x 3 rosuav rosuav 4096 Aug 31 14:17 .. rosuav at sikorsky:~/tmp/a/b/c/d/e$ cd .. rosuav at sikorsky:~/tmp/a/q/c/d$ pwd /home/rosuav/tmp/a/q/c/d rosuav at sikorsky:~/tmp/a/q/c/d$ As soon as I try to go to the parent, it has to figure out what the real path to that parent is. Otherwise, it's just the path that I typed to get there - even though that might no longer be correct. (There have been times, for instance, when I'm in a "dead" directory and have to cd `pwd` to get back to the "real" directory with the same name.) The parent directory is crucially important here. ChrisA From auriocus at gmx.de Mon Aug 31 01:34:02 2020 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 31 Aug 2020 07:34:02 +0200 Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> <88f95135-c790-40ff-ad0e-b8dd77070993n@googlegroups.com> <0f089fb8-8a2d-4739-960c-8a3d34dfb735n@googlegroups.com> <2b43517b-072f-70be-0461-2683dfd58710@mrabarnett.plus.com> <090f6bf9-8b73-9e63-3be1-1d3369d50d77@mrabarnett.plus.com> Message-ID: Am 30.08.20 um 21:43 schrieb MRAB: > On 2020-08-30 18:10, Christian Gollwitzer wrote: >> Well, with enough effort it is possible to build a system that is more >> useful than "entertaining". Google did that, English youtube videos can >> be annotated with subtitles from speech recognition. For example, try >> this video: >> https://www.youtube.com/watch?v=lYVLpC_8SQE >> >> > There's not much background noise there; it takes place in a quiet room. It becomes a bit worse once the background music sets in, but still is usable. Feel free to try any other video. I think, it works with any video in English. I think that for "Hollywood"-style movies you will always have a crisp sound of the speech. They want the viewers to listen effortlessly - background music is typical, "true" noise is rare. Maybe try with this video: https://www.youtube.com/watch?v=nHn4XpKA6vM As soon as they are up in the air you have the engine sound overlaying the speech, and still the transcription is quite good. It sometimes mistakes the flapping of the engine as "applause" and misses a word or a sentence, but still very good. Christian From rosuav at gmail.com Mon Aug 31 02:11:30 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 31 Aug 2020 16:11:30 +1000 Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> <88f95135-c790-40ff-ad0e-b8dd77070993n@googlegroups.com> <0f089fb8-8a2d-4739-960c-8a3d34dfb735n@googlegroups.com> <2b43517b-072f-70be-0461-2683dfd58710@mrabarnett.plus.com> <090f6bf9-8b73-9e63-3be1-1d3369d50d77@mrabarnett.plus.com> Message-ID: On Mon, Aug 31, 2020 at 3:36 PM Christian Gollwitzer wrote: > > Am 30.08.20 um 21:43 schrieb MRAB: > > On 2020-08-30 18:10, Christian Gollwitzer wrote: > >> Well, with enough effort it is possible to build a system that is more > >> useful than "entertaining". Google did that, English youtube videos can > >> be annotated with subtitles from speech recognition. For example, try > >> this video: > >> https://www.youtube.com/watch?v=lYVLpC_8SQE > >> > >> > > There's not much background noise there; it takes place in a quiet room. > > It becomes a bit worse once the background music sets in, but still is > usable. Feel free to try any other video. I think, it works with any > video in English. > > I think that for "Hollywood"-style movies you will always have a crisp > sound of the speech. They want the viewers to listen effortlessly - > background music is typical, "true" noise is rare. > > Maybe try with this video: > https://www.youtube.com/watch?v=nHn4XpKA6vM > > As soon as they are up in the air you have the engine sound overlaying > the speech, and still the transcription is quite good. It sometimes > mistakes the flapping of the engine as "applause" and misses a word or a > sentence, but still very good. > But remember, the OP specifically does NOT want to use Google or Amazon services for this. What you're showcasing here has been trained on the gigantic corpus of Youtube videos, and that's simply not going to be practical to recreate. When I said the results were "entertaining", I was talking about what CMU Sphinx is capable of without any assistance (and also what I've seen from numerous real-time captioning tools across the internet). Sometimes it's reasonable... sometimes it just isn't. ChrisA From cs at cskk.id.au Mon Aug 31 03:26:35 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 31 Aug 2020 17:26:35 +1000 Subject: Symlinks already present In-Reply-To: References: Message-ID: <20200831072635.GA27335@cskk.homeip.net> On 31Aug2020 14:20, Chris Angelico wrote: >On Mon, Aug 31, 2020 at 1:17 PM Cameron Simpson wrote: >> Each "source" symlink has its own inode. But if you os.stat() the >> symlink it follows the symlink and you get the inode for the "target" >> directory - two symlinks which point at the same directory will return the same >> inode and thus (st_dev,st_ino) in that stat result. >> >> That can be used for comparison, and you don't need to readlink or >> anything like that - let the OS do it all for you during the os.stat() >> call. > >Note that this is only the case if os.stat is called with >follow_symlinks=True, which is the default, but isn't the only way to >do things. Maybe not, but it is the way I'm suggesting. >> >[old-Unix-guy story: Way back when, SunOS used to allow you (if >> >root) >> >to create a hard link to a directory. It's not something you did a >> >second time.] >> >> It's a well defined operation. There are some policy choices an OS can >> make about some of the side effects (how does pwd work? how you got >> there? or some underlying "real" path - this spills over into "what does >> ".." mean?), etc. But having made those choices, the idea is just fine. > >Is it well defined? It can be well defined. Probably should have phrased it that way. >Because of the ".." issue, it's not going to be as >symmetric as hardlinking files is. You can move a file by hardlinking >it and then unlinking the original name. If you do that with a >directory, at what point do you update its parent pointer? What >happens if you create TWO more hardlinks, and then unlink the original >name? Can you even *have* a single concept of a "real path" without it >basically just being symlinks in disguise? Shrug. Who says ".." is wired to the directory, and not the user's process context? Who says a wired to the directory ".." needs changing at any time except when its referring link count goes to 1? There are many choices here. Making those choices is a policy decision for the OS implementor, and they all have their costs and benefits. >BTW, the pwd issue actually isn't an issue, since it really *will* be >"how you got there". You can see that with modern systems if you have >symlinks in the path, or rename a directory: [...snip...] Yeah, makes me ill. That's because these days "pwd" is usually a shell builtin with funny semantics and a cache/sanity=check against $PWD (which gets computed as you cd around, typically). And if has a -P option and friends explicitly because of this hideous stuff. Cheers, Cameron Simpson From rosuav at gmail.com Mon Aug 31 03:35:12 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 31 Aug 2020 17:35:12 +1000 Subject: Symlinks already present In-Reply-To: <20200831072635.GA27335@cskk.homeip.net> References: <20200831072635.GA27335@cskk.homeip.net> Message-ID: On Mon, Aug 31, 2020 at 5:28 PM Cameron Simpson wrote: > >Because of the ".." issue, it's not going to be as > >symmetric as hardlinking files is. You can move a file by hardlinking > >it and then unlinking the original name. If you do that with a > >directory, at what point do you update its parent pointer? What > >happens if you create TWO more hardlinks, and then unlink the original > >name? Can you even *have* a single concept of a "real path" without it > >basically just being symlinks in disguise? > > Shrug. Who says ".." is wired to the directory, and not the user's > process context? Who says a wired to the directory ".." needs changing > at any time except when its referring link count goes to 1? There are > many choices here. Making those choices is a policy decision for the OS > implementor, and they all have their costs and benefits. > Consider the situation I posed: start with one reference to the directory, add two more, then remove the original. Where is its parent? Is there any good way to handle that? And if you allow hardlinking of directories at all, there's no reason to block this particular sequence of operations. A naive reading of your description is that the parent, in this situation, would remain unchanged - which means the parent is some completely unrelated directory. Or, worse, it could end up with a parent of itself, or a parent of its own child. Are you SURE it can be well-defined? ChrisA From __peter__ at web.de Mon Aug 31 03:56:09 2020 From: __peter__ at web.de (Peter Otten) Date: Mon, 31 Aug 2020 09:56:09 +0200 Subject: How do I pull the updated information from a tkinter form? References: <004b01d67ef1$216eb590$644c20b0$@SGA.Ninja> <005601d67efa$3a439640$aecac2c0$@SGA.Ninja> Message-ID: Steve wrote: > OK, I was closer than I thought. > > Two weeks ago, the concept of tkinter and these forms were totally new to > me > as well as, about two days ago, python list was totally new too. I > somehow thought that "window.mainloop()" was supposed to be the last entry > in the function, silly me... > I did not think of returning the list. Note that what I showed is probably not the best option. Usually you would add a button that allows the user to trigger the write operation. From Gronicus at SGA.Ninja Mon Aug 31 04:09:30 2020 From: Gronicus at SGA.Ninja (Steve) Date: Mon, 31 Aug 2020 04:09:30 -0400 Subject: How do I pull the updated information from a tkinter form? In-Reply-To: References: <004b01d67ef1$216eb590$644c20b0$@SGA.Ninja> <005601d67efa$3a439640$aecac2c0$@SGA.Ninja> Message-ID: <008d01d67f6e$0e149b90$2a3dd2b0$@SGA.Ninja> At least it is working and lets me continue to develop the overall program. I am working on the option to cancel the update if the user wants. Since I do not know of a better way, is it not the best at the moment? (-: My original design to edit the specifications by form was approaching 200 lines of code. With the loops, probably now is 75..... Steve FootNote: If money does not grow on trees, then why do banks have branches? -----Original Message----- From: Python-list On Behalf Of Peter Otten Sent: Monday, August 31, 2020 3:56 AM To: python-list at python.org Subject: RE: How do I pull the updated information from a tkinter form? Steve wrote: > OK, I was closer than I thought. > > Two weeks ago, the concept of tkinter and these forms were totally new > to me as well as, about two days ago, python list was totally new > too. I somehow thought that "window.mainloop()" was supposed to be the > last entry in the function, silly me... > I did not think of returning the list. Note that what I showed is probably not the best option. Usually you would add a button that allows the user to trigger the write operation. -- https://mail.python.org/mailman/listinfo/python-list From lizzyhollins99 at gmail.com Mon Aug 31 07:40:46 2020 From: lizzyhollins99 at gmail.com (Betty Hollinshead) Date: Mon, 31 Aug 2020 04:40:46 -0700 (PDT) Subject: Video file to subtitles file In-Reply-To: References: <3f2154c1-e261-47b8-aaba-b426cce617f1n@googlegroups.com> <5c4fabe0-2b71-4fa6-9088-54424b7891ecn@googlegroups.com> <88f95135-c790-40ff-ad0e-b8dd77070993n@googlegroups.com> <0f089fb8-8a2d-4739-960c-8a3d34dfb735n@googlegroups.com> <2b43517b-072f-70be-0461-2683dfd58710@mrabarnett.plus.com> <090f6bf9-8b73-9e63-3be1-1d3369d50d77@mrabarnett.plus.com> Message-ID: <11555c6b-96f5-40a6-a181-64c2ba89137an@googlegroups.com> ffmpeg mentioned elsewhere is the goto toolkit for all things video. Subtitles, see: https://trac.ffmpeg.org/wiki/ExtractSubtitles B. From Richard at Damon-Family.org Mon Aug 31 07:55:36 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Mon, 31 Aug 2020 07:55:36 -0400 Subject: Symlinks already present In-Reply-To: References: <20200831072635.GA27335@cskk.homeip.net> Message-ID: <0a196beb-cdc6-8045-79b2-684b6241fda5@Damon-Family.org> On 8/31/20 3:35 AM, Chris Angelico wrote: > On Mon, Aug 31, 2020 at 5:28 PM Cameron Simpson wrote: >>> Because of the ".." issue, it's not going to be as >>> symmetric as hardlinking files is. You can move a file by hardlinking >>> it and then unlinking the original name. If you do that with a >>> directory, at what point do you update its parent pointer? What >>> happens if you create TWO more hardlinks, and then unlink the original >>> name? Can you even *have* a single concept of a "real path" without it >>> basically just being symlinks in disguise? >> Shrug. Who says ".." is wired to the directory, and not the user's >> process context? Who says a wired to the directory ".." needs changing >> at any time except when its referring link count goes to 1? There are >> many choices here. Making those choices is a policy decision for the OS >> implementor, and they all have their costs and benefits. >> > Consider the situation I posed: start with one reference to the > directory, add two more, then remove the original. Where is its > parent? Is there any good way to handle that? And if you allow > hardlinking of directories at all, there's no reason to block this > particular sequence of operations. A naive reading of your description > is that the parent, in this situation, would remain unchanged - which > means the parent is some completely unrelated directory. Or, worse, it > could end up with a parent of itself, or a parent of its own child. > > Are you SURE it can be well-defined? > > ChrisA EVERY? reference to the .. file link has to have a full path to that link, either explicit with the reference of implicit via the current working directory. That can define what is the parent. Yes, that says that two references to the 'same' directory (same as in same inode, but different paths) will find a different value for .. in it. So the definition of .. can be well defined, even in the presence of multiple parent directories. -- Richard Damon From rosuav at gmail.com Mon Aug 31 09:00:03 2020 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 31 Aug 2020 23:00:03 +1000 Subject: Symlinks already present In-Reply-To: <0a196beb-cdc6-8045-79b2-684b6241fda5@Damon-Family.org> References: <20200831072635.GA27335@cskk.homeip.net> <0a196beb-cdc6-8045-79b2-684b6241fda5@Damon-Family.org> Message-ID: On Mon, Aug 31, 2020 at 9:57 PM Richard Damon wrote: > > On 8/31/20 3:35 AM, Chris Angelico wrote: > > On Mon, Aug 31, 2020 at 5:28 PM Cameron Simpson wrote: > >>> Because of the ".." issue, it's not going to be as > >>> symmetric as hardlinking files is. You can move a file by hardlinking > >>> it and then unlinking the original name. If you do that with a > >>> directory, at what point do you update its parent pointer? What > >>> happens if you create TWO more hardlinks, and then unlink the original > >>> name? Can you even *have* a single concept of a "real path" without it > >>> basically just being symlinks in disguise? > >> Shrug. Who says ".." is wired to the directory, and not the user's > >> process context? Who says a wired to the directory ".." needs changing > >> at any time except when its referring link count goes to 1? There are > >> many choices here. Making those choices is a policy decision for the OS > >> implementor, and they all have their costs and benefits. > >> > > Consider the situation I posed: start with one reference to the > > directory, add two more, then remove the original. Where is its > > parent? Is there any good way to handle that? And if you allow > > hardlinking of directories at all, there's no reason to block this > > particular sequence of operations. A naive reading of your description > > is that the parent, in this situation, would remain unchanged - which > > means the parent is some completely unrelated directory. Or, worse, it > > could end up with a parent of itself, or a parent of its own child. > > > > Are you SURE it can be well-defined? > > > > ChrisA > > EVERY reference to the .. file link has to have a full path to that > link, either explicit with the reference of implicit via the current > working directory. That can define what is the parent. Yes, that says > that two references to the 'same' directory (same as in same inode, but > different paths) will find a different value for .. in it. So the > definition of .. can be well defined, even in the presence of multiple > parent directories. > That's incompatible with the normal meaning of "..", and it also implies that any time you rename any directory, you have to scan all of its children (recursively) to find any parent directory references that need to change. I'm still not sure how this solves the problem - it just pushes it to everything else, and you still have to have ".." mean multiple things somehow. ChrisA From Richard at Damon-Family.org Mon Aug 31 12:38:34 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Mon, 31 Aug 2020 12:38:34 -0400 Subject: Symlinks already present In-Reply-To: References: <20200831072635.GA27335@cskk.homeip.net> <0a196beb-cdc6-8045-79b2-684b6241fda5@Damon-Family.org> Message-ID: <9dcd2f23-5912-de18-2dbc-ff94eb850d23@Damon-Family.org> On 8/31/20 9:00 AM, Chris Angelico wrote: > On Mon, Aug 31, 2020 at 9:57 PM Richard Damon wrote: >> On 8/31/20 3:35 AM, Chris Angelico wrote: >>> On Mon, Aug 31, 2020 at 5:28 PM Cameron Simpson wrote: >>>>> Because of the ".." issue, it's not going to be as >>>>> symmetric as hardlinking files is. You can move a file by hardlinking >>>>> it and then unlinking the original name. If you do that with a >>>>> directory, at what point do you update its parent pointer? What >>>>> happens if you create TWO more hardlinks, and then unlink the original >>>>> name? Can you even *have* a single concept of a "real path" without it >>>>> basically just being symlinks in disguise? >>>> Shrug. Who says ".." is wired to the directory, and not the user's >>>> process context? Who says a wired to the directory ".." needs changing >>>> at any time except when its referring link count goes to 1? There are >>>> many choices here. Making those choices is a policy decision for the OS >>>> implementor, and they all have their costs and benefits. >>>> >>> Consider the situation I posed: start with one reference to the >>> directory, add two more, then remove the original. Where is its >>> parent? Is there any good way to handle that? And if you allow >>> hardlinking of directories at all, there's no reason to block this >>> particular sequence of operations. A naive reading of your description >>> is that the parent, in this situation, would remain unchanged - which >>> means the parent is some completely unrelated directory. Or, worse, it >>> could end up with a parent of itself, or a parent of its own child. >>> >>> Are you SURE it can be well-defined? >>> >>> ChrisA >> EVERY reference to the .. file link has to have a full path to that >> link, either explicit with the reference of implicit via the current >> working directory. That can define what is the parent. Yes, that says >> that two references to the 'same' directory (same as in same inode, but >> different paths) will find a different value for .. in it. So the >> definition of .. can be well defined, even in the presence of multiple >> parent directories. >> > That's incompatible with the normal meaning of "..", and it also > implies that any time you rename any directory, you have to scan all > of its children (recursively) to find any parent directory references > that need to change. I'm still not sure how this solves the problem - > it just pushes it to everything else, and you still have to have ".." > mean multiple things somehow. > > ChrisA The . and .. entries in a directory don't need to be 'real' entries added to the directory using up directory slots in the directory, but pseudo entries created by the file system when reading a directory. To read a directory, you need to specify it (how else do you say you want to read it), and the meaning of . and .. can be derived from the path used to read the directory. And yes, this means that a given directory, reachable by multiple paths, may give different values for .. (or .) based on which path you came to it from. -- Richard Damon From rosuav at gmail.com Mon Aug 31 12:49:27 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Sep 2020 02:49:27 +1000 Subject: Symlinks already present In-Reply-To: <9dcd2f23-5912-de18-2dbc-ff94eb850d23@Damon-Family.org> References: <20200831072635.GA27335@cskk.homeip.net> <0a196beb-cdc6-8045-79b2-684b6241fda5@Damon-Family.org> <9dcd2f23-5912-de18-2dbc-ff94eb850d23@Damon-Family.org> Message-ID: On Tue, Sep 1, 2020 at 2:40 AM Richard Damon wrote: > > On 8/31/20 9:00 AM, Chris Angelico wrote: > > That's incompatible with the normal meaning of "..", and it also > > implies that any time you rename any directory, you have to scan all > > of its children (recursively) to find any parent directory references > > that need to change. I'm still not sure how this solves the problem - > > it just pushes it to everything else, and you still have to have ".." > > mean multiple things somehow. > > > > ChrisA > > The . and .. entries in a directory don't need to be 'real' entries > added to the directory using up directory slots in the directory, but > pseudo entries created by the file system when reading a directory. To > read a directory, you need to specify it (how else do you say you want > to read it), and the meaning of . and .. can be derived from the path > used to read the directory. You can open a directory (same as you open a file), and then you have an open file descriptor. You can open something relative to something else. And you can chroot in between those two operations, which would mean that there is no complete path that references what you are opening. > And yes, this means that a given directory, reachable by multiple paths, > may give different values for .. (or .) based on which path you came to > it from. That would basically violate the concept of hardlinks, which is that they have the same content regardless of how you access them. What you're suggesting is far better handled by symlinks. ChrisA From barry at barrys-emacs.org Mon Aug 31 13:07:29 2020 From: barry at barrys-emacs.org (Barry Scott) Date: Mon, 31 Aug 2020 18:07:29 +0100 Subject: Symlinks already present In-Reply-To: <9dcd2f23-5912-de18-2dbc-ff94eb850d23@Damon-Family.org> References: <20200831072635.GA27335@cskk.homeip.net> <0a196beb-cdc6-8045-79b2-684b6241fda5@Damon-Family.org> <9dcd2f23-5912-de18-2dbc-ff94eb850d23@Damon-Family.org> Message-ID: > On 31 Aug 2020, at 17:38, Richard Damon wrote: > > On 8/31/20 9:00 AM, Chris Angelico wrote: >> On Mon, Aug 31, 2020 at 9:57 PM Richard Damon wrote: >>> On 8/31/20 3:35 AM, Chris Angelico wrote: >>>> On Mon, Aug 31, 2020 at 5:28 PM Cameron Simpson wrote: >>>>>> Because of the ".." issue, it's not going to be as >>>>>> symmetric as hardlinking files is. You can move a file by hardlinking >>>>>> it and then unlinking the original name. If you do that with a >>>>>> directory, at what point do you update its parent pointer? What >>>>>> happens if you create TWO more hardlinks, and then unlink the original >>>>>> name? Can you even *have* a single concept of a "real path" without it >>>>>> basically just being symlinks in disguise? >>>>> Shrug. Who says ".." is wired to the directory, and not the user's >>>>> process context? Who says a wired to the directory ".." needs changing >>>>> at any time except when its referring link count goes to 1? There are >>>>> many choices here. Making those choices is a policy decision for the OS >>>>> implementor, and they all have their costs and benefits. >>>>> >>>> Consider the situation I posed: start with one reference to the >>>> directory, add two more, then remove the original. Where is its >>>> parent? Is there any good way to handle that? And if you allow >>>> hardlinking of directories at all, there's no reason to block this >>>> particular sequence of operations. A naive reading of your description >>>> is that the parent, in this situation, would remain unchanged - which >>>> means the parent is some completely unrelated directory. Or, worse, it >>>> could end up with a parent of itself, or a parent of its own child. >>>> >>>> Are you SURE it can be well-defined? >>>> >>>> ChrisA >>> EVERY reference to the .. file link has to have a full path to that >>> link, either explicit with the reference of implicit via the current >>> working directory. That can define what is the parent. Yes, that says >>> that two references to the 'same' directory (same as in same inode, but >>> different paths) will find a different value for .. in it. So the >>> definition of .. can be well defined, even in the presence of multiple >>> parent directories. >>> >> That's incompatible with the normal meaning of "..", and it also >> implies that any time you rename any directory, you have to scan all >> of its children (recursively) to find any parent directory references >> that need to change. I'm still not sure how this solves the problem - >> it just pushes it to everything else, and you still have to have ".." >> mean multiple things somehow. >> >> ChrisA > > The . and .. entries in a directory don't need to be 'real' entries > added to the directory using up directory slots in the directory, but > pseudo entries created by the file system when reading a directory. To > read a directory, you need to specify it (how else do you say you want > to read it), and the meaning of . and .. can be derived from the path > used to read the directory. > > And yes, this means that a given directory, reachable by multiple paths, > may give different values for .. (or .) based on which path you came to > it from. I'm intrigued. How are you adding a second path that shows this mutating ".." ? I tried with a symlink and that did not change the ".." inode. Do you mean that I can do this with a bind mount? Barry > > -- > Richard Damon > > -- > https://mail.python.org/mailman/listinfo/python-list From Richard at Damon-Family.org Mon Aug 31 14:55:52 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Mon, 31 Aug 2020 14:55:52 -0400 Subject: Symlinks already present In-Reply-To: References: <20200831072635.GA27335@cskk.homeip.net> <0a196beb-cdc6-8045-79b2-684b6241fda5@Damon-Family.org> <9dcd2f23-5912-de18-2dbc-ff94eb850d23@Damon-Family.org> Message-ID: <862ccd03-ba42-6db8-bf8d-4c372aa0ce6b@Damon-Family.org> On 8/31/20 1:07 PM, Barry Scott wrote: > > I'm intrigued. > > How are you adding a second path that shows this mutating ".." ? > I tried with a symlink and that did not change the ".." inode. > Do you mean that I can do this with a bind mount? > > Barry > This is based on a hypothetical OS that allows creating hard-links to directories, just like to files. Because current *nix system don't do it this way, they don't allow hard-links to directories because it does cause this sort of issue. -- Richard Damon From Richard at Damon-Family.org Mon Aug 31 15:07:21 2020 From: Richard at Damon-Family.org (Richard Damon) Date: Mon, 31 Aug 2020 15:07:21 -0400 Subject: Symlinks already present In-Reply-To: References: <20200831072635.GA27335@cskk.homeip.net> <0a196beb-cdc6-8045-79b2-684b6241fda5@Damon-Family.org> <9dcd2f23-5912-de18-2dbc-ff94eb850d23@Damon-Family.org> Message-ID: On 8/31/20 12:49 PM, Chris Angelico wrote: > On Tue, Sep 1, 2020 at 2:40 AM Richard Damon wrote: >> On 8/31/20 9:00 AM, Chris Angelico wrote: >>> That's incompatible with the normal meaning of "..", and it also >>> implies that any time you rename any directory, you have to scan all >>> of its children (recursively) to find any parent directory references >>> that need to change. I'm still not sure how this solves the problem - >>> it just pushes it to everything else, and you still have to have ".." >>> mean multiple things somehow. >>> >>> ChrisA >> The . and .. entries in a directory don't need to be 'real' entries >> added to the directory using up directory slots in the directory, but >> pseudo entries created by the file system when reading a directory. To >> read a directory, you need to specify it (how else do you say you want >> to read it), and the meaning of . and .. can be derived from the path >> used to read the directory. > You can open a directory (same as you open a file), and then you have > an open file descriptor. You can open something relative to something > else. And you can chroot in between those two operations, which would > mean that there is no complete path that references what you are > opening. The file descriptor could remember the path used to get to it. chroot shows that .. needs to be somewhat special, as it needs to go away for anyone that . is their current root. > >> And yes, this means that a given directory, reachable by multiple paths, >> may give different values for .. (or .) based on which path you came to >> it from. > That would basically violate the concept of hardlinks, which is that > they have the same content regardless of how you access them. What > you're suggesting is far better handled by symlinks. > > ChrisA I see no problem with it being a hardlink, and in fact, executables know the name they were executed by, so directories? knowing the path isn't that different. The key differnce between a hardlink and a symlink is that hardlinks maintain existance, and always point to something that exists (things know how many hardlinks refer to them). symlinks don't reference the actual file object, but the symbolic path to it, which may or may not actually exist, and who doesn't know such a link exists. -- Richard Damon From rosuav at gmail.com Mon Aug 31 18:05:27 2020 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 1 Sep 2020 08:05:27 +1000 Subject: Symlinks already present In-Reply-To: References: <20200831072635.GA27335@cskk.homeip.net> <0a196beb-cdc6-8045-79b2-684b6241fda5@Damon-Family.org> <9dcd2f23-5912-de18-2dbc-ff94eb850d23@Damon-Family.org> Message-ID: On Tue, Sep 1, 2020 at 5:08 AM Richard Damon wrote: > The file descriptor could remember the path used to get to it. chroot > shows that .. needs to be somewhat special, as it needs to go away for > anyone that . is their current root. But my point is that there might not actually *be* a valid path that gets you to a file descriptor. It can't remember something that doesn't exist. (And it's pretty impractical to do that even if it does.) > I see no problem with it being a hardlink, and in fact, executables know > the name they were executed by, so directories knowing the path isn't > that different. Actually no, they don't. They are all taught, and being taught, believe, that their first argument is their name. > The key differnce between a hardlink and a symlink is > that hardlinks maintain existance, and always point to something that > exists (things know how many hardlinks refer to them). symlinks don't > reference the actual file object, but the symbolic path to it, which may > or may not actually exist, and who doesn't know such a link exists. Symlinks refer to a path, which may be relative. Hardlinks refer to an inode (or whatever other way you choose to identify an actual file's contents). It's entirely possible to have an open file or directory that no longer has any actual path referring to it; in fact, things don't know how many hardlinks refer to them, just how many references there are. ChrisA From hjp-python at hjp.at Mon Aug 31 18:28:38 2020 From: hjp-python at hjp.at (Peter J. Holzer) Date: Tue, 1 Sep 2020 00:28:38 +0200 Subject: Another 2 to 3 mail encoding problem In-Reply-To: <7q7k1h-vap31.ln1@esprimo.zbmc.eu> References: <20200826180648.GA19793@hjp.at> <7q7k1h-vap31.ln1@esprimo.zbmc.eu> Message-ID: <20200831222838.GA3937@hjp.at> On 2020-08-27 09:34:47 +0100, Chris Green wrote: > Peter J. Holzer wrote: > > The problem is that the message contains a '\ufeff' character (byte > > order mark) where email/generator.py expects only ASCII characters. > > > > I see two possible reasons for this: [...] > > Both reasons are weird. [...] > > But then you haven't shown where msg comes from. How do you parse the > > message to get "msg"? > > > > Can you construct a minimal test message which triggers the bug? > > > Yes, simply sending myself an E-Mail with (for example) accented > characters triggers the error. Ok. So it's not a specific message, but any mail with accented characters. Since Python's mailbox module handles mails with accented characters just fine (I've processed thousands of mails with it), the bug is almost certainly in your program. And, as I explained above, almost certainly in the part which you didn't show us. Can you reduce your program to the minimum which still triggers the bug and post the result here? 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: