From pjfarley3 at earthlink.net Tue Jun 1 00:52:32 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Tue, 1 Jun 2021 00:52:32 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> Message-ID: <002101d756a1$eeedbc40$ccc934c0$@earthlink.net> > -----Original Message----- > From: Chris Angelico > Sent: Sunday, May 30, 2021 5:47 PM > To: Python > Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn] > > Never had this problem with curses per se (partly because I've used it very little), > but a more general technique for debugging things that don't have a "normal" > console is to create one via a pipe or file. The easiest way is something like: > > log = open("logfile.txt", "w") > print(f"At this point, {foo=}", file=log, flush=True) > > Then, in a separate window - or even on a completely different machine, via SSH > or equivalent - "tail -F logfile.txt" will be your console. Thank Chris. Your method will certainly work, I just used the python logging facilities to do effectively the same thing, but it is a slower debugging process than having the ability to examine the program environment dynamically while it is actually executing but stopped at a chosen breakpoint. Using tail on a Windows system requires non-native facilities (though gnuwin32's tail does a creditable job). I'm used to having the facilities of an interactive debugger available in my day job (not on *ix or Windows systems though), I just thought that interactive debugging would be more the rule than the exception here too. Peter -- From pjfarley3 at earthlink.net Tue Jun 1 00:38:43 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Tue, 1 Jun 2021 00:38:43 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> Message-ID: <001d01d756a0$00ebf9e0$02c3eda0$@earthlink.net> > -----Original Message----- > From: Dennis Lee Bieber > Sent: Sunday, May 30, 2021 4:32 PM > To: python-list at python.org > Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn] > > On Sun, 30 May 2021 13:26:40 -0400, declaimed the > following: > > Follow-up to my prior response (which doesn't seem to have > propagated out and back in to gmane yet). > > >Does anyone here know if winpdb-reborn or any other debugger can > >support 2-window debugging for a python script that uses the curses > >module? It seems to me that a 2-window debugging session is necessary > >for a python script that uses the curses module because using curses > >takes over the screen from which the script is started, so debugging > >output and script output need to be in separate windows. > > > > The winpdb executable itself (with a .py as argument) was doing > NOTHING on my system. Running the winpdb.py file (again with a .py as > argument) instead did open a graphical user interface, AND it opened a new > console window... But that is as far as it went. The winpdb GUI status reported > that it could not find the script (even if I specified a full path to it). > > The File/Launch behaved the same way -- opened a console for the > selected .py, but did not run it... Thank you Dennis. I think I remember having the same issue. From examination of the session_manager.py code at the winpdb_reborn github repo it would appear that the RPDBTERM environment variable needs to be defined on a Windows system at a global level with the value "nt" to get the correct osSpawn dictionary entry to start a new Windows console window. And there may be more that needs to be done to ensure that starting a new CMD.EXE console window gets you into the correct directory. There may need to be additional CMD.EXE options passed into the osSpawn value to get to that working directory where you are actually debugging. Although I do also see code in that same module that *looks" like it should do that job, but it may or may not be working right for a Windows system. I may try winpdb_reborn again using RPDBTERM=nt. Thanks for the several replies, appreciated. Peter From pjfarley3 at earthlink.net Tue Jun 1 00:55:39 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Tue, 1 Jun 2021 00:55:39 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: Message-ID: <002201d756a2$5e4e7610$1aeb6230$@earthlink.net> > -----Original Message----- > From: Cameron Simpson > Sent: Sunday, May 30, 2021 6:07 PM > To: Python > Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn] > > On 31May2021 07:46, Chris Angelico wrote: > Also untried, but should work: > > Open another terminal, note its terminal device with the "tty" command. > Start your programme like this: > > python ...... 2>/dev/tty-of-the-other-termina > > Send debug statements to sys.stderr. They should show in the other window. > > I'd also think one could do some kind of shuffle setting up curses to attach its > display to another terminal, letting you use an interactive debugging in the > invoking terminal. Haven't tried this yet. Thanks Cameron, but that could only work from an *ix console. Not so easy from a Windows console. Peter -- From pjfarley3 at earthlink.net Tue Jun 1 00:41:13 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Tue, 1 Jun 2021 00:41:13 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> Message-ID: <001e01d756a0$5a33a890$0e9af9b0$@earthlink.net> > -----Original Message----- > From: Alan Gauld > Sent: Sunday, May 30, 2021 4:38 PM > To: python-list at python.org > Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn] > > On 30/05/2021 18:26, pjfarley3 at earthlink.net wrote: > > I tried winpdb-reborn some time last year on my Win10 system (python > > 3.8.3 at that time), but could not figure out how to use it to debug a > > python script that uses the curses module. > > You are not alone. debugging curses is one of the biggest obstacles to its use. > > My approach is to define a status line at the bottom of my program and write > print statements into that window. Something like: > > def main(stdwin): > appwin = curses.newwin(...) # LINES-1 high > status = curses.newwin(...) # 1 line high positioned on bottom > # more code here > status.addstr(0,0, "Value of foo = %s" % foo) > > curses.wrapper(main) > > After debugging the status window can either be retained as an application > status bar or removed and the main window enlarged by one line... > > If anyone else has found a better way to debug curses code I'm also keen to > hear! Thanks Alan, interesting idea. And it will work whether you are running in a Windows system or a *ix one. Peter From pablogsal at gmail.com Tue Jun 1 07:06:11 2021 From: pablogsal at gmail.com (Pablo Galindo Salgado) Date: Tue, 1 Jun 2021 12:06:11 +0100 Subject: [RELEASE] Python 3.10.0b2 is available Message-ID: After fighting with some release blockers, implementing a bunch of GC traversal functions, and fixing some pending reference leaks, we finally have Python 3.10.0 beta 2 ready for you! Thanks to everyone that helped to unblock the release! https://www.python.org/downloads/release/python-3100b2/ # This is a beta preview of Python 3.10 Python 3.10 is still in development. 3.10.0b2 is the second of four planned beta release previews. Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release. We **strongly encourage** maintainers of third-party Python projects to **test with 3.10** during the beta phase and report issues found to [the Python bug tracker](https://bugs.python.org/) as soon as possible. While the release is planned to be feature complete entering the beta phase, it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase (Monday, 2021-08-02). Our goal is to have no ABI changes after beta 4 and as few code changes as possible after 3.10.0rc1, the first release candidate. To achieve that, it will be **extremely important** to get as much exposure for 3.10 as possible during the beta phase. Please keep in mind that this is a preview release and its use is **not** recommended for production environments. The next pre-release of Python 3.10 will be 3.10.0b3, currently scheduled for Thursday, 2021-06-17. # And now for something completely different The Ehrenfest paradox concerns the rotation of a "rigid" disc in the theory of relativity. In its original 1909 formulation as presented by Paul Ehrenfest in relation to the concept of Born rigidity within special relativity, it discusses an ideally rigid cylinder that is made to rotate about its axis of symmetry. The radius R as seen in the laboratory frame is always perpendicular to its motion and should therefore be equal to its value R0 when stationary. However, the circumference (2?R) should appear Lorentz-contracted to a smaller value than at rest. This leads to the apparent contradiction that R = R0 and R < R0. # We hope you enjoy those new releases! Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Regards from very sunny London, Your friendly release team, Pablo Galindo @pablogsal Ned Deily @nad Steve Dower @steve.dower From jon+usenet at unequivocal.eu Tue Jun 1 08:19:13 2021 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 1 Jun 2021 12:19:13 -0000 (UTC) Subject: Definition of "property" References: <5BD50721-94C9-472B-B7AC-6A16EB13941A@furrypants.com> Message-ID: On 2021-06-01, Greg Ewing wrote: > On 1/06/21 2:34 am, Jon Ribbens wrote: >> From the outside, it's just a *data* attribute. Which, from the inside, >> it isn't. Hence "pretending". > > But what is it about the external appearance that would make > you think it's a data attribute, rather than some other kind > of attribute? I already answered that in the post you are responding to, but you snipped it: You can tell something's definitely not a data attribute if you have to put brackets after its name to call it as a method to invoke its function or retrieve the value it returns. > (I'm assuming that by "data attribute" you mean a piece of > data that's stored directly in the object. If you mean > something else, we might be talking at cross purposes.) I mean it in the sense it is used by the Python documentation. From nospam at please.ty Tue Jun 1 03:33:51 2021 From: nospam at please.ty (jak) Date: Tue, 1 Jun 2021 09:33:51 +0200 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] References: <8rb8bg1qonkhcr5bkh27is6br690gm2845@4ax.com> Message-ID: Il 31/05/2021 02:36, Dennis Lee Bieber ha scritto: > On Mon, 31 May 2021 08:07:21 +1000, Cameron Simpson > declaimed the following: > > >> Open another terminal, note its terminal device with the "tty" command. >> Start your programme like this: >> >> python ...... 2>/dev/tty-of-the-other-termina >> > > The OP specified Win10, so the above is dead from the start. > > OP can try this way on win10: write the debug information in a log file and, from another console, open the same log file with an editor that knows how to check the active status of the file (eg: notepad++), which can automatically update the changes (you can remove the notification for this action from the tab preferences). cheers From ikorot01 at gmail.com Tue Jun 1 14:01:51 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 1 Jun 2021 13:01:51 -0500 Subject: Python app setup In-Reply-To: References: Message-ID: Hi, On Tue, Jun 1, 2021 at 12:25 PM Murali Pa wrote: > > Hi, > I've installed latest version of Python 3.9.5 and downloaded for Windows. > Once I click on the Python app, I'm getting command screen and not sure on > the next action. could you please help me to fix this issue. > Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 > bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> Congratulations!! You successfully installed python onm your box. Now you can start coding in python. Thank you. > Thanks, > Murali PA > > > Disclaimer: The information in this email is the property of IBM and may > be IBM Confidential and privileged. It is intended solely for the > addressee. Access to this email by anyone else is unauthorized. If you are > not the intended recipient, any disclosure, copying, distribution or any > action taken in reliance on it is prohibited. If you receive this message > in error please notify the sender immediately and delete all copies of > this message. > > -- > https://mail.python.org/mailman/listinfo/python-list From eryksun at gmail.com Tue Jun 1 15:13:57 2021 From: eryksun at gmail.com (Eryk Sun) Date: Tue, 1 Jun 2021 14:13:57 -0500 Subject: Definition of "property" In-Reply-To: References: <5BD50721-94C9-472B-B7AC-6A16EB13941A@furrypants.com> Message-ID: On 6/1/21, Jon Ribbens via Python-list wrote: > > I already answered that in the post you are responding to, but you > snipped it: You can tell something's definitely not a data attribute > if you have to put brackets after its name to call it as a method to > invoke its function or retrieve the value it returns. I prefer to use the generic term "computed attribute", which doesn't interfere with the use of "data" in Python's concept of a data descriptor and instance data. All descriptors are accessed without calling them. Usually a non-data descriptor returns a bound callable object, such as a method. But it can return anything. For example, take the following P descriptor type: class P: def __get__(self, obj, cls): if obj is not None: return 42 return self class C: p = P() obj = C() >>> obj.p 42 The P type doesn't implement __set__ or __delete__, so it's not a data descriptor. This means we can set instance data `p` that overrides the computed attribute. For example: >>> obj.p = 21 >>> vars(obj) {'p': 21} >>> obj.p 21 >>> del obj.p >>> obj.p 42 From drsalists at gmail.com Tue Jun 1 15:45:46 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 1 Jun 2021 12:45:46 -0700 Subject: Python app setup In-Reply-To: References: Message-ID: What you've got there is a REPL, or Read-Evaluate-Print-Loop. It's good for quick little exploratory tests. For actually writing code, most people would prefer to use PyCharm or VSCode or IDLE. You may find that IDLE has come with your CPython install. Personally, I prefer vim+syntastic+jedi, but I realize that's not everyone's cup of meat. If you have an application you want to install that is built on Python, rather than write your own code, there will probably be a pip command you can run, or a setup.py to use. If this is the case, let us know. HTH. On Tue, Jun 1, 2021 at 10:23 AM Murali Pa wrote: > Hi, > I've installed latest version of Python 3.9.5 and downloaded for > Windows. > Once I click on the Python app, I'm getting command screen and not sure > on > the next action. could you please help me to fix this issue. > Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 > bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> > Thanks, > Murali PA > > > Disclaimer: The information in this email is the property of IBM and may > be IBM Confidential and privileged. It is intended solely for the > addressee. Access to this email by anyone else is unauthorized. If you > are > not the intended recipient, any disclosure, copying, distribution or any > action taken in reliance on it is prohibited. If you receive this > message > in error please notify the sender immediately and delete all copies of > this message. > > -- > https://mail.python.org/mailman/listinfo/python-list > From rshepard at appl-ecosys.com Tue Jun 1 16:18:38 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 1 Jun 2021 13:18:38 -0700 (PDT) Subject: Neither pdb or print() displays the bug Message-ID: On Sun, 30 May 2021, Cameron Simpson wrote: > I've only just started with pdb. As of Python 3.7 there's a builtin > function named breakpoint() which drops you into the debugger. I've never > been a big debugger person, historicly using print() and equivalent. > However, this makes it very easy to insert this call into a piece of code > instead of having to invoke one's programme in a special way. I'm stuck with neither approach (pdb, print()) working. I moved the database code to a separate module, datasource.py, and when I run the activitytypes.py module (using pdb and having entered print() statements at various places in both the datasource and activities modules all I get is a small, empty window with the window title. The QSize() statement is never reached. The activitytypes.py module: import sys from PyQt5 import QtWidgets as qtw from PyQt5 import QtGui as qtg from PyQt5 import QtCore as qtc from PyQt5 import QtSql as qts from datasource import db class ATMainWindow(qtw.QMainWindow): def __init__(self): super().__init__() # Model/View here. self.model = qts.QSqlTableModel(db=db) # for single table self.model.setTable('activitytypes') self.model.select() self.table = qtw.QTableView() self.table.setModel(self.model) self.setFixedSize(qtc.QSize(800, 600)) self.setCentralWidget(self.table) if __name__ == '__main__': app = qtw.QApplication(sys.argv) window = ATMainWindow() window.show() #sys.exit(app.exec()) app.exec_() Running the module in pdb and using 'next' to step through it produces this result: > $/development/business_tracker/activitytypes.py(29)() -> window = ATMainWindow() (Pdb) n False > $/development/business_tracker/activitytypes.py(30)() -> window.show() (Pdb) n > $/development/business_tracker/activitytypes.py(32)() -> app.exec_() (Pdb) n n > $/development/business_tracker/activitytypes.py(32)()->None -> app.exec_() (Pdb) n and there it sits. No (Pdb) prompt, nothing. And no printed statements. I'd appreciate recommendations on the process to find where the bug lives since I can't seem to find it with print() or line-by-line in pdb. TIA, Rich From drsalists at gmail.com Tue Jun 1 16:20:04 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 1 Jun 2021 13:20:04 -0700 Subject: python 3.9.5 In-Reply-To: <3dt9bgtbfg9qo8gfighag2jqls6ekksbhj@4ax.com> References: <60b48d10.1c69fb81.6dc92.a3e7@mx.google.com> <3dt9bgtbfg9qo8gfighag2jqls6ekksbhj@4ax.com> Message-ID: On Tue, Jun 1, 2021 at 10:12 AM Dennis Lee Bieber wrote: > On Mon, 31 May 2021 02:15:28 -0500, said ganoune > declaimed the following: > > is this the third one in the last week... > > Does the Python FAQ address contemporary FAQ's? It seems like https://docs.python.org/3/faq/windows.html would be the place. From ethan at stoneleaf.us Tue Jun 1 16:25:09 2021 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 1 Jun 2021 13:25:09 -0700 Subject: Neither pdb or print() displays the bug In-Reply-To: References: Message-ID: <20cb1a4f-ec85-9ea0-effe-b916f8be5a23@stoneleaf.us> On 6/1/21 1:18 PM, Rich Shepard wrote: > I'd appreciate recommendations on the process to find where the bug lives > since I can't seem to find it with print() or line-by-line in pdb. Sounds like a console issue. Try using `logging` with a file... you could even use `print` with a file if you wanted to. -- ~Ethan~ From tjreedy at udel.edu Tue Jun 1 14:29:15 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 1 Jun 2021 14:29:15 -0400 Subject: Python app setup In-Reply-To: References: Message-ID: On 5/31/2021 2:20 PM, Murali Pa wrote: > Hi, > I've installed latest version of Python 3.9.5 and downloaded for Windows. > Once I click on the Python app, I'm getting command screen You are getting the Python interactive interpreter. This is different from the system command line console/terminal in which you enter system commands. > and not sure on the next action. Enter a Python statement. See the Python tutorial which explains. > could you please help me to fix this issue. If you wish to run a python program in a file, you have to enter a command line in the system terminal, click on the file, or load the file in an IDE such as IDLE and run it from there. See the chapter of the doc Using Python for your system. > Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 > bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> Enter the first line of a statement, or if using IDLE, a complete statement. > Disclaimer: The information in this email is the property of IBM and may > be IBM Confidential and privileged. It is intended solely for the > addressee. Access to this email by anyone else is unauthorized. If you are > not the intended recipient, any disclosure, copying, distribution or any > action taken in reliance on it is prohibited. If you receive this message > in error please notify the sender immediately and delete all copies of > this message. When one sends a message to a mailing list or newsgroup, this is complete nonsense. The 'addressee' is anyone and everyone in the world. Try to avoid it if you can. -- Terry Jan Reedy From alan.gauld at yahoo.co.uk Tue Jun 1 14:39:24 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 1 Jun 2021 19:39:24 +0100 Subject: Definition of "property" In-Reply-To: References: <5BD50721-94C9-472B-B7AC-6A16EB13941A@furrypants.com> Message-ID: On 31/05/2021 15:59, Dennis Lee Bieber wrote: > On Sun, 30 May 2021 21:20:24 +0100, Alan Gauld via Python-list > declaimed the following: > >> On 30/05/2021 17:57, Irv Kalb wrote: >>> I am doing some writing (for an upcoming book on OOP), and I'm a little stuck. >> >> Oh dear, that's one of myt hot buttons I'm afraid! >> I hope it really is about OOP and not about classes. Classes >> are such a minor part of OOP that it is depressing how many > To me, OOP tends to be language specific... OOP is supposed to be a programming paradigm in the same way that Functional or Logic programming are paradigms. Its all about how you organise your code. It should be based on message passing between autonomous agents(objects). Classes etc are language constructs aimed at making OOP easier, but they are not OOP. It's very easy to build a class/object based program that is not in any way OOP (in fact I'd go as far as to say the majority of such programs today come into that category). It's also possible (but difficult!) to build an OOP program without classes. Incidentally, I'm not arguing that classes should not be used in imperative programming, they can be very powerful there too. Just that using classes is not necessarily OOP. > Finding books on OOAD -- which should be language agnostic -- is > more difficult, and tend to turn into books about how to use > UML rather than how to analyze/design using OO. That's a fairly modern phenomenon. Most of the early books about OOAD were language agnostic - even when they used a language for demonstration purposes. Books like Grady Booch's classic OOAD, or Peter Coad's series with Ed Yourdon. The so-called method wars. They all had their own methodology, but mostly that was just diagrammatic variances. The underlying techniques and resultant structures were the same. (And hence the move to UML, which is just a notation - an extremely useful one, although often abused through over zealous application.) Even Rumbaugh's OMT book was meant to be general OOD, although IMHO it was the least OO of all of them being heavily based on data modelling. Sadly, there are very few books today that even attempt to describe the difference between OOP and the more common procedural programming paradigm. Discussions of OOP have degenerated into discussions about OOPL features rather than how to build worlds of objects passing messages to each other. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From alan.gauld at yahoo.co.uk Tue Jun 1 14:48:05 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 1 Jun 2021 19:48:05 +0100 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> Message-ID: On 31/05/2021 16:16, Grant Edwards wrote: > On 2021-05-30, Alan Gauld via Python-list wrote: >> You are not alone. debugging curses is one of the biggest obstacles to >> its use. > > Can't you just run the debugger in a different window and attach to > the process you want to debug? That's how one uses a debugger with > curses apps written in C/C++. That's how we did it when I used curses on VMS/Unix using C. But I confess I didn't think you could attach any python debugger to another python session? > Or I add debugging printf calls which > write to stderr and redirect stderr to a file. I do use logging sometimes but its not as immediate as seeing the messages in the application as you run it. >> My approach is to define a status line at the bottom of my program and >> write print statements into that window. Something like: > > Why not just use the standard python logging facility and log to a > file or another terminal window? I find the immediacy of an in-window message much easier. Its like using print() statements in a regular CLI application. Its there in front of you, no other terminals to look at. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From ekesawi at yahoo.com Tue Jun 1 16:21:15 2021 From: ekesawi at yahoo.com (EK Esawi) Date: Tue, 1 Jun 2021 20:21:15 +0000 (UTC) Subject: Pandsa to Excel conversion issue References: <2118919626.1319748.1622578875491.ref@mail.yahoo.com> Message-ID: <2118919626.1319748.1622578875491@mail.yahoo.com> Hi All-- I am using Pandas to read an excel file which is very "dirty" and needs cleaning. I read the file via pandas and did not setup dtypes or converters hoping i can do so later.. When i run my code, most columns did come out as strings but i cannot convert them to float or integer using astype or pandas.to numeric method. Every time i tried, i get the same error listed below Here is my code import pandas as pd import numpy as np MyFile='C:/Users/Temp.xlsx' df=pd.read_excel(io=MyFile, nrows=100) The error message i get when i tried to convert a string like '22.3' via astype or pd.to_numeric is below Unable to parse string "22." at position 0 Thanks in advance EK From rshepard at appl-ecosys.com Tue Jun 1 16:30:36 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 1 Jun 2021 13:30:36 -0700 (PDT) Subject: Neither pdb or print() displays the bug In-Reply-To: References: Message-ID: On Tue, 1 Jun 2021, Rich Shepard wrote: > The QSize() statement is never reached. Correction: the window is 800 x 600, but it's still empty. Rich From rshepard at appl-ecosys.com Tue Jun 1 16:42:30 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 1 Jun 2021 13:42:30 -0700 (PDT) Subject: Neither pdb or print() displays the bug In-Reply-To: <20cb1a4f-ec85-9ea0-effe-b916f8be5a23@stoneleaf.us> References: <20cb1a4f-ec85-9ea0-effe-b916f8be5a23@stoneleaf.us> Message-ID: On Tue, 1 Jun 2021, Ethan Furman wrote: > Sounds like a console issue. Try using `logging` with a file... you could > even use `print` with a file if you wanted to. Ethan, Not before using logging I found a reference/example page and modified the module to this: # activitytypes.py import sys import logging from PyQt5 import QtWidgets as qtw from PyQt5 import QtGui as qtg from PyQt5 import QtCore as qtc from PyQt5 import QtSql as qts from datasource import db logging.basicConfig(level=logging.DEBUG, format='%(asctime)s -%(levelname)s - %(message)s') logging.debug("Start of Program") class ATMainWindow(qtw.QMainWindow): def __init__(self): super().__init__() # Model/View here. self.model = qts.QSqlTableModel(db=db) # for single table self.model.setTable('activitytypes') self.model.select() self.table = qtw.QTableView() self.table.setModel(self.model) self.setMinimumSize(qtc.QSize(800, 600)) self.setCentralWidget(self.table) if __name__ == '__main__': app = qtw.QApplication(sys.argv) window = ATMainWindow() window.show() #sys.exit(app.exec()) app.exec_() logging.debug("End of Program") When I run it this is the output: $ python activitytypes.py 2021-06-01 13:39:10,219 -DEBUG - Start of Program 2021-06-01 13:39:15,229 -DEBUG - End of Program Obviously I have much to learn about using python's logging capabilities. I'll keep looking. Thanks, Rich From sjeik_appie at hotmail.com Tue Jun 1 16:25:02 2021 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Tue, 01 Jun 2021 22:25:02 +0200 Subject: Async requests library with NTLM auth support? Message-ID: Hi, I need to make thousands of requests that require ntlm authentication so I was hoping to do them asynchronously. With synchronous requests I use requests/requests_ntlm. Asyncio and httpx [1] look promising but don't seem to support ntlm. Any tips? Cheers! Albert-Jan [1] https://www.python-httpx.org/ From ethan at stoneleaf.us Tue Jun 1 17:07:15 2021 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 1 Jun 2021 14:07:15 -0700 Subject: Neither pdb or print() displays the bug In-Reply-To: References: <20cb1a4f-ec85-9ea0-effe-b916f8be5a23@stoneleaf.us> Message-ID: <0343b334-2e10-f055-896b-b3ef9d080401@stoneleaf.us> On 6/1/21 1:42 PM, Rich Shepard wrote: > When I run it this is the output: > $ python activitytypes.py 2021-06-01 13:39:10,219 -DEBUG - Start of Program > 2021-06-01 13:39:15,229 -DEBUG - End of Program Well, you only had two logging statements in that code -- logging is like print: if you want to see it, you have to call it: logging.info('start of xx procedure') logging.info('spam = %s', spam) # note the comma and not actual %-interpolation > Obviously I have much to learn about using python's logging capabilities. > I'll keep looking. I'm certainly not an expert, but this is how I do it: from logging import INFO, getLogger, Formatter, handlers logger = getLogger() logger.setLevel(INFO) _handler = handlers.TimedRotatingFileHandler( virtualenv / 'var/log/openerp/continuous_sync_records.log', when='midnight', backupCount=30, ) _formatter = Formatter('%(asctime)s %(funcName)-25s %(message)s') _handler.setFormatter(_formatter) logger.addHandler(_handler) del _handler, _formatter and then in my code: logger.info('failure converting %r to %r', target_bmp_file, target_png_file) -- ~Ethan~ From rshepard at appl-ecosys.com Tue Jun 1 17:32:49 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 1 Jun 2021 14:32:49 -0700 (PDT) Subject: Neither pdb or print() displays the bug In-Reply-To: <0343b334-2e10-f055-896b-b3ef9d080401@stoneleaf.us> References: <20cb1a4f-ec85-9ea0-effe-b916f8be5a23@stoneleaf.us> <0343b334-2e10-f055-896b-b3ef9d080401@stoneleaf.us> Message-ID: On Tue, 1 Jun 2021, Ethan Furman wrote: > Well, you only had two logging statements in that code -- logging is like > print: if you want to see it, you have to call it: Ethan, Got it, thanks. I believe my problem is with the datasource module. I'm focused on making it work (using logging to confirm that it is doing so). Will report results when they're available. Regards, Rich From rshepard at appl-ecosys.com Tue Jun 1 19:01:24 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 1 Jun 2021 16:01:24 -0700 (PDT) Subject: Neither pdb or print() displays the bug In-Reply-To: References: Message-ID: On Tue, 1 Jun 2021, Dennis Lee Bieber wrote: > I suspect you really should be stepping INTO the calls, not just > invoking the functions completely and going to the next LOCAL statement. > $ /development/business_tracker/activitytypes.py(1)() -> import sys (Pdb) s > $ /development/business_tracker/activitytypes.py(2)() -> import logging (Pdb) s --Call-- > (978)_find_and_load() (Pdb) s Now I'll go learn what this means. Rich From cs at cskk.id.au Tue Jun 1 19:32:17 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 2 Jun 2021 09:32:17 +1000 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: Message-ID: On 01Jun2021 19:48, Alan Gauld wrote: >On 31/05/2021 16:16, Grant Edwards wrote: >> On 2021-05-30, Alan Gauld via Python-list wrote: >>> You are not alone. debugging curses is one of the biggest obstacles >>> to >>> its use. >> >> Can't you just run the debugger in a different window and attach to >> the process you want to debug? That's how one uses a debugger with >> curses apps written in C/C++. > >That's how we did it when I used curses on VMS/Unix using C. That's ok for C-level things - they're close to the metal. But this is Python, so such tools may well be poorly adapted. >But I confess I didn't think you could attach any python >debugger to another python session? Dennis Lee Bieber wrote earlier in this thread: From http://heather.cs.ucdavis.edu/~matloff/winpdb.html """ About Winpdb and RPDB2: The Winpdb package, by Nir Aides, is an excellent Python debugger. It is especially nice because it can handle the debugging of threads- and curses-based code. It is a remote debugger, meaning that it connects through the network to a remote site (which can be the same machine at which it is invoked, which is typical). RPDB2 is text-based, while Winpdb is a GUI front end to RPDB2. """ So it sounds like someone's done the hard work here. I can imagine it embeds a Python proxy in the app which can be remote controlled from the debugger client, but I'm just guessing wildly. Cheers, Cameron Simpson From alan.gauld at yahoo.co.uk Tue Jun 1 19:10:33 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 2 Jun 2021 00:10:33 +0100 Subject: Neither pdb or print() displays the bug In-Reply-To: References: Message-ID: On 01/06/2021 21:18, Rich Shepard wrote: > On Sun, 30 May 2021, Cameron Simpson wrote: > >> I've only just started with pdb. As of Python 3.7 there's a builtin >> function named breakpoint() which drops you into the debugger. > I'm stuck with neither approach (pdb, print()) working. > The activitytypes.py module: > > class ATMainWindow(qtw.QMainWindow): > > def __init__(self): > super().__init__() > > # Model/View here. > self.model = qts.QSqlTableModel(db=db) # for single table > self.model.setTable('activitytypes') > self.model.select() > > self.table = qtw.QTableView() > self.table.setModel(self.model) > > self.setFixedSize(qtc.QSize(800, 600)) Assuming this is the line you want to examine set a beakpoint just above it using the function that Cameron mentioned (Or just set a breakpoint on the init() from pdb... Trying to use step/next to debug an event driven application is next to impossible. set breakpoints on the methods that get triggered by events then generate the event to reach the breakpoint. Or, as in this case, on the init if you want to examine objects as they are created. As a general rule if you have to hit next/step more than half a dozen times in a row you are probably making extra work for yourself! >> $/development/business_tracker/activitytypes.py(29)() > -> window = ATMainWindow() > (Pdb) n > False >> $/development/business_tracker/activitytypes.py(30)() > -> window.show() > (Pdb) n >> $/development/business_tracker/activitytypes.py(32)() > -> app.exec_() > (Pdb) n > n >> $/development/business_tracker/activitytypes.py(32)()->None > -> app.exec_() > (Pdb) n I'm not sure why you got that twice. I'd expect you to only see it once. > > and there it sits. No (Pdb) prompt, nothing. And no printed statements. It's waiting while the app runs and for you to terminate it. > I'd appreciate recommendations on the process to find where the bug lives > since I can't seem to find it with print() or line-by-line in pdb. Use breakpoints, don't try to step through the code from the beginning - there lies madness! And for event handlers that get called a lot use conditional breakpoints so that you only stop when you want to. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From greg.ewing at canterbury.ac.nz Tue Jun 1 20:41:08 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 2 Jun 2021 12:41:08 +1200 Subject: Definition of "property" In-Reply-To: References: <5BD50721-94C9-472B-B7AC-6A16EB13941A@furrypants.com> Message-ID: On 1/06/21 7:01 am, Alan Gauld wrote: > That was the point, the OP said it was a book about OOP. > Not a book about "OOP in Python". In that case it would be best to avoid the word, or give a definition of the way he's using it, making it clear that it's not a universal definition. Python's definition is somewhat unusual, and so would not be appropriate. -- Greg From jfong at ms4.hinet.net Tue Jun 1 21:19:06 2021 From: jfong at ms4.hinet.net (Jach Feng) Date: Tue, 1 Jun 2021 18:19:06 -0700 (PDT) Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> Message-ID: <068f1d86-9e7e-495b-bf7a-8cb570a24966n@googlegroups.com> pjfa... at earthlink.net ? 2021?5?31? ?????1:42:43 [UTC+8] ?????? > I tried winpdb-reborn some time last year on my Win10 system (python 3.8.3 > at that time), but could not figure out how to use it to debug a python > script that uses the curses module. > > Does anyone here know if winpdb-reborn or any other debugger can support > 2-window debugging for a python script that uses the curses module? It > seems to me that a 2-window debugging session is necessary for a python > script that uses the curses module because using curses takes over the > screen from which the script is started, so debugging output and script > output need to be in separate windows. > > I've been forced to use a logger to trace critical values and program flow > for errors in such a script. It works, but it is annoyingly slow to debug > that way. > > TIA for any advice or RTFM you can provide. > > Peter > -- I have no problem on using rpdb2 to debug a script which is based on curses. My environment are: Windows Vista, Python 3.4.4, rpdb2 of winpdb-1.4.8, curses-2.2-cp34-cp34m-win32.whl, snake.py Everything are old, but it works:-) --Jach From robertvstepp at gmail.com Wed Jun 2 00:21:02 2021 From: robertvstepp at gmail.com (boB Stepp) Date: Tue, 1 Jun 2021 23:21:02 -0500 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: <8rb8bg1qonkhcr5bkh27is6br690gm2845@4ax.com> Message-ID: On Tue, Jun 1, 2021 at 12:20 PM Dennis Lee Bieber wrote: > > On Tue, 1 Jun 2021 08:04:54 +1000, Cameron Simpson > declaimed the following: > > >On 30May2021 20:36, Dennis Lee Bieber wrote: > >>On Mon, 31 May 2021 08:07:21 +1000, Cameron Simpson > >>declaimed the following: > >>>Open another terminal, note its terminal device with the "tty" > >>>command. > >>>Start your programme like this: > >>> python ...... 2>/dev/tty-of-the-other-termina > >>> > >> The OP specified Win10, so the above is dead from the start. > > > >Good point; I wasn't aware that curses worked in Windows. > > https://docs.python.org/3/howto/curses.html > "The Windows version of Python doesn?t include the curses module. A ported > version called UniCurses is available." > > Appears the easiest is to PIP "windows-curses" then track down > piecemeal installs (it is unclear if UniCurses includes PDCurses, or needs > that as a separate install). windows-curses 2.2.0 has been working well for me so far on Win10: https://pypi.org/project/windows-curses/ "Adds support for the standard Python curses module on Windows. Based on these wheels. Uses the PDCurses curses implementation." boB Stepp From __peter__ at web.de Wed Jun 2 05:02:55 2021 From: __peter__ at web.de (Peter Otten) Date: Wed, 2 Jun 2021 11:02:55 +0200 Subject: Neither pdb or print() displays the bug In-Reply-To: References: <20cb1a4f-ec85-9ea0-effe-b916f8be5a23@stoneleaf.us> <0343b334-2e10-f055-896b-b3ef9d080401@stoneleaf.us> Message-ID: On 01/06/2021 23:32, Rich Shepard wrote: > On Tue, 1 Jun 2021, Ethan Furman wrote: > >> Well, you only had two logging statements in that code -- logging is like >> print: if you want to see it, you have to call it: > > Ethan, > > Got it, thanks. > > I believe Do you have unit tests? Those are an excellent tool to ensure that the components of an application work as expected and that those components have well-defined interfaces. Debugging a failing unittest is usually easier than to debug a complex application. While I don't know if there is a convenient way to test the GUI everything else should run reliably *before* connecting it with the GUI. > my problem is with the datasource module. I'm focused on > making it > work (using logging to confirm that it is doing so). Will report results > when they're available. > > Regards, > > Rich From rshepard at appl-ecosys.com Wed Jun 2 08:33:14 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 2 Jun 2021 05:33:14 -0700 (PDT) Subject: Neither pdb or print() displays the bug In-Reply-To: References: <20cb1a4f-ec85-9ea0-effe-b916f8be5a23@stoneleaf.us> <0343b334-2e10-f055-896b-b3ef9d080401@stoneleaf.us> Message-ID: On Wed, 2 Jun 2021, Peter Otten wrote: > Do you have unit tests? Those are an excellent tool to ensure that the > components of an application work as expected and that those components > have well-defined interfaces. Debugging a failing unittest is usually > easier than to debug a complex application. While I don't know if there is > a convenient way to test the GUI everything else should run reliably > *before* connecting it with the GUI. Peter, I believe there is a way to apply unit tests to PyQt and I'll certainly learn to take this testing-while-developing approach. Thanks, Rich From n_jayshankar at yahoo.com Wed Jun 2 09:35:52 2021 From: n_jayshankar at yahoo.com (jayshankar nair) Date: Wed, 2 Jun 2021 13:35:52 +0000 (UTC) Subject: fabric: fab command References: <1357746172.2718507.1622640952663.ref@mail.yahoo.com> Message-ID: <1357746172.2718507.1622640952663@mail.yahoo.com> Hi, I am unable to find the package for the below module. The error shows when i run the command fab(fabric). import tools.fab.dev_utils as dev_utilsImportError: No module named tools.fab.dev_utils Please let me know which package i have to install. Thanks,Jayshankar From george at fischhof.hu Wed Jun 2 09:57:16 2021 From: george at fischhof.hu (George Fischhof) Date: Wed, 2 Jun 2021 15:57:16 +0200 Subject: Definition of "property" In-Reply-To: References: <5BD50721-94C9-472B-B7AC-6A16EB13941A@furrypants.com> Message-ID: Greg Ewing ezt ?rta (id?pont: 2021. j?n. 2., Sze, 4:01): > On 1/06/21 7:01 am, Alan Gauld wrote: > > That was the point, the OP said it was a book about OOP. > > Not a book about "OOP in Python". > > In that case it would be best to avoid the word, or give > a definition of the way he's using it, making it clear > that it's not a universal definition. Python's definition > is somewhat unusual, and so would not be appropriate. > > -- > Greg > > -- > https://mail.python.org/mailman/listinfo/python-list > Hi, I think in OOP point of view one can write that property is the python implementation of the OOP concepts: Encapsulation and Information hiding Some explanation for beginners on these paradigms: https://stackify.com/oop-concept-for-beginners-what-is-encapsulation/ BR, George From alan.gauld at yahoo.co.uk Wed Jun 2 13:48:53 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 2 Jun 2021 18:48:53 +0100 Subject: fabric: fab command In-Reply-To: <1357746172.2718507.1622640952663@mail.yahoo.com> References: <1357746172.2718507.1622640952663.ref@mail.yahoo.com> <1357746172.2718507.1622640952663@mail.yahoo.com> Message-ID: On 02/06/2021 14:35, jayshankar nair via Python-list wrote: > import tools.fab.dev_utils as dev_utilsImportError: No module named tools.fab.dev_utils > Please let me know which package i have to install. Work backwards. Can you import tools.fab? Can you import tools? Once you know what you do have you can figure out what you don't and why. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From braimalice at gmail.com Wed Jun 2 05:34:12 2021 From: braimalice at gmail.com (Alice Braim) Date: Wed, 2 Jun 2021 10:34:12 +0100 Subject: Interpreter Bug Message-ID: <15B0F3F4-C638-45BF-8369-3FB82B0479FD@hxcore.ol> Good morning- I am having some very serious issues with Python, and I was hoping you could help? I downloaded both Python and PyCharm, and the 2 do not seem to be working. Every time I select Python as an interpreter, the whole thing crashes. Obviously, I went onto repairs, but even then it told me there was a `fatal error'. I tried uninstalling and restarting multiple times, and nothing improved. I've tried redownloading loads of times, no improvement. I have the latest version (3.9.5) and there definitely seems to be something going on at your end. Any ideas? ~Alexa From cronox892 at gmail.com Wed Jun 2 13:18:08 2021 From: cronox892 at gmail.com (Luke) Date: Wed, 2 Jun 2021 20:18:08 +0300 Subject: 3.7.6 struggles a bit Message-ID: <707063C2-576F-471D-9A5D-E0404EC06E45@hxcore.ol> When i wrote a program, i tried to open it but it struggles to open. From faraazc at gmail.com Wed Jun 2 07:36:15 2021 From: faraazc at gmail.com (Faraaz Mohammed) Date: Wed, 2 Jun 2021 04:36:15 -0700 (PDT) Subject: Embedding Python In-Reply-To: References: Message-ID: <04866a70-c5ba-418e-a6a8-ce530325aae3n@googlegroups.com> On Tuesday, 1 July 2008 at 21:37:49 UTC+5:30, mk wrote: > Carsten Haese wrote: > > python_code is a C string containing the raw bytes from your pyc file. > > Casting that to a PyObject pointer will not magically transform it into > > a Python code object. > well yeah, I kind of didn't think that through.. > A pyc file contains the following: > > > > 1) An 8 byte header containing a magic number. > > 2) A "marshal" serialization of the code object. > > > > So, in order to transform those contents into a code object, you need to > > skip the 8 byte header and an unmarshal the rest. Basically, replace the > > line above with something like this: > > > > codeobj = PyMarshal_ReadObjectFromString(python_code+8, size-8); > > mainobj = PyImport_ExecCodeModule("multiply", codeobj); > > > > where codeobj is of type (PyObject *). > > > > Once that works, add magic number checking and exception handling to taste. > Thanks. That's exactly what I was looking for. I tried exactly the same thing. but I am still hitting segmentation fault at PyImport_ExecCodeModule(). python version is 2.7.17 From rosuav at gmail.com Wed Jun 2 14:08:47 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 3 Jun 2021 04:08:47 +1000 Subject: Embedding Python In-Reply-To: <04866a70-c5ba-418e-a6a8-ce530325aae3n@googlegroups.com> References: <04866a70-c5ba-418e-a6a8-ce530325aae3n@googlegroups.com> Message-ID: On Thu, Jun 3, 2021 at 4:05 AM Faraaz Mohammed wrote: > > On Tuesday, 1 July 2008 at 21:37:49 UTC+5:30, mk wrote: > > Carsten Haese wrote: > > > python_code is a C string containing the raw bytes from your pyc file. > > > Casting that to a PyObject pointer will not magically transform it into > > > a Python code object. > > well yeah, I kind of didn't think that through.. > > A pyc file contains the following: > > > > > > 1) An 8 byte header containing a magic number. > > > 2) A "marshal" serialization of the code object. > > > > > > So, in order to transform those contents into a code object, you need to > > > skip the 8 byte header and an unmarshal the rest. Basically, replace the > > > line above with something like this: > > > > > > codeobj = PyMarshal_ReadObjectFromString(python_code+8, size-8); > > > mainobj = PyImport_ExecCodeModule("multiply", codeobj); > > > > > > where codeobj is of type (PyObject *). > > > > > > Once that works, add magic number checking and exception handling to taste. > > Thanks. That's exactly what I was looking for. > > > I tried exactly the same thing. but I am still hitting segmentation fault at PyImport_ExecCodeModule(). python version is 2.7.17 You're replying to something from *thirteen years ago*. A lot has changed in that time. I'd recommend starting over, figuring out what's going on, and preferably, using Python 3. ChrisA From barry at barrys-emacs.org Wed Jun 2 14:32:20 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 2 Jun 2021 19:32:20 +0100 Subject: 3.7.6 struggles a bit In-Reply-To: <707063C2-576F-471D-9A5D-E0404EC06E45@hxcore.ol> References: <707063C2-576F-471D-9A5D-E0404EC06E45@hxcore.ol> Message-ID: <0FD8B9D9-3970-4784-AAF7-51927B7E6DAA@barrys-emacs.org> > On 2 Jun 2021, at 18:18, Luke wrote: > > When i wrote a program, i tried to open it but it struggles to open. I'm guessing you are a Windows user. Does this help? https://docs.python.org/3/faq/windows.html Barry From barry at barrys-emacs.org Wed Jun 2 14:34:31 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 2 Jun 2021 19:34:31 +0100 Subject: Interpreter Bug In-Reply-To: <15B0F3F4-C638-45BF-8369-3FB82B0479FD@hxcore.ol> References: <15B0F3F4-C638-45BF-8369-3FB82B0479FD@hxcore.ol> Message-ID: <7C465B77-DFD9-4B6F-81BA-68E4F3E307FA@barrys-emacs.org> > On 2 Jun 2021, at 10:34, Alice Braim wrote: > > Good morning- > > > > I am having some very serious issues with Python, and I was hoping you > could help? > > I downloaded both Python and PyCharm, and the 2 do not seem to be working. > Every time I select Python as an interpreter, the whole thing crashes. > Obviously, I went onto repairs, but even then it told me there was a > `fatal error'. I tried uninstalling and restarting multiple times, and > nothing improved. I've tried redownloading loads of times, no improvement. > I have the latest version (3.9.5) and there definitely seems to be > something going on at your end. Details please: Which OS which version of Python etc. What does crashes mean exactly? Was it PyCharm that crashes or python that crashes? Barry > > Any ideas? > > > > ~Alexa > > > -- > https://mail.python.org/mailman/listinfo/python-list > From pjfarley3 at earthlink.net Wed Jun 2 21:24:55 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Wed, 2 Jun 2021 21:24:55 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: <8rb8bg1qonkhcr5bkh27is6br690gm2845@4ax.com> Message-ID: <004f01d75817$43bde710$cb39b530$@earthlink.net> > -----Original Message----- > From: Grant Edwards > Sent: Monday, May 31, 2021 11:18 AM > To: python-list at python.org > Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn] > > On 2021-05-31, Dennis Lee Bieber wrote: > > On Mon, 31 May 2021 08:07:21 +1000, Cameron Simpson > > declaimed the following: > > > > > >>Open another terminal, note its terminal device with the "tty" command. > >>Start your programme like this: > >> > >> python ...... 2>/dev/tty-of-the-other-termina > > > > The OP specified Win10, so the above is dead from the start. > > Perhaps Windows isn't an appropriate OS under which to develop curses > applicatoins? Perhaps, but why isn't it? Why are Windows users, even knowledgeable ones, so often considered second- or even third-class netizens? I do know some of the answers that will come back for that question, but the attitude is not professional. Peter From pjfarley3 at earthlink.net Wed Jun 2 21:31:34 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Wed, 2 Jun 2021 21:31:34 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: <8rb8bg1qonkhcr5bkh27is6br690gm2845@4ax.com> Message-ID: <005001d75818$3164d4b0$942e7e10$@earthlink.net> > -----Original Message----- > From: Dennis Lee Bieber > Sent: Monday, May 31, 2021 7:11 PM > To: python-list at python.org > Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn] > > On Tue, 1 Jun 2021 08:04:54 +1000, Cameron Simpson > declaimed the following: > > >On 30May2021 20:36, Dennis Lee Bieber wrote: > >>On Mon, 31 May 2021 08:07:21 +1000, Cameron Simpson > >>declaimed the following: > >>>Open another terminal, note its terminal device with the "tty" > >>>command. > >>>Start your programme like this: > >>> python ...... 2>/dev/tty-of-the-other-termina > >>> > >> The OP specified Win10, so the above is dead from the start. > > > >Good point; I wasn't aware that curses worked in Windows. > > https://docs.python.org/3/howto/curses.html > "The Windows version of Python doesn?t include the curses module. A ported > version called UniCurses is available." > > Appears the easiest is to PIP "windows-curses" then track down > piecemeal installs (it is unclear if UniCurses includes PDCurses, or needs that as a > separate install). Indeed, that is likely the one most commonly used because it is easy to install and mostly "just works". Unicurses has not been worked on since 2010 and gets no responses to issues raised, plus these days it requires compiling your own binary of the PDCurses libraries (which isn?t actually very hard, but . . .). Also, PDCurses no longer distributes binary downloads for recent python versions. The last version available as a binary download is for python 3.4. Peter From pjfarley3 at earthlink.net Wed Jun 2 21:17:50 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Wed, 2 Jun 2021 21:17:50 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> Message-ID: <004e01d75816$4679a120$d36ce360$@earthlink.net> > -----Original Message----- > From: Grant Edwards > Sent: Monday, May 31, 2021 11:17 AM > To: python-list at python.org > Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn] > > On 2021-05-30, Alan Gauld via Python-list wrote: > > On 30/05/2021 18:26, pjfarley3 at earthlink.net wrote: > >> I tried winpdb-reborn some time last year on my Win10 system (python > >> 3.8.3 at that time), but could not figure out how to use it to debug > >> a python script that uses the curses module. > > > > You are not alone. debugging curses is one of the biggest obstacles to > > its use. > > Can't you just run the debugger in a different window and attach to the process > you want to debug? That's how one uses a debugger with curses apps written in > C/C++. Or I add debugging printf calls which write to stderr and redirect stderr to > a file. "Attach to another (console) process you want to debug" isn't, AFAIK, a command-line capability from a Windows command prompt as it is in *ix terminal windows. > > My approach is to define a status line at the bottom of my program and > > write print statements into that window. Something like: > > Why not just use the standard python logging facility and log to a file or another > terminal window? As I said in an earlier reply, I have done that, and it works, but it is somewhat slower and certainly not interactive. Peter From pjfarley3 at earthlink.net Wed Jun 2 21:34:35 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Wed, 2 Jun 2021 21:34:35 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: <8rb8bg1qonkhcr5bkh27is6br690gm2845@4ax.com> Message-ID: <005101d75818$9caf9110$d60eb330$@earthlink.net> > -----Original Message----- > From: jak > Sent: Tuesday, June 1, 2021 3:34 AM > To: python-list at python.org > Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn] > > Il 31/05/2021 02:36, Dennis Lee Bieber ha scritto: > > On Mon, 31 May 2021 08:07:21 +1000, Cameron Simpson > > declaimed the following: > > > > > >> Open another terminal, note its terminal device with the "tty" command. > >> Start your programme like this: > >> > >> python ...... 2>/dev/tty-of-the-other-termina > >> > > > > The OP specified Win10, so the above is dead from the start. > > > > > > OP can try this way on win10: write the debug information in a log file and, from > another console, open the same log file with an editor that knows how to check > the active status of the file (eg: notepad++), which can automatically update the > changes (you can remove the notification for this action from the tab > preferences). For this kind of debugging (write a log and review it later) a live view of what is happening in the log isn't always that helpful. Peter From pjfarley3 at earthlink.net Wed Jun 2 21:37:55 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Wed, 2 Jun 2021 21:37:55 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: Message-ID: <005201d75819$13be1510$3b3a3f30$@earthlink.net> > -----Original Message----- > From: Cameron Simpson > Sent: Tuesday, June 1, 2021 7:32 PM > To: python-list at python.org > Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn] > > On 01Jun2021 19:48, Alan Gauld wrote: > >On 31/05/2021 16:16, Grant Edwards wrote: > >> On 2021-05-30, Alan Gauld via Python-list wrote: > >>> You are not alone. debugging curses is one of the biggest obstacles > >>> to its use. > >> > >> Can't you just run the debugger in a different window and attach to > >> the process you want to debug? That's how one uses a debugger with > >> curses apps written in C/C++. > > > >That's how we did it when I used curses on VMS/Unix using C. > > That's ok for C-level things - they're close to the metal. But this is Python, so > such tools may well be poorly adapted. > > >But I confess I didn't think you could attach any python debugger to > >another python session? > > Dennis Lee Bieber wrote earlier in this thread: > So it sounds like someone's done the hard work here. I can imagine it embeds a > Python proxy in the app which can be remote controlled from the debugger > client, but I'm just guessing wildly. If winpdb_reborn worked, that would be true. The original thread did also discuss how often it did not work. Peter From pjfarley3 at earthlink.net Wed Jun 2 21:42:11 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Wed, 2 Jun 2021 21:42:11 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: <068f1d86-9e7e-495b-bf7a-8cb570a24966n@googlegroups.com> References: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> <068f1d86-9e7e-495b-bf7a-8cb570a24966n@googlegroups.com> Message-ID: <005301d75819$ac633b10$0529b130$@earthlink.net> > -----Original Message----- > From: Jach Feng > Sent: Tuesday, June 1, 2021 9:19 PM > To: python-list at python.org > Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn] > > pjfa... at earthlink.net ? 2021?5?31? ?????1:42:43 [UTC+8] ???? > ?? > > I tried winpdb-reborn some time last year on my Win10 system (python > > 3.8.3 at that time), but could not figure out how to use it to debug a > > python script that uses the curses module. > > > > Does anyone here know if winpdb-reborn or any other debugger can > > support 2-window debugging for a python script that uses the curses > > module? It seems to me that a 2-window debugging session is necessary > > for a python script that uses the curses module because using curses > > takes over the screen from which the script is started, so debugging > > output and script output need to be in separate windows. > > > > I've been forced to use a logger to trace critical values and program > > flow for errors in such a script. It works, but it is annoyingly slow > > to debug that way. > > > > TIA for any advice or RTFM you can provide. > > > > Peter > > -- > I have no problem on using rpdb2 to debug a script which is based on curses. > > My environment are: > Windows Vista, Python 3.4.4, rpdb2 of winpdb-1.4.8, curses-2.2-cp34-cp34m- > win32.whl, snake.py > > Everything are old, but it works:-) Indeed, I can believe that. My problem is that my system has much more recent versions that I do need to use. I may, as I said previously, try winpdb_reborn again and see how it works with fresh eyes and some accumulated experience. Peter -- From pjfarley3 at earthlink.net Wed Jun 2 21:44:33 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Wed, 2 Jun 2021 21:44:33 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: References: <8rb8bg1qonkhcr5bkh27is6br690gm2845@4ax.com> Message-ID: <005401d7581a$014b6030$03e22090$@earthlink.net> > -----Original Message----- > From: boB Stepp > Sent: Wednesday, June 2, 2021 12:21 AM > To: python-list at python.org > Subject: Re: How to debug python + curses? [was: RE: Applying winpdb_reborn] > windows-curses 2.2.0 has been working well for me so far on Win10: > https://pypi.org/project/windows-curses/ > > "Adds support for the standard Python curses module on Windows. Based on > these wheels. Uses the PDCurses curses implementation." Agreed. Mostly it "just works". Peter -- From grant.b.edwards at gmail.com Wed Jun 2 22:13:46 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 3 Jun 2021 02:13:46 -0000 (UTC) Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] References: <8rb8bg1qonkhcr5bkh27is6br690gm2845@4ax.com> <004f01d75817$43bde710$cb39b530$@earthlink.net> Message-ID: On 2021-06-03, wrote: >> -----Original Message----- >> From: Grant Edwards >> Sent: Monday, May 31, 2021 11:18 AM >> To: python-list at python.org >> Subject: Re: How to debug python + curses? [was: RE: Applying > winpdb_reborn] >> >> On 2021-05-31, Dennis Lee Bieber wrote: >> > On Mon, 31 May 2021 08:07:21 +1000, Cameron Simpson >> > declaimed the following: >> > >> > >> >>Open another terminal, note its terminal device with the "tty" command. >> >>Start your programme like this: >> >> >> >> python ...... 2>/dev/tty-of-the-other-termina >> > >> > The OP specified Win10, so the above is dead from the start. >> >> Perhaps Windows isn't an appropriate OS under which to develop curses >> applicatoins? > > Perhaps, but why isn't it? 1. Because it's (apparently) so difficult to debug Windows Python console programs from another window. 2. Because curses applications are very rare on Windows, yet are still quite common on Unix. -- Grant From cs at cskk.id.au Thu Jun 3 00:18:37 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 3 Jun 2021 14:18:37 +1000 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: <004f01d75817$43bde710$cb39b530$@earthlink.net> References: <004f01d75817$43bde710$cb39b530$@earthlink.net> Message-ID: On 02Jun2021 21:24, pjfarley3 at earthlink.net wrote: >> -----Original Message----- >> From: Grant Edwards >> Perhaps Windows isn't an appropriate OS under which to develop curses >> applicatoins? > >Perhaps, but why isn't it? I don't think it isn't. (Um, so many negatives in that sentence - I mean I don't consider Windows inappropriate.) The only salient negative I've seen in this thread is that it isn't trivial to "open another terminal and direct messages there". Otherwise, if there's a decent remote debugger I don't see a technical reason to diss Windows. That said, I am not a Windows person and probably never will be; Microsoft the company have had a long history of gratuitously doing things differently for market based reasons rather than technical reasons and on a personal basis I find Windows desktops painful to use. Some of that is lack of familiarity, doubtless. And my own UNIX side desktops are usually spartan by others' standards. > >Why are Windows users, even knowledgeable ones, so often considered second- >or even third-class netizens? > >I do know some of the answers that will come back for that question, but the >attitude is not professional. > I agree it is not professional. I know some Windows devs and they're broadly just as sane as the UNIXy folks I'm more familiar with. But a lot of things in Windows do seem... more complex. The UNIX world has quite a simple underlying basis, and that spills over into the simplicity of connecting things together. We _expect_ to just glom files and terminals and whatever together with pipes and redirections, and the flip side is that many things developed in that world are slanted for that to be easy, and when that doesn't translate to Windows that looks like a poor environment to an outsider. The historic difficulties with installing Python on Windows probably also spill over into this. There are skilled people inside Microsoft who have brought Python installs into the (I gather) first class citizen area recently, meaning (again, I gather) that a user can go to the MS store and push a button. Most UNIXy platforms come with Python preinstalled. All of these caveats aside, I think Grant's being a bit uncharitable. Cheers, Cameron Simpson From sjeik_appie at hotmail.com Thu Jun 3 07:30:48 2021 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Thu, 03 Jun 2021 13:30:48 +0200 Subject: Async requests library with NTLM auth support? In-Reply-To: Message-ID: > Asyncio and httpx [1] look promising but don't seem to support ntlm. Any tips? ==> https://pypi.org/project/httpx-ntlm/ Not sure how I missed this in the first place. :-) From sjeik_appie at hotmail.com Thu Jun 3 07:38:33 2021 From: sjeik_appie at hotmail.com (Albert-Jan Roskam) Date: Thu, 03 Jun 2021 13:38:33 +0200 Subject: Async code across Python versions Message-ID: Hi, I just started using async functions and I was wondering if there are any best practices to deal with developments in this area for Python 3.6 and up. I'm currently using Python 3.6 but I hope I can upgrade to 3.8 soon. Do I have to worry that my code might break? If so, is it better to use 3rd party libraries? It seems that things get a little easier with newer Python versions, so it might also a reason to simplify the code. Cheers! Albert-Jan From menyland at gmail.com Fri Jun 4 09:47:48 2021 From: menyland at gmail.com (Chris Nyland) Date: Fri, 4 Jun 2021 09:47:48 -0400 Subject: Data structure for plotting monotonically expanding data set In-Reply-To: <57afea5c-03dd-c1d2-ca12-ca849107997c@DancesWithMice.info> References: <878s40h6fo.fsf@hornfels.zedat.fu-berlin.de> <57afea5c-03dd-c1d2-ca12-ca849107997c@DancesWithMice.info> Message-ID: I agree with dn. While you could scrape the text files each time you want to display a user from a design perspective it makes more sense to use a database to store the data. This doesn't mean that you need to get rid of the text files or change the format that they are written to but instead that you just make a small ingest process that adds the data to the database at a regular interval, or it can even be triggered manually by you. You don't mention how many columns you have but even if it is a large number, say 100 I would recommend that you look into SQLite. It is a file based database that is widely used and supported and has a module that is included in core Python. As dn noted this will make retrieving the data much easier when you want to plot it. Additionally you don't mention how you want to display the information but if you want to use a web based application having your data in a database is going to make integration easier there as well. If you have all your data in a SQLite database you should be able to easily build a dashboard in Flask or in an Jupyter Notebook, or you will likely be able to take advantage of third party tools like Kibana. I know it may seem like more work now but getting your data into a database will pay off big in the long run. Chris On Thu, May 27, 2021 at 8:43 PM dn via Python-list wrote: > On 27/05/2021 21.28, Loris Bennett wrote: > > Hi, > > > > I currently a have around 3 years' worth of files like > > > > home.20210527 > > home.20210526 > > home.20210525 > > ... > > > > so around 1000 files, each of which contains information about data > > usage in lines like > > > > name kb > > alice 123 > > bob 4 > > ... > > zebedee 9999999 > > > > (there are actually more columns). I have about 400 users and the > > individual files are around 70 KB in size. > > > > Once a month I want to plot the historical usage as a line graph for the > > whole period for which I have data for each user. > > > > I already have some code to extract the current usage for a single from > > the most recent file: > > > > for line in open(file, "r"): > > columns = line.split() > > if len(columns) < data_column: > > logging.debug("no. of cols.: %i less than data col", > len(columns)) > > continue > > regex = re.compile(user) > > if regex.match(columns[user_column]): > > usage = columns[data_column] > > logging.info(usage) > > return usage > > logging.error("unable to find %s in %s", user, file) > > return "none" > > > > Obviously I will want to extract all the data for all users from a file > > once I have opened it. After looping over all files I would naively end > > up with, say, a nested dict like > > > > {"20210527": { "alice" : 123, , ..., "zebedee": 9999999}, > > "20210526": { "alice" : 123, "bob" : 3, ..., "zebedee": 9}, > > "20210525": { "alice" : 123, "bob" : 1, ..., "zebedee": 9999999}, > > "20210524": { "alice" : 123, ..., "zebedee": 9}, > > "20210523": { "alice" : 123, ..., "zebedee": 9999999}, > > ...} > > > > where the user keys would vary over time as accounts, such as 'bob', are > > added and latter deleted. > > > > Is creating a potentially rather large structure like this the best way > > to go (I obviously could limit the size by, say, only considering the > > last 5 years)? Or is there some better approach for this kind of > > problem? For plotting I would probably use matplotlib. > > > NB I am predisposed to use databases. People without such skills will > likely feel the time-and-effort investment to learn uneconomic for such > a simple, single, example! > > > Because the expressed concern seems to be the size of the data-set, (one > assumes) only certain users' data will be graphed (at one time). Another > concern may be that every time the routine executes, it repeats the bulk > of its regex-based processing. > > I would establish a DB with (at least, as appropriate) two tables: one > the list of files from which the data has been extracted, and the second > containing the data currently formatted as a dict. NB The second may > benefit from stating in "normal form" or splitting into related tables, > and certainly indexing. > > Thus the process requires two steps: firstly to capture the data (from > the files) into the DB, and secondly to graph the appropriate groups or > otherwise 'chosen' users. > > SQL will simplify data retrieval, and feeding into matplotlib (or > whichever tool). It will also enable simple improvements both to select > sub-sets of users or to project over various periods of time. > > YMMV! > -- > Regards, > =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From martinp.dipaola at gmail.com Sat Jun 5 10:24:10 2021 From: martinp.dipaola at gmail.com (Martin Di Paola) Date: Sat, 5 Jun 2021 14:24:10 +0000 Subject: Data structure for plotting monotonically expanding data set In-Reply-To: <5b2c8611-a7e2-4d15-8361-d171d8b4acafn@googlegroups.com> References: <878s40h6fo.fsf@hornfels.zedat.fu-berlin.de> <5b2c8611-a7e2-4d15-8361-d171d8b4acafn@googlegroups.com> Message-ID: <20210605142410.73fdouhyfjnyfd4z@gmail.com> One way to go is using Pandas as it was mentioned before and Seaborn for plotting (built on top of matplotlib) I would approach this prototyping first with a single file and not with the 1000 files that you have. Using the code that you have for parsing, add the values to a Pandas DataFrame (aka, a table). # load pandas and create a 'date' object to represent the file date # You'll have "pip install pandas" to use it import pandas as pd file_date = pd.to_datetime('20210527') # data that you parsed as list of lists with each list being # each line in your file. data = [ ["alice", 123, file_date], ["bob", 4, file_date], ["zebedee", 9999999, file_date] ] # then, load it as a pd.DataFrame df = pd.DataFrame(data, columns=['name', 'kb', 'date']) # print it print(df) name kb date 0 alice 123 2021-05-27 1 bob 4 2021-05-27 2 zebedee 9999999 2021-05-27 Now, this is the key point: You can save the dataframe in a file so you don't have to process the same file over and over. Pandas has different formats, some are more suitable than others. # I'm going to use "parquet" format which compress really well # and it is quite fast. You'll have "pip install pyarrow" to use it df.to_parquet('df-20210527.pq') Now you repeat this for all your files so you will end up with ~1000 parquet files. So, let's say that you want to plot some lines. You'll need to load those dataframes from disk. You read each file, get a Pandas DataFrame for each and then "concatenate" them into a single Pandas DataFrame all_dfs = [pd.read_parquet() for in <...>] df = pd.concat(all_dfs, ignore_index=True) Now, the plotting part. You said that you wanted to use matplotlib. I'll go one step forward and use seaborn (which it is implemented on top of matplotlib) import matplotlib.pyplot as plt import seaborn as sns # plot the mean of 'kb' per date as a point. Per each point # plot a vertical line showing the "spread" of the values and connect # the points with lines to show the slope (changes) between days sns.pointplot(data=df, x="date", y="kb") plt.show() # plot the distribution of the 'kb' values per each user 'name'. sns.violinplot(data=df, x="name", y="kb") plt.show() # plot the 'kb' per day for the 'alice' user sns.lineplot(data=df.query('name == "alice"'), x="date", y="kb") plt.show() That's all, a very quick intro to Pandas and Seaborn. Enjoy the hacking. Thanks, Martin. On Thu, May 27, 2021 at 08:55:11AM -0700, Edmondo Giovannozzi wrote: >Il giorno gioved? 27 maggio 2021 alle 11:28:31 UTC+2 Loris Bennett ha scritto: >> Hi, >> >> I currently a have around 3 years' worth of files like >> >> home.20210527 >> home.20210526 >> home.20210525 >> ... >> >> so around 1000 files, each of which contains information about data >> usage in lines like >> >> name kb >> alice 123 >> bob 4 >> ... >> zebedee 9999999 >> >> (there are actually more columns). I have about 400 users and the >> individual files are around 70 KB in size. >> >> Once a month I want to plot the historical usage as a line graph for the >> whole period for which I have data for each user. >> >> I already have some code to extract the current usage for a single from >> the most recent file: >> >> for line in open(file, "r"): >> columns = line.split() >> if len(columns) < data_column: >> logging.debug("no. of cols.: %i less than data col", len(columns)) >> continue >> regex = re.compile(user) >> if regex.match(columns[user_column]): >> usage = columns[data_column] >> logging.info(usage) >> return usage >> logging.error("unable to find %s in %s", user, file) >> return "none" >> >> Obviously I will want to extract all the data for all users from a file >> once I have opened it. After looping over all files I would naively end >> up with, say, a nested dict like >> >> {"20210527": { "alice" : 123, , ..., "zebedee": 9999999}, >> "20210526": { "alice" : 123, "bob" : 3, ..., "zebedee": 9}, >> "20210525": { "alice" : 123, "bob" : 1, ..., "zebedee": 9999999}, >> "20210524": { "alice" : 123, ..., "zebedee": 9}, >> "20210523": { "alice" : 123, ..., "zebedee": 9999999}, >> ...} >> >> where the user keys would vary over time as accounts, such as 'bob', are >> added and latter deleted. >> >> Is creating a potentially rather large structure like this the best way >> to go (I obviously could limit the size by, say, only considering the >> last 5 years)? Or is there some better approach for this kind of >> problem? For plotting I would probably use matplotlib. >> >> Cheers, >> >> Loris >> >> -- >> This signature is currently under construction. > >Have you tried to use pandas to read the data? >Then you may try to add a column with the date and then join the datasets. >-- >https://mail.python.org/mailman/listinfo/python-list From rshepard at appl-ecosys.com Sat Jun 5 17:36:43 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 5 Jun 2021 14:36:43 -0700 (PDT) Subject: Posting code on stackoverflow Message-ID: I tried to post a question on stackoverflow.com which included a bunch of code (entered after clicking the box 'code'). I noticed that lines were wrapped but could not find how to expand the input box so they would not wrap. SO wouldn't let me post the question because of the wrapped code. As I've not asked a question ther for a long time, and it didn't involve long lines of code, I need to learn a) how to enter code if it's not just clicking on the 'code' box before pasting text and b) how to keep code lines from wrapping so a horizontal scroll bar is made available. TIA, Rich From roel at roelschroeven.net Sat Jun 5 19:00:17 2021 From: roel at roelschroeven.net (Roel Schroeven) Date: Sun, 6 Jun 2021 01:00:17 +0200 Subject: Posting code on stackoverflow In-Reply-To: References: Message-ID: Rich Shepard schreef op 5/06/2021 om 23:36: > I tried to post a question on stackoverflow.com which included a bunch of > code (entered after clicking the box 'code'). I noticed that lines were > wrapped but could not find how to expand the input box so they would not > wrap. > > SO wouldn't let me post the question because of the wrapped code. As I've > not asked a question ther for a long time, and it didn't involve long lines > of code, I need to learn a) how to enter code if it's not just clicking on > the 'code' box before pasting text and b) how to keep code lines from > wrapping so a horizontal scroll bar is made available. There are several ways to format code on StackOverflow, see https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks What I do most of the time is indent the code by 4 spaces and make sure there are blank lines before and after the code block. -- "Honest criticism is hard to take, particularly from a relative, a friend, an acquaintance, or a stranger." -- Franklin P. Jones Roel Schroeven From rshepard at appl-ecosys.com Sat Jun 5 22:02:13 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 5 Jun 2021 19:02:13 -0700 (PDT) Subject: Posting code on stackoverflow In-Reply-To: References: Message-ID: On Sun, 6 Jun 2021, Roel Schroeven wrote: > There are several ways to format code on StackOverflow, see > https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks Roel, Thanks very much for the URL. > What I do most of the time is indent the code by 4 spaces and make sure > there are blank lines before and after the code block. Just now I noticed a link 'code' along the top of the window. Clicking on that I read that a code block can be identified as such by surrounding it with sets of three backticks (```). That worked. Regards, Rich From tjreedy at udel.edu Sat Jun 5 21:56:54 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 5 Jun 2021 21:56:54 -0400 Subject: Posting code on stackoverflow In-Reply-To: References: Message-ID: On 6/5/2021 5:36 PM, Rich Shepard wrote: > I tried to post a question on stackoverflow.com which included a bunch of > code (entered after clicking the box 'code'). I noticed that lines were > wrapped but could not find how to expand the input box so they would not > wrap. > > SO wouldn't let me post the question because of the wrapped code. As I've > not asked a question ther for a long time, and it didn't involve long lines > of code, I need to learn a) how to enter code if it's not just clicking on > the 'code' box before pasting text Last time I tried *before*, it did not work. paste, reselect (a nuisance) and click does. -- Terry Jan Reedy From PythonList at DancesWithMice.info Sun Jun 6 04:23:56 2021 From: PythonList at DancesWithMice.info (dn) Date: Sun, 6 Jun 2021 20:23:56 +1200 Subject: Posting code on stackoverflow In-Reply-To: References: Message-ID: On 06/06/2021 13.56, Terry Reedy wrote: > On 6/5/2021 5:36 PM, Rich Shepard wrote: >> I tried to post a question on stackoverflow.com which included a bunch of >> code (entered after clicking the box 'code'). I noticed that lines were >> wrapped but could not find how to expand the input box so they would not >> wrap. >> >> SO wouldn't let me post the question because of the wrapped code. As I've >> not asked a question ther for a long time, and it didn't involve long >> lines >> of code, I need to learn a) how to enter code if it's not just >> clicking on >> the 'code' box before pasting text > > Last time I tried *before*, it did not work.? paste, reselect (a > nuisance) and click does. Using text-mode email formatting and copy-pasting 'here', works well! -- Regards, =dn From joepareti54 at gmail.com Sun Jun 6 05:17:46 2021 From: joepareti54 at gmail.com (joseph pareti) Date: Sun, 6 Jun 2021 11:17:46 +0200 Subject: Posting code on stackoverflow In-Reply-To: References: Message-ID: you need to put the code between 2 lines defined as follows: ``` then it will be formatted for you Am Sa., 5. Juni 2021 um 23:40 Uhr schrieb Rich Shepard < rshepard at appl-ecosys.com>: > I tried to post a question on stackoverflow.com which included a bunch of > code (entered after clicking the box 'code'). I noticed that lines were > wrapped but could not find how to expand the input box so they would not > wrap. > > SO wouldn't let me post the question because of the wrapped code. As I've > not asked a question ther for a long time, and it didn't involve long lines > of code, I need to learn a) how to enter code if it's not just clicking on > the 'code' box before pasting text and b) how to keep code lines from > wrapping so a horizontal scroll bar is made available. > > TIA, > > Rich > -- > https://mail.python.org/mailman/listinfo/python-list > -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 From fabiofz at gmail.com Sun Jun 6 06:21:34 2021 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Sun, 6 Jun 2021 07:21:34 -0300 Subject: Neither pdb or print() displays the bug In-Reply-To: References: <20cb1a4f-ec85-9ea0-effe-b916f8be5a23@stoneleaf.us> <0343b334-2e10-f055-896b-b3ef9d080401@stoneleaf.us> Message-ID: Em qua., 2 de jun. de 2021 ?s 09:34, Rich Shepard escreveu: > On Wed, 2 Jun 2021, Peter Otten wrote: > > > Do you have unit tests? Those are an excellent tool to ensure that the > > components of an application work as expected and that those components > > have well-defined interfaces. Debugging a failing unittest is usually > > easier than to debug a complex application. While I don't know if there > is > > a convenient way to test the GUI everything else should run reliably > > *before* connecting it with the GUI. > > Peter, > > I believe there is a way to apply unit tests to PyQt and I'll certainly > learn to take this testing-while-developing approach. > Hint: you should be able to use https://pypi.org/project/pytest-qt/ to unit-test a PyQt application... From fabiofz at gmail.com Sun Jun 6 06:28:27 2021 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Sun, 6 Jun 2021 07:28:27 -0300 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> References: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> Message-ID: You could try other debuggers (possibly doing a remote debug session or attach to pid). Eclipse-PyDev: https://www.pydev.org/manual_adv_remote_debugger.html VsCode-python: https://code.visualstudio.com/docs/python/debugging PyCharm: https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html Em dom., 30 de mai. de 2021 ?s 14:43, escreveu: > I tried winpdb-reborn some time last year on my Win10 system (python 3.8.3 > at that time), but could not figure out how to use it to debug a python > script that uses the curses module. > > Does anyone here know if winpdb-reborn or any other debugger can support > 2-window debugging for a python script that uses the curses module? It > seems to me that a 2-window debugging session is necessary for a python > script that uses the curses module because using curses takes over the > screen from which the script is started, so debugging output and script > output need to be in separate windows. > > I've been forced to use a logger to trace critical values and program flow > for errors in such a script. It works, but it is annoyingly slow to debug > that way. > > TIA for any advice or RTFM you can provide. > > Peter > -- > > -- > https://mail.python.org/mailman/listinfo/python-list > From rshepard at appl-ecosys.com Sun Jun 6 08:33:19 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 6 Jun 2021 05:33:19 -0700 (PDT) Subject: Posting code on stackoverflow In-Reply-To: References: Message-ID: On Sun, 6 Jun 2021, joseph pareti wrote: > you need to put the code between 2 lines defined as follows: > ``` > then it will be formatted for you Thanks, Joseph. I figured that out on the web page. Regards, Rich From rshepard at appl-ecosys.com Sun Jun 6 08:34:49 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 6 Jun 2021 05:34:49 -0700 (PDT) Subject: Neither pdb or print() displays the bug In-Reply-To: References: <20cb1a4f-ec85-9ea0-effe-b916f8be5a23@stoneleaf.us> <0343b334-2e10-f055-896b-b3ef9d080401@stoneleaf.us> Message-ID: On Sun, 6 Jun 2021, Fabio Zadrozny wrote: > Hint: you should be able to use https://pypi.org/project/pytest-qt/ to > unit-test a PyQt application... Fabio, Thank you for confirming this. I hadn't remembered the name so your URL is really helpful. Regards, Rich From rshepard at appl-ecosys.com Sun Jun 6 08:36:36 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 6 Jun 2021 05:36:36 -0700 (PDT) Subject: Posting code on stackoverflow In-Reply-To: References: Message-ID: On Sat, 5 Jun 2021, Terry Reedy wrote: > Last time I tried *before*, it did not work. paste, reselect (a nuisance) > and click does. Terry, I had tried that and it didn't work any better. Bounding the code with two sets of three backticks does work. Regards, Rich From inhahe at gmail.com Sun Jun 6 13:00:15 2021 From: inhahe at gmail.com (inhahe) Date: Sun, 6 Jun 2021 13:00:15 -0400 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> References: <000001d75578$f4ced0b0$de6c7210$@earthlink.net> Message-ID: On Sun, May 30, 2021 at 1:43 PM wrote: > I tried winpdb-reborn some time last year on my Win10 system (python 3.8.3 > at that time), but could not figure out how to use it to debug a python > script that uses the curses module. > > Does anyone here know if winpdb-reborn or any other debugger can support > 2-window debugging for a python script that uses the curses module? It > seems to me that a 2-window debugging session is necessary for a python > script that uses the curses module because using curses takes over the > screen from which the script is started, so debugging output and script > output need to be in separate windows. > > I've been forced to use a logger to trace critical values and program flow > for errors in such a script. It works, but it is annoyingly slow to debug > that way. > > TIA for any advice or RTFM you can provide. > > Peter > -- > > -- > https://mail.python.org/mailman/listinfo/python-list I don 't know if this solution was mentioned, but someone in IRC just said this is especially useful for debugging curses, and it reminded me of this thread. https://pypi.org/project/q/ From pjfarley3 at earthlink.net Mon Jun 7 00:04:46 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Mon, 7 Jun 2021 00:04:46 -0400 Subject: ctypes on Windows question: How to access an array of uint32_t exported from a DLL? Message-ID: <000201d75b52$414dc2a0$c3e947e0$@earthlink.net> On a Windows 10 platform (python 3.8.9 and 3.9.5), how do I use ctypes to access an array of uint32_t's exported from a DLL? The array (after various #define's are resolved) is defined as: __declspec(dllexport) extern uint32_t array_name[128]; I have read and re-read the ctypes documentation and I am still confused about how to access the exported array (read only, not for modification) from a python script. The DLL is successfully accessed and functions from it are usable after executing syntax similar to this: extlib = ctypes.CDLL(dllpath) Where "dllpath" is a fully-qualified path to the DLL. TIA for any help you can provide. Peter -- From gorlemaheshwari at gmail.com Mon Jun 7 00:03:56 2021 From: gorlemaheshwari at gmail.com (Maheshwari Gorle) Date: Sun, 6 Jun 2021 21:03:56 -0700 (PDT) Subject: Help me in setting the path in python program. Message-ID: <150a5036-4e83-4240-b284-b5b2990aca24n@googlegroups.com> I am using Google co lab. Guide me how to set the path. # Error: SwissEph file 'se13681s.se1' not found in PATH '/usr/share/ephe/' is coming, how to overcome this problem. pip install pyswisseph import swisseph as swe swe.set_ephe_path ('/usr/share/ephe') # set path to ephemeris files jd = swe.julday(2008,3,21) swe.calc_ut(jd, swe.AST_OFFSET+13681[0][0] From eryksun at gmail.com Mon Jun 7 12:33:52 2021 From: eryksun at gmail.com (Eryk Sun) Date: Mon, 7 Jun 2021 11:33:52 -0500 Subject: ctypes on Windows question: How to access an array of uint32_t exported from a DLL? In-Reply-To: <000201d75b52$414dc2a0$c3e947e0$@earthlink.net> References: <000201d75b52$414dc2a0$c3e947e0$@earthlink.net> Message-ID: On 6/6/21, pjfarley3 at earthlink.net wrote: > > On a Windows 10 platform (python 3.8.9 and 3.9.5), how do I use ctypes to > access an array of uint32_t's exported from a DLL? > ... > __declspec(dllexport) extern uint32_t array_name[128]; A ctypes data type has an in_dll() method [1] that returns an instance of the type that references data in a shared library (DLL). It takes a CDLL instance for the shared library and the exported symbol name. For example: data = (ctypes.c_uint32 * 128).in_dll(library, "array_name") --- [1] https://docs.python.org/3/library/ctypes.html#ctypes._CData.in_dll From mats at wichmann.us Mon Jun 7 19:39:40 2021 From: mats at wichmann.us (Mats Wichmann) Date: Mon, 7 Jun 2021 17:39:40 -0600 Subject: How to debug python + curses? [was: RE: Applying winpdb_reborn] In-Reply-To: <004f01d75817$43bde710$cb39b530$@earthlink.net> References: <8rb8bg1qonkhcr5bkh27is6br690gm2845@4ax.com> <004f01d75817$43bde710$cb39b530$@earthlink.net> Message-ID: <975d2522-ea88-8f62-f118-552ff014485b@wichmann.us> On 6/2/21 7:24 PM, pjfarley3 at earthlink.net wrote: >> -----Original Message----- >> From: Grant Edwards >> Sent: Monday, May 31, 2021 11:18 AM >> To: python-list at python.org >> Subject: Re: How to debug python + curses? [was: RE: Applying > winpdb_reborn] >> >> On 2021-05-31, Dennis Lee Bieber wrote: >>> On Mon, 31 May 2021 08:07:21 +1000, Cameron Simpson >>> declaimed the following: >>> >>> >>>> Open another terminal, note its terminal device with the "tty" command. >>>> Start your programme like this: >>>> >>>> python ...... 2>/dev/tty-of-the-other-termina >>> >>> The OP specified Win10, so the above is dead from the start. >> >> Perhaps Windows isn't an appropriate OS under which to develop curses >> applicatoins? > > Perhaps, but why isn't it? > > > Why are Windows users, even knowledgeable ones, so often considered second- > or even third-class netizens? > > I do know some of the answers that will come back for that question, but the > attitude is not professional. > Not trying to answer the question, just commenting: it's gotten a lot better in the Python world the last few years, as people have realized that like it or not, most users are actually on Windows. BUT, the ML/Big Data world isn't quite the same. It's new and people are developing at a rapid rate and Windows just seems to get in the way (again avoiding speculating since I don't work in that world) and those things often are heavily tilted to a Linux bias. Or if you can't do that, WSL. So the bias you mention is arising again in a new way. curses is its own story - that's what kicked off this thread. It was a UNIX thing well before there was a Windows at all (1970s, "I was there", but not in any way a contributor), and just wasn't built to the WIndows programming paradigm, why would it be? Of course people have tried to fill that void over the years, with some success, but as has been seen from details in this thread it just doesn't seem to be that important even to those folks and seems to be dying on the vine again. From pjfarley3 at earthlink.net Mon Jun 7 21:47:44 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Mon, 7 Jun 2021 21:47:44 -0400 Subject: ctypes on Windows question: How to access an array of uint32_t exported from a DLL? In-Reply-To: References: <000201d75b52$414dc2a0$c3e947e0$@earthlink.net> Message-ID: <000001d75c08$470fa3a0$d52eeae0$@earthlink.net> > -----Original Message----- > From: Eryk Sun > Sent: Monday, June 7, 2021 12:34 PM > To: python-list at python.org > Cc: pjfarley3 at earthlink.net > Subject: Re: ctypes on Windows question: How to access an array of uint32_t > exported from a DLL? > > On 6/6/21, pjfarley3 at earthlink.net wrote: > > > > On a Windows 10 platform (python 3.8.9 and 3.9.5), how do I use ctypes > > to access an array of uint32_t's exported from a DLL? > > ... > > __declspec(dllexport) extern uint32_t array_name[128]; > > A ctypes data type has an in_dll() method [1] that returns an instance of the type > that references data in a shared library (DLL). It takes a CDLL instance for the > shared library and the exported symbol name. For > example: > > data = (ctypes.c_uint32 * 128).in_dll(library, "array_name") Thanks for the help. I just didn't see this kind of simple case demonstrated on the ctypes doc page. I guess I am just a bit dense. Mea culpa. Anyway, thanks again. Peter -- From rshepard at appl-ecosys.com Tue Jun 8 14:54:17 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 8 Jun 2021 11:54:17 -0700 (PDT) Subject: Neither pdb or print() displays the bug [FIXED] In-Reply-To: References: Message-ID: On Tue, 1 Jun 2021, Rich Shepard wrote: > I'm stuck with neither approach (pdb, print()) working. I moved the > database code to a separate module, datasource.py, and when I run the > activitytypes.py module (using pdb and having entered print() statements > at various places in both the datasource and activities modules all I get > is a small, empty window with the window title. The QSize() statement is > never reached. Found and fixed the problem. Qt5 added support for PostgreSQL-12 in Qt5-5.15.0. I upgraded both Qt5 and PyQt5 to 5.15.2 and now the tables display the rows in the one column of the table. Thanks for all the suggestions, Rich From darcy at VybeNetworks.com Tue Jun 8 15:08:53 2021 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Tue, 8 Jun 2021 15:08:53 -0400 Subject: Replacement for Mailman Message-ID: Given that mailman still runs under 2.7 and that's being deprecated, does anyone have a suggestion for a replacement? -- 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: OpenPGP_signature Type: application/pgp-signature Size: 236 bytes Desc: OpenPGP digital signature URL: From pbryan at anode.ca Tue Jun 8 15:36:25 2021 From: pbryan at anode.ca (Paul Bryan) Date: Tue, 08 Jun 2021 12:36:25 -0700 Subject: Replacement for Mailman In-Reply-To: References: Message-ID: How about Mailman 3.x on Python 3.x? On Tue, 2021-06-08 at 15:08 -0400, D'Arcy Cain wrote: > Given that mailman still runs under 2.7 and that's being deprecated, > does > anyone have a suggestion for a replacement? > From jon+usenet at unequivocal.eu Tue Jun 8 15:27:47 2021 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 8 Jun 2021 19:27:47 -0000 (UTC) Subject: Replacement for Mailman References: Message-ID: On 2021-06-08, D'Arcy Cain wrote: > Given that mailman still runs under 2.7 and that's being deprecated, > does anyone have a suggestion for a replacement? There is always Mailman 3... From grant.b.edwards at gmail.com Tue Jun 8 15:45:41 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 8 Jun 2021 19:45:41 -0000 (UTC) Subject: Replacement for Mailman References: Message-ID: On 2021-06-08, Paul Bryan wrote: > How about Mailman 3.x on Python 3.x? According to https://www.gnu.org/software/mailman/requirements.html mailman 3.x still requires Python 2.7 for the archiver and the web UI. -- Grant Edwards grant.b.edwards Yow! Do you guys know we at just passed thru a BLACK gmail.com HOLE in space? From jon+usenet at unequivocal.eu Tue Jun 8 16:36:26 2021 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 8 Jun 2021 20:36:26 -0000 (UTC) Subject: Replacement for Mailman References: Message-ID: On 2021-06-08, Grant Edwards wrote: > On 2021-06-08, Paul Bryan wrote: >> How about Mailman 3.x on Python 3.x? > > According to https://www.gnu.org/software/mailman/requirements.html > mailman 3.x still requires Python 2.7 for the archiver and the web UI. I'm pretty sure that's out of date. From tjreedy at udel.edu Tue Jun 8 19:22:57 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 8 Jun 2021 19:22:57 -0400 Subject: Replacement for Mailman In-Reply-To: References: Message-ID: On 6/8/2021 3:08 PM, D'Arcy Cain wrote: > Given that mailman still runs under 2.7 and that's being deprecated, It is not 'deprecated'. Rather, official python.org support, including security fixes, has ended. The same is true of 3.x up to 3.5, and 3.6 by the end of the year. I don't know if RedHat, for instance, followed through with plans to extend security fixes for customers paying for long-term support releases. If they have, a patched 2.7 might be safer than the last 3.5. -- Terry Jan Reedy From tjreedy at udel.edu Tue Jun 8 19:28:06 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 8 Jun 2021 19:28:06 -0400 Subject: Replacement for Mailman In-Reply-To: References: Message-ID: On 6/8/2021 4:36 PM, Jon Ribbens via Python-list wrote: > On 2021-06-08, Grant Edwards wrote: >> On 2021-06-08, Paul Bryan wrote: >>> How about Mailman 3.x on Python 3.x? >> >> According to https://www.gnu.org/software/mailman/requirements.html >> mailman 3.x still requires Python 2.7 for the archiver and the web UI. > > I'm pretty sure that's out of date. https://pypi.org/project/mailman/ 3.3.4 works with 3.6 to 3.9 -- Terry Jan Reedy From rosuav at gmail.com Tue Jun 8 19:34:56 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 9 Jun 2021 09:34:56 +1000 Subject: Replacement for Mailman In-Reply-To: References: Message-ID: On Wed, Jun 9, 2021 at 8:46 AM Jon Ribbens via Python-list wrote: > > On 2021-06-08, Grant Edwards wrote: > > On 2021-06-08, Paul Bryan wrote: > >> How about Mailman 3.x on Python 3.x? > > > > According to https://www.gnu.org/software/mailman/requirements.html > > mailman 3.x still requires Python 2.7 for the archiver and the web UI. > > I'm pretty sure that's out of date. Needs a Mailman expert to confirm, but this page does seem to imply that you can use Python 3.6+ (preferably 3.7+) for everything: https://docs.mailman3.org/en/latest/install/virtualenv.html#virtualenv-install Notably, mailman-web gets installed into the same venv as everything else, implying that it should be using the exact same Python version. ChrisA From mats at wichmann.us Tue Jun 8 20:13:06 2021 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 8 Jun 2021 18:13:06 -0600 Subject: Replacement for Mailman In-Reply-To: References: Message-ID: On 6/8/21 5:34 PM, Chris Angelico wrote: > On Wed, Jun 9, 2021 at 8:46 AM Jon Ribbens via Python-list > wrote: >> >> On 2021-06-08, Grant Edwards wrote: >>> On 2021-06-08, Paul Bryan wrote: >>>> How about Mailman 3.x on Python 3.x? >>> >>> According to https://www.gnu.org/software/mailman/requirements.html >>> mailman 3.x still requires Python 2.7 for the archiver and the web UI. >> >> I'm pretty sure that's out of date. > > Needs a Mailman expert to confirm, but this page does seem to imply > that you can use Python 3.6+ (preferably 3.7+) for everything: I know drifting well off topic, but I'm involved with some projects that get free mailman hosting from a generous provider, which however has expressed no interest at all (rather, a specific "we will not") in upgrading from mm2. Sigh. From jon+usenet at unequivocal.eu Tue Jun 8 20:45:08 2021 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 9 Jun 2021 00:45:08 -0000 (UTC) Subject: Replacement for Mailman References: Message-ID: On 2021-06-08, Terry Reedy wrote: > On 6/8/2021 4:36 PM, Jon Ribbens via Python-list wrote: >> On 2021-06-08, Grant Edwards wrote: >>> On 2021-06-08, Paul Bryan wrote: >>>> How about Mailman 3.x on Python 3.x? >>> >>> According to https://www.gnu.org/software/mailman/requirements.html >>> mailman 3.x still requires Python 2.7 for the archiver and the web UI. >> >> I'm pretty sure that's out of date. > > https://pypi.org/project/mailman/ > 3.3.4 works with 3.6 to 3.9 That's doesn't provide the complete answer though. A Mailman 3 installation requires multiple packages to be installed, including: * Mailman Core * Postorius * MailmanClient * HyperKitty * HyperKitty Mailman plugin * Django * uwsgi / gunicorn / etc >From a brief look, I think all of these support Python 3.6+. Obviously, the delegation of separate functions of the system to separate packages is in many respects entirely sensible, but it also seems likely that this complexity is the cause of the very low take-up of Mailman 3. From muralidhar.n at lge.com Wed Jun 9 13:25:35 2021 From: muralidhar.n at lge.com (Muralidhar N) Date: Thu, 10 Jun 2021 02:25:35 +0900 Subject: Threads shutting down in Py 2.7 but not in Py 3.69(or 3.x) Message-ID: Dear All, Threads shutting down in Py 2.7 but not in Py 3.69(or 3.x) while making SSH connection using Paramiko/PySSH module or Socket Executing code qa-test-execute.py in Py 2.7 (Ubuntu 14.04.6 LTS) Command 1 : sudo python ./qa-test-execute.py Output 1 : 2021-05-24 23:35:59,889[BaseCommandLine __init__ 139916740505872][DEBUG]: Attempt to close ssh-session within 10.0 seconds. Exception AssertionError: 'attempt to release recursive lock not owned by thread' in > ignored Command 2 : sudo python ./qa-test-execute.py 2>&1 | tee 24052021_py27_execute_1.log Output 2 : 2021-05-24 23:50:16,303[BaseCommandLine __init__ 139863250567440][DEBUG]: Attempt to close ssh-session within 10.0 seconds. Exception AssertionError: 'attempt to release recursive lock not owned by thread' in > ignored Executing code qa-test-execute.py in Py 3.69 ( or 3.x - Ubuntu 18.04.5 LTS) Command 1 : sudo python ./qa-test-execute-xxx.py Output 1 : 2021-05-24 23:53:49,293[BaseCommandLine __init__ 139973197423840][DEBUG]: Attempt to close ssh-session within 10.0 seconds. 2021-05-24 23:53:49,293[BaseCommandLine __init__ 139973197423840][DEBUG]: Closing internal ssh-client. Fatal Python error: could not acquire lock for <_io.BufferedWriter name=''> at interpreter shutdown, possibly due to daemon threads Command 2 : sudo python3 ./qa-test-execute-xxx.py 2>&1 | tee test.log Output 2 : Terminal hangs & CTRL C to return prompt 2021-05-24 23:56:31,646[BaseCommandLine __init__ 140516619855072][DEBUG]: Attempt to close ssh-session within 10.0 seconds. 2021-05-24 23:56:31,646[BaseCommandLine __init__ 140516619855072][DEBUG]: Closing internal ssh-client. ^C Behaviour of same code is different when executed in Py 2.7 & Py 3.69 ( or 3.x ). Threads not terminating normally conflicting with paramiko or pyssh or socket & logging module -------------- next part -------------- #!/usr/bin/env python3 import sys import traceback import logging import logging.config import time import threading import multiprocessing import paramiko ######################################################################## def lock_acquire_with_timeout1(lock, timeout_seconds): """ Try to acquire lock without specified timeout @param lock: threading lock to be acquired @type lock: threading.Lock @param timeout_seconds: maximal time to make lock acquire attempts @type timeout_seconds: float """ begin_time = time.time() while time.time() - begin_time < timeout_seconds: if lambda: lock.acquire(False): return True else: time.sleep(1.0) return None def call_with_timeout1(method_to_call, timeout_seconds): """ Good for potentially "freeze" methods calls. Executes passed method in separate thread. Waits for control returns within timeout. If timeout exceed - return control to callee thread. Separate execution thread will still be active. @param method_to_call: method te be called @type method_to_call: function @param timeout_seconds: maximal time to wait for method call finished @type timeout_seconds: float """ stop_thread = threading.Barrier(2) thread_name = threading._newname("{}-%d".format(__name__)) call_thread = threading.Thread(target=method_to_call, name=thread_name) call_thread.daemon = True call_thread.start() print ("threading.activeCount() : %s",threading.activeCount()) print ("threading.currentThread() : %s", threading.currentThread()) print ("threading.enumerate() : %s", threading.enumerate() ) call_thread.join(timeout=timeout_seconds) if call_thread.is_alive(): stop_thread.abort() return not call_thread.is_alive() def format_all_threads_stacks1(): """ @return: formatted stacks for all running threads. """ stacktraces = [] for thread_id, stack in list(dict(list(sys._current_frames().items())).items()): for thread1 in threading.enumerate(): if thread1.ident == thread_id: stacktraces.append('Thread %s (daemon=%r) stacktrace: \n%s' % (thread1.name, thread1.daemon, ''.join(traceback.format_stack(stack)))) else: thread = None return '\n'.join(stacktraces) class SSHClient_noauth1(paramiko.SSHClient): def _auth(self, username, *args): self._transport.auth_none(username) return class BaseCommandLine1(object): def __init__(self, connection_timeout=None): self._connection_timeout = connection_timeout self._connection_lock = multiprocessing.RLock() self._ssh_client = None self.logger = logging.getLogger('BaseCommandLine __init__ {}'.format(id(self))) self.reset_connection1() def __del__(self): self.close1() def _wait_for_connection1(self): begin_time = time.time() self.logger.debug("Will attempt to connect with device for %s seconds." % self._connection_timeout) while time.time() - begin_time < self._connection_timeout: try: self._connect_ssh1() self._ssh_client.get_transport().set_keepalive(5) self.logger.debug('BaseCommandLine1 new SSH connection with {}:{} established.'. format("10.221.42.29", "22")) break except Exception as e: self.logger.debug('BaseCommandLine1 SSH-connection failed after %d seconds passed with exception: %s' % (time.time() - begin_time, e)) self.logger.debug('BaseCommandLine1 Next attempt after {} seconds.'.format(5.0)) time.sleep(5.0) else: self.logger.debug('BaseCommandLine1 Failed to connect to {}:{} within {} seconds: {}'.format( "10.221.42.29","22",self._connection_timeout,traceback.format_exc())) def reset_connection1(self): with self._connection_lock: self.close1() self.logger.debug('reset connection begin.') self._wait_for_connection1() def close1(self): if not self._ssh_client: return close_timeout = 10.0 begin_time = time.time() self.logger.debug("Attempt to close ssh-session within %s seconds." % close_timeout) if lock_acquire_with_timeout1(self._connection_lock, close_timeout): try: if call_with_timeout1(self.__nonblocking_close1, timeout_seconds=close_timeout): self.logger.debug("Successfully closed SSHClient within %d seconds." % (time.time() - begin_time)) else: self.logger.warning("Failed to close SSHClient within %d seconds." % close_timeout) self.logger.warning("All threads state:\n%s" % format_all_threads_stacks1()) finally: self._connection_lock.release() else: self.logger.warning("Failed to acquire lock within %s timeout." % close_timeout) self._ssh_client = None def __nonblocking_close1(self): """ Non-blocking call to close SSH connection. May freeze on internal SSHClient.close(). """ self.logger.debug("Closing internal ssh-client.") if self._ssh_client: self._ssh_client.close1() self.logger.debug("Internal ssh-client closed.") self._ssh_client = None def _connect_ssh1(self, key_filename=None): client = SSHClient_noauth1() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: # try using specified password first self.logger.debug("BaseCommandLine1 _connect_ssh1 - try using specified password first") client.connect("10.221.42.29", port="22", username="root", password="", timeout=60.0, banner_timeout=60.0, key_filename=None, allow_agent=False) except paramiko.AuthenticationException as e: # in case of authentication error try to connect without password self.logger.debug("BaseCommandLine1_connect_ssh1 - in case of authentication error try to connect without password : %s" % str(e)) self._ssh_client = client return client def config_logging(): formatter = logging.Formatter("%(asctime)s[%(name)s]" "[%(levelname)s]: %(message)s") console_logger = logging.StreamHandler(sys.stdout) console_logger.setFormatter(formatter) root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG) root_logger.addHandler(logging.NullHandler()) paramiko_logger = logging.getLogger('paramiko') paramiko_logger.setLevel(logging.CRITICAL) paramiko_logger.addHandler(console_logger) console_logger.setLevel(logging.DEBUG) root_logger.addHandler(console_logger) def main(argv): config_logging() try: result = BaseCommandLine1(300) except Exception: logging.debug("Exception from BaseCommandLine1") logging.debug("Show all threads status before exit attempt:\n %s", format_all_threads_stacks1()) if __name__ == "__main__": main(sys.argv) -------------- next part -------------- #!/usr/bin/env python3 import sys import traceback import logging import logging.config import time import threading import multiprocessing import socket ######################################################################## def lock_acquire_with_timeout1(lock, timeout_seconds): """ Try to acquire lock without specified timeout @param lock: threading lock to be acquired @type lock: threading.Lock @param timeout_seconds: maximal time to make lock acquire attempts @type timeout_seconds: float """ begin_time = time.time() while time.time() - begin_time < timeout_seconds: if lambda: lock.acquire(False): return True else: time.sleep(1.0) return None def call_with_timeout1(method_to_call, timeout_seconds): """ Good for potentially "freeze" methods calls. Executes passed method in separate thread. Waits for control returns within timeout. If timeout exceed - return control to callee thread. Separate execution thread will still be active. @param method_to_call: method te be called @type method_to_call: function @param timeout_seconds: maximal time to wait for method call finished @type timeout_seconds: float """ stop_thread = threading.Barrier(2) thread_name = threading._newname("{}-%d".format(__name__)) call_thread = threading.Thread(target=method_to_call, name=thread_name) call_thread.daemon = True call_thread.start() print ("threading.activeCount() : %s",threading.activeCount()) print ("threading.currentThread() : %s", threading.currentThread()) print ("threading.enumerate() : %s", threading.enumerate() ) call_thread.join(timeout=timeout_seconds) if call_thread.is_alive(): stop_thread.abort() return not call_thread.is_alive() #return True def format_all_threads_stacks1(): """ @return: formatted stacks for all running threads. """ stacktraces = [] for thread_id, stack in list(dict(list(sys._current_frames().items())).items()): for thread1 in threading.enumerate(): if thread1.ident == thread_id: stacktraces.append('Thread %s (daemon=%r) stacktrace: \n%s' % (thread1.name, thread1.daemon, ''.join(traceback.format_stack(stack)))) else: thread = None return '\n'.join(stacktraces) class BaseCommandLine1(object): def __init__(self, connection_timeout=None): self._connection_timeout = connection_timeout self._connection_lock = multiprocessing.RLock() self._ssh_client = None self.logger = logging.getLogger('BaseCommandLine __init__ {}'.format(id(self))) self.reset_connection1() def __del__(self): self.close1() def _wait_for_connection1(self): begin_time = time.time() self.logger.debug("Will attempt to connect with device for %s seconds." % self._connection_timeout) while time.time() - begin_time < self._connection_timeout: try: self._connect_ssh1() self.logger.debug('BaseCommandLine1 new SSH connection with {}:{} established.'. format("10.221.42.29", "22")) break except Exception as e: self.logger.debug('BaseCommandLine1 SSH-connection failed after %d seconds passed with exception: %s' % (time.time() - begin_time, e)) self.logger.debug('BaseCommandLine1 Next attempt after {} seconds.'.format(5.0)) time.sleep(5.0) else: self.logger.debug('BaseCommandLine1 Failed to connect to {}:{} within {} seconds: {}'.format( "10.221.42.29","22",self._connection_timeout,traceback.format_exc())) def reset_connection1(self): with self._connection_lock: self.close1() self.logger.debug('reset connection begin.') self._wait_for_connection1() def close1(self): if not self._ssh_client: return close_timeout = 10.0 begin_time = time.time() self.logger.debug("Attempt to close ssh-session within %s seconds." % close_timeout) if lock_acquire_with_timeout1(self._connection_lock, close_timeout): try: if call_with_timeout1(self.__nonblocking_close1, timeout_seconds=close_timeout): #if self.__nonblocking_close1(): self.logger.debug("Successfully closed SSHClient within %d seconds." % (time.time() - begin_time)) else: self.logger.warning("Failed to close SSHClient within %d seconds." % close_timeout) self.logger.warning("All threads state:\n%s" % format_all_threads_stacks1()) finally: #self._connection_lock.release() self.logger.debug('self._connection_lock release') else: self.logger.warning("Failed to acquire lock within %s timeout." % close_timeout) self._ssh_client = None def __nonblocking_close1(self): """ Non-blocking call to close SSH connection. May freeze on internal SSHClient.close(). """ result = False self.logger.debug("Closing internal ssh-client.") if self._ssh_client: socket_close_response = self._ssh_client.close() self.logger.debug('self._ssh_client.close1 : %s' % socket_close_response) result = True self.logger.debug("Internal ssh-client closed.") self._ssh_client = None return result def _connect_ssh1(self, key_filename=None): s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) print("Socket Name : " , s1) # get local machine name host = '10.221.42.29' port = 22 # connection to hostname on the port. try: s1.connect((host, port)) print("Connection Established", s1) except Exception as e: print("Connection error :", str(e)) self._ssh_client = s1 return s1 def config_logging(): formatter = logging.Formatter("%(asctime)s[%(name)s]" "[%(levelname)s]: %(message)s") console_logger = logging.StreamHandler(sys.stdout) console_logger.setFormatter(formatter) root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG) root_logger.addHandler(logging.NullHandler()) paramiko_logger = logging.getLogger('paramiko') paramiko_logger.setLevel(logging.CRITICAL) paramiko_logger.addHandler(console_logger) console_logger.setLevel(logging.DEBUG) root_logger.addHandler(console_logger) def main(argv): config_logging() try: result = BaseCommandLine1(300) except Exception: logging.debug("Exception from BaseCommandLine1") logging.debug("Show all threads status before exit attempt:\n %s", format_all_threads_stacks1()) if __name__ == "__main__": main(sys.argv) -------------- next part -------------- #!/usr/bin/env python3 import sys import traceback import logging import logging.config import time import threading import multiprocessing import pyssh ######################################################################## def lock_acquire_with_timeout1(lock, timeout_seconds): """ Try to acquire lock without specified timeout @param lock: threading lock to be acquired @type lock: threading.Lock @param timeout_seconds: maximal time to make lock acquire attempts @type timeout_seconds: float """ begin_time = time.time() while time.time() - begin_time < timeout_seconds: if lambda: lock.acquire(False): return True else: time.sleep(1.0) return None def call_with_timeout1(method_to_call, timeout_seconds): """ Good for potentially "freeze" methods calls. Executes passed method in separate thread. Waits for control returns within timeout. If timeout exceed - return control to callee thread. Separate execution thread will still be active. @param method_to_call: method te be called @type method_to_call: function @param timeout_seconds: maximal time to wait for method call finished @type timeout_seconds: float """ stop_thread = threading.Barrier(2) thread_name = threading._newname("{}-%d".format(__name__)) call_thread = threading.Thread(target=method_to_call, name=thread_name) call_thread.daemon = True call_thread.start() print ("threading.activeCount() : %s",threading.activeCount()) print ("threading.currentThread() : %s", threading.currentThread()) print ("threading.enumerate() : %s", threading.enumerate() ) call_thread.join(timeout=timeout_seconds) if call_thread.is_alive(): stop_thread.abort() return not call_thread.is_alive() def format_all_threads_stacks1(): """ @return: formatted stacks for all running threads. """ stacktraces = [] for thread_id, stack in list(dict(list(sys._current_frames().items())).items()): for thread1 in threading.enumerate(): if thread1.ident == thread_id: stacktraces.append('Thread %s (daemon=%r) stacktrace: \n%s' % (thread1.name, thread1.daemon, ''.join(traceback.format_stack(stack)))) else: thread = None return '\n'.join(stacktraces) class BaseCommandLine1(object): def __init__(self, connection_timeout=None): self._connection_timeout = connection_timeout self._connection_lock = multiprocessing.RLock() self._ssh_client = None self.logger = logging.getLogger('BaseCommandLine __init__ {}'.format(id(self))) self.reset_connection1() def __del__(self): self.close1() def _wait_for_connection1(self): begin_time = time.time() self.logger.debug("Will attempt to connect with device for %s seconds." % self._connection_timeout) while time.time() - begin_time < self._connection_timeout: try: self._connect_ssh1() self.logger.debug('BaseCommandLine1 new SSH connection with {}:{} established.'. format("10.221.42.29", "22")) break except Exception as e: self.logger.debug('BaseCommandLine1 SSH-connection failed after %d seconds passed with exception: %s' % (time.time() - begin_time, e)) self.logger.debug('BaseCommandLine1 Next attempt after {} seconds.'.format(5.0)) time.sleep(5.0) else: self.logger.debug('BaseCommandLine1 Failed to connect to {}:{} within {} seconds: {}'.format( "10.221.42.29","22",self._connection_timeout,traceback.format_exc())) def reset_connection1(self): with self._connection_lock: self.close1() self.logger.debug('reset connection begin.') self._wait_for_connection1() def close1(self): if not self._ssh_client: return close_timeout = 10.0 begin_time = time.time() self.logger.debug("Attempt to close ssh-session within %s seconds." % close_timeout) if lock_acquire_with_timeout1(self._connection_lock, close_timeout): try: if call_with_timeout1(self.__nonblocking_close1, timeout_seconds=close_timeout): self.logger.debug("Successfully closed SSHClient within %d seconds." % (time.time() - begin_time)) else: self.logger.warning("Failed to close SSHClient within %d seconds." % close_timeout) self.logger.warning("All threads state:\n%s" % format_all_threads_stacks1()) finally: self._connection_lock.release() else: self.logger.warning("Failed to acquire lock within %s timeout." % close_timeout) self._ssh_client = None def __nonblocking_close1(self): """ Non-blocking call to close SSH connection. May freeze on internal SSHClient.close(). """ self.logger.debug("Closing internal ssh-client.") if self._ssh_client: self._ssh_client.close1() self.logger.debug("Internal ssh-client closed.") self._ssh_client = None def _connect_ssh1(self, key_filename=None): try: s = pyssh.new_session(hostname="10.221.42.29", port="22", username="root", password="") r = s.execute("uname -a") self.logger.debug("pyssh data : %s" % r.as_bytes()) except Exception as e: self.logger.debug("Connection Error : %s" % str(e)) self._ssh_client = s return s def config_logging(): formatter = logging.Formatter("%(asctime)s[%(name)s]" "[%(levelname)s]: %(message)s") console_logger = logging.StreamHandler(sys.stdout) console_logger.setFormatter(formatter) root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG) root_logger.addHandler(logging.NullHandler()) paramiko_logger = logging.getLogger('paramiko') paramiko_logger.setLevel(logging.CRITICAL) paramiko_logger.addHandler(console_logger) console_logger.setLevel(logging.DEBUG) root_logger.addHandler(console_logger) def main(argv): config_logging() try: result = BaseCommandLine1(300) except Exception: logging.debug("Exception from BaseCommandLine1") logging.debug("Show all threads status before exit attempt:\n %s", format_all_threads_stacks1()) if __name__ == "__main__": main(sys.argv) From lists at mostrom.pp.se Fri Jun 11 08:38:37 2021 From: lists at mostrom.pp.se (Jan Erik =?utf-8?q?Mostr=C3=B6m?=) Date: Fri, 11 Jun 2021 14:38:37 +0200 Subject: Recommendation for drawing graphs and creating tables, saving as PDF Message-ID: <1B193C69-48F0-4655-B06D-02693C4EF6C9@mostrom.pp.se> I'm doing something that I've never done before and need some advise for suitable libraries. I want to a) create diagrams similar to this one https://www.dropbox.com/s/kyh7rxbcogvecs1/graph.png?dl=0 (but with more nodes) and save them as PDFs or some format that can easily be converted to PDFs b) generate documents that contains text, lists, and tables with some styling. Here my idea was to save the info as markdown and create PDFs from those files, but if there is some other tools that gives me better control over the tables I'm interested in knowing about them. I looked around around but could only find two types of libraries for a) libraries for creating histograms, bar charts, etc, b) very basic drawing tools that requires me to figure out the layout etc. I would prefer a library that would allow me to state "connect A to B", "connect C to B", "connect B to D", and the library would do the whole layout. The closest I've found it to use markdown and mermaid or graphviz but ... PDFs (perhaps I should just forget about PDFs, then it should be enough to send people to a web page) (and yes, I could obviously use LaTeX ...) = jem From rshepard at appl-ecosys.com Fri Jun 11 08:49:12 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 11 Jun 2021 05:49:12 -0700 (PDT) Subject: Recommendation for drawing graphs and creating tables, saving as PDF In-Reply-To: <1B193C69-48F0-4655-B06D-02693C4EF6C9@mostrom.pp.se> References: <1B193C69-48F0-4655-B06D-02693C4EF6C9@mostrom.pp.se> Message-ID: On Fri, 11 Jun 2021, Jan Erik Mostr?m wrote: > I looked around around but could only find two types of libraries for a) > libraries for creating histograms, bar charts, etc, b) very basic drawing > tools that requires me to figure out the layout etc. I would prefer a > library that would allow me to state "connect A to B", "connect C to B", > "connect B to D", and the library would do the whole layout. JEM, PSTricks > (and yes, I could obviously use LaTeX ...) They work well together. Rich From ndbecker2 at gmail.com Fri Jun 11 08:52:20 2021 From: ndbecker2 at gmail.com (Neal Becker) Date: Fri, 11 Jun 2021 08:52:20 -0400 Subject: Recommendation for drawing graphs and creating tables, saving as PDF References: <1B193C69-48F0-4655-B06D-02693C4EF6C9@mostrom.pp.se> Message-ID: Jan Erik Mostr?m wrote: > I'm doing something that I've never done before and need some advise for > suitable libraries. > > I want to > > a) create diagrams similar to this one > https://www.dropbox.com/s/kyh7rxbcogvecs1/graph.png?dl=0 (but with more > nodes) and save them as PDFs or some format that can easily be converted > to PDFs > > b) generate documents that contains text, lists, and tables with some > styling. Here my idea was to save the info as markdown and create PDFs > from those files, but if there is some other tools that gives me better > control over the tables I'm interested in knowing about them. > > I looked around around but could only find two types of libraries for a) > libraries for creating histograms, bar charts, etc, b) very basic > drawing tools that requires me to figure out the layout etc. I would > prefer a library that would allow me to state "connect A to B", "connect > C to B", "connect B to D", and the library would do the whole layout. > > The closest I've found it to use markdown and mermaid or graphviz but > ... PDFs (perhaps I should just forget about PDFs, then it should be > enough to send people to a web page) > > (and yes, I could obviously use LaTeX ...) > > = jem Like this? https://pypi.org/project/blockdiag/ From bpruitt at opentext.com Fri Jun 11 09:24:45 2021 From: bpruitt at opentext.com (Steve Pruitt) Date: Fri, 11 Jun 2021 13:24:45 +0000 Subject: jython getting started question Message-ID: Not sure if this is the right list for jython questions. I am getting started with both python and jython. My use case need is invoking python from java. org.python:jython:2.7.2 loaded ok. To check, I executed the following. ScriptEngineManager manager = new ScriptEngineManager(); List engines = manager.getEngineFactories(); Engine name: Oracle Nashorn Version: 1.8.0_242 Language: ECMAScript Short Names: nashorn Nashorn js JS JavaScript javascript ECMAScript ecmascript Engine name: jython Version: 2.7.2 Language: python Short Names: python jython The output looks like I have two engines: Oracle Nashorn and jython (the one I need). But when, I try: ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("jython"); engine is null. I tried the python short name and got a null engine too. Thanks. From bpruitt at opentext.com Fri Jun 11 12:34:32 2021 From: bpruitt at opentext.com (Steve Pruitt) Date: Fri, 11 Jun 2021 16:34:32 +0000 Subject: jython getting started question In-Reply-To: References: Message-ID: Finally found the solution Options.importSite = false; which solved my issue. I can't set Bindings and pass args to script. The only example I found is for JavaScript. I think maybe it doesn't work for jython. Thanks ________________________________ From: Python-list on behalf of Steve Pruitt via Python-list Sent: Friday, June 11, 2021 9:24 AM To: python-list at python.org Subject: [EXTERNAL] - jython getting started question CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe. If you feel that the email is suspicious, please report it using PhishAlarm. Not sure if this is the right list for jython questions. I am getting started with both python and jython. My use case need is invoking python from java. org.python:jython:2.7.2 loaded ok. To check, I executed the following. ScriptEngineManager manager = new ScriptEngineManager(); List engines = manager.getEngineFactories(); Engine name: Oracle Nashorn Version: 1.8.0_242 Language: ECMAScript Short Names: nashorn Nashorn js JS JavaScript javascript ECMAScript ecmascript Engine name: jython Version: 2.7.2 Language: python Short Names: python jython The output looks like I have two engines: Oracle Nashorn and jython (the one I need). But when, I try: ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("jython"); engine is null. I tried the python short name and got a null engine too. Thanks. -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Obbck6kTJA!OfpEEVqhd12SZnOn5z54YO293doFSUn7b0oSkx11CgsDEFXZNFbK1pjNDo4VS4F4$ From rshepard at appl-ecosys.com Fri Jun 11 17:20:13 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 11 Jun 2021 14:20:13 -0700 (PDT) Subject: Tkinter8.6: date picker Message-ID: I need a date picker for a couple of Python-3.7.2/Tkinter8.6 applications. There seem to be some available on the web. If you have experience with a date picker (not a calendar that holds appointments for a given date) I'd like your suggestions and recommendations for one. TIA, Rich From rshepard at appl-ecosys.com Fri Jun 11 18:34:46 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 11 Jun 2021 15:34:46 -0700 (PDT) Subject: Tkinter8.6: date picker In-Reply-To: References: Message-ID: On Fri, 11 Jun 2021, Dan Stromberg wrote: > I think most Python folks are doing their GUI's with a web browser, Qt, or > GTK+. I mostly use GTK+. But best wishes on getting a recommendation for a > Tkinter date picker. Dan, I don't like working in a web browser; Qt apparently has very weak support for multiple-table databases where joins involve several tables, and I've never used GTK+ for UI. One of the applications I'm developing will be for my clients to use. Most of them run some flavor of Windows so I want to keep the software requirements simple: Python3 and SQLite3. Regards, Rich From martinp.dipaola at gmail.com Fri Jun 11 22:32:28 2021 From: martinp.dipaola at gmail.com (Martin Di Paola) Date: Sat, 12 Jun 2021 02:32:28 +0000 Subject: Recommendation for drawing graphs and creating tables, saving as PDF In-Reply-To: References: <1B193C69-48F0-4655-B06D-02693C4EF6C9@mostrom.pp.se> Message-ID: <20210612023228.rzilhait3d3costt@gmail.com> You could try https://plantuml.com and http://ditaa.sourceforge.net/. Plantuml may not sound as the right tool but it is quite flexible and after a few tweak you can create a block diagram as you shown. And the good thing is that you *write* which elements and relations are in your diagram and it is Plantuml which will draw it for you. On the other hand, in Ditaa you have to do the layout but contrary to most of the GUI apps, Ditaa processes plaintext (ascii art if you want). For simple things, Ditaa is probably a good option too. Finally, I use https://pandoc.org/ to transform my markdowns into PDFs for a textbook that I'm writing (and in the short term for my blog). None of those are "libraries" in the sense that you can load in Python, however nothing should prevent you to call them from Python with `subprocess`. By the way, I'm interesting too in to know other tools for making diagrams. On Fri, Jun 11, 2021 at 08:52:20AM -0400, Neal Becker wrote: >Jan Erik Mostr?m wrote: > >> I'm doing something that I've never done before and need some advise for >> suitable libraries. >> >> I want to >> >> a) create diagrams similar to this one >> https://www.dropbox.com/s/kyh7rxbcogvecs1/graph.png?dl=0 (but with more >> nodes) and save them as PDFs or some format that can easily be converted >> to PDFs >> >> b) generate documents that contains text, lists, and tables with some >> styling. Here my idea was to save the info as markdown and create PDFs >> from those files, but if there is some other tools that gives me better >> control over the tables I'm interested in knowing about them. >> >> I looked around around but could only find two types of libraries for a) >> libraries for creating histograms, bar charts, etc, b) very basic >> drawing tools that requires me to figure out the layout etc. I would >> prefer a library that would allow me to state "connect A to B", "connect >> C to B", "connect B to D", and the library would do the whole layout. >> >> The closest I've found it to use markdown and mermaid or graphviz but >> ... PDFs (perhaps I should just forget about PDFs, then it should be >> enough to send people to a web page) >> >> (and yes, I could obviously use LaTeX ...) >> >> = jem > >Like this? >https://pypi.org/project/blockdiag/ > >-- >https://mail.python.org/mailman/listinfo/python-list From menyland at gmail.com Sat Jun 12 13:19:43 2021 From: menyland at gmail.com (Chris Nyland) Date: Sat, 12 Jun 2021 13:19:43 -0400 Subject: Recommendation for drawing graphs and creating tables, saving as PDF In-Reply-To: <20210612023228.rzilhait3d3costt@gmail.com> References: <1B193C69-48F0-4655-B06D-02693C4EF6C9@mostrom.pp.se> <20210612023228.rzilhait3d3costt@gmail.com> Message-ID: If you don't want to have to do any layout, Graphviz, which you mentioned, is probably the best and there are/were Python libraries that will let you control it to automatically produce files. The whole point of graphviz is to do all the layout, however my only grip is it doesn't always make the best choices and then it is a bit of a burden to get it to do what you want. That was also years ago though so maybe the functionality has expanded. I used it then to create huge hierarchical graphs. Additionally Graphviz is more like a framework and there are in reality many backends to choose from. I started to look into this to see if there were backends that made more sense for my charts but the project lost steam and I never got back to it. That would be my recommendation and then like Martin said use Markdown plus pandoc. I have been using this system for years at work and it works really well. I will write up specifications and requirements in mark down so I can version control them in Git then I use Markdown to convert to Word and PDF to distribute to coworkers. If they make changes I just convert the files back to mark down and then I can use KDiff and other merge tools to review the changes and commit them if I want. Graphviz will export PNGs which you can embed easily in markdown. Graphviz can also work by typing up a simple viz file which is just text and then that file is compiled into the visualization. That text file can of course be version controlled which if you can't tell I am big on so this is another bonus for me. Chris Chris On Fri, Jun 11, 2021 at 10:35 PM Martin Di Paola wrote: > You could try https://plantuml.com and http://ditaa.sourceforge.net/. > > Plantuml may not sound as the right tool but it is quite flexible and > after a few tweak you can create a block diagram as you shown. > > And the good thing is that you *write* which elements and relations are > in your diagram and it is Plantuml which will draw it for you. > > On the other hand, in Ditaa you have to do the layout but contrary to > most of the GUI apps, Ditaa processes plaintext (ascii art if you want). > > For simple things, Ditaa is probably a good option too. > > Finally, I use https://pandoc.org/ to transform my markdowns into PDFs > for a textbook that I'm writing (and in the short term for my blog). > > None of those are "libraries" in the sense that you can load in Python, > however nothing should prevent you to call them from Python with > `subprocess`. > > By the way, I'm interesting too in to know other tools for making > diagrams. > > On Fri, Jun 11, 2021 at 08:52:20AM -0400, Neal Becker wrote: > >Jan Erik Mostr?m wrote: > > > >> I'm doing something that I've never done before and need some advise for > >> suitable libraries. > >> > >> I want to > >> > >> a) create diagrams similar to this one > >> https://www.dropbox.com/s/kyh7rxbcogvecs1/graph.png?dl=0 (but with more > >> nodes) and save them as PDFs or some format that can easily be converted > >> to PDFs > >> > >> b) generate documents that contains text, lists, and tables with some > >> styling. Here my idea was to save the info as markdown and create PDFs > >> from those files, but if there is some other tools that gives me better > >> control over the tables I'm interested in knowing about them. > >> > >> I looked around around but could only find two types of libraries for a) > >> libraries for creating histograms, bar charts, etc, b) very basic > >> drawing tools that requires me to figure out the layout etc. I would > >> prefer a library that would allow me to state "connect A to B", "connect > >> C to B", "connect B to D", and the library would do the whole layout. > >> > >> The closest I've found it to use markdown and mermaid or graphviz but > >> ... PDFs (perhaps I should just forget about PDFs, then it should be > >> enough to send people to a web page) > >> > >> (and yes, I could obviously use LaTeX ...) > >> > >> = jem > > > >Like this? > >https://pypi.org/project/blockdiag/ > > > >-- > >https://mail.python.org/mailman/listinfo/python-list > -- > https://mail.python.org/mailman/listinfo/python-list > From PythonList at DancesWithMice.info Sat Jun 12 23:21:01 2021 From: PythonList at DancesWithMice.info (dn) Date: Sun, 13 Jun 2021 15:21:01 +1200 Subject: Terminology: EU language skills, and Master to Main (or ...) Message-ID: <94394a89-e123-eedb-ea7b-bf64bb5762dd@DancesWithMice.info> [to folk subscribed to both the Python list and Python-Tutor: apologies for cross-posting] Regarding levels of skill or complexity in learning, the European Union has been working on "The Common European Framework of Reference for Languages: Learning, Teaching, Assessment". It also standardises terminology for spoken/national-language training courses. https://en.wikipedia.org/wiki/Common_European_Framework_of_Reference_for_Languages I'm not a fan of such abstract labelling of one's progress (or a tutorial's content) with codes or "reference levels" (A1, A2, B1, B2, C1, C2) but maybe it will become widely recognised... The web-page amuses (this small mind) noting non-PC stereotypes, that the ever-pragmatic Dutch have scaled language skills based upon how one wants to apply or use them; the Scandinavians go for numerical progression; which the Italians do similarly but with 'flair' (using words not digits). LanguageCert International have added the EU-codes to their practical terms: Preliminary, Access, Achiever, Communicator, Expert, Mastery. A group at the King Juan-Carlos University (Madrid, Spain) is collecting practitioners' opinions in a bid to categorise Python mastery according to the Framework. You may like to contribute by responding to their research surveys (one form takes five-minutes, the other fifteen): https://docs.google.com/forms/d/e/1FAIpQLSdlzWGpvZHLHXl6iEdHbLTB6QvYXknrD9-JKmzY7riYJkPmNw/viewform I like to label tutorials and conference-talks (and sometimes individual slides/sections) to indicate levels of complexity. However, have replaced abstract terms such as "Beginner" or "Junior", "Intermediate", and "Advanced" or "Senior" which all sound school-ish; with the three terms: "Apprentice", "Journeyman", and "Master" (see also https://leanpub.com/b/python-craftsman). Whilst, there have been folk unfamiliar with (UK) "Guild" terms, they generally respond readily to explanation and the professional context. NB I use the terms solely to indicate an expected audience, as distinct from assessing an individual's capability (or pay-rate)! There is a potential-problem in the rising sensitivity of the word "Master", eg the git CVS has replaced the idea of a Master-branch with "Main branch" (or user-chosen alternative name). Will referring to skilled professionals as 'masters (of their profession/craft)' transgress (international or at least US-instigated) 'Political Correctness'? What do you think a professionally-recognisable series of skill-levels for programmers? -- Regards, =dn From pjfarley3 at earthlink.net Sun Jun 13 03:49:10 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Sun, 13 Jun 2021 03:49:10 -0400 Subject: Has anone seen or know of a CFFI wrapper for PDCurses? Message-ID: <000f01d76028$98ea4fd0$cabeef70$@earthlink.net> Hi All, I have been investigating the possibility of wrapping the PDCurses DLL on Windows (or even better the PDCursesMod fork) using cffi instead of ctypes.? The unicurses project tried this using ctypes 11 years ago but unicurses hasn't been worked on since 2010, and it shows its age. I think I have figured out a reasonably clean way to do it using the cffi ABI interface with a "cleaned up" copy of the provided "curses.h" header (using the API interface looks to me like it would be quite a bit more work for this library; not impossible, but a lot more work). Before I go down this path I wanted to ask here if anyone else has already been down that way, or knows of a project that wen that way, and if so what roadblocks and/or successes were seen? I also asked this question on the cffi mailing list, but that seems to be a low-traffic list. In any case, I haven't gotten any response there yet. TIA for any references or advice you can offer. Peter From drsalists at gmail.com Mon Jun 14 00:35:50 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 13 Jun 2021 21:35:50 -0700 Subject: Has anone seen or know of a CFFI wrapper for PDCurses? In-Reply-To: <000f01d76028$98ea4fd0$cabeef70$@earthlink.net> References: <000f01d76028$98ea4fd0$cabeef70$@earthlink.net> Message-ID: On Sun, Jun 13, 2021 at 12:50 AM wrote: > Hi All, > > I have been investigating the possibility of wrapping the PDCurses DLL on > Windows (or even better the PDCursesMod fork) using cffi instead of > ctypes. > The unicurses project tried this using ctypes 11 years ago but unicurses > hasn't been worked on since 2010, and it shows its age. > An option for your consideration: Maybe port Python's included curses module to PDCursesMod? From rtm443x at googlemail.com Mon Jun 14 01:10:20 2021 From: rtm443x at googlemail.com (jan) Date: Mon, 14 Jun 2021 06:10:20 +0100 Subject: Terminology: EU language skills, and Master to Main (or ...) In-Reply-To: <94394a89-e123-eedb-ea7b-bf64bb5762dd@DancesWithMice.info> References: <94394a89-e123-eedb-ea7b-bf64bb5762dd@DancesWithMice.info> Message-ID: Hi, see below On 13/06/2021, dn via Python-list wrote: > [to folk subscribed to both the Python list and Python-Tutor: apologies > for cross-posting] > > > Regarding levels of skill or complexity in learning, the European Union > has been working on "The Common European Framework of Reference for > Languages: Learning, Teaching, Assessment". It also standardises > terminology for spoken/national-language training courses. > https://en.wikipedia.org/wiki/Common_European_Framework_of_Reference_for_Languages To re-state what you already said but I didn't pick up on, this is natural spoken languages. [snip] > > A group at the King Juan-Carlos University (Madrid, Spain) is collecting > practitioners' opinions in a bid to categorise Python mastery according > to the Framework. You may like to contribute by responding to their > research surveys (one form takes five-minutes, the other fifteen): > https://docs.google.com/forms/d/e/1FAIpQLSdlzWGpvZHLHXl6iEdHbLTB6QvYXknrD9-JKmzY7riYJkPmNw/viewform Also I'm not sure there's much to relate artificial (programming) languages with natural (spoken) ones. 'Mastery; of python programming is almost meaningless because if you are a decent programmer you will be able to pick up new paradigms *reasonably* straightforwardly, and paradignms thus internalised (functional/OO/procedural/logic/etc) will then transfer fairly easily across languages. Also it's about problem solving which is an independent skill altogether. Also it includes transferrable prior experiences and knowledge/exposure ("IThere's a library for that" / "regexps are a trap here" / "just use a parser generator, don't write it by hand" / "The largest element every time? Let me introduce you to the Heap data structure" / "if you stick a bloom filter in front of that you can cut out 90% of database accesses here") If you're a good scala programmer it will take only a few weeks to get up to speed with python - I've done it. Most of that time went on learning the libraries (of python, and scala) anyway. > > > I like to label tutorials and conference-talks (and sometimes individual > slides/sections) to indicate levels of complexity. However, have > replaced abstract terms such as "Beginner" or "Junior", "Intermediate", > and "Advanced" or "Senior" which all sound school-ish; with the three > terms: "Apprentice", "Journeyman", and "Master" (see also > https://leanpub.com/b/python-craftsman). Just words. > [snip] > > There is a potential-problem in the rising sensitivity of the word > "Master", eg the git CVS has replaced the idea of a Master-branch with > "Main branch" (or user-chosen alternative name). Will referring to > skilled professionals as 'masters (of their profession/craft)' > transgress (international or at least US-instigated) 'Political > Correctness'? I've never seen any of this at my workplaces. When I occasionally read about this on the web and follow up to the source posts of those doing this, my impression is there are a few, vocal people who are just there to disrupt rather than do anything constructive. That may be reporting bias though so my view may be of questionable reliability. Basically I've not seen much if any value in this PC stuff. > > > What do you think a professionally-recognisable series of skill-levels > for programmers? Fine. If you can do it in any meaningful sense. jan > > -- > Regards, > =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From pjfarley3 at earthlink.net Mon Jun 14 01:42:36 2021 From: pjfarley3 at earthlink.net (pjfarley3 at earthlink.net) Date: Mon, 14 Jun 2021 01:42:36 -0400 Subject: Has anone seen or know of a CFFI wrapper for PDCurses? In-Reply-To: References: <000f01d76028$98ea4fd0$cabeef70$@earthlink.net> Message-ID: <000001d760e0$15815fe0$40841fa0$@earthlink.net> > From: Dan Stromberg > Sent: Monday, June 14, 2021 12:36 AM > To: pjfarley3 at earthlink.net > Cc: Python List > Subject: Re: Has anone seen or know of a CFFI wrapper for PDCurses? > > > On Sun, Jun 13, 2021 at 12:50 AM wrote: > > Hi All, > > > > I have been investigating the possibility of wrapping the PDCurses DLL on > > Windows (or even better the PDCursesMod fork) using cffi instead of ctypes. > > The unicurses project tried this using ctypes 11 years ago but unicurses > > hasn't been worked on since 2010, and it shows its age. > > An option for your consideration: Maybe port Python's included curses module to PDCursesMod? An interesting idea, to be sure, and one I have looked at to some extent. One thing that I've never quite learned is whether the included curses and curses_panel modules statically link a copy of the ncurses library on *ix systems or whether they invoke the ncurses.so library dynamically. If it is designed to invoke the ncurses and panels subroutines from the shared library it could be a possible path. One obstacle I thought that I saw is that building cpython modules based on non-python library sources AssUMes that the build process can get the library source from the cpython repository, rather than from a non-python external source repository. I have built some scripts to get around that assumption, but they would have to be integrated into the cpython external library build process for any wide distribution. And there are some differences between the PDCurses and ncurses assumed internal structures and what is externalized and what is not that might make that harder than it first appears. Plus taking that path really does requires the porter to learn at least the generics of the cpython internal macros and functions in order to be able to debug the result, which is a little bit daunting. Not impossible, but many molehills look like mountains to the uninitiated. Anyway, I am just investigating options at present, so thanks for the suggestion. Peter From drsalists at gmail.com Mon Jun 14 10:09:19 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 14 Jun 2021 07:09:19 -0700 Subject: Has anone seen or know of a CFFI wrapper for PDCurses? In-Reply-To: <000001d760e0$15815fe0$40841fa0$@earthlink.net> References: <000f01d76028$98ea4fd0$cabeef70$@earthlink.net> <000001d760e0$15815fe0$40841fa0$@earthlink.net> Message-ID: On Sun, Jun 13, 2021 at 10:42 PM wrote: > > From: Dan Stromberg > > Sent: Monday, June 14, 2021 12:36 AM > > To: pjfarley3 at earthlink.net > > Cc: Python List > > Subject: Re: Has anone seen or know of a CFFI wrapper for PDCurses? > > > > > On Sun, Jun 13, 2021 at 12:50 AM > wrote: > > > Hi All, > > > > > > I have been investigating the possibility of wrapping the PDCurses DLL > on > > > Windows (or even better the PDCursesMod fork) using cffi instead of > ctypes. > > > The unicurses project tried this using ctypes 11 years ago but > unicurses > > > hasn't been worked on since 2010, and it shows its age. > > > > An option for your consideration: Maybe port Python's included curses > module to PDCursesMod? > > An interesting idea, to be sure, and one I have looked at to some extent. > One thing that I've never quite learned is whether the included curses and > curses_panel modules statically link a copy of the ncurses library on *ix > systems or whether they invoke the ncurses.so library dynamically. > Why would it matter? Anyway, if I start up a CPython 3.9, import curses, and lsof the interpreter, I can see: $ lsof -p 26258 | grep curses below cmd output started 2021 Mon Jun 14 07:04:25 AM PDT python3 26258 dstromberg mem REG 254,1 231360 25167676 /usr/lib/x86_64-linux-gnu/libncursesw.so.6.1 python3 26258 dstromberg mem REG 254,1 546400 1316749 /usr/local/cpython-3.9/lib/python3.9/lib-dynload/_ curses.cpython-39-x86_64-linux-gnu.so ...which would seem to say that curses is brought into the interpreter on demand, from a shared object (dll). HTH. From michael.stemper at gmail.com Sat Jun 12 10:37:12 2021 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Sat, 12 Jun 2021 09:37:12 -0500 Subject: Python In-Reply-To: References: Message-ID: On 12/06/2021 01.25, Adarsh Kumar wrote: > How to run python file in normal laptop > actually when i run python it is showing error pls tell me how to add python extension in xammp Are you trying to run a python program, as the first line suggests, or are you trying to run python itself, as the second line says? How are you trying to do this? What error do you get? This is important. Do not paraphrase the error message, copy and paste it directly. (Do not try to send a screenshot, as it will be stripped off of your message.) Also, in what environment are you doing this? Windows, MacOS, Linux, something else? Specific version. -- Michael F. Stemper You can lead a horse to water, but you can't make him talk like Mr. Ed by rubbing peanut butter on his gums. From alan.gauld at yahoo.co.uk Sat Jun 12 15:07:38 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sat, 12 Jun 2021 20:07:38 +0100 Subject: Tkinter8.6: date picker In-Reply-To: References: Message-ID: On 11/06/2021 22:20, Rich Shepard wrote: > I need a date picker +1 -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From grant.b.edwards at gmail.com Sun Jun 13 13:44:40 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 13 Jun 2021 17:44:40 -0000 (UTC) Subject: curses apps on MS Windows? Message-ID: There's been a surprising amount of discussion lately about using curses libraries on Windows OS. I'm surprised by this, because I don't think I've ever even seen a Windows curses application. Are there examples of popular curses applications for Windows? Does windows have a terminfo/termcap subsystem to deal with different terminal types? Or do the apps only work with the built-in terminal windows implemented by command.com/cmd.exe? Can windows curses apps be used via real serial terminals? Is that even "a thing" under Windows? Is there such a thing as a Windows ssh server with some sort of shell in which one can run console-mode applications? -- Grant From greg.ewing at canterbury.ac.nz Mon Jun 14 03:29:08 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 14 Jun 2021 19:29:08 +1200 Subject: Behaviour of pop() for dictionaries In-Reply-To: References: Message-ID: On 14/06/21 4:19 am, BlindAnagram wrote: > Am I missing the obvious way to obtain the value (or the key) from a > dictionary that is known to hold only one item? v = d.popitem()[1] > More importantly, is there a good reason why we don't have d.pop() for > dictionaries? My guess is because it's not generally useful to get an arbitrary value from a dict without its corresponding key. Hence the existence of popitem(). -- Greg From greg.ewing at canterbury.ac.nz Mon Jun 14 03:39:17 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 14 Jun 2021 19:39:17 +1200 Subject: optimization of rule-based model on discrete variables In-Reply-To: References: Message-ID: On 14/06/21 4:15 am, Elena wrote: > Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is this > rule-based function. > > I know an operator g that can calculate a real value from Y: e = g(Y) > g is too complex to be written analytically. > > I would like to find a set of rules f able to minimize e on X. There must be something missing from the problem description. From what you've said here, it seems like you could simply find a value k for Y that minimises g, regardless of X, and then f would consist of a single rule: y = k. Can you tell us in more concrete terms what X and g represent? -- Greg From greg.ewing at canterbury.ac.nz Mon Jun 14 03:56:14 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 14 Jun 2021 19:56:14 +1200 Subject: Terminology: EU language skills, and Master to Main (or ...) In-Reply-To: References: <94394a89-e123-eedb-ea7b-bf64bb5762dd@DancesWithMice.info> Message-ID: On 13/06/21 3:21 pm, dn wrote: > Will referring to > skilled professionals as 'masters (of their profession/craft)' > transgress (international or at least US-instigated) 'Political > Correctness'? And what about all the university degrees with the word "master" in their names? Worst of all, will episodes of Doctor Who featuring the Master be banned? -- Greg From alan.gauld at yahoo.co.uk Mon Jun 14 04:27:26 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Mon, 14 Jun 2021 09:27:26 +0100 Subject: Terminology: EU language skills, and Master to Main (or ...) In-Reply-To: <94394a89-e123-eedb-ea7b-bf64bb5762dd@DancesWithMice.info> References: <94394a89-e123-eedb-ea7b-bf64bb5762dd@DancesWithMice.info> Message-ID: On 13/06/2021 04:21, dn via Python-list wrote: > What do you think a professionally-recognisable series of skill-levels > for programmers? This has been done or attempted many times, with perhaps the most complete scheme being the British Computer Society's "Industry Standard Model" which breaks jobs/skills in the industry into many categories(30 or so?) and within each category there are up to 6 levels of achievement. (Some skills don't have the lowest levels(e.g. architect) while some only have lower levels. The theory being a level 6 practitioner in and skill is equally "good" as a level 6 in any other skill. One of the skills is programming, and significantly, it is language independent. I don't know if the ISM is still in use, it is many years since I worked with the BCS as the training officer for our office. But there used to be a comprehensive set of web pages describing the requirements for each level for each skill. A quick search for BCS ISM didn't throw up a link, sorry. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From maddenlogan5678 at gmail.com Fri Jun 11 18:37:11 2021 From: maddenlogan5678 at gmail.com (Madden) Date: Fri, 11 Jun 2021 18:37:11 -0400 Subject: Cant find sorcecode Message-ID: Hi so I've been trying to find my sorcecode files so I can 7zip them to get to the ovl_tool_gui so I can add mods but I haven't been able to find them could you help? Sent from [1]Mail for Windows 10 References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From jfong at ms4.hinet.net Fri Jun 11 22:02:25 2021 From: jfong at ms4.hinet.net (Jach Feng) Date: Fri, 11 Jun 2021 19:02:25 -0700 (PDT) Subject: Is there a way to get the following result in Python? Message-ID: <65089d21-5d26-4970-978d-ca2159cfcb01n@googlegroups.com> >>> def foo(): ... # do something ... >>> a = [] >>> for i in range(3): ... a.append(foo()) ... >>> a [] >>> --Jach From adarsh13881 at gmail.com Sat Jun 12 02:25:27 2021 From: adarsh13881 at gmail.com (Adarsh Kumar) Date: Fri, 11 Jun 2021 23:25:27 -0700 (PDT) Subject: Python Message-ID: How to run python file in normal laptop actually when i run python it is showing error pls tell me how to add python extension in xammp From rudrakshnanavaty at gmail.com Sat Jun 12 08:32:52 2021 From: rudrakshnanavaty at gmail.com (Rudraksh Nanavaty) Date: Sat, 12 Jun 2021 18:02:52 +0530 Subject: Fwd: Unable to uninstall Python 3.8.7 In-Reply-To: References: Message-ID: I previously uninstalled to python install directory which was: ?C:\Users\{username}\Python\Python 3.8.4? Then I went to programs and features in the control panel and clicked uninstall. Wizard said uninstall successful, but it didn?t remove python from the programs list. I left it as is. Ignored it, and installed python 3.9.2 But VSCode says I have no python installed. Please Help From veekm at foo.com Sat Jun 12 11:26:30 2021 From: veekm at foo.com (Veek M) Date: Sat, 12 Jun 2021 15:26:30 -0000 (UTC) Subject: Tree library that allows conditions on nodes and will return the node Message-ID: LibreOffice has a huge class tree and I need to familiarize myself with it - trouble is, it won't fit on A4 because it has a flat hierarchy with loads of leaf nodes. I wanted to shove all the leaf nodes > x into a subgraph and style that differently using Graphviz. I tried treelib but while i can build and print a tree, AND figure out the size for each level of the Tree, it won't give me the parent node for a particular size.. So I know that level 3 has 7 children too much but which is the jackass parentID responsible - no idea. Graphviz has nice plotting and subgraphs and such but same problem - I checked pydot which is a clone of Graphviz and I'm not sure what exactly it does different from Graphviz.. Anyway I don't want to spend another two days checking out Plotly or Pygraphviz.. can someone point me in the right direction? From jfong at ms4.hinet.net Sun Jun 13 05:31:18 2021 From: jfong at ms4.hinet.net (Jach Feng) Date: Sun, 13 Jun 2021 02:31:18 -0700 (PDT) Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? Message-ID: >>> n = [(1,2) for i in range(3)] >>> n [(1, 2), (1, 2), (1, 2)] >>> id(n[0]) == id(n[1]) == id(n[2]) True >>> m = [[1,2] for i in range(3)] >>> m [[1, 2], [1, 2], [1, 2]] >>> id(m[0]) == id(m[1]) == id(m[2]) False >>> --Jach From pleasedonotsendspam at yahoo.ru Sun Jun 13 12:15:54 2021 From: pleasedonotsendspam at yahoo.ru (Elena) Date: Sun, 13 Jun 2021 16:15:54 +0000 (UTC) Subject: optimization of rule-based model on discrete variables Message-ID: Hi, I have, say 10 variables (x1 ... x10) which can assume discrete finite values, for instance [0,1 or 2]. I need to build a set of rules, such as: 1) if x1==0 and x2==1 and x10==2 then y = 1 2) if x2==1 and x3==1 and x4==2 and x6==0 then y = 0 3) if x2==0 and x3==1 then y = 2 4) if x6==0 and x7==2 then y = 0 ... ... (actually it can be seen as a decision tree classifier). y can assume the same discrete value [0,1 or 2] I don't know a-priori anything about the number of rules and the combinations of the tested inputs. Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is this rule-based function. I know an operator g that can calculate a real value from Y: e = g(Y) g is too complex to be written analytically. I would like to find a set of rules f able to minimize e on X. I know the problem can become NP-hard, but I would be fine also with a suboptimal solution. What's the best way to approach the problem? In case, does something already exist in python? thank you From blindanagram at nowhere.org Sun Jun 13 12:19:02 2021 From: blindanagram at nowhere.org (BlindAnagram) Date: Sun, 13 Jun 2021 17:19:02 +0100 Subject: Behaviour of pop() for dictionaries Message-ID: The pop() method exists for five mainstream data items and shows a range of different behaviours for each of them. But, of the five, pop for dictionaries is the only one for which the first parameter is required and this makes d.pop() for dictionaries an error rather than doing something useful. I came across this in trying to use this sequence for a dictionary : if len(d.keys()) == 1: v = d.pop() I found it surprising that this failed given how the pops for the other types work. So I then tried: v = d.values()[0] and this doesn't work either since dict_keys items don't accept indexing. So I was driven to use: v = list(d.values())[0] which seems to me a lot less intuitive (and messier) than d.pop(). These: v = next(iter(d.values())) v, = d.values() also seem poor substitutes for giving d.pop() for dictionaries a useful and intuitive purpose. Am I missing the obvious way to obtain the value (or the key) from a dictionary that is known to hold only one item? More importantly, is there a good reason why we don't have d.pop() for dictionaries? Brian From blindanagram at nowhere.org Mon Jun 14 04:39:26 2021 From: blindanagram at nowhere.org (BlindAnagram) Date: Mon, 14 Jun 2021 09:39:26 +0100 Subject: Behaviour of pop() for dictionaries In-Reply-To: References: Message-ID: On 14/06/2021 08:29, Greg Ewing wrote: > On 14/06/21 4:19 am, BlindAnagram wrote: >> Am I missing the obvious way to obtain the value (or the key) from a >> dictionary that is known to hold only one item? > > v = d.popitem()[1] Thanks, Greg, I missed that. > >> More importantly, is there a good reason why we don't have d.pop() for >> dictionaries? > > My guess is because it's not generally useful to get an returns the value arbitrary > value from a dict without its corresponding key. Hence the existence > of popitem(). However, d.pop(key, [default]) returns the value (or the default) and consistency with other pops (a good thing in my view) would suggest that d.pop() could return a random value, which would serve my purpose when there is only one element. From pleasedonotsendspam at yahoo.ru Mon Jun 14 08:51:34 2021 From: pleasedonotsendspam at yahoo.ru (Elena) Date: Mon, 14 Jun 2021 12:51:34 +0000 (UTC) Subject: optimization of rule-based model on discrete variables References: Message-ID: Il Mon, 14 Jun 2021 19:39:17 +1200, Greg Ewing ha scritto: > On 14/06/21 4:15 am, Elena wrote: >> Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is >> this rule-based function. >> >> I know an operator g that can calculate a real value from Y: e = g(Y) >> g is too complex to be written analytically. >> >> I would like to find a set of rules f able to minimize e on X. > > There must be something missing from the problem description. > From what you've said here, it seems like you could simply find > a value k for Y that minimises g, regardless of X, and then f would > consist of a single rule: y = k. > > Can you tell us in more concrete terms what X and g represent? I see what you mean, so I try to explain it better: Y is a vector say [y1, y2, ... yn], with large (n>>10), where yi = f(Xi) with Xi = [x1i, x2i, ... x10i] 1<=i<=n. All yi and xji assume discrete values. I already have a dataset of X={Xi} and would like to find the rules f able to minimize a complicated-undifferenciable Real function g(f(X)). Hope this makes more sense. x1...x10 are 10 chemical components that can be absent (0), present (1), modified (2). yi represent a quality index of the mixtures and g is a global quality of the whole process. Thank you in advance ele From grimble at nomail.afraid.org Mon Jun 14 09:00:53 2021 From: grimble at nomail.afraid.org (Grimble) Date: Mon, 14 Jun 2021 14:00:53 +0100 Subject: Where did the message go? Message-ID: I have two machines running Mageia 8 and Python 2.8.9, They use the same Python script to maintain a list of changed packages from dnf update and dnf install. In addition the script sends a short email message to my main email address. The problem is: the message from machine B arrives, the message from machine H does not. The part of the script that sends the message is: with open('email.txt') as fmail: msg = EmailMessage() msg.set_content(fmail.read()) msg['Subject'] = 'System update' msg['From'] = sysname msg['To'] = 'graeme at XXXX.XXXX' (details removed to protect the innocent) # Send the message via our own SMTP server. s = smtplib.SMTP('localhost') s.set_debuglevel(True) s.send_message(msg) s.quit() The last lines of s.set_debuglevel are reply: retcode (250); Msg: b'2.0.0 Ok: queued as B57B42C042F' data: (250, b'2.0.0 Ok: queued as B57B42C042F') send: 'quit\r\n' reply: b'221 2.0.0 Bye\r\n' reply: retcode (221); Msg: b'2.0.0 Bye' The SMTP part of the system is working (hence this message). The message from machine B correctly interprets "sysname" as sysname at sysname.XXXX.XXXX i.e a valid addr4ess. Where do I look now, please? -- Grimble Machine 'Haydn' running Plasma 5.20.4 on 5.10.41-desktop-1.mga8 kernel. Mageia release 8 (Official) for x86_64 From stestagg at gmail.com Mon Jun 14 15:13:57 2021 From: stestagg at gmail.com (Stestagg) Date: Mon, 14 Jun 2021 20:13:57 +0100 Subject: Behaviour of pop() for dictionaries In-Reply-To: References: Message-ID: You can do the following: _,v = d.popitem() Or: key, value = d.popitem() Steve On Mon, 14 Jun 2021 at 20:10, Greg Ewing wrote: > On 14/06/21 4:19 am, BlindAnagram wrote: > > Am I missing the obvious way to obtain the value (or the key) from a > > dictionary that is known to hold only one item? > > v = d.popitem()[1] > > > More importantly, is there a good reason why we don't have d.pop() for > > dictionaries? > > My guess is because it's not generally useful to get an arbitrary > value from a dict without its corresponding key. Hence the existence > of popitem(). > > -- > Greg > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Mon Jun 14 15:35:48 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Jun 2021 05:35:48 +1000 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: Message-ID: On Tue, Jun 15, 2021 at 5:12 AM Jach Feng wrote: > > >>> n = [(1,2) for i in range(3)] > >>> n > [(1, 2), (1, 2), (1, 2)] > >>> id(n[0]) == id(n[1]) == id(n[2]) > True This is three tuples. Tuples are immutable and you get three references to the same thing. > >>> m = [[1,2] for i in range(3)] > >>> m > [[1, 2], [1, 2], [1, 2]] > >>> id(m[0]) == id(m[1]) == id(m[2]) > False > >>> > These are lists. Each one is distinct. You could change one of them and the other two would remain as they are. ChrisA From rosuav at gmail.com Mon Jun 14 15:41:07 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Jun 2021 05:41:07 +1000 Subject: Is there a way to get the following result in Python? In-Reply-To: <65089d21-5d26-4970-978d-ca2159cfcb01n@googlegroups.com> References: <65089d21-5d26-4970-978d-ca2159cfcb01n@googlegroups.com> Message-ID: On Tue, Jun 15, 2021 at 5:23 AM Jach Feng wrote: > > >>> def foo(): > ... # do something > ... > >>> a = [] > >>> for i in range(3): > ... a.append(foo()) > ... > >>> a > [] > >>> > Barring shenanigans like messing with globals, no, there is no way for a function to return a lack of value. Fundamentally, EVERY expression in Python has to have a value, and that value must be a single object. The only exception - pun intended - is if the function doesn't return at all, eg if "# do something" is "raise Exception". But if that happens, you won't have the output you're looking for either, unless you wrap the append in a try/except. So, no. There is no "return emptiness" concept. You can be 100% confident that "a.append(foo())" will always append exactly one value, if the following line of code is indeed executed. ChrisA From rosuav at gmail.com Mon Jun 14 15:43:37 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Jun 2021 05:43:37 +1000 Subject: Behaviour of pop() for dictionaries In-Reply-To: References: Message-ID: On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram wrote: > However, d.pop(key, [default]) returns the value (or the default) and > consistency with other pops (a good thing in my view) would suggest that > d.pop() could return a random value, which would serve my purpose when > there is only one element. > Is this actually important or are you just looking for a meaningless "inconsistency"? Dictionaries are fundamentally different from lists. Is it really that hard to use popitem? ChrisA From barpasc at yahoo.com Mon Jun 14 15:17:30 2021 From: barpasc at yahoo.com (Pascal B) Date: Mon, 14 Jun 2021 19:17:30 +0000 (UTC) Subject: Php vs Python gui (tkinter...) for small remote database app References: <2065682577.10278618.1623698250789.ref@mail.yahoo.com> Message-ID: <2065682577.10278618.1623698250789@mail.yahoo.com> Hi, I would like to know if for a small app for instance that requires a connection to a remote server database if php is more suitable than Python mainly regarding security. Php requires one port for http and one port for the connection to the database open. If using Python with a tkinter gui, I understand a small app can connect to a database so only one port to the database would need to be accessed/open listening to connection. So I would need to worry less about security if using Python over Php for something small, like a small python app that I give over to users. Am I missing something in this assertion? From PythonList at DancesWithMice.info Mon Jun 14 15:58:51 2021 From: PythonList at DancesWithMice.info (dn) Date: Tue, 15 Jun 2021 07:58:51 +1200 Subject: Where did the message go? In-Reply-To: References: Message-ID: <0753f4a8-1f36-5616-6891-b27296292ee1@DancesWithMice.info> On 15/06/2021 01.00, Grimble wrote: > I have two machines running Mageia 8 and Python 2.8.9, They use the same > Python script to maintain a list of changed packages from dnf update and > dnf install. In addition the script sends a short email message to my > main email address. The problem is: the message from machine B arrives, > the message from machine H does not. > The part of the script that sends the message is: > ?? with open('email.txt') as fmail: > ??????? msg = EmailMessage() > ??????? msg.set_content(fmail.read()) > > ??? msg['Subject'] = 'System update' > ??? msg['From'] = sysname > ??? msg['To'] = 'graeme at XXXX.XXXX' (details removed to protect the > innocent) > > ??? # Send the message via our own SMTP server. > ??? s = smtplib.SMTP('localhost') > ??? s.set_debuglevel(True) > ??? s.send_message(msg) > ??? s.quit() > > The last lines of s.set_debuglevel are > reply: retcode (250); Msg: b'2.0.0 Ok: queued as B57B42C042F' > data: (250, b'2.0.0 Ok: queued as B57B42C042F') > send: 'quit\r\n' > reply: b'221 2.0.0 Bye\r\n' > reply: retcode (221); Msg: b'2.0.0 Bye' > > The SMTP part of the system is working (hence this message). > The message from machine B correctly interprets "sysname" as > sysname at sysname.XXXX.XXXX i.e a valid addr4ess. > > Where do I look now, please? That's machine B, but the issue is with machine H. Have you compared the contents of the two machines' /var/log/maillog? -- Regards, =dn From PythonList at DancesWithMice.info Mon Jun 14 16:39:51 2021 From: PythonList at DancesWithMice.info (dn) Date: Tue, 15 Jun 2021 08:39:51 +1200 Subject: Php vs Python gui (tkinter...) for small remote database app In-Reply-To: <2065682577.10278618.1623698250789@mail.yahoo.com> References: <2065682577.10278618.1623698250789.ref@mail.yahoo.com> <2065682577.10278618.1623698250789@mail.yahoo.com> Message-ID: <1e79e70f-2e35-200f-ffb4-a40b8c4ade65@DancesWithMice.info> On 15/06/2021 07.17, Pascal B via Python-list wrote: > Hi, > I would like to know if for a small app for instance that requires a connection to a remote server database if php is more suitable than Python mainly regarding security. > Php requires one port for http and one port for the connection to the database open. If using Python with a tkinter gui, I understand a small app can connect to a database so only one port to the database would need to be accessed/open listening to connection. So I would need to worry less about security if using Python over Php for something small, like a small python app that I give over to users. > > Am I missing something in this assertion? Yes - or maybe I'm missing the point of your question? There are two connections to consider: the database and the GUI. Database: In each case, the programming-language must make a connection to the Database Management System. The API, the manner for doing-so may vary slightly between DBMS-es, but will not particularly between languages. Thus, if we talk about MySQL/MariaDB, the data which must be exchanged between language and DBMS is identical (even if the code, and appearance of the 'variables' differs). As far as security goes, the different DBMS-publishers have decided, in their wisdom, to select different IP-ports for communication with their products (see https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers). Please refer to (their, cf Python's) specific documentation to ascertain security and encryption options. GUI: There's a bit of 'chalk and cheese' in this question. PHP is built around HTML. HTML requires an HTTP server (ignoring the interpreter built-in to a web-browser). Thus, PHP or Python (likely Python plus Flask or some other framework) will need to connect to httpd/Apache/NGINX/etc, in similar fashion to the above. In this case, the choice of IP-port is more standard - 80 for http and 443 for https. Whereas tkinter is a module which can be import-ed into a Python program(me). There is no separate server. Thus no need for an IP-connection between application and front-end. The (Internet-connected) world runs on TLS. If you wish to secure/encrypt communications between application and server, this is accepted by most. If you wish to 'secure' by reducing inter-connections, then using tkinter and its tight-linkage to Python removes the need for the (http) web-server. -- Regards, =dn From rob.cliffe at btinternet.com Mon Jun 14 17:04:37 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 14 Jun 2021 22:04:37 +0100 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: Message-ID: This puzzled me, so I played around with it a bit (Python 3.8.3): n = [] for i in range(3): ??? n.append((1,7,-3,None,"x")) for i in range(3): ??? n.append((1,7,-3,None,"x")) print([id(x) for x in n]) a = 4 n = [] for i in range(3): ??? n.append((1,7,-3,a,None,"x")) for i in range(3): ??? n.append((1,7,-3,a,None,"x")) print([id(x) for x in n]) Output: [27164832, 27164832, 27164832, 27164832, 27164832, 27164832] [30065208, 30065496, 30237192, 30239976, 30240024, 30343928] Evidently the compiler is clever enough to pick out a constant tuple and create (or cause to get created) a single instance of it which is used when required.? Indeed disassembling the code shows that LOAD_CONST is used to get the tuple.? But it obviously can't do that when the tuple contains a variable. Rob Cliffe On 14/06/2021 20:35, Chris Angelico wrote: > On Tue, Jun 15, 2021 at 5:12 AM Jach Feng wrote: >>>>> n = [(1,2) for i in range(3)] >>>>> n >> [(1, 2), (1, 2), (1, 2)] >>>>> id(n[0]) == id(n[1]) == id(n[2]) >> True > This is three tuples. Tuples are immutable and you get three > references to the same thing. > >>>>> m = [[1,2] for i in range(3)] >>>>> m >> [[1, 2], [1, 2], [1, 2]] >>>>> id(m[0]) == id(m[1]) == id(m[2]) >> False > These are lists. Each one is distinct. You could change one of them > and the other two would remain as they are. > > ChrisA From rosuav at gmail.com Mon Jun 14 17:22:41 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Jun 2021 07:22:41 +1000 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: Message-ID: On Tue, Jun 15, 2021 at 7:11 AM Rob Cliffe via Python-list wrote: > > This puzzled me, so I played around with it a bit (Python 3.8.3): > > n = [] > for i in range(3): > n.append((1,7,-3,None,"x")) > for i in range(3): > n.append((1,7,-3,None,"x")) > print([id(x) for x in n]) > > a = 4 > n = [] > for i in range(3): > n.append((1,7,-3,a,None,"x")) > for i in range(3): > n.append((1,7,-3,a,None,"x")) > print([id(x) for x in n]) > > Output: > > [27164832, 27164832, 27164832, 27164832, 27164832, 27164832] > [30065208, 30065496, 30237192, 30239976, 30240024, 30343928] > > Evidently the compiler is clever enough to pick out a constant tuple and > create (or cause to get created) a single instance of it which is used > when required. Indeed disassembling the code shows that LOAD_CONST is > used to get the tuple. But it obviously can't do that when the tuple > contains a variable. Correct. In theory, Python could intern the tuples (as can be done with strings), noticing that it's constructing one that is identical to one it already has, but the effort of doing that is hard to justify. Simpler to just build a brand new tuple every time. ChrisA From blindanagram at nowhere.org Mon Jun 14 17:18:17 2021 From: blindanagram at nowhere.org (BlindAnagram) Date: Mon, 14 Jun 2021 22:18:17 +0100 Subject: Behaviour of pop() for dictionaries In-Reply-To: References: Message-ID: <0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk> On 14/06/2021 20:43, Chris Angelico wrote: > On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram wrote: >> However, d.pop(key, [default]) returns the value (or the default) and >> consistency with other pops (a good thing in my view) would suggest that >> d.pop() could return a random value, which would serve my purpose when >> there is only one element. >> > > Is this actually important or are you just looking for a meaningless > "inconsistency"? Dictionaries are fundamentally different from lists. > Is it really that hard to use popitem? No I am not looking for meaningless inconsistency - just the opposite in fact - meaningful consistency. I believe that consistency in how methods common to different types work is useful since it adds to the coherence of the language as a whole and avoids the need to remember special cases. No it isn't hard to use popitem() but it evidently proved hard for me to remember that it was there. Brian From PythonList at DancesWithMice.info Mon Jun 14 19:11:31 2021 From: PythonList at DancesWithMice.info (dn) Date: Tue, 15 Jun 2021 11:11:31 +1200 Subject: Behaviour of pop() for dictionaries In-Reply-To: <0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk> References: <0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk> Message-ID: <0184de41-3482-c576-60ed-343fbe0fe73d@DancesWithMice.info> On 15/06/2021 09.18, BlindAnagram wrote: > On 14/06/2021 20:43, Chris Angelico wrote: >> On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram ... > No it isn't hard to use popitem() but it evidently proved hard for me to > remember that it was there. If that's a problem, you're going to love using deques with their 'popping from the left' and 'popping from the right' concepts! I don't know if you are ComSc student or not, but there isn't even consistency at the theoretical level. I first arrived at the concept of "queuing" and "dequeuing" (NB the latter is not the same as the Python Collections module "deque" library) whilst studying Queue Theory in Operations Research. At about the same time, my ComSc studies took me into "stacks". Queues are known as FIFO constructs - "first-in, first-out". Stacks are somewhat the opposite: LIFO - "last-in, first-out". The "pop" operation was defined as taking the "next" item from the queue or the "last" item from a stack (the opposite of "push"). However, between queue and stack, the term "next" refers to opposite ends of the (implementing in Python) list! In fact, coming from a Burroughs mainframe, which ran on "stack architecture" (cf IBM's multiplicity of "ALU registers"), it came as something of a surprise when programming languages started allowing me to "pop" elements that weren't at the LIFO-end of the 'list', eg list.pop( 3 ) where len( list ) > 4! Next consider how the terms "next" and "element" factor into the thinking. If we consider a (Python) list there is an implied sequence of elements based upon their relative position. Notice also that the basic implementation of list.pop() is LIFO! Whereas, the definition of a set involves no concept of sequence or order - only of membership (and that the elements are "hashable"). Accordingly, a pop() operation returns an "arbitrary value", cf 'next please'. Similarly, a dict's keys are referred-to as hashable, with the idea of "random access" to an element via its key (cf the "sequential access" of a list). Thus, we can ask to pop() a dict, but only if we provide a key - in which case, pop( key ) is the same as dict[ key ] except that the key-value pair is also removed from the dict! Recall though, it is possible to use list.pop() without any argument. So, consistency has been thrown-out-the-window there as well. Also, with LIFO in-mind, Python v3.7 brought a concept of 'sequence' (population order) to dicts, and thus we now have this "guarantee" in popitem() - and thus a memory-confusion for those of us who learned the original "arbitrary" definition - confusion both of dict behavior and of dict.popitem() specifically! Worse confusion awaits (and referring to a conversation 'here' last week) Python's pop() exhibits elements of both an "expression" and of a "statement", ie it not only returns a value, but it affects (?"side-effects") the underlying collection. Thus, no pop() for strings, tuples, etc, because they are immutable collections! The action of pop() is clearly inconsistent across types of collection. It's effect is data-structure dependent because the purposes of those structures are inherently different. "Consistency" would aid memory, but "polymorphism" can only deliver functionality according to the characteristics of the specific data-type! Having entered the queue-of-life a long time ago, and shuffling ever closer to 'the end of the line', this memory-challenged 'silver-surfer' prefers to reserve pop() for straightforward stacks and lists, which implies quite enough inconsistency, without trying to convolute my mind to pop()-ing dicts, sets (or 'worse'!). That said, whether I actually use dict.pop() or not, these 'features' which are consistent in name but not necessarily in arguments or effects, contribute to Python's great flexibility and power! Thank goodness for help() and the Python docs... -- Regards, =dn From Richard at Damon-Family.org Mon Jun 14 20:19:44 2021 From: Richard at Damon-Family.org (Richard Damon) Date: Mon, 14 Jun 2021 20:19:44 -0400 Subject: optimization of rule-based model on discrete variables In-Reply-To: References: Message-ID: <78a84612-6ef0-e91b-9215-c7d530119c8a@Damon-Family.org> On 6/13/21 12:15 PM, Elena via Python-list wrote: > Hi, I have, say 10 variables (x1 ... x10) which can assume discrete finite > values, for instance [0,1 or 2]. > I need to build a set of rules, such as: > > 1) if x1==0 and x2==1 and x10==2 then y = 1 > 2) if x2==1 and x3==1 and x4==2 and x6==0 then y = 0 > 3) if x2==0 and x3==1 then y = 2 > 4) if x6==0 and x7==2 then y = 0 > ... > ... > (actually it can be seen as a decision tree classifier). > > y can assume the same discrete value [0,1 or 2] > I don't know a-priori anything about the number of rules and the > combinations of the tested inputs. > > Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is this > rule-based function. > > I know an operator g that can calculate a real value from Y: e = g(Y) > g is too complex to be written analytically. > > I would like to find a set of rules f able to minimize e on X. > > I know the problem can become NP-hard, but I would be fine also with a > suboptimal solution. > > What's the best way to approach the problem? > In case, does something already exist in python? > > > thank you My first feeling is that this doesn't have a lot of structure to do a lot of optimizations, and just brute forcing might be the answer. Of course, one option is just sort the rules by Y, then iterate through the rules and see if any data matches, for that putting the dataset into something like an SQLite database with indexes on the various X columns might work (with 10 columns, the 45 indexes on each column pair might make things reasonably efficient.) The biggest gain would happen if you could look at the rule set and find patterns in it. The big question is making sure that the rule set covers every value in the data array, and never gives one input value two different y values. -- Richard Damon From greg.ewing at canterbury.ac.nz Mon Jun 14 18:40:05 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 15 Jun 2021 10:40:05 +1200 Subject: optimization of rule-based model on discrete variables In-Reply-To: References: Message-ID: On 15/06/21 12:51 am, Elena wrote: > I see what you mean, so I try to explain it better: Y is a vector say [y1, > y2, ... yn], with large (n>>10), where yi = f(Xi) with Xi = [x1i, x2i, ... > x10i] 1<=i<=n. All yi and xji assume discrete values. > > I already have a dataset of X={Xi} and would like to find the rules f able > to minimize a complicated-undifferenciable Real function g(f(X)). > Hope this makes more sense. Hmmm, so the problem breaks down into two parts: (1) find a vector Y that minimises g (2) find a set of rules that will allow you to predict each component of Y from its corresponding X values Is that right? > x1...x10 are 10 chemical components that can be absent (0), present (1), > modified (2). yi represent a quality index of the mixtures and g is a > global quality of the whole process. I ztill don't really understand. What are you going to do with this function f once you have it? I would have thought the idea was that if someone gives you a new mixture X[n+1] you can use f to predict how well it will work. But that will just give you a y[n+1], and it's not clear what to do with that. Do you append it to Y and feed an n+1 component vector into g? I think I still need more information about the underlying problem before I can help you much. -- Greg From tjreedy at udel.edu Mon Jun 14 18:50:21 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 14 Jun 2021 18:50:21 -0400 Subject: curses apps on MS Windows? In-Reply-To: References: Message-ID: On 6/13/2021 1:44 PM, Grant Edwards wrote: > Does windows have a terminfo/termcap subsystem to deal with different > terminal types? No. AFAIK >Or do the apps only work with the built-in terminal > windows implemented by command.com/cmd.exe? The windows console is implemented by separate code. It is used Command Prompt, Powershell, Python, and other test-mode console applications. I can't answer other questions. I imagine that *nix-like operations, one best use WSL? (Windows Subsystem for Linux?) or a Windows Bash imitation (Git bash, for instance). I believe git bash uses the same console as its interface. -- Terry Jan Reedy From nospam at please.ty Mon Jun 14 19:56:37 2021 From: nospam at please.ty (jak) Date: Tue, 15 Jun 2021 01:56:37 +0200 Subject: curses apps on MS Windows? References: Message-ID: Il 13/06/2021 19:44, Grant Edwards ha scritto: > There's been a surprising amount of discussion lately about using > curses libraries on Windows OS. I'm surprised by this, because I don't > think I've ever even seen a Windows curses application. > > Are there examples of popular curses applications for Windows? > > Does windows have a terminfo/termcap subsystem to deal with different > terminal types? Or do the apps only work with the built-in terminal > windows implemented by command.com/cmd.exe? > > Can windows curses apps be used via real serial terminals? Is that > even "a thing" under Windows? > > Is there such a thing as a Windows ssh server with some sort of shell > in which one can run console-mode applications? > > -- > Grant > > > https://winaero.com/enable-openssh-server-windows-10/ From tjreedy at udel.edu Mon Jun 14 20:36:49 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 14 Jun 2021 20:36:49 -0400 Subject: Behaviour of pop() for dictionaries In-Reply-To: <0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk> References: <0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk> Message-ID: On 6/14/2021 5:18 PM, BlindAnagram wrote: > I believe that consistency in how methods common to different types work > is useful since it adds to the coherence of the language as a whole and > avoids the need to remember special cases. Each collection class *is* a special case, and pop has to be adjusted to each. However, you seem to have missed an essential commonality. Lists and dicts are both subscripted classes. So the basic API is col.pop(sub), which removes and returns the sub item, whereas col[sub] leaves and returns. Lists have a special index, -1, the most commonly used, so that is the default. In fact, when I proposed list.pop(), I only proposed that, as I wanted pop to be the inverse of append, so a list could be used as a stack. Bad list subscripts are an error (unless one is slicing), whereas where dicts allow a default (when subscripted with the get method). Hence the optional default only for dicts. At one time, dicts, like sets, were unordered collections (of functional item pairs). dict.pop(), with no arg, could have been used to return a random 2-ple, but Guido is generally against having return types depend on arguments. So a new popxxx name was added. Note that deques have a popleft in addition to pop (right). -- Terry Jan Reedy From torriem at gmail.com Mon Jun 14 21:39:28 2021 From: torriem at gmail.com (Michael Torrie) Date: Mon, 14 Jun 2021 19:39:28 -0600 Subject: curses apps on MS Windows? In-Reply-To: References: Message-ID: <2269a82b-757a-3681-982a-05f4a24d2141@gmail.com> On 6/13/21 11:44 AM, Grant Edwards wrote: > There's been a surprising amount of discussion lately about using > curses libraries on Windows OS. I'm surprised by this, because I don't > think I've ever even seen a Windows curses application. > > Are there examples of popular curses applications for Windows? None that I know of, but then again the Windows console was horrible. With the advent of the new Windows Terminal, Windows 10 now has a first-class terminal system with all the capabilities of any Unix terminal. So who knows, maybe curses might actually find a use on Windows! MS seems to be giving the idea of terminal applications a bit of love. From martinp.dipaola at gmail.com Mon Jun 14 21:53:09 2021 From: martinp.dipaola at gmail.com (Martin Di Paola) Date: Tue, 15 Jun 2021 01:53:09 +0000 Subject: optimization of rule-based model on discrete variables In-Reply-To: References: Message-ID: <20210615015309.dt2clmvcm2hketrm@gmail.com> From what I'm understanding it is an "optimization problem" like the ones that you find in "linear programming". But in your case the variables are not Real (they are Integers) and the function to minimize g() is not linear. You could try/explore CVXPY (https://www.cvxpy.org/) which it's a solver for different kinds of "convex programming". I don't have experience with it however. The other weapon in my arsenal would be Z3 (https://theory.stanford.edu/~nikolaj/programmingz3.html) which it's a SMT/SAT solver with a built-in extension for optimization problems. I've more experience with this so here is a "draft" of what you may be looking for. from z3 import Integers, Optimize, And, If # create a Python array X with 3 Z3 Integer variables named x0, x1, x2 X = Integers('x0 x1 x2') Y = Integers('y0 y1') # create the solver solver = Optimize() # add some restrictions like lower and upper bounds for x in X: solver.add(And(0 <= x, x <= 2)) # each x is between 0 and 2 for y in Y: solver.add(And(0 <= y, y <= 2)) def f(X): # Conditional expression can be modeled too with "If" # These are *not* evaluated like a normal Python "if" but # modeled as a whole. It'll be the solver which will "run it" return If( And(x[0] == 0, x[1] == 0), # the condition Y[0] == 0, # Y[0] will *must* be 0 *if* the condition holds Y[0] == 2 # Y[0] will *must* be 2 *if* the condition doesn't hold ) solver.add(f(X)) # let's define the function to optimize g = Y[0]**2 solver.maximize(g) # check if we have a solution solver.check() # this should return 'sat' # get one of the many optimum solutions solver.model() I would recommend you to write a very tiny problem with 2 or 3 variables and a very simple f() and g() functions, make it work (manually and with Z3) and only then build a more complex program. You may find useful (or not) these two posts that I wrote a month ago about Z3. These are not tutorials, just personal experience with a concrete example. Combine Real, Integer and Bool variables: https://book-of-gehn.github.io/articles/2021/05/02/Planning-Space-Missions.html Lookup Tables (this may be useful for programming a f() "variable" function where the code of f() (the decision tree) is set by Z3 and not by you such f() leads to the optimum of g()) https://book-of-gehn.github.io/articles/2021/05/26/Casting-Broadcasting-LUT-and-Bitwise-Ops.html Happy hacking. Martin. On Mon, Jun 14, 2021 at 12:51:34PM +0000, Elena via Python-list wrote: >Il Mon, 14 Jun 2021 19:39:17 +1200, Greg Ewing ha scritto: > >> On 14/06/21 4:15 am, Elena wrote: >>> Given a dataset of X={(x1... x10)} I can calculate Y=f(X) where f is >>> this rule-based function. >>> >>> I know an operator g that can calculate a real value from Y: e = g(Y) >>> g is too complex to be written analytically. >>> >>> I would like to find a set of rules f able to minimize e on X. >> >> There must be something missing from the problem description. >> From what you've said here, it seems like you could simply find >> a value k for Y that minimises g, regardless of X, and then f would >> consist of a single rule: y = k. >> >> Can you tell us in more concrete terms what X and g represent? > >I see what you mean, so I try to explain it better: Y is a vector say [y1, >y2, ... yn], with large (n>>10), where yi = f(Xi) with Xi = [x1i, x2i, ... >x10i] 1<=i<=n. All yi and xji assume discrete values. > >I already have a dataset of X={Xi} and would like to find the rules f able >to minimize a complicated-undifferenciable Real function g(f(X)). >Hope this makes more sense. > >x1...x10 are 10 chemical components that can be absent (0), present (1), >modified (2). yi represent a quality index of the mixtures and g is a >global quality of the whole process. > >Thank you in advance > >ele >-- >https://mail.python.org/mailman/listinfo/python-list From eryksun at gmail.com Mon Jun 14 23:33:45 2021 From: eryksun at gmail.com (Eryk Sun) Date: Mon, 14 Jun 2021 22:33:45 -0500 Subject: curses apps on MS Windows? In-Reply-To: References: Message-ID: On 6/13/21, Grant Edwards wrote: > > Are there examples of popular curses applications for Windows? I don't think are any popular examples. The port of the "nano" editor uses ncurses. https://github.com/lhmouse/nano-win IIRC, PDCurses has better support -- e.g. 256 colors and blinking under Windows 10 or ConEmu. The Windows ports of Python's curses module that I know of are based on PDCurses. > Does windows have a terminfo/termcap subsystem to deal with different > terminal types? No, but in Windows 10 the virtual-terminal mode of the console emulates xterm256-color: https://github.com/microsoft/terminal/issues/2958 https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences The console host (i.e. conhost.exe, or the open-source build OpenConsole.exe) supports a headless mode (ConPTY / pseudconsole), which is what Windows Terminal and the sshd server use. Terminal support is handled by the host, which defaults to enabling virtual-terminal mode in a headless session. The console host process sits in the middle between client applications and the terminal application or service that created the console session. For example, each tab in Windows Terminal is a headless console session that's hosted by a separate instance of OpenConsole.exe. Applications are unaware that it's a headless session. They request the normal read/write/IOCTL operations on console files, which are provided by the console driver, i.e. condrv.sys in the kernel. The driver in turn talks to the attached console host. If it's a ConPTY session, the host talks to the service or terminal application that created the console session, e.g. WindowsTerminal.exe. Classically, or without ConPTY, the console host provides a builtin terminal/console interface, which is what most people are used to in Windows and what many people confuse with cmd.exe. Alternate terminals such as ConEmu have existed for a long time, but prior to ConPTY support their implementation was a pile of hacks. The terminal had to attach to the console host to read the console's input and screen buffers and poll the screen for changes, and even inject a DLL in client applications to hook various API calls. > Is there such a thing as a Windows ssh server with some sort of shell > in which one can run console-mode applications? I've used third-party SSH servers in the past, but Windows 10 includes an ssh server and client. The sshd.exe server launches a headless console session, which by default runs an instance of the cmd.exe shell. Installation: https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse > Or do the apps only work with the built-in terminal > windows implemented by command.com/cmd.exe? cmd.exe is a shell that uses standard I/O. It's not a terminal or console. It's fundamentally no different from the REPL shell that's implemented by python.exe, except the cmd.exe shell and batch scripting language make it relatively easier to administrate the machine and run programs. COMMAND.COM is a 16-bit DOS shell from the 1980s and 1990s. Most people may as well forget about COMMAND.COM, unless they're fascinated with relics from the 80s. From drsalists at gmail.com Tue Jun 15 00:06:22 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 14 Jun 2021 21:06:22 -0700 Subject: Cant find sorcecode In-Reply-To: References: Message-ID: I don't know where your source code is specifically, but here's an example of looking up where a file lives: $ python3 below cmd output started 2021 Mon Jun 14 09:05:54 PM PDT Python 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import heapq >>> heapq.__file__ '/usr/lib/python3.7/heapq.py' >>> On Mon, Jun 14, 2021 at 12:04 PM Madden wrote: > > > Hi so I've been trying to find my sorcecode files so I can 7zip them to > get to the ovl_tool_gui so I can add mods but I haven't been able to > find > them could you help? > > > > > > Sent from [1]Mail for Windows 10 > > > > References > > Visible links > 1. https://go.microsoft.com/fwlink/?LinkId=550986 > -- > https://mail.python.org/mailman/listinfo/python-list > From cs at cskk.id.au Tue Jun 15 01:03:16 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 15 Jun 2021 15:03:16 +1000 Subject: Is there a way to get the following result in Python? In-Reply-To: <65089d21-5d26-4970-978d-ca2159cfcb01n@googlegroups.com> References: <65089d21-5d26-4970-978d-ca2159cfcb01n@googlegroups.com> Message-ID: On 11Jun2021 19:02, Jach Fong wrote: >>>> def foo(): >... # do something >... >>>> a = [] >>>> for i in range(3): >... a.append(foo()) >... >>>> a >[] >>>> Chris has explained that what you've written will never do it. But if instead you wanted to filter out None results, getting an empty list from the filter, then the filter() builtin function will do you. First, as Chris alluded to, all functions return values. Those with a "bare" return (no expression) or which just fall off the end of the function body actaully return None. There's the obvious: a = [] for i in range(3): item = foo() if item is not None: a.append(item) Using a filter... "help(filter)" says: >>> help(filter) Help on class filter in module builtins: class filter(object) | filter(function or None, iterable) --> filter object | | Return an iterator yielding those items of iterable for which function(item) | is true. If function is None, return the items that are true. | | Methods defined here: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __iter__(self, /) | Implement iter(self). | | __next__(self, /) | Implement next(self). | | __reduce__(...) | Return state information for pickling. | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. which is more that I expected. Usage: a = list(filter(lambda item: item is not None, items)) where items is the various returns from foo(). Or you could just write a list comprehension directly: a = [ item for item in items if items is not None ] You want items to be your calls to foo(). Eg: a = [ item for item in (foo() for _ in range(3)) if items is not None ] The (expression for name in iterable) is a generator expression. Like a list comprehension but it is a generator - it only runs as it is consumed. A list comprehension makes an actual list (stores all the results in the list). Cheers, Cameron Simpson From __peter__ at web.de Tue Jun 15 02:47:41 2021 From: __peter__ at web.de (Peter Otten) Date: Tue, 15 Jun 2021 08:47:41 +0200 Subject: Is there a way to get the following result in Python? In-Reply-To: <65089d21-5d26-4970-978d-ca2159cfcb01n@googlegroups.com> References: <65089d21-5d26-4970-978d-ca2159cfcb01n@googlegroups.com> Message-ID: On 12/06/2021 04:02, Jach Feng wrote: >>>> def foo(): > ... # do something > ... >>>> a = [] >>>> for i in range(3): > ... a.append(foo()) > ... >>>> a > [] The most natural way to achieve something similar is to replace append() with extend(): >>> def foo(): return () >>> a = [] >>> for i in range(3): a.extend(foo()) >>> a [] From cs at cskk.id.au Tue Jun 15 04:18:48 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 15 Jun 2021 18:18:48 +1000 Subject: Behaviour of pop() for dictionaries In-Reply-To: References: Message-ID: On 14Jun2021 09:39, BlindAnagram wrote: >However, d.pop(key, [default]) returns the value (or the default) and >consistency with other pops (a good thing in my view) would suggest >that d.pop() could return a random value, which would serve my purpose >when there is only one element. If you don't care what key was popped, maybe you want a set and not a dict? Just a thought. Cheers, Cameron Simpson From dieter at handshake.de Tue Jun 15 04:32:02 2021 From: dieter at handshake.de (Dieter Maurer) Date: Tue, 15 Jun 2021 10:32:02 +0200 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: Message-ID: <24776.25986.205672.813043@ixdm.fritz.box> Chris Angelico wrote at 2021-6-15 05:35 +1000: >On Tue, Jun 15, 2021 at 5:12 AM Jach Feng wrote: >> >> >>> n = [(1,2) for i in range(3)] >> >>> n >> [(1, 2), (1, 2), (1, 2)] >> >>> id(n[0]) == id(n[1]) == id(n[2]) >> True > >This is three tuples. Tuples are immutable and you get three >references to the same thing. In addition: object identity (as revealed by `id(...)`) is an implementation detail. Do not rely on it! From rosuav at gmail.com Tue Jun 15 05:08:34 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 15 Jun 2021 19:08:34 +1000 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: <24776.25986.205672.813043@ixdm.fritz.box> References: <24776.25986.205672.813043@ixdm.fritz.box> Message-ID: On Tue, Jun 15, 2021 at 6:32 PM Dieter Maurer wrote: > > Chris Angelico wrote at 2021-6-15 05:35 +1000: > >On Tue, Jun 15, 2021 at 5:12 AM Jach Feng wrote: > >> > >> >>> n = [(1,2) for i in range(3)] > >> >>> n > >> [(1, 2), (1, 2), (1, 2)] > >> >>> id(n[0]) == id(n[1]) == id(n[2]) > >> True > > > >This is three tuples. Tuples are immutable and you get three > >references to the same thing. > > In addition: object identity (as revealed by `id(...)`) is > an implementation detail. Do not rely on it! Hmm, not always. In this case, object identity isn't guaranteed - every literal could give you a unique object - but in other cases, object identity is a language guarantee. For instance: >>> l = (1, 2) # or [1, 2] >>> [l for _ in range(10)] [(1, 2), (1, 2), (1, 2), (1, 2), (1, 2), (1, 2), (1, 2), (1, 2), (1, 2), (1, 2)] >>> [id(x) for x in _] [140499111503808, 140499111503808, 140499111503808, 140499111503808, 140499111503808, 140499111503808, 140499111503808, 140499111503808, 140499111503808, 140499111503808] In this example, it doesn't matter whether it's a list or a tuple (or anything else) - the IDs are all guaranteed to be the same. The only thing that's an implementation detail is whether immutable objects are folded together. You'll find similar situations with strings, numbers, etc, etc. For example, "name-like" strings are often interned in CPython, but other strings aren't, so sometimes you might find different behaviour if you have a space in the string than if you don't. ChrisA From rtomek at ceti.pl Tue Jun 15 11:16:04 2021 From: rtomek at ceti.pl (Tomasz Rola) Date: Tue, 15 Jun 2021 17:16:04 +0200 Subject: Php vs Python gui (tkinter...) for small remote database app In-Reply-To: <1e79e70f-2e35-200f-ffb4-a40b8c4ade65@DancesWithMice.info> References: <2065682577.10278618.1623698250789.ref@mail.yahoo.com> <2065682577.10278618.1623698250789@mail.yahoo.com> <1e79e70f-2e35-200f-ffb4-a40b8c4ade65@DancesWithMice.info> Message-ID: <20210615151603.GA6063@tau1.ceti.pl> On Tue, Jun 15, 2021 at 08:39:51AM +1200, dn via Python-list wrote: > On 15/06/2021 07.17, Pascal B via Python-list wrote: > > Hi, > > I would like to know if for a small app for instance that requires a connection to a remote server database if php is more suitable than Python mainly regarding security. > > Php requires one port for http and one port for the connection to the database open. If using Python with a tkinter gui, I understand a small app can connect to a database so only one port to the database would need to be accessed/open listening to connection. So I would need to worry less about security if using Python over Php for something small, like a small python app that I give over to users. > > > > Am I missing something in this assertion? > > Yes - or maybe I'm missing the point of your question? > > There are two connections to consider: the database and the GUI. > > > Database: > [...] > > > GUI: > [...] > The (Internet-connected) world runs on TLS. If you wish to > secure/encrypt communications between application and server, this is > accepted by most. If you wish to 'secure' by reducing inter-connections, > then using tkinter and its tight-linkage to Python removes the need for > the (http) web-server. I would rather go with https-based "app", but not necessarily in PHP, if security is to be considered (albeit I am not sure if Python framework would do better). Nowadays, there should be a firewall and server sitting behind it (this is simple description, let us not put load balancing, many servers etc into the mix, or if firewall really helps). So, in case of http(s), there should be more tutorials and hints about doing this well. Browser would do the gui side, http server will talk to the database and to the world, but database itself is secured (hopefully) from outside access. I suspect it is easier to secure web server than db from various kind of 'kacks'. If you go with well rounded Python framework, you can count on its authors carefully thinking about various threats to apps written in it. Sorry, I cannot give any hints - see, I rather deteste browser based apps, so this advice goes against my own liking but one should be objective when giving advices... If you are truly new to this all, I suggest CGI, especially if you want to do some proof of concept prototype, quickly. CGI is quite easy to understand and as long as you are working out communications between your code and DB, I think it simplifies the job a lot. Later on, choose your framework and do the gui. If you go with tkinter, then you will have to do the job already done by authors of web server and web framework, you will have to rethink various problems they gave their thoughts to, but in much shorter time and on your own. -- Regards, Tomasz Rola -- ** A C programmer asked whether computer had Buddha's nature. ** ** As the answer, master did "rm -rif" on the programmer's home ** ** directory. And then the C programmer became enlightened... ** ** ** ** Tomasz Rola mailto:tomasz_rola at bigfoot.com ** From greg.ewing at canterbury.ac.nz Tue Jun 15 03:01:28 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 15 Jun 2021 19:01:28 +1200 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: Message-ID: On 15/06/21 3:18 pm, Jach Feng wrote: > From a user's point, I don't really care how Python creates thoseinstances, > either using an already exist one or create a new one, as > long as each element (and its sub-element) are independent from each > other so a modification of one will not influence the other. The real > problem is there are different methods can be used to build it and some > will fail in this purpose. The * operator is one of them, but anyone > else? I really like to know:-) This really has nothing to do with how the tuples are created. It all depends on what you choose to put in them. When you use square brackets to build a list, you can be sure that it will create a new list object each time. Also, if you create two tuples, by any means, containing distinct elements, you can be sure that you will get two distinct tuple objects. So, if you do this: a = [1, 2] b = [1, 2] c = [1, 2] d = [1, 2] s = (a, b) t = (c, d) then you are guaranteed to get four different list objects and two diffferent tuple objects. Does that help to ease your fears? -- Greg From dieter at handshake.de Tue Jun 15 12:18:32 2021 From: dieter at handshake.de (Dieter Maurer) Date: Tue, 15 Jun 2021 18:18:32 +0200 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: <24776.25986.205672.813043@ixdm.fritz.box> Message-ID: <24776.53976.739836.800023@ixdm.fritz.box> Chris Angelico wrote at 2021-6-15 19:08 +1000: >On Tue, Jun 15, 2021 at 6:32 PM Dieter Maurer wrote: >> >> Chris Angelico wrote at 2021-6-15 05:35 +1000: >> >On Tue, Jun 15, 2021 at 5:12 AM Jach Feng wrote: >> >> >> >> >>> n = [(1,2) for i in range(3)] >> >> >>> n >> >> [(1, 2), (1, 2), (1, 2)] >> >> >>> id(n[0]) == id(n[1]) == id(n[2]) >> >> True >> > >> >This is three tuples. Tuples are immutable and you get three >> >references to the same thing. >> >> In addition: object identity (as revealed by `id(...)`) is >> an implementation detail. Do not rely on it! > >Hmm, not always. In this case, object identity isn't guaranteed - >every literal could give you a unique object - but in other cases, >object identity is a language guarantee. For instance: As far as I know, there are no guarantees are the language level. There are some (partially documented) implementation details for CPython (which is just one possible implementation). From rosuav at gmail.com Tue Jun 15 12:20:45 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Jun 2021 02:20:45 +1000 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: <24776.53976.739836.800023@ixdm.fritz.box> References: <24776.25986.205672.813043@ixdm.fritz.box> <24776.53976.739836.800023@ixdm.fritz.box> Message-ID: On Wed, Jun 16, 2021 at 2:18 AM Dieter Maurer wrote: > > Chris Angelico wrote at 2021-6-15 19:08 +1000: > >On Tue, Jun 15, 2021 at 6:32 PM Dieter Maurer wrote: > >> > >> Chris Angelico wrote at 2021-6-15 05:35 +1000: > >> >On Tue, Jun 15, 2021 at 5:12 AM Jach Feng wrote: > >> >> > >> >> >>> n = [(1,2) for i in range(3)] > >> >> >>> n > >> >> [(1, 2), (1, 2), (1, 2)] > >> >> >>> id(n[0]) == id(n[1]) == id(n[2]) > >> >> True > >> > > >> >This is three tuples. Tuples are immutable and you get three > >> >references to the same thing. > >> > >> In addition: object identity (as revealed by `id(...)`) is > >> an implementation detail. Do not rely on it! > > > >Hmm, not always. In this case, object identity isn't guaranteed - > >every literal could give you a unique object - but in other cases, > >object identity is a language guarantee. For instance: > > As far as I know, there are no guarantees are the language level. > There are some (partially documented) implementation details > for CPython (which is just one possible implementation). Yes there are - plenty of them :) The example I gave is a language guarantee. Object identity is maintained in various places, and MUST be; in fact, I've heard tell that PyPy actually has to do some shenanigans to ensure that identities can be tracked across certain types of optimizations (where the object mightn't actually exist temporarily). ChrisA From jfong at ms4.hinet.net Mon Jun 14 23:18:00 2021 From: jfong at ms4.hinet.net (Jach Feng) Date: Mon, 14 Jun 2021 20:18:00 -0700 (PDT) Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: Message-ID: Chris Angelico ? 2021?6?15? ?????5:23:12 [UTC+8] ?????? > On Tue, Jun 15, 2021 at 7:11 AM Rob Cliffe via Python-list > wrote: > > > > This puzzled me, so I played around with it a bit (Python 3.8.3): > > > > n = [] > > for i in range(3): > > n.append((1,7,-3,None,"x")) > > for i in range(3): > > n.append((1,7,-3,None,"x")) > > print([id(x) for x in n]) > > > > a = 4 > > n = [] > > for i in range(3): > > n.append((1,7,-3,a,None,"x")) > > for i in range(3): > > n.append((1,7,-3,a,None,"x")) > > print([id(x) for x in n]) > > > > Output: > > > > [27164832, 27164832, 27164832, 27164832, 27164832, 27164832] > > [30065208, 30065496, 30237192, 30239976, 30240024, 30343928] > > > > Evidently the compiler is clever enough to pick out a constant tuple and > > create (or cause to get created) a single instance of it which is used > > when required. Indeed disassembling the code shows that LOAD_CONST is > > used to get the tuple. But it obviously can't do that when the tuple > > contains a variable. > Correct. In theory, Python could intern the tuples (as can be done > with strings), noticing that it's constructing one that is identical > to one it already has, but the effort of doing that is hard to > justify. Simpler to just build a brand new tuple every time. > > ChrisA >From a user's point, I don't really care how Python creates those instances, either using an already exist one or create a new one, as long as each element (and its sub-element) are independent from each other so a modification of one will not influence the other. The real problem is there are different methods can be used to build it and some will fail in this purpose. The * operator is one of them, but anyone else? I really like to know:-) --Jach From auriocus at gmx.de Tue Jun 15 02:13:29 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 15 Jun 2021 08:13:29 +0200 Subject: Is there a way to get the following result in Python? In-Reply-To: <65089d21-5d26-4970-978d-ca2159cfcb01n@googlegroups.com> References: <65089d21-5d26-4970-978d-ca2159cfcb01n@googlegroups.com> Message-ID: Am 12.06.21 um 04:02 schrieb Jach Feng: >>>> def foo(): > ... # do something > ... >>>> a = [] >>>> for i in range(3): > ... a.append(foo()) > ... >>>> a > [] >>>> How about having "foo" return a list of things? Then you can append that list and return an empty list if you want nothing added: In [1]: def foo(): ...: return [1,2,3] ...: In [2]: def bar(): ...: return [] ...: In [3]: a=[] In [4]: a += foo() In [5]: a Out[5]: [1, 2, 3] In [6]: a += bar() In [7]: a Out[7]: [1, 2, 3] Christian From jfong at ms4.hinet.net Tue Jun 15 03:32:15 2021 From: jfong at ms4.hinet.net (Jach Feng) Date: Tue, 15 Jun 2021 00:32:15 -0700 (PDT) Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: Message-ID: <9d43e9f4-db11-40d4-b5f1-dd581af291ddn@googlegroups.com> Greg Ewing ? 2021?6?15? ?????3:01:46 [UTC+8] ?????? > On 15/06/21 3:18 pm, Jach Feng wrote: > > From a user's point, I don't really care how Python creates thoseinstances, > either using an already exist one or create a new one, as > > long as each element (and its sub-element) are independent from each > > other so a modification of one will not influence the other. The real > > problem is there are different methods can be used to build it and some > > will fail in this purpose. The * operator is one of them, but anyone > > else? I really like to know:-) > This really has nothing to do with how the tuples are created. > It all depends on what you choose to put in them. > > When you use square brackets to build a list, you can be sure that > it will create a new list object each time. > > Also, if you create two tuples, by any means, containing distinct > elements, you can be sure that you will get two distinct tuple > objects. > > So, if you do this: > > a = [1, 2] > b = [1, 2] > c = [1, 2] > d = [1, 2] > > s = (a, b) > t = (c, d) > > then you are guaranteed to get four different list objects and > two diffferent tuple objects. > > Does that help to ease your fears? > > -- > Greg But usually the list creation is not in simple way:-) for example: >>> a = [1,2] >>> m = [a for i in range(3)] >>> m [[1, 2], [1, 2], [1, 2]] >>> id(m[0]) == id(m[1]) == id(m[2]) True --Jach From jfong at ms4.hinet.net Tue Jun 15 03:33:51 2021 From: jfong at ms4.hinet.net (Jach Feng) Date: Tue, 15 Jun 2021 00:33:51 -0700 (PDT) Subject: Is there a way to get the following result in Python? In-Reply-To: References: <65089d21-5d26-4970-978d-ca2159cfcb01n@googlegroups.com> Message-ID: Peter Otten ? 2021?6?15? ?????2:48:07 [UTC+8] ?????? > On 12/06/2021 04:02, Jach Feng wrote: > > >>>> def foo(): > > ... # do something > > ... > >>>> a = [] > >>>> for i in range(3): > > ... a.append(foo()) > > ... > >>>> a > > [] > The most natural way to achieve something similar is to replace append() > with extend(): > > >>> def foo(): return () > >>> a = [] > >>> for i in range(3): > a.extend(foo()) > > > >>> a > [] Yes, return a list and using extend() to collect value is exactly what I need! Thank you, Christian and Peter. --Jach From blindanagram at nowhere.org Tue Jun 15 05:37:03 2021 From: blindanagram at nowhere.org (BlindAnagram) Date: Tue, 15 Jun 2021 10:37:03 +0100 Subject: Behaviour of pop() for dictionaries In-Reply-To: References: <0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk> <0184de41-3482-c576-60ed-343fbe0fe73d@DancesWithMice.info> Message-ID: On 15/06/2021 00:11, dn wrote: > On 15/06/2021 09.18, BlindAnagram wrote: >> On 14/06/2021 20:43, Chris Angelico wrote: >>> On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram > ... > >> No it isn't hard to use popitem() but it evidently proved hard for me to >> remember that it was there. > > If that's a problem, you're going to love using deques with their > 'popping from the left' and 'popping from the right' concepts! I think the difference here is that I know I am going to have to look at the documentation for dequeue when I want to use it. For lists, sets and dictionaries, I don't expect to look at the documentation and pop() seemed a good bet for what I wanted to do. > I don't know if you are ComSc student or not, but there isn't even > consistency at the theoretical level. I first arrived at the concept of > "queuing" and "dequeuing" (NB the latter is not the same as the Python > Collections module "deque" library) whilst studying Queue Theory in > Operations Research. At about the same time, my ComSc studies took me > into "stacks". My student days are well over (about 60 years over). > Queues are known as FIFO constructs - "first-in, first-out". > Stacks are somewhat the opposite: LIFO - "last-in, first-out". > > The "pop" operation was defined as taking the "next" item from the queue > or the "last" item from a stack (the opposite of "push"). However, > between queue and stack, the term "next" refers to opposite ends of the > (implementing in Python) list! > > In fact, coming from a Burroughs mainframe, which ran on "stack > architecture" (cf IBM's multiplicity of "ALU registers"), it came as > something of a surprise when programming languages started allowing me > to "pop" elements that weren't at the LIFO-end of the 'list', eg > list.pop( 3 ) where len( list ) > 4! > > > Next consider how the terms "next" and "element" factor into the > thinking. If we consider a (Python) list there is an implied sequence of > elements based upon their relative position. Notice also that the basic > implementation of list.pop() is LIFO! Whereas, the definition of a set > involves no concept of sequence or order - only of membership (and that > the elements are "hashable"). Accordingly, a pop() operation returns an > "arbitrary value", cf 'next please'. > > Similarly, a dict's keys are referred-to as hashable, with the idea of > "random access" to an element via its key (cf the "sequential access" of > a list). Thus, we can ask to pop() a dict, but only if we provide a key > - in which case, pop( key ) is the same as dict[ key ] except that the > key-value pair is also removed from the dict! > > Recall though, it is possible to use list.pop() without any argument. > So, consistency has been thrown-out-the-window there as well. > > Also, with LIFO in-mind, Python v3.7 brought a concept of 'sequence' > (population order) to dicts, and thus we now have this "guarantee" in > popitem() - and thus a memory-confusion for those of us who learned the > original "arbitrary" definition - confusion both of dict behavior and of > dict.popitem() specifically! > > Worse confusion awaits (and referring to a conversation 'here' last > week) Python's pop() exhibits elements of both an "expression" and of a > "statement", ie it not only returns a value, but it affects > (?"side-effects") the underlying collection. Thus, no pop() for strings, > tuples, etc, because they are immutable collections! > > The action of pop() is clearly inconsistent across types of collection. > It's effect is data-structure dependent because the purposes of those > structures are inherently different. "Consistency" would aid memory, but > "polymorphism" can only deliver functionality according to the > characteristics of the specific data-type! Yes, but we can still seek consistency where it is possible > Having entered the queue-of-life a long time ago, and shuffling ever > closer to 'the end of the line', this memory-challenged 'silver-surfer' > prefers to reserve pop() for straightforward stacks and lists, which > implies quite enough inconsistency, without trying to convolute my mind > to pop()-ing dicts, sets (or 'worse'!). > > That said, whether I actually use dict.pop() or not, these 'features' > which are consistent in name but not necessarily in arguments or > effects, contribute to Python's great flexibility and power! Thank > goodness for help() and the Python docs... I don't like 'pop's at all since it meant that a valve had exploded on the Ferranti Pegasus that was my first encounter with computers. Brian From blindanagram at nowhere.org Tue Jun 15 05:49:49 2021 From: blindanagram at nowhere.org (BlindAnagram) Date: Tue, 15 Jun 2021 10:49:49 +0100 Subject: Behaviour of pop() for dictionaries In-Reply-To: References: <0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk> Message-ID: On 15/06/2021 01:36, Terry Reedy wrote: > On 6/14/2021 5:18 PM, BlindAnagram wrote: > >> I believe that consistency in how methods common to different types >> work is useful since it adds to the coherence of the language as a >> whole and avoids the need to remember special cases. > > Each collection class *is* a special case, and pop has to be adjusted to > each.? However, you seem to have missed an essential commonality. > > Lists and dicts are both subscripted classes.? So the basic API is > col.pop(sub), which removes and returns the sub item, whereas col[sub] > leaves and returns. > > Lists have a special index, -1, the most commonly used, so that is the > default.? In fact, when I proposed list.pop(), I only proposed that, as > I wanted pop to be the inverse of append, so a list could be used as a > stack. > > Bad list subscripts are an error (unless one is slicing), whereas where > dicts allow a default (when subscripted with the get method).? Hence the > optional default only for dicts. > > At one time, dicts, like sets, were unordered collections (of functional > item pairs). dict.pop(), with no arg, could have been used to return a > random 2-ple, but Guido is generally against having return types depend > on arguments. So a new popxxx name was added.? Note that deques have a > popleft in addition to pop (right). Thanks for the interesting history. Having found that dict.pop() caused an error, I did wonder whether it should have returned a (key, value) pair but quickly came to the conclusion that this would be awful because it would be inconsistent with the normal value returned by pop(x). Sadly this did not result in any recollection that there was a popitem() :-( Brian From pleasedonotsendspam at yahoo.ru Tue Jun 15 06:07:02 2021 From: pleasedonotsendspam at yahoo.ru (Elena) Date: Tue, 15 Jun 2021 10:07:02 +0000 (UTC) Subject: optimization of rule-based model on discrete variables References: Message-ID: Il Tue, 15 Jun 2021 10:40:05 +1200, Greg Ewing ha scritto: > On 15/06/21 12:51 am, Elena wrote: > Hmmm, so the problem breaks down into two parts: > (1) find a vector Y that minimises g (2) find a set of rules that will > allow you to predict each component of Y from its corresponding X values > > Is that right? Correct, the split can be an interesting approach. > > I ztill don't really understand. What are you going to do with this > function f once you have it? > > I would have thought the idea was that if someone gives you a new > mixture X[n+1] you can use f to predict how well it will work. > But that will just give you a y[n+1], and it's not clear what to do with > that. Do you append it to Y and feed an n+1 component vector into g? > > I think I still need more information about the underlying problem > before I can help you much. After the optimization, I will use f just to predict new Xi. Thanks From pleasedonotsendspam at yahoo.ru Tue Jun 15 06:18:36 2021 From: pleasedonotsendspam at yahoo.ru (Elena) Date: Tue, 15 Jun 2021 10:18:36 +0000 (UTC) Subject: optimization of rule-based model on discrete variables References: <20210615015309.dt2clmvcm2hketrm@gmail.com> Message-ID: Il Tue, 15 Jun 2021 01:53:09 +0000, Martin Di Paola ha scritto: > From what I'm understanding it is an "optimization problem" like the > ones that you find in "linear programming". > > But in your case the variables are not Real (they are Integers) and the > function to minimize g() is not linear. > > You could try/explore CVXPY (https://www.cvxpy.org/) which it's a solver > for different kinds of "convex programming". I don't have experience > with it however. > > The other weapon in my arsenal would be Z3 > (https://theory.stanford.edu/~nikolaj/programmingz3.html) which it's a > SMT/SAT solver with a built-in extension for optimization problems. > > I've more experience with this so here is a "draft" of what you may be > looking for. > > > from z3 import Integers, Optimize, And, If > > # create a Python array X with 3 Z3 Integer variables named x0, x1, x2 X > = Integers('x0 x1 x2') > Y = Integers('y0 y1') > > # create the solver solver = Optimize() > > # add some restrictions like lower and upper bounds for x in X: > solver.add(And(0 <= x, x <= 2)) # each x is between 0 and 2 > for y in Y: > solver.add(And(0 <= y, y <= 2)) > > def f(X): > # Conditional expression can be modeled too with "If" > # These are *not* evaluated like a normal Python "if" but # modeled > as a whole. It'll be the solver which will "run it" > return If( > And(x[0] == 0, x[1] == 0), # the condition Y[0] == 0, # Y[0] will > *must* be 0 *if* the condition holds Y[0] == 2 # Y[0] will *must* > be 2 *if* the condition doesn't hold ) > > solver.add(f(X)) > > # let's define the function to optimize g = Y[0]**2 solver.maximize(g) > > # check if we have a solution solver.check() # this should return 'sat' > > # get one of the many optimum solutions solver.model() > > > I would recommend you to write a very tiny problem with 2 or 3 variables > and a very simple f() and g() functions, make it work (manually and with > Z3) and only then build a more complex program. > > You may find useful (or not) these two posts that I wrote a month ago > about Z3. These are not tutorials, just personal experience with a > concrete example. > > Combine Real, Integer and Bool variables: > https://book-of-gehn.github.io/articles/2021/05/02/Planning-Space- Missions.html > > Lookup Tables (this may be useful for programming a f() "variable" > function where the code of f() (the decision tree) is set by Z3 and not > by you such f() leads to the optimum of g()) > https://book-of-gehn.github.io/articles/2021/05/26/Casting-Broadcasting- LUT-and-Bitwise-Ops.html > > > Happy hacking. > Martin. > > Interesting, I completely didn't know about this Z3 tool, I'll try to go into that. Thank you for hint. BTW the first two links I think are broken. Ele From mennoholscher at gmail.com Tue Jun 15 06:51:06 2021 From: mennoholscher at gmail.com (Menno Holscher) Date: Tue, 15 Jun 2021 12:51:06 +0200 Subject: Php vs Python gui (tkinter...) for small remote database app In-Reply-To: <2065682577.10278618.1623698250789@mail.yahoo.com> References: <2065682577.10278618.1623698250789.ref@mail.yahoo.com> <2065682577.10278618.1623698250789@mail.yahoo.com> Message-ID: Op 14-06-2021 om 21:17 schreef Pascal B via Python-list: > Hi, > I would like to know if for a small app for instance that requires a connection to a remote server database if php is more suitable than Python mainly regarding security. > Php requires one port for http and one port for the connection to the database open. If using Python with a tkinter gui, I understand a small app can connect to a database so only one port to the database would need to be accessed/open listening to connection. So I would need to worry less about security if using Python over Php for something small, like a small python app that I give over to users. > > Am I missing something in this assertion? > There is no difference regarding security concerns. In the case of a PHP (or any web app for that matter) you indeed have to worry about the security of the connection to the browser. But, e.g. the access to the database is only in one place, on the server. If you use a Tkinter application, each user will have the access to the database at his/her own machine, causing other worries than connection security. The attack vector may be different, but the worries are no less or more in one of the solutions. First investigate what you need to be afraid of/worried about, do not make a decision on a simple criterion like the number of connections. -- Met vriendelijke groet / Kind regards Menno H?lscher From grimble at nomail.afraid.org Tue Jun 15 09:04:41 2021 From: grimble at nomail.afraid.org (Grimble) Date: Tue, 15 Jun 2021 14:04:41 +0100 Subject: Where did the message go? In-Reply-To: References: <0753f4a8-1f36-5616-6891-b27296292ee1@DancesWithMice.info> Message-ID: On 14/06/2021 20:58, dn wrote: > On 15/06/2021 01.00, Grimble wrote: >> I have two machines running Mageia 8 and Python 2.8.9, They use the same >> Python script to maintain a list of changed packages from dnf update and >> dnf install. In addition the script sends a short email message to my >> main email address. The problem is: the message from machine B arrives, >> the message from machine H does not. >> The part of the script that sends the message is: >> ?? with open('email.txt') as fmail: >> ??????? msg = EmailMessage() >> ??????? msg.set_content(fmail.read()) >> >> ??? msg['Subject'] = 'System update' >> ??? msg['From'] = sysname >> ??? msg['To'] = 'graeme at XXXX.XXXX' (details removed to protect the >> innocent) >> >> ??? # Send the message via our own SMTP server. >> ??? s = smtplib.SMTP('localhost') >> ??? s.set_debuglevel(True) >> ??? s.send_message(msg) >> ??? s.quit() >> >> The last lines of s.set_debuglevel are >> reply: retcode (250); Msg: b'2.0.0 Ok: queued as B57B42C042F' >> data: (250, b'2.0.0 Ok: queued as B57B42C042F') >> send: 'quit\r\n' >> reply: b'221 2.0.0 Bye\r\n' >> reply: retcode (221); Msg: b'2.0.0 Bye' >> >> The SMTP part of the system is working (hence this message). >> The message from machine B correctly interprets "sysname" as >> sysname at sysname.XXXX.XXXX i.e a valid addr4ess. >> >> Where do I look now, please? > > That's machine B, but the issue is with machine H. > Have you compared the contents of the two machines' /var/log/maillog? > Thanks for reminding me of the log files. I've worked out that the message on machine H (for haydn, which shows my preferred music genre) was bouncing because haydn.XXXX.XXXX was not a registered subdomain with my ISP, whereas bach.XXXX.XXXX was registered. Sorted now. -- Grimble Registered Linux User #450547 Machine 'Bach' running Plasma 5.20.4 on 5.10.43-desktop-1.mga8 kernel. Mageia release 8 (Official) for x86_64 From arakelthedragon at gmail.com Tue Jun 15 10:17:12 2021 From: arakelthedragon at gmail.com (Arak Rachael) Date: Tue, 15 Jun 2021 07:17:12 -0700 (PDT) Subject: Help with Python circular error Message-ID: <477e80fd-131b-4892-bb1d-ac9e984c9035n@googlegroups.com> Hi to everyone, I am having a problem with this error, I created a package and uploaded it to Test PyPi, but I can not get it to work, can someone help me please? https://test.pypi.org/manage/project/videotesting/releases/' The error: /home/user/anaconda3/envs/testing/bin/python /home/user/devel/python.assignments/topgis-viz/topgis-test.py Traceback (most recent call last): File "/home/user/devel/python.assignments/topgis-viz/topgis-test.py", line 10, in from videotesting import downsample_and_save_npz File "/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py", line 7, in from videotesting import extract_video ImportError: cannot import name 'extract_video' from partially initialized module 'videotesting' (most likely due to a circular import) (/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py) From python at mrabarnett.plus.com Tue Jun 15 12:42:39 2021 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 15 Jun 2021 17:42:39 +0100 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: <24776.53976.739836.800023@ixdm.fritz.box> References: <24776.25986.205672.813043@ixdm.fritz.box> <24776.53976.739836.800023@ixdm.fritz.box> Message-ID: On 2021-06-15 17:18, Dieter Maurer wrote: > Chris Angelico wrote at 2021-6-15 19:08 +1000: >>On Tue, Jun 15, 2021 at 6:32 PM Dieter Maurer wrote: >>> >>> Chris Angelico wrote at 2021-6-15 05:35 +1000: >>> >On Tue, Jun 15, 2021 at 5:12 AM Jach Feng wrote: >>> >> >>> >> >>> n = [(1,2) for i in range(3)] >>> >> >>> n >>> >> [(1, 2), (1, 2), (1, 2)] >>> >> >>> id(n[0]) == id(n[1]) == id(n[2]) >>> >> True >>> > >>> >This is three tuples. Tuples are immutable and you get three >>> >references to the same thing. >>> >>> In addition: object identity (as revealed by `id(...)`) is >>> an implementation detail. Do not rely on it! >> >>Hmm, not always. In this case, object identity isn't guaranteed - >>every literal could give you a unique object - but in other cases, >>object identity is a language guarantee. For instance: > > As far as I know, there are no guarantees are the language level. > There are some (partially documented) implementation details > for CPython (which is just one possible implementation). > There is a language guarantee that every object has an identity that's given by 'id' and that 'x is y' is equivalent to 'id(x) == id(y)'. In CPython it happens to be the address of the object, but that's an implementation detail. From rosuav at gmail.com Tue Jun 15 12:47:15 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Jun 2021 02:47:15 +1000 Subject: Where did the message go? In-Reply-To: References: <0753f4a8-1f36-5616-6891-b27296292ee1@DancesWithMice.info> Message-ID: On Wed, Jun 16, 2021 at 2:41 AM Grimble wrote: > Thanks for reminding me of the log files. I've worked out that the > message on machine H (for haydn, which shows my preferred music genre) > was bouncing because haydn.XXXX.XXXX was not a registered subdomain with > my ISP, whereas bach.XXXX.XXXX was registered. Sorted now. > I like your naming convention :) ChrisA From rosuav at gmail.com Tue Jun 15 12:49:02 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Jun 2021 02:49:02 +1000 Subject: Help with Python circular error In-Reply-To: <477e80fd-131b-4892-bb1d-ac9e984c9035n@googlegroups.com> References: <477e80fd-131b-4892-bb1d-ac9e984c9035n@googlegroups.com> Message-ID: On Wed, Jun 16, 2021 at 2:45 AM Arak Rachael wrote: > > Hi to everyone, > > I am having a problem with this error, I created a package and uploaded it to Test PyPi, but I can not get it to work, can someone help me please? > > https://test.pypi.org/manage/project/videotesting/releases/' > > The error: > > /home/user/anaconda3/envs/testing/bin/python /home/user/devel/python.assignments/topgis-viz/topgis-test.py > Traceback (most recent call last): > File "/home/user/devel/python.assignments/topgis-viz/topgis-test.py", line 10, in > from videotesting import downsample_and_save_npz > File "/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py", line 7, in > from videotesting import extract_video > ImportError: cannot import name 'extract_video' from partially initialized module 'videotesting' (most likely due to a circular import) (/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py) > Hard to diagnose without the source code, but I'm thinking that your __init__.py is probably trying to import from elsewhere in the package? If so, try "from . import extract_video" instead. ChrisA From PythonList at DancesWithMice.info Tue Jun 15 13:10:44 2021 From: PythonList at DancesWithMice.info (dn) Date: Wed, 16 Jun 2021 05:10:44 +1200 Subject: Where did the message go? In-Reply-To: References: <0753f4a8-1f36-5616-6891-b27296292ee1@DancesWithMice.info> Message-ID: <338923ea-0305-d7cc-34f3-4efd233394c9@DancesWithMice.info> On 16/06/2021 04.47, Chris Angelico wrote: > On Wed, Jun 16, 2021 at 2:41 AM Grimble wrote: >> Thanks for reminding me of the log files. I've worked out that the >> message on machine H (for haydn, which shows my preferred music genre) >> was bouncing because haydn.XXXX.XXXX was not a registered subdomain with >> my ISP, whereas bach.XXXX.XXXX was registered. Sorted now. >> > > I like your naming convention :) He's playing your tune! -- Regards, =dn From python at mrabarnett.plus.com Tue Jun 15 13:13:20 2021 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 15 Jun 2021 18:13:20 +0100 Subject: Help with Python circular error In-Reply-To: References: <477e80fd-131b-4892-bb1d-ac9e984c9035n@googlegroups.com> Message-ID: <940d2f0c-0e79-1003-68ee-7a8981aa2c38@mrabarnett.plus.com> On 2021-06-15 17:49, Chris Angelico wrote: > On Wed, Jun 16, 2021 at 2:45 AM Arak Rachael wrote: >> >> Hi to everyone, >> >> I am having a problem with this error, I created a package and uploaded it to Test PyPi, but I can not get it to work, can someone help me please? >> >> https://test.pypi.org/manage/project/videotesting/releases/' >> >> The error: >> >> /home/user/anaconda3/envs/testing/bin/python /home/user/devel/python.assignments/topgis-viz/topgis-test.py >> Traceback (most recent call last): >> File "/home/user/devel/python.assignments/topgis-viz/topgis-test.py", line 10, in >> from videotesting import downsample_and_save_npz >> File "/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py", line 7, in >> from videotesting import extract_video >> ImportError: cannot import name 'extract_video' from partially initialized module 'videotesting' (most likely due to a circular import) (/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py) >> > > Hard to diagnose without the source code, but I'm thinking that your > __init__.py is probably trying to import from elsewhere in the > package? If so, try "from . import extract_video" instead. > Well, the traceback says that videotesting/__init__.py has: from videotesting import extract_video so it is trying to import from itself during initialisation. From grant.b.edwards at gmail.com Tue Jun 15 13:14:01 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 15 Jun 2021 17:14:01 -0000 (UTC) Subject: Php vs Python gui (tkinter...) for small remote database app References: <2065682577.10278618.1623698250789.ref@mail.yahoo.com> <2065682577.10278618.1623698250789@mail.yahoo.com> Message-ID: On 2021-06-15, Menno Holscher wrote: > There is no difference regarding security concerns. I find that hard to believe given the long list of CVEs I've just had to sort through for even fairly recent versions of PHP. I just can't belive that Python has anywhere close to that many secruity issues. -- Grant Edwards grant.b.edwards Yow! I'd like some JUNK at FOOD ... and then I want to gmail.com be ALONE -- From rosuav at gmail.com Tue Jun 15 13:29:57 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Jun 2021 03:29:57 +1000 Subject: Help with Python circular error In-Reply-To: <940d2f0c-0e79-1003-68ee-7a8981aa2c38@mrabarnett.plus.com> References: <477e80fd-131b-4892-bb1d-ac9e984c9035n@googlegroups.com> <940d2f0c-0e79-1003-68ee-7a8981aa2c38@mrabarnett.plus.com> Message-ID: On Wed, Jun 16, 2021 at 3:17 AM MRAB wrote: > > On 2021-06-15 17:49, Chris Angelico wrote: > > On Wed, Jun 16, 2021 at 2:45 AM Arak Rachael wrote: > >> > >> Hi to everyone, > >> > >> I am having a problem with this error, I created a package and uploaded it to Test PyPi, but I can not get it to work, can someone help me please? > >> > >> https://test.pypi.org/manage/project/videotesting/releases/' > >> > >> The error: > >> > >> /home/user/anaconda3/envs/testing/bin/python /home/user/devel/python.assignments/topgis-viz/topgis-test.py > >> Traceback (most recent call last): > >> File "/home/user/devel/python.assignments/topgis-viz/topgis-test.py", line 10, in > >> from videotesting import downsample_and_save_npz > >> File "/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py", line 7, in > >> from videotesting import extract_video > >> ImportError: cannot import name 'extract_video' from partially initialized module 'videotesting' (most likely due to a circular import) (/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py) > >> > > > > Hard to diagnose without the source code, but I'm thinking that your > > __init__.py is probably trying to import from elsewhere in the > > package? If so, try "from . import extract_video" instead. > > > Well, the traceback says that videotesting/__init__.py has: > from videotesting import extract_video > > so it is trying to import from itself during initialisation. Yes, but what we can't tell is what the intention is. It could be trying to import from its own package (in which case my suggestion would be correct), or it could be trying to import from something completely different (in which case the solution is to rename something to avoid the conflict). Or it could be something else entirely. ChrisA From greg.ewing at canterbury.ac.nz Tue Jun 15 19:11:16 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 16 Jun 2021 11:11:16 +1200 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: <9d43e9f4-db11-40d4-b5f1-dd581af291ddn@googlegroups.com> References: <9d43e9f4-db11-40d4-b5f1-dd581af291ddn@googlegroups.com> Message-ID: On 15/06/21 7:32 pm, Jach Feng wrote: > But usually the list creation is not in simple way:-) for example: >>>> a = [1,2] >>>> m = [a for i in range(3)] >>>> m > [[1, 2], [1, 2], [1, 2]] >>>> id(m[0]) == id(m[1]) == id(m[2]) > True The first line is only executed once, so you just get one list object [1, 2]. You then refer to that object three times when you build the outer list. To get three different [1, 2] lists you would need something like this: m = [[1,2] for i in range(3)] This executes the [1, 2] expression 3 times. Because lists are mutable, you can be sure that this will give you 3 distinct list objects. -- Greg From greg.ewing at canterbury.ac.nz Tue Jun 15 19:37:42 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 16 Jun 2021 11:37:42 +1200 Subject: optimization of rule-based model on discrete variables In-Reply-To: References: Message-ID: On 15/06/21 10:07 pm, Elena wrote: > After the optimization, I will use f just to predict new Xi. So you're going to use f backwards? I don't see how that will work. Where are you going to find a new yi to feed into the inverse of f? I think I don't understand what role g plays in all of this. If the ultimate goal is to find a better mixture, you need some kind of figure of merit for an individual mixture. But you don't have that, you only have this thing g that somehow depends on all of your mixtures at once. I'm still not seeing the big picture. -- Greg From mennoholscher at gmail.com Tue Jun 15 15:50:49 2021 From: mennoholscher at gmail.com (Menno Holscher) Date: Tue, 15 Jun 2021 21:50:49 +0200 Subject: Php vs Python gui (tkinter...) for small remote database app In-Reply-To: References: <2065682577.10278618.1623698250789.ref@mail.yahoo.com> <2065682577.10278618.1623698250789@mail.yahoo.com> Message-ID: Op 15-06-2021 om 19:14 schreef Grant Edwards: > On 2021-06-15, Menno Holscher wrote: > >> There is no difference regarding security concerns. > > I find that hard to believe given the long list of CVEs I've just had > to sort through for even fairly recent versions of PHP. I just can't > belive that Python has anywhere close to that many secruity issues. > An excellent example. The "concerns" here are "Is this platform safe?" and "Does the supplier/community react promptly to security problems?". In case of PHP indeed the safety of the platform is a worry, however, apparently if there is a problem, action is taken. How does the Tkinter/TCL/TK software or the PyQt/Qt do in that respect? Just looking at the number of CVEs, is that enough? What if one of these stacks has few, but long outstanding security problems? Would that be better or worse than the situation for PHP? As an aside, I do not know the amount of CVEs PHP nor Python is receiving. When I search the NIST CVE database for the word Python I get 43 hits for the last 3 months. None of those are against the language or the CPython interpreter and only 1 against a Standard Library package or module (urllib3). A lot of the others are for web frameworks and extensions for those, as well as Tensorflow. So as you argue, it seems Python does really well as a secure development platform. -- Met vriendelijke groet / Kind regards Menno H?lscher From avigross at verizon.net Tue Jun 15 20:15:39 2021 From: avigross at verizon.net (Avi Gross) Date: Tue, 15 Jun 2021 20:15:39 -0400 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: <9d43e9f4-db11-40d4-b5f1-dd581af291ddn@googlegroups.com> Message-ID: <03db01d76244$bd57b920$38072b60$@verizon.net> May I ask if there are any PRACTICAL differences if multiple immutable tuples share the same address or not? I mean if I use a tuple in a set or as the key in a dictionary and a second one comes along, will it result in two entries one time and only one the other time? Some languages I use often have a lazy evaluation where things are not even copied when doing some things and only copied if absolutely needed as in when you make a change. So you can create say a data.frame then make another from it with some columns added and removed and the storage used does not change much, but add or remove one or two, and suddenly entire large amounts get copied. So by that argument, you could have the copies of the list also be the same at first and since they are mutable, they might diverge later or not but tuples would never change so why not share if the compiler or interpreter was set to use less space when possible. Now if you really still want true copies, what ways might fool a compiler? NoDup = [(5, 2), (6-1, 6/3), (12%7, 1/1 + 1/1)] -----Original Message----- From: Python-list On Behalf Of Greg Ewing Sent: Tuesday, June 15, 2021 7:11 PM To: python-list at python.org Subject: Re: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? On 15/06/21 7:32 pm, Jach Feng wrote: > But usually the list creation is not in simple way:-) for example: >>>> a = [1,2] >>>> m = [a for i in range(3)] >>>> m > [[1, 2], [1, 2], [1, 2]] >>>> id(m[0]) == id(m[1]) == id(m[2]) > True The first line is only executed once, so you just get one list object [1, 2]. You then refer to that object three times when you build the outer list. To get three different [1, 2] lists you would need something like this: m = [[1,2] for i in range(3)] This executes the [1, 2] expression 3 times. Because lists are mutable, you can be sure that this will give you 3 distinct list objects. -- Greg -- https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Jun 15 20:21:23 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Jun 2021 10:21:23 +1000 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: <03db01d76244$bd57b920$38072b60$@verizon.net> References: <9d43e9f4-db11-40d4-b5f1-dd581af291ddn@googlegroups.com> <03db01d76244$bd57b920$38072b60$@verizon.net> Message-ID: On Wed, Jun 16, 2021 at 10:17 AM Avi Gross via Python-list wrote: > > May I ask if there are any PRACTICAL differences if multiple immutable > tuples share the same address or not? No, there aren't. It's nothing more than an (optional) optimization. This is true of every immutable type, including strings (both text and byte), numbers (int, float, etc), and less obvious ones like code objects. (Though not function objects. They're mutable.) > I mean if I use a tuple in a set or as the key in a dictionary and a second > one comes along, will it result in two entries one time and only one the > other time? Nope; dictionaries use the *value*, so even if you have two distinct tuples with the same value, they will be considered equal. > Some languages I use often have a lazy evaluation where things are not even > copied when doing some things and only copied if absolutely needed as in > when you make a change. So you can create say a data.frame then make > another from it with some columns added and removed and the storage used > does not change much, but add or remove one or two, and suddenly entire > large amounts get copied. > > So by that argument, you could have the copies of the list also be the same > at first and since they are mutable, they might diverge later or not but > tuples would never change so why not share if the compiler or interpreter > was set to use less space when possible. Hmm. Copy-on-write is permissible but wouldn't be worthwhile in most cases. But I'm sure there are situations where it would be worth it. > Now if you really still want true copies, what ways might fool a compiler? > > NoDup = [(5, 2), (6-1, 6/3), (12%7, 1/1 + 1/1)] > Note that these would all compare equal, but they are NOT indistinguishable. The first one has a pair of integers, the other two have an int and a float. But with the two that *are* indistinguishable, CPython 3.10 folds them together and has two references to the same tuple. ChrisA From greg.ewing at canterbury.ac.nz Tue Jun 15 21:00:11 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 16 Jun 2021 13:00:11 +1200 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: <9d43e9f4-db11-40d4-b5f1-dd581af291ddn@googlegroups.com> <03db01d76244$bd57b920$38072b60$@verizon.net> Message-ID: On 16/06/21 12:15 pm, Avi Gross wrote: > May I ask if there are any PRACTICAL differences if multiple immutable > tuples share the same address or not? Only if some piece of code relies on the identity of tuples by using 'is' or id() on them. There's rarely any need to write code like that, though. Normally you should compare tuples using '==', not 'is'. Exceptions to this usually involve something like cacheing where identity is only used for optimisation purposes, and the end result doesn't depend in it. > I mean if I use a tuple in a set or as the key in a dictionary and a second > one comes along, will it result in two entries one time and only one the > other time? Dicts and sets compare keys by equality, not identity, so there is no problem here. >>> a = 1 >>> b = 2 >>> t1 = (a, b) >>> t2 = (a, b) >>> t1 is t2 False >>> d = {} >>> d[t1] = 'spam' >>> t2 in d True >>> s = set() >>> s.add(t1) >>> t2 in s True > Some languages I use often have a lazy evaluation where things are not even > copied when doing some things and only copied if absolutely needed > So by that argument, you could have the copies of the list also be the > same at first and since they are mutable, they might diverge later Python is not one of those languages, though, and it won't do things like that. (At least not on its own -- you can certainly implement such a lazily-copied data structure if you want.) > Now if you really still want true copies, what ways might fool a compiler? I've shown one way above that works in CPython, but a smarter implementation might notice that t1 and t2 will always be equal and merge them. > NoDup = [(5, 2), (6-1, 6/3), (12%7, 1/1 + 1/1)] CPython merges the last two of these, but not the first: >>> NoDup = [(5, 2), (6-1, 6/3), (12%7, 1/1 + 1/1)] >>> [id(x) for x in NoDup] [4387029696, 4386827968, 4386827968] The reason is that '/' does float division in Python 3. If you use int division instead, they all get merged: >>> NoDup = [(5, 2), (6-1, 6//3), (12%7, 1//1 + 1//1)] >>> [id(x) for x in NoDup] [4387030272, 4387030272, 4387030272] So you need to be tricker than that to fool it! The bottom line is, don't write code that depends on the identities of immutable objects. -- Greg From avigross at verizon.net Tue Jun 15 22:43:14 2021 From: avigross at verizon.net (Avi Gross) Date: Tue, 15 Jun 2021 22:43:14 -0400 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: <9d43e9f4-db11-40d4-b5f1-dd581af291ddn@googlegroups.com> <03db01d76244$bd57b920$38072b60$@verizon.net> Message-ID: <051401d76259$5b4b9390$11e2bab0$@verizon.net> Greg, My point was not to ASK what python does as much as to ask why it matters to anyone which way it does it. Using less space at absolutely no real expense is generally a plus. Having a compiler work too hard, or even ask the code to work too hard, is often a minus. If I initialized the tuples by calling f(5) and g(5) and so on, the compiler might not even be easily able to figure out that they all return the same thing. So should it make a run-time addition to the code so that after calculating the second, it should look around and if it matches the first, combine them? Again, I have seen languages where the implementation is to have exactly one copy of each unique string of characters. That can be useful but if it is done by creating some data structure and searching through it even when we have millions of unique strings, ... Heck, one excellent reason to use "constants" in your code (i.e. something immutable) is to allow such optimizations. In some programs, garbage collection is very active as things get copied and modified and parts released. So it can be worth some effort to mark some items as copy-on-change as they are often abandoned without changes. The common paradigm I often see is you bring in a structure like a data.frame with dozens of columns and then make a new variable containing a subset, perhaps in a different order and perhaps then then add another column made by some calculation like it being equal to the items in the column called "distance" divided by the column entries called "time" to make a speed column. You might graph the result and then make other such structures and graphs all without doing anything but reading some columns. If you then decided to just take a subset of the rows, or update even a single item in one column, sure, you then take a copy but only of the vectors that changed. Does python need something like this. I doubt it. Languages with such lazy features can do very powerful things but then need even more operators to force certain evaluations to be done in certain ways that leave other parts unevaluated. R, for amusement, has an operator called !! (named bang bang) for some such purposes and another operator !!! (obviously called The Big Bang) for others. But it has radical differences in philosophy as compared to something like python and each has a role and places it is easier to write some kinds of programs than others. The original question here was why there are different results. I think the answer to my question is that it does not matter for most purposes. I can think of one that MAYBE does. If an application has some kind of ceiling, such as calculating how much memory is left before deciding if a mail message is too big to send, and it sometimes runs on machines with different amounts of such resources, you can end up with a message being shunted along the way towards the destination (we are talking ages ago) and suddenly hitting a machine where it is tossed into junkmail as too big. So if your compiler/interpreter is one that allows you to use less memory in circumstances like we are discussing, you may not get what you think. Imagine a program that every time it creates a data structure, adds some measure like sizeof() the new item and halts if the size reached a gigabyte or perhaps charges extra because you used more of a resource. The programmer choosing the list versus tuple alternative, would get different behavior in such a hypothetical scenario. -----Original Message----- From: Python-list On Behalf Of Greg Ewing Sent: Tuesday, June 15, 2021 9:00 PM To: python-list at python.org Subject: Re: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? On 16/06/21 12:15 pm, Avi Gross wrote: > May I ask if there are any PRACTICAL differences if multiple immutable > tuples share the same address or not? Only if some piece of code relies on the identity of tuples by using 'is' or id() on them. There's rarely any need to write code like that, though. Normally you should compare tuples using '==', not 'is'. Exceptions to this usually involve something like cacheing where identity is only used for optimisation purposes, and the end result doesn't depend in it. > I mean if I use a tuple in a set or as the key in a dictionary and a > second one comes along, will it result in two entries one time and > only one the other time? Dicts and sets compare keys by equality, not identity, so there is no problem here. >>> a = 1 >>> b = 2 >>> t1 = (a, b) >>> t2 = (a, b) >>> t1 is t2 False >>> d = {} >>> d[t1] = 'spam' >>> t2 in d True >>> s = set() >>> s.add(t1) >>> t2 in s True > Some languages I use often have a lazy evaluation where things are not > even copied when doing some things and only copied if absolutely > needed > So by that argument, you could have the copies of the list also be the > same at first and since they are mutable, they might diverge later Python is not one of those languages, though, and it won't do things like that. (At least not on its own -- you can certainly implement such a lazily-copied data structure if you want.) > Now if you really still want true copies, what ways might fool a compiler? I've shown one way above that works in CPython, but a smarter implementation might notice that t1 and t2 will always be equal and merge them. > NoDup = [(5, 2), (6-1, 6/3), (12%7, 1/1 + 1/1)] CPython merges the last two of these, but not the first: >>> NoDup = [(5, 2), (6-1, 6/3), (12%7, 1/1 + 1/1)] >>> [id(x) for x in NoDup] [4387029696, 4386827968, 4386827968] The reason is that '/' does float division in Python 3. If you use int division instead, they all get merged: >>> NoDup = [(5, 2), (6-1, 6//3), (12%7, 1//1 + 1//1)] >>> [id(x) for x in NoDup] [4387030272, 4387030272, 4387030272] So you need to be tricker than that to fool it! The bottom line is, don't write code that depends on the identities of immutable objects. -- Greg -- https://mail.python.org/mailman/listinfo/python-list From PythonList at DancesWithMice.info Wed Jun 16 01:04:29 2021 From: PythonList at DancesWithMice.info (dn) Date: Wed, 16 Jun 2021 17:04:29 +1200 Subject: Behaviour of pop() for dictionaries In-Reply-To: References: <0cydnfLE1o4LWlr9nZ2dnUU78eHNnZ2d@brightview.co.uk> <0184de41-3482-c576-60ed-343fbe0fe73d@DancesWithMice.info> Message-ID: <12ae29a6-d96a-7075-6554-29e741aa5f73@DancesWithMice.info> On 15/06/2021 21.37, BlindAnagram wrote: > On 15/06/2021 00:11, dn wrote: >> On 15/06/2021 09.18, BlindAnagram wrote: >>> On 14/06/2021 20:43, Chris Angelico wrote: >>>> On Tue, Jun 15, 2021 at 5:41 AM BlindAnagram >> ... > I think the difference here is that I know I am going to have to look at > the documentation for dequeue when I want to use it. For lists, sets and > dictionaries, I don't expect to look at the documentation and pop() > seemed a good bet for what I wanted to do. "What I expect" (aka 'dim/dusty recollection' or 'gut feel') is a good way to learn - match it with the Python REPL and a couple of experiments to 'prove' your expectation/recollection. Thereafter there is a far greater likelihood of "learning" - and remembering-correctly 'next time'... The other worthy technique in this field is "deliberate learning". Thus, spending some time studying the docs for the built-ins' functionality (and experimentation) to obviate the need to look-up that level of documentation. Contrary to the learning-practices of 'our day', these days there is a far lower reliance on memory, in favor of rapid-access to reference data, eg the Python docs and REPL's help(), etc. Accordingly, the 'bits' that we might think of as 'minimum knowledge' may be seen as somewhat "arbitrary". (actually it is called Curriculum Design, but given that there is no single application-area for Python there is no single curriculum either) No matter: we are completely correct, no question - and what would 'they' know anyway? PS we were also subject to the idea that intelligence/ability was largely genetic and thus only available in a fixed quantity - either one is 'good' at something, or not (full stop). These days we know ourselves (brains) to be more "plastic", and that with sufficient motivation and effort we can learn 'new stuff', regardless of whether we were 'good at it' yesterday! >> I don't know if you are ComSc student or not, but there isn't even >> consistency at the theoretical level. I first arrived at the concept of >> "queuing" and "dequeuing" (NB the latter is not the same as the Python >> Collections module "deque" library) whilst studying Queue Theory in >> Operations Research. At about the same time, my ComSc studies took me >> into "stacks". > > My student days are well over (about 60 years over). Someone with an even longer beard than mine! We could compare walking sticks... Oh wait, aren't we talking about Python. I'm amazed at how stuff from 'history' is recyclable and becomes applicable to whichever is described as 'today'. Even 'new' things in computing! There's always something new to adapt, if not learn... ... > Yes, but we can still seek consistency where it is possible Trouble is, there are different ways of looking at 'stuff', and thus different dimensions of "consistent". Thus, dict methods try to be consistent to the way a dict behaves. Whereas being 'consistent' with other collections: sets, lists, strings, etc; comes second. Oops if not OOPs! >> Having entered the queue-of-life a long time ago, and shuffling ever >> closer to 'the end of the line', this memory-challenged 'silver-surfer' >> prefers to reserve pop() for straightforward stacks and lists, which >> implies quite enough inconsistency, without trying to convolute my mind >> to pop()-ing dicts, sets (or 'worse'!). I still haven't recalled a single occasion when I've used set.pop() or dict.pop(). Was that because I didn't recall their availability at the right time, or does my mind simply not see that 'consistency' yours recognises? (not that it matters particularly) >> That said, whether I actually use dict.pop() or not, these 'features' >> which are consistent in name but not necessarily in arguments or >> effects, contribute to Python's great flexibility and power! Thank >> goodness for help() and the Python docs... > > I don't like 'pop's at all since it meant that a valve had exploded on > the Ferranti Pegasus that was my first encounter with computers. That does pre-date the prehistoric computers I managed to play-with! There's apparently one in LON's Science Museum. Don't know if it was there when I last visited (c.15 years ago) - I do recall their Babbage implementations and an analog computer (looked like some torture rack) similar to one that my father used way, way, way-back. Similarly, considering it/another similar exhibit and talking with our friends about the 'joys' of using paper tape (and its talent for wrapping itself around anything and everything, except where you wanted it) and those of (assembler) programming delays in order to store data on rotating mag-drums. Those were the days! (or maybe not) -- Regards, =dn From rosuav at gmail.com Wed Jun 16 01:56:26 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 16 Jun 2021 15:56:26 +1000 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: <051401d76259$5b4b9390$11e2bab0$@verizon.net> References: <9d43e9f4-db11-40d4-b5f1-dd581af291ddn@googlegroups.com> <03db01d76244$bd57b920$38072b60$@verizon.net> <051401d76259$5b4b9390$11e2bab0$@verizon.net> Message-ID: On Wed, Jun 16, 2021 at 12:44 PM Avi Gross via Python-list wrote: > > Greg, > > My point was not to ASK what python does as much as to ask why it matters to > anyone which way it does it. Using less space at absolutely no real expense > is generally a plus. Having a compiler work too hard, or even ask the code > to work too hard, is often a minus. > > If I initialized the tuples by calling f(5) and g(5) and so on, the compiler > might not even be easily able to figure out that they all return the same > thing. So should it make a run-time addition to the code so that after > calculating the second, it should look around and if it matches the first, > combine them? Again, I have seen languages where the implementation is to > have exactly one copy of each unique string of characters. That can be > useful but if it is done by creating some data structure and searching > through it even when we have millions of unique strings, ... "some data structure" being, in all probability, a hashtable, so that searching through it is fast :) Python lets you do this via sys.intern(), and CPython automatically does it for any strings that look like identifiers. Your analyses are both correct; but the compiler is generally allowed to work hard, because its work can be dumped out into a file for next time. Consider this code: def make_adder(n): def adder(values): return [v + n for v in values] return adder This has four distinct code blocks (module, make_adder, adder, and the list comp), all of which are represented as immutable code objects, and can be saved into the .pyc file. If the compiler has to do extra work, that's fine! And in fact, it does a LOT of constant folding and other optimizations, based on what it can know about immediately. Everything else (constructing function objects, constructing lists, etc) is done at run time, although sometimes it's worth considering "function definition time" as a separate phase of execution (since, in many Python modules, that all happens at the very start of execution). Optimizations done at that point are potentially more expensive, since they might be done multiple times - imagine calling make_adder in a loop. But since the code object can be used as-is, it's no trouble to keep all the optimizations :) ChrisA From greg.ewing at canterbury.ac.nz Tue Jun 15 21:08:11 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 16 Jun 2021 13:08:11 +1200 Subject: Where did the message go? In-Reply-To: References: <0753f4a8-1f36-5616-6891-b27296292ee1@DancesWithMice.info> Message-ID: On 16/06/21 4:47 am, Chris Angelico wrote: > On Wed, Jun 16, 2021 at 2:41 AM Grimble wrote: > >> was bouncing because haydn.XXXX.XXXX was not a registered subdomain with >> my ISP, whereas bach.XXXX.XXXX was registered. > > I like your naming convention :) Weirdly, the first association "haydn" triggered in my brain was a local company that I have professional dealings with. Only when I read a bit further did I realise it was referring to the composer! -- Greg From jfong at ms4.hinet.net Tue Jun 15 22:07:27 2021 From: jfong at ms4.hinet.net (Jach Feng) Date: Tue, 15 Jun 2021 19:07:27 -0700 (PDT) Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: <9d43e9f4-db11-40d4-b5f1-dd581af291ddn@googlegroups.com> Message-ID: <19087eda-81b7-4f86-9d50-f0da25fb37een@googlegroups.com> Greg Ewing ? 2021?6?16? ?????7:11:35 [UTC+8] ?????? > On 15/06/21 7:32 pm, Jach Feng wrote: > > But usually the list creation is not in simple way:-) for example: > >>>> a = [1,2] > >>>> m = [a for i in range(3)] > >>>> m > > [[1, 2], [1, 2], [1, 2]] > >>>> id(m[0]) == id(m[1]) == id(m[2]) > > True > The first line is only executed once, so you just get one > list object [1, 2]. You then refer to that object three times > when you build the outer list. > > To get three different [1, 2] lists you would need something > like this: > m = [[1,2] for i in range(3)] > This executes the [1, 2] expression 3 times. Because lists are > mutable, you can be sure that this will give you 3 distinct > list objects. > > -- > Greg Yes, I know. Here I just want to show another gutter I had found:-). Anyone else? --Jach From arakelthedragon at gmail.com Wed Jun 16 04:32:38 2021 From: arakelthedragon at gmail.com (Arak Rachael) Date: Wed, 16 Jun 2021 01:32:38 -0700 (PDT) Subject: Help with Python circular error In-Reply-To: References: <477e80fd-131b-4892-bb1d-ac9e984c9035n@googlegroups.com> <940d2f0c-0e79-1003-68ee-7a8981aa2c38@mrabarnett.plus.com> Message-ID: On Tuesday, 15 June 2021 at 19:30:28 UTC+2, Chris Angelico wrote: > On Wed, Jun 16, 2021 at 3:17 AM MRAB wrote: > > > > On 2021-06-15 17:49, Chris Angelico wrote: > > > On Wed, Jun 16, 2021 at 2:45 AM Arak Rachael wrote: > > >> > > >> Hi to everyone, > > >> > > >> I am having a problem with this error, I created a package and uploaded it to Test PyPi, but I can not get it to work, can someone help me please? > > >> > > >> https://test.pypi.org/manage/project/videotesting/releases/' > > >> > > >> The error: > > >> > > >> /home/user/anaconda3/envs/testing/bin/python /home/user/devel/python.assignments/topgis-viz/topgis-test.py > > >> Traceback (most recent call last): > > >> File "/home/user/devel/python.assignments/topgis-viz/topgis-test.py", line 10, in > > >> from videotesting import downsample_and_save_npz > > >> File "/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py", line 7, in > > >> from videotesting import extract_video > > >> ImportError: cannot import name 'extract_video' from partially initialized module 'videotesting' (most likely due to a circular import) (/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py) > > >> > > > > > > Hard to diagnose without the source code, but I'm thinking that your > > > __init__.py is probably trying to import from elsewhere in the > > > package? If so, try "from . import extract_video" instead. > > > > > Well, the traceback says that videotesting/__init__.py has: > > from videotesting import extract_video > > > > so it is trying to import from itself during initialisation. > Yes, but what we can't tell is what the intention is. It could be > trying to import from its own package (in which case my suggestion > would be correct), or it could be trying to import from something > completely different (in which case the solution is to rename > something to avoid the conflict). Or it could be something else > entirely. > > ChrisA Thanks all! I have __init__.py in the create and uploaded package and I have __init_.py in the new package, which is not ready yet. Its 2 projects, but I am using project 1 into project 2. Here is the first package as a .zip https://www.dropbox.com/s/lkz0qf4mq9afpaz/video-testing-package1.zip?dl=0 Here is the second project in which I try to use the first one: https://www.dropbox.com/s/sxjpip23619fven/topgis-viz-package2.zip?dl=0 From arakelthedragon at gmail.com Wed Jun 16 05:23:17 2021 From: arakelthedragon at gmail.com (Arak Rachael) Date: Wed, 16 Jun 2021 02:23:17 -0700 (PDT) Subject: Help with Python circular error In-Reply-To: References: <477e80fd-131b-4892-bb1d-ac9e984c9035n@googlegroups.com> <940d2f0c-0e79-1003-68ee-7a8981aa2c38@mrabarnett.plus.com> Message-ID: <55b7b301-a9f4-462b-af83-4226a2d60b49n@googlegroups.com> On Wednesday, 16 June 2021 at 10:32:50 UTC+2, Arak Rachael wrote: > On Tuesday, 15 June 2021 at 19:30:28 UTC+2, Chris Angelico wrote: > > On Wed, Jun 16, 2021 at 3:17 AM MRAB wrote: > > > > > > On 2021-06-15 17:49, Chris Angelico wrote: > > > > On Wed, Jun 16, 2021 at 2:45 AM Arak Rachael wrote: > > > >> > > > >> Hi to everyone, > > > >> > > > >> I am having a problem with this error, I created a package and uploaded it to Test PyPi, but I can not get it to work, can someone help me please? > > > >> > > > >> https://test.pypi.org/manage/project/videotesting/releases/' > > > >> > > > >> The error: > > > >> > > > >> /home/user/anaconda3/envs/testing/bin/python /home/user/devel/python.assignments/topgis-viz/topgis-test.py > > > >> Traceback (most recent call last): > > > >> File "/home/user/devel/python.assignments/topgis-viz/topgis-test.py", line 10, in > > > >> from videotesting import downsample_and_save_npz > > > >> File "/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py", line 7, in > > > >> from videotesting import extract_video > > > >> ImportError: cannot import name 'extract_video' from partially initialized module 'videotesting' (most likely due to a circular import) (/home/user/anaconda3/envs/testing/lib/python3.8/site-packages/videotesting/__init__.py) > > > >> > > > > > > > > Hard to diagnose without the source code, but I'm thinking that your > > > > __init__.py is probably trying to import from elsewhere in the > > > > package? If so, try "from . import extract_video" instead. > > > > > > > Well, the traceback says that videotesting/__init__.py has: > > > from videotesting import extract_video > > > > > > so it is trying to import from itself during initialisation. > > Yes, but what we can't tell is what the intention is. It could be > > trying to import from its own package (in which case my suggestion > > would be correct), or it could be trying to import from something > > completely different (in which case the solution is to rename > > something to avoid the conflict). Or it could be something else > > entirely. > > > > ChrisA > Thanks all! > > > I have __init__.py in the create and uploaded package and I have __init_.py in the new package, which is not ready yet. Its 2 projects, but I am using project 1 into project 2. > > Here is the first package as a .zip > https://www.dropbox.com/s/lkz0qf4mq9afpaz/video-testing-package1.zip?dl=0 > > Here is the second project in which I try to use the first one: > https://www.dropbox.com/s/sxjpip23619fven/topgis-viz-package2.zip?dl=0 The problems were 2: 1. This has to be in __init__.py: import pipreqs import cv2 import numpy import os import PIL #import videotesting from .videotest import extract_video from .videotest import resize_and_grayscale from .videotest import add_progress_bar from .videotest import downsample_and_save_npz the dots before videotest are critical 2. The module is named videotest as the file videotest.py, not videotesting From pleasedonotsendspam at yahoo.ru Wed Jun 16 06:51:11 2021 From: pleasedonotsendspam at yahoo.ru (Elena) Date: Wed, 16 Jun 2021 10:51:11 +0000 (UTC) Subject: optimization of rule-based model on discrete variables References: Message-ID: Il Wed, 16 Jun 2021 11:37:42 +1200, Greg Ewing ha scritto: > On 15/06/21 10:07 pm, Elena wrote: >> After the optimization, I will use f just to predict new Xi. > > So you're going to use f backwards? > > I don't see how that will work. Where are you going to find a new yi to > feed into the inverse of f? > > I think I don't understand what role g plays in all of this. If the > ultimate goal is to find a better mixture, > you need some kind of figure of merit for an individual mixture. But you > don't have that, you only have this thing g that somehow depends on all > of your mixtures at once. > > I'm still not seeing the big picture. sorry I wrote it wrongly, my bad, I will use f just to predict yi from new coming Xi. From loris.bennett at fu-berlin.de Wed Jun 16 07:41:35 2021 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Wed, 16 Jun 2021 13:41:35 +0200 Subject: SettingWithCopyWarning despite df.loc Message-ID: <87o8c6vxxs.fsf@hornfels.zedat.fu-berlin.de> Hi, I have read a CSV file into a pandas DataFrame. The data contain a column for disk-space usage in KB. To plot the data, I would like to scale the date to, say, GB. What I have is the following: size_unit = "GB" factor = {"GB": 1/(1024*1024)} usage.loc[:, size_unit] = usage.loc[:, 'KB'] usage.loc[:, size_unit] = usage.loc[:, size_unit] * factor[size_unit] This works, but I get the warning: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy self.obj[item] = s I added the .loc stuff after getting the same warning from my naive attempts at copying and modifying an existing column and then trying to understand the information pointed to by the URL. However, I don't see what my example has to do with "chained indexing" and why what I now have is still wrong. Can anyone illuminate me? Cheers, Loris -- This signature is currently under construction. From rshepard at appl-ecosys.com Wed Jun 16 12:31:29 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Jun 2021 09:31:29 -0700 (PDT) Subject: tkinter: tksheet Message-ID: Reading the doc for tksheet tells me that it allows me to modify cells (or entire rows) as well as display them. What I don't see is whether I can add a new row using tksheet and change the column used for sorting (e.g., sorting by company number or company name). If you have experience with tksheet perhaps you can answer my questions about it's capabilities. Rich From dieter at handshake.de Wed Jun 16 12:32:46 2021 From: dieter at handshake.de (Dieter Maurer) Date: Wed, 16 Jun 2021 18:32:46 +0200 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: References: <24776.25986.205672.813043@ixdm.fritz.box> <24776.53976.739836.800023@ixdm.fritz.box> Message-ID: <24778.10158.27247.212907@ixdm.fritz.box> Chris Angelico wrote at 2021-6-16 02:20 +1000: >On Wed, Jun 16, 2021 at 2:18 AM Dieter Maurer wrote: >> As far as I know, there are no guarantees are the language level. >> There are some (partially documented) implementation details >> for CPython (which is just one possible implementation). > >Yes there are - plenty of them :) The example I gave is a language >guarantee. Would you point to the documentation location where this is guaranteed? -- Dieter From rosuav at gmail.com Wed Jun 16 15:34:04 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Jun 2021 05:34:04 +1000 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: <24778.10158.27247.212907@ixdm.fritz.box> References: <24776.25986.205672.813043@ixdm.fritz.box> <24776.53976.739836.800023@ixdm.fritz.box> <24778.10158.27247.212907@ixdm.fritz.box> Message-ID: On Thu, Jun 17, 2021 at 2:32 AM Dieter Maurer wrote: > > Chris Angelico wrote at 2021-6-16 02:20 +1000: > >On Wed, Jun 16, 2021 at 2:18 AM Dieter Maurer wrote: > >> As far as I know, there are no guarantees are the language level. > >> There are some (partially documented) implementation details > >> for CPython (which is just one possible implementation). > > > >Yes there are - plenty of them :) The example I gave is a language > >guarantee. > > Would you point to the documentation location where this is guaranteed? > Probably somewhere in the tutorial where object identity is explained? Not sure. It's pretty fundamental. ChrisA From greg.ewing at canterbury.ac.nz Wed Jun 16 09:55:55 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 17 Jun 2021 01:55:55 +1200 Subject: optimization of rule-based model on discrete variables In-Reply-To: References: Message-ID: On 16/06/21 10:51 pm, Elena wrote: > sorry I wrote it wrongly, my bad, I will use f just to predict yi from new > coming Xi. Then what do you do with the new yi? -- Greg From arakelthedragon at gmail.com Wed Jun 16 11:25:12 2021 From: arakelthedragon at gmail.com (Arak Rachael) Date: Wed, 16 Jun 2021 08:25:12 -0700 (PDT) Subject: How to check if an image contains an element I am searchig for Message-ID: <96a5ea4e-0325-4746-a7fa-e65be301e041n@googlegroups.com> Hi guys, I have an image from google maps to say and I need to check if it has road markings, in order to do that, I believe I need to change the effects on the image so the markings and road can be white or something and the things I don't need like cars, trees and so on to be black. images should contain only road surface and/or road markings (lines, zebras, stripes. Can anyone help me on this, I already have the crop code, I just need to check if the cropped part contains what I need. From tjreedy at udel.edu Wed Jun 16 14:01:35 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 16 Jun 2021 14:01:35 -0400 Subject: tkinter: tksheet In-Reply-To: References: Message-ID: On 6/16/2021 12:31 PM, Rich Shepard wrote: > Reading the doc for tksheet tells me that it allows me to modify cells (or > entire rows) as well as display them. What I don't see is whether I can add > a new row using tksheet Somewhat sparse doc at https://github.com/ragardner/tksheet/blob/master/DOCUMENTATION.md#5-modifying-table-data insert_row() and change the column used for sorting (e.g., > sorting by company number or company name). I did not see anything about sorting. tksheet is generic 'table', not a database viewer -- Terry Jan Reedy From roel at roelschroeven.net Wed Jun 16 14:49:16 2021 From: roel at roelschroeven.net (Roel Schroeven) Date: Wed, 16 Jun 2021 20:49:16 +0200 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: <24778.10158.27247.212907@ixdm.fritz.box> References: <24776.25986.205672.813043@ixdm.fritz.box> <24776.53976.739836.800023@ixdm.fritz.box> <24778.10158.27247.212907@ixdm.fritz.box> Message-ID: Dieter Maurer schreef op 16/06/2021 om 18:32: > Chris Angelico wrote at 2021-6-16 02:20 +1000: >> On Wed, Jun 16, 2021 at 2:18 AM Dieter Maurer wrote: >>> As far as I know, there are no guarantees are the language level. >>> There are some (partially documented) implementation details >>> for CPython (which is just one possible implementation). >> >> Yes there are - plenty of them :) The example I gave is a language >> guarantee. > > Would you point to the documentation location where this is guaranteed? I lost track of which exact guarantee we're discussing here. In any case, the documentation for the id() function ([1]) says: "This is an integer which is guaranteed to be unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value. CPython implementation detail: This is the address of the object in memory." Does that answer your doubts? [1] https://docs.python.org/3.8/library/functions.html?highlight=id#id -- "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 Wed Jun 16 16:07:59 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Jun 2021 06:07:59 +1000 Subject: How to check if an image contains an element I am searchig for In-Reply-To: <96a5ea4e-0325-4746-a7fa-e65be301e041n@googlegroups.com> References: <96a5ea4e-0325-4746-a7fa-e65be301e041n@googlegroups.com> Message-ID: On Thu, Jun 17, 2021 at 6:06 AM Arak Rachael wrote: > > Hi guys, > > I have an image from google maps to say and I need to check if it has road markings, in order to do that, I believe I need to change the effects on the image so the markings and road can be white or something and the things I don't need like cars, trees and so on to be black. > > images should contain only road surface and/or road markings (lines, zebras, stripes. > > Can anyone help me on this, I already have the crop code, I just need to check if the cropped part contains what I need. How well can you define the things you're looking for? https://xkcd.com/1425/ ChrisA From arakelthedragon at gmail.com Wed Jun 16 16:18:54 2021 From: arakelthedragon at gmail.com (Arak Rachael) Date: Wed, 16 Jun 2021 13:18:54 -0700 (PDT) Subject: How to check if an image contains an element I am searchig for In-Reply-To: References: <96a5ea4e-0325-4746-a7fa-e65be301e041n@googlegroups.com> Message-ID: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> On Wednesday, 16 June 2021 at 22:08:31 UTC+2, Chris Angelico wrote: > On Thu, Jun 17, 2021 at 6:06 AM Arak Rachael wrote: > > > > Hi guys, > > > > I have an image from google maps to say and I need to check if it has road markings, in order to do that, I believe I need to change the effects on the image so the markings and road can be white or something and the things I don't need like cars, trees and so on to be black. > > > > images should contain only road surface and/or road markings (lines, zebras, stripes. > > > > Can anyone help me on this, I already have the crop code, I just need to check if the cropped part contains what I need. > How well can you define the things you're looking for? > > https://xkcd.com/1425/ > > ChrisA Hi Chris, what do you mean? Here is the image, I need to separate the road and markings from the rest and divide the image into squares of 100x100 pixels, for each square I need to check if it contains a road and markings: https://www.dropbox.com/s/iduxj0j8w0ic616/SatelliteProcessing_Image.png?dl=0 From rshepard at appl-ecosys.com Wed Jun 16 16:45:50 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Jun 2021 13:45:50 -0700 (PDT) Subject: tkinter: tksheet In-Reply-To: References: Message-ID: On Wed, 16 Jun 2021, Terry Reedy wrote: > Somewhat sparse doc at > https://github.com/ragardner/tksheet/blob/master/DOCUMENTATION.md#5-modifying-table-data > insert_row() Terry, I'm reading this now and saw that. > and change the column used for sorting (e.g., >> sorting by company number or company name). > > I did not see anything about sorting. tksheet is generic 'table', not a > database viewer The two applications I'm building are both database applications. If tksheet() is not the most appropriate widget to display database tables what alternative would be better? Thanks, Rich From rosuav at gmail.com Wed Jun 16 16:56:56 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Jun 2021 06:56:56 +1000 Subject: How to check if an image contains an element I am searchig for In-Reply-To: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> References: <96a5ea4e-0325-4746-a7fa-e65be301e041n@googlegroups.com> <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> Message-ID: On Thu, Jun 17, 2021 at 6:44 AM Arak Rachael wrote: > > On Wednesday, 16 June 2021 at 22:08:31 UTC+2, Chris Angelico wrote: > > On Thu, Jun 17, 2021 at 6:06 AM Arak Rachael wrote: > > > > > > Hi guys, > > > > > > I have an image from google maps to say and I need to check if it has road markings, in order to do that, I believe I need to change the effects on the image so the markings and road can be white or something and the things I don't need like cars, trees and so on to be black. > > > > > > images should contain only road surface and/or road markings (lines, zebras, stripes. > > > > > > Can anyone help me on this, I already have the crop code, I just need to check if the cropped part contains what I need. > > How well can you define the things you're looking for? > > > > https://xkcd.com/1425/ > > > > ChrisA > Hi Chris, > > what do you mean? > > Here is the image, I need to separate the road and markings from the rest and divide the image into squares of 100x100 pixels, for each square I need to check if it contains a road and markings: > > https://www.dropbox.com/s/iduxj0j8w0ic616/SatelliteProcessing_Image.png?dl=0 > How will a program know if something contains a road? Are you trying to solve captchas? ChrisA From barry at barrys-emacs.org Wed Jun 16 17:03:26 2021 From: barry at barrys-emacs.org (Barry) Date: Wed, 16 Jun 2021 22:03:26 +0100 Subject: How to check if an image contains an element I am searchig for In-Reply-To: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> References: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> Message-ID: <0804AD1B-CD65-4468-9447-7B5C0A5CB9FE@barrys-emacs.org> > On 16 Jun 2021, at 21:46, Arak Rachael wrote: > > ?On Wednesday, 16 June 2021 at 22:08:31 UTC+2, Chris Angelico wrote: >>> On Thu, Jun 17, 2021 at 6:06 AM Arak Rachael wrote: >>> >>> Hi guys, >>> >>> I have an image from google maps to say and I need to check if it has road markings, in order to do that, I believe I need to change the effects on the image so the markings and road can be white or something and the things I don't need like cars, trees and so on to be black. >>> >>> images should contain only road surface and/or road markings (lines, zebras, stripes. >>> >>> Can anyone help me on this, I already have the crop code, I just need to check if the cropped part contains what I need. >> How well can you define the things you're looking for? >> >> https://xkcd.com/1425/ >> >> ChrisA > Hi Chris, > > what do you mean? He means that image processing is a hard problem that requires expertise to solve. > > Here is the image, I need to separate the road and markings from the rest and divide the image into squares of 100x100 pixels, for each square I need to check if it contains a road and markings: Can you define road in terms of an algorithm that looks at the pixels? > > https://www.dropbox.com/s/iduxj0j8w0ic616/SatelliteProcessing_Image.png?dl=0 > > -- > https://mail.python.org/mailman/listinfo/python-list > From hjp-python at hjp.at Wed Jun 16 17:11:07 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Wed, 16 Jun 2021 23:11:07 +0200 Subject: Why the list creates in two different ways? Does it cause by the mutability of its elements? Where the Python document explains it? In-Reply-To: <24778.10158.27247.212907@ixdm.fritz.box> References: <24776.25986.205672.813043@ixdm.fritz.box> <24776.53976.739836.800023@ixdm.fritz.box> <24778.10158.27247.212907@ixdm.fritz.box> Message-ID: <20210616211107.GA31701@hjp.at> On 2021-06-16 18:32:46 +0200, Dieter Maurer wrote: > Chris Angelico wrote at 2021-6-16 02:20 +1000: > >On Wed, Jun 16, 2021 at 2:18 AM Dieter Maurer wrote: > >> As far as I know, there are no guarantees are the language level. > >> There are some (partially documented) implementation details > >> for CPython (which is just one possible implementation). > > > >Yes there are - plenty of them :) The example I gave is a language > >guarantee. > > Would you point to the documentation location where this is guaranteed? I think it's in https://docs.python.org/3/reference/expressions.html#atom-identifiers | When the name is bound to an object, evaluation of the atom yields that object. So in x = whatever a_list = [x for _ in range(3)] you get a list of 3 references to the same object, not 3 references to 3 different copies of that object. 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 rosuav at gmail.com Wed Jun 16 17:29:38 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Jun 2021 07:29:38 +1000 Subject: How to check if an image contains an element I am searchig for In-Reply-To: References: <96a5ea4e-0325-4746-a7fa-e65be301e041n@googlegroups.com> Message-ID: On Thu, Jun 17, 2021 at 7:25 AM Dennis Lee Bieber wrote: > > On Thu, 17 Jun 2021 06:07:59 +1000, Chris Angelico > declaimed the following: > > > >How well can you define the things you're looking for? > > > >https://xkcd.com/1425/ > > Non sequitur comment -- Sounds like a potential usage of a BeagleBone > AI with the TI Deep Learning modules... though I don't think they've > documented how to go from the example learning images to teaching it to > recognize birds Yeah. We have the tools for high-grade AI now, but.... ultimately, teaching an AI to recognize birds requires someone spending quite a few hours going through photos of birds and drawing boxes around them. "That's a bird. That's a bird. That's a bird. That's not a bird, it's a plane. That's a bird. That's a bird. That's not a bird, it's Superman." > Won't help the OP unless it can be taught to recognize vehicles and > somehow provide coordinates to let the OP "blank out" said vehicles. > > Edge detection might provide some hints -- but simple "same color > pixels" won't -- as the roads may have different colors (concrete vs > asphalt vs gravel vs dirt -- and then you get asphalt/tar patches applied > to pot-holes and cracks in concrete). Also, as in that photo, many of the > vehicles are near enough to the road color that any range used to ensure > picking up variations in the road will pick up the vehicles. > Yup. Image processing is hard. Having seen what people can do with various tools, I can only conclude that (a) the tools are magic, and (b) the job is STILL a big one, even with magical tools. ChrisA From drsalists at gmail.com Wed Jun 16 17:34:08 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 16 Jun 2021 14:34:08 -0700 Subject: How to check if an image contains an element I am searchig for In-Reply-To: <0804AD1B-CD65-4468-9447-7B5C0A5CB9FE@barrys-emacs.org> References: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> <0804AD1B-CD65-4468-9447-7B5C0A5CB9FE@barrys-emacs.org> Message-ID: On Wed, Jun 16, 2021 at 2:04 PM Barry wrote: > >>> On Thu, Jun 17, 2021 at 6:06 AM Arak Rachael > wrote: > >>> > >>> Hi guys, > >>> > >>> I have an image from google maps to say and I need to check if it has > road markings, in order to do that, I believe I need to change the effects > on the image so the markings and road can be white or something and the > things I don't need like cars, trees and so on to be black. > >>> > >>> images should contain only road surface and/or road markings (lines, > zebras, stripes. > >>> > >>> Can anyone help me on this, I already have the crop code, I just need > to check if the cropped part contains what I need. > >> How well can you define the things you're looking for? > >> > >> https://xkcd.com/1425/ > >> > >> ChrisA > > Hi Chris, > > > > what do you mean? > > He means that image processing is a hard problem that requires expertise > to solve. > > > > > Here is the image, I need to separate the road and markings from the > rest and divide the image into squares of 100x100 pixels, for each square I > need to check if it contains a road and markings: > > Can you define road in terms of an algorithm that looks at the pixels? > I think that XKCD may be a little out of date. You could probably train a Deep Learning model to do this, if you have enough prelabeled data with enough variation. And of course dividing a picture up into 100x100 squares is pretty easy if you convert to ppm. Perhaps Pillow can do this too. HTH. From rosuav at gmail.com Wed Jun 16 17:43:30 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Jun 2021 07:43:30 +1000 Subject: How to check if an image contains an element I am searchig for In-Reply-To: References: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> <0804AD1B-CD65-4468-9447-7B5C0A5CB9FE@barrys-emacs.org> Message-ID: On Thu, Jun 17, 2021 at 7:35 AM Dan Stromberg wrote: > > On Wed, Jun 16, 2021 at 2:04 PM Barry wrote: > > > >>> On Thu, Jun 17, 2021 at 6:06 AM Arak Rachael > > wrote: > > >>> > > >>> Hi guys, > > >>> > > >>> I have an image from google maps to say and I need to check if it has > > road markings, in order to do that, I believe I need to change the effects > > on the image so the markings and road can be white or something and the > > things I don't need like cars, trees and so on to be black. > > >>> > > >>> images should contain only road surface and/or road markings (lines, > > zebras, stripes. > > >>> > > >>> Can anyone help me on this, I already have the crop code, I just need > > to check if the cropped part contains what I need. > > >> How well can you define the things you're looking for? > > >> > > >> https://xkcd.com/1425/ > > >> > > >> ChrisA > > > Hi Chris, > > > > > > what do you mean? > > > > He means that image processing is a hard problem that requires expertise > > to solve. > > > > > > > > Here is the image, I need to separate the road and markings from the > > rest and divide the image into squares of 100x100 pixels, for each square I > > need to check if it contains a road and markings: > > > > Can you define road in terms of an algorithm that looks at the pixels? > > > > I think that XKCD may be a little out of date. It's not out of date. The task still requires a lot of effort - it's just that the effort is now "preparing a suitable corpus" rather than "figuring out how on earth to do this". Even with all the tools at our disposal, there's still a stark (and often surprising) distinction between the easy and the hard. For instance, calculating square roots is pretty hard to do by hand, but computers don't have any trouble with that. But "what's that song about blah blah blah" is incredibly difficult, and if you try to write your own tool to do that (rather than doing what most people would do, and type something into a search engine!), you'll find that it's far easier to just give the job to a human. > You could probably train a Deep Learning model to do this, if you have > enough prelabeled data with enough variation. That is, in fact, the exact difficulty. > And of course dividing a picture up into 100x100 squares is pretty easy if > you convert to ppm. Perhaps Pillow can do this too. Sure, but that's the trivially easy part. And probably not even all that helpful in the scheme of things. ChrisA From PythonList at DancesWithMice.info Wed Jun 16 17:48:41 2021 From: PythonList at DancesWithMice.info (dn) Date: Thu, 17 Jun 2021 09:48:41 +1200 Subject: tkinter: tksheet In-Reply-To: References: Message-ID: On 17/06/2021 08.45, Rich Shepard wrote: > On Wed, 16 Jun 2021, Terry Reedy wrote: > >> Somewhat sparse doc at >> https://github.com/ragardner/tksheet/blob/master/DOCUMENTATION.md#5-modifying-table-data >> >> insert_row() > > Terry, > > I'm reading this now and saw that. > >> and change the column used for sorting (e.g., >>> sorting by company number or company name). >> >> I did not see anything about sorting.? tksheet is generic 'table', not >> a database viewer > > The two applications I'm building are both database applications. If > tksheet() is not the most appropriate widget to display database tables > what > alternative would be better? Use the DBMS by retrieving the data in the desired sequence? -- Regards, =dn From alan.gauld at yahoo.co.uk Wed Jun 16 18:24:32 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 16 Jun 2021 23:24:32 +0100 Subject: tkinter: tksheet In-Reply-To: References: Message-ID: On 16/06/2021 21:45, Rich Shepard wrote: > The two applications I'm building are both database applications. If > tksheet() is not the most appropriate widget to display database tables what > alternative would be better? I've not used tksheet but it sounds like it might be worth investigating. There is a grid in Tix but its quite hard to use and Tix is now deprecated. It was also a bit unreliable when used from Python (that's euphemistic for "I couldn't get it to work!" :-) But there is nothing I know of for Tkinter that provides views of database tables in the way that Delphi or VB or C# do, for example. You have to extract the data using SQL and populate the table and manage all changes (of both view and data) yourself. A good grid component would be a huge boon for tkinter, its one of the most commonly used widgets in VB/Delphi etc A DB-API linked grid would be the height of luxury... If you do a lot of that kind of desktop apps then you could look at Dabo which is built on wxPython but has links to databases. Unfortunately it looks like work ground to a halt about 5 years ago. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From rshepard at appl-ecosys.com Wed Jun 16 19:06:54 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Jun 2021 16:06:54 -0700 (PDT) Subject: tkinter: tksheet In-Reply-To: References: Message-ID: On Wed, 16 Jun 2021, Dennis Lee Bieber wrote: > Scroll further down to "bindings"... rc_insert_row -- a > menu binding Dennis, Yes, I saw that one, too. > As for sorting, I don't see anything that allows one to add custom > events to the bindings... best I can come up with is that if a header > column is selected you sort the data and reload the table. My naive idea is to use two queries, one selects * from the company table ordered by nunber, the other by name. The UI offers two radiobuttons when viewing the results, one for each sort column. Thanks, Rich From rshepard at appl-ecosys.com Wed Jun 16 19:08:09 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Jun 2021 16:08:09 -0700 (PDT) Subject: tkinter: tksheet In-Reply-To: References: Message-ID: On Thu, 17 Jun 2021, dn via Python-list wrote: > Use the DBMS by retrieving the data in the desired sequence? dn, Yep. That's what I thought would be the best approach. Thanks, Rich From rshepard at appl-ecosys.com Wed Jun 16 19:15:42 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 16 Jun 2021 16:15:42 -0700 (PDT) Subject: tkinter: tksheet In-Reply-To: References: Message-ID: On Wed, 16 Jun 2021, Alan Gauld via Python-list wrote: > But there is nothing I know of for Tkinter that provides views of database > tables in the way that Delphi or VB or C# do, for example. Alan, These are all Microsoft tools. I run linux only. > You have to extract the data using SQL and populate the table and manage > all changes (of both view and data) yourself. >From an incomplete reading of the tksheet() doc it looks to be the best way to display tables returned by a SQL query. PyQt5 has a QTableView() that does the job, and it works great for a single table, but apparently not so well with complex joins on multiple tables. When I view my contacts table it needs to includes attributes from the company, people, and contacts tables so I can view all prior contacts with that person. > If you do a lot of that kind of desktop apps then you could look at Dabo > which is built on wxPython but has links to databases. Unfortunately it > looks like work ground to a halt about 5 years ago. Many years ago I used wxPython. For several reasons I decided to learn and use tkinter from now one. One reason is that the application for my clients will run mostly on windows hosts and I want to limit the software they need to install and maintain in order to run it. Regards, Rich From arakelthedragon at gmail.com Wed Jun 16 18:51:49 2021 From: arakelthedragon at gmail.com (Arak Rachael) Date: Wed, 16 Jun 2021 15:51:49 -0700 (PDT) Subject: How to check if an image contains an element I am searchig for In-Reply-To: References: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> <0804AD1B-CD65-4468-9447-7B5C0A5CB9FE@barrys-emacs.org> Message-ID: <523d6c24-5230-4421-86dc-121376820800n@googlegroups.com> On Wednesday, 16 June 2021 at 23:44:02 UTC+2, Chris Angelico wrote: > On Thu, Jun 17, 2021 at 7:35 AM Dan Stromberg wrote: > > > > On Wed, Jun 16, 2021 at 2:04 PM Barry wrote: > > > > > >>> On Thu, Jun 17, 2021 at 6:06 AM Arak Rachael > > > wrote: > > > >>> > > > >>> Hi guys, > > > >>> > > > >>> I have an image from google maps to say and I need to check if it has > > > road markings, in order to do that, I believe I need to change the effects > > > on the image so the markings and road can be white or something and the > > > things I don't need like cars, trees and so on to be black. > > > >>> > > > >>> images should contain only road surface and/or road markings (lines, > > > zebras, stripes. > > > >>> > > > >>> Can anyone help me on this, I already have the crop code, I just need > > > to check if the cropped part contains what I need. > > > >> How well can you define the things you're looking for? > > > >> > > > >> https://xkcd.com/1425/ > > > >> > > > >> ChrisA > > > > Hi Chris, > > > > > > > > what do you mean? > > > > > > He means that image processing is a hard problem that requires expertise > > > to solve. > > > > > > > > > > > Here is the image, I need to separate the road and markings from the > > > rest and divide the image into squares of 100x100 pixels, for each square I > > > need to check if it contains a road and markings: > > > > > > Can you define road in terms of an algorithm that looks at the pixels? > > > > > > > I think that XKCD may be a little out of date. > It's not out of date. The task still requires a lot of effort - it's > just that the effort is now "preparing a suitable corpus" rather than > "figuring out how on earth to do this". Even with all the tools at our > disposal, there's still a stark (and often surprising) distinction > between the easy and the hard. > > For instance, calculating square roots is pretty hard to do by hand, > but computers don't have any trouble with that. But "what's that song > about blah blah blah" is incredibly difficult, and if you try to write > your own tool to do that (rather than doing what most people would do, > and type something into a search engine!), you'll find that it's far > easier to just give the job to a human. > > You could probably train a Deep Learning model to do this, if you have > > enough prelabeled data with enough variation. > That is, in fact, the exact difficulty. > > And of course dividing a picture up into 100x100 squares is pretty easy if > > you convert to ppm. Perhaps Pillow can do this too. > Sure, but that's the trivially easy part. And probably not even all > that helpful in the scheme of things. > > ChrisA I understand your concerns. Actually I am doing image processing of satellite pictures for smart cars. I have been given the option to use InfranView and do it manually or create a Python script. From cs at cskk.id.au Wed Jun 16 20:49:36 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 17 Jun 2021 10:49:36 +1000 Subject: How to check if an image contains an element I am searchig for In-Reply-To: <523d6c24-5230-4421-86dc-121376820800n@googlegroups.com> References: <523d6c24-5230-4421-86dc-121376820800n@googlegroups.com> Message-ID: On 16Jun2021 15:51, Arak Rachael wrote: >I understand your concerns. Actually I am doing image processing of >satellite pictures for smart cars. I have been given the option to use >InfranView and do it manually or create a Python script. If you need to slice images into 100x100 pixels squares, the Pillow module should make that easy. Just looking at InfranView here: https://www.irfanview.com/main_what_is_engl.htm I imagine it can do the same - there's some reference to a batch mode but I have no idea what it can do. Or a shell script using GraphicswMagick or ImageMagick. The hard part is the image classification: does this imagine contain a pedestrian crossing, etc etc etc? Unless InfranView has some outstanding image processing plugin with access to a precatalogued corpus of images I'd be surprised if it will help. This doesn't solve your problem, but it feels like you think there are easy ways to look at a small chunk of an image and analyse its content for high level features. Smart cars need that for hazard recognition etc if they use cameras (eg Teslas, which I believe want to eschew LIDAR for cameras). What little I know of the field says that these things are not easily done. Camera data are full of noise, not geommetricaly aligned with what you're looking for (stripes and various angles, for example), will only have a portion of the feature in view (particularly after cropping into little squares), varying lighting, varying feature colours, people wearing stripey shirts. So an AI approach relies not on semantic knowledge of how things are constructed (rectangular stripes of paint on a raod surface or whatever) but on training a neural net style learner to correlate image measures with categories, in the hope that those measures (and their combinations/correlations) will recognise other objects in the same categories correctly after being fed sufficient images (all correctly precategorised of course). Can you outline how you'd like the Python side to work? It sounds likee you have a batch of images to: - crop into tiles of a particular size (maybe to constraint the compute used per tile) - recognise features in each tile The first part is easily done in Python. The second part is _hard_. Cheers, Cameron Simpson From drsalists at gmail.com Thu Jun 17 02:43:12 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 16 Jun 2021 23:43:12 -0700 Subject: How to check if an image contains an element I am searchig for In-Reply-To: References: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> <0804AD1B-CD65-4468-9447-7B5C0A5CB9FE@barrys-emacs.org> Message-ID: On Wed, Jun 16, 2021 at 2:44 PM Chris Angelico wrote: > On Thu, Jun 17, 2021 at 7:35 AM Dan Stromberg wrote: > > > >> How well can you define the things you're looking for? > > > >> > > > >> https://xkcd.com/1425/ > > > >> > > > > He means that image processing is a hard problem that requires > expertise > > > to solve. > > > > > > > > > > > Here is the image, I need to separate the road and markings from the > > > rest and divide the image into squares of 100x100 pixels, for each > square I > > > need to check if it contains a road and markings: > > > > > > Can you define road in terms of an algorithm that looks at the pixels? > > > > > > > I think that XKCD may be a little out of date. > > It's not out of date. The task still requires a lot of effort - it's > just that the effort is now "preparing a suitable corpus" rather than > "figuring out how on earth to do this". Even with all the tools at our > disposal, there's still a stark (and often surprising) distinction > between the easy and the hard. > Well... Are you sure? It's no longer a problem that requires 5 years and a research team. It's now a problem that requires hunting for relevant labeled data, and failing that, paying a small team of unskilled laborers minimum wage to classify images from google images or similar. Plus some programming to create the model and to use it in production. Deep Learning is catching on, in significant part, because lots of useful data is becoming available. Also because hardware is getting faster and the algorithms have improved. Clearly some things are harder than others, but the "hard" example given in the XKCD is no longer really a good example. From rosuav at gmail.com Thu Jun 17 02:49:40 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 17 Jun 2021 16:49:40 +1000 Subject: How to check if an image contains an element I am searchig for In-Reply-To: References: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> <0804AD1B-CD65-4468-9447-7B5C0A5CB9FE@barrys-emacs.org> Message-ID: On Thu, Jun 17, 2021 at 4:43 PM Dan Stromberg wrote: > > > > On Wed, Jun 16, 2021 at 2:44 PM Chris Angelico wrote: >> >> On Thu, Jun 17, 2021 at 7:35 AM Dan Stromberg wrote: >> > > >> How well can you define the things you're looking for? >> > > >> >> > > >> https://xkcd.com/1425/ >> > > >> >> >> > > He means that image processing is a hard problem that requires expertise >> > > to solve. >> > > >> > > > >> > > > Here is the image, I need to separate the road and markings from the >> > > rest and divide the image into squares of 100x100 pixels, for each square I >> > > need to check if it contains a road and markings: >> > > >> > > Can you define road in terms of an algorithm that looks at the pixels? >> > > >> > >> > I think that XKCD may be a little out of date. >> >> It's not out of date. The task still requires a lot of effort - it's >> just that the effort is now "preparing a suitable corpus" rather than >> "figuring out how on earth to do this". Even with all the tools at our >> disposal, there's still a stark (and often surprising) distinction >> between the easy and the hard. > > > Well... Are you sure? > > It's no longer a problem that requires 5 years and a research team. That's because the research years have been done for that particular case. > It's now a problem that requires hunting for relevant labeled data, and failing that, paying a small team of unskilled laborers minimum wage to classify images from google images or similar. Plus some programming to create the model and to use it in production. > > Deep Learning is catching on, in significant part, because lots of useful data is becoming available. Also because hardware is getting faster and the algorithms have improved. > > Clearly some things are harder than others, but the "hard" example given in the XKCD is no longer really a good example. > I don't think it's a bad example. We needed hindsight to be able to figure that out - see the hover text. And it's still much MUCH harder to say "is this thing in this person's hand a gun?" than to say "is this light on?". But as we've seen from all the various voice-command assistants, the difficulty of doing a good job doesn't stop people from doing a bad job... "Close Spotify." // "Okay. Opening Spotify." ChrisA From hjp-python at hjp.at Thu Jun 17 02:52:36 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Thu, 17 Jun 2021 08:52:36 +0200 Subject: How to check if an image contains an element I am searchig for In-Reply-To: <523d6c24-5230-4421-86dc-121376820800n@googlegroups.com> References: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> <0804AD1B-CD65-4468-9447-7B5C0A5CB9FE@barrys-emacs.org> <523d6c24-5230-4421-86dc-121376820800n@googlegroups.com> Message-ID: <20210617065236.GA20630@hjp.at> On 2021-06-16 15:51:49 -0700, Arak Rachael wrote: > On Wednesday, 16 June 2021 at 23:44:02 UTC+2, Chris Angelico wrote: > > On Thu, Jun 17, 2021 at 7:35 AM Dan Stromberg wrote: > > > > > > On Wed, Jun 16, 2021 at 2:04 PM Barry wrote: > > > > > > > >>> On Thu, Jun 17, 2021 at 6:06 AM Arak Rachael > > > > wrote: > > > > >>> I have an image from google maps to say and I need to check if it has > > > > road markings, in order to do that, I believe I need to change the effects > > > > on the image so the markings and road can be white or something and the > > > > things I don't need like cars, trees and so on to be black. [...] > I understand your concerns. Actually I am doing image processing of > satellite pictures for smart cars. Using satellite images probably makes that a lot easier (yes, you wrote "Google maps", but for some reason I thought of Google Street View). At least you have a consistent angle (almost from straight above) and know the scale (given the zoom factor and the latitude). 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 arakelthedragon at gmail.com Thu Jun 17 03:59:37 2021 From: arakelthedragon at gmail.com (Arak Rachael) Date: Thu, 17 Jun 2021 00:59:37 -0700 (PDT) Subject: How to check if an image contains an element I am searchig for In-Reply-To: References: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> <0804AD1B-CD65-4468-9447-7B5C0A5CB9FE@barrys-emacs.org> <20210617065236.GA20630@hjp.at> <523d6c24-5230-4421-86dc-121376820800n@googlegroups.com> Message-ID: <015dba6c-0c11-4a1d-84a2-9c199fef4fa6n@googlegroups.com> On Thursday, 17 June 2021 at 08:52:55 UTC+2, Peter J. Holzer wrote: > On 2021-06-16 15:51:49 -0700, Arak Rachael wrote: > > On Wednesday, 16 June 2021 at 23:44:02 UTC+2, Chris Angelico wrote: > > > On Thu, Jun 17, 2021 at 7:35 AM Dan Stromberg wrote: > > > > > > > > On Wed, Jun 16, 2021 at 2:04 PM Barry wrote: > > > > > > > > > >>> On Thu, Jun 17, 2021 at 6:06 AM Arak Rachael > > > > > wrote: > > > > > >>> I have an image from google maps to say and I need to check if it has > > > > > road markings, in order to do that, I believe I need to change the effects > > > > > on the image so the markings and road can be white or something and the > > > > > things I don't need like cars, trees and so on to be black. > [...] > > I understand your concerns. Actually I am doing image processing of > > satellite pictures for smart cars. > Using satellite images probably makes that a lot easier (yes, you wrote > "Google maps", but for some reason I thought of Google Street View). At > least you have a consistent angle (almost from straight above) and know > the scale (given the zoom factor and the latitude). > > hp > > -- > _ | Peter J. Holzer | Story must make more sense than reality. > |_|_) | | > | | | h... at hjp.at | -- Charles Stross, "Creative writing > __/ | http://www.hjp.at/ | challenge!" I made the crop code, before I posted the question, I just need the identification part: [code] # Library includes import os import cv2 # image and other special formats processing library # for computer vision import numpy as np from numpy import asarray import PIL from PIL import Image # Global variables # Recommended: move to a separate file # Recommended approach instead of using the "target" # name directly source_directory = "test" # Do not put a slash at the beginning output_directory = "test2" # Do not put a slash at the beginning # Function definitions def image_contains_required_elements(image): # Description: # The function will check if the cropped image contains the # required elements of the road(markings, road and others) # Local variables and initialization raise Exception("Not implemented yet") def split_image(path, dstpath): # Description: # Convert the generated frames(images) from # extract_video(video_path, target_dir_path) to grayscale # and reduce their size to half # Local variables and initialization # Requires the libraries: # import cv2 # import os # import pytest # import numpy as np # Processing # Reading an image in default mode #path = r'/home/yordan/devel/python.assignments/topgis-viz.2/data' # Source Folder #dstpath = r'/home/yordan/devel/python.assignments/topgis-viz.2/output_directory' # Destination Folder #path = source_directory # source_directory containing the images before the processing #dstpath = output_directory # output_directory containing the images after the processing """ # Test if target_directory exists try: # Try makedirs(dstpath) # to create target_directory except: # if there is an error print("Directory already exist, images will be written in same folder") # print the error message """ files = os.listdir(path) # Read the files from source_directory and record them in a list for image in files: # For index in list img = cv2.imread(os.path.join(path, image)) # Read the image from path + image name as an array into img # Split image into b, g ,r function gray = img #b, g, r = cv2.split(gray) # Split the image into BGR channels #print(b, g, r) # print the b, g, r channels(codes) crop_img = gray[100:100 + 100, 100:100 + 100] # Crop the image with numpy, x and y are flipped, # example crop_img = img[margin:-margin, margin:-margin] if image_contains_required_elements(crop_img) == True: cv2.imwrite(os.path.join(dstpath, image), crop_img) # Write the image crop_img to a file with name # target_directory + image name # Displaying the image #cv2.imshow("Test", crop_img) # Show the image split_image(source_directory, output_directory) [code] From alan.gauld at yahoo.co.uk Thu Jun 17 04:34:49 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 17 Jun 2021 09:34:49 +0100 Subject: tkinter: tksheet In-Reply-To: References: Message-ID: On 17/06/2021 00:15, Rich Shepard wrote: > When I view my contacts table it needs to includes attributes from the > company, people, and contacts tables so I can view all prior contacts with > that person. Sounds like a job for a database view. Can you modify the database schema? Could you create a view - even a temporary one just while your app is running? Alternatively, and I've done this trick myself, create an in-memory SqlLite database with a table that holds all the columns you want then fetch the data from the master and manipulate/view it from Sqlite - this makes sorting by different columns fast and simple. The downside is you have to refresh it periodically or you will miss all changes in the master. > Many years ago I used wxPython. For several reasons I decided to learn and > use tkinter from now one. One reason is that the application for my clients > will run mostly on windows hosts and I want to limit the software they need > to install and maintain in order to run it. Sure, that's the main reason I use tkinter too. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From arakelthedragon at gmail.com Thu Jun 17 09:35:24 2021 From: arakelthedragon at gmail.com (Arak Rachael) Date: Thu, 17 Jun 2021 06:35:24 -0700 (PDT) Subject: How to check if an image contains an element I am searchig for In-Reply-To: <015dba6c-0c11-4a1d-84a2-9c199fef4fa6n@googlegroups.com> References: <4d0a726d-f665-420a-85ec-47d4f4251e0fn@googlegroups.com> <0804AD1B-CD65-4468-9447-7B5C0A5CB9FE@barrys-emacs.org> <20210617065236.GA20630@hjp.at> <523d6c24-5230-4421-86dc-121376820800n@googlegroups.com> <015dba6c-0c11-4a1d-84a2-9c199fef4fa6n@googlegroups.com> Message-ID: <503e9080-6fa3-4206-bb9b-4ff0e9ffd12an@googlegroups.com> On Thursday, 17 June 2021 at 09:59:49 UTC+2, Arak Rachael wrote: > On Thursday, 17 June 2021 at 08:52:55 UTC+2, Peter J. Holzer wrote: > > On 2021-06-16 15:51:49 -0700, Arak Rachael wrote: > > > On Wednesday, 16 June 2021 at 23:44:02 UTC+2, Chris Angelico wrote: > > > > On Thu, Jun 17, 2021 at 7:35 AM Dan Stromberg wrote: > > > > > > > > > > On Wed, Jun 16, 2021 at 2:04 PM Barry wrote: > > > > > > > > > > > >>> On Thu, Jun 17, 2021 at 6:06 AM Arak Rachael > > > > > > wrote: > > > > > > >>> I have an image from google maps to say and I need to check if it has > > > > > > road markings, in order to do that, I believe I need to change the effects > > > > > > on the image so the markings and road can be white or something and the > > > > > > things I don't need like cars, trees and so on to be black. > > [...] > > > I understand your concerns. Actually I am doing image processing of > > > satellite pictures for smart cars. > > Using satellite images probably makes that a lot easier (yes, you wrote > > "Google maps", but for some reason I thought of Google Street View). At > > least you have a consistent angle (almost from straight above) and know > > the scale (given the zoom factor and the latitude). > > > > hp > > > > -- > > _ | Peter J. Holzer | Story must make more sense than reality. > > |_|_) | | > > | | | h... at hjp.at | -- Charles Stross, "Creative writing > > __/ | http://www.hjp.at/ | challenge!" > I made the crop code, before I posted the question, I just need the identification part: > [code] > # Library includes > import os > import cv2 # image and other special formats processing library > # for computer vision > import numpy as np > from numpy import asarray > import PIL > from PIL import Image > > # Global variables > # Recommended: move to a separate file > > # Recommended approach instead of using the "target" > # name directly > source_directory = "test" # Do not put a slash at the beginning > output_directory = "test2" # Do not put a slash at the beginning > > # Function definitions > def image_contains_required_elements(image): # Description: > # The function will check if the cropped image contains the > # required elements of the road(markings, road and others) > > # Local variables and initialization > raise Exception("Not implemented yet") > > > > def split_image(path, dstpath): # Description: > # Convert the generated frames(images) from > # extract_video(video_path, target_dir_path) to grayscale > # and reduce their size to half > > # Local variables and initialization > # Requires the libraries: > # import cv2 > # import os > # import pytest > # import numpy as np > > # Processing > # Reading an image in default mode > #path = r'/home/yordan/devel/python.assignments/topgis-viz.2/data' # Source Folder > #dstpath = r'/home/yordan/devel/python.assignments/topgis-viz.2/output_directory' # Destination Folder > > #path = source_directory # source_directory containing the images before the processing > #dstpath = output_directory # output_directory containing the images after the processing > """ > # Test if target_directory exists > try: # Try > makedirs(dstpath) # to create target_directory > except: # if there is an error > print("Directory already exist, images will be written in same folder") # print the error message > """ > files = os.listdir(path) # Read the files from source_directory and record them in a list > > for image in files: # For index in list > img = cv2.imread(os.path.join(path, image)) # Read the image from path + image name as an array into img > > # Split image into b, g ,r function > gray = img > #b, g, r = cv2.split(gray) # Split the image into BGR channels > #print(b, g, r) # print the b, g, r channels(codes) > crop_img = gray[100:100 + 100, 100:100 + 100] # Crop the image with numpy, x and y are flipped, > # example crop_img = img[margin:-margin, margin:-margin] > if image_contains_required_elements(crop_img) == True: > cv2.imwrite(os.path.join(dstpath, image), crop_img) # Write the image crop_img to a file with name > # target_directory + image name > > # Displaying the image > #cv2.imshow("Test", crop_img) # Show the image > > > split_image(source_directory, output_directory) > [code] Thanks for the help guys, I did it with OpenCV and Numpy, here is the code, but please download it, because its in my dropbox unsorted folder and I might delete it in time: https://www.dropbox.com/s/cr46m538to0j9ja/file_split.py?dl=0 here is a video processing file for who ever needs it: https://www.dropbox.com/s/39lrxkrfxuws1yd/videotest.py?dl=0 From j.wuttke at fz-juelich.de Thu Jun 17 03:53:09 2021 From: j.wuttke at fz-juelich.de (Joachim Wuttke) Date: Thu, 17 Jun 2021 09:53:09 +0200 Subject: module include path - /usr/local/lib/python3 vs /usr/local/lib/python3.9 Message-ID: How to write a platform-independent CMake install command to install a Swig-generated Python module? The following brings us very close to a solution: ``` execute_process( COMMAND "${Python3_EXECUTABLE}" -c "from distutils import sysconfig as sc; print(sc.get_python_lib(prefix='', plat_specific=True))" OUTPUT_VARIABLE PYTHON_SITE OUTPUT_STRIP_TRAILING_WHITESPACE) message(STATUS "Python module libcerf will be installed to ${PYTHON_SITE}") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/.py DESTINATION ${PYTHON_SITE}) ``` So far, we only tested under Debain, where the problem arises: - distutils.sysconfig.get_python_lib(...) returns lib/python3/dist-packages - CMake provides CMAKE_INSTALL_PREFIX=/usr/local/ - So installation goes to /usr/local/lib/python3/dist-packages - sys.path, however, does not contain /usr/local/lib/python3/dist-packages. sys.path contains /usr/local/lib/python3.9/dist-packages, and also /usr/lib/python3/dist-packages, so this is slightly incoherent. Anyway, we won't want to change sys.path. So we need to change the above CMake/Python code to return a local installation directory that is part of sys.path. Thanks for any hints - Joachim From rshepard at appl-ecosys.com Thu Jun 17 12:29:06 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 17 Jun 2021 09:29:06 -0700 (PDT) Subject: tkinter: tksheet In-Reply-To: References: Message-ID: On Thu, 17 Jun 2021, Dennis Lee Bieber wrote: >> My naive idea is to use two queries, one selects * from the company table >> ordered by nunber, the other by name. The UI offers two radiobuttons when >> viewing the results, one for each sort column. >> > Presuming all the data fits in memory, it may be faster to just define > the key structure for Python's internal sort() function than to go back out > to the database server, wait for it to gather the desired fields and sort > them, then transfer all the data back to your script. Dennis, That's a possibility. Thanks, Rich From rshepard at appl-ecosys.com Thu Jun 17 12:31:30 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 17 Jun 2021 09:31:30 -0700 (PDT) Subject: tkinter: tksheet In-Reply-To: References: Message-ID: On Thu, 17 Jun 2021, Alan Gauld via Python-list wrote: > Sounds like a job for a database view. Can you modify the database schema? > Could you create a view - even a temporary one just while your app is > running? Alan, Yes, created views work well with postgres. Building one for complex, multitable queries is always a good idea. Thanks, Rich From rshepard at appl-ecosys.com Thu Jun 17 12:33:29 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 17 Jun 2021 09:33:29 -0700 (PDT) Subject: tkinter: tksheet In-Reply-To: References: Message-ID: On Thu, 17 Jun 2021, Dennis Lee Bieber wrote: > FreePascal/Lazarus is supposed to be similar to Delphi, and does > have Linux installs -- but I don't know what it provides for database > linkages. I do have it installed on my Windows box (the Linux install is > HUGE; takes up over 1/4 of the space on BeagleBone Black so I didn't > install it there). Dennis, In the 1980s I looked closely at Pascal. More recently I did so again because the local linux/UNIX group had a presentation on its use. Decided another language was not for me. Thanks, Rich From mal at europython.eu Thu Jun 17 12:46:51 2021 From: mal at europython.eu (Marc-Andre Lemburg) Date: Thu, 17 Jun 2021 18:46:51 +0200 Subject: EuroPython 2021: Schedule published Message-ID: <29922359-692e-49e0-f116-bdf08b23c5ac@europython.eu> After two weeks of hard work by our program workgroup, we are very excited to announce the EuroPython 2021 schedule: * EuroPython 2021 Schedule * https://ep2021.europython.eu/schedule/ Seven full days of Python ------------------------- EuroPython 2021 will be held online in the week of July 26: - Two workshop/training days (Monday, Tuesday): training sessions and workshops - Three conference days (Wednesday, Thursday, Friday): keynotes, talks, lightning talks, poster session - Two sprint days (Saturday, Sunday): code sprints / hackathons Lots of engaging content waiting for you ---------------------------------------- The conference will be packed with interesting Python content, provided in many different formats and presented by our fantastic team of volunteers, speakers and sponsors: - 6 exciting keynotes, - 97 talks, - 18 training sessions, - 3 fun lightning talk blocks, - overall, more than 130 sessions in total, - presented by more than 130 speakers from around the world, - 4 all-day conference tracks, - with a whole track dedicated to data science topics, - a poster track, - interactive sessions, - a virtual social event, - an after party, - and lots of socializing on our conference platform. https://ep2021.europython.eu/events/sessions/ https://ep2021.europython.eu/events/speakers/ We would like to thank all speakers and sponsors who submitted session proposals to the conference. Never miss a talk ----------------- All talks will be made available to the attendees via streaming to our Matrix based conference platform, with easy switching between tracks and chat. We?ll also make the streams available with rewind functionality and give you access to the streams after the conference. Conference Tickets ------------------ Conference tickets are available on our registration page. We have several ticket types available to make the conference affordable for everyone and we're also offering financial aid to increase our reach even more. https://ep2021.europython.eu/registration/buy-tickets/ https://ep2021.europython.eu/registration/financial-aid/ EuroPython is your conference ----------------------------- EuroPython has always been a completely volunteer based effort. The organizers work hundreds of hours to make the event happen and will try very hard to create an inspiring and exciting event. However, we can only provide the setting. You, as our attendees, are the ones who fill it with life and creativity. We are very much looking forward to having you at the conference ! Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/europython-2021-schedule-published/ Tweet: https://twitter.com/europython/status/1405538503048327169 Enjoy, -- EuroPython 2021 Team https://ep2021.europython.eu/ https://www.europython-society.org/ From mats at wichmann.us Thu Jun 17 14:22:24 2021 From: mats at wichmann.us (Mats Wichmann) Date: Thu, 17 Jun 2021 12:22:24 -0600 Subject: module include path - /usr/local/lib/python3 vs /usr/local/lib/python3.9 In-Reply-To: References: Message-ID: <2d42140d-393b-a7bf-5d43-c87e865e67a0@wichmann.us> On 6/17/21 1:53 AM, Joachim Wuttke wrote: > How to write a platform-independent CMake install command > to install a Swig-generated Python module? > > The following brings us very close to a solution: > ``` > execute_process( > ??? COMMAND "${Python3_EXECUTABLE}" > ??? -c "from distutils import sysconfig as sc; > ??????? print(sc.get_python_lib(prefix='', plat_specific=True))" > ??? OUTPUT_VARIABLE PYTHON_SITE > ??? OUTPUT_STRIP_TRAILING_WHITESPACE) > message(STATUS "Python module libcerf will be installed to ${PYTHON_SITE}") > > install(FILES ${CMAKE_CURRENT_BINARY_DIR}/.py > ??????? DESTINATION ${PYTHON_SITE}) > ``` > > So far, we only tested under Debain, where the problem arises: > > - distutils.sysconfig.get_python_lib(...) returns lib/python3/dist-packages > - CMake provides CMAKE_INSTALL_PREFIX=/usr/local/ > - So installation goes to /usr/local/lib/python3/dist-packages > - sys.path, however, does not contain /usr/local/lib/python3/dist-packages. > > sys.path contains /usr/local/lib/python3.9/dist-packages, and also > /usr/lib/python3/dist-packages, so this is slightly incoherent. > Anyway, we won't want to change sys.path. So we need to change > the above CMake/Python code to return a local installation directory > that is part of sys.path. > > Thanks for any hints - Joachim dist-packages is Debian-family-specific anyway, other Linux distros don't use it - and some have some interesting conventions - if you're using Swig to build a binary extension module, it needs to go in a lib-dynload directory on Fedora. You should look at the Python sysconfig module in preference to using the one from distutils. You probably need to say more about what the target is - are you attempting to install as part of the process building a distro package, or are you expecting to install directly? From pablogsal at gmail.com Thu Jun 17 17:33:18 2021 From: pablogsal at gmail.com (Pablo Galindo Salgado) Date: Thu, 17 Jun 2021 22:33:18 +0100 Subject: [RELEASE] Python 3.10.0b3 is available Message-ID: Summer is almost here (at least in half of the planet) and Python 3.10 is finishing baking in the oven. For those of you that want to taste it before is finally ready (and if you are a library developer, you certainly do!) you can have the second-to-last beta now, but be careful as is still very hot ;) https://www.python.org/downloads/release/python-3100b3/ #This is a beta preview of Python 3.10 Python 3.10 is still in development. 3.10.0b3 is the third of four planned beta release previews. Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release. We strongly encourage maintainers of third-party Python projects to test with 3.10 during the beta phase and report issues found to the Python bug tracker as soon as possible. While the release is planned to be feature complete entering the beta phase, it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase (Monday, 2021-08-02). Our goal is to have no ABI changes after beta 4 and as few code changes as possible after 3.10.0rc1, the first release candidate. To achieve that, it will be extremely important to get as much exposure for 3.10 as possible during the beta phase. Please keep in mind that this is a preview release and its use is not recommended for production environments. The next pre-release of Python 3.10 will be 3.10.0b4, currently scheduled for Saturday, 2021-07-10. #And now for something completely different There are no green stars. Why? In general, objects don?t emit a single wavelength of light when they shine. Instead, they emit photons in a range of wavelengths. If you were to use some sort of detector that is sensitive to the wavelengths of light emitted by an object, and then plotted the number of them versus wavelength, you get a lopsided plot called a blackbody curve. For an object as hot as the Sun, that curve peaks at blue-green, so it emits most of its photons there. But it still emits some that are bluer, and some that are redder. When we look at the Sun, we see all these colors blended together. Our eyes mix them up to produce one color: white. A warmer star will put out more blue, and a cooler one redder, but no matter what, our eyes just won?t see that as green. Due to how we perceive color, the only way to see a star as being green is for it to be only emitting green light. But as starts always emit radiation following the blackbody curve, that?s pretty much impossible. # We hope you enjoy those new releases! Thanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation. Regards from very cloudy London, Your friendly release team, Pablo Galindo @pablogsal Ned Deily @nad Steve Dower @steve.dower From boom0192 at hotmail.com Thu Jun 17 17:02:46 2021 From: boom0192 at hotmail.com (Michael Boom) Date: Thu, 17 Jun 2021 21:02:46 +0000 Subject: How Do I Get A Bug In Multiprocessing Fixed? Message-ID: The below issue is pretty serious and it is preventing me from using a system I wrote on a larger scale. How do I get this bug fixed? Thanks. https://bugs.python.org/issue43329 From alexander at neilson.net.nz Fri Jun 18 01:04:45 2021 From: alexander at neilson.net.nz (Alexander Neilson) Date: Fri, 18 Jun 2021 17:04:45 +1200 Subject: How Do I Get A Bug In Multiprocessing Fixed? In-Reply-To: References: Message-ID: Hi Michael It may be helpful to populate the ticket with further details: * actual output from when you execute the server and client (possibly with extra verbosity enabled) * system you are running this on (windows, macos, linux) flavour / version details * minor version of Python interpreter used * whether you are using a packaged version from your os distributor or from python.org (or even built your own) * If you believe it's a regression the version it is working on Some more guidance can be found here covering some of the above https://docs.python.org/3/bugs.html I am very interested to note that a report filed in February hasn't had at least one person take a brief look at it and post a note or set a status like "needs more info" etc. Also I am by no means an expert in multi processing at all as so far my webapps work worker processes, I am wondering if the wrong approach to this may be happening and so the client is trying to reuse the same pipe and it may need a different tear down / process to release that and create a new pipe / socket / underlying connection cleanly rather than the re connect in the same object. For example I am running python 3.7.7 on windows: Manager Output: >python manager.py In test_method >python manager.py Client Output: result: ', TEST' Kill and restart the server and press return Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting Got exception , ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None) Reconnecting # At this point I terminated the manager Got exception , ConnectionRefusedError(10061, 'No connection could be made because the target machine actively refused it', None, 10061, None) Reconnecting Traceback (most recent call last): File "C:\Users\Alexander\AppData\Local\Programs\Python\Python37\lib\multiprocessing\connection.py", line 619, in SocketClient s.connect(address) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it During handling of the above exception, another exception occurred: Traceback (most recent call last): File "client.py", line 27, in manager.connect() File "C:\Users\Alexander\AppData\Local\Programs\Python\Python37\lib\multiprocessing\managers.py", line 532, in connect conn = Client(self._address, authkey=self._authkey) File "C:\Users\Alexander\AppData\Local\Programs\Python\Python37\lib\multiprocessing\connection.py", line 492, in Client c = SocketClient(address) File "C:\Users\Alexander\AppData\Local\Programs\Python\Python37\lib\multiprocessing\connection.py", line 619, in SocketClient s.connect(address) KeyboardInterrupt Regards Alexander Alexander Neilson Neilson Productions Limited alexander at neilson.net.nz 021 329 681 022 456 2326 On Fri, 18 Jun 2021 at 15:27, Michael Boom wrote: > The below issue is pretty serious and it is preventing me from using a > system I wrote on a larger scale. How do I get this bug fixed? Thanks. > https://bugs.python.org/issue43329 > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Fri Jun 18 02:41:47 2021 From: barry at barrys-emacs.org (Barry) Date: Fri, 18 Jun 2021 07:41:47 +0100 Subject: How Do I Get A Bug In Multiprocessing Fixed? In-Reply-To: References: Message-ID: <6571798D-30B0-47D7-AC49-76C30878F360@barrys-emacs.org> Also you report requires any developer to write a program from you notes to reproduce the problem. Attach a program that shows the problem would help. Better yet diagnose the problem after you reproduce it with a fix in a PR. Barry > On 18 Jun 2021, at 06:07, Alexander Neilson wrote: > > ?Hi Michael > > It may be helpful to populate the ticket with further details: > * actual output from when you execute the server and client (possibly with > extra verbosity enabled) > * system you are running this on (windows, macos, linux) flavour / version > details > * minor version of Python interpreter used > * whether you are using a packaged version from your os distributor or from > python.org (or even built your own) > * If you believe it's a regression the version it is working on > > Some more guidance can be found here covering some of the above > https://docs.python.org/3/bugs.html > > I am very interested to note that a report filed in February hasn't had at > least one person take a brief look at it and post a note or set a status > like "needs more info" etc. > > Also I am by no means an expert in multi processing at all as so far my > webapps work worker processes, I am wondering if the wrong approach to this > may be happening and so the client is trying to reuse the same pipe and it > may need a different tear down / process to release that and create a new > pipe / socket / underlying connection cleanly rather than the re connect in > the same object. > > For example I am running python 3.7.7 on windows: > > Manager Output: >> python manager.py > In test_method > >> python manager.py > > > Client Output: > result: ', TEST' > Kill and restart the server and press return > > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting > Got exception , ConnectionResetError(10054, > 'An existing connection was forcibly closed by the remote host', None, > 10054, None) > Reconnecting # At this point I terminated the manager > Got exception , > ConnectionRefusedError(10061, 'No connection could be made because the > target machine actively refused it', None, 10061, None) > Reconnecting > Traceback (most recent call last): > File > "C:\Users\Alexander\AppData\Local\Programs\Python\Python37\lib\multiprocessing\connection.py", > line 619, in SocketClient > s.connect(address) > ConnectionRefusedError: [WinError 10061] No connection could be made > because the target machine actively refused it > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "client.py", line 27, in > manager.connect() > File > "C:\Users\Alexander\AppData\Local\Programs\Python\Python37\lib\multiprocessing\managers.py", > line 532, in connect > conn = Client(self._address, authkey=self._authkey) > File > "C:\Users\Alexander\AppData\Local\Programs\Python\Python37\lib\multiprocessing\connection.py", > line 492, in Client > c = SocketClient(address) > File > "C:\Users\Alexander\AppData\Local\Programs\Python\Python37\lib\multiprocessing\connection.py", > line 619, in SocketClient > s.connect(address) > KeyboardInterrupt > > > > > Regards > Alexander > > Alexander Neilson > Neilson Productions Limited > > alexander at neilson.net.nz > 021 329 681 > 022 456 2326 > > >> On Fri, 18 Jun 2021 at 15:27, Michael Boom wrote: >> >> The below issue is pretty serious and it is preventing me from using a >> system I wrote on a larger scale. How do I get this bug fixed? Thanks. >> https://bugs.python.org/issue43329 >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Fri Jun 18 06:04:45 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 18 Jun 2021 20:04:45 +1000 Subject: Strange disassembly Message-ID: >>> sys.version '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' >>> def chk(x): ... if not(0 < x < 10): raise Exception ... >>> dis.dis(chk) 2 0 LOAD_CONST 1 (0) 2 LOAD_FAST 0 (x) 4 DUP_TOP 6 ROT_THREE 8 COMPARE_OP 0 (<) 10 POP_JUMP_IF_FALSE 11 (to 22) 12 LOAD_CONST 2 (10) 14 COMPARE_OP 0 (<) 16 POP_JUMP_IF_TRUE 14 (to 28) 18 LOAD_GLOBAL 0 (Exception) 20 RAISE_VARARGS 1 >> 22 POP_TOP 24 LOAD_GLOBAL 0 (Exception) 26 RAISE_VARARGS 1 >> 28 LOAD_CONST 0 (None) 30 RETURN_VALUE >>> Why are there two separate bytecode blocks for the "raise Exception"? I'd have thought that the double condition would still be evaluated as one thing, or at least that the jump destinations for both the early-abort and the main evaluation should be the same. ChrisA From oscar.j.benjamin at gmail.com Fri Jun 18 09:22:04 2021 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Fri, 18 Jun 2021 14:22:04 +0100 Subject: How Do I Get A Bug In Multiprocessing Fixed? In-Reply-To: References: Message-ID: On Fri, 18 Jun 2021 at 15:27, Michael Boom wrote: > The below issue is pretty serious and it is preventing me from using a > system I wrote on a larger scale. How do I get this bug fixed? Thanks. > https://bugs.python.org/issue43329 On Fri, 18 Jun 2021 at 06:07, Alexander Neilson wrote: > > I am very interested to note that a report filed in February hasn't had at > least one person take a brief look at it and post a note or set a status > like "needs more info" etc. > Personally I don't find that surprising. I just looked at the issue very quickly and I couldn't immediately tell if the problem was a bug in multiprocessing or a mistake in the code shown. Just figuring that out would take more than the very little time I was prepared to spend looking at it so I moved on. If the OP hopes that someone else will use their limited time to fix this issue for them then they should do what they can to make it as quick as possible for that other person. The first part of that is making clear why it should be considered a bug in the first place. Don't expect the reader to spend time deciphering your code to figure that out. If there is a bug in multiprocessing then the issue should be clearer about what it is or why it should be considered a bug. Which function is documented as doing something that apparently does not work in this case? Why should it be expected to work? -- Oscar From rshepard at appl-ecosys.com Fri Jun 18 18:24:58 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 18 Jun 2021 15:24:58 -0700 (PDT) Subject: Faker package Message-ID: I'm trying to use the faker package to generate data to load in a sample postgres database so I can learn how to use tksheet and psycopg2. The 8.8.1 documentation shows output on a root shell prompt (#), not a python prompt (>>>). It also has a description of using faker from 'the command line', which I assume is the python shell, and I can't get it to work. I suppose that I can generate one name, address, etc. at a time and them copy and concatenate them into table data, but I thought that the faker package would do this all for me. Is there a tool that will let me generate the equivalent of a database row worth of data? That is, a set of strings of different types that can then be inserted into the testing database? Rich From tjreedy at udel.edu Fri Jun 18 13:17:30 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 18 Jun 2021 13:17:30 -0400 Subject: How Do I Get A Bug In Multiprocessing Fixed? In-Reply-To: References: Message-ID: On 6/17/2021 5:02 PM, Michael Boom wrote: > The below issue is pretty serious and it is preventing me from using a system I wrote on a larger scale. How do I get this bug fixed? Thanks. > https://bugs.python.org/issue43329 Reduce your code to the minimum needed to exhibit the problem. Then run it with 3.9.5 and 3.10.0b3. 3.8 only gets security fixes. To get attention, demonstrate that there is a problem with current versions. -- Terry Jan Reedy From tjreedy at udel.edu Fri Jun 18 14:03:00 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 18 Jun 2021 14:03:00 -0400 Subject: Strange disassembly In-Reply-To: References: Message-ID: On 6/18/2021 6:04 AM, Chris Angelico wrote: >>>> sys.version > '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' >>>> def chk(x): > ... if not(0 < x < 10): raise Exception 0 < x < 10 == 0 < x and x < 10, except that 'x' is evaluated once. not(_) == (not 0 < x) or (not x < 10) [== x <= 0 or 10 <= x] >>>> dis.dis(chk) > 2 0 LOAD_CONST 1 (0) > 2 LOAD_FAST 0 (x) stack = 0 x. Since compare will remove both, must duplicate x and move duplicate out of the way. > 4 DUP_TOP > 6 ROT_THREE stack = x 0 x > 8 COMPARE_OP 0 (<) test 0 < x, remove both, leaving stack = x > 10 POP_JUMP_IF_FALSE 11 (to 22) if false, not 0 12 LOAD_CONST 2 (10) > 14 COMPARE_OP 0 (<) Raise exception if false, making not x < 10 true So if true, jump to normal exit at end. Stack is empty. > 16 POP_JUMP_IF_TRUE 14 (to 28) > 18 LOAD_GLOBAL 0 (Exception) > 20 RAISE_VARARGS > >> 22 POP_TOP Must first remove unneeded duplicate of x! > 24 LOAD_GLOBAL 0 (Exception) > 26 RAISE_VARARGS 1 > >> 28 LOAD_CONST 0 (None) > 30 RETURN_VALUE > Why are there two separate bytecode blocks for the "raise Exception"? Because one block must POP_TOP and other must not. > I'd have thought that the double condition would still be evaluated as > one thing, or at least that the jump destinations for both the > early-abort and the main evaluation should be the same. To reuse the exception block with POP_TOP, could jump over it after the 2nd compare. > 14 COMPARE_OP 0 (<) > 16 POP_JUMP_IF_TRUE 14 (to 28) 18 JUMP (to 24) 20 NOP (#to avoid renumbering) > >> 22 POP_TOP > 24 LOAD_GLOBAL 0 (Exception) > 26 RAISE_VARARGS 1 For the simplest and fasted bytecode, write normal logic and let x be reloaded instead of duplicated and rotated. >>> import dis >>> def f(x): ... if x <= 0 or 10 <= x: raise Exception ... ... >>> dis.dis(f) 2 0 LOAD_FAST 0 (x) 2 LOAD_CONST 1 (0) 4 COMPARE_OP 1 (<=) 6 POP_JUMP_IF_TRUE 8 (to 16) 8 LOAD_CONST 2 (10) 10 LOAD_FAST 0 (x) 12 COMPARE_OP 1 (<=) 14 POP_JUMP_IF_FALSE 10 (to 20) >> 16 LOAD_GLOBAL 0 (Exception) 18 RAISE_VARARGS 1 >> 20 LOAD_CONST 0 (None) 22 RETURN_VALUE >>> -- Terry Jan Reedy From tjreedy at udel.edu Fri Jun 18 19:02:58 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 18 Jun 2021 19:02:58 -0400 Subject: Faker package In-Reply-To: References: Message-ID: On 6/18/2021 6:24 PM, Rich Shepard wrote: > I'm trying to use the faker package to generate data to load in a sample > postgres database so I can learn how to use tksheet and psycopg2. > > The 8.8.1 documentation shows output on a root shell prompt (#), not a > python prompt (>>>). It also has a description of using faker from 'the > command line', which I assume is the python shell, and I can't get it to > work. I suppose that I can generate one name, address, etc. at a time and > them copy and concatenate them into table data, but I thought that the > faker > package would do this all for me. > > Is there a tool that will let me generate the equivalent of a database row > worth of data? That is, a set of strings of different types that can > then be > inserted into the testing database? I would try using the 'given' function/decorator of hypothesis (on pypi) to generate random data that conforms to whatever specification. -- Terry Jan Reedy From liyaannsunny1995 at gmail.com Fri Jun 18 02:28:23 2021 From: liyaannsunny1995 at gmail.com (Liya Ann Sunny) Date: Thu, 17 Jun 2021 23:28:23 -0700 (PDT) Subject: Tkinter problem Message-ID: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> I am using Colab. How could solve this problem. import tkinter as Tk from tkinter import * import sys import os #create main window master = Tk() master.title("tester") master.geometry("300x100") #make a label for the window label1 = tkinter.Label(master, text='Hellooooo') # Lay out label label1.pack() # Run forever! master.mainloop() The error shows that : in () 9 10 #create main window ---> 11 master = Tk() 12 master.title("tester") 13 master.geometry("300x100") /usr/lib/python3.7/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use) 2021 baseName = baseName + ext 2022 interactive = 0 -> 2023 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) 2024 if useTk: 2025 self._loadtk() TclError: couldn't connect to display ":0.0" From auriocus at gmx.de Fri Jun 18 02:44:21 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 18 Jun 2021 08:44:21 +0200 Subject: Tkinter problem In-Reply-To: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> References: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> Message-ID: Am 18.06.21 um 08:28 schrieb Liya Ann Sunny: > I am using Colab. How could solve this problem. > TclError: couldn't connect to display ":0.0" You're either not running an X server, or having problems to connect to it. Are you sure that Google Colab supports X11 at all? This link doesn't seem to support that idea: https://stackoverflow.com/questions/61168210/is-there-any-way-to-use-tkinter-with-google-colaboratory Christian From rosuav at gmail.com Fri Jun 18 20:13:33 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Jun 2021 10:13:33 +1000 Subject: Strange disassembly In-Reply-To: References: Message-ID: On Sat, Jun 19, 2021 at 9:50 AM Terry Reedy wrote: > > Why are there two separate bytecode blocks for the "raise Exception"? > > Because one block must POP_TOP and other must not. > > > I'd have thought that the double condition would still be evaluated as > > one thing, or at least that the jump destinations for both the > > early-abort and the main evaluation should be the same. > > To reuse the exception block with POP_TOP, could jump over it after the > 2nd compare. Hmm, fair enough I guess. The compiler figured that it'd be faster to duplicate the executable code rather than have the jump. It made for a somewhat confusing disassembly, but I presume it's faster to run. > For the simplest and fasted bytecode, write normal logic and let x be > reloaded instead of duplicated and rotated. > > >>> import dis > >>> def f(x): > ... if x <= 0 or 10 <= x: raise Exception > ... > ... > >>> dis.dis(f) > 2 0 LOAD_FAST 0 (x) > 2 LOAD_CONST 1 (0) > 4 COMPARE_OP 1 (<=) > 6 POP_JUMP_IF_TRUE 8 (to 16) > 8 LOAD_CONST 2 (10) > 10 LOAD_FAST 0 (x) > 12 COMPARE_OP 1 (<=) > 14 POP_JUMP_IF_FALSE 10 (to 20) > >> 16 LOAD_GLOBAL 0 (Exception) > 18 RAISE_VARARGS 1 > >> 20 LOAD_CONST 0 (None) > 22 RETURN_VALUE > >>> > Makes sense. I'm not sure if this would actually run faster, but I can't really justify warping my code around the disassembly :) Thanks for the explanation. I guess I just assumed the interpreter would prefer a jump to the duplication, but that's a decision it's free to take! ChrisA From rshepard at appl-ecosys.com Fri Jun 18 20:19:02 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 18 Jun 2021 17:19:02 -0700 (PDT) Subject: Faker package In-Reply-To: References: Message-ID: On Fri, 18 Jun 2021, Terry Reedy wrote: > I would try using the 'given' function/decorator of hypothesis (on pypi) > to generate random data that conforms to whatever specification. Thank you, Terry. I'll do that. Regards, Rich From python at mrabarnett.plus.com Fri Jun 18 20:22:05 2021 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 19 Jun 2021 01:22:05 +0100 Subject: Faker package In-Reply-To: References: Message-ID: <7f55cbe8-02b1-9d71-9100-d371ea190056@mrabarnett.plus.com> On 2021-06-18 23:24, Rich Shepard wrote: > I'm trying to use the faker package to generate data to load in a sample > postgres database so I can learn how to use tksheet and psycopg2. > > The 8.8.1 documentation shows output on a root shell prompt (#), not a > python prompt (>>>). It also has a description of using faker from 'the > command line', which I assume is the python shell, and I can't get it to > work. I suppose that I can generate one name, address, etc. at a time and > them copy and concatenate them into table data, but I thought that the faker > package would do this all for me. > When it says "command line" it means the operating system's command line. If it's the Python shell , it'll say "Python shell" or "Python prompt. The "root shell prompt (#)" suggests to me that it's Linux, so if you're using Windows you'll need to use the equivalent for Windows. > Is there a tool that will let me generate the equivalent of a database row > worth of data? That is, a set of strings of different types that can then be > inserted into the testing database? > From rshepard at appl-ecosys.com Fri Jun 18 21:51:19 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 18 Jun 2021 18:51:19 -0700 (PDT) Subject: Faker package In-Reply-To: <7f55cbe8-02b1-9d71-9100-d371ea190056@mrabarnett.plus.com> References: <7f55cbe8-02b1-9d71-9100-d371ea190056@mrabarnett.plus.com> Message-ID: On Sat, 19 Jun 2021, MRAB wrote: > When it says "command line" it means the operating system's command line. If > it's the Python shell , it'll say "Python shell" or "Python prompt. MRAB, The root shell's (#) what I assumed. User shells (in bash, anyway) have $ as the prompt. Regardless, $ faker -o temp.out faker.names() -bash: syntax error near unexpected token `(' [rshepard at salmo ~]$ faker -o temp.out faker.names Traceback (most recent call last): File "/usr/bin/faker", line 8, in sys.exit(execute_from_command_line()) File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 264, in execute_from_command_line command.execute() File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 246, in execute includes=arguments.include, File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 67, in print_doc provider_or_field], includes=includes) File "/usr/lib64/python3.7/site-packages/faker/proxy.py", line 63, in __init__ **config) File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 56, in create prov_cls, lang_found = cls._get_provider_class(prov_name, locale) File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 68, in _get_provider_class provider_class = cls._find_provider_class(provider, locale) File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 90, in _find_provider_class provider_module = import_module(provider_path) File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 965, in _find_and_load_unlocked ModuleNotFoundError: No module named 'faker.names' [rshepard at salmo ~]$ It does not work from the bash command line as a user or as root. > The "root shell prompt (#)" suggests to me that it's Linux, so if you're > using Windows you'll need to use the equivalent for Windows. I don't do windows; defenestrated 24 years ago. Rich From python at mrabarnett.plus.com Fri Jun 18 22:10:41 2021 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 19 Jun 2021 03:10:41 +0100 Subject: Faker package In-Reply-To: References: <7f55cbe8-02b1-9d71-9100-d371ea190056@mrabarnett.plus.com> Message-ID: <5d5e04b2-5fd9-7fef-ddcb-1561ec68c1c3@mrabarnett.plus.com> On 2021-06-19 02:51, Rich Shepard wrote: > On Sat, 19 Jun 2021, MRAB wrote: > >> When it says "command line" it means the operating system's command line. If >> it's the Python shell , it'll say "Python shell" or "Python prompt. > > MRAB, > > The root shell's (#) what I assumed. User shells (in bash, anyway) have $ as > the prompt. > > Regardless, > > $ faker -o temp.out faker.names() > -bash: syntax error near unexpected token `(' > [rshepard at salmo ~]$ faker -o temp.out faker.names > Traceback (most recent call last): > File "/usr/bin/faker", line 8, in > sys.exit(execute_from_command_line()) > File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 264, in execute_from_command_line > command.execute() > File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 246, in execute > includes=arguments.include, > File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 67, in print_doc > provider_or_field], includes=includes) > File "/usr/lib64/python3.7/site-packages/faker/proxy.py", line 63, in __init__ > **config) > File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 56, in create > prov_cls, lang_found = cls._get_provider_class(prov_name, locale) > File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 68, in _get_provider_class > provider_class = cls._find_provider_class(provider, locale) > File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 90, in _find_provider_class > provider_module = import_module(provider_path) > File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module > return _bootstrap._gcd_import(name[level:], package, level) > File "", line 1006, in _gcd_import > File "", line 983, in _find_and_load > File "", line 965, in _find_and_load_unlocked > ModuleNotFoundError: No module named 'faker.names' > [rshepard at salmo ~]$ > > It does not work from the bash command line as a user or as root. > >> The "root shell prompt (#)" suggests to me that it's Linux, so if you're >> using Windows you'll need to use the equivalent for Windows. > > I don't do windows; defenestrated 24 years ago. > It looks like you're mixing some Python usage ("faker.names()") in with command line usage. Judging from the docs, I'd say you need something more like: $ faker -o temp.out name for 1 fake name or: $ faker -r=10 -o temp.out name for 10 fake names. From rob.cliffe at btinternet.com Sat Jun 19 02:14:33 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Sat, 19 Jun 2021 07:14:33 +0100 Subject: Strange disassembly In-Reply-To: References: Message-ID: On 18/06/2021 11:04, Chris Angelico wrote: >>>> sys.version > '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' >>>> def chk(x): > ... if not(0 < x < 10): raise Exception > ... >>>> dis.dis(chk) > 2 0 LOAD_CONST 1 (0) > 2 LOAD_FAST 0 (x) > 4 DUP_TOP > 6 ROT_THREE > 8 COMPARE_OP 0 (<) > 10 POP_JUMP_IF_FALSE 11 (to 22) > 12 LOAD_CONST 2 (10) > 14 COMPARE_OP 0 (<) > 16 POP_JUMP_IF_TRUE 14 (to 28) > 18 LOAD_GLOBAL 0 (Exception) > 20 RAISE_VARARGS 1 > >> 22 POP_TOP > 24 LOAD_GLOBAL 0 (Exception) > 26 RAISE_VARARGS 1 > >> 28 LOAD_CONST 0 (None) > 30 RETURN_VALUE > Why are there two separate bytecode blocks for the "raise Exception"? > I'd have thought that the double condition would still be evaluated as > one thing, or at least that the jump destinations for both the > early-abort and the main evaluation should be the same. > > ChrisA As an ornery human I could refactor this to avoid the code duplication as ? 2?????????? 0 LOAD_CONST?????????????? 1 (0) ????????????? 2 LOAD_FAST??????????????? 0 (x) ????????????? 4 DUP_TOP ????????????? 6 ROT_THREE ????????????? 8 COMPARE_OP?????????????? 0 (<) ???????????? 10 POP_JUMP_IF_TRUE??????? 10 (to 18) ???????????? 12 POP_TOP ??????? >>?? 14 LOAD_GLOBAL????????????? 0 (Exception) ???????????? 16 RAISE_VARARGS??????????? 1 ??????? >>?? 18 LOAD_CONST?????????????? 2 (10) ???????????? 20 COMPARE_OP?????????????? 0 (<) ???????????? 22 POP_JUMP_IF_FALSE?????? 21 (to 14) ???????????? 24 LOAD_CONST?????????????? 0 (None) ???????????? 26 RETURN_VALUE >>> (there may be mistakes in this) but this is probably too much to expect of the compiler. Rob Cliffe From rosuav at gmail.com Sat Jun 19 02:50:12 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Jun 2021 16:50:12 +1000 Subject: Strange disassembly In-Reply-To: References: Message-ID: On Sat, Jun 19, 2021 at 4:16 PM Rob Cliffe via Python-list wrote: > > > > On 18/06/2021 11:04, Chris Angelico wrote: > >>>> sys.version > > '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' > >>>> def chk(x): > > ... if not(0 < x < 10): raise Exception > > ... > >>>> dis.dis(chk) > > 2 0 LOAD_CONST 1 (0) > > 2 LOAD_FAST 0 (x) > > 4 DUP_TOP > > 6 ROT_THREE > > 8 COMPARE_OP 0 (<) > > 10 POP_JUMP_IF_FALSE 11 (to 22) > > 12 LOAD_CONST 2 (10) > > 14 COMPARE_OP 0 (<) > > 16 POP_JUMP_IF_TRUE 14 (to 28) > > 18 LOAD_GLOBAL 0 (Exception) > > 20 RAISE_VARARGS 1 > > >> 22 POP_TOP > > 24 LOAD_GLOBAL 0 (Exception) > > 26 RAISE_VARARGS 1 > > >> 28 LOAD_CONST 0 (None) > > 30 RETURN_VALUE > > Why are there two separate bytecode blocks for the "raise Exception"? > > I'd have thought that the double condition would still be evaluated as > > one thing, or at least that the jump destinations for both the > > early-abort and the main evaluation should be the same. > > > > ChrisA > As an ornery human I could refactor this to avoid the code duplication as > > 2 0 LOAD_CONST 1 (0) > 2 LOAD_FAST 0 (x) > 4 DUP_TOP > 6 ROT_THREE > 8 COMPARE_OP 0 (<) > 10 POP_JUMP_IF_TRUE 10 (to 18) > 12 POP_TOP > >> 14 LOAD_GLOBAL 0 (Exception) > 16 RAISE_VARARGS 1 > >> 18 LOAD_CONST 2 (10) > 20 COMPARE_OP 0 (<) > 22 POP_JUMP_IF_FALSE 21 (to 14) > 24 LOAD_CONST 0 (None) > 26 RETURN_VALUE > >>> > > (there may be mistakes in this) but this is probably too much to expect > of the compiler. Hmm, I think that depends too much on knowing that the raise won't return. That might be a neat optimization (effectively a form of dead code removal), but otherwise, the best you could do would be to also have it jump out after the raise. ChrisA From rob.cliffe at btinternet.com Sat Jun 19 03:00:37 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Sat, 19 Jun 2021 08:00:37 +0100 Subject: Strange disassembly In-Reply-To: References: Message-ID: <9b5670d9-fddf-81ed-e6c0-ca6744298bed@btinternet.com> On 19/06/2021 07:50, Chris Angelico wrote: > On Sat, Jun 19, 2021 at 4:16 PM Rob Cliffe via Python-list > wrote: >> >> >> On 18/06/2021 11:04, Chris Angelico wrote: >>>>>> sys.version >>> '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' >>>>>> def chk(x): >>> ... if not(0 < x < 10): raise Exception >>> ... >>>>>> dis.dis(chk) >>> 2 0 LOAD_CONST 1 (0) >>> 2 LOAD_FAST 0 (x) >>> 4 DUP_TOP >>> 6 ROT_THREE >>> 8 COMPARE_OP 0 (<) >>> 10 POP_JUMP_IF_FALSE 11 (to 22) >>> 12 LOAD_CONST 2 (10) >>> 14 COMPARE_OP 0 (<) >>> 16 POP_JUMP_IF_TRUE 14 (to 28) >>> 18 LOAD_GLOBAL 0 (Exception) >>> 20 RAISE_VARARGS 1 >>> >> 22 POP_TOP >>> 24 LOAD_GLOBAL 0 (Exception) >>> 26 RAISE_VARARGS 1 >>> >> 28 LOAD_CONST 0 (None) >>> 30 RETURN_VALUE >>> Why are there two separate bytecode blocks for the "raise Exception"? >>> I'd have thought that the double condition would still be evaluated as >>> one thing, or at least that the jump destinations for both the >>> early-abort and the main evaluation should be the same. >>> >>> ChrisA >> As an ornery human I could refactor this to avoid the code duplication as >> >> 2 0 LOAD_CONST 1 (0) >> 2 LOAD_FAST 0 (x) >> 4 DUP_TOP >> 6 ROT_THREE >> 8 COMPARE_OP 0 (<) >> 10 POP_JUMP_IF_TRUE 10 (to 18) >> 12 POP_TOP >> >> 14 LOAD_GLOBAL 0 (Exception) >> 16 RAISE_VARARGS 1 >> >> 18 LOAD_CONST 2 (10) >> 20 COMPARE_OP 0 (<) >> 22 POP_JUMP_IF_FALSE 21 (to 14) >> 24 LOAD_CONST 0 (None) >> 26 RETURN_VALUE >> >>> >> >> (there may be mistakes in this) but this is probably too much to expect >> of the compiler. > Hmm, I think that depends too much on knowing that the raise won't > return. That might be a neat optimization (effectively a form of dead > code removal), but otherwise, the best you could do would be to also > have it jump out after the raise. > > ChrisA Er, doesn't your original dis output make the same assumption? Otherwise, after this line 20 RAISE_VARARGS 1 it would attempt to do an extra pop, then raise a second time. Rob Cliffe From rosuav at gmail.com Sat Jun 19 03:53:11 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 19 Jun 2021 17:53:11 +1000 Subject: Strange disassembly In-Reply-To: <9b5670d9-fddf-81ed-e6c0-ca6744298bed@btinternet.com> References: <9b5670d9-fddf-81ed-e6c0-ca6744298bed@btinternet.com> Message-ID: On Sat, Jun 19, 2021 at 5:13 PM Rob Cliffe via Python-list wrote: > > > > On 19/06/2021 07:50, Chris Angelico wrote: > > On Sat, Jun 19, 2021 at 4:16 PM Rob Cliffe via Python-list > > wrote: > >> > >> > >> On 18/06/2021 11:04, Chris Angelico wrote: > >>>>>> sys.version > >>> '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' > >>>>>> def chk(x): > >>> ... if not(0 < x < 10): raise Exception > >>> ... > >>>>>> dis.dis(chk) > >>> 2 0 LOAD_CONST 1 (0) > >>> 2 LOAD_FAST 0 (x) > >>> 4 DUP_TOP > >>> 6 ROT_THREE > >>> 8 COMPARE_OP 0 (<) > >>> 10 POP_JUMP_IF_FALSE 11 (to 22) > >>> 12 LOAD_CONST 2 (10) > >>> 14 COMPARE_OP 0 (<) > >>> 16 POP_JUMP_IF_TRUE 14 (to 28) > >>> 18 LOAD_GLOBAL 0 (Exception) > >>> 20 RAISE_VARARGS 1 > >>> >> 22 POP_TOP > >>> 24 LOAD_GLOBAL 0 (Exception) > >>> 26 RAISE_VARARGS 1 > >>> >> 28 LOAD_CONST 0 (None) > >>> 30 RETURN_VALUE > >>> Why are there two separate bytecode blocks for the "raise Exception"? > >>> I'd have thought that the double condition would still be evaluated as > >>> one thing, or at least that the jump destinations for both the > >>> early-abort and the main evaluation should be the same. > >>> > >>> ChrisA > >> As an ornery human I could refactor this to avoid the code duplication as > >> > >> 2 0 LOAD_CONST 1 (0) > >> 2 LOAD_FAST 0 (x) > >> 4 DUP_TOP > >> 6 ROT_THREE > >> 8 COMPARE_OP 0 (<) > >> 10 POP_JUMP_IF_TRUE 10 (to 18) > >> 12 POP_TOP > >> >> 14 LOAD_GLOBAL 0 (Exception) > >> 16 RAISE_VARARGS 1 > >> >> 18 LOAD_CONST 2 (10) > >> 20 COMPARE_OP 0 (<) > >> 22 POP_JUMP_IF_FALSE 21 (to 14) > >> 24 LOAD_CONST 0 (None) > >> 26 RETURN_VALUE > >> >>> > >> > >> (there may be mistakes in this) but this is probably too much to expect > >> of the compiler. > > Hmm, I think that depends too much on knowing that the raise won't > > return. That might be a neat optimization (effectively a form of dead > > code removal), but otherwise, the best you could do would be to also > > have it jump out after the raise. > > > > ChrisA > Er, doesn't your original dis output make the same assumption? > Otherwise, after this line > > 20 RAISE_VARARGS 1 > > it would attempt to do an extra pop, then raise a second time. In my original, I expected to see a single RAISE, with a jump over the POP. The thing that surprised me was duplicating the RAISE to avoid the jump. Either way, the behaviour would be the same, though. ChrisA From rshepard at appl-ecosys.com Sat Jun 19 08:43:52 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sat, 19 Jun 2021 05:43:52 -0700 (PDT) Subject: Faker package [RESOLVED] In-Reply-To: <5d5e04b2-5fd9-7fef-ddcb-1561ec68c1c3@mrabarnett.plus.com> References: <7f55cbe8-02b1-9d71-9100-d371ea190056@mrabarnett.plus.com> <5d5e04b2-5fd9-7fef-ddcb-1561ec68c1c3@mrabarnett.plus.com> Message-ID: On Sat, 19 Jun 2021, MRAB wrote: > It looks like you're mixing some Python usage ("faker.names()") in with > command line usage. MRAB, You are correct. That was my problem. > Judging from the docs, I'd say you need something more like: > $ faker -o temp.out name > for 1 fake name or: > $ faker -r=10 -o temp.out name > for 10 fake names. Thank you. I didn't pick that up when I read the document. Much appreciated, Rich From jfong at ms4.hinet.net Fri Jun 18 23:59:45 2021 From: jfong at ms4.hinet.net (Jach Feng) Date: Fri, 18 Jun 2021 20:59:45 -0700 (PDT) Subject: Tkinter problem In-Reply-To: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> References: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> Message-ID: liyaanns... at gmail.com ? 2021?6?18? ?????2:28:35 [UTC+8] ?????? > I am using Colab. How could solve this problem. > import tkinter as Tk > from tkinter import * > import sys > import os > #create main window > master = Tk() > master.title("tester") > master.geometry("300x100") > > > #make a label for the window > label1 = tkinter.Label(master, text='Hellooooo') > # Lay out label > label1.pack() > > # Run forever! > master.mainloop() > The error shows that : > in () > 9 > 10 #create main window > ---> 11 master = Tk() > 12 master.title("tester") > 13 master.geometry("300x100") > > /usr/lib/python3.7/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use) > 2021 baseName = baseName + ext > 2022 interactive = 0 > -> 2023 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) > 2024 if useTk: > 2025 self._loadtk() > > TclError: couldn't connect to display ":0.0" >>> import tkinter as Tk >>> Tk >>> from tkinter import * >>> Tk >>> tkinter Traceback (most recent call last): File "", line 1, in NameError: name 'tkinter' is not defined >>> --Jach From jfong at ms4.hinet.net Sat Jun 19 01:16:18 2021 From: jfong at ms4.hinet.net (Jach Feng) Date: Fri, 18 Jun 2021 22:16:18 -0700 (PDT) Subject: Tkinter problem In-Reply-To: References: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> Message-ID: <2033f21c-81e3-4e91-8213-11625c7b634an@googlegroups.com> Christian Gollwitzer ? 2021?6?19? ?????12:27:54 [UTC+8] ?????? > Am 19.06.21 um 05:59 schrieb Jach Feng: > >>>> import tkinter as Tk > >>>> Tk > > > >>>> from tkinter import * > >>>> Tk > > > >>>> tkinter > > Traceback (most recent call last): > > File "", line 1, in > > NameError: name 'tkinter' is not defined > >>>> > What's the point? That has no relation to the question. > > "import A as B" does not define A. That's a feature, not a bug. > > Christian No, it's not. It's only because this line triggers my response:-) > label1 = tkinter.Label(master, text='Hellooooo') --Jach From jfong at ms4.hinet.net Sat Jun 19 02:48:49 2021 From: jfong at ms4.hinet.net (Jach Feng) Date: Fri, 18 Jun 2021 23:48:49 -0700 (PDT) Subject: Tkinter problem In-Reply-To: References: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> <2033f21c-81e3-4e91-8213-11625c7b634an@googlegroups.com> Message-ID: <82bff357-dafd-4c18-8111-4a12cc355d86n@googlegroups.com> Christian Gollwitzer ? 2021?6?19? ?????1:54:46 [UTC+8] ?????? > Am 19.06.21 um 07:16 schrieb Jach Feng: > > Christian Gollwitzer ? 2021?6?19? ?????12:27:54 [UTC+8] ?????? > >> Am 19.06.21 um 05:59 schrieb Jach Feng: > >>>>>> import tkinter as Tk > >>>>>> Tk > >>> > >>>>>> from tkinter import * > >>>>>> Tk > >>> > >>>>>> tkinter > >>> Traceback (most recent call last): > >>> File "", line 1, in > >>> NameError: name 'tkinter' is not defined > >>>>>> > >> What's the point? That has no relation to the question. > >> > >> "import A as B" does not define A. That's a feature, not a bug. > >> > >> Christian > > No, it's not. It's only because this line triggers my response:-) > >> label1 = tkinter.Label(master, text='Hellooooo') > You have posted this as an answer to Liya's question about Google Colab. > What you wrote has nothing to do with it and does not help with Liya's > problem. > > I guess you wanted to post another question? Then please open a new > thread. In addition, the question is unclear, you just posted a > transcript of three lines of Python. > > Christian I posted to point out there is an error in Liya's script. It's not related to Colab, but it may relate to his problem. --Jach From tjreedy at udel.edu Sat Jun 19 05:23:29 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 19 Jun 2021 05:23:29 -0400 Subject: Strange disassembly In-Reply-To: References: Message-ID: On 6/18/2021 8:13 PM, Chris Angelico wrote: > On Sat, Jun 19, 2021 at 9:50 AM Terry Reedy wrote: >>> Why are there two separate bytecode blocks for the "raise Exception"? >> >> Because one block must POP_TOP and other must not. >> >>> I'd have thought that the double condition would still be evaluated as >>> one thing, or at least that the jump destinations for both the >>> early-abort and the main evaluation should be the same. >> >> To reuse the exception block with POP_TOP, could jump over it after the >> 2nd compare. > > Hmm, fair enough I guess. The compiler figured that it'd be faster to > duplicate the executable code rather than have the jump. I would not assume that any alternative was considered. > It made for a > somewhat confusing disassembly, but I presume it's faster to run. > >> For the simplest and fasted bytecode, write normal logic and let x be >> reloaded instead of duplicated and rotated. >> >> >>> import dis >> >>> def f(x): >> ... if x <= 0 or 10 <= x: raise Exception >> ... >> ... >> >>> dis.dis(f) >> 2 0 LOAD_FAST 0 (x) >> 2 LOAD_CONST 1 (0) >> 4 COMPARE_OP 1 (<=) >> 6 POP_JUMP_IF_TRUE 8 (to 16) >> 8 LOAD_CONST 2 (10) >> 10 LOAD_FAST 0 (x) >> 12 COMPARE_OP 1 (<=) >> 14 POP_JUMP_IF_FALSE 10 (to 20) >> >> 16 LOAD_GLOBAL 0 (Exception) >> 18 RAISE_VARARGS 1 >> >> 20 LOAD_CONST 0 (None) >> 22 RETURN_VALUE >> >>> >> > > Makes sense. I'm not sure if this would actually run faster, but I > can't really justify warping my code around the disassembly :) > > Thanks for the explanation. I guess I just assumed the interpreter > would prefer a jump to the duplication, but that's a decision it's > free to take! -- Terry Jan Reedy From tjreedy at udel.edu Sat Jun 19 05:32:52 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 19 Jun 2021 05:32:52 -0400 Subject: Tkinter problem In-Reply-To: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> References: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> Message-ID: On 6/18/2021 2:28 AM, Liya Ann Sunny wrote: > I am using Colab. How could solve this problem. > import tkinter as Tk If you do this, import 'as tk'. > from tkinter import * The second import overwrites the first since it imports tkinter.Tk as 'Tk'. Don't try to do both. > import sys > import os > #create main window > master = Tk() > master.title("tester") > master.geometry("300x100") > > > #make a label for the window > label1 = tkinter.Label(master, text='Hellooooo') > # Lay out label > label1.pack() > > # Run forever! > master.mainloop() > The error shows that : > in () > 9 > 10 #create main window > ---> 11 master = Tk() > 12 master.title("tester") > 13 master.geometry("300x100") > > /usr/lib/python3.7/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use) > 2021 baseName = baseName + ext > 2022 interactive = 0 > -> 2023 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) > 2024 if useTk: > 2025 self._loadtk() > > TclError: couldn't connect to display ":0.0" > -- Terry Jan Reedy From auriocus at gmx.de Sat Jun 19 00:22:15 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 19 Jun 2021 06:22:15 +0200 Subject: Tkinter problem In-Reply-To: References: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> Message-ID: Am 19.06.21 um 05:59 schrieb Jach Feng: >>>> import tkinter as Tk >>>> Tk > >>>> from tkinter import * >>>> Tk > >>>> tkinter > Traceback (most recent call last): > File "", line 1, in > NameError: name 'tkinter' is not defined >>>> What's the point? That has no relation to the question. "import A as B" does not define A. That's a feature, not a bug. Christian From auriocus at gmx.de Sat Jun 19 00:42:14 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 19 Jun 2021 06:42:14 +0200 Subject: Subpixel positioning on Tk canvas In-Reply-To: <87c1107c-7577-4d4a-8962-e087b0d79f04n@googlegroups.com> References: <48f323d8-b754-48ba-88ed-2eade6d8e230n@googlegroups.com> <87c1107c-7577-4d4a-8962-e087b0d79f04n@googlegroups.com> Message-ID: Am 19.06.21 um 06:26 schrieb George Furbish: > On Saturday, June 19, 2021 at 12:22:31 AM UTC-4, Christian Gollwitzer wrote: >> Am 19.06.21 um 02:03 schrieb George Furbish: >>> Does Tk support interpolation/subpixel positioning of canvas elements? (e.g. images, text.) I have moving elements on my canvas, but the movement isn't very smooth and it's especially obvious when I have text moving alongside an image, since the two elements tend to jump to the next pixel at different times, creating a little judder between the two. >> There is an "improved canvas" available, tkpath, which supports >> antialiasing on all platforms. It is part of, e.g. undroidwish, if you >> want to experiment with it. Last time I tested it had problems on macOS >> though. > > How can I enable or access the improved canvas via Tkinter? > Probably by writing the wrapper for it ;) Sorry for that answer, but Tkinter does not support many of the most useful extensions for Tcl/Tk, because someone has to write the wrappers. It only supports what is provided by base Tk. Among those I consider useful and use in almost any application are: * TkDnD for native drag'n'drop support (there is an inferior python package of the same name which implements local DnD only) * tablelist - complete widget for displaying trees and tables like ttk::treeview, but with almost every feature one could imagine * pdf4tcl - create a PDF from a canvas content, e.g. for printing .... Basically you call Tcl via the eval() method of tkinter; in principle you could do ======================== import tkinter as tk root=tk() root.eval('package require tkpath') root.eval('...here comes your tkpath code...') root.call('.tkp', 'create', 'oval', ....) ============================ tkpath is described here: https://wiki.tcl-lang.org/page/tkpath For the wrapping, look at the implementation files of Tkinter, for say, the original canvas, and modify accordingly. Christian From auriocus at gmx.de Sat Jun 19 01:54:28 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 19 Jun 2021 07:54:28 +0200 Subject: Tkinter problem In-Reply-To: <2033f21c-81e3-4e91-8213-11625c7b634an@googlegroups.com> References: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> <2033f21c-81e3-4e91-8213-11625c7b634an@googlegroups.com> Message-ID: Am 19.06.21 um 07:16 schrieb Jach Feng: > Christian Gollwitzer ? 2021?6?19? ?????12:27:54 [UTC+8] ?????? >> Am 19.06.21 um 05:59 schrieb Jach Feng: >>>>>> import tkinter as Tk >>>>>> Tk >>> >>>>>> from tkinter import * >>>>>> Tk >>> >>>>>> tkinter >>> Traceback (most recent call last): >>> File "", line 1, in >>> NameError: name 'tkinter' is not defined >>>>>> >> What's the point? That has no relation to the question. >> >> "import A as B" does not define A. That's a feature, not a bug. >> >> Christian > No, it's not. It's only because this line triggers my response:-) >> label1 = tkinter.Label(master, text='Hellooooo') You have posted this as an answer to Liya's question about Google Colab. What you wrote has nothing to do with it and does not help with Liya's problem. I guess you wanted to post another question? Then please open a new thread. In addition, the question is unclear, you just posted a transcript of three lines of Python. Christian From manishjain1423 at gmail.com Sat Jun 19 12:14:04 2021 From: manishjain1423 at gmail.com (Manish Jain) Date: Sat, 19 Jun 2021 21:44:04 +0530 Subject: Unable to remove setup of 3.9.5 from Windows 10 Message-ID: Hello Team, I have installed the Python 3.9.5 and trying to remove from the PC through the Uninstall Program (All Possible ways - Through Control Panel or Uninstall Python executable) It just outputs saying Uninstall Successfully but nothing happening (Still listed in Programs List) and even not allowing me to install again. Please let me know if there is any alternate resolution Thanks, Manish From mats at wichmann.us Sat Jun 19 16:55:54 2021 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 19 Jun 2021 14:55:54 -0600 Subject: Unable to remove setup of 3.9.5 from Windows 10 In-Reply-To: References: Message-ID: <55c6ae5a-941b-4614-7bf0-899ce4d0cf0f@wichmann.us> On 6/19/21 10:14 AM, Manish Jain wrote: > Hello Team, > > I have installed the Python 3.9.5 and trying to remove from the PC through > the Uninstall Program (All Possible ways - Through Control Panel or > Uninstall Python executable) > > It just outputs saying Uninstall Successfully but nothing happening (Still > listed in Programs List) and even not allowing me to install again. > > Please let me know if there is any alternate resolution > > Thanks, > Manish > You could try this: https://support.microsoft.com/en-us/topic/fix-problems-that-block-programs-from-being-installed-or-removed-cca7d1b6-65a9-3d98-426b-e9f927e1eb4d From tjreedy at udel.edu Sat Jun 19 19:49:47 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 19 Jun 2021 19:49:47 -0400 Subject: Subpixel positioning on Tk canvas In-Reply-To: References: <48f323d8-b754-48ba-88ed-2eade6d8e230n@googlegroups.com> <87c1107c-7577-4d4a-8962-e087b0d79f04n@googlegroups.com> Message-ID: On 6/19/2021 12:42 AM, Christian Gollwitzer wrote: > Am 19.06.21 um 06:26 schrieb George Furbish: >> On Saturday, June 19, 2021 at 12:22:31 AM UTC-4, Christian Gollwitzer >> wrote: >>> Am 19.06.21 um 02:03 schrieb George Furbish: >>>> Does Tk support interpolation/subpixel positioning of canvas >>>> elements? (e.g. images, text.) I have moving elements on my canvas, >>>> but the movement isn't very smooth and it's especially obvious when >>>> I have text moving alongside an image, since the two elements tend >>>> to jump to the next pixel at different times, creating a little >>>> judder between the two. >>> There is an "improved canvas" available, tkpath, which supports >>> antialiasing on all platforms. It is part of, e.g. undroidwish, if you >>> want to experiment with it. Last time I tested it had problems on macOS >>> though. >> >> How can I enable or access the improved canvas via Tkinter? >> > > Probably by writing the wrapper for it ;) > > Sorry for that answer, but Tkinter does not support many of the most > useful extensions for Tcl/Tk, because someone has to write the wrappers. > It only supports what is provided by base Tk. Among those I consider > useful and use in almost any application are: Are these extensions included with the tcl/tk distribution, or otherwise available from active state? Are this extensions included with Linux installations of tcl/tk? Or easily installed? > * TkDnD for native drag'n'drop support (there is an inferior python > package of the same name which implements local DnD only) > > * tablelist - complete widget for displaying trees and tables like > ttk::treeview, but with almost every feature one could imagine > > * pdf4tcl - create a PDF from a canvas content, e.g. for printing > .... > > Basically you call Tcl via the eval() method of tkinter; in principle > you could do > > ======================== > import tkinter as tk > root=tk() > > root.eval('package require tkpath') > root.eval('...here comes your tkpath code...') > root.call('.tkp', 'create', 'oval', ....) > ============================ > > tkpath is described here: https://wiki.tcl-lang.org/page/tkpath > > For the wrapping, look at the implementation files of Tkinter, for say, > the original canvas, and modify accordingly. > > ????Christian > -- Terry Jan Reedy From alan at csail.mit.edu Sat Jun 19 22:07:12 2021 From: alan at csail.mit.edu (Alan Bawden) Date: Sat, 19 Jun 2021 22:07:12 -0400 Subject: Strange disassembly References: Message-ID: <86a6nli90v.fsf@williamsburg.bawden.org> Chris Angelico writes: >>> sys.version '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' >>> def chk(x): ... if not(0 < x < 10): raise Exception ... >>> dis.dis(chk) 2 0 LOAD_CONST 1 (0) 2 LOAD_FAST 0 (x) 4 DUP_TOP 6 ROT_THREE 8 COMPARE_OP 0 (<) 10 POP_JUMP_IF_FALSE 11 (to 22) 12 LOAD_CONST 2 (10) 14 COMPARE_OP 0 (<) 16 POP_JUMP_IF_TRUE 14 (to 28) 18 LOAD_GLOBAL 0 (Exception) 20 RAISE_VARARGS 1 >> 22 POP_TOP 24 LOAD_GLOBAL 0 (Exception) 26 RAISE_VARARGS 1 >> 28 LOAD_CONST 0 (None) 30 RETURN_VALUE >>> Why are there two separate bytecode blocks for the "raise Exception"? I'd have thought that the double condition would still be evaluated as one thing, or at least that the jump destinations for both the early-abort and the main evaluation should be the same. Looks like in 3.8 it compiles more like the way you expected. I didn't try 3.9, but it looks like a recent change to te compiler. From bluebox03 at gmail.com Sun Jun 20 02:24:29 2021 From: bluebox03 at gmail.com (tommy yama) Date: Sun, 20 Jun 2021 15:24:29 +0900 Subject: Unable to remove setup of 3.9.5 from Windows 10 In-Reply-To: <55c6ae5a-941b-4614-7bf0-899ce4d0cf0f@wichmann.us> References: <55c6ae5a-941b-4614-7bf0-899ce4d0cf0f@wichmann.us> Message-ID: Unrelated topic, but i thought Windows 10 will be retired anytime soon. On Sun, Jun 20, 2021 at 5:58 AM Mats Wichmann wrote: > On 6/19/21 10:14 AM, Manish Jain wrote: > > Hello Team, > > > > I have installed the Python 3.9.5 and trying to remove from the PC > through > > the Uninstall Program (All Possible ways - Through Control Panel or > > Uninstall Python executable) > > > > It just outputs saying Uninstall Successfully but nothing happening > (Still > > listed in Programs List) and even not allowing me to install again. > > > > Please let me know if there is any alternate resolution > > > > Thanks, > > Manish > > > > You could try this: > > > https://support.microsoft.com/en-us/topic/fix-problems-that-block-programs-from-being-installed-or-removed-cca7d1b6-65a9-3d98-426b-e9f927e1eb4d > > -- > https://mail.python.org/mailman/listinfo/python-list > From hjp-python at hjp.at Sun Jun 20 02:59:58 2021 From: hjp-python at hjp.at (Peter J. Holzer) Date: Sun, 20 Jun 2021 08:59:58 +0200 Subject: Unable to remove setup of 3.9.5 from Windows 10 In-Reply-To: References: <55c6ae5a-941b-4614-7bf0-899ce4d0cf0f@wichmann.us> Message-ID: <20210620065958.GA25878@hjp.at> On 2021-06-20 15:24:29 +0900, tommy yama wrote: > Unrelated topic, but i thought Windows 10 will be retired anytime soon. October 2025, according to current plans. So you still have more than 4 years to upgrade to Windows 11 (or better yet, Linux ;-)). 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 liyaannsunny1995 at gmail.com Sun Jun 20 00:21:01 2021 From: liyaannsunny1995 at gmail.com (Liya Ann Sunny) Date: Sat, 19 Jun 2021 21:21:01 -0700 (PDT) Subject: Anaconda navigator not working Message-ID: <56a92952-22ad-42ba-8c93-f6b3f88fb725n@googlegroups.com> After installing Anaconda, I tried to open the anaconda navigator but it did not work. When i check in anaconda prompt by running code >>>anaconda it got error like this (base) C:\Users\Acer>anaconda Traceback (most recent call last): File "C:\Users\Acer\anaconda3\Scripts\anaconda-script.py", line 6, in from binstar_client.scripts.cli import main File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\__init__.py", line 17, in from .utils import compute_hash, jencode, pv File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\__init__.py", line 17, in from .config import (get_server_api, dirs, load_token, store_token, File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\config.py", line 54, in USER_LOGDIR = dirs.user_log_dir File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\appdirs.py", line 257, in user_log_dir return user_log_dir(self.appname, self.appauthor, File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\appdirs.py", line 205, in user_log_dir path = user_data_dir(appname, appauthor, version); version = False File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\appdirs.py", line 67, in user_data_dir path = os.path.join(_get_win_folder(const), appauthor, appname) File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\appdirs.py", line 284, in _get_win_folder_with_pywin32 from win32com.shell import shellcon, shell ImportError: DLL load failed while importing shell: %1 is not a valid Win32 application. what is its solution? From auriocus at gmx.de Sun Jun 20 07:18:18 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sun, 20 Jun 2021 13:18:18 +0200 Subject: Tkinter problem In-Reply-To: <82bff357-dafd-4c18-8111-4a12cc355d86n@googlegroups.com> References: <6ff48a7f-7093-4451-876c-63743ccab072n@googlegroups.com> <2033f21c-81e3-4e91-8213-11625c7b634an@googlegroups.com> <82bff357-dafd-4c18-8111-4a12cc355d86n@googlegroups.com> Message-ID: Am 19.06.21 um 08:48 schrieb Jach Feng: > Christian Gollwitzer ? 2021?6?19? ?????1:54:46 [UTC+8] ?????? >> I guess you wanted to post another question? Then please open a new >> thread. In addition, the question is unclear, you just posted a >> transcript of three lines of Python. > I posted to point out there is an error in Liya's script. It's not related to Colab, but it may relate to his problem. > Ah! Now I get it, sorry, missed that earlier. Christian From rob.cliffe at btinternet.com Sun Jun 20 21:05:00 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Mon, 21 Jun 2021 02:05:00 +0100 Subject: Anaconda navigator not working In-Reply-To: <56a92952-22ad-42ba-8c93-f6b3f88fb725n@googlegroups.com> References: <56a92952-22ad-42ba-8c93-f6b3f88fb725n@googlegroups.com> Message-ID: <286fb530-e923-bbf6-a96b-ce8703be093e@btinternet.com> I'm afraid I can't help at all, but I have many times (well, it feels like many) encountered the ??? "%1 is not a valid Win32 application" error message.? It looks like a format string that has not been given an argument to format. I would guess it's a bug either in Windows or somewhere in Python. Can anybody shed light on this? Best wishes Rob Cliffe PS I have a very vague idea it's to do with mixing 32-bit and 64-bit software. On 20/06/2021 05:21, Liya Ann Sunny wrote: > After installing Anaconda, I tried to open the anaconda navigator but it did not work. > When i check in anaconda prompt by running code >>>> anaconda > it got error like this > (base) C:\Users\Acer>anaconda > Traceback (most recent call last): > File "C:\Users\Acer\anaconda3\Scripts\anaconda-script.py", line 6, in > from binstar_client.scripts.cli import main > File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\__init__.py", line 17, in > from .utils import compute_hash, jencode, pv > File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\__init__.py", line 17, in > from .config import (get_server_api, dirs, load_token, store_token, > File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\config.py", line 54, in > USER_LOGDIR = dirs.user_log_dir > File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\appdirs.py", line 257, in user_log_dir > return user_log_dir(self.appname, self.appauthor, > File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\appdirs.py", line 205, in user_log_dir > path = user_data_dir(appname, appauthor, version); version = False > File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\appdirs.py", line 67, in user_data_dir > path = os.path.join(_get_win_folder(const), appauthor, appname) > File "C:\Users\Acer\anaconda3\lib\site-packages\binstar_client\utils\appdirs.py", line 284, in _get_win_folder_with_pywin32 > from win32com.shell import shellcon, shell > ImportError: DLL load failed while importing shell: %1 is not a valid Win32 application. > > what is its solution? From ayaanasoni at gmail.com Mon Jun 21 01:03:26 2021 From: ayaanasoni at gmail.com (Ayaana Soni) Date: Mon, 21 Jun 2021 10:33:26 +0530 Subject: PYTHON Message-ID: have installed python from your site. After installation my IDLE doesn't work. IDLE is not in my search list. Plz help!! Thank you! From arakelthedragon at gmail.com Mon Jun 21 06:52:32 2021 From: arakelthedragon at gmail.com (Arak Rachael) Date: Mon, 21 Jun 2021 03:52:32 -0700 (PDT) Subject: create an empty RGB image with specified number of cells (rows, columns) Message-ID: <47804d6c-2fab-42f4-93ac-175297867f5dn@googlegroups.com> Hi guys! Does anyone know how to do this, if possible with OpenCv? From pkpearson at nowhere.invalid Mon Jun 21 10:27:05 2021 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 21 Jun 2021 14:27:05 GMT Subject: PYTHON References: Message-ID: On Mon, 21 Jun 2021 10:33:26 +0530, Ayaana Soni wrote: > have installed python from your site. After installation my IDLE doesn't > work. IDLE is not in my search list. Plz help!! "Your site" is ambiguous. Does your computer run Windows, Linux, Apple something, ... ? -- To email me, substitute nowhere->runbox, invalid->com. From drsalists at gmail.com Mon Jun 21 15:19:45 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 21 Jun 2021 12:19:45 -0700 Subject: create an empty RGB image with specified number of cells (rows, columns) In-Reply-To: <47804d6c-2fab-42f4-93ac-175297867f5dn@googlegroups.com> References: <47804d6c-2fab-42f4-93ac-175297867f5dn@googlegroups.com> Message-ID: I don't know about OpenCV, but here's a way of creating a ppm image file of arbitrary size and arbitrary solid color: https://stromberg.dnsalias.org/svn/solid/trunk On Mon, Jun 21, 2021 at 4:01 AM Arak Rachael wrote: > Hi guys! > > Does anyone know how to do this, if possible with OpenCv? > -- > https://mail.python.org/mailman/listinfo/python-list > From auriocus at gmx.de Mon Jun 21 17:37:42 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 21 Jun 2021 23:37:42 +0200 Subject: Subpixel positioning on Tk canvas In-Reply-To: References: <48f323d8-b754-48ba-88ed-2eade6d8e230n@googlegroups.com> <87c1107c-7577-4d4a-8962-e087b0d79f04n@googlegroups.com> Message-ID: Am 20.06.21 um 01:49 schrieb Terry Reedy: > On 6/19/2021 12:42 AM, Christian Gollwitzer wrote: >> Sorry for that answer, but Tkinter does not support many of the most >> useful extensions for Tcl/Tk, because someone has to write the >> wrappers. It only supports what is provided by base Tk. Among those I >> consider useful and use in almost any application are: > > Are these extensions included with the tcl/tk distribution, or otherwise > available from active state?? Are this extensions included with Linux > installations of tcl/tk?? Or easily installed? Since ActiveState has pulled out the developers of Tcl a few years ago, I haven't used ActiveTcl anymore. I was surprised to see that they actually offer a fairly recent version, but it also cannot be simply downloaded, one has to register. It was unclear to me if it costs money. Other people have stepped in to provide Tcl distributions where tese extensions are included; notable exanples are BAWT by Paul Obermeier http://www.bawt.tcl3d.org/download.html which offers all of the mentioned packages (and many more), Androwish/Undroidwish by Christian Werner which was originally developed for Android, but now works on te major desktop platforms, http://androwish.org/home/wiki?name=undroidwish and even kbskit can be mentioned, started by Rene Zaumseil and now updated in irregular intervals by me https://github.com/auriocus/kbskit I haven't checked the major linux distros, but they also might ship with some of these extensions. Concerning installation, it differs. Tablelist (also part of tklib) and pdf4tcl are pure-Tcl packages and therefore easily installed. TkDnD, TkTable and tkTreeCtrl are compiled extensions and therefore more difficult - however, due to the stubs mechanism of Tcl, the version number of Tcl and C compiler do NOT need to match. Typically a binary downloaded for the right OS and bitness will work, and compilation from source works with an autoconf-based configure script. Due to ActiveState's failure with the teapot, the Tcl world does now not any longer have a central repository tool like "pip" which works for everyone. This has just recently been discussed on comp.lang.tcl, but it is unlikely to happen in the near future. It is of course unrealistic to expect that Tkinter supports every odd Tk extension fron the Tcl world, which might not even be maintained any longer. OTOH there are extensions that are well-maintained, that could as well be part of the core Tk, but aren't for political reasons. If Tkinter continues to be the shipped "first choice" GUI for Python, then a few could be included - or otherwise Tkinter will lack Drag'n'drop for ever and a reasonable Tree widget (the core one is verrrry basic). Best regards, Christian From ayaanasoni at gmail.com Tue Jun 22 01:14:04 2021 From: ayaanasoni at gmail.com (Ayaana Soni) Date: Tue, 22 Jun 2021 10:44:04 +0530 Subject: IDLE is not working after Python installation . Message-ID: I have installed python from your site. After installation my IDLE doesn't work. IDLE is not in my search list. Plz help!! Thank you! From arakelthedragon at gmail.com Tue Jun 22 06:36:45 2021 From: arakelthedragon at gmail.com (Arak Rachael) Date: Tue, 22 Jun 2021 03:36:45 -0700 (PDT) Subject: create an empty RGB image with specified number of cells (rows, columns) In-Reply-To: References: <47804d6c-2fab-42f4-93ac-175297867f5dn@googlegroups.com> Message-ID: <31e58571-7df6-439e-80d8-2f55629c9018n@googlegroups.com> On Monday, 21 June 2021 at 21:20:18 UTC+2, Dan Stromberg wrote: > I don't know about OpenCV, but here's a way of creating a ppm image file of > arbitrary size and arbitrary solid color: > https://stromberg.dnsalias.org/svn/solid/trunk > > On Mon, Jun 21, 2021 at 4:01 AM Arak Rachael > wrote: > > Hi guys! > > > > Does anyone know how to do this, if possible with OpenCv? > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Thanks for the help! I am new to Python, one company gave me a 2 month test period to see if I can, but its really hard. This is the assignment: [code] TopGIS Dataset Visualization In this assignment, you will work with satellite images downloaded along a GPS route from TopGIS service. You can download the dataset here: http://download.mykkro.cz/valeo/route.zip . 1. Create a new Python module (package) named topgis-viz. This module will have this basic directory structure: topgis-viz/ config/ # this will contain your YAML configuration files (if any is necessary) config.yaml # a default configuration file data/ # unpack the dataset into this directory (so it contains a subdirectory named topgis with images) target/ # this folder will contain all of your outputs topgisviz/ # this folder will contain the module code __init__.py # all the other stuff setup.py # the setup script for the package requirements.txt README.md # a documentation page, with a short description of the module and usage instructions topgis-test.py .gitignore # don't forget to .gitignore data/ and target/ folders You will use the module by calling it from command line as follows: python topgis-test.py [--config=config/config.yaml] The --config parameter is optional, if not used, the default value config/config.yaml will be used. Use argparse library to read the command line arguments, like this: import argparse parser = argparse.ArgumentParser() parser.add_argument( "-c", "--config", help="Path to the config file." ) args = parser.parse_args() config = args.config When run, this script will read the configuration file in YAML format (read about YAML here: https://yaml.org/) into a Python dictionary. You can use this code: def load_yaml(yaml_path): with open(yaml_path, "r", encoding="utf-8") as infile: return yaml.load(infile, Loader=yaml.FullLoader) The configuration file will look similarly to this: # configuration file for topgis-viz # glob pattern for finding the source files sources: "data/topgis/utm_*.jpg" output_dir: "target/mosaic/" mosaic: columns: 5 rows: 2 cell_width: 250 cell_height: 250 pipeline: - "A0 = src" - "A1 = greyscale A0" - "A2 = red A0" - "A3 = green A0" - "A4 = blue A0" - "B0 = equalized A0" - "B1 = equalized_greyscale A1" - "B2 = equalized A2" - "B3 = equalized A3" - "B4 = equalized A4" These parameters govern what the script will do with the images. The script will: get a list of available images (based on sources parameter, via glob.glob function) and sort it alphabetically in increasing order iterate over the list of images and for each of those source images: create an empty RGB image with specified number of cells (rows, columns) the cells of the grid are denoted by letter-number code indicating column and row. E.g. A0 is top-left cell. run a processing pipeline on the source image. The pipeline is defined by a list of strings, which are evaluated in sequence. The format of each string is as follows: CELL = FUNCTION [ARGS]. E.g. string B0 = equalized A0 means that cell B0 of the grid will be filled with an image that comes as result of calling image function equalized on an image in cell A0. the original size of the images is 1000x1000 pixels. Do the pipeline operations on images with this original size. Resize the images (to cell_width * cell_height) only when putting them into the big mosaic image. the result of the pipeline will be stored in the specified output directory as a JPG image (Use this naming pattern: f"{index:05}.jpg"). The following pipeline functions should be supported: src - just the source image greyscale RGB_IMAGE - returns a greyscale image constructed from RGB_IMAGE red RGB_IMAGE - returns a color image that contains only red channel green RGB_IMAGE - returns a color image that contains only green channel blue RGB_IMAGE - returns a color image that contains only blue channel equalized RGB_IMAGE - returns a color image with equalized intensities equalized_greyscale BW_IMAGE - returns a greyscale image with equalized intensities Most of the functions should be easy to implement. For equalization of colored images, use this function: def equalize_histogram_rgb(rgb_img): # convert from RGB color-space to YCrCb ycrcb_img = cv2.cvtColor(rgb_img, cv2.COLOR_BGR2YCrCb) # equalize the histogram of the Y channel ycrcb_img[:, :, 0] = cv2.equalizeHist(ycrcb_img[:, :, 0]) # convert back to RGB color-space from YCrCb equalized_img = cv2.cvtColor(ycrcb_img, cv2.COLOR_YCrCb2BGR) return equalized_img The cv2.equalizeHist function can be used for equalization of black and white images. Running this script should result with the target/mosaic directory populated with 624 of JPEG images named 00000.jpg to 00623.jpg. Each of these images should be 1250 pixels wide and 500 pixels high and contain a mosaic of images, first row containing original, greyscale, red, green and blue images and the second row should contain the equalized versions of these images. [code] This is my code so far: https://www.dropbox.com/s/qos0gztp4g936tk/topgis-test.py?dl=0 From arakelthedragon at gmail.com Tue Jun 22 06:38:32 2021 From: arakelthedragon at gmail.com (Arak Rachael) Date: Tue, 22 Jun 2021 03:38:32 -0700 (PDT) Subject: create an empty RGB image with specified number of cells (rows, columns) In-Reply-To: References: <47804d6c-2fab-42f4-93ac-175297867f5dn@googlegroups.com> Message-ID: Thanks for the help! I am new to Python, one company gave me a 2 month test period to see if I can, but its really hard. This is the assignment: [code] TopGIS Dataset Visualization In this assignment, you will work with satellite images downloaded along a GPS route from TopGIS service. You can download the dataset here: link removed do to NDA. 1. Create a new Python module (package) named topgis-viz. This module will have this basic directory structure: topgis-viz/ config/ # this will contain your YAML configuration files (if any is necessary) config.yaml # a default configuration file data/ # unpack the dataset into this directory (so it contains a subdirectory named topgis with images) target/ # this folder will contain all of your outputs topgisviz/ # this folder will contain the module code __init__.py # all the other stuff setup.py # the setup script for the package requirements.txt README.md # a documentation page, with a short description of the module and usage instructions topgis-test.py .gitignore # don't forget to .gitignore data/ and target/ folders You will use the module by calling it from command line as follows: python topgis-test.py [--config=config/config.yaml] The --config parameter is optional, if not used, the default value config/config.yaml will be used. Use argparse library to read the command line arguments, like this: import argparse parser = argparse.ArgumentParser() parser.add_argument( "-c", "--config", help="Path to the config file." ) args = parser.parse_args() config = args.config When run, this script will read the configuration file in YAML format (read about YAML here: https://yaml.org/) into a Python dictionary. You can use this code: def load_yaml(yaml_path): with open(yaml_path, "r", encoding="utf-8") as infile: return yaml.load(infile, Loader=yaml.FullLoader) The configuration file will look similarly to this: # configuration file for topgis-viz # glob pattern for finding the source files sources: "data/topgis/utm_*.jpg" output_dir: "target/mosaic/" mosaic: columns: 5 rows: 2 cell_width: 250 cell_height: 250 pipeline: - "A0 = src" - "A1 = greyscale A0" - "A2 = red A0" - "A3 = green A0" - "A4 = blue A0" - "B0 = equalized A0" - "B1 = equalized_greyscale A1" - "B2 = equalized A2" - "B3 = equalized A3" - "B4 = equalized A4" These parameters govern what the script will do with the images. The script will: get a list of available images (based on sources parameter, via glob.glob function) and sort it alphabetically in increasing order iterate over the list of images and for each of those source images: create an empty RGB image with specified number of cells (rows, columns) the cells of the grid are denoted by letter-number code indicating column and row. E.g. A0 is top-left cell. run a processing pipeline on the source image. The pipeline is defined by a list of strings, which are evaluated in sequence. The format of each string is as follows: CELL = FUNCTION [ARGS]. E.g. string B0 = equalized A0 means that cell B0 of the grid will be filled with an image that comes as result of calling image function equalized on an image in cell A0. the original size of the images is 1000x1000 pixels. Do the pipeline operations on images with this original size. Resize the images (to cell_width * cell_height) only when putting them into the big mosaic image. the result of the pipeline will be stored in the specified output directory as a JPG image (Use this naming pattern: f"{index:05}.jpg"). The following pipeline functions should be supported: src - just the source image greyscale RGB_IMAGE - returns a greyscale image constructed from RGB_IMAGE red RGB_IMAGE - returns a color image that contains only red channel green RGB_IMAGE - returns a color image that contains only green channel blue RGB_IMAGE - returns a color image that contains only blue channel equalized RGB_IMAGE - returns a color image with equalized intensities equalized_greyscale BW_IMAGE - returns a greyscale image with equalized intensities Most of the functions should be easy to implement. For equalization of colored images, use this function: def equalize_histogram_rgb(rgb_img): # convert from RGB color-space to YCrCb ycrcb_img = cv2.cvtColor(rgb_img, cv2.COLOR_BGR2YCrCb) # equalize the histogram of the Y channel ycrcb_img[:, :, 0] = cv2.equalizeHist(ycrcb_img[:, :, 0]) # convert back to RGB color-space from YCrCb equalized_img = cv2.cvtColor(ycrcb_img, cv2.COLOR_YCrCb2BGR) return equalized_img The cv2.equalizeHist function can be used for equalization of black and white images. Running this script should result with the target/mosaic directory populated with 624 of JPEG images named 00000.jpg to 00623.jpg. Each of these images should be 1250 pixels wide and 500 pixels high and contain a mosaic of images, first row containing original, greyscale, red, green and blue images and the second row should contain the equalized versions of these images. [code] This is my code so far: https://www.dropbox.com/s/qos0gztp4g936tk/topgis-test.py?dl=0 From tjreedy at udel.edu Tue Jun 22 07:48:38 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 22 Jun 2021 07:48:38 -0400 Subject: IDLE is not working after Python installation . In-Reply-To: References: Message-ID: On 6/22/2021 1:14 AM, Ayaana Soni wrote: > I have installed python from your site. For what OS. > After installation my IDLE doesn't work. How did you try to start it? Did you read the Using Python doc on the website? Can you start python? > IDLE is not in my search list. On Windows and macOS, IDLE is usually started from an installed icon. -- Terry Jan Reedy From mats at wichmann.us Tue Jun 22 10:35:44 2021 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 22 Jun 2021 08:35:44 -0600 Subject: IDLE is not working after Python installation . In-Reply-To: References: Message-ID: On 6/21/21 11:14 PM, Ayaana Soni wrote: > I have installed python from your site. After installation my IDLE doesn't > work. IDLE is not in my search list. Plz help!! > > > > > Thank you! > you asked this before, and didn't answer the questions you got in reply. What does "doesn't work" mean? How is the problem manifested? Doesn't IDLE selected from the start menu come up? Normally the installation creates a shortcut there that "does the right thing". On Windows you don't normally start IDLE by typing a command name. You *can* bring it up from a command-line if you type py -m idlelib but this is definitely not the most common way to launch. If you haven't read it, look at https://docs.python.org/3/using/windows.html among other things, the Microsoft Store version of Python is sometimes a little easier to get started with (it's the same programs, just packaged differently) From drsalists at gmail.com Tue Jun 22 15:33:11 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 22 Jun 2021 12:33:11 -0700 Subject: Python threading comparison Message-ID: I put together a little python runtime comparison, with an embarallel, cpu-heavy threading microbenchmark. It turns out that the performance-oriented Python implementations, Pypy3 and Nuitka3, are both poor at threading, as is CPython of course. On the plus side for CPython, adding cpu-heavy threads doesn't cause performance to get significantly worse anymore. The pleasant result is that Micropython threads pretty well! There's a graph of the performance curves at: https://stromberg.dnsalias.org/~strombrg/python-thread-comparison/ From rosuav at gmail.com Tue Jun 22 16:15:29 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 23 Jun 2021 06:15:29 +1000 Subject: Python threading comparison In-Reply-To: References: Message-ID: On Wed, Jun 23, 2021 at 5:34 AM Dan Stromberg wrote: > > I put together a little python runtime comparison, with an embarallel, > cpu-heavy threading microbenchmark. > > It turns out that the performance-oriented Python implementations, Pypy3 > and Nuitka3, are both poor at threading, as is CPython of course. > > On the plus side for CPython, adding cpu-heavy threads doesn't cause > performance to get significantly worse anymore. > > The pleasant result is that Micropython threads pretty well! > > There's a graph of the performance curves at: > https://stromberg.dnsalias.org/~strombrg/python-thread-comparison/ The legend's collided with some of the graph itself, making it a bit hard to read, but if I'm not mistaken, you have CPython and Nuitka basically identical and worst, and then PyPy much faster but not benefiting from threads, and uPy as the only one that benefits. So what that means is that uPy has a completely different threading/locking model, which is interesting, but all the others are basically just behaving the same way as each other. I'd be curious to know how this would be affected if the threads had a small amount of shared data. Once they get into their main work (summing a range), they're completely independent, apart from potentially sharing integer objects in the low range (which will be completely insignificant in the stats). What if, instead, you create a single global range object and all the threads iterate over it? ChrisA From kayadiwork at gmail.com Tue Jun 22 11:03:53 2021 From: kayadiwork at gmail.com (Kais Ayadi) Date: Tue, 22 Jun 2021 08:03:53 -0700 (PDT) Subject: Optimizing Small Python Code Message-ID: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> Hi There! this is a small python code executed in 61 steps for n in range(1, 7): print (n) for x in range(0, n): print(" ", x) can this code be more optimised? From greg.ewing at canterbury.ac.nz Tue Jun 22 19:04:40 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 23 Jun 2021 11:04:40 +1200 Subject: Optimizing Small Python Code In-Reply-To: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> References: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> Message-ID: On 23/06/21 3:03 am, Kais Ayadi wrote: > for n in range(1, 7): > print (n) > for x in range(0, n): > print(" ", x) > > can this code be more optimised? Optimised for what? Readability? Execution speed? Code size? Memory usage? -- Greg From bschollnick at schollnick.net Tue Jun 22 20:00:16 2021 From: bschollnick at schollnick.net (Benjamin Schollnick) Date: Tue, 22 Jun 2021 20:00:16 -0400 Subject: Optimizing Small Python Code In-Reply-To: References: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> Message-ID: How would you measure the steps that it takes? - Benjamin > On Jun 22, 2021, at 7:04 PM, Greg Ewing wrote: > > On 23/06/21 3:03 am, Kais Ayadi wrote: >> for n in range(1, 7): >> print (n) >> for x in range(0, n): >> print(" ", x) >> can this code be more optimised? > > Optimised for what? Readability? Execution speed? Code size? > Memory usage? > > -- > Greg > -- > https://mail.python.org/mailman/listinfo/python-list From avigross at verizon.net Tue Jun 22 21:53:03 2021 From: avigross at verizon.net (Avi Gross) Date: Tue, 22 Jun 2021 21:53:03 -0400 Subject: Optimizing Small Python Code In-Reply-To: References: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> Message-ID: <012701d767d2$811ccb60$83566220$@verizon.net> I had a similar question, Greg. Optimized for what, indeed. Some might suggest removing a VISIBLE loop is an optimization and some might not. First you need to look at what your code does. It is fairly primitive. Here is a two-line version but is it simpler: for n in range(1, 7): print (n, "\n", ''.join([("\t" + str(x) + "\n") for x in range(0, n)])) It has the same output: 1 0 2 0 1 ... 6 0 1 2 3 4 5 This can be made a one-liner too! LOL! But there are other optimizations as the calculation sort of keeps recalculating what is a simple enough pattern. You can for example in a loop of some kind keep appending to a structure like a list but perhaps simpler is using indexing into a tuple or list made in advance and only once. Here is the code that works for any size by changing the value of "last" without constant recalculation. Is it better? Who knows? last = 7; nl = "\n"; tab = "\t" using = [ tab + str(num) for num in range(0,last)] print(''.join([str(n) + nl + nl.join(using[:n]) + nl for n in range(1, last)])) Now why you want this is beyond me! -----Original Message----- From: Python-list On Behalf Of Greg Ewing Sent: Tuesday, June 22, 2021 7:05 PM To: python-list at python.org Subject: Re: Optimizing Small Python Code On 23/06/21 3:03 am, Kais Ayadi wrote: > for n in range(1, 7): > print (n) > for x in range(0, n): > print(" ", x) > > can this code be more optimised? Optimised for what? Readability? Execution speed? Code size? Memory usage? -- Greg -- https://mail.python.org/mailman/listinfo/python-list From dieter at handshake.de Wed Jun 23 12:24:40 2021 From: dieter at handshake.de (Dieter Maurer) Date: Wed, 23 Jun 2021 18:24:40 +0200 Subject: Optimizing Small Python Code In-Reply-To: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> References: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> Message-ID: <24787.24648.178718.305254@ixdm.fritz.box> Kais Ayadi wrote at 2021-6-22 08:03 -0700: >Hi There! >this is a small python code executed in 61 steps > >for n in range(1, 7): > print (n) > for x in range(0, n): > print(" ", x) > >can this code be more optimised? You should proceed as follows: implement a task in the most straightforward way possible. Only if you hit a problem look for optimizations -- to solve the problem. Small pieces of code rarely need optimizations -- unless they are called very often. Optimizations often aim to reduce runtime. In your code, the runtime is dominated by the output. Output speed is mostly outside your control. Do not try to optimize the code above for runtime. -- Dieter From surethaweweje at gmail.com Wed Jun 23 08:47:41 2021 From: surethaweweje at gmail.com (Suretha Weweje) Date: Wed, 23 Jun 2021 14:47:41 +0200 Subject: Uninstall and Re-install Python - Windows 10 issues Message-ID: After I uninstalled Python 3.7and Python 3.9 and installed Python 3.9.5 and is displayed in Apps & features: Python 3.9.5 Python 3.9.5 (64-bit), size 101 MB, and Python Launcher, size 1.80 MB Upon checking the python version, I get the following error message: C:\>python --version Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases. In the Start Menu, Python 3.9 shortcut is present, and when I click on that it takes me to Python 3.9(64-bit) CMD. Just to test, I add a print statement. Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print("This is Tuesday") This is Tuesday >>> Python 3.9.5 was installed in the C:\Python3.9.5 folder and it seems that not all the files were downloaded and for some reason, old files were added. On the Local Disk (C:) > Python3.9.5 and the folder created for the installation displays: Folders - DLLs, Doc, include, Lib, libs, Scripts, tcl, Tools The date on the above-mentioned folders is the same date as when Python 3.9.5 was installed (2021/06/21) however, the dates are displayed (2021/05/03) on the rest of the files as below: Text Document - LICENSE, NEWS, Application - python, pythonw Application extention - python3.dll, python39.dll, vcruntime140.dll, vcruntime140_1.dll The dates are different from the date of Python 3.9.5 installation I have no way of fully uninstalling the separate python installations and install a new python version. Can someone kindly assist or direct me to where I can find a solution for this? Thank you, Suretha From michael.stemper at gmail.com Wed Jun 23 10:22:50 2021 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Wed, 23 Jun 2021 09:22:50 -0500 Subject: Optimizing Small Python Code In-Reply-To: References: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> <012701d767d2$811ccb60$83566220$@verizon.net> Message-ID: On 23/06/2021 08.17, Stefan Ram wrote: > "Avi Gross" writes: >> This can be made a one-liner too! LOL! > > print( '1\n 0\n2\n 0\n 1\n3\n 0\n 1\n 2\n4\n 0\n 1\n 2\n 3\n5\n 0\n 1\n 2\n 3\n 4\n6\n 0\n 1\n 2\n 3\n 4\n 5\n' ) Unless I'm figuring ot wrong, you just took it from O(n^2) to O(1). That deserves a Turing award or something. -- Michael F. Stemper You can lead a horse to water, but you can't make him talk like Mr. Ed by rubbing peanut butter on his gums. From ayaanasoni at gmail.com Tue Jun 22 22:47:09 2021 From: ayaanasoni at gmail.com (Ayaana Soni) Date: Wed, 23 Jun 2021 08:17:09 +0530 Subject: Python-list Digest, Vol 213, Issue 24 In-Reply-To: References: Message-ID: Thank you it worked using the code you gave!!! On Tue, Jun 22, 2021 at 9:33 PM wrote: > Send Python-list mailing list submissions to > python-list at python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-request at python.org > > You can reach the person managing the list at > python-list-owner at python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > Today's Topics: > > 1. Re: PYTHON (Peter Pearson) > 2. Re: create an empty RGB image with specified number of cells > (rows, columns) (Dan Stromberg) > 3. Re: Subpixel positioning on Tk canvas (Christian Gollwitzer) > 4. IDLE is not working after Python installation . (Ayaana Soni) > 5. Re: create an empty RGB image with specified number of cells > (rows, columns) (Arak Rachael) > 6. Re: create an empty RGB image with specified number of cells > (rows, columns) (Arak Rachael) > 7. Re: IDLE is not working after Python installation . (Terry Reedy) > 8. Re: IDLE is not working after Python installation . > (Mats Wichmann) > > > > ---------- Forwarded message ---------- > From: Peter Pearson > To: python-list at python.org > Cc: > Bcc: > Date: 21 Jun 2021 14:27:05 GMT > Subject: Re: PYTHON > On Mon, 21 Jun 2021 10:33:26 +0530, Ayaana Soni > wrote: > > have installed python from your site. After installation my IDLE doesn't > > work. IDLE is not in my search list. Plz help!! > > "Your site" is ambiguous. > > Does your computer run Windows, Linux, Apple something, ... ? > > -- > To email me, substitute nowhere->runbox, invalid->com. > > > > > ---------- Forwarded message ---------- > From: Dan Stromberg > To: Arak Rachael > Cc: Python List > Bcc: > Date: Mon, 21 Jun 2021 12:19:45 -0700 > Subject: Re: create an empty RGB image with specified number of cells > (rows, columns) > I don't know about OpenCV, but here's a way of creating a ppm image file of > arbitrary size and arbitrary solid color: > https://stromberg.dnsalias.org/svn/solid/trunk > > On Mon, Jun 21, 2021 at 4:01 AM Arak Rachael > wrote: > > > Hi guys! > > > > Does anyone know how to do this, if possible with OpenCv? > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > ---------- Forwarded message ---------- > From: Christian Gollwitzer > To: python-list at python.org > Cc: > Bcc: > Date: Mon, 21 Jun 2021 23:37:42 +0200 > Subject: Re: Subpixel positioning on Tk canvas > Am 20.06.21 um 01:49 schrieb Terry Reedy: > > On 6/19/2021 12:42 AM, Christian Gollwitzer wrote: > >> Sorry for that answer, but Tkinter does not support many of the most > >> useful extensions for Tcl/Tk, because someone has to write the > >> wrappers. It only supports what is provided by base Tk. Among those I > >> consider useful and use in almost any application are: > > > > Are these extensions included with the tcl/tk distribution, or otherwise > > available from active state? Are this extensions included with Linux > > installations of tcl/tk? Or easily installed? > > Since ActiveState has pulled out the developers of Tcl a few years ago, > I haven't used ActiveTcl anymore. I was surprised to see that they > actually offer a fairly recent version, but it also cannot be simply > downloaded, one has to register. It was unclear to me if it costs money. > > Other people have stepped in to provide Tcl distributions where tese > extensions are included; notable exanples are BAWT by Paul Obermeier > http://www.bawt.tcl3d.org/download.html which offers all of the > mentioned packages (and many more), Androwish/Undroidwish by Christian > Werner which was originally developed for Android, but now works on te > major desktop platforms, http://androwish.org/home/wiki?name=undroidwish > and even kbskit can be mentioned, started by Rene Zaumseil and now > updated in irregular intervals by me https://github.com/auriocus/kbskit > > I haven't checked the major linux distros, but they also might ship with > some of these extensions. > > Concerning installation, it differs. Tablelist (also part of tklib) and > pdf4tcl are pure-Tcl packages and therefore easily installed. > TkDnD, TkTable and tkTreeCtrl are compiled extensions and therefore more > difficult - however, due to the stubs mechanism of Tcl, the version > number of Tcl and C compiler do NOT need to match. Typically a binary > downloaded for the right OS and bitness will work, and compilation from > source works with an autoconf-based configure script. > > Due to ActiveState's failure with the teapot, the Tcl world does now not > any longer have a central repository tool like "pip" which works for > everyone. This has just recently been discussed on comp.lang.tcl, but it > is unlikely to happen in the near future. > > It is of course unrealistic to expect that Tkinter supports every odd Tk > extension fron the Tcl world, which might not even be maintained any > longer. OTOH there are extensions that are well-maintained, that could > as well be part of the core Tk, but aren't for political reasons. If > Tkinter continues to be the shipped "first choice" GUI for Python, then > a few could be included - or otherwise Tkinter will lack Drag'n'drop for > ever and a reasonable Tree widget (the core one is verrrry basic). > > Best regards, > > Christian > > > > > > > ---------- Forwarded message ---------- > From: Ayaana Soni > To: python-list at python.org > Cc: > Bcc: > Date: Tue, 22 Jun 2021 10:44:04 +0530 > Subject: IDLE is not working after Python installation . > I have installed python from your site. After installation my IDLE doesn't > work. IDLE is not in my search list. Plz help!! > > > > > Thank you! > > > > > ---------- Forwarded message ---------- > From: Arak Rachael > To: python-list at python.org > Cc: > Bcc: > Date: Tue, 22 Jun 2021 03:36:45 -0700 (PDT) > Subject: Re: create an empty RGB image with specified number of cells > (rows, columns) > On Monday, 21 June 2021 at 21:20:18 UTC+2, Dan Stromberg wrote: > > I don't know about OpenCV, but here's a way of creating a ppm image file > of > > arbitrary size and arbitrary solid color: > > https://stromberg.dnsalias.org/svn/solid/trunk > > > > On Mon, Jun 21, 2021 at 4:01 AM Arak Rachael > > wrote: > > > Hi guys! > > > > > > Does anyone know how to do this, if possible with OpenCv? > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > Thanks for the help! I am new to Python, one company gave me a 2 month > test period to see if I can, but its really hard. > > This is the assignment: > [code] > TopGIS Dataset Visualization > > In this assignment, you will work with satellite images downloaded along a > GPS route from TopGIS service. You can download the dataset here: > http://download.mykkro.cz/valeo/route.zip . > > 1. Create a new Python module (package) named topgis-viz. This module will > have this basic directory structure: > > topgis-viz/ > config/ # this will contain your YAML configuration files (if any > is necessary) > config.yaml # a default configuration file > data/ # unpack the dataset into this directory (so it contains a > subdirectory named topgis with images) > target/ # this folder will contain all of your outputs > topgisviz/ # this folder will contain the module code > __init__.py > # all the other stuff > setup.py # the setup script for the package > requirements.txt > README.md # a documentation page, with a short description of the > module and usage instructions > topgis-test.py > .gitignore # don't forget to .gitignore data/ and target/ folders > > You will use the module by calling it from command line as follows: > > python topgis-test.py [--config=config/config.yaml] > > The --config parameter is optional, if not used, the default value > config/config.yaml will be used. Use argparse library to read the command > line arguments, like this: > > import argparse > > parser = argparse.ArgumentParser() > parser.add_argument( > "-c", > "--config", > help="Path to the config file." > ) > > args = parser.parse_args() > config = args.config > > When run, this script will read the configuration file in YAML format > (read about YAML here: https://yaml.org/) into a Python dictionary. You > can use this code: > > def load_yaml(yaml_path): > with open(yaml_path, "r", encoding="utf-8") as infile: > return yaml.load(infile, Loader=yaml.FullLoader) > > The configuration file will look similarly to this: > > # configuration file for topgis-viz > > # glob pattern for finding the source files > sources: "data/topgis/utm_*.jpg" > output_dir: "target/mosaic/" > mosaic: > columns: 5 > rows: 2 > cell_width: 250 > cell_height: 250 > pipeline: > - "A0 = src" > - "A1 = greyscale A0" > - "A2 = red A0" > - "A3 = green A0" > - "A4 = blue A0" > - "B0 = equalized A0" > - "B1 = equalized_greyscale A1" > - "B2 = equalized A2" > - "B3 = equalized A3" > - "B4 = equalized A4" > > These parameters govern what the script will do with the images. The > script will: > > get a list of available images (based on sources parameter, via > glob.glob function) and sort it alphabetically in increasing order > iterate over the list of images and for each of those source images: > create an empty RGB image with specified number of cells (rows, > columns) > the cells of the grid are denoted by letter-number code indicating > column and row. E.g. A0 is top-left cell. > run a processing pipeline on the source image. The pipeline is > defined by a list of strings, which are evaluated in sequence. The format > of each string is as follows: CELL = FUNCTION [ARGS]. E.g. string B0 = > equalized A0 means that cell B0 of the grid will be filled with an image > that comes as result of calling image function equalized on an image in > cell A0. > the original size of the images is 1000x1000 pixels. Do the > pipeline operations on images with this original size. Resize the images > (to cell_width * cell_height) only when putting them into the big mosaic > image. > the result of the pipeline will be stored in the specified output > directory as a JPG image (Use this naming pattern: f"{index:05}.jpg"). > > The following pipeline functions should be supported: > > src - just the source image > greyscale RGB_IMAGE - returns a greyscale image constructed from > RGB_IMAGE > red RGB_IMAGE - returns a color image that contains only red channel > green RGB_IMAGE - returns a color image that contains only green > channel > blue RGB_IMAGE - returns a color image that contains only blue channel > equalized RGB_IMAGE - returns a color image with equalized intensities > equalized_greyscale BW_IMAGE - returns a greyscale image with > equalized intensities > > Most of the functions should be easy to implement. For equalization of > colored images, use this function: > > def equalize_histogram_rgb(rgb_img): > # convert from RGB color-space to YCrCb > ycrcb_img = cv2.cvtColor(rgb_img, cv2.COLOR_BGR2YCrCb) > > # equalize the histogram of the Y channel > ycrcb_img[:, :, 0] = cv2.equalizeHist(ycrcb_img[:, :, 0]) > > # convert back to RGB color-space from YCrCb > equalized_img = cv2.cvtColor(ycrcb_img, cv2.COLOR_YCrCb2BGR) > > return equalized_img > > The cv2.equalizeHist function can be used for equalization of black and > white images. > > Running this script should result with the target/mosaic directory > populated with 624 of JPEG images named 00000.jpg to 00623.jpg. Each of > these images should be 1250 pixels wide and 500 pixels high and contain a > mosaic of images, first row containing original, greyscale, red, green and > blue images and the second row should contain the equalized versions of > these images. > [code] > > This is my code so far: > https://www.dropbox.com/s/qos0gztp4g936tk/topgis-test.py?dl=0 > > > > > ---------- Forwarded message ---------- > From: Arak Rachael > To: python-list at python.org > Cc: > Bcc: > Date: Tue, 22 Jun 2021 03:38:32 -0700 (PDT) > Subject: Re: create an empty RGB image with specified number of cells > (rows, columns) > Thanks for the help! I am new to Python, one company gave me a 2 month > test period to see if I can, but its really hard. > > This is the assignment: > [code] > TopGIS Dataset Visualization > > In this assignment, you will work with satellite images downloaded along a > GPS route from TopGIS service. You can download the dataset here: link > removed do to NDA. > > 1. Create a new Python module (package) named topgis-viz. This module will > have this basic directory structure: > > topgis-viz/ > config/ # this will contain your YAML configuration files (if any is > necessary) > config.yaml # a default configuration file > data/ # unpack the dataset into this directory (so it contains a > subdirectory named topgis with images) > target/ # this folder will contain all of your outputs > topgisviz/ # this folder will contain the module code > __init__.py > # all the other stuff > setup.py # the setup script for the package > requirements.txt > README.md # a documentation page, with a short description of the module > and usage instructions > topgis-test.py > .gitignore # don't forget to .gitignore data/ and target/ folders > > You will use the module by calling it from command line as follows: > > python topgis-test.py [--config=config/config.yaml] > > The --config parameter is optional, if not used, the default value > config/config.yaml will be used. Use argparse library to read the command > line arguments, like this: > > import argparse > > parser = argparse.ArgumentParser() > parser.add_argument( > "-c", > "--config", > help="Path to the config file." > ) > > args = parser.parse_args() > config = args.config > > When run, this script will read the configuration file in YAML format > (read about YAML here: https://yaml.org/) into a Python dictionary. You > can use this code: > > def load_yaml(yaml_path): > with open(yaml_path, "r", encoding="utf-8") as infile: > return yaml.load(infile, Loader=yaml.FullLoader) > > The configuration file will look similarly to this: > > # configuration file for topgis-viz > > # glob pattern for finding the source files > sources: "data/topgis/utm_*.jpg" > output_dir: "target/mosaic/" > mosaic: > columns: 5 > rows: 2 > cell_width: 250 > cell_height: 250 > pipeline: > - "A0 = src" > - "A1 = greyscale A0" > - "A2 = red A0" > - "A3 = green A0" > - "A4 = blue A0" > - "B0 = equalized A0" > - "B1 = equalized_greyscale A1" > - "B2 = equalized A2" > - "B3 = equalized A3" > - "B4 = equalized A4" > > These parameters govern what the script will do with the images. The > script will: > > get a list of available images (based on sources parameter, via glob.glob > function) and sort it alphabetically in increasing order > iterate over the list of images and for each of those source images: > create an empty RGB image with specified number of cells (rows, columns) > the cells of the grid are denoted by letter-number code indicating column > and row. E.g. A0 is top-left cell. > run a processing pipeline on the source image. The pipeline is defined by > a list of strings, which are evaluated in sequence. The format of each > string is as follows: CELL = FUNCTION [ARGS]. E.g. string B0 = equalized A0 > means that cell B0 of the grid will be filled with an image that comes as > result of calling image function equalized on an image in cell A0. > the original size of the images is 1000x1000 pixels. Do the pipeline > operations on images with this original size. Resize the images (to > cell_width * cell_height) only when putting them into the big mosaic image. > the result of the pipeline will be stored in the specified output > directory as a JPG image (Use this naming pattern: f"{index:05}.jpg"). > > The following pipeline functions should be supported: > > src - just the source image > greyscale RGB_IMAGE - returns a greyscale image constructed from RGB_IMAGE > red RGB_IMAGE - returns a color image that contains only red channel > green RGB_IMAGE - returns a color image that contains only green channel > blue RGB_IMAGE - returns a color image that contains only blue channel > equalized RGB_IMAGE - returns a color image with equalized intensities > equalized_greyscale BW_IMAGE - returns a greyscale image with equalized > intensities > > Most of the functions should be easy to implement. For equalization of > colored images, use this function: > > def equalize_histogram_rgb(rgb_img): > # convert from RGB color-space to YCrCb > ycrcb_img = cv2.cvtColor(rgb_img, cv2.COLOR_BGR2YCrCb) > > # equalize the histogram of the Y channel > ycrcb_img[:, :, 0] = cv2.equalizeHist(ycrcb_img[:, :, 0]) > > # convert back to RGB color-space from YCrCb > equalized_img = cv2.cvtColor(ycrcb_img, cv2.COLOR_YCrCb2BGR) > > return equalized_img > > The cv2.equalizeHist function can be used for equalization of black and > white images. > > Running this script should result with the target/mosaic directory > populated with 624 of JPEG images named 00000.jpg to 00623.jpg. Each of > these images should be 1250 pixels wide and 500 pixels high and contain a > mosaic of images, first row containing original, greyscale, red, green and > blue images and the second row should contain the equalized versions of > these images. > [code] > > This is my code so far: > https://www.dropbox.com/s/qos0gztp4g936tk/topgis-test.py?dl=0 > > > > > ---------- Forwarded message ---------- > From: Terry Reedy > To: python-list at python.org > Cc: > Bcc: > Date: Tue, 22 Jun 2021 07:48:38 -0400 > Subject: Re: IDLE is not working after Python installation . > On 6/22/2021 1:14 AM, Ayaana Soni wrote: > > I have installed python from your site. > > For what OS. > > > After installation my IDLE doesn't work. > > How did you try to start it? Did you read the Using Python doc on the > website? Can you start python? > > > IDLE is not in my search list. > > On Windows and macOS, IDLE is usually started from an installed icon. > > -- > Terry Jan Reedy > > > > > > ---------- Forwarded message ---------- > From: Mats Wichmann > To: python-list at python.org > Cc: > Bcc: > Date: Tue, 22 Jun 2021 08:35:44 -0600 > Subject: Re: IDLE is not working after Python installation . > > On 6/21/21 11:14 PM, Ayaana Soni wrote: > > I have installed python from your site. After installation my IDLE > doesn't > > work. IDLE is not in my search list. Plz help!! > > > > > > > > > > Thank you! > > > > you asked this before, and didn't answer the questions you got in reply. > > What does "doesn't work" mean? How is the problem manifested? Doesn't > IDLE selected from the start menu come up? Normally the installation > creates a shortcut there that "does the right thing". On Windows you > don't normally start IDLE by typing a command name. You *can* bring it > up from a command-line if you type > > py -m idlelib > > but this is definitely not the most common way to launch. > > If you haven't read it, look at > > https://docs.python.org/3/using/windows.html > > > among other things, the Microsoft Store version of Python is sometimes a > little easier to get started with (it's the same programs, just packaged > differently) > > -- > https://mail.python.org/mailman/listinfo/python-list > From larry.martell at gmail.com Wed Jun 23 13:42:42 2021 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 23 Jun 2021 10:42:42 -0700 Subject: creating raw AWS log event Message-ID: When an AWS cloudwatch event is passed to a consumer it looks like this: { "awslogs": { "data": "ewogICAgIm1l..." } } To get the actual message I do this: def _decode(data): compressed_payload = b64decode(data) json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) return json.loads(json_payload) message = _decode(json.dumps(event['awslogs']['data'])) This returns the log message as a string. For my unit tests I need to reverse this - given a message as a string I want to generate the compressed, encoded event structure. I have not been able to get this to work. I have this: message = b'test message' compressed= zlib.compress(message) event['awslogs']['data'] = str(compressed) message = _decode(json.dumps(event['awslogs']['data'])) Traceback (most recent call last): File "", line 1, in File "", line 3, in _decode zlib.error: Error -3 while decompressing data: incorrect header check Anyone see how to make this work? TIA! From robertvstepp at gmail.com Wed Jun 23 14:44:40 2021 From: robertvstepp at gmail.com (boB Stepp) Date: Wed, 23 Jun 2021 13:44:40 -0500 Subject: Uninstall and Re-install Python - Windows 10 issues In-Reply-To: References: Message-ID: Disclaimer: I am no Python or programming expert! However, I recently installed Python 3.9.5 on my Windows 10 laptop, so I may be able to help with some things. On Wed, Jun 23, 2021 at 11:29 AM Suretha Weweje wrote: > > After I uninstalled Python 3.7and Python 3.9 and installed Python 3.9.5 and > is displayed in Apps & features: > > Python 3.9.5 Python 3.9.5 (64-bit), size 101 MB, and > Python Launcher, size 1.80 MB > > Upon checking the python version, I get the following error message: > C:\>python --version > Python was not found; run without arguments to install from the Microsoft > Store, or disable this shortcut from Settings > Manage App Execution > Aliases. Unless you checked the checkbox to add Python to your path in the installer then this is normal. To check your version, instead type: PS C:\Users\boB> py --version Python 3.9.5 If you did not add Python 3.9.5 to your path you will need to use "py" wherever you think you would use "python" to launch whatever, for instance py -m pip install ... if you were going to install a package. BTW, if you *want* to add Python 3.9.5 to your path it is not very difficult to do so. Search online if you do not know how. > In the Start Menu, Python 3.9 shortcut is present, and when I click on that > it takes me to Python 3.9(64-bit) CMD. Just to test, I add a print > statement. > > Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 > bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print("This is Tuesday") > This is Tuesday > >>> > > Python 3.9.5 was installed in the C:\Python3.9.5 folder and it seems that > not all the files were downloaded and for some reason, old files were added. > > On the Local Disk (C:) > Python3.9.5 and the folder created for the > installation displays: > > Folders - DLLs, Doc, include, Lib, libs, Scripts, tcl, Tools > > The date on the above-mentioned folders is the same date as when Python > 3.9.5 was installed (2021/06/21) however, the dates are displayed > (2021/05/03) on the rest of the files as below: > > Text Document - LICENSE, NEWS, > Application - python, pythonw > Application extention - python3.dll, python39.dll, vcruntime140.dll, > vcruntime140_1.dll > The dates are different from the date of Python 3.9.5 installation I believe these differing dates are normal as I show similar results. For instance the individual files you mention all have the same date of "5/3/2021 5:35 PM" on my laptop. However, the folders all have a date of "5/12/2021 7:25 (or 7:24)PM" with one exception, the "Scripts" folder which has a date of "5/28/2021 9:52 PM". This makes sense to me. The heading for this date/time column in the file explorer is "Date modified". Neither of us have "modified" the dll's for instance. The date of release of Python 3.9.5 was, in fact, "5/3/2021", so that checks out. OTOH, after installing Python 3.9.5 I *later* installed (using pip) pytest and spacy. The most recent of these two installations reflects the "Scripts" folder's date modified stamp. If I go into the "Scripts" folder I do in fact see that pytest was installed earlier and its date modified reflects that correct date and time. As for the other folders I believe (Someone correct me if I am mistaken.) that the folder dates normally reflect the installation date by you as that is when those folders were created. However, if you open one of them and examine the contents you will see that the individual files have the Python 3.9.5 release date since you have not modified those files. > I have no way of fully uninstalling the separate python installations and > install a new python version. As for your Python 3.7 installation still being around it all depends. You will get different results when you originally installed Python 3.7.x if you (1) install for all users; (2) install with administrative privileges; or (3) install just for the current user. For instance I had Python 3.7.x installed prior to installing 3.9.5. I uninstalled Python 3.7.x. But it is still available! If I run "py -3.7 --version" I see it is still there. If I look in my Windows Start folder there is an entry for Python 3.7. What gives? In my case my son also uses my laptop and *he* installed his own version of Python 3.7.x as a *user*. My uninstalling *my* installation of Python 3.7.x did not affect his installation. And since my laptop account has administrator privileges I can still see it in the Start Menu, but *not* in the settings uninstall programs list. Perhaps you are experiencing something similar? I don't fully understand how Windows implements user privileges and the full details of what an administrator account can and cannot see. Wiser heads than mine will have to chime in and explain as needed. HTH! boB Stepp From mats at wichmann.us Wed Jun 23 14:45:33 2021 From: mats at wichmann.us (Mats Wichmann) Date: Wed, 23 Jun 2021 12:45:33 -0600 Subject: Uninstall and Re-install Python - Windows 10 issues In-Reply-To: References: Message-ID: <43d76c9f-e648-de4d-6474-a9debbf02661@wichmann.us> On 6/23/21 6:47 AM, Suretha Weweje wrote: > After I uninstalled Python 3.7and Python 3.9 and installed Python 3.9.5 and > is displayed in Apps & features: > > Python 3.9.5 Python 3.9.5 (64-bit), size 101 MB, and > Python Launcher, size 1.80 MB > > Upon checking the python version, I get the following error message: > C:\>python --version > Python was not found; run without arguments to install from the Microsoft > Store, or disable this shortcut from Settings > Manage App Execution > Aliases. > > In the Start Menu, Python 3.9 shortcut is present, and when I click on that > it takes me to Python 3.9(64-bit) CMD. Just to test, I add a print > statement. > > Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 > bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> print("This is Tuesday") > This is Tuesday >>>> In other words, your Python installation is working fine. So what's the problem? > Can someone kindly assist or direct me to where I can find a solution python itself isn't normally in the path. this is in common with every app you install on Windows, where they all go to their own place. some installers force-add their path to the environment, Python gives you a choice, which you can go back to the installer to activate. More commonly, if you use the python.org installer, you also install the Python Launcher which helps with a variety of problems, in particular with making sense of when you have multiple Python versions installed. If you installed that, launch Python by typing "py" (rather than "python"). See here for some more reading: https://docs.python.org/3/using/windows.html From avigross at verizon.net Wed Jun 23 21:56:59 2021 From: avigross at verizon.net (Avi Gross) Date: Wed, 23 Jun 2021 21:56:59 -0400 Subject: Optimizing Small Python Code In-Reply-To: References: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> <012701d767d2$811ccb60$83566220$@verizon.net> Message-ID: <03f201d7689c$3836a090$a8a3e1b0$@verizon.net> Yes, I agree that if you do not need to show your work to a human, then the problem specified could be solved beforeand and a simple print statement would suffice. Ideally you want to make a problem harder such as by specifying an N that varies then testing it with an arbitrary N. But I suggest the item below is not minimal. You can store the printout more compactly as the only symbols out put are tabs, newlines and seven digits. If your language supported some function that expanded a binary string that used say 4 bytes per symbol so it could be printed, or accepted a compressed form of the string and uncompressed it, you might have code like: print(unzip("n*n&&S!~se")) -----Original Message----- From: Python-list On Behalf Of Michael F. Stemper Sent: Wednesday, June 23, 2021 10:23 AM To: python-list at python.org Subject: Re: Optimizing Small Python Code On 23/06/2021 08.17, Stefan Ram wrote: > "Avi Gross" writes: >> This can be made a one-liner too! LOL! > > print( '1\n 0\n2\n 0\n 1\n3\n 0\n 1\n 2\n4\n 0\n 1\n 2\n 3\n5\n 0\n 1\n 2\n 3\n 4\n6\n 0\n 1\n 2\n 3\n 4\n 5\n' ) Unless I'm figuring ot wrong, you just took it from O(n^2) to O(1). That deserves a Turing award or something. -- Michael F. Stemper You can lead a horse to water, but you can't make him talk like Mr. Ed by rubbing peanut butter on his gums. -- https://mail.python.org/mailman/listinfo/python-list From larry.martell at gmail.com Wed Jun 23 22:26:07 2021 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 23 Jun 2021 19:26:07 -0700 Subject: creating raw AWS log event In-Reply-To: References: Message-ID: On Wed, Jun 23, 2021 at 7:05 PM Dennis Lee Bieber wrote: > > On Wed, 23 Jun 2021 10:42:42 -0700, Larry Martell > declaimed the following: > > >def _decode(data): > > compressed_payload = b64decode(data) > > json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) > > return json.loads(json_payload) > > > > >message = b'test message' > >compressed= zlib.compress(message) > >event['awslogs']['data'] = str(compressed) > > Where do you perform a B64 ENCODE operation? > > str() doesn't do that, it just converts the argument to a string which > may mean using escapes for non-printable bytes. B64 converts everything to > printable characters. Copy/paste fail. This is actually the code I tried: message = b'test message' compressed= zlib.compress(message) encoded = b64encode(compressed) event['awslogs']['data'] = str(encoded) message = _decode(json.dumps(event['awslogs']['data'])) From rtm443x at googlemail.com Thu Jun 24 03:00:32 2021 From: rtm443x at googlemail.com (jan) Date: Thu, 24 Jun 2021 08:00:32 +0100 Subject: Optimizing Small Python Code In-Reply-To: <03f201d7689c$3836a090$a8a3e1b0$@verizon.net> References: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> <012701d767d2$811ccb60$83566220$@verizon.net> <03f201d7689c$3836a090$a8a3e1b0$@verizon.net> Message-ID: If I'm not mistaken, the original output is O(n^2) in quantity of chars, and as output time is proportional to the length of the output, that makes the output time also O(n^2) here too. So I guess this only looks like it's reduced to linear because the output here is very small. For large n it would become obvious. jan On 24/06/2021, Avi Gross via Python-list wrote: > Yes, I agree that if you do not need to show your work to a human, then the > problem specified could be solved beforeand and a simple print statement > would suffice. > > Ideally you want to make a problem harder such as by specifying an N that > varies then testing it with an arbitrary N. > > But I suggest the item below is not minimal. You can store the printout > more > compactly as the only symbols out put are tabs, newlines and seven digits. > If your language supported some function that expanded a binary string that > used say 4 bytes per symbol so it could be printed, or accepted a > compressed > form of the string and uncompressed it, you might have code like: > > print(unzip("n*n&&S!~se")) > > -----Original Message----- > From: Python-list On > Behalf Of Michael F. Stemper > Sent: Wednesday, June 23, 2021 10:23 AM > To: python-list at python.org > Subject: Re: Optimizing Small Python Code > > On 23/06/2021 08.17, Stefan Ram wrote: >> "Avi Gross" writes: >>> This can be made a one-liner too! LOL! >> >> print( '1\n 0\n2\n 0\n 1\n3\n 0\n 1\n >> 2\n4\n > 0\n 1\n 2\n 3\n5\n 0\n 1\n 2\n 3\n > 4\n6\n 0\n 1\n 2\n 3\n 4\n 5\n' ) > > Unless I'm figuring ot wrong, you just took it from O(n^2) to O(1). That > deserves a Turing award or something. > > -- > Michael F. Stemper > You can lead a horse to water, but you can't make him talk like Mr. Ed by > rubbing peanut butter on his gums. > -- > https://mail.python.org/mailman/listinfo/python-list > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Thu Jun 24 03:19:14 2021 From: __peter__ at web.de (Peter Otten) Date: Thu, 24 Jun 2021 09:19:14 +0200 Subject: creating raw AWS log event In-Reply-To: References: Message-ID: On 23/06/2021 19:42, Larry Martell wrote: > When an AWS cloudwatch event is passed to a consumer it looks like this: > > { > "awslogs": { > "data": "ewogICAgIm1l..." > } > } > > To get the actual message I do this: > > def _decode(data): > compressed_payload = b64decode(data) > json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) > return json.loads(json_payload) > > message = _decode(json.dumps(event['awslogs']['data'])) > > This returns the log message as a string. > > For my unit tests I need to reverse this - given a message as a string > I want to generate the compressed, encoded event structure. > > I have not been able to get this to work. I have this: > > message = b'test message' > compressed= zlib.compress(message) > event['awslogs']['data'] = str(compressed) > > message = _decode(json.dumps(event['awslogs']['data'])) > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in _decode > zlib.error: Error -3 while decompressing data: incorrect header check > > Anyone see how to make this work? The json/bas64 parts are not involved in the problem: >>> zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS) Traceback (most recent call last): File "", line 1, in zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS) zlib.error: Error -3 while decompressing data: incorrect header check whereas: >>> zlib.decompress(zlib.compress(b"foo")) b'foo' Unfortunately compress() doesn't accept the flags you seem to require. However, reading around a bit in the zlib docs turns up the compressobj which does. So >>> def mycompress(data): obj = zlib.compressobj(wbits=16 + zlib.MAX_WBITS) result = obj.compress(data) result += obj.flush() return result >>> zlib.decompress(mycompress(b"foo"), 16 + zlib.MAX_WBITS) b'foo' From avigross at verizon.net Thu Jun 24 11:58:20 2021 From: avigross at verizon.net (Avi Gross) Date: Thu, 24 Jun 2021 11:58:20 -0400 Subject: Optimizing Small Python Code In-Reply-To: References: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> <012701d767d2$811ccb60$83566220$@verizon.net> <03f201d7689c$3836a090$a8a3e1b0$@verizon.net> Message-ID: <018201d76911$c109e290$431da7b0$@verizon.net> Jan, As an academic discussion, yes, many enhancements only pay off when things are larger. And for most purposes, I/O is so much slower that it makes little difference. But on a multi-processing machine, extra CPU may impact how much else the machine can do at the same time. Here is an example of what I meant. Given exactly the current output, what is the shorter program you can use to cheat and produce an answer. Recall the original output has a length of 169: a = """1 0 2 0 1 3 0 1 2 4 0 1 2 3 5 0 1 2 3 4 6 0 1 2 3 4 5 """ len(a) Now if you had already used a compression algorithm on it, you would get this: import zlib a = zlib.compress(a.encode("ascii")) len(a) Now a has a length of 53! It now looks like this: b'x\x9c3\xe4R\x00\x03\x03.#8\x0bB\x1br\x19c\x88(\x18q\x99p!q\xc1\x00\xa6\xd1\x98\xcb\x14S\x03\x9a\n\x13.3\x82j \xb4\t\x94\x86\x99\t\x00\xdc\x87\x14\xb7' So the shorter cheat program might now be: >>> print(zlib.decompress(b'x\x9c3\xe4R\x00\x03\x03.#8\x0bB\x1br\x19c\x88(\x18q\x99p!q\xc1\x00\xa6\xd1\x98\xcb\x14S\x03\x9a\n\x13.3\x82j \xb4\t\x94\x86\x99\t\x00\xdc\x87\x14\xb7').decode("ASCII")) 1 0 2 0 1 3 0 1 2 4 0 1 2 3 5 0 1 2 3 4 6 0 1 2 3 4 5 Of course, the above has overhead as you have a line to import the library as well as the darn function names but for larger amounts of text, those stay fixed. I note again this won't fool humans but some on-line courses that just take your program and run it and only compare the output will be fooled. -----Original Message----- From: jan Sent: Thursday, June 24, 2021 3:01 AM To: Avi Gross Cc: python-list at python.org Subject: Re: Optimizing Small Python Code If I'm not mistaken, the original output is O(n^2) in quantity of chars, and as output time is proportional to the length of the output, that makes the output time also O(n^2) here too. So I guess this only looks like it's reduced to linear because the output here is very small. For large n it would become obvious. jan On 24/06/2021, Avi Gross via Python-list wrote: > Yes, I agree that if you do not need to show your work to a human, > then the problem specified could be solved beforeand and a simple > print statement would suffice. > > Ideally you want to make a problem harder such as by specifying an N > that varies then testing it with an arbitrary N. > > But I suggest the item below is not minimal. You can store the > printout more compactly as the only symbols out put are tabs, newlines > and seven digits. > If your language supported some function that expanded a binary string > that used say 4 bytes per symbol so it could be printed, or accepted a > compressed form of the string and uncompressed it, you might have code > like: > > print(unzip("n*n&&S!~se")) > > -----Original Message----- > From: Python-list > On Behalf Of > Michael F. Stemper > Sent: Wednesday, June 23, 2021 10:23 AM > To: python-list at python.org > Subject: Re: Optimizing Small Python Code > > On 23/06/2021 08.17, Stefan Ram wrote: >> "Avi Gross" writes: >>> This can be made a one-liner too! LOL! >> >> print( '1\n 0\n2\n 0\n 1\n3\n 0\n 1\n >> 2\n4\n > 0\n 1\n 2\n 3\n5\n 0\n 1\n 2\n 3\n > 4\n6\n 0\n 1\n 2\n 3\n 4\n 5\n' ) > > Unless I'm figuring ot wrong, you just took it from O(n^2) to O(1). > That deserves a Turing award or something. > > -- > Michael F. Stemper > You can lead a horse to water, but you can't make him talk like Mr. Ed > by rubbing peanut butter on his gums. > -- > https://mail.python.org/mailman/listinfo/python-list > > -- > https://mail.python.org/mailman/listinfo/python-list > From larry.martell at gmail.com Thu Jun 24 13:38:28 2021 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 24 Jun 2021 10:38:28 -0700 Subject: creating raw AWS log event In-Reply-To: References: Message-ID: On Thu, Jun 24, 2021 at 12:20 AM Peter Otten <__peter__ at web.de> wrote: > > On 23/06/2021 19:42, Larry Martell wrote: > > When an AWS cloudwatch event is passed to a consumer it looks like this: > > > > { > > "awslogs": { > > "data": "ewogICAgIm1l..." > > } > > } > > > > To get the actual message I do this: > > > > def _decode(data): > > compressed_payload = b64decode(data) > > json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) > > return json.loads(json_payload) > > > > message = _decode(json.dumps(event['awslogs']['data'])) > > > > This returns the log message as a string. > > > > For my unit tests I need to reverse this - given a message as a string > > I want to generate the compressed, encoded event structure. > > > > I have not been able to get this to work. I have this: > > > > message = b'test message' > > compressed= zlib.compress(message) > > event['awslogs']['data'] = str(compressed) > > > > message = _decode(json.dumps(event['awslogs']['data'])) > > Traceback (most recent call last): > > File "", line 1, in > > File "", line 3, in _decode > > zlib.error: Error -3 while decompressing data: incorrect header check > > > > Anyone see how to make this work? > > The json/bas64 parts are not involved in the problem: > > >>> zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS) > Traceback (most recent call last): > File "", line 1, in > zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS) > zlib.error: Error -3 while decompressing data: incorrect header check > > whereas: > > >>> zlib.decompress(zlib.compress(b"foo")) > b'foo' > > Unfortunately compress() doesn't accept the flags you seem to require. > However, reading around a bit in the zlib docs turns up the compressobj > which does. So > > >>> def mycompress(data): > obj = zlib.compressobj(wbits=16 + zlib.MAX_WBITS) > result = obj.compress(data) > result += obj.flush() > return result > > >>> zlib.decompress(mycompress(b"foo"), 16 + zlib.MAX_WBITS) > b'foo' Thanks. Turns out I don't need this after all. From rtm443x at googlemail.com Thu Jun 24 14:05:41 2021 From: rtm443x at googlemail.com (jan) Date: Thu, 24 Jun 2021 19:05:41 +0100 Subject: Optimizing Small Python Code In-Reply-To: <018201d76911$c109e290$431da7b0$@verizon.net> References: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> <012701d767d2$811ccb60$83566220$@verizon.net> <03f201d7689c$3836a090$a8a3e1b0$@verizon.net> <018201d76911$c109e290$431da7b0$@verizon.net> Message-ID: You're right, I was making an academic point. I think this whole compression question relates to Kolmogorov complexity "In algorithmic information theory (a subfield of computer science and mathematics), the Kolmogorov complexity of an object, such as a piece of text, is the length of a shortest computer program (in a predetermined programming language) that produces the object as output". cheers jan On 24/06/2021, Avi Gross via Python-list wrote: > Jan, > > As an academic discussion, yes, many enhancements only pay off when things > are larger. > > And for most purposes, I/O is so much slower that it makes little > difference. But on a multi-processing machine, extra CPU may impact how much > else the machine can do at the same time. > > Here is an example of what I meant. Given exactly the current output, what > is the shorter program you can use to cheat and produce an answer. > > Recall the original output has a length of 169: > > a = """1 > 0 > 2 > 0 > 1 > 3 > 0 > 1 > 2 > 4 > 0 > 1 > 2 > 3 > 5 > 0 > 1 > 2 > 3 > 4 > 6 > 0 > 1 > 2 > 3 > 4 > 5 > """ > > len(a) > > > Now if you had already used a compression algorithm on it, you would get > this: > > import zlib > a = zlib.compress(a.encode("ascii")) > len(a) > > Now a has a length of 53! > > It now looks like this: > > b'x\x9c3\xe4R\x00\x03\x03.#8\x0bB\x1br\x19c\x88(\x18q\x99p!q\xc1\x00\xa6\xd1\x98\xcb\x14S\x03\x9a\n\x13.3\x82j > \xb4\t\x94\x86\x99\t\x00\xdc\x87\x14\xb7' > > So the shorter cheat program might now be: > >>>> print(zlib.decompress(b'x\x9c3\xe4R\x00\x03\x03.#8\x0bB\x1br\x19c\x88(\x18q\x99p!q\xc1\x00\xa6\xd1\x98\xcb\x14S\x03\x9a\n\x13.3\x82j >>>> \xb4\t\x94\x86\x99\t\x00\xdc\x87\x14\xb7').decode("ASCII")) > 1 > 0 > 2 > 0 > 1 > 3 > 0 > 1 > 2 > 4 > 0 > 1 > 2 > 3 > 5 > 0 > 1 > 2 > 3 > 4 > 6 > 0 > 1 > 2 > 3 > 4 > 5 > > Of course, the above has overhead as you have a line to import the library > as well as the darn function names but for larger amounts of text, those > stay fixed. > > I note again this won't fool humans but some on-line courses that just take > your program and run it and only compare the output will be fooled. > > > -----Original Message----- > From: jan > Sent: Thursday, June 24, 2021 3:01 AM > To: Avi Gross > Cc: python-list at python.org > Subject: Re: Optimizing Small Python Code > > If I'm not mistaken, the original output is O(n^2) in quantity of chars, and > as output time is proportional to the length of the output, that makes the > output time also O(n^2) here too. > > So I guess this only looks like it's reduced to linear because the output > here is very small. For large n it would become obvious. > > jan > > On 24/06/2021, Avi Gross via Python-list wrote: >> Yes, I agree that if you do not need to show your work to a human, >> then the problem specified could be solved beforeand and a simple >> print statement would suffice. >> >> Ideally you want to make a problem harder such as by specifying an N >> that varies then testing it with an arbitrary N. >> >> But I suggest the item below is not minimal. You can store the >> printout more compactly as the only symbols out put are tabs, newlines >> and seven digits. >> If your language supported some function that expanded a binary string >> that used say 4 bytes per symbol so it could be printed, or accepted a >> compressed form of the string and uncompressed it, you might have code >> like: >> >> print(unzip("n*n&&S!~se")) >> >> -----Original Message----- >> From: Python-list >> On Behalf Of >> Michael F. Stemper >> Sent: Wednesday, June 23, 2021 10:23 AM >> To: python-list at python.org >> Subject: Re: Optimizing Small Python Code >> >> On 23/06/2021 08.17, Stefan Ram wrote: >>> "Avi Gross" writes: >>>> This can be made a one-liner too! LOL! >>> >>> print( '1\n 0\n2\n 0\n 1\n3\n 0\n 1\n >>> 2\n4\n >> 0\n 1\n 2\n 3\n5\n 0\n 1\n 2\n 3\n >> 4\n6\n 0\n 1\n 2\n 3\n 4\n 5\n' ) >> >> Unless I'm figuring ot wrong, you just took it from O(n^2) to O(1). >> That deserves a Turing award or something. >> >> -- >> Michael F. Stemper >> You can lead a horse to water, but you can't make him talk like Mr. Ed >> by rubbing peanut butter on his gums. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Thu Jun 24 15:12:22 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 24 Jun 2021 20:12:22 +0100 Subject: Optimizing Small Python Code In-Reply-To: <018201d76911$c109e290$431da7b0$@verizon.net> References: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> <012701d767d2$811ccb60$83566220$@verizon.net> <03f201d7689c$3836a090$a8a3e1b0$@verizon.net> <018201d76911$c109e290$431da7b0$@verizon.net> Message-ID: <6405985A-77CA-4214-B12E-87BD150B4E7C@barrys-emacs.org> > On 24 Jun 2021, at 16:58, Avi Gross via Python-list wrote: > > Now a has a length of 53! > > It now looks like this: > > b'x\x9c3\xe4R\x00\x03\x03.#8\x0bB\x1br\x19c\x88(\x18q\x99p!q\xc1\x00\xa6\xd1\x98\xcb\x14S\x03\x9a\n\x13.3\x82j \xb4\t\x94\x86\x99\t\x00\xdc\x87\x14\xb7' > > So the shorter cheat program might now be: The data is smaller, but at the cost of the code that knows how to decompress it. I'd expect that by using compression you have increased memory use as this amount of data is far smaller than code to decompress it. Barry From larry.martell at gmail.com Thu Jun 24 16:28:18 2021 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 24 Jun 2021 13:28:18 -0700 Subject: creating raw AWS log event In-Reply-To: References: Message-ID: On Thu, Jun 24, 2021 at 10:38 AM Larry Martell wrote: > > On Thu, Jun 24, 2021 at 12:20 AM Peter Otten <__peter__ at web.de> wrote: > > > > On 23/06/2021 19:42, Larry Martell wrote: > > > When an AWS cloudwatch event is passed to a consumer it looks like this: > > > > > > { > > > "awslogs": { > > > "data": "ewogICAgIm1l..." > > > } > > > } > > > > > > To get the actual message I do this: > > > > > > def _decode(data): > > > compressed_payload = b64decode(data) > > > json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) > > > return json.loads(json_payload) > > > > > > message = _decode(json.dumps(event['awslogs']['data'])) > > > > > > This returns the log message as a string. > > > > > > For my unit tests I need to reverse this - given a message as a string > > > I want to generate the compressed, encoded event structure. > > > > > > I have not been able to get this to work. I have this: > > > > > > message = b'test message' > > > compressed= zlib.compress(message) > > > event['awslogs']['data'] = str(compressed) > > > > > > message = _decode(json.dumps(event['awslogs']['data'])) > > > Traceback (most recent call last): > > > File "", line 1, in > > > File "", line 3, in _decode > > > zlib.error: Error -3 while decompressing data: incorrect header check > > > > > > Anyone see how to make this work? > > > > The json/bas64 parts are not involved in the problem: > > > > >>> zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS) > > Traceback (most recent call last): > > File "", line 1, in > > zlib.decompress(zlib.compress(b"foo"), 16 + zlib.MAX_WBITS) > > zlib.error: Error -3 while decompressing data: incorrect header check > > > > whereas: > > > > >>> zlib.decompress(zlib.compress(b"foo")) > > b'foo' > > > > Unfortunately compress() doesn't accept the flags you seem to require. > > However, reading around a bit in the zlib docs turns up the compressobj > > which does. So > > > > >>> def mycompress(data): > > obj = zlib.compressobj(wbits=16 + zlib.MAX_WBITS) > > result = obj.compress(data) > > result += obj.flush() > > return result > > > > >>> zlib.decompress(mycompress(b"foo"), 16 + zlib.MAX_WBITS) > > b'foo' > > Thanks. Turns out I don't need this after all. Well I did need this after all and this works perfectly. Thanks so much! From avigross at verizon.net Thu Jun 24 20:21:36 2021 From: avigross at verizon.net (Avi Gross) Date: Thu, 24 Jun 2021 20:21:36 -0400 Subject: Optimizing Small Python Code In-Reply-To: <6405985A-77CA-4214-B12E-87BD150B4E7C@barrys-emacs.org> References: <43c128cc-7164-4904-a003-95ed9be17b06n@googlegroups.com> <012701d767d2$811ccb60$83566220$@verizon.net> <03f201d7689c$3836a090$a8a3e1b0$@verizon.net> <018201d76911$c109e290$431da7b0$@verizon.net> <6405985A-77CA-4214-B12E-87BD150B4E7C@barrys-emacs.org> Message-ID: <062401d76958$0f9c77b0$2ed56710$@verizon.net> Barry, I am not going to continue replying in this thread. I made my point and it was focused after a while on the size of the CODE. Of course, the code can be made ever smaller using gimmicks and yet run longer or use more memory or CPU. If you have control of a package with a short name like "x" for example, you can write a function y() that builds in the code described or any variant and your program becomes: Import x y() and it would print out whatever you need. If you can get the python interpreter to make that module standard, it can be shorted more! As mentioned, one suggested metric for how complex a program is, or maybe how much information it contains, is the shortest program you can write to generate the info. Something already compressed may not be easy to make smaller. But the above idea does not care if the solution takes forever to run as in if it uses lots of tiny re-usable functions and does lots of recursion. Clearly, as has been pointed out, for many of the one-off programs people write here, optimization is not necessarily worthwhile. The program asked for here actually has minimal purpose as it does one thing that could be done in advance and replaced by a print statement. My "contribution" above does look stupid but consider what it would mean if the program asked you to print the first billion prime numbers. The program that simulated the output would likely read in huge file from disk and print it. The first part of the I/O might be much faster if the data on disk was compressed and if it could be uncompressed as it was being read and printed to the output, might be lots faster and even use less memory. Clearly it would likely use more CPU but far less than finding the first billion primes that hard way. Final note is there is not much in the discussion that is really about Python as much of the argument remains similar in many programming languages. So, I am done and will ignore this thread. From: Barry Scott Sent: Thursday, June 24, 2021 3:12 PM To: Avi Gross Cc: python-list at python.org Subject: Re: Optimizing Small Python Code On 24 Jun 2021, at 16:58, Avi Gross via Python-list > wrote: Now a has a length of 53! It now looks like this: b'x\x9c3\xe4R\x00\x03\x03.#8\x0bB\x1br\x19c\x88(\x18q\x99p!q\xc1\x00\xa6\xd1 \x98\xcb\x14S\x03\x9a\n\x13.3\x82j \xb4\t\x94\x86\x99\t\x00\xdc\x87\x14\xb7' So the shorter cheat program might now be: The data is smaller, but at the cost of the code that knows how to decompress it. I'd expect that by using compression you have increased memory use as this amount of data is far smaller than code to decompress it. Barry From grant.b.edwards at gmail.com Thu Jun 24 10:42:55 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 24 Jun 2021 14:42:55 -0000 (UTC) Subject: creating raw AWS log event References: Message-ID: On 2021-06-24, Larry Martell wrote: > On Wed, Jun 23, 2021 at 7:05 PM Dennis Lee Bieber wrote: >> >> On Wed, 23 Jun 2021 10:42:42 -0700, Larry Martell >> declaimed the following: >> >> >def _decode(data): >> > compressed_payload = b64decode(data) >> > json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) >> > return json.loads(json_payload) >> > >> >> >message = b'test message' >> >compressed= zlib.compress(message) >> >event['awslogs']['data'] = str(compressed) >> >> Where do you perform a B64 ENCODE operation? >> >> str() doesn't do that, it just converts the argument to a string which >> may mean using escapes for non-printable bytes. B64 converts everything to >> printable characters. > > Copy/paste fail. This is actually the code I tried: > > message = b'test message' > compressed= zlib.compress(message) > encoded = b64encode(compressed) > event['awslogs']['data'] = str(encoded) Try printout out the result of each step: >>> encoded b'eJwrSS0uUchNLS5OTE8FAB8fBMY=' >>> str(encoded) "b'eJwrSS0uUchNLS5OTE8FAB8fBMY='" Ah, that's not what you want, is it? >>> encoded.decode('ascii') 'eJwrSS0uUchNLS5OTE8FAB8fBMY=' That's better. -- Grant Edwards grant.b.edwards Yow! I think my career at is ruined! gmail.com From greg.ewing at canterbury.ac.nz Thu Jun 24 20:21:40 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 25 Jun 2021 12:21:40 +1200 Subject: How to iterate through maildir messages in python 3? In-Reply-To: <1m1fqh-32gb.ln1@esprimo.zbmc.eu> References: <1m1fqh-32gb.ln1@esprimo.zbmc.eu> Message-ID: On 25/06/21 7:06 am, Chris Green wrote: > In python 2 one can do:- > > for msg in maildir: > print msg # or whatever you want to do with the message > > > However in python 3 this produces "TypeError: string argument > expected, got 'bytes'". > > How should one iterate over a maildir in python3? You're already iterating over it just fine. Your problem is actually how to *print* a mail message. The answer to this will depend on what your purpose is. If you just want a rough-and-ready idea of what the message contains, you could do this: print(repr(msg)) However, that won't work very well if the message doesn't consist of mostly text in an ASCII-compatible encoding. If you want something better, Python comes with some standard library code for dealing with mail messages. Check out the 'email' module. -- Greg From jo at email.com Thu Jun 24 10:23:03 2021 From: jo at email.com (jo) Date: Thu, 24 Jun 2021 14:23:03 +0000 (UTC) Subject: round decimal values Message-ID: Hi, this code generate 4 values with gaussian distribution (mu=5, sigma=1): import numpy as np x = np.random.normal(5, 1, 4) print(x) Output: [5.87879753 3.29162433 3.83024698 4.92997148] I would like to round the output like this: [6, 3, 4, 5] What should I add to the code? Thank you j. From jo at email.com Thu Jun 24 12:27:58 2021 From: jo at email.com (jo) Date: Thu, 24 Jun 2021 16:27:58 +0000 (UTC) Subject: round decimal values References: Message-ID: Il Thu, 24 Jun 2021 18:07:07 +0200, Julio Di Egidio ha scritto: > On 24/06/2021 16:23, jo wrote: >> Hi, >> >> this code generate 4 values with gaussian distribution (mu=5, sigma=1): >> >> import numpy as np x = np.random.normal(5, 1, 4) >> print(x) >> >> Output: >> [5.87879753 3.29162433 3.83024698 4.92997148] >> >> I would like to round the output like this: >> >> [6, 3, 4, 5] >> >> What should I add to the code? >> >> Thank you > > Have a look at numpy.around: > > > HTH, > > Julio Yes, np.around() works fine. Thank you. This is the new code: import numpy as np x = np.random.normal(5, 1, 4) y=np.around(x) print(x) print(y) output: [4.68551569 3.9610641 6.1119447 4.81012246] [5. 4. 6. 5.] Thank you very much, j. From cl at isbd.net Thu Jun 24 15:06:09 2021 From: cl at isbd.net (Chris Green) Date: Thu, 24 Jun 2021 20:06:09 +0100 Subject: How to iterate through maildir messages in python 3? Message-ID: <1m1fqh-32gb.ln1@esprimo.zbmc.eu> In python 2 one can do:- for msg in maildir: print msg # or whatever you want to do with the message However in python 3 this produces "TypeError: string argument expected, got 'bytes'". How should one iterate over a maildir in python3? (I've been here before but this problem is subtly different from the one I had before and I can't find the answer) -- Chris Green ? From mal at europython.eu Fri Jun 25 09:31:32 2021 From: mal at europython.eu (Marc-Andre Lemburg) Date: Fri, 25 Jun 2021 15:31:32 +0200 Subject: EuroPython 2021: Free tickets for Python Core Developers Message-ID: <6969c97d-b6fe-845f-4172-6b5f1680ac92@europython.eu> In 2019, we have set up the Guido van Rossum Core Developer Grant, to make it easy for Python Core Developers to attend EuroPython, but also to give something back to the core team and add a perk to make core development more attractive. If you are a core developer, please check our grant page for details on how to apply: https://www.europython-society.org/core-grant PS: If you are a core developer and want to organize a core sprint, workshop, language summit or similar event at EuroPython 2021, please get in touch with our program workgroup soon, so that we can help arrange things: program at europython.eu PPS: If you want to become a core developer, please have a look at the Python Dev Guide: https://devguide.python.org/coredev/ Quick Summary ------------- EuroPython 2021 will be run online from July 26 - August 1: - Two workshop/training days (July 26 - 27) - Three conference days (July 28 - 30) - Two sprint days (July 31 - August 1) The sessions will be scheduled to ensure they are also accessible for those in the Asian and Americas time zones. More infos are available on our website at https://ep2021.europython.eu/ Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/europython-2021-schedule-published/ Tweet: https://twitter.com/europython/status/1405538503048327169 Enjoy, -- EuroPython 2021 Team https://ep2021.europython.eu/ https://www.europython-society.org/ From cl at isbd.net Fri Jun 25 04:19:49 2021 From: cl at isbd.net (Chris Green) Date: Fri, 25 Jun 2021 09:19:49 +0100 Subject: How to iterate through maildir messages in python 3? References: <1m1fqh-32gb.ln1@esprimo.zbmc.eu> Message-ID: <56ggqh-v2de.ln1@esprimo.zbmc.eu> Greg Ewing wrote: > On 25/06/21 7:06 am, Chris Green wrote: > > In python 2 one can do:- > > > > for msg in maildir: > > print msg # or whatever you want to do with the message > > > > > > However in python 3 this produces "TypeError: string argument > > expected, got 'bytes'". > > > > How should one iterate over a maildir in python3? > > You're already iterating over it just fine. Your problem is > actually how to *print* a mail message. > > The answer to this will depend on what your purpose is. If > you just want a rough-and-ready idea of what the message > contains, you could do this: > > print(repr(msg)) > > However, that won't work very well if the message doesn't > consist of mostly text in an ASCII-compatible encoding. > > If you want something better, Python comes with some standard > library code for dealing with mail messages. Check out the > 'email' module. > The error comes from the line "for msg in maildir:", not the print. Here's the full program where I'm encountering the error (yes, I should have posted this first time around) :- #!/usr/bin/python3 import mailbox import sys import email # open the existing maildir and the target mbox file maildir = mailbox.Maildir(sys.argv [-2], email.message_from_file) mbox = mailbox.mbox(sys.argv[-1]) # lock the mbox mbox.lock() # iterate over messages in the maildir and add to the mbox for msg in maildir: mbox.add(msg) # close and unlock mbox.close() maildir.close() (... and it's not my coding style, just copied) Here's the error trace:- chris$ ./md.py houseSitting fred Traceback (most recent call last): File "/home/chris/tmp/./md.py", line 18, in for msg in maildir: File "/usr/lib/python3.9/mailbox.py", line 110, in itervalues value = self[key] File "/usr/lib/python3.9/mailbox.py", line 77, in __getitem__ return self._factory(file) File "/usr/lib/python3.9/email/__init__.py", line 54, in message_from_file return Parser(*args, **kws).parse(fp) File "/usr/lib/python3.9/email/parser.py", line 56, in parse feedparser.feed(data) File "/usr/lib/python3.9/email/feedparser.py", line 175, in feed self._input.push(data) File "/usr/lib/python3.9/email/feedparser.py", line 103, in push self._partial.write(data) TypeError: string argument expected, got 'bytes' chris$ Line 18 is the "for msg in maildir:". Presumably the program worked as posted under python 2, all I have done is to change the shebang line to use python 3 (I no longer have python 2 on my system, otherwise I'd have used it as this is only a quick and dirty conversion script to be used once). -- Chris Green ? From cl at isbd.net Fri Jun 25 08:58:46 2021 From: cl at isbd.net (Chris Green) Date: Fri, 25 Jun 2021 13:58:46 +0100 Subject: How to iterate through maildir messages in python 3? References: <1m1fqh-32gb.ln1@esprimo.zbmc.eu> <56ggqh-v2de.ln1@esprimo.zbmc.eu> Message-ID: <6h0hqh-64jf.ln1@esprimo.zbmc.eu> Gilmeh Serda wrote: > On Fri, 25 Jun 2021 09:19:49 +0100, Chris Green wrote: > > > TypeError: string argument expected, got 'bytes' > > couple things comes to mind: > > 1. find py2 as archive, put it somewhere and run it from that > Hmm! :-) > 2. convert the bytes to str (find and replace) > How? It's failing at "for msg in maildir:", you can't change it to "for str(msg) in maildir" (well you can but it gives a syntax error). > 3. run the py2>py3 conversion script > That does nothing, says "No files need to be modified" -- Chris Green ? From rosuav at gmail.com Fri Jun 25 12:00:26 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 26 Jun 2021 02:00:26 +1000 Subject: How to iterate through maildir messages in python 3? In-Reply-To: <56ggqh-v2de.ln1@esprimo.zbmc.eu> References: <1m1fqh-32gb.ln1@esprimo.zbmc.eu> <56ggqh-v2de.ln1@esprimo.zbmc.eu> Message-ID: On Sat, Jun 26, 2021 at 12:28 AM Chris Green wrote: > > Greg Ewing wrote: > > On 25/06/21 7:06 am, Chris Green wrote: > > > In python 2 one can do:- > > > > > > for msg in maildir: > > > print msg # or whatever you want to do with the message > > > > > > > > > However in python 3 this produces "TypeError: string argument > > > expected, got 'bytes'". > > > > > > How should one iterate over a maildir in python3? > > > > You're already iterating over it just fine. Your problem is > > actually how to *print* a mail message. > > > > The answer to this will depend on what your purpose is. If > > you just want a rough-and-ready idea of what the message > > contains, you could do this: > > > > print(repr(msg)) > > > > However, that won't work very well if the message doesn't > > consist of mostly text in an ASCII-compatible encoding. > > > > If you want something better, Python comes with some standard > > library code for dealing with mail messages. Check out the > > 'email' module. > > > The error comes from the line "for msg in maildir:", not the print. > > Here's the full program where I'm encountering the error (yes, I > should have posted this first time around) :- > > #!/usr/bin/python3 > > import mailbox > import sys > import email > > > # open the existing maildir and the target mbox file > maildir = mailbox.Maildir(sys.argv [-2], email.message_from_file) > mbox = mailbox.mbox(sys.argv[-1]) > > # iterate over messages in the maildir and add to the mbox > for msg in maildir: > mbox.add(msg) > Maildir says that the factory has to take a binary file object. It looks like email.message_from_file is expecting a text file object, but there's a very similar function message_from_binary_file that might be what you want. Haven't tested it, but worth a try. ChrisA From cl at isbd.net Fri Jun 25 13:56:05 2021 From: cl at isbd.net (Chris Green) Date: Fri, 25 Jun 2021 18:56:05 +0100 Subject: How to iterate through maildir messages in python 3? References: <1m1fqh-32gb.ln1@esprimo.zbmc.eu> <56ggqh-v2de.ln1@esprimo.zbmc.eu> Message-ID: Chris Angelico wrote: > On Sat, Jun 26, 2021 at 12:28 AM Chris Green wrote: > > > > Greg Ewing wrote: > > > On 25/06/21 7:06 am, Chris Green wrote: > > > > In python 2 one can do:- > > > > > > > > for msg in maildir: > > > > print msg # or whatever you want to do with the message > > > > > > > > > > > > However in python 3 this produces "TypeError: string argument > > > > expected, got 'bytes'". > > > > > > > > How should one iterate over a maildir in python3? > > > > > > You're already iterating over it just fine. Your problem is > > > actually how to *print* a mail message. > > > > > > The answer to this will depend on what your purpose is. If > > > you just want a rough-and-ready idea of what the message > > > contains, you could do this: > > > > > > print(repr(msg)) > > > > > > However, that won't work very well if the message doesn't > > > consist of mostly text in an ASCII-compatible encoding. > > > > > > If you want something better, Python comes with some standard > > > library code for dealing with mail messages. Check out the > > > 'email' module. > > > > > The error comes from the line "for msg in maildir:", not the print. > > > > Here's the full program where I'm encountering the error (yes, I > > should have posted this first time around) :- > > > > #!/usr/bin/python3 > > > > import mailbox > > import sys > > import email > > > > > > # open the existing maildir and the target mbox file > > maildir = mailbox.Maildir(sys.argv [-2], email.message_from_file) > > mbox = mailbox.mbox(sys.argv[-1]) > > > > # iterate over messages in the maildir and add to the mbox > > for msg in maildir: > > mbox.add(msg) > > > > Maildir says that the factory has to take a binary file object. It > looks like email.message_from_file is expecting a text file object, > but there's a very similar function message_from_binary_file that > might be what you want. > > Haven't tested it, but worth a try. > Even simpler, just remove email.message_from_file! :-) The following works fine:- #!/usr/bin/python3 import mailbox import sys import email # open the existing maildir and the target mbox file maildir = mailbox.Maildir(sys.argv [-2]) mbox = mailbox.mbox(sys.argv[-1]) # lock the mbox mbox.lock() # iterate over messages in the maildir and add to the mbox for msg in maildir: mbox.add(msg) # close and unlock mbox.close() maildir.close() Thank you for pointing me in the right direction. -- Chris Green ? From cl at isbd.net Sun Jun 27 03:35:29 2021 From: cl at isbd.net (Chris Green) Date: Sun, 27 Jun 2021 08:35:29 +0100 Subject: How to iterate through maildir messages in python 3? References: <1m1fqh-32gb.ln1@esprimo.zbmc.eu> <56ggqh-v2de.ln1@esprimo.zbmc.eu> <7g0cdgpen22qgs1a805j3qshdpkmp2bqo7@4ax.com> Message-ID: <1bmlqh-g5d5.ln1@esprimo.zbmc.eu> Dennis Lee Bieber wrote: > On Fri, 25 Jun 2021 09:19:49 +0100, Chris Green declaimed the > following: > > > > >Here's the full program where I'm encountering the error (yes, I > >should have posted this first time around) :- > > > > #!/usr/bin/python3 > > > > import mailbox > > import sys > > import email > > > > > > # open the existing maildir and the target mbox file > > maildir = mailbox.Maildir(sys.argv [-2], email.message_from_file) > > Is there some reason you are overriding whatever the default "factory" > is for Maildir? > Only that it was 'as copied' off the blog where I found it. As you can see elsewhere in the thread that was exactly the problem, simply removing the email.message_from_file fixed the error. -- Chris Green ? From michael.stemper at gmail.com Mon Jun 28 12:24:15 2021 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Mon, 28 Jun 2021 11:24:15 -0500 Subject: Syntactic sugar Message-ID: I often want to execute a chunk of code n times for iter in range(n): chunkofcode Sometimes, the chunk of code doesn't care about which iteration it's on. A week or two back, I would have sworn that I came across a syntax for the above that eliminates the iteration counter. This morning, I had use for that syntax, but couldn't find it on-line or guess what it was. Does this syntax exist, or am I simply imagining things? Thanks, -- Michael F. Stemper There's no "me" in "team". There's no "us" in "team", either. From michael.stemper at gmail.com Mon Jun 28 14:16:25 2021 From: michael.stemper at gmail.com (Michael F. Stemper) Date: Mon, 28 Jun 2021 13:16:25 -0500 Subject: Syntactic sugar In-Reply-To: References: Message-ID: On 28/06/2021 11.57, Stefan Ram wrote: > "Michael F. Stemper" writes: >> for iter in range(n): >> chunkofcode > > When the counter does not matter, people sometimes write "_": > > for _ in range( n ): > chunkofcode That looks like what I wanted. Thanks! -- Michael F. Stemper Indians scattered on dawn's highway bleeding; Ghosts crowd the young child's fragile eggshell mind. From jerrythefilmmaker at gmail.com Mon Jun 28 12:42:00 2021 From: jerrythefilmmaker at gmail.com (Jerry Thefilmmaker) Date: Mon, 28 Jun 2021 09:42:00 -0700 (PDT) Subject: python: server is not receiving input from client flask Message-ID: <7fe2b8e8-b05a-426f-9000-b4561f4da31an@googlegroups.com> I am new at python but newer at flask, and I'm trying to deploy a web app where I: 1. Send the user the question 2. Get the answer from the user 3. Send additional information based on the answer I am able to send the question but stuck at getting the answer from the user. Base on the answer from the user the server returns a specific answer from a list of dict. Here's my html: THE QUIZ

QUIZ GAME

Welcome

Would you like to play

Enter your answer:
Here's my python code: @app.route("/", methods = ['POST', 'GET']) def play(): qa = questions.qa #list of dict with questions user1, user2 = [], [] #containers for each player's answers if request.method == 'POST': answers = request.form.get('answers') random.shuffle(questions.qa) response = quiz(qa, user1) return response def quiz(qa, user): for rand_q in qa: i = rand_q['question'] i2 = check_answer(i, user) #print(rand_q["question"]) return i2 @app.route("/", methods = ['POST', 'GET']) def check_answer(ans, user): if request.method == 'POST': answers = request.form.get('answers') if 'yes' in answers: user.append('yes') i3 = ans.get(answers, '')#if the client answers "yes" to the question this part iterates over the part corresponds to yes in the list of dict return i3 #this should send 2nd part of question/rand_q Can anyone help me see what I'm doing wrong, and how do I pass the 2nd answer from my list of dict to the client. Thanks! From rosuav at gmail.com Mon Jun 28 14:40:53 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Jun 2021 04:40:53 +1000 Subject: python: server is not receiving input from client flask In-Reply-To: <7fe2b8e8-b05a-426f-9000-b4561f4da31an@googlegroups.com> References: <7fe2b8e8-b05a-426f-9000-b4561f4da31an@googlegroups.com> Message-ID: On Tue, Jun 29, 2021 at 4:36 AM Jerry Thefilmmaker wrote: > @app.route("/", methods = ['POST', 'GET']) > def play(): > > @app.route("/", methods = ['POST', 'GET']) > def check_answer(ans, user): When you're building a Flask app, you're defining a bunch of functions that get called when particular requests come in. There needs to be exactly *one* function for any given request. I would actually recommend making the GET and POST endpoints completely separate here, and designing them in independent functions. One extremely helpful technique here: "If In Doubt, Print It Out". Event-driven code can be hard to debug, so don't be afraid to make extensive use of print() calls to examine various aspects of the incoming request. Even just a simple thing like print("check_answer called") can tell you all kinds of things. HTTP is stateless by nature. You will have to think about each request independently, and figure out how to carry the information you need. Play around with it, have fun, and see what you can learn! ChrisA From lukasz at langa.pl Mon Jun 28 15:12:59 2021 From: lukasz at langa.pl (=?utf-8?Q?=C5=81ukasz_Langa?=) Date: Mon, 28 Jun 2021 21:12:59 +0200 Subject: [RELEASE] Python 3.9.6, 3.8.11, 3.7.11, and 3.6.14 are now available Message-ID: <282BC1D6-8B23-482B-BA19-8987B4CDF3B5@langa.pl> Python 3.9.6 Get it here: https://www.python.org/downloads/release/python-396/ Python 3.9.6 is the newest major stable release of the Python programming language, and it contains many new features and optimizations. There?s been 146 commits since 3.9.5 which is a similar amount compared to 3.8 at the same stage of the release cycle. See the change log for details. On macOS, we encourage you to use the universal2 binary installer variant whenever possible. The legacy 10.9+ Intel-only variant will not be provided for Python 3.10 and the universal2 variant will become the default download for future 3.9.x releases. You may need to upgrade third-party components, like pip, to later versions once they are released. You may experience differences in behavior in IDLE and other Tk-based applications due to using the newer version of Tk. As always, if you encounter problems when using this installer variant, please check https://bugs.python.org for existing reports and for opening new issues. The next Python 3.9 maintenance release will be 3.9.7, currently scheduled for 2021-08-30. The First Security-Only Release of Python 3.8 Get it here: https://www.python.org/downloads/release/python-3811/ Security content in this release contains three fixes. There?s also two fixes for 3.8.10 regressions. Take a look at the change log for details. According to the release calendar specified in PEP 569 , Python 3.8 is now in security fixes only stage of its life cycle: 3.8 branch only accepts security fixes and releases of those are made irregularly in source-only form until October 2024. Python 3.8 isn?t receiving regular bugfixes anymore, and binary installers are no longer provided for it. Python 3.8.10 was the last full bugfix release of Python 3.8 with binary installers. Security releases of 3.7.11 and 3.6.14 Get them here: https://www.python.org/downloads/release/python-3711/ https://www.python.org/downloads/release/python-3614/ Security content in those releases contains five fixes each. Check out the relevant change logs for 3.7.11 and 3.6.14 for details. Similarly to 3.8, Python 3.7 and 3.6 are now in security fixes only stage of their life cycle. Python 3.7 will be providing them until June 2023 while Python 3.6 ends its life in December 2021. We hope you enjoy the new releases Your friendly release team, Ned Deily @nad Steve Dower @steve.dower ?ukasz Langa @ambv -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: Message signed with OpenPGP URL: From jerrythefilmmaker at gmail.com Mon Jun 28 15:46:07 2021 From: jerrythefilmmaker at gmail.com (Jerry Thefilmmaker) Date: Mon, 28 Jun 2021 12:46:07 -0700 (PDT) Subject: python: server is not receiving input from client flask In-Reply-To: References: <7fe2b8e8-b05a-426f-9000-b4561f4da31an@googlegroups.com> Message-ID: On Monday, June 28, 2021 at 2:41:23 PM UTC-4, Chris Angelico wrote: > On Tue, Jun 29, 2021 at 4:36 AM Jerry Thefilmmaker > wrote: > > @app.route("/", methods = ['POST', 'GET']) > > def play(): > > > > @app.route("/", methods = ['POST', 'GET']) > > def check_answer(ans, user): > When you're building a Flask app, you're defining a bunch of functions > that get called when particular requests come in. There needs to be > exactly *one* function for any given request. I would actually > recommend making the GET and POST endpoints completely separate here, > and designing them in independent functions. > > One extremely helpful technique here: "If In Doubt, Print It Out". > Event-driven code can be hard to debug, so don't be afraid to make > extensive use of print() calls to examine various aspects of the > incoming request. Even just a simple thing like print("check_answer > called") can tell you all kinds of things. > > HTTP is stateless by nature. You will have to think about each request > independently, and figure out how to carry the information you need. > Play around with it, have fun, and see what you can learn! > > ChrisA Do you mind elaborating a bit more on making one function for any given request? As far as defining a bunch of functions that get called when particular requests come in I thought that's what I had going on in my codes. No? Also thank you, on making use of the print statement. Thought once I crossed over to the web side there was no more need for it. But what you said makes sense in terms of debugging, because sometimes I couldn't tell whether the client's variable was getting pass to my function which caused it not to be triggered. Thank you! From rosuav at gmail.com Mon Jun 28 15:59:20 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 29 Jun 2021 05:59:20 +1000 Subject: python: server is not receiving input from client flask In-Reply-To: References: <7fe2b8e8-b05a-426f-9000-b4561f4da31an@googlegroups.com> Message-ID: On Tue, Jun 29, 2021 at 5:43 AM Jerry Thefilmmaker wrote: > > Do you mind elaborating a bit more on making one function for any given request? > > As far as defining a bunch of functions that get called when particular requests come in I thought that's what I had going on in my codes. No? > > Also thank you, on making use of the print statement. Thought once I crossed over to the web side there was no more need for it. But what you said makes sense in terms of debugging, because sometimes I couldn't tell whether the client's variable was getting pass to my function which caused it not to be triggered. > > Thank you! > Sure. I'll take a step back and look quickly at the way HTTP works and how Flask figures out what function to call; you probably know all this but it'll make the explanation easier. Every HTTP request has a method (GET, POST, PUT, DELETE, etc) and a request URI. Some of the URI just figures out whether it goes to your server or not, and the rest is which page within your server. So if you're running on, say, port 5000 on the same computer the web browser is on, then you can go to http://localhost:5000/any/path/here and it'll be handled by your web app. Since the "http://localhost:5000" part is the way to find the whole server, Flask just looks at the rest of it - "/any/path/here" - to do its routing. So we have two parts - a path and a method - that define which function is called. When you point your browser at "http://localhost:5000/", that's a GET request (normal web page fetches are GET requests) with a path of "/". When you submit the form, that's a POST request (because the form's method) with a path of "/" (because that's the form's action). I'm assuming here that nothing is getting in the way of that, but that's what printing stuff out can help with. So far, so good. I'm pretty sure none of what I just said is news to you, but let's focus on those two requests: "GET /" and "POST /". The app.route decorator lets you associate a function with some path/method combination. What you have in the code you shared is this: > @app.route("/", methods = ['POST', 'GET']) > def play(): > > @app.route("/", methods = ['POST', 'GET']) > def check_answer(ans, user): That tells Flask that the play function should be associated with "POST /" and "GET /". And then it tells Flask that the check_answer function should be associated with... the same two routes. I suspect that what you actually intend is for one of those functions to just handle GET, and the other to just handle POST. But another way you could fix this would be to change the URL used as the form's action. It's up to you and what your plans are for the rest of this app. (My recommendation is to start out with each function handling just one route - say, "GET /" for play() and "POST /" for check_answer - and only combine them (with multiple keywords in methods=[...]) once you find that the two functions are duplicating a lot of code.) Once that's sorted out, you'll want to figure out exactly what parameters your functions take. As a general rule, the function's parameters will match the placeholders in the route, so if you're not using placeholders, you'll probably just want them all to take no parameters. Here are some examples from a project of mine: @app.route("/login") def login(): @app.route("/force/") def force_timer(id): @app.route("/") @app.route("/editor/") def mainpage(channelid=None): In the case of mainpage, it handles both "GET /" and "GET /editor/12345", so the function might get a parameter and might not - hence it takes a parameter with a default. For what you're doing here, there are no placeholders in your routes, so all your routed functions will take no args (like login in my example - it only ever handles "GET /login", so it doesn't need anything else). Hope that helps! ChrisA From mal at europython.eu Tue Jun 29 10:55:41 2021 From: mal at europython.eu (Marc-Andre Lemburg) Date: Tue, 29 Jun 2021 16:55:41 +0200 Subject: EuroPython 2021: Volume Discount for Company Teams Message-ID: EuroPython 2021 offers special discounts on business tickets for company teams. * EuroPython Volume Discounts * https://ep2021.europython.eu/sponsor/packages/#Volume-Discount If you are going to attend the conference as a team, we offer the following volume discounts as a thank you: - 5 business tickets for the price of 4 - 10 business tickets for the price of 8 - 15 business tickets for the price of 11 In addition to the above offer, we'll also send out a mention on Twitter welcoming your team. Your company should email sponsoring at europython.eu to apply. You will then receive a coupon code and the welcome tweet will be handled by us. You can also visit the ticket shop to view the different ticket types and this year?s schedule to see the timetable for EuroPython 2021 in your local time zone. https://ep2021.europython.eu/registration/buy-tickets/ https://ep2021.europython.eu/schedule/ Quick Summary ------------- EuroPython 2021 will be run online from July 26 - August 1: - Two workshop/training days (July 26 - 27) - Three conference days (July 28 - 30) - Two sprint days (July 31 - August 1) The sessions will be scheduled to ensure they are also accessible for those in the Asian and Americas time zones. More infos are available on our website at https://ep2021.europython.eu/ Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/europython-2021-volume-discount-for-company-teams/ Tweet: https://twitter.com/europython/status/1409886833085980686 Enjoy, -- EuroPython 2021 Team https://ep2021.europython.eu/ https://www.europython-society.org/ From souravbose.aiemd at gmail.com Tue Jun 29 10:01:21 2021 From: souravbose.aiemd at gmail.com (Sourav Bose) Date: Tue, 29 Jun 2021 19:31:21 +0530 Subject: Paramiko installation issue Message-ID: Hello, I was using Python 3.8 32 bit ,but while trying to install the paramiko there is some wheel issue I'm facing. definitely it is due to version mismatching of the python and the paramiko. I have uninstalled 3.8 Could you please help me by providing the exact paramiko files for 3.8 then i will again try to install it other wise check the below paramiko files and let me know which python version is compatible with this. Paramiko files :- pycparser-2.20-py2.py3-none-any.whl -- Installed six-1.16.0-py2.py3-none-any.whl -- Installed PyNaCl-1.4.0-cp37-cp37m-win_amd64.whl -- error cryptography-3.4.7-cp36-abi3-win_amd64.whl --error cffi-1.14.5-cp37-cp37m-win_amd64.whl -- error bcrypt-3.2.0-cp36-abi3-win_amd64.whl -- error paramiko-2.7.2-py2.py3-none-any.whl --error Please help me to get the exact version. Thanks, Sourav 9836231860 -- Thanks & Regards, Sourav Bose, +919836231860 From jerrythefilmmaker at gmail.com Tue Jun 29 11:34:21 2021 From: jerrythefilmmaker at gmail.com (Jerry Thefilmmaker) Date: Tue, 29 Jun 2021 08:34:21 -0700 (PDT) Subject: python: server is not receiving input from client flask In-Reply-To: References: <7fe2b8e8-b05a-426f-9000-b4561f4da31an@googlegroups.com> Message-ID: On Monday, June 28, 2021 at 3:59:54 PM UTC-4, Chris Angelico wrote: > On Tue, Jun 29, 2021 at 5:43 AM Jerry Thefilmmaker > wrote: > > > > Do you mind elaborating a bit more on making one function for any given request? > > > > As far as defining a bunch of functions that get called when particular requests come in I thought that's what I had going on in my codes. No? > > > > Also thank you, on making use of the print statement. Thought once I crossed over to the web side there was no more need for it. But what you said makes sense in terms of debugging, because sometimes I couldn't tell whether the client's variable was getting pass to my function which caused it not to be triggered. > > > > Thank you! > > > Sure. I'll take a step back and look quickly at the way HTTP works and > how Flask figures out what function to call; you probably know all > this but it'll make the explanation easier. > > Every HTTP request has a method (GET, POST, PUT, DELETE, etc) and a > request URI. Some of the URI just figures out whether it goes to your > server or not, and the rest is which page within your server. So if > you're running on, say, port 5000 on the same computer the web browser > is on, then you can go to http://localhost:5000/any/path/here and > it'll be handled by your web app. Since the "http://localhost:5000" > part is the way to find the whole server, Flask just looks at the rest > of it - "/any/path/here" - to do its routing. So we have two parts - a > path and a method - that define which function is called. > > When you point your browser at "http://localhost:5000/", that's a GET > request (normal web page fetches are GET requests) with a path of "/". > > When you submit the form, that's a POST request (because the form's > method) with a path of "/" (because that's the form's action). I'm > assuming here that nothing is getting in the way of that, but that's > what printing stuff out can help with. > > So far, so good. I'm pretty sure none of what I just said is news to > you, but let's focus on those two requests: "GET /" and "POST /". > > The app.route decorator lets you associate a function with some > path/method combination. What you have in the code you shared is this: > > @app.route("/", methods = ['POST', 'GET']) > > def play(): > > > > @app.route("/", methods = ['POST', 'GET']) > > def check_answer(ans, user): > That tells Flask that the play function should be associated with > "POST /" and "GET /". And then it tells Flask that the check_answer > function should be associated with... the same two routes. > > I suspect that what you actually intend is for one of those functions > to just handle GET, and the other to just handle POST. But another way > you could fix this would be to change the URL used as the form's > action. It's up to you and what your plans are for the rest of this > app. > > (My recommendation is to start out with each function handling just > one route - say, "GET /" for play() and "POST /" for check_answer - > and only combine them (with multiple keywords in methods=[...]) once > you find that the two functions are duplicating a lot of code.) > > Once that's sorted out, you'll want to figure out exactly what > parameters your functions take. As a general rule, the function's > parameters will match the placeholders in the route, so if you're not > using placeholders, you'll probably just want them all to take no > parameters. Here are some examples from a project of mine: > > @app.route("/login") > def login(): > > @app.route("/force/") > def force_timer(id): > > @app.route("/") > @app.route("/editor/") > def mainpage(channelid=None): > > In the case of mainpage, it handles both "GET /" and "GET > /editor/12345", so the function might get a parameter and might not - > hence it takes a parameter with a default. For what you're doing here, > there are no placeholders in your routes, so all your routed functions > will take no args (like login in my example - it only ever handles > "GET /login", so it doesn't need anything else). > > Hope that helps! > > ChrisA Thanks for taking the time to explained, Chris. Believe me, it helps. It had me thinking for a while. So, All the stuff about HTTP makes sense. I've been studying and trying to wrap my head around the rest of your explanation and see how I can apply it to my codes. So, if I separate my GET method which would be to get the web page from my POST method which would be assigned to returning value from my form, wouldn't I have to dedicate 2 functions for any given requests in that sense? The only reason I have parameters in my functions is so I can pass value from 1 function to another which is just stuff that happens in the background. Is it necessary to have them in my decorators as well, or is it that these values won't get passed around if they're not integrated in the decorators? From rosuav at gmail.com Tue Jun 29 14:03:27 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Jun 2021 04:03:27 +1000 Subject: python: server is not receiving input from client flask In-Reply-To: References: <7fe2b8e8-b05a-426f-9000-b4561f4da31an@googlegroups.com> Message-ID: On Wed, Jun 30, 2021 at 3:38 AM Jerry Thefilmmaker wrote: > Thanks for taking the time to explained, Chris. Believe me, it helps. It had me thinking for a while. So, All the stuff about HTTP makes sense. I've been studying and trying to wrap my head around the rest of your explanation and see how I can apply it to my codes. > Glad to hear it :) > So, if I separate my GET method which would be to get the web page from my POST method which would be assigned to returning value from my form, wouldn't I have to dedicate 2 functions for any given requests in that sense? > The web page and form response are two completely separate requests. You can't think of them as a single request; in fact, it's entirely possible for someone to send the POST request without first getting the page at all. > The only reason I have parameters in my functions is so I can pass value from 1 function to another which is just stuff that happens in the background. Is it necessary to have them in my decorators as well, or is it that these values won't get passed around if they're not integrated in the decorators? > They won't get passed around. The only way to share that information is via the page itself (or something along those lines, like a session variable - which is some magic built on top of cookies). Think about the two requests completely independently, and make sure that (a) the GET request sends back the correct page, and (b) the POST request does whatever it needs to, and sends back a new page. Hopefully that should set you in the right direction! ChrisA From python at mrabarnett.plus.com Tue Jun 29 15:15:13 2021 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 29 Jun 2021 20:15:13 +0100 Subject: Paramiko installation issue In-Reply-To: References: Message-ID: <6937b9e4-6dac-439d-f037-92f296189132@mrabarnett.plus.com> On 2021-06-29 15:01, Sourav Bose wrote: > Hello, > I was using Python 3.8 32 bit ,but while trying to install the paramiko > there is some wheel issue I'm facing. definitely it is due to version > mismatching of the python and the paramiko. > I have uninstalled 3.8 > Could you please help me by providing the exact paramiko files for 3.8 then > i will again try to install it other wise check the below paramiko files > and let me know which python version is compatible with this. > Paramiko files :- > pycparser-2.20-py2.py3-none-any.whl -- Installed > six-1.16.0-py2.py3-none-any.whl -- Installed > PyNaCl-1.4.0-cp37-cp37m-win_amd64.whl -- error > cryptography-3.4.7-cp36-abi3-win_amd64.whl --error > cffi-1.14.5-cp37-cp37m-win_amd64.whl -- error > bcrypt-3.2.0-cp36-abi3-win_amd64.whl -- error > paramiko-2.7.2-py2.py3-none-any.whl --error > > Please help me to get the exact version. > If the name contains "cp37" then it's for CPython 3.7, and so on. Install the Python version (ideally the latest version) and then use the python launcher, "py". For example, if you installed Python 3.9, typing: py on the Windows command line (in a Command Prompt window) should start it. From the Windows command line, install the packages by calling the pip module via the Python launcher: py -m pip install paramiko and so on. That should pick up and install the correct version. From jerrythefilmmaker at gmail.com Tue Jun 29 16:07:42 2021 From: jerrythefilmmaker at gmail.com (Jerry Thefilmmaker) Date: Tue, 29 Jun 2021 13:07:42 -0700 (PDT) Subject: python: server is not receiving input from client flask In-Reply-To: References: <7fe2b8e8-b05a-426f-9000-b4561f4da31an@googlegroups.com> Message-ID: <84f4e236-8f42-4527-b285-fc5989a67ae3n@googlegroups.com> On Tuesday, June 29, 2021 at 2:03:58 PM UTC-4, Chris Angelico wrote: > On Wed, Jun 30, 2021 at 3:38 AM Jerry Thefilmmaker > wrote: > > Thanks for taking the time to explained, Chris. Believe me, it helps. It had me thinking for a while. So, All the stuff about HTTP makes sense. I've been studying and trying to wrap my head around the rest of your explanation and see how I can apply it to my codes. > > > Glad to hear it :) > > So, if I separate my GET method which would be to get the web page from my POST method which would be assigned to returning value from my form, wouldn't I have to dedicate 2 functions for any given requests in that sense? > > > The web page and form response are two completely separate requests. > You can't think of them as a single request; in fact, it's entirely > possible for someone to send the POST request without first getting > the page at all. > > The only reason I have parameters in my functions is so I can pass value from 1 function to another which is just stuff that happens in the background. Is it necessary to have them in my decorators as well, or is it that these values won't get passed around if they're not integrated in the decorators? > > > They won't get passed around. The only way to share that information > is via the page itself (or something along those lines, like a session > variable - which is some magic built on top of cookies). Think about > the two requests completely independently, and make sure that (a) the > GET request sends back the correct page, and (b) the POST request does > whatever it needs to, and sends back a new page. > > Hopefully that should set you in the right direction! > > ChrisA Got it. It all makes sense. It feels like I'm doing all the right things, accounting for all functions but somehow it's not working. I changed my methods. Adjusted my routes. Still the same thing. Now I get this error: i3 = ans.get(answers, '') AttributeError: 'str' object has no attribute 'get' Which doesn't make sense because my object ans is a dictionary and get method here is supposed to get another value within the dictionary based on the key value of answers which is passed from the client. Does that make sense? -------------------------------------------------------------------------------------------------------------------------------------------------------------- Here's my modified code by the way: @app.route("/") def main(): return render_template('app.html') @app.route("/play", methods = ['GET']) def play(): qa = questions.qa #list of dict with questions #user1, user2 = [], [] #containers for each player's answers if request.method == 'GET': answers = request.form.get('answers') random.shuffle(questions.qa) response = quiz(qa) print(answers) return response def quiz(qa): for rand_q in qa: i = rand_q['question'] i2 = check_answer(i) return render_template('app.html') + i, i2 @app.route("/check_answer/", methods = ['POST']) def check_answer(ans): user1 = [] if request.method == 'POST': answers = request.form.get('answers') if 'yes' in answers: print(ans) user1.append('yes') i3 = ans.get(answers, '') return i3 ---------------------------------------------------------------------------------------------------------------------------------------------------------- Here's my form from the html file:
Enter your answer:
Also, where do I see my print statement in this case? Mind you the codes worked fine before I attempted to use flask. From rosuav at gmail.com Tue Jun 29 16:32:14 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 30 Jun 2021 06:32:14 +1000 Subject: python: server is not receiving input from client flask In-Reply-To: <84f4e236-8f42-4527-b285-fc5989a67ae3n@googlegroups.com> References: <7fe2b8e8-b05a-426f-9000-b4561f4da31an@googlegroups.com> <84f4e236-8f42-4527-b285-fc5989a67ae3n@googlegroups.com> Message-ID: On Wed, Jun 30, 2021 at 6:21 AM Jerry Thefilmmaker wrote: > @app.route("/check_answer/", methods = ['POST']) > def check_answer(ans): > >
> Enter your answer: > >
What you're creating here is a route with a placeholder. The check_answer function will handle POST requests to /check_answer/foo, /check_answer/spam, /check_answer/barney, /check_answer/whatever. In each case, the variable "ans" will be given the part of the URL that represents - the string "foo" or "spam" or "barney" or whatever. It's never going to carry a dictionary around. I'll stress this again: *Your requests must be independently handled*. You can't think of passing information from one request to another, because there might not have been a previous request. Moving to the web means thinking differently about things; you no longer have control flow from one part of the program to another, you instead have independent handlers that have to think exclusively about their own requests. This might mean carrying some extra information through the form. For instance, you could include a question ID of some sort (using for that purpose), and then you could have a global constant with all of your prewritten questions. There are other ways to carry information around, but they have to go via the request itself; you can't keep variables from one function to another. > Also, where do I see my print statement in this case? Mind you the codes worked fine before I attempted to use flask. Hmm, that depends on how you're running your code. Ideally, you should have a server running somewhere - a terminal window or equivalent - and if you're using Flask's default server (werkzeug), it will be reporting every request as it goes through. It might look something like this: INFO:geventwebsocket.handler:127.0.0.1 - - [2021-06-30 06:30:51] "GET / HTTP/1.1" 200 10267 1.569960 INFO:geventwebsocket.handler:127.0.0.1 - - [2021-06-30 06:30:52] "GET /api/twitch_schedule?channelid=49497888 HTTP/1.1" 200 593 1.403456 INFO:geventwebsocket.handler:127.0.0.1 - - [2021-06-30 06:31:06] "GET / HTTP/1.1" 200 10267 1.724949 INFO:geventwebsocket.handler:127.0.0.1 - - [2021-06-30 06:31:07] "GET /api/twitch_schedule?channelid=49497888 HTTP/1.1" 200 593 1.277206 Your print calls will insert messages into that log, prior to their corresponding summary lines (the summary is written when you return a response, so that's at the very end of your function). ChrisA