From alan at csail.mit.edu Fri Jan 1 00:23:38 2021 From: alan at csail.mit.edu (Alan Bawden) Date: Fri, 01 Jan 2021 00:23:38 -0500 Subject: Control stript which is runing in background. References: Message-ID: <86a6ttjkmd.fsf@williamsburg.bawden.org> jak writes: Running the command: $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe the three texts do not mix.... The three texts do not mix as long at the contents of bible.txt is short enough (and provided `cat' only calls `write' once). In the POSIX specification, the manual page for the `write' system call describes writing to a pipe or FIFO as follows: Write requests of {PIPE_BUF} bytes or less shall not be interleaved with data from other processes doing writes on the same pipe. Writes of greater than {PIPE_BUF} bytes may have data interleaved, on arbitrary boundaries, with writes by other processes, whether or not the O_NONBLOCK flag of the file status flags is set. -- Alan Bawden From nospam at please.ty Fri Jan 1 04:58:48 2021 From: nospam at please.ty (jak) Date: Fri, 1 Jan 2021 10:58:48 +0100 Subject: Control stript which is runing in background. References: <86a6ttjkmd.fsf@williamsburg.bawden.org> Message-ID: Il 01/01/2021 06:23, Alan Bawden ha scritto: > jak writes: > > Running the command: > > $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe > > the three texts do not mix.... > > The three texts do not mix as long at the contents of bible.txt is short > enough (and provided `cat' only calls `write' once). In the POSIX > specification, the manual page for the `write' system call describes > writing to a pipe or FIFO as follows: > > Write requests of {PIPE_BUF} bytes or less shall not be interleaved > with data from other processes doing writes on the same pipe. Writes > of greater than {PIPE_BUF} bytes may have data interleaved, on > arbitrary boundaries, with writes by other processes, whether or not > the O_NONBLOCK flag of the file status flags is set. > Ok. And... ...Running the command: $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe the three texts do not mix.... From __peter__ at web.de Fri Jan 1 05:03:34 2021 From: __peter__ at web.de (Peter Otten) Date: Fri, 1 Jan 2021 11:03:34 +0100 Subject: Funny error message In-Reply-To: References: Message-ID: <3ab14244-7681-a93b-57f9-75a6bb7beacb@web.de> On 31/12/2020 23:46, Bob van der Poel wrote: > When I run python from the command line and generate an error I get the > following: > > Python 3.8.5 (default, Jul 28 2020, 12:59:40) > [GCC 9.3.0] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> z > /home/bob/.local/lib/python3.8/site-packages/requests/__init__.py:89: > RequestsDependencyWarning: urllib3 (1.24.3) or chardet (4.0.0) doesn't > match a supported version! > warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported " > Traceback (most recent call last): > File "", line 1, in > NameError: name 'z' is not defined > > I understand "z in not defined" ... but what's with the warnings? It looks like Python tries to import requests as a side effect of printing the traceback. Start the interpreter in verbose mode $ python -v and trigger the name error again to see which module triggers that import. From nospam at please.ty Fri Jan 1 05:11:47 2021 From: nospam at please.ty (jak) Date: Fri, 1 Jan 2021 11:11:47 +0100 Subject: Control stript which is runing in background. References: Message-ID: Il 01/01/2021 04:14, 2QdxY4RzWzUUiLuE at potatochowder.com ha scritto: > On 2021-01-01 at 03:43:43 +0100, > Regarding "Re: Control stript which is runing in background.," > jak wrote: > >> Il 01/01/2021 01:43, Cameron Simpson ha scritto: >>> On 01Jan2021 01:21, jak wrote: >>>> Il 01/01/2021 00:58, 2QdxY4RzWzUUiLuE at potatochowder.com ha scritto: >>>>> Most of the time, I have several shells open, often with their own >>>>> background jobs running. Limiting write permission on the pipe to "me" >>>>> wouldn't prevent concurrent access. >>>> >>>> This is true but there would be no difference if this happened through >>>> a socket. >>> >>> Accessing a socket makes a distinct separate data connection - other >>> openers do not conflict with it. That's the critical difference between >>> a socket and a pipe in terms of functionality, and why sockets have a >>> connect/accept step. >>> >>> Cheers, >>> Cameron Simpson >>> >> >> Maybe the fact that I'm not English and I don't know the language well >> doesn't allow me to express myself clearly. Try it one more time: >> The OP would like to give some command to a script that is running. How? >> With a script that sends commands to it. One of the ways, as mentioned, >> is by using a mini socket server. Given the needs of the OP and the fact >> that sockets are a limited resource in a system, I took the liberty of >> proposing a simple alternative: using a named pipe, also because, IMO, >> sockets, in this case, are an overkill. with a few lines of code in a >> thread in the running script they can allow it to receive commands: >> #----------------- >> import os, errno >> >> fnpipe = 'cmdpipe' >> >> try: >> os.mkfifo(fnpipe) >> except OSError as e: >> if e.errno != errno.EEXIST: >> raise >> while True: >> with open(fnpipe, 'rt', 1) as fifo: >> for line in fifo: >> print(line, ends='') >> #----------------- >> >> Running the command: >> >> $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > >> cmdpipe >> >> the three texts do not mix. IMO, the OP should be enough. after that, I >> know that a pipe is more like a queue than a soket and in this case a >> socket, IMO, is wasted. > > Only the OP knows for sure. :-) Does the server send data back to the > client that made the request? Are the requests (and the responses, if > any) small enough to be sent/received atomically? *If* the answers are > no and yes, then you're right, a named pipe would be good enough. If > not, then a socket *might* be better. Until the OP clarifies, we can't > tell. > >> greetings, hoping to have been clearer than before. > > I think you were clear enough before, but you may not have considered > things the OP did not specify. One of the hardest parts of software > development is understanding and specifying the actual problem to be > solved. I've never done that in a second language (I'm nowhere near > fluent in anything other than English); I can only imagine the extra > layers of complexity. > This is the OP's initial request: > Hi. > I would like to make something like this: > A python script would run headlessly in the background. > I would like to control the script from the command line using other python scripts or from the python shell. > From time to time I would ask the main script to create a popup window with an image or a plot. > What would be the proper way to approach it. How to make communication between two scripts? > Thank you. > Petro. I have suggested an alternative way for his necessity. It will be up to him to decide which one he should adopt. That way he has a choice, at least. I don't know where you work. I know, however, that in these zones, if you do more than necessary wasting their time, they will kick you away. From mkarkera98 at gmail.com Fri Jan 1 06:17:42 2021 From: mkarkera98 at gmail.com (Meghna Karkera) Date: Fri, 1 Jan 2021 16:47:42 +0530 Subject: Plotting in python for Monte Carlo Method Message-ID: Dear Respected Sir May I request you to help me plot the number of histories versus standard deviation along with mean for integral of 2x dx from 0 to 5 abtained using the Monte Carlo python program. I've calculated the integral of 2x dx from 0 to 5 using the Monte Carlo method described in the following link. https://youtu.be/WAf0rqwAvgg Thanks Sincerely Meghna From nulla.epistola at web.de Fri Jan 1 07:45:06 2021 From: nulla.epistola at web.de (Sibylle Koczian) Date: Fri, 1 Jan 2021 13:45:06 +0100 Subject: help In-Reply-To: <46b11e77-ac1c-3071-3a07-8b23fb0c898c@wichmann.us> References: <46b11e77-ac1c-3071-3a07-8b23fb0c898c@wichmann.us> Message-ID: <8e3d9019-a318-2f03-1c69-58a48a6f5fd9@web.de> Am 31.12.2020 um 18:06 schrieb Mats Wichmann: >> What you're doing is going to give you probably unexpected results > anyway. Here's why:? (when it's set up properly) when clicking from > explorer Windows will create a window to run the Python interpreter in, > and when your script finishes, Python quits. Windows will take that as a > clue that the window is no longer needed, and it will be discarded. This > will usually have the visual effect of a window flashing onto the screen > and then vanishing, as if things were broken, but they're not.? Only a > Python script that is written to manage a display window, is going to > stay around. An old is to add an input() call at the end of your script, > so it waits for you to hit the enter key before finishing, and that will > leave the window open) > But that doesn't help, if the script raises an exception. In that case the input() call won't be reached and the window will close anyway before you could see anything. And in a script with errors that's even worse. Same effect with the "run" window. > Either run your scripts from a command shell... > It's really bad that Windows doesn't put links to the command shell on the desktop and into the task bar on installation. > Or use an editor or IDE that has an integrated way to run your programs > there in the editor's environment - here the IDE manages the windows so > you don't get the opens-then-closes effect. > > Hope this helps. > From nulla.epistola at web.de Fri Jan 1 07:45:06 2021 From: nulla.epistola at web.de (Sibylle Koczian) Date: Fri, 1 Jan 2021 13:45:06 +0100 Subject: help In-Reply-To: <46b11e77-ac1c-3071-3a07-8b23fb0c898c@wichmann.us> References: <46b11e77-ac1c-3071-3a07-8b23fb0c898c@wichmann.us> Message-ID: <8e3d9019-a318-2f03-1c69-58a48a6f5fd9@web.de> Am 31.12.2020 um 18:06 schrieb Mats Wichmann: >> What you're doing is going to give you probably unexpected results > anyway. Here's why:? (when it's set up properly) when clicking from > explorer Windows will create a window to run the Python interpreter in, > and when your script finishes, Python quits. Windows will take that as a > clue that the window is no longer needed, and it will be discarded. This > will usually have the visual effect of a window flashing onto the screen > and then vanishing, as if things were broken, but they're not.? Only a > Python script that is written to manage a display window, is going to > stay around. An old is to add an input() call at the end of your script, > so it waits for you to hit the enter key before finishing, and that will > leave the window open) > But that doesn't help, if the script raises an exception. In that case the input() call won't be reached and the window will close anyway before you could see anything. And in a script with errors that's even worse. Same effect with the "run" window. > Either run your scripts from a command shell... > It's really bad that Windows doesn't put links to the command shell on the desktop and into the task bar on installation. > Or use an editor or IDE that has an integrated way to run your programs > there in the editor's environment - here the IDE manages the windows so > you don't get the opens-then-closes effect. > > Hope this helps. > From john.steve.ur at gmail.com Fri Jan 1 08:22:26 2021 From: john.steve.ur at gmail.com (john steve) Date: Fri, 1 Jan 2021 05:22:26 -0800 (PST) Subject: Why do I have both /usr/lib/python3 and /usr/lib/python3.8? In-Reply-To: References: <9ftrbh-97i3.ln1@esprimo.zbmc.eu> Message-ID: On Wednesday, December 30, 2020 at 9:03:28 AM UTC-8, Chris Green wrote: > Anssi Saari wrote: > > Chris Green writes: > > > > > Why are there both /usr/lib/python3 and /usr/lib/python3.8 on my > > > x[ubuntu] system? > > > > While it's more of an Ubuntu (or Debian) question better asked in some > > relevant Linux forum, in the end it's because some package managers > > decided to do that. You can use commands like these to see which > > packages put stuff in which directory: > > > > dpkg -S /usr/lib/python3.8 > > dpkg -S /usr/lib/python3 > > > > On my Debian system the corresponding output looks like this: > > > > $ dpkg -S /usr/lib/python3.7 > > python3.7, libpython3.7-minimal:amd64, python3-tk:amd64, > > libpython3.7-dev:amd64, libpython3.7-stdlib:amd64, libpython3.7:amd64, > > python3-distutils, python3-lib2to3: /usr/lib/python3.7 > > > > $ dpkg -S /usr/lib/python3 > > python3-scipy, python3-opengl, python3-statsmodels, iotop, > > python3-reportlab-accel:amd64, python3-magic, python3-pkg-resources, > > python3-kiwisolver, python3.7, python3-pandas-lib, python3-kerberos, > > python3-lz4, python3-renderpm:amd64, python3-numexpr, > > python3-cffi-backend, python3-crypto, python3-tables, python3-rencode, > > python3-gi, python3-dbus, devscripts, python3-gpg, python3-pyasn1, > > python3-py, python3-eyed3, pdfarranger, python3-pip, python3-virtualenv, > > xpra, python3-pandas, python3-pil:amd64, python3-requests, > > python3-urllib3, python3-psutil, python3-paramiko, python3-netifaces, > > python3-patsy, python3-gssapi, python3-sklearn, python3-cycler, > > python3-sip, python3-cairo:amd64, python3-six, python3-chardet, > > python3-nose, python3-debian, python3-wheel, python3-attr, > > python3-soupsieve, python3-bcrypt, python3-bs4, python3-sklearn-lib, > > python3-scour, python3-setuptools, python3-entrypoints, > > python3-gi-cairo, python3-cups, python3-keyrings.alt, python3-pluggy, > > python3-tz, python3-ifaddr, python3-joblib, python3-cvxopt, > > python3-secretstorage, python3-reportlab, python3-more-itertools, > > python3-keyring, python3-asn1crypto, python3-html5lib, python3-dns, > > python3-decorator, python3-dateutil, meson, python3-pexpect, > > python3-idna, python3-seaborn, lsb-release, python3-numpy, > > python3-brotli, python3-tables-lib, python3-lxml:amd64, python3-pytest, > > python3-simplejson, python3-nacl, python3-zeroconf, python3-xdg, > > python3-libvoikko, python3-gst-1.0, python3-pypdf2, python3-evdev, > > python3-matplotlib, python3-statsmodels-lib, python3-cryptography, > > python3-certifi, python3-atomicwrites, python3-pyparsing, > > python3-ptyprocess, python3-webencodings, piper, python3-uno, > > python3-apt, python3-setproctitle:amd64, hplip: /usr/lib/python3 > > > > So I'd say as a rule stuff relevant to the specific version of python > > goes in the specific version directory (i.e. /usr/lib/python3.8 in your > > case) and python software packages in general go in /usr/lib/python3. > > > Yes, there are some oddities though, for example python3.7 seems to be > installed in both locations (python3.8 in my case). > > -- > Chris Green > ? some tools require any of them. From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Jan 1 08:49:48 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 1 Jan 2021 07:49:48 -0600 Subject: Control stript which is runing in background. In-Reply-To: References: Message-ID: On 2021-01-01 at 11:11:47 +0100, jak wrote: > Il 01/01/2021 04:14, 2QdxY4RzWzUUiLuE at potatochowder.com ha scritto: > > On 2021-01-01 at 03:43:43 +0100, > > jak wrote: > > > > I think you were clear enough before, but you may not have > > considered things the OP did not specify. One of the hardest parts > > of software development is understanding and specifying the actual > > problem to be solved. I've never done that in a second language > > (I'm nowhere near fluent in anything other than English); I can only > > imagine the extra layers of complexity. > > This is the OP's initial request: > > > Hi. I would like to make something like this: > > A python script would run headlessly in the background. > > I would like to control the script from the command line using other python scripts or from the python shell. > > From time to time I would ask the main script to create a popup window with an image or a plot. > > What would be the proper way to approach it. How to make communication between two scripts? > > Thank you. > > Petro. > > I have suggested an alternative way for his necessity. > It will be up to him to decide which one he should adopt. That way he > has a choice, at least. > I don't know where you work. I know, however, that in these zones, if > you do more than necessary wasting their time, they will kick you away. So what is necessary? Does "control the script" include reporting success or failure of a request? The OP also said "communication between two scripts," which to me means two way traffic. Only the OP knows for sure, and at least one of us might get it wrong if we don't ask, or at least acknowledge that we don't know. If I start with a named pipe because it's good enough for Phase Zero, or Version 0.0.1, or Release Experimental Alpha, then I'm going to end up ripping that out or reinventing something that already existed on top of that named pipe. Suppose I look ahead just a little, and use a socket in the first place. Yes, you could argue that it's more than what was necessary and kick me away. Will you kick me again when you can build on it (I can't; I'm gone) instead of having to rebuild what already worked? I'm retired now, but I at one employer, I worked on products with (a) lifetimes measured in decades, (b) extremely expensive (money, time, convenience, etc.) upgrade/maintenance cycles, and therefore (c) strict interoperability requirements.? A little bit of foresight and extra analysis up front went a long way towards saving a lot of headaches and development resources (and customers!) in the long term. Communications protocols in particular had to be well thought out, and often more complex than was immediately necessary, because backwards and forwards compatibility were not negotiable. Again, I'm not (and no one else is, either) saying that your solution is wrong or won't work. Your solution may even be the be the best solution to the OP's problem. All I'm saying is that we can't know until the OP tells us more. Yes, the OP has a choice to make. Maybe we have helped, not by making that choice, but by giving it to the OP with enough supporting information to make it. ? Think about a system containing dozens of individually field upgradeable components. It had to work when a customer upgraded one component at a time (over the course of weeks or months), or plugged in an old component while they were waiting for a broken one to be repaired, or added a brand new component to a system that hadn't been changed or upgraded for years. There was no such thing as telling the customer to wait, or to make them take down the entire system to upgrade everything at once. *That* was what was necessary. From eryksun at gmail.com Fri Jan 1 10:00:22 2021 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 1 Jan 2021 09:00:22 -0600 Subject: help In-Reply-To: <8e3d9019-a318-2f03-1c69-58a48a6f5fd9@web.de> References: <46b11e77-ac1c-3071-3a07-8b23fb0c898c@wichmann.us> <8e3d9019-a318-2f03-1c69-58a48a6f5fd9@web.de> Message-ID: On 1/1/21, Sibylle Koczian wrote: > > But that doesn't help, if the script raises an exception. In that case > the input() call won't be reached and the window will close anyway > before you could see anything. And in a script with errors that's even > worse. Same effect with the "run" window. The simplest, best option is running the script from an existing shell that owns the console session. That said, here are a couple alternatives to calling input() in a `finally` block. If you have .py files associated with the py launcher, for testing you can use a shebang such as `#!/usr/bin/python3 -i`. The "-i" option enters interactive mode after executing the script, even if there's an unhandled Python exception. Entering interactive mode won't work if the process crashes at a low level. To handle that, you can instead spawn a child process in the console session that waits forever. A good candidate is "waitfor.exe", which opens a mailslot and waits for it to be signaled. For example: import subprocess subprocess.Popen('waitfor.exe ever') This process will still be attached to the console session after Python exits. You can kill it by closing the console window, or by running `waitfor.exe /si ever` to signal it. From barry at barrys-emacs.org Fri Jan 1 11:35:16 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Fri, 1 Jan 2021 16:35:16 +0000 Subject: Why do I have both /usr/lib/python3 and /usr/lib/python3.8? In-Reply-To: <9ftrbh-97i3.ln1@esprimo.zbmc.eu> References: <9ftrbh-97i3.ln1@esprimo.zbmc.eu> Message-ID: <0B4092CE-BD13-4BFC-B5C9-35645FE26186@barrys-emacs.org> > On 29 Dec 2020, at 15:10, Chris Green wrote: > > Why are there both /usr/lib/python3 and /usr/lib/python3.8 on my > x[ubuntu] system? > > /usr/lib/python3 has just the dist-packages directory in it, > /usr/lib/python3.8 has lots of individual python files in it as well > as quite a number of directories. > > There's also a /usr/lib/python3.9 directory even though Ubuntu hasn't > moved to python3.9 yet. > It is common on linux systems for python3 to be a sym link to the systems preferred version of python3 to use. It is also common to be able to install multiple versions of python on a system. Both older and newer versions. Usually I use '#!/usr/bin/python3' in my scripts unless I know that a script has version dependences. By using python3 you do not have to edit your scripts shebang lines when your distro updates to a newer version of python. If you are testing your code against multiple version of python you need the version specific names like python3.8, python3.10 etc. Barry FYI this is what I have installed (lspy is a personal script): $ lspy /bin/python: 3.9.1 final 0 /bin/python2: 2.7.18 final 0 /bin/python2.7: 2.7.18 final 0 /bin/python3: 3.9.1 final 0 /bin/python3.10: 3.10.0 alpha 3 /bin/python3.4: 3.4.10 final 0 /bin/python3.5: 3.5.10 final 0 /bin/python3.6: 3.6.12 final 0 /bin/python3.9: 3.9.1 final 0 /bin/python34: 3.4.10 final 0 /bin/python35: 3.5.10 final 0 /usr/bin/python: 3.9.1 final 0 /usr/bin/python2: 2.7.18 final 0 /usr/bin/python2.7: 2.7.18 final 0 /usr/bin/python3: 3.9.1 final 0 /usr/bin/python3.10: 3.10.0 alpha 3 /usr/bin/python3.4: 3.4.10 final 0 /usr/bin/python3.5: 3.5.10 final 0 /usr/bin/python3.6: 3.6.12 final 0 /usr/bin/python3.9: 3.9.1 final 0 /usr/bin/python34: 3.4.10 final 0 /usr/bin/python35: 3.5.10 final 0 From barry at barrys-emacs.org Fri Jan 1 11:39:56 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Fri, 1 Jan 2021 16:39:56 +0000 Subject: Does windows edit .py file shebangs? Message-ID: <00C1C4B3-01C9-4DE9-AD24-17A0C209D998@barrys-emacs.org> I found python scripts have had their shebang lines edited behind my back. The shebang line I'm seeing is: #!C:\Users\barry\AppData\Local\Microsoft\WindowsApps\python3.EXE Is this Microsoft being "helpful"? Does anyone know what I will have done to best with this "help"? What do I need to do to prevent this happening? Barry From bob at mellowood.ca Fri Jan 1 11:39:53 2021 From: bob at mellowood.ca (Bob van der Poel) Date: Fri, 1 Jan 2021 09:39:53 -0700 Subject: Funny error message In-Reply-To: <3ab14244-7681-a93b-57f9-75a6bb7beacb@web.de> References: <3ab14244-7681-a93b-57f9-75a6bb7beacb@web.de> Message-ID: It appears that a couple of things are happening ... and not being a python install expert by a long shot, none of it makes sense to me. But, let me first state that I've never screwed around with the python installation. I let the Ubuntu packager take care of that. - running "python -v" I get A LOT of data about various modules being loaded, etc. I see that most of the modules are loaded from the system dir /usr/lib/python3.8 but some from .local/lib/python3.8. I have never created the .local tree so I, again, assume that the installer is doing this. BTW, sys.path is: ['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/bob/.local /lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages'] - running python -v gives too much info. I really can't see what is causing the unneeded text, but assume it is "requests". Note that this is the module from .local. Experimenting, I deleted .local/.../requests and it is now using /usr/.../requests. I've undeleted the .local version. - creating a one line script with only a bad command in it and running "python -v script.py >err_file" does not give the lengthy printout. The same error message is displayed on the terminal. I really have no idea ... and don't care that much, except it is annoying to have these same lines repeated over and over again after every error. Could this be a bug in requests? On Fri, Jan 1, 2021 at 3:03 AM Peter Otten <__peter__ at web.de> wrote: > On 31/12/2020 23:46, Bob van der Poel wrote: > > > When I run python from the command line and generate an error I get the > > following: > > > > Python 3.8.5 (default, Jul 28 2020, 12:59:40) > > [GCC 9.3.0] on linux > > Type "help", "copyright", "credits" or "license" for more information. > >>>> z > > /home/bob/.local/lib/python3.8/site-packages/requests/__init__.py:89: > > RequestsDependencyWarning: urllib3 (1.24.3) or chardet (4.0.0) doesn't > > match a supported version! > > warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported > " > > Traceback (most recent call last): > > File "", line 1, in > > NameError: name 'z' is not defined > > > > I understand "z in not defined" ... but what's with the warnings? > > It looks like Python tries to import requests as a side effect of > printing the traceback. > Start the interpreter in verbose mode > > $ python -v > > and trigger the name error again to see which module triggers that import. > > -- > https://mail.python.org/mailman/listinfo/python-list > -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From rosuav at gmail.com Fri Jan 1 11:42:06 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Jan 2021 03:42:06 +1100 Subject: Why do I have both /usr/lib/python3 and /usr/lib/python3.8? In-Reply-To: <0B4092CE-BD13-4BFC-B5C9-35645FE26186@barrys-emacs.org> References: <9ftrbh-97i3.ln1@esprimo.zbmc.eu> <0B4092CE-BD13-4BFC-B5C9-35645FE26186@barrys-emacs.org> Message-ID: On Sat, Jan 2, 2021 at 3:36 AM Barry Scott wrote: > > FYI this is what I have installed (lspy is a personal script): > > $ lspy > /bin/python: 3.9.1 final 0 > /bin/python2: 2.7.18 final 0 > /bin/python2.7: 2.7.18 final 0 > /bin/python3: 3.9.1 final 0 > /bin/python3.10: 3.10.0 alpha 3 > /bin/python3.4: 3.4.10 final 0 > /bin/python3.5: 3.5.10 final 0 > /bin/python3.6: 3.6.12 final 0 > /bin/python3.9: 3.9.1 final 0 > /bin/python34: 3.4.10 final 0 > /bin/python35: 3.5.10 final 0 > /usr/bin/python: 3.9.1 final 0 > /usr/bin/python2: 2.7.18 final 0 > /usr/bin/python2.7: 2.7.18 final 0 > /usr/bin/python3: 3.9.1 final 0 > /usr/bin/python3.10: 3.10.0 alpha 3 > /usr/bin/python3.4: 3.4.10 final 0 > /usr/bin/python3.5: 3.5.10 final 0 > /usr/bin/python3.6: 3.6.12 final 0 > /usr/bin/python3.9: 3.9.1 final 0 > /usr/bin/python34: 3.4.10 final 0 > /usr/bin/python35: 3.5.10 final 0 > Pretty similar to mine, except that (a) most of the Pythons are in /usr/local/bin rather than /bin or /usr/bin, and (b) with just a couple of exceptions, they're all alphas and betas (eg 3.7.0a4+) built from git. I keep a single 2.7 around (provided by Debian Stable), and a couple of different 3.x versions are Debian-provided, with all the rest (from 3.4 to 3.10) hanging around from having been built. ChrisA From bob at mellowood.ca Fri Jan 1 11:50:07 2021 From: bob at mellowood.ca (Bob van der Poel) Date: Fri, 1 Jan 2021 09:50:07 -0700 Subject: Funny error message In-Reply-To: References: Message-ID: On Thu, Dec 31, 2020 at 9:25 PM DL Neil via Python-list < python-list at python.org> wrote: > On 1/1/21 11:46 AM, Bob van der Poel wrote: > > When I run python from the command line and generate an error I get the > > following: > > > > Python 3.8.5 (default, Jul 28 2020, 12:59:40) > > [GCC 9.3.0] on linux > > Type "help", "copyright", "credits" or "license" for more information. > >>>> z > > /home/bob/.local/lib/python3.8/site-packages/requests/__init__.py:89: > > RequestsDependencyWarning: urllib3 (1.24.3) or chardet (4.0.0) doesn't > > match a supported version! > > warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported " > > Traceback (most recent call last): > > File "", line 1, in > > NameError: name 'z' is not defined > > > > I understand "z in not defined" ... but what's with the warnings? > > > The implication is that there is a version-mismatch between Python 3.8 > and whichever urllib3 and chardet libraries currently installed. > > Recommend updating the system, container, or venv: either Python, pip3 > of the two and/or requests or html-parser [as appropriate to the > installed libraries - see below], or both/all. > > > System here runs as-expected: > > dn $ ... python > Python 3.9.1 (default, Dec 8 2020, 00:00:00) > [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> z > Traceback (most recent call last): > File "", line 1, in > NameError: name 'z' is not defined > >>> import chardet > >>> import urllib3 > >>> exit() > dn $ ... pip show chardet urllib3 > Name: chardet > Version: 3.0.4 > Summary: Universal encoding detector for Python 2 and 3 > Home-page: https://github.com/chardet/chardet > Author: Mark Pilgrim > Author-email: mark at diveintomark.org > License: LGPL > Location: /usr/lib/python3.9/site-packages > Requires: > Required-by: html5-parser, requests > --- > Name: urllib3 > Version: 1.25.8 > Summary: HTTP library with thread-safe connection pooling, file post, > and more. > Home-page: https://urllib3.readthedocs.io/ > Author: Andrey Petrov > Author-email: andrey.petrov at shazow.net > License: MIT > Location: /usr/lib/python3.9/site-packages > Requires: > Required-by: requests > > Found it! I had the proper urllib3 installed. But, in my .local/lib/ a previous version was installed. Removing .local/lib/python3.8 has resolved the problem. Anyone hazard a guess as to why I had a .local tree (nope, I did not create it ... I don't think!). -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From barry at barrys-emacs.org Fri Jan 1 11:54:39 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Fri, 1 Jan 2021 16:54:39 +0000 Subject: Why do I have both /usr/lib/python3 and /usr/lib/python3.8? In-Reply-To: References: <9ftrbh-97i3.ln1@esprimo.zbmc.eu> <0B4092CE-BD13-4BFC-B5C9-35645FE26186@barrys-emacs.org> Message-ID: <9DF11D45-B03F-40FF-8499-C9DFDA32B21F@barrys-emacs.org> > On 1 Jan 2021, at 16:42, Chris Angelico wrote: > > On Sat, Jan 2, 2021 at 3:36 AM Barry Scott > wrote: >> >> FYI this is what I have installed (lspy is a personal script): >> >> $ lspy >> /bin/python: 3.9.1 final 0 >> /bin/python2: 2.7.18 final 0 >> /bin/python2.7: 2.7.18 final 0 >> /bin/python3: 3.9.1 final 0 >> /bin/python3.10: 3.10.0 alpha 3 >> /bin/python3.4: 3.4.10 final 0 >> /bin/python3.5: 3.5.10 final 0 >> /bin/python3.6: 3.6.12 final 0 >> /bin/python3.9: 3.9.1 final 0 >> /bin/python34: 3.4.10 final 0 >> /bin/python35: 3.5.10 final 0 >> /usr/bin/python: 3.9.1 final 0 >> /usr/bin/python2: 2.7.18 final 0 >> /usr/bin/python2.7: 2.7.18 final 0 >> /usr/bin/python3: 3.9.1 final 0 >> /usr/bin/python3.10: 3.10.0 alpha 3 >> /usr/bin/python3.4: 3.4.10 final 0 >> /usr/bin/python3.5: 3.5.10 final 0 >> /usr/bin/python3.6: 3.6.12 final 0 >> /usr/bin/python3.9: 3.9.1 final 0 >> /usr/bin/python34: 3.4.10 final 0 >> /usr/bin/python35: 3.5.10 final 0 >> > > Pretty similar to mine, except that (a) most of the Pythons are in > /usr/local/bin rather than /bin or /usr/bin, and (b) with just a > couple of exceptions, they're all alphas and betas (eg 3.7.0a4+) built > from git. I keep a single 2.7 around (provided by Debian Stable), and > a couple of different 3.x versions are Debian-provided, with all the > rest (from 3.4 to 3.10) hanging around from having been built. In my case they are all installed from Fedora officially built and maintained RPMs. Barry From barry at barrys-emacs.org Fri Jan 1 11:56:21 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Fri, 1 Jan 2021 16:56:21 +0000 Subject: Funny error message In-Reply-To: References: Message-ID: <9EB9874B-1DB0-425C-A6A9-4224D00C345F@barrys-emacs.org> > On 1 Jan 2021, at 16:50, Bob van der Poel wrote: > > On Thu, Dec 31, 2020 at 9:25 PM DL Neil via Python-list < > python-list at python.org > wrote: > >> On 1/1/21 11:46 AM, Bob van der Poel wrote: >>> When I run python from the command line and generate an error I get the >>> following: >>> >>> Python 3.8.5 (default, Jul 28 2020, 12:59:40) >>> [GCC 9.3.0] on linux >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> z >>> /home/bob/.local/lib/python3.8/site-packages/requests/__init__.py:89: >>> RequestsDependencyWarning: urllib3 (1.24.3) or chardet (4.0.0) doesn't >>> match a supported version! >>> warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported " >>> Traceback (most recent call last): >>> File "", line 1, in >>> NameError: name 'z' is not defined >>> >>> I understand "z in not defined" ... but what's with the warnings? >> >> >> The implication is that there is a version-mismatch between Python 3.8 >> and whichever urllib3 and chardet libraries currently installed. >> >> Recommend updating the system, container, or venv: either Python, pip3 >> of the two and/or requests or html-parser [as appropriate to the >> installed libraries - see below], or both/all. >> >> >> System here runs as-expected: >> >> dn $ ... python >> Python 3.9.1 (default, Dec 8 2020, 00:00:00) >> [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> z >> Traceback (most recent call last): >> File "", line 1, in >> NameError: name 'z' is not defined >>>>> import chardet >>>>> import urllib3 >>>>> exit() >> dn $ ... pip show chardet urllib3 >> Name: chardet >> Version: 3.0.4 >> Summary: Universal encoding detector for Python 2 and 3 >> Home-page: https://github.com/chardet/chardet >> Author: Mark Pilgrim >> Author-email: mark at diveintomark.org >> License: LGPL >> Location: /usr/lib/python3.9/site-packages >> Requires: >> Required-by: html5-parser, requests >> --- >> Name: urllib3 >> Version: 1.25.8 >> Summary: HTTP library with thread-safe connection pooling, file post, >> and more. >> Home-page: https://urllib3.readthedocs.io/ >> Author: Andrey Petrov >> Author-email: andrey.petrov at shazow.net >> License: MIT >> Location: /usr/lib/python3.9/site-packages >> Requires: >> Required-by: requests >> >> > Found it! > > I had the proper urllib3 installed. But, in my .local/lib/ a previous > version was installed. Removing .local/lib/python3.8 has resolved the > problem. > > Anyone hazard a guess as to why I had a .local tree (nope, I did not create > it ... I don't think!). > That is where "python3.8 -m pip install --user" puts the packages you install. Barry > > -- > > **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** > Bob van der Poel ** Wynndel, British Columbia, CANADA ** > EMAIL: bob at mellowood.ca > WWW: http://www.mellowood.ca > -- > https://mail.python.org/mailman/listinfo/python-list From arj.python at gmail.com Fri Jan 1 12:01:23 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 1 Jan 2021 21:01:23 +0400 Subject: Does windows edit .py file shebangs? In-Reply-To: <00C1C4B3-01C9-4DE9-AD24-17A0C209D998@barrys-emacs.org> References: <00C1C4B3-01C9-4DE9-AD24-17A0C209D998@barrys-emacs.org> Message-ID: Greetings list, Being a windows user since long, this made me laugh. Tell me 1/ What version of Python are you running? 2/ What editor/IDE are you using? Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius On Fri, Jan 1, 2021 at 8:43 PM Barry Scott wrote: > I found python scripts have had their shebang lines edited behind my back. > > The shebang line I'm seeing is: > > #!C:\Users\barry\AppData\Local\Microsoft\WindowsApps\python3.EXE > > Is this Microsoft being "helpful"? > Does anyone know what I will have done to best with this "help"? > > What do I need to do to prevent this happening? > > Barry > > -- > https://mail.python.org/mailman/listinfo/python-list > From eryksun at gmail.com Fri Jan 1 12:03:07 2021 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 1 Jan 2021 11:03:07 -0600 Subject: Does windows edit .py file shebangs? In-Reply-To: <00C1C4B3-01C9-4DE9-AD24-17A0C209D998@barrys-emacs.org> References: <00C1C4B3-01C9-4DE9-AD24-17A0C209D998@barrys-emacs.org> Message-ID: On 1/1/21, Barry Scott wrote: > I found python scripts have had their shebang lines edited behind my back. > > The shebang line I'm seeing is: > > #!C:\Users\barry\AppData\Local\Microsoft\WindowsApps\python3.EXE > > Is this Microsoft being "helpful"? > Does anyone know what I will have done to best with this "help"? > > What do I need to do to prevent this happening? Shebang lines may be localized to the current interpreter when installing a package. Otherwise I don't know what's causing that. Regarding Windows, the system doesn't support shebang lines in any way. Python's installer associates .py files with the py.exe launcher, which looks for a shebang line in a script in order to determine which executable to run. It supports shebangs with fully-qualified Windows paths, as well as virtual commands for registered installations, such as "python", "python3", "python3.9-32", "/usr/bin/python3", and "/usr/bin/env python". From bob at mellowood.ca Fri Jan 1 12:35:49 2021 From: bob at mellowood.ca (Bob van der Poel) Date: Fri, 1 Jan 2021 10:35:49 -0700 Subject: Funny error message In-Reply-To: <9EB9874B-1DB0-425C-A6A9-4224D00C345F@barrys-emacs.org> References: <9EB9874B-1DB0-425C-A6A9-4224D00C345F@barrys-emacs.org> Message-ID: Found it! > > I had the proper urllib3 installed. But, in my .local/lib/ a previous > version was installed. Removing .local/lib/python3.8 has resolved the > problem. > > Anyone hazard a guess as to why I had a .local tree (nope, I did not create > it ... I don't think!). > > > That is where "python3.8 -m pip install --user" puts the packages you > install. > > Barry > > > > Okay ... I'll take your word for it. But, I really don't think I've every run that command :) -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From PythonList at danceswithmice.info Fri Jan 1 14:17:58 2021 From: PythonList at danceswithmice.info (DL Neil) Date: Sat, 2 Jan 2021 08:17:58 +1300 Subject: Funny error message In-Reply-To: References: <9EB9874B-1DB0-425C-A6A9-4224D00C345F@barrys-emacs.org> Message-ID: <98db8b2f-81f7-83c7-8e24-b5619f5912ef@DancesWithMice.info> On 1/2/21 6:35 AM, Bob van der Poel wrote: > Found it! Well done! >> I had the proper urllib3 installed. But, in my .local/lib/ a previous >> version was installed. Removing .local/lib/python3.8 has resolved the >> problem. >> >> Anyone hazard a guess as to why I had a .local tree (nope, I did >> not create >> it ... I don't think!). >> > > That is where "python3.8 -m pip install --user" puts the packages > you install. > > Barry > > > > Okay ... I'll take your word for it. But, I really don't think I've > every run that command :) Assuming Python is maintained only at the system-level (cf --user or venv) then it may be possible that installing some application that runs 'on' Python added the local-library (as a "dependency"). Alternately, many beginners following installation instructions on a paint-by-numbers basis, may type/copy-paste commands without retaining any memory of same. [observation, not personal criticism] Python has been designed to offer flexibility. One of which is the ability to have multiple, co-resident, versions of Python and/or libraries. Of course, this also produces exactly the type of 'gotcha' illustrated (detected, and solved) here. Someone more familiar with Python-packaging may improve/correct... On a thematically-related, but OT-note: I decided to install a 'fresh' version of Fedora 33 on this machine, rather than performing a version-update. (required one hour from start-to-finish - try that MS-Win users!) The Python-relevance was to ensure there was no legacy-Python2 left 'lying-around'. However, the GIMP (popular graphics package) still uses (and has some sort of 'exemption' to use) Python2. Stymied! Not quite - there's a Flatpak option - which will enable my Python3-only objective by ring-fencing the GIMP and its dependencies. However... now I have a system package manager (dnf (~apt)) installing most system-software and 'other stuff' under a different method (I took the same approach with the Chromium browser) - how long will it be before such 'cleverness' is forgotten/trips me up? -- Regards =dn From bob at mellowood.ca Fri Jan 1 15:39:00 2021 From: bob at mellowood.ca (Bob van der Poel) Date: Fri, 1 Jan 2021 13:39:00 -0700 Subject: Funny error message In-Reply-To: <98db8b2f-81f7-83c7-8e24-b5619f5912ef@DancesWithMice.info> References: <9EB9874B-1DB0-425C-A6A9-4224D00C345F@barrys-emacs.org> <98db8b2f-81f7-83c7-8e24-b5619f5912ef@DancesWithMice.info> Message-ID: On Fri, Jan 1, 2021 at 12:17 PM DL Neil via Python-list < python-list at python.org> wrote: > On 1/2/21 6:35 AM, Bob van der Poel wrote: > > Found it! > > Well done! > > > >> I had the proper urllib3 installed. But, in my .local/lib/ a > previous > >> version was installed. Removing .local/lib/python3.8 has resolved > the > >> problem. > >> > >> Anyone hazard a guess as to why I had a .local tree (nope, I did > >> not create > >> it ... I don't think!). > >> > > > > That is where "python3.8 -m pip install --user" puts the packages > > you install. > > > > Barry > > > > > > > > Okay ... I'll take your word for it. But, I really don't think I've > > every run that command :) > > Assuming Python is maintained only at the system-level (cf --user or > venv) then it may be possible that installing some application that runs > 'on' Python added the local-library (as a "dependency"). Alternately, > many beginners following installation instructions on a paint-by-numbers > basis, may type/copy-paste commands without retaining any memory of same. > [observation, not personal criticism] > > Python has been designed to offer flexibility. One of which is the > ability to have multiple, co-resident, versions of Python and/or > libraries. Of course, this also produces exactly the type of 'gotcha' > illustrated (detected, and solved) here. > > Someone more familiar with Python-packaging may improve/correct... > > > On a thematically-related, but OT-note: > I decided to install a 'fresh' version of Fedora 33 on this machine, > rather than performing a version-update. (required one hour from > start-to-finish - try that MS-Win users!) The Python-relevance was to > ensure there was no legacy-Python2 left 'lying-around'. However, the > GIMP (popular graphics package) still uses (and has some sort of > 'exemption' to use) Python2. Stymied! Not quite - there's a Flatpak > option - which will enable my Python3-only objective by ring-fencing the > GIMP and its dependencies. However... now I have a system package > manager (dnf (~apt)) installing most system-software and 'other stuff' > under a different method (I took the same approach with the Chromium > browser) - how long will it be before such 'cleverness' is > forgotten/trips me up? > I have installed a few packages using pip. I "try" to do so as root (this is basically a one user machine) ... but I may have installed as user. Still, it should not have brought in a complete py set of libraries. I'm going with the idea that some other package, either via apt or flatpak (which I really don't trust) decided to be nice. But it was a mess to have python distros in /usr/lib, /usr/local/lib and ./local ... I am going to really try in the future to have everything in one spot! Speaking of "one spot" I also see that some functions do not create the .pyc versions. Running as a user, the compressed version can't be created in /usr/lib/. I assume the installer is supposed to do that, but it does appear that it's not 100%. -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From nospam at please.ty Fri Jan 1 15:41:24 2021 From: nospam at please.ty (jak) Date: Fri, 1 Jan 2021 21:41:24 +0100 Subject: Control stript which is runing in background. References: Message-ID: Il 01/01/2021 14:49, 2QdxY4RzWzUUiLuE at potatochowder.com ha scritto: > On 2021-01-01 at 11:11:47 +0100, > jak wrote: > >> Il 01/01/2021 04:14, 2QdxY4RzWzUUiLuE at potatochowder.com ha scritto: >>> On 2021-01-01 at 03:43:43 +0100, >>> jak wrote: >>> >>> I think you were clear enough before, but you may not have >>> considered things the OP did not specify. One of the hardest parts >>> of software development is understanding and specifying the actual >>> problem to be solved. I've never done that in a second language >>> (I'm nowhere near fluent in anything other than English); I can only >>> imagine the extra layers of complexity. >> >> This is the OP's initial request: >> >>> Hi. I would like to make something like this: >>> A python script would run headlessly in the background. >>> I would like to control the script from the command line using other python scripts or from the python shell. >>> From time to time I would ask the main script to create a popup window with an image or a plot. >>> What would be the proper way to approach it. How to make communication between two scripts? >>> Thank you. >>> Petro. >> >> I have suggested an alternative way for his necessity. >> It will be up to him to decide which one he should adopt. That way he >> has a choice, at least. >> I don't know where you work. I know, however, that in these zones, if >> you do more than necessary wasting their time, they will kick you away. > > So what is necessary? Does "control the script" include reporting > success or failure of a request? The OP also said "communication > between two scripts," which to me means two way traffic. Only the OP > knows for sure, and at least one of us might get it wrong if we don't > ask, or at least acknowledge that we don't know. > > If I start with a named pipe because it's good enough for Phase Zero, or > Version 0.0.1, or Release Experimental Alpha, then I'm going to end up > ripping that out or reinventing something that already existed on top of > that named pipe. > > Suppose I look ahead just a little, and use a socket in the first place. > Yes, you could argue that it's more than what was necessary and kick me > away. Will you kick me again when you can build on it (I can't; I'm > gone) instead of having to rebuild what already worked? > > I'm retired now, but I at one employer, I worked on products with (a) > lifetimes measured in decades, (b) extremely expensive (money, time, > convenience, etc.) upgrade/maintenance cycles, and therefore (c) strict > interoperability requirements.? A little bit of foresight and extra > analysis up front went a long way towards saving a lot of headaches and > development resources (and customers!) in the long term. > Communications protocols in particular had to be well thought out, and > often more complex than was immediately necessary, because backwards and > forwards compatibility were not negotiable. > > Again, I'm not (and no one else is, either) saying that your solution is > wrong or won't work. Your solution may even be the be the best solution > to the OP's problem. All I'm saying is that we can't know until the OP > tells us more. Yes, the OP has a choice to make. Maybe we have helped, > not by making that choice, but by giving it to the OP with enough > supporting information to make it. > > ? Think about a system containing dozens of individually field > upgradeable components. It had to work when a customer upgraded one > component at a time (over the course of weeks or months), or plugged in > an old component while they were waiting for a broken one to be > repaired, or added a brand new component to a system that hadn't been > changed or upgraded for years. There was no such thing as telling the > customer to wait, or to make them take down the entire system to upgrade > everything at once. *That* was what was necessary. > Sorry if I made you argumentative. It was not my intention. Let me reiterate once again that my intention was to offer an alternative to the OP and that I never claimed my way was better than the other suggestions. Furthermore, the OP will have already made its choice by now. Just one last comment: I understand your point of view but I disagree because the difficulty in providing assistance as the customer wishes depends on how you have designed the product and not on how you develop the pieces that compose it. One more thing: you probably don't care anymore, but people have taught me that if you give a customer something, you can't sell it to him anymore. Sorry again. From garabik-news-2005-05 at kassiopeia.juls.savba.sk Fri Jan 1 15:48:44 2021 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Fri, 1 Jan 2021 20:48:44 +0000 (UTC) Subject: ANN: unicode 2.8 References: Message-ID: Terry Reedy wrote: > On 12/31/2020 9:36 AM, garabik-news-2005-05 at kassiopeia.juls.savba.sk wrote: >> unicode is a simple python command line utility that displays >> properties for a given unicode character, or searches >> unicode database for a given name. > ... >> Changes since previous versions: >> >> * display ASCII table (either traditional with --ascii or the new >> EU?UK Trade and Cooperation Agreement version with --brexit-ascii) > > Are you reproducing it with bugs included? > How is that of any use to anyone? Including the (correct) ASCII table has been a long term, low priority - I am using ascii(1) utility reasonably often and it makes sense to reproduce this functionality. And when implementing this, it was a no-brainer to include also the brexit varian (verbatim). After all, given the blood and sweat and tears shed during the negotiations, I am sure each and every line of the Agreement has been combed and (re)negotiated over and over by experienced negotiators and verified an army of experts in the fields -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From cs at cskk.id.au Fri Jan 1 16:13:24 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 2 Jan 2021 08:13:24 +1100 Subject: Control stript which is runing in background. In-Reply-To: References: Message-ID: On 01Jan2021 03:43, jak wrote: >Maybe the fact that I'm not English and I don't know the language well >doesn't allow me to express myself clearly. Try it one more time: >The OP would like to give some command to a script that is running. How? >With a script that sends commands to it. One of the ways, as mentioned, >is by using a mini socket server. Given the needs of the OP and the fact >that sockets are a limited resource in a system, I took the liberty of >proposing a simple alternative: using a named pipe, also because, IMO, >sockets, in this case, are an overkill. with a few lines of code in a >thread in the running script they can allow it to receive commands: You're right. For receive only of small things this is pretty simple. Not to mention much easier on the command sender: echo "my command" >the-named-pipe I'm sorry for conflating the concurrency and return-a-response needs of a full blown client/server app with the much simpler request of the OP: to control a daemon simply. I've even done exactly what you suggested myself. I think it's pretty clear that you're aware of the difference in behaviours and semantics between UNIX named pipes (unidirection shared single channel) with sockets (bidirection distinct multichannels). Cheers, Cameron Simpson From PythonList at danceswithmice.info Fri Jan 1 16:38:01 2021 From: PythonList at danceswithmice.info (DL Neil) Date: Sat, 2 Jan 2021 10:38:01 +1300 Subject: Funny error message In-Reply-To: References: <9EB9874B-1DB0-425C-A6A9-4224D00C345F@barrys-emacs.org> <98db8b2f-81f7-83c7-8e24-b5619f5912ef@DancesWithMice.info> Message-ID: <2ce4765f-bcab-05a9-055b-82507e2aa103@DancesWithMice.info> On 1/2/21 9:39 AM, Bob van der Poel wrote: > > > On Fri, Jan 1, 2021 at 12:17 PM DL Neil via Python-list > > wrote: > > On 1/2/21 6:35 AM, Bob van der Poel wrote: > > Found it! > > Well done! > > > >>? ? ?I had the proper urllib3 installed. But, in my .local/lib/ a > previous > >>? ? ?version was installed. Removing .local/lib/python3.8 has > resolved the > >>? ? ?problem. > >> > >>? ? ?Anyone hazard a guess as to why I had a .local tree (nope, I did > >>? ? ?not create > >>? ? ?it ... I don't think!). > >> > > > >? ? ?That is where "python3.8 -m pip install --user" puts the packages > >? ? ?you install. > > > >? ? ?Barry > > > > > > > > Okay ... I'll take your word for it. But, I really don't think I've > > every run that command :) > > Assuming Python is maintained only at the system-level (cf --user or > venv) then it may be possible that installing some application that runs > 'on' Python added the local-library (as a "dependency"). Alternately, > many beginners following installation instructions on a paint-by-numbers > basis, may type/copy-paste commands without retaining any memory of > same. > [observation, not personal criticism] > > Python has been designed to offer flexibility. One of which is the > ability to have multiple, co-resident, versions of Python and/or > libraries. Of course, this also produces exactly the type of 'gotcha' > illustrated (detected, and solved) here. > > Someone more familiar with Python-packaging may improve/correct... > > > On a thematically-related, but OT-note: > I decided to install a 'fresh' version of Fedora 33 on this machine, > rather than performing a version-update. (required one hour from > start-to-finish - try that MS-Win users!) The Python-relevance was to > ensure there was no legacy-Python2 left 'lying-around'. However, the > GIMP (popular graphics package) still uses (and has some sort of > 'exemption' to use) Python2. Stymied! Not quite - there's a Flatpak > option - which will enable my Python3-only objective by ring-fencing the > GIMP and its dependencies. However... now I have a system package > manager (dnf (~apt)) installing most system-software and 'other stuff' > under a different method (I took the same approach with the Chromium > browser) - how long will it be before such 'cleverness' is > forgotten/trips me up? > > > I have installed a few packages using pip. I "try" to do so as root > (this is basically a one user machine) ... but I may have installed as > user. Still, it should not have brought in a complete py set of > libraries. I'm going with the idea that some other package, either via > apt or flatpak (which I really don't trust) decided to be nice. But it > was a mess to have python distros in /usr/lib, /usr/local/lib and > ./local ... I am going to really try in the future to have everything in > one spot! I'm not sure if you mean that you intend moving files from the directory where they were loaded to somewhere else - I would hesitate! As before, there is a tradeoff between 'tidiness' and 'flexibility'. Perhaps do some reading to ensure a grasp of Python's library/directory structures and system/virtual environments, first? Suggestions: sys.path https://docs.python.org/3/using/cmdline.html 2.3. Python-related paths and files https://docs.python.org/3/using/unix.html#python-related-paths-and-files PEP 370 -- Per user site-packages directory https://www.python.org/dev/peps/pep-0370/ and to really dive 'under the covers' https://www.python.org/dev/peps/pep-0587/ - with plenty more, both on-site and externally. It quickly becomes apparent that there are risks in assuming that what 'should be done' for one project/application will 'always' be OK. Sadly, such may have an (undesirable) impact on another/others. Thus, the virtue of project-dedicated venvs (alternately OpSys-level containers)! > Speaking of "one spot" I also see that some functions do not create the > .pyc versions. Running as a user, the compressed version can't be > created in /usr/lib/. I assume the installer is supposed to do that, but > it does appear that it's not 100%. There are multiple reasons for this, but the first time that code is run, a .pyc will (presumably) be created - and we're back to considerations of Python environments, Python cf C, perhaps even differences between OpSys - certainly and once-again, 'here be dragons'... -- Regards =dn From bob at mellowood.ca Fri Jan 1 17:06:51 2021 From: bob at mellowood.ca (Bob van der Poel) Date: Fri, 1 Jan 2021 15:06:51 -0700 Subject: Funny error message In-Reply-To: <2ce4765f-bcab-05a9-055b-82507e2aa103@DancesWithMice.info> References: <9EB9874B-1DB0-425C-A6A9-4224D00C345F@barrys-emacs.org> <98db8b2f-81f7-83c7-8e24-b5619f5912ef@DancesWithMice.info> <2ce4765f-bcab-05a9-055b-82507e2aa103@DancesWithMice.info> Message-ID: > Assuming Python is maintained only at the system-level (cf --user or > > venv) then it may be possible that installing some application that > runs > > 'on' Python added the local-library (as a "dependency"). Alternately, > > many beginners following installation instructions on a > paint-by-numbers > > basis, may type/copy-paste commands without retaining any memory of > > same. > > [observation, not personal criticism] > > > > Python has been designed to offer flexibility. One of which is the > > ability to have multiple, co-resident, versions of Python and/or > > libraries. Of course, this also produces exactly the type of 'gotcha' > > illustrated (detected, and solved) here. > > > > Someone more familiar with Python-packaging may improve/correct... > > > > > > On a thematically-related, but OT-note: > > I decided to install a 'fresh' version of Fedora 33 on this machine, > > rather than performing a version-update. (required one hour from > > start-to-finish - try that MS-Win users!) The Python-relevance was to > > ensure there was no legacy-Python2 left 'lying-around'. However, the > > GIMP (popular graphics package) still uses (and has some sort of > > 'exemption' to use) Python2. Stymied! Not quite - there's a Flatpak > > option - which will enable my Python3-only objective by ring-fencing > the > > GIMP and its dependencies. However... now I have a system package > > manager (dnf (~apt)) installing most system-software and 'other > stuff' > > under a different method (I took the same approach with the Chromium > > browser) - how long will it be before such 'cleverness' is > > forgotten/trips me up? > > > > > > I have installed a few packages using pip. I "try" to do so as root > > (this is basically a one user machine) ... but I may have installed as > > user. Still, it should not have brought in a complete py set of > > libraries. I'm going with the idea that some other package, either via > > apt or flatpak (which I really don't trust) decided to be nice. But it > > was a mess to have python distros in /usr/lib, /usr/local/lib and > > ./local ... I am going to really try in the future to have everything in > > one spot! > > I'm not sure if you mean that you intend moving files from the directory > where they were loaded to somewhere else - I would hesitate! > > > As before, there is a tradeoff between 'tidiness' and 'flexibility'. > Perhaps do some reading to ensure a grasp of Python's library/directory > structures and system/virtual environments, first? > > What me? Read? Actually a good suggestion ... I'll make note of the recommended reading list. Thanks. > Suggestions: > sys.path https://docs.python.org/3/using/cmdline.html > 2.3. Python-related paths and files > https://docs.python.org/3/using/unix.html#python-related-paths-and-files > PEP 370 -- Per user site-packages directory > https://www.python.org/dev/peps/pep-0370/ > and to really dive 'under the covers' > https://www.python.org/dev/peps/pep-0587/ > - with plenty more, both on-site and externally. > > It quickly becomes apparent that there are risks in assuming that what > 'should be done' for one project/application will 'always' be OK. Sadly, > such may have an (undesirable) impact on another/others. Thus, the > virtue of project-dedicated venvs (alternately OpSys-level containers)! > > > > Speaking of "one spot" I also see that some functions do not create the > > .pyc versions. Running as a user, the compressed version can't be > > created in /usr/lib/. I assume the installer is supposed to do that, but > > it does appear that it's not 100%. > > There are multiple reasons for this, but the first time that code is > run, a .pyc will (presumably) be created - and we're back to > considerations of Python environments, Python cf C, perhaps even > > Oh no! Not these damned dragons again :) But, seriously. No, I have no idea of moving installed stuff around between /usr /.local and /usr/local. There lies no dragons but madness :) I meant that I will pay more attention as to what the installer(s) are doing. Thanks for the input. -- **** Listen to my FREE CD at http://www.mellowood.ca/music/cedars **** Bob van der Poel ** Wynndel, British Columbia, CANADA ** EMAIL: bob at mellowood.ca WWW: http://www.mellowood.ca From Bischoop at vimart.net Fri Jan 1 17:58:54 2021 From: Bischoop at vimart.net (Bischoop) Date: Fri, 1 Jan 2021 22:58:54 -0000 (UTC) Subject: A random word from one of two lists Message-ID: I have two lists *animal* and *fruit* and I try to get a random variable animal or fruit and then random word from that list. I thought that dictionary(*words*) could help me but no succes, the only way I've done partially what was with list *kinds* and by using two times random.choice. However print(kind) return me a list not a variable: animal or fruit so now I'm kinda confuse if I can achieve that. import random animal = ['koala', 'kangaroo'] fruit = ['banana', 'apple'] kinds = [animal,fruit] words = {'animals': animal, 'fruits': fruit} kind = random.choice(kinds) print(kind) word = random.choice(kind) print(word) #output: ['kolala', 'kangaroo'] kangaroo -- Thanks From 2QdxY4RzWzUUiLuE at potatochowder.com Fri Jan 1 18:07:05 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Fri, 1 Jan 2021 17:07:05 -0600 Subject: Control stript which is runing in background. In-Reply-To: References: Message-ID: On 2021-01-01 at 21:41:24 +0100, jak wrote: > Sorry if I made you argumentative ... And I didn't mean to be argumentative. :-) We both offered alternatives, and we both argued for them (in the sense of claiming that our own ideas were good). Each solution is better, depending on certain details of the OP's requirements. > ... Furthermore, the OP will have already made its choice by now ... We don't know that. > ... Just one last comment: I understand your point of view but I > disagree because the difficulty in providing assistance as the > customer wishes depends on how you have designed the product and not > on how you develop the pieces that compose it ... I agree: most companies have no more customer service. :-) Our business was emergency communications equipment; if we didn't provide such assistance, or the equipment didn't do certain things, there was a distinct possibility that someome could die. When a police officer presses the button, he or she has to talk to the dispatcher in 250ms or less. Same for an emergency medical technician in an ambulance. A 60-second TCP timeout or an HTTP 503 error is not okay. You can't tell people in a burning building to wait until the dispatch center has finished their upgrades, and you can't take the whole fire department off line to upgrade the radios in all the trucks at once. It's not a matter of what's easiest to develop, or the easiest to support. I think I'm coming off gruffly again, but I don't mean to. > ... One more thing: you probably don't care anymore, but people have > taught me that if you give a customer something, you can't sell it to > him anymore. Please don't tell me what I do or don't care about. :-) I agree: once you give something away for free, it's very difficult to charge money for it later. Believe me, we didn't give our communications equipment (or the subsequent software upgrades, unless there was a serious bug) away for free. :-) From Richard at Damon-Family.org Fri Jan 1 18:12:57 2021 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 1 Jan 2021 18:12:57 -0500 Subject: A random word from one of two lists In-Reply-To: References: Message-ID: On 1/1/21 5:58 PM, Bischoop wrote: > I have two lists *animal* and *fruit* and I try to get a random variable > animal or fruit and then random word from that list. > I thought that dictionary(*words*) could help me but no succes, the only way I've > done partially what was with list *kinds* and by using two times > random.choice. However print(kind) return me a list not a variable: > animal or fruit so now I'm kinda confuse if I can achieve that. > > > > import random > animal = ['koala', 'kangaroo'] > fruit = ['banana', 'apple'] > kinds = [animal,fruit] > words = {'animals': animal, 'fruits': fruit} > > > kind = random.choice(kinds) > print(kind) > word = random.choice(kind) > print(word) > #output: > ['kolala', 'kangaroo'] > kangaroo > > -- > Thanks random.choice doesn't return 'a variable' but an object. Which is the same object that one of the variables that you used. IF you wanted to use words, then you could have made kinds = {'animals', 'fruits'} and then looked up the list in words, but that is really just more work (unless you want to know which list it came from) Note that 'animals' isn't a variable, but a string value. -- Richard Damon From cs at cskk.id.au Fri Jan 1 18:18:20 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 2 Jan 2021 10:18:20 +1100 Subject: A random word from one of two lists In-Reply-To: References: Message-ID: On 01Jan2021 22:58, Bischoop wrote: >I have two lists *animal* and *fruit* and I try to get a random variable >animal or fruit and then random word from that list. >I thought that dictionary(*words*) could help me but no succes, the only way I've >done partially what was with list *kinds* and by using two times >random.choice. However print(kind) return me a list not a variable: >animal or fruit so now I'm kinda confuse if I can achieve that. > >import random >animal = ['koala', 'kangaroo'] >fruit = ['banana', 'apple'] This is fine. >kinds = [animal,fruit] This probably isn't what you intend. Print out kinds: print(repr(kinds)) >words = {'animals': animal, 'fruits': fruit} I suspect you want, after this line: kinds = list(words.keys()) which gets you a list of the dictionary keys. Print that, too, to see the difference. >kind = random.choice(kinds) >print(kind) When the earlier stuff works, this should be a string. >word = random.choice(kind) This picks a random character from the string. Probably not what you want. You want to pick from the list of animals or fruits. Since you (will) have the word "animals" or "fruits" in "kind", how do you reference the appropriate list? Cheers, Cameron Simpson From Marco.Sulla.Python at gmail.com Fri Jan 1 18:18:06 2021 From: Marco.Sulla.Python at gmail.com (Marco Sulla) Date: Sat, 2 Jan 2021 00:18:06 +0100 Subject: A random word from one of two lists In-Reply-To: References: Message-ID: Try this: >>> animal = ['koala', 'kangaroo'] >>> fruit = ['banana', 'apple'] >>> words = {'animals': animal, 'fruits': fruit} >>> kinds = tuple(words.keys()) >>> kind = random.choice(kinds) >>> kind 'animals' >>> word = random.choice(words[kind]) >>> word 'koala' From alan at csail.mit.edu Fri Jan 1 19:07:22 2021 From: alan at csail.mit.edu (Alan Bawden) Date: Fri, 01 Jan 2021 19:07:22 -0500 Subject: Control stript which is runing in background. References: <86a6ttjkmd.fsf@williamsburg.bawden.org> Message-ID: <865z4gjj5x.fsf@williamsburg.bawden.org> jak writes: Il 01/01/2021 06:23, Alan Bawden ha scritto: > jak writes: > > Running the command: > > $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe > > the three texts do not mix.... > > The three texts do not mix as long at the contents of bible.txt is short > enough (and provided `cat' only calls `write' once). In the POSIX > specification, the manual page for the `write' system call describes > writing to a pipe or FIFO as follows: > > Write requests of {PIPE_BUF} bytes or less shall not be interleaved > with data from other processes doing writes on the same pipe. Writes > of greater than {PIPE_BUF} bytes may have data interleaved, on > arbitrary boundaries, with writes by other processes, whether or not > the O_NONBLOCK flag of the file status flags is set. > Ok. And... ...Running the command: $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe the three texts do not mix.... Saying it again doesn't make it any more true. If bible.txt is large enough, they most definitely DO mix! Just to make sure I wasn't missing something, I tested your exact command before I sent my previous reply. They mixed. -- Alan Bawden From Bischoop at vimart.net Fri Jan 1 20:25:32 2021 From: Bischoop at vimart.net (Bischoop) Date: Sat, 2 Jan 2021 01:25:32 -0000 (UTC) Subject: A random word from one of two lists References: Message-ID: On 2021-01-01, Cameron Simpson wrote: > > kinds = list(words.keys()) > Yes, solved it with that exeactly. -- thanks From Bischoop at vimart.net Fri Jan 1 20:28:11 2021 From: Bischoop at vimart.net (Bischoop) Date: Sat, 2 Jan 2021 01:28:11 -0000 (UTC) Subject: A random word from one of two lists References: <5fefbb0d$0$3250$426a34cc@news.free.fr> Message-ID: On 2021-01-02, Python wrote: > > >>> from random import choice > >>> choice(words[choice(list(words.keys()))]) > 'apple' > >>> choice(words[choice(list(words.keys()))]) > 'kangaroo' > >>> choice(words[choice(list(words.keys()))]) > 'koala' > >>> choice(words[choice(list(words.keys()))]) > 'apple' > >>> choice(words[choice(list(words.keys()))]) > 'kangaroo' > > or this? > > >>> randstuff = lambda: choice(words[choice(list(words.keys()))]) > >>> randstuff() > 'kangaroo' > >>> randstuff() > 'kangaroo' > >>> randstuff() > 'apple' > >>> randstuff() > 'kangaroo' > >>> randstuff() > 'koala' > >>> randstuff() > 'banana' that lambada method is good. -- Thanks From nospam at please.ty Sat Jan 2 02:55:14 2021 From: nospam at please.ty (jak) Date: Sat, 2 Jan 2021 08:55:14 +0100 Subject: Control stript which is runing in background. References: <86a6ttjkmd.fsf@williamsburg.bawden.org> <865z4gjj5x.fsf@williamsburg.bawden.org> Message-ID: Il 02/01/2021 01:07, Alan Bawden ha scritto: > jak writes: > > Il 01/01/2021 06:23, Alan Bawden ha scritto: > > jak writes: > > > > Running the command: > > > > $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe > > > > the three texts do not mix.... > > > > The three texts do not mix as long at the contents of bible.txt is short > > enough (and provided `cat' only calls `write' once). In the POSIX > > specification, the manual page for the `write' system call describes > > writing to a pipe or FIFO as follows: > > > > Write requests of {PIPE_BUF} bytes or less shall not be interleaved > > with data from other processes doing writes on the same pipe. Writes > > of greater than {PIPE_BUF} bytes may have data interleaved, on > > arbitrary boundaries, with writes by other processes, whether or not > > the O_NONBLOCK flag of the file status flags is set. > > > Ok. And... > ...Running the command: > > $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe > > the three texts do not mix.... > > Saying it again doesn't make it any more true. If bible.txt is large > enough, they most definitely DO mix! Just to make sure I wasn't missing > something, I tested your exact command before I sent my previous reply. > They mixed. > This is really strange. On which system did you test? unix, linux or a surrogate (cygwin, msys)? I asked this because bible.txt is 4.25MB size (https://github.com/mxw/grmr/blob/master/src/finaltests/bible.txt)... and the OP needs to send only commands (I hope smaller than the bible). From nospam at please.ty Sat Jan 2 06:06:42 2021 From: nospam at please.ty (jak) Date: Sat, 2 Jan 2021 12:06:42 +0100 Subject: Control stript which is runing in background. References: <86a6ttjkmd.fsf@williamsburg.bawden.org> <865z4gjj5x.fsf@williamsburg.bawden.org> Message-ID: Il 02/01/2021 01:07, Alan Bawden ha scritto: > jak writes: > > Il 01/01/2021 06:23, Alan Bawden ha scritto: > > jak writes: > > > > Running the command: > > > > $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe > > > > the three texts do not mix.... > > > > The three texts do not mix as long at the contents of bible.txt is short > > enough (and provided `cat' only calls `write' once). In the POSIX > > specification, the manual page for the `write' system call describes > > writing to a pipe or FIFO as follows: > > > > Write requests of {PIPE_BUF} bytes or less shall not be interleaved > > with data from other processes doing writes on the same pipe. Writes > > of greater than {PIPE_BUF} bytes may have data interleaved, on > > arbitrary boundaries, with writes by other processes, whether or not > > the O_NONBLOCK flag of the file status flags is set. > > > Ok. And... > ...Running the command: > > $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe > > the three texts do not mix.... > > Saying it again doesn't make it any more true. If bible.txt is large > enough, they most definitely DO mix! Just to make sure I wasn't missing > something, I tested your exact command before I sent my previous reply. > They mixed. > You're right it's mixed. I tried this: terminal 1: $ python3 pmkfifo.py > output.txt terminal 2: cat bible.txt > mypipe & cat bible.txt > mypipe & cat bible.txt > mypipe result: -rw-rw-r-- 1 jak jak 4351187 gen 1 02:56 bible.txt prw-rw-r-- 1 jak jak 0 gen 2 11:40 mypipe -rw-rw-r-- 1 jak jak 13053561 gen 2 11:40 output.txt -rw-rw-r-- 1 jak jak 237 gen 1 02:46 pmkfifo.py then I split ouput.txt: $ split -n 3 -d output.txt result result: -rw-rw-r-- 1 jak jak 4351187 gen 1 02:56 bible.txt prw-rw-r-- 1 jak jak 0 gen 2 11:40 mypipe -rw-rw-r-- 1 jak jak 13053561 gen 2 11:40 output.txt -rw-rw-r-- 1 jak jak 237 gen 1 02:46 pmkfifo.py -rw-rw-r-- 1 jak jak 4351187 gen 2 11:41 result00 -rw-rw-r-- 1 jak jak 4351187 gen 2 11:41 result01 -rw-rw-r-- 1 jak jak 4351187 gen 2 11:41 result02 but: $ cmp result00 result01 result00 result01 differ: byte 1, line 1 $ cmp result01 result02 result01 result02 differ: byte 1, line 1 ...but not happy I wanted to try sure that each process used a single write and I wrote this program in C: int main() { FILE *fp; long len, readed; char *buffer; if((fp = fopen("bible.txt", "rt")) == NULL) return -1; // get file size if(!fseek(fp, 0, SEEK_END)) { len = ftell(fp); } else return -1; // build buffer if((buffer = malloc(len)) == NULL) return -1; // reset position if(fseek(fp, 0, SEEK_SET)) return -1; if((readed = fread(buffer, len, 1, fp)) != 1) return -1; if((fwrite(buffer, len, 1, stdout)) < 1) return -1; fflush(stdout); free(buffer); fclose(fp); return 0; } ... and runned: $ ./mycat > mypipe & ./mycat > mypipe & ./mycat > mypipe I, however, got the same result. From alan at csail.mit.edu Sat Jan 2 06:30:56 2021 From: alan at csail.mit.edu (Alan Bawden) Date: Sat, 02 Jan 2021 06:30:56 -0500 Subject: Control stript which is runing in background. References: <86a6ttjkmd.fsf@williamsburg.bawden.org> <865z4gjj5x.fsf@williamsburg.bawden.org> Message-ID: <861rf3k233.fsf@williamsburg.bawden.org> jak writes: Il 02/01/2021 01:07, Alan Bawden ha scritto: > jak writes: > > Il 01/01/2021 06:23, Alan Bawden ha scritto: > > jak writes: > > > > Running the command: > > > > $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt > cmdpipe > > > > the three texts do not mix.... > > > > The three texts do not mix as long at the contents of bible.txt is short > > enough (and provided `cat' only calls `write' once). In the POSIX > > specification, the manual page for the `write' system call describes > > writing to a pipe or FIFO as follows: > > > > Write requests of {PIPE_BUF} bytes or less shall not be interleaved > > with data from other processes doing writes on the same pipe. Writes > > of greater than {PIPE_BUF} bytes may have data interleaved, on > > arbitrary boundaries, with writes by other processes, whether or not > > the O_NONBLOCK flag of the file status flags is set. > > > ... Just to make sure I wasn't missing > something, I tested your exact command before I sent my previous reply. > They mixed. > This is really strange. On which system did you test? unix, linux or a surrogate (cygwin, msys)? I asked this because bible.txt is 4.25MB size (https://github.com/mxw/grmr/blob/master/src/finaltests/bible.txt)... and the OP needs to send only commands (I hope smaller than the bible). I tested it on both Linux and FreeBSD. My test data was a 289M file I happend to have handy. I didn't try to see how much smaller that file could be to still see mixing, but I can tell you that on FreeBSD PIPE_BUF is 512 bytes and on Linux PIPE_BUF is 4096 bytes. Recent versions of POSIX apparently require PIPE_BUF to be at least 512. (My older copy of POSIX doesn't mention any lower bound at all!) So as long as the OP's commands are no longer than 512 bytes, and as long as they are careful to send commands in a single call to write(), and as long as the commands don't require a reply, they can get away with using a pipe/FIFO. (Or maybe they can know that there will only ever be one client.) -- Alan Bawden From nospam at please.ty Sat Jan 2 06:33:11 2021 From: nospam at please.ty (jak) Date: Sat, 2 Jan 2021 12:33:11 +0100 Subject: Control stript which is runing in background. References: <86a6ttjkmd.fsf@williamsburg.bawden.org> <865z4gjj5x.fsf@williamsburg.bawden.org> Message-ID: PS: difference starts after 64K block From greg.ewing at canterbury.ac.nz Sat Jan 2 08:45:47 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 3 Jan 2021 02:45:47 +1300 Subject: Control stript which is runing in background. In-Reply-To: <861rf3k233.fsf@williamsburg.bawden.org> References: <86a6ttjkmd.fsf@williamsburg.bawden.org> <865z4gjj5x.fsf@williamsburg.bawden.org> <861rf3k233.fsf@williamsburg.bawden.org> Message-ID: On 3/01/21 12:30 am, Alan Bawden wrote: > So as long as the OP's commands are no longer than 512 bytes, and as > long as they are careful to send commands in a single call to write(), Also note that's one write() system call, which may or may not correspond to one Python write() call. -- Greg From topandroidapps.zooparty at gmail.com Sat Jan 2 12:14:34 2021 From: topandroidapps.zooparty at gmail.com (Housebyte Bestofnet) Date: Sat, 2 Jan 2021 09:14:34 -0800 (PST) Subject: Kalman Filter for predicting randomized chaos in jupyter labs Message-ID: As a start to this forum Ive included this wonderful peice of Vanilla code - [b]The Kalman Filter[/b] I downloaded from github this wonderfully elegant Kalman filter : [url]https://github.com/hbcbh1999/kalman-filter[/url] Its a really nice and simple implementation using the equations you can find on wikipedia [url]https://en.wikipedia.org/wiki/Kalman_filter[/url] It looks really awsome when applied to the [url=http://spacetripping.just4books.co.uk/HiRobot/viewtopic.php?f=7&t=6]Arneodo XS dimension Chaotic Attractor[/url] with added noise. Enjoy. [color=#FF0000]Works in Python 2.7 or Python 3.0+[/color] [code]#!/usr/bin/env python # coding: utf-8 # In[1]: get_ipython().magic(u'matplotlib inline') import numpy as np # In[2]: class KalmanFilter(object): def __init__(self, F = None, B = None, H = None, Q = None, R = None, P = None, x0 = None): if(F is None or H is None): raise ValueError("Set proper system dynamics.") self.n = F.shape[1] self.m = H.shape[1] self.F = F self.H = H self.B = 0 if B is None else B self.Q = np.eye(self.n) if Q is None else Q self.R = np.eye(self.n) if R is None else R self.P = np.eye(self.n) if P is None else P self.x = np.zeros((self.n, 1)) if x0 is None else x0 def predict(self, u = 0): self.x = np.dot(self.F, self.x) + np.dot(self.B, u) self.P = np.dot(np.dot(self.F, self.P), self.F.T) + self.Q return self.x def update(self, z): y = z - np.dot(self.H, self.x) S = self.R + np.dot(self.H, np.dot(self.P, self.H.T)) K = np.dot(np.dot(self.P, self.H.T), np.linalg.inv(S)) self.x = self.x + np.dot(K, y) I = np.eye(self.n) self.P = np.dot(np.dot(I - np.dot(K, self.H), self.P), (I - np.dot(K, self.H)).T) + np.dot(np.dot(K, self.R), K.T) return y def arneodo(x, y, z, a=-5.5, b=3.5, c=-1): ''' Given: x, y, z: a point of interest in three dimensional space s, r, b: parameters defining the lorenz attractor Returns: x_dot, y_dot, z_dot: values of the lorenz attractor's partial derivatives at the point x, y, z ''' x_dot = y y_dot = z z_dot = -a*x-b*y-z+c*(x**3) return x_dot, y_dot, z_dot dt = 0.01 num_steps = 7000 # Need one more for the initial values xs = np.empty(num_steps + 1) ys = np.empty(num_steps + 1) zs = np.empty(num_steps + 1) # Set initial values xs[0], ys[0], zs[0] = (0.1, 0, 0.1) # Step through "time", calculating the partial derivatives at the current point # and using them to estimate the next point for i in range(num_steps): x_dot, y_dot, z_dot = arneodo(xs[i], ys[i], zs[i]) xs[i + 1] = xs[i] + (x_dot * dt) ys[i + 1] = ys[i] + (y_dot * dt) zs[i + 1] = zs[i] + (z_dot * dt) def example(): dt = 1.0/60 F = np.array([[1, dt, 0], [0, 1, dt], [0, 0, 1]]).reshape(3,3) H = np.array([1, 0, 0]).reshape(1, 3) Q = np.array([[0.05, 0.05, 0.0], [0.05, 0.05, 0.0], [0.0, 0.0, 0.0]]).reshape(3,3) R = np.array([0.5]).reshape(1, 1) Error = np.empty(7002) x = np.linspace(-10, 10, 100) measurements = xs + np.random.normal(0, 2, 7001) #- (x**2 + 2*x - 2) kf = KalmanFilter(F = F, H = H, Q = Q, R = R) predictions = [] n=0 for z in measurements: n+=1 predictions.append(np.dot(H, kf.predict())[0]) Error[n] =kf.update(z) import matplotlib.pyplot as plt plt.plot(range(len(Error)), Error, label = 'Error') plt.plot(range(len(measurements)), measurements, label = 'Measurements') plt.plot(range(len(predictions)), np.array(predictions), label = 'Kalman Filter Prediction') plt.plot(range(len(xs)), xs, label = 'Signal') plt.legend() plt.show() if __name__ == '__main__': example() [/code] The proceeding discussions will be about the use of the following matrices in the Kalman Filter, what form they may take and how they can be derived from the distribution we are modelling : dt = 1.0/60 F = np.array([[1, dt, 0], [0, 1, dt], [0, 0, 1]]).reshape(3,3) #State Transition Model H = np.array([1, 0, 0]).reshape(1, 3) #Observation Model Q = np.array([[0.05, 0.05, 0.0], [0.05, 0.05, 0.0], [0.0, 0.0, 0.0]]).reshape(3,3) #Covariance Matrix R = np.array([0.5]).reshape(1, 1)[/code] #Covariance Matrix [url=https://en.wikipedia.org/wiki/Autoregressive_integrated_moving_average]ARIMA - Wikipedia[/url] [img]http://spacetripping.just4books.co.uk/HiRobot/output_4_0.png[/img] Original source: http://spacetripping.just4books.co.uk/HiRobot/viewtopic.php?f=7&t=3 From Bischoop at vimart.net Sat Jan 2 13:36:47 2021 From: Bischoop at vimart.net (Bischoop) Date: Sat, 2 Jan 2021 18:36:47 -0000 (UTC) Subject: A random word from one of two lists References: Message-ID: On 2021-01-02, Stefan Ram wrote: > > The following might /not/ be good programming style, > but addresses the idea to choose a "variable". > I kinda like the below one. > import random > animal = ['koala', 'kangaroo'] > fruit = ['banana', 'apple'] > kinds = ['animal','fruit'] > variable = random.choice( kinds ) > result = random.choice( globals()[ variable ]) > print( result ) > > Otherweise, I'd go this way without a dictionary. > import random > animal = ['koala', 'kangaroo'] > fruit = ['banana', 'apple'] > kinds = [animal,fruit] > kind = random.choice( kinds ) > result = random.choice( kind ) > print( result ) > I had that solution in mind but I thought that one is not good programming style or not Pythonin :-) -- Thanks > From PythonList at DancesWithMice.info Sat Jan 2 15:42:20 2021 From: PythonList at DancesWithMice.info (dn) Date: Sun, 3 Jan 2021 09:42:20 +1300 Subject: Plotting in python for Monte Carlo Method In-Reply-To: References: Message-ID: <6376e994-fc19-5556-45f1-b78dd0256ef8@DancesWithMice.info> On 1/2/21 12:17 AM, Meghna Karkera wrote: > Dear Respected Sir > > May I request you to help me plot the number of histories versus standard > deviation along with mean for integral of 2x dx from 0 to 5 abtained using > the Monte Carlo python program. > > I've calculated the integral of 2x dx from 0 to 5 using the Monte Carlo > method described in the following link. https://youtu.be/WAf0rqwAvgg Welcome to the list. Let's try to clarify a few points:- Is this request connected with a course of study? If so, which one? We don't 'do homework' but are happy to help. What code have you written so far, and which part is not working? (please copy-paste exact code and error messages, after reducing the code to its shortest reproducible state) NB there is also the Python-Tutor Discussion List which is specifically for trainees' and trainers' use. Contrarily, if you are looking for someone to write code for you, then there are likely many 'here' who will be happy to quote an hourly-rate. -- Regards =dn From tjreedy at udel.edu Sat Jan 2 17:16:43 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 2 Jan 2021 17:16:43 -0500 Subject: ANN: unicode 2.8 In-Reply-To: References: Message-ID: On 1/1/2021 3:48 PM, garabik-news-2005-05 at kassiopeia.juls.savba.sk wrote: > Terry Reedy wrote: >> On 12/31/2020 9:36 AM, garabik-news-2005-05 at kassiopeia.juls.savba.sk wrote: >>> unicode is a simple python command line utility that displays >>> properties for a given unicode character, or searches >>> unicode database for a given name. >> ... >>> Changes since previous versions: >>> >>> * display ASCII table (either traditional with --ascii or the new >>> EU?UK Trade and Cooperation Agreement version with --brexit-ascii) The latter option implied to me that the agreement defines an intentional variation on standard ASCII. I immediately wondered whether they had changed the actual 7-bit ascii code, which would be egregiously bad, or made yet another variation of 8-bit 'extended ascii', perhaps to ensure inclusion both the pound and euro signs. So I googled 'brexit ascii'. And was surprised to discover that there is no such thing as 'brexit ascii', just yet another cock-up in text preparation. (I have seen worse when a digital text of mine was mangled during markup. Fortunately, I was allowed to read the page proofs. But I still don't understand how spelling errors were introduced within words I had spelled correctly.) >> Are you reproducing it with bugs included? >> How is that of any use to anyone? I followed this with links to justify my claim and question: A tweet linking the treaty annex page https://twitter.com/thejsa_/status/1343291595899207681 A stackoverflow question and discussion of the bugs and oddities. https://politics.stackexchange.com/questions/61178/why-does-the-eu-uk-trade-deal-have-the-7-bit-ascii-table-as-an-appendix In the latter are mentions of other text, perhaps copy-pasted from the 1990s recommending the now deprecated SHA1 and referring to Netscape Navigator 4 as a modern browser. Clearly, in the rush to finish, the annex was not properly reviewed by current technical experts. > Including the (correct) ASCII table has been a long term, low priority - > I am using ascii(1) utility reasonably often and it makes sense to > reproduce this functionality. > > And when implementing this, it was a no-brainer to include also the > brexit varian (verbatim). I assume you meant 'variation' and not Varian, the maker of scientific instruments. But why do you consider it a no-brainer to include nonsense in your program and mislead people? People already have enough trouble dealing with text coding. > After all, given the blood and sweat and tears > shed during the negotiations, I am sure each and every line of the > Agreement has been combed and (re)negotiated over and over by experienced > negotiators and verified an army of experts in the fields What are we supposed to make of this? That you already knew that 'brexit-ascii' is nonsense? -- Terry Jan Reedy From rosuav at gmail.com Sat Jan 2 18:53:43 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 3 Jan 2021 10:53:43 +1100 Subject: ANN: unicode 2.8 In-Reply-To: References: Message-ID: On Sun, Jan 3, 2021 at 10:28 AM Terry Reedy wrote: > > And when implementing this, it was a no-brainer to include also the > > brexit varian (verbatim). > > I assume you meant 'variation' and not Varian, the maker of scientific > instruments. I assumed simple typo for "variant" ChrisA From arj.python at gmail.com Sat Jan 2 23:01:54 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 3 Jan 2021 08:01:54 +0400 Subject: Python Mauritius Usergroup - End of Year report 2020 Message-ID: Greetings list, Here's our usergroup's end of year report for 2020: Happy reading! https://www.pymug.com/assets/pymug_end_of_year_2020_v2.pdf Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius From PythonList at DancesWithMice.info Sat Jan 2 23:12:22 2021 From: PythonList at DancesWithMice.info (dn) Date: Sun, 3 Jan 2021 17:12:22 +1300 Subject: Python Mauritius Usergroup - End of Year report 2020 In-Reply-To: References: Message-ID: <73c514b9-3772-bbaf-ec41-f739368396ea@DancesWithMice.info> On 1/3/21 5:01 PM, Abdur-Rahmaan Janhangeer wrote: > Greetings list, > > Here's our usergroup's end of year report for 2020: > Happy reading! > > https://www.pymug.com/assets/pymug_end_of_year_2020_v2.pdf Well done @A-R! -- Regards =dn From arj.python at gmail.com Sun Jan 3 04:03:15 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Sun, 3 Jan 2021 13:03:15 +0400 Subject: Python Mauritius Usergroup - End of Year report 2020 In-Reply-To: <73c514b9-3772-bbaf-ec41-f739368396ea@DancesWithMice.info> References: <73c514b9-3772-bbaf-ec41-f739368396ea@DancesWithMice.info> Message-ID: Greetings, ^^ Thanks! Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius On Sun, Jan 3, 2021 at 8:12 AM dn via Python-list wrote: > On 1/3/21 5:01 PM, Abdur-Rahmaan Janhangeer wrote: > > Greetings list, > > > > Here's our usergroup's end of year report for 2020: > > Happy reading! > > > > https://www.pymug.com/assets/pymug_end_of_year_2020_v2.pdf > > > Well done @A-R! > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list > From Bischoop at vimart.net Sun Jan 3 07:30:58 2021 From: Bischoop at vimart.net (Bischoop) Date: Sun, 3 Jan 2021 12:30:58 -0000 (UTC) Subject: A random word from one of two lists References: Message-ID: On 2021-01-02, Stefan Ram wrote: > Bischoop writes: >>On 2021-01-02, Stefan Ram wrote: >>>Otherweise, I'd go this way without a dictionary. >>>import random >>>animal = ['koala', 'kangaroo'] >>>fruit = ['banana', 'apple'] >>>kinds = [animal,fruit] >>>kind = random.choice( kinds ) >>>result = random.choice( kind ) >>>print( result ) >>I had that solution in mind but I thought that one is not good >>programming style or not Pythonin :-) > > I do not see any stylistic problem when you use this approach > with "nested lists". List indexing by a number should even be > faster than indexing a dictionary. > > Now I know that's ok, seems I was ovethingking while solution was so simply. -- Thanks From barry at barrys-emacs.org Sun Jan 3 08:49:46 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Sun, 3 Jan 2021 13:49:46 +0000 Subject: Does windows edit .py file shebangs? In-Reply-To: References: <00C1C4B3-01C9-4DE9-AD24-17A0C209D998@barrys-emacs.org> Message-ID: <02DECEE8-FE3C-4111-8D79-6671999FD023@barrys-emacs.org> > On 1 Jan 2021, at 17:03, Eryk Sun wrote: > > On 1/1/21, Barry Scott wrote: >> I found python scripts have had their shebang lines edited behind my back. >> >> The shebang line I'm seeing is: >> >> #!C:\Users\barry\AppData\Local\Microsoft\WindowsApps\python3.EXE >> >> Is this Microsoft being "helpful"? >> Does anyone know what I will have done to best with this "help"? >> >> What do I need to do to prevent this happening? > > Shebang lines may be localized to the current interpreter when > installing a package. Otherwise I don't know what's causing that. These are personal scripts not installed from PyPI for example. > > Regarding Windows, the system doesn't support shebang lines in any > way. Python's installer associates .py files with the py.exe launcher, > which looks for a shebang line in a script in order to determine which > executable to run. It supports shebangs with fully-qualified Windows > paths, as well as virtual commands for registered installations, such > as "python", "python3", "python3.9-32", "/usr/bin/python3", and > "/usr/bin/env python". Indeed since py.exe is the only tool that supports the shebang this is very strange that the change was made. I rely on py.exe handling shebang for my cross platform scripts. I've been doing some more investigation and found that the change happened at 01/01/2021 16:16. The shebang is pointing to a 0 length PYTHON3.EXE. The files that where changed where all in my %USERPROFILE%\bin folder that is on my PATH. I manage the files in that folder with tools that sync the files from an SVN repo. The version of the files in the repo do not have the edit. My PATH does not have a PYTHON.EXE or PYTHON3.EXE on it as I use py.exe. Is that the path used by the Microsoft store for the python alias? I have now turned off the alias in the "Manage App execution aliases" in settings. I did find this blog post from Steve Dower about the app store python. https://devblogs.microsoft.com/python/python-in-the-windows-10-may-2019-update/ I have also scanned the Windows logs for events at the time stamp from the file and could not see anything. Thinking back to the 1st I did run Visual Studio 2019 Community edition at that time. It was first time on a long time and I had to login and update it. Is Visual Studio doing the change? If so why? Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From mystirk at gmail.com Sun Jan 3 09:48:56 2021 From: mystirk at gmail.com (Alex Kaye) Date: Sun, 3 Jan 2021 07:48:56 -0700 Subject: Python Mauritius Usergroup - End of Year report 2020 In-Reply-To: References: <73c514b9-3772-bbaf-ec41-f739368396ea@DancesWithMice.info> Message-ID: Super report, need more like it from others ! A.K. On Sun, Jan 3, 2021 at 2:06 AM Abdur-Rahmaan Janhangeer < arj.python at gmail.com> wrote: > Greetings, > > ^^ Thanks! > > Kind Regards, > > Abdur-Rahmaan Janhangeer > about | blog > > github > Mauritius > > > On Sun, Jan 3, 2021 at 8:12 AM dn via Python-list > wrote: > > > On 1/3/21 5:01 PM, Abdur-Rahmaan Janhangeer wrote: > > > Greetings list, > > > > > > Here's our usergroup's end of year report for 2020: > > > Happy reading! > > > > > > https://www.pymug.com/assets/pymug_end_of_year_2020_v2.pdf > > > > > > Well done @A-R! > > -- > > Regards =dn > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > From rshepard at appl-ecosys.com Sun Jan 3 10:13:22 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 3 Jan 2021 07:13:22 -0800 (PST) Subject: NumPy: build script not finding correct python version Message-ID: I'm trying to rebuild numpy-1.18.2 using the newly installed Python-3.9.1. The script fails when running setup.py: Traceback (most recent call last): File "setup.py", line 32, in raise RuntimeError("Python version >= 3.5 required.") RuntimeError: Python version >= 3.5 required. When I invoke python3 from the command line the version is correctly indentified: $ python3 Python 3.9.1 (default, Dec 29 2020, 15:09:15) [GCC 5.5.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.version_info[:2] (3, 9) >>> Ignoring the large explanatory comment the lines above that throwing the error are: from __future__ import division, print_function DOCLINES = (__doc__ or '').split("\n") import os import sys import subprocess import textwrap import sysconfig if sys.version_info[:2] < (3, 5): raise RuntimeError("Python version >= 3.5 required.") I'm not seeing why sys.version_info is not finding the installed version within the script and need insight from others with greater Python knowledge than I have. TIA, Rich From eryksun at gmail.com Sun Jan 3 10:13:40 2021 From: eryksun at gmail.com (Eryk Sun) Date: Sun, 3 Jan 2021 09:13:40 -0600 Subject: Does windows edit .py file shebangs? In-Reply-To: <02DECEE8-FE3C-4111-8D79-6671999FD023@barrys-emacs.org> References: <00C1C4B3-01C9-4DE9-AD24-17A0C209D998@barrys-emacs.org> <02DECEE8-FE3C-4111-8D79-6671999FD023@barrys-emacs.org> Message-ID: On 1/3/21, Barry Scott wrote: > > I've been doing some more investigation and found that the change happened > at 01/01/2021 16:16. The shebang is pointing to a 0 length PYTHON3.EXE. The files in "%LocalAppData%\Microsoft\WindowsApps" are AppExec reparse points. NT filesystem reparse points are a generalized form of filesystem link, with registered handlers indentified by a tag value in the reparse data buffer. Various reparse-point types implement Unix-style mountpoints and symlinks, as well as dynamic offline and virtual files such as OneDrive. AppExec reparse points (aka app execution aliases) have no handler in the kernel, so they can only be accessed by directly opening them. WinAPI CreateProcessW uses information in the link to locate the app and create an access token that allows executing it. The app itself is usually installed in a directory in "%ProgramFiles%\WindowsApps". You can view the raw contents of a reparse point using `fsutil.exe reparsepoint query `. > Thinking back to the 1st I did run Visual Studio 2019 Community edition at > that time. It was first time on a long time and I had to login and update it. You could try to reproduce the scenario to see whether it modifies your files. I wouldn't expect it to do something like that automatically, but it does seem like the kind of 'helpful' thing a full-service IDE would do when saving a script. From barry at barrys-emacs.org Sun Jan 3 10:29:13 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Sun, 3 Jan 2021 15:29:13 +0000 Subject: Does windows edit .py file shebangs? In-Reply-To: References: <00C1C4B3-01C9-4DE9-AD24-17A0C209D998@barrys-emacs.org> <02DECEE8-FE3C-4111-8D79-6671999FD023@barrys-emacs.org> Message-ID: > On 3 Jan 2021, at 15:13, Eryk Sun wrote: > > On 1/3/21, Barry Scott wrote: >> >> I've been doing some more investigation and found that the change happened >> at 01/01/2021 16:16. The shebang is pointing to a 0 length PYTHON3.EXE. > > The files in "%LocalAppData%\Microsoft\WindowsApps" are AppExec > reparse points. NT filesystem reparse points are a generalized form of > filesystem link, with registered handlers indentified by a tag value > in the reparse data buffer. Various reparse-point types implement > Unix-style mountpoints and symlinks, as well as dynamic offline and > virtual files such as OneDrive. > > AppExec reparse points (aka app execution aliases) have no handler in > the kernel, so they can only be accessed by directly opening them. > WinAPI CreateProcessW uses information in the link to locate the app > and create an access token that allows executing it. The app itself is > usually installed in a directory in "%ProgramFiles%\WindowsApps". > > You can view the raw contents of a reparse point using `fsutil.exe > reparsepoint query `. Aha a reparse point! I've cleaned up too much to do this. I had to get back to a working state. If it breaks again I'll use fsutils to investigate. > >> Thinking back to the 1st I did run Visual Studio 2019 Community edition at >> that time. It was first time on a long time and I had to login and update it. > > You could try to reproduce the scenario to see whether it modifies > your files. I wouldn't expect it to do something like that > automatically, but it does seem like the kind of 'helpful' thing a > full-service IDE would do when saving a script. The only time I every use the IDE is when I run the debugger everything else I do from the command line. The only reason I ran the IDE at all is that is the way to get it to update itself. In other words its not that it "fixed" a file I was editing. I can only think that it was part of the updating of Visual Studio that did this. Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From semantina at gmail.com Sun Jan 3 11:34:35 2021 From: semantina at gmail.com (Codeliner) Date: Sun, 3 Jan 2021 08:34:35 -0800 (PST) Subject: Copying column values up based on other column values Message-ID: Hello, I have this dataframe import numpy as np import pandas as pd from numpy.random import randn df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z']) W X Y Z A -0.183141 -0.398652 0.909746 0.332105 B -0.587611 -2.046930 1.446886 0.167606 C 1.142661 -0.861617 -0.180631 1.650463 D 1.174805 -0.957653 1.854577 0.335818 E -0.680611 -1.051793 1.448004 -0.490869 is there a way to create a column S - which will copy column column Y values UP- if values in column Y are above 1 - otherwise return new value above zero?.I made this manually: S: A 1.446886 B 1.446886 C 1.854577 D 1.854577 E 1.448004 thanks a lot! From rshepard at appl-ecosys.com Sun Jan 3 11:53:43 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Sun, 3 Jan 2021 08:53:43 -0800 (PST) Subject: NumPy: build script not finding correct python version [UPDATE] In-Reply-To: References: Message-ID: On Sun, 3 Jan 2021, Rich Shepard wrote: > I'm trying to rebuild numpy-1.18.2 using the newly installed Python-3.9.1. > The script fails when running setup.py: > Traceback (most recent call last): > File "setup.py", line 32, in > raise RuntimeError("Python version >= 3.5 required.") > RuntimeError: Python version >= 3.5 required. Okay. Further research taught me that setup.py has been replaced with setuptools so I need to learn how to convert the build script to setuptools rather than setup.py. Rich From jsf80238 at gmail.com Sun Jan 3 12:08:11 2021 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 3 Jan 2021 10:08:11 -0700 Subject: Copying column values up based on other column values In-Reply-To: References: Message-ID: > > import numpy as np > import pandas as pd > from numpy.random import randn > df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z']) > > W X Y Z > A -0.183141 -0.398652 0.909746 0.332105 > B -0.587611 -2.046930 1.446886 0.167606 > C 1.142661 -0.861617 -0.180631 1.650463 > D 1.174805 -0.957653 1.854577 0.335818 > E -0.680611 -1.051793 1.448004 -0.490869 > > is there a way to create a column S - which will copy column column Y > values UP- if values in column Y are above 1 - otherwise return new value > above zero?.I made this manually: > > S: > > A 1.446886 > B 1.446886 > C 1.854577 > D 1.854577 > E 1.448004 > Here's one solution. No consideration to performance. import numpy as np import pandas as pd from numpy.random import randn df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z']) print(df) y_series = df["Y"] for i in range(len(y_series)): if i == len(y_series) - 1: # Last one, nothing to copy break if y_series[i+1] > 1: y_series[i] = y_series[i+1] df["Y"] = y_series print(df) From mats at wichmann.us Sun Jan 3 12:38:26 2021 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 3 Jan 2021 10:38:26 -0700 Subject: A random word from one of two lists In-Reply-To: References: Message-ID: <86d5018e-b835-ea1f-ed84-99829e0edc89@wichmann.us> On 1/3/21 5:30 AM, Bischoop wrote: > On 2021-01-02, Stefan Ram wrote: >> Bischoop writes: >>> On 2021-01-02, Stefan Ram wrote: >>>> Otherweise, I'd go this way without a dictionary. >>>> import random >>>> animal = ['koala', 'kangaroo'] >>>> fruit = ['banana', 'apple'] >>>> kinds = [animal,fruit] >>>> kind = random.choice( kinds ) >>>> result = random.choice( kind ) >>>> print( result ) >>> I had that solution in mind but I thought that one is not good >>> programming style or not Pythonin :-) >> >> I do not see any stylistic problem when you use this approach >> with "nested lists". List indexing by a number should even be >> faster than indexing a dictionary. >> >> > Now I know that's ok, seems I was ovethingking while solution was so > simply. > > -- > Thanks > You don't really need to do this as a two-level selection: import random animal = ['koala', 'kangaroo'] fruit = ['banana', 'apple'] result = random.choice(animal + fruit) print(result) From semantina at gmail.com Sun Jan 3 13:16:55 2021 From: semantina at gmail.com (Codeliner) Date: Sun, 3 Jan 2021 10:16:55 -0800 (PST) Subject: Copying column values up based on other column values In-Reply-To: References: Message-ID: On Sunday, January 3, 2021 at 7:08:49 PM UTC+2, Jason Friedman wrote: > > > > import numpy as np > > import pandas as pd > > from numpy.random import randn > > df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z']) > > > > W X Y Z > > A -0.183141 -0.398652 0.909746 0.332105 > > B -0.587611 -2.046930 1.446886 0.167606 > > C 1.142661 -0.861617 -0.180631 1.650463 > > D 1.174805 -0.957653 1.854577 0.335818 > > E -0.680611 -1.051793 1.448004 -0.490869 > > > > is there a way to create a column S - which will copy column column Y > > values UP- if values in column Y are above 1 - otherwise return new value > > above zero?.I made this manually: > > > > S: > > > > A 1.446886 > > B 1.446886 > > C 1.854577 > > D 1.854577 > > E 1.448004 > > > Here's one solution. No consideration to performance. > import numpy as np > import pandas as pd > from numpy.random import randn > df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z']) > print(df) > > y_series = df["Y"] > for i in range(len(y_series)): > if i == len(y_series) - 1: > # Last one, nothing to copy > break > if y_series[i+1] > 1: > y_series[i] = y_series[i+1] > > df["Y"] = y_series > print(df) Thank you Jason for this lovely for loop - is there a way to make this with pandas series or numpy arrays? for maximum speed? From Richard at Damon-Family.org Sun Jan 3 13:34:19 2021 From: Richard at Damon-Family.org (Richard Damon) Date: Sun, 3 Jan 2021 13:34:19 -0500 Subject: A random word from one of two lists In-Reply-To: <86d5018e-b835-ea1f-ed84-99829e0edc89@wichmann.us> References: <86d5018e-b835-ea1f-ed84-99829e0edc89@wichmann.us> Message-ID: <3e20779e-ceea-e74f-c62e-d4d2f785de86@Damon-Family.org> On 1/3/21 12:38 PM, Mats Wichmann wrote: > On 1/3/21 5:30 AM, Bischoop wrote: >> On 2021-01-02, Stefan Ram wrote: >>> Bischoop writes: >>>> On 2021-01-02, Stefan Ram wrote: >>>>> Otherweise, I'd go this way without a dictionary. >>>>> import random >>>>> animal = ['koala', 'kangaroo'] >>>>> fruit = ['banana', 'apple'] >>>>> kinds = [animal,fruit] >>>>> kind = random.choice( kinds ) >>>>> result = random.choice( kind ) >>>>> print( result ) >>>> I had that solution in mind but I thought that one is not good >>>> programming style or not Pythonin :-) >>> >>> ?? I do not see any stylistic problem when you use this approach >>> ?? with "nested lists". List indexing by a number should even be >>> ?? faster than indexing a dictionary. >>> >>> >> Now I know that's ok, seems I was ovethingking while solution was so >> simply. >> >> -- >> Thanks >> > > You don't really need to do this as a two-level selection: > > import random > animal = ['koala', 'kangaroo'] > fruit = ['banana', 'apple'] > result = random.choice(animal + fruit) > print(result) It depends on what distribution of results you want. Since the example had two equal length list is doesn't matter, but if, say, there were many more animals then fruit, your method would produce an animal more often than a fruit, but the two level method will make the distribution 50% fruits, 50% animals independent on the number in each category. Which is the right answer is problem specific. -- Richard Damon From semantina at gmail.com Sun Jan 3 13:32:53 2021 From: semantina at gmail.com (Codeliner) Date: Sun, 3 Jan 2021 10:32:53 -0800 (PST) Subject: Copying column values up based on other column values In-Reply-To: References: Message-ID: <0542abf2-425a-409c-8fa5-3cd51daaf869n@googlegroups.com> On Sunday, January 3, 2021 at 8:17:16 PM UTC+2, Codeliner wrote: > On Sunday, January 3, 2021 at 7:08:49 PM UTC+2, Jason Friedman wrote: > > > > > > import numpy as np > > > import pandas as pd > > > from numpy.random import randn > > > df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z']) > > > > > > W X Y Z > > > A -0.183141 -0.398652 0.909746 0.332105 > > > B -0.587611 -2.046930 1.446886 0.167606 > > > C 1.142661 -0.861617 -0.180631 1.650463 > > > D 1.174805 -0.957653 1.854577 0.335818 > > > E -0.680611 -1.051793 1.448004 -0.490869 > > > > > > is there a way to create a column S - which will copy column column Y > > > values UP- if values in column Y are above 1 - otherwise return new value > > > above zero?.I made this manually: > > > > > > S: > > > > > > A 1.446886 > > > B 1.446886 > > > C 1.854577 > > > D 1.854577 > > > E 1.448004 > > > > > Here's one solution. No consideration to performance. > > import numpy as np > > import pandas as pd > > from numpy.random import randn > > df=pd.DataFrame(randn(5,4),['A','B','C','D','E'],['W','X','Y','Z']) > > print(df) > > > > y_series = df["Y"] > > for i in range(len(y_series)): > > if i == len(y_series) - 1: > > # Last one, nothing to copy > > break > > if y_series[i+1] > 1: > > y_series[i] = y_series[i+1] > > > > df["Y"] = y_series > > print(df) > Thank you Jason for this lovely for loop - is there a way to make this with pandas series or numpy arrays? for maximum speed? can something done along these lines? df['run2'] = df['b'].apply(lambda x: df['b'].shift(1) if x > 1 else df['b']) From mats at wichmann.us Sun Jan 3 14:40:47 2021 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 3 Jan 2021 12:40:47 -0700 Subject: A random word from one of two lists In-Reply-To: <3e20779e-ceea-e74f-c62e-d4d2f785de86@Damon-Family.org> References: <86d5018e-b835-ea1f-ed84-99829e0edc89@wichmann.us> <3e20779e-ceea-e74f-c62e-d4d2f785de86@Damon-Family.org> Message-ID: On 1/3/21 11:34 AM, Richard Damon wrote: > It depends on what distribution of results you want. Since the example > had two equal length list is doesn't matter, but if, say, there were > many more animals then fruit, your method would produce an animal more > often than a fruit, but the two level method will make the distribution > 50% fruits, 50% animals independent on the number in each category. > > Which is the right answer is problem specific. quite true! From pablogsal at gmail.com Mon Jan 4 16:36:59 2021 From: pablogsal at gmail.com (Pablo Galindo Salgado) Date: Mon, 4 Jan 2021 21:36:59 +0000 Subject: [RELEASE] Python 3.10.0a4 is now available Message-ID: Happy new year to all of you. I hope you all have a great start of the year! And how to best celebrate that we have left 2020 behind that with a new Python alpha release? :) Go get it here: https://www.python.org/downloads/release/python-3100a4/ *Major new features of the 3.10 series, compared to 3.9* Python 3.10 is still in development. This releasee, 3.10.0a4 is the second of six planned alpha releases. Alpha releases are intended to make it easier to test the current state of new features and bug fixes and to test the release process. During the alpha phase, features may be added up until the start of the beta phase (2021-05-03) and, if necessary, may be modified or deleted up until the release candidate phase (2021-10-04). Please keep in mind that this is a preview release and its use is not recommended for production environments. Many new features for Python 3.10 are still being planned and written. Among the new major new features and changes so far: * PEP 623 ? Remove wstr from Unicode * PEP 604 ? Allow writing union types as X | Y * PEP 612 ? Parameter Specification Variables * PEP 626 ? Precise line numbers for debugging and other tools. * bpo-38605: from __future__ import annotations (PEP 563) is now the default. * PEP 618 ? Add Optional Length-Checking To zip. (Hey, fellow core developer, if a feature you find important is missing from this list, let me know.) The next pre-release of Python 3.10 will be 3.10.0a5, currently scheduled for 2021-02-01. *And now for something completely different* The Majumdar?Papapetrou spacetime is one surprising solution of the coupled Einstein-Maxwell equations that describe a cluster of static charged black holes with the gravitational and the electrostatic forces cancelling each other out. Each one of these many black holes of the multi-black holes system has a spherical topology and follows the Reissner?Nordstr?m metric . Unsurprisingly, the movement of a test particle in such spacetime is not only a very chaotic system but also has some fractals hiding the complexity of its movement. Regards from cold London, Pablo Galindo Salgado From martin.schoon at gmail.com Tue Jan 5 15:55:10 2021 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 5 Jan 2021 20:55:10 GMT Subject: dayofyear is not great when going into a new year Message-ID: Hello, I have had some Python fun with COVID-19 data. I have done some curve fitting and to make that easier I have transformed date to day of year. Come end of 2020 and beginning of 2021 and this idea falls on its face. There must be a better way of doing this. I am using Pandas for reading and manipulating data coming from a csv file. Scipy, numpy and matplotlib are used for the curve fitting and plotting. TIA, /Martin From rosuav at gmail.com Tue Jan 5 16:27:58 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jan 2021 08:27:58 +1100 Subject: dayofyear is not great when going into a new year In-Reply-To: References: Message-ID: On Wed, Jan 6, 2021 at 8:02 AM Martin Sch??n wrote: > > Hello, > > I have had some Python fun with COVID-19 data. I have done > some curve fitting and to make that easier I have transformed > date to day of year. Come end of 2020 and beginning of 2021 > and this idea falls on its face. > There are multiple definitions for "day of year", depending on how you want to handle certain oddities. The simplest is to identify Jan 1st as 1, Jan 2nd as 2, etc, to Dec 31st as either 365 or 366; but some libraries will define the year as starting with the week that contains the Thursday, or something, and then will define days of year accordingly. If you want an easy way to graph day-by-day data and the exact day numbers are irrelevant, what I'd recommend is: Convert the date into Unix time, divide by 86400, floor it. That'll give you a Julian-style date number where Jan 1st 1970 is 0, Jan 2nd is 1, etc, and at the end of a year, it'll just keep on incrementing. That would get you past the 2020/2021 boundary pretty smoothly. ChrisA From PythonList at danceswithmice.info Tue Jan 5 17:12:11 2021 From: PythonList at danceswithmice.info (dn) Date: Wed, 6 Jan 2021 11:12:11 +1300 Subject: dayofyear is not great when going into a new year In-Reply-To: References: Message-ID: On 1/6/21 9:55 AM, Martin Sch??n wrote: > Hello, > > I have had some Python fun with COVID-19 data. I have done > some curve fitting and to make that easier I have transformed > date to day of year. Come end of 2020 and beginning of 2021 > and this idea falls on its face. > > There must be a better way of doing this. > > I am using Pandas for reading and manipulating data coming > from a csv file. Scipy, numpy and matplotlib are used > for the curve fitting and plotting. An important question is how the day/date is presented in these graphs. The Julian date format used to be more common in Data Processing. Dates are expressed as yy-ddd. Thus, prepending "20" or "21" to existing day-of-year numbers, would separate and sequence correctly. (NB carefully consider str cf int) Another solution is to use a Unix Timestamp for each day. In both cases, arithmetic comparison-logic is possible, and library routines exist to format various reporting-formats. -- Regards =dn From mstemper at gmail.com Tue Jan 5 17:46:09 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Tue, 5 Jan 2021 16:46:09 -0600 Subject: dayofyear is not great when going into a new year In-Reply-To: References: Message-ID: On 05/01/2021 15.27, Chris Angelico wrote: > On Wed, Jan 6, 2021 at 8:02 AM Martin Sch??n wrote: >> I have had some Python fun with COVID-19 data. I have done >> some curve fitting and to make that easier I have transformed >> date to day of year. Come end of 2020 and beginning of 2021 >> and this idea falls on its face. > There are multiple definitions for "day of year", depending on how you > want to handle certain oddities. The simplest is to identify Jan 1st > as 1, Jan 2nd as 2, etc, to Dec 31st as either 365 or 366; but some > libraries will define the year as starting with the week that contains > the Thursday, or something, and then will define days of year > accordingly. > > If you want an easy way to graph day-by-day data and the exact day > numbers are irrelevant, what I'd recommend is: Convert the date into > Unix time, divide by 86400, floor it. That'll give you a Julian-style > date number where Jan 1st 1970 is 0, Jan 2nd is 1, etc, and at the end > of a year, it'll just keep on incrementing. That would get you past > the 2020/2021 boundary pretty smoothly. Possibly better than rolling your own is using standard stuff: >>> from datetime import date,datetime >>> datetime.toordinal(date(2020,1,1)) 737425 >>> datetime.toordinal(date(2021,1,5)) 737795 >>> datetime.toordinal(date(2021,1,5)) - datetime.toordinal(date(2020,1,1)) 370 >>> -- Michael F. Stemper This post contains greater than 95% post-consumer bytes by weight. From rosuav at gmail.com Tue Jan 5 17:53:40 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jan 2021 09:53:40 +1100 Subject: dayofyear is not great when going into a new year In-Reply-To: References: Message-ID: On Wed, Jan 6, 2021 at 9:51 AM Michael F. Stemper wrote: > > On 05/01/2021 15.27, Chris Angelico wrote: > > On Wed, Jan 6, 2021 at 8:02 AM Martin Sch??n wrote: > > >> I have had some Python fun with COVID-19 data. I have done > >> some curve fitting and to make that easier I have transformed > >> date to day of year. Come end of 2020 and beginning of 2021 > >> and this idea falls on its face. > > > There are multiple definitions for "day of year", depending on how you > > want to handle certain oddities. The simplest is to identify Jan 1st > > as 1, Jan 2nd as 2, etc, to Dec 31st as either 365 or 366; but some > > libraries will define the year as starting with the week that contains > > the Thursday, or something, and then will define days of year > > accordingly. > > > > If you want an easy way to graph day-by-day data and the exact day > > numbers are irrelevant, what I'd recommend is: Convert the date into > > Unix time, divide by 86400, floor it. That'll give you a Julian-style > > date number where Jan 1st 1970 is 0, Jan 2nd is 1, etc, and at the end > > of a year, it'll just keep on incrementing. That would get you past > > the 2020/2021 boundary pretty smoothly. > > Possibly better than rolling your own is using standard stuff: > > >>> from datetime import date,datetime > >>> datetime.toordinal(date(2020,1,1)) > 737425 > >>> datetime.toordinal(date(2021,1,5)) > 737795 > >>> datetime.toordinal(date(2021,1,5)) - datetime.toordinal(date(2020,1,1)) > 370 > >>> > Oh yes. In fact, not "possibly", but "definitely" :) ALWAYS use a library for date manipulation. But you have to know what you're doing before you can figure out how to call on the library. ChrisA From * at eli.users.panix.com Tue Jan 5 17:56:28 2021 From: * at eli.users.panix.com (Eli the Bearded) Date: Tue, 5 Jan 2021 22:56:28 +0000 (UTC) Subject: dayofyear is not great when going into a new year References: Message-ID: In comp.lang.python, Chris Angelico wrote: > There are multiple definitions for "day of year", depending on how you > want to handle certain oddities. The simplest is to identify Jan 1st > as 1, Jan 2nd as 2, etc, to Dec 31st as either 365 or 366; but some > libraries will define the year as starting with the week that contains > the Thursday, or something, and then will define days of year > accordingly. That sounds like some weird off-shoot of the ISO-8601 calendar. That document primarily concerns itself with weeks. Week 1 of a year is the first week with a Thursday in it. The last week of a year will be either 52 or 53, and you can have things like days in January belonging to the week of the previous year. Wikipedia gives examples: https://en.wikipedia.org/wiki/ISO_week_date If you are operating on that, then it might indeed make sense to number the days from YYYY-W1-1. I can't say I've ever encountered that. Since W1-1 is always a Monday on the ISO calendar, it would have the neat property that you could always turn day of year into day of week with a mod operation. It would have the quirk that years are either 364 or 371 days, neither of which most people would answer when asked "How many days are there in a year?" I've only used ISO dates for by-week graphs, because they have the nice property of "all weeks are seven days", so you don't get oddball weeks screwing up your plots. > If you want an easy way to graph day-by-day data and the exact day > numbers are irrelevant, what I'd recommend is: Convert the date into > Unix time, divide by 86400, floor it. That'll give you a Julian-style > date number where Jan 1st 1970 is 0, Jan 2nd is 1, etc, and at the end > of a year, it'll just keep on incrementing. That would get you past > the 2020/2021 boundary pretty smoothly. That works well. The previous suggestion using January 1st 2020 as an epoch start is also good. Elijah ------ also finds "week starts on Monday" to be oddball about ISO-8601 From rosuav at gmail.com Tue Jan 5 18:04:56 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 6 Jan 2021 10:04:56 +1100 Subject: dayofyear is not great when going into a new year In-Reply-To: References: Message-ID: On Wed, Jan 6, 2021 at 10:01 AM Eli the Bearded <*@eli.users.panix.com> wrote: > > In comp.lang.python, Chris Angelico wrote: > > There are multiple definitions for "day of year", depending on how you > > want to handle certain oddities. The simplest is to identify Jan 1st > > as 1, Jan 2nd as 2, etc, to Dec 31st as either 365 or 366; but some > > libraries will define the year as starting with the week that contains > > the Thursday, or something, and then will define days of year > > accordingly. > > That sounds like some weird off-shoot of the ISO-8601 calendar. That > document primarily concerns itself with weeks. Week 1 of a year is the > first week with a Thursday in it. The last week of a year will be either > 52 or 53, and you can have things like days in January belonging to the > week of the previous year. The "weird off-shoot" part is probably a result of me misremembering things, so don't read too much into the details :) I just remember coming across something that numbered days within a year in a way that was consistent with the way that it numbered weeks, which would indeed have been based on the ISO 8601 week numbering. Not 100% sure of the exact details. ChrisA From mats at wichmann.us Tue Jan 5 20:02:41 2021 From: mats at wichmann.us (Mats Wichmann) Date: Tue, 5 Jan 2021 18:02:41 -0700 Subject: dayofyear is not great when going into a new year In-Reply-To: References: Message-ID: On 1/5/21 4:04 PM, Chris Angelico wrote: > On Wed, Jan 6, 2021 at 10:01 AM Eli the Bearded <*@eli.users.panix.com> wrote: >> >> In comp.lang.python, Chris Angelico wrote: >>> There are multiple definitions for "day of year", depending on how you >>> want to handle certain oddities. The simplest is to identify Jan 1st >>> as 1, Jan 2nd as 2, etc, to Dec 31st as either 365 or 366; but some >>> libraries will define the year as starting with the week that contains >>> the Thursday, or something, and then will define days of year >>> accordingly. >> >> That sounds like some weird off-shoot of the ISO-8601 calendar. That >> document primarily concerns itself with weeks. Week 1 of a year is the >> first week with a Thursday in it. The last week of a year will be either >> 52 or 53, and you can have things like days in January belonging to the >> week of the previous year. > > The "weird off-shoot" part is probably a result of me misremembering > things, so don't read too much into the details :) I just remember > coming across something that numbered days within a year in a way that > was consistent with the way that it numbered weeks, which would indeed > have been based on the ISO 8601 week numbering. Not 100% sure of the > exact details. "workweeks" has always been fun, ISO standard or not, there's been a variation for ages since people don't seem to always follow ISO for that. I spent over a decade at a place that lived and died by their WorkWeek references ("due WW22" or the like would appear in every status report ever written, and there were zillions of those) - and it didn't agree with ISO on whether WW1 was the week that contained Jan 1 or whether it was the week that followed the previous year's last workweek. After all, those few days can't actually belong to two different workweeks, now can they? :) (that was not a good memory you guys brought back :) ) From * at eli.users.panix.com Tue Jan 5 20:38:09 2021 From: * at eli.users.panix.com (Eli the Bearded) Date: Wed, 6 Jan 2021 01:38:09 +0000 (UTC) Subject: dayofyear is not great when going into a new year References: Message-ID: In comp.lang.python, Mats Wichmann wrote: > "workweeks" has always been fun, ISO standard or not, there's been a > variation for ages since people don't seem to always follow ISO for > that. I spent over a decade at a place that lived and died by their > WorkWeek references ("due WW22" or the like would appear in every status > report ever written, and there were zillions of those) - and it didn't > agree with ISO on whether WW1 was the week that contained Jan 1 or > whether it was the week that followed the previous year's last workweek. > After all, those few days can't actually belong to two different > workweeks, now can they? :) I think the ISO standard was to try to unify a bunch of inconsistent locally defined things like that. In Gnu date(1), there are THREE different, and sometimes the same and sometimes not, week of year codes: %U week number of year, with Sunday as first day of week (00..53) %V ISO week number, with Monday as first day of week (01..53) %W week number of year, with Monday as first day of week (00..53) I don't think that is an exhaustive list of methods used, either. (excuse the vi command ugliness; % is special to : commands in vi) :r! date +"U: \%U; V: \%V; W: \%W" U: 01; V: 01; W: 01 Today they all match. But not always. :r! date --date="Jan 02 2005" +"U: \%U; V: \%V; W: \%W" U: 01; V: 53; W: 00 > (that was not a good memory you guys brought back :) ) Oh what a tangled web we weave, when we first begin to [measure time]. Elijah ------ they all disagree for Jan 02 2022, too, but slightly differently From Richard at Damon-Family.org Tue Jan 5 20:46:54 2021 From: Richard at Damon-Family.org (Richard Damon) Date: Tue, 5 Jan 2021 20:46:54 -0500 Subject: dayofyear is not great when going into a new year In-Reply-To: References: Message-ID: <53fd9bb2-bf98-12df-e0d8-e3b1a39b793f@Damon-Family.org> On 1/5/21 8:02 PM, Mats Wichmann wrote: > On 1/5/21 4:04 PM, Chris Angelico wrote: >> On Wed, Jan 6, 2021 at 10:01 AM Eli the Bearded >> <*@eli.users.panix.com> wrote: >>> >>> In comp.lang.python, Chris Angelico? wrote: >>>> There are multiple definitions for "day of year", depending on how you >>>> want to handle certain oddities. The simplest is to identify Jan 1st >>>> as 1, Jan 2nd as 2, etc, to Dec 31st as either 365 or 366; but some >>>> libraries will define the year as starting with the week that contains >>>> the Thursday, or something, and then will define days of year >>>> accordingly. >>> >>> That sounds like some weird off-shoot of the ISO-8601 calendar. That >>> document primarily concerns itself with weeks. Week 1 of a year is the >>> first week with a Thursday in it. The last week of a year will be >>> either >>> 52 or 53, and you can have things like days in January belonging to the >>> week of the previous year. >> >> The "weird off-shoot" part is probably a result of me misremembering >> things, so don't read too much into the details :) I just remember >> coming across something that numbered days within a year in a way that >> was consistent with the way that it numbered weeks, which would indeed >> have been based on the ISO 8601 week numbering. Not 100% sure of the >> exact details. > > "workweeks" has always been fun, ISO standard or not, there's been a > variation for ages since people don't seem to always follow ISO for > that.? I spent over a decade at a place that lived and died by their > WorkWeek references ("due WW22" or the like would appear in every > status report ever written, and there were zillions of those) - and it > didn't agree with ISO on whether WW1 was the week that contained Jan 1 > or whether it was the week that followed the previous year's last > workweek. After all, those few days can't actually belong to two > different workweeks, now can they?? :) > > (that was not a good memory you guys brought back :) ) I'm reminded of a video made describing 'ISO Weeks' that was put out on Dec 30, 2019, which was the first day of the ISO week bsed 2020, and he ended it with a comment that if 2019 wasn't going so well, you could always just use ISO to get an early start on 2020. Apparently a lot of people were getting this recommended a number of months later, and people were commenting how that line just was not aging well. And we couldn't use that te get out of 2020, as 2020 is a long year, and ISO 2021 didn't start until Jan 4th. -- Richard Damon From jmfmoraes at yahoo.com Wed Jan 6 06:50:49 2021 From: jmfmoraes at yahoo.com (Joseph Milroy Felix Moraes (Moraes)) Date: Wed, 6 Jan 2021 11:50:49 +0000 (UTC) Subject: Python 3.8.5 References: <1653769609.7728239.1609933849407.ref@mail.yahoo.com> Message-ID: <1653769609.7728239.1609933849407@mail.yahoo.com> Good day, I keep getting this error message when trying to open Python 3.8.5 on my computer windows 7 , 64 bit. --------------------------- python.exe - System Error --------------------------- The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem. --------------------------- OK? --------------------------- kindly assist Regards, Milroy From grant.b.edwards at gmail.com Wed Jan 6 09:49:28 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 6 Jan 2021 14:49:28 -0000 (UTC) Subject: Python 3.8.5 References: <1653769609.7728239.1609933849407.ref@mail.yahoo.com> <1653769609.7728239.1609933849407@mail.yahoo.com> Message-ID: On 2021-01-06, Joseph Milroy Felix Moraes (Moraes) via Python-list wrote: > Good day, > > I keep getting this error message when trying to open Python 3.8.5 on my computer windows 7 , 64 bit. > > --------------------------- > python.exe - System Error > --------------------------- > The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem. > --------------------------- > OK? > --------------------------- > > kindly assist https://www.google.com/search?q=api-ms-win-crt-runtime-l1-1-0.dll+is+missing From rshepard at appl-ecosys.com Wed Jan 6 13:32:58 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 6 Jan 2021 10:32:58 -0800 (PST) Subject: Tkinter menu item underline syntax Message-ID: My application's menu has lines like this: file_menu.add_command( label = 'New', command = self.callbacks['file->new', underline 0], accelerator = 'Ctrl+N' ) Python reports a syntax error when specifying the string index to underline; it rejects both a space and an equals sign (=). In "Modern Tkinter", page 88, the author explains, "Underline "While all platforms support keyboard traversal of the menubar via the arrow keys, on Windows and X11, you can also use other keys to jump to particular menus or menu items. The keys that trigger these jumps are indicated by an underlined letter in the menu item?s label. If you want to add one of these to a menu item, you can use the "underline" configuration option for the item. The value of this option should be the index of the character you?d like underlined (from 0 to the length of the string - 1)." There is no example of the proper syntax and my web searches haven't found one, either. How do I pass a string index to the command to underline that character? TIA, Rich From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Jan 6 14:08:55 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Wed, 6 Jan 2021 13:08:55 -0600 Subject: Tkinter menu item underline syntax In-Reply-To: References: Message-ID: On 2021-01-06 at 10:32:58 -0800, Rich Shepard wrote: > My application's menu has lines like this: > file_menu.add_command( > label = 'New', > command = self.callbacks['file->new', underline 0], > accelerator = 'Ctrl+N' > ) > > Python reports a syntax error when specifying the string index to underline; > it rejects both a space and an equals sign (=). I'm not a TKinter expert (nor even a current user), but that line that begins with whitespace and "command =" looks suspicious. As far as I can see, Python is correct to call it syntactically erroneous. What is self.callbacks? Is it a function, a list of functions, a list of something else? Did you possibly mean to use parentheses "(" and ")" instead of brackets "[" and "]"? Or perhaps some different punctuation between the "[" and the "]"? >From what I remember about TKinter, embedding Tcl/TK code inside strings inside Python can be tricky (to say the least). Sorry I don't have a concrete solution, just more to think about. From rshepard at appl-ecosys.com Wed Jan 6 14:18:15 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 6 Jan 2021 11:18:15 -0800 (PST) Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On Wed, 6 Jan 2021, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > I'm not a TKinter expert (nor even a current user), but that line that > begins with whitespace and "command =" looks suspicious. As far as I can > see, Python is correct to call it syntactically erroneous. Yes, the line above it needed to be terminated by a comma, not \n. I found the answer: underline is an option and options are key: value pairs. So, the correct syntax is underline: 0. Thanks, Rich From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Jan 6 15:03:50 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Wed, 6 Jan 2021 14:03:50 -0600 Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On 2021-01-06 at 11:18:15 -0800, Rich Shepard wrote: > On Wed, 6 Jan 2021, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > > > I'm not a TKinter expert (nor even a current user), but that line that > > begins with whitespace and "command =" looks suspicious. As far as I can > > see, Python is correct to call it syntactically erroneous. > > Yes, the line above it needed to be terminated by a comma, not \n. > > I found the answer: underline is an option and options are key: value pairs. > So, the correct syntax is underline: 0. Glad you found it. :-) For the sake of future generations who may run into this issue, can you post the complete, correct call to file_menu.add_command? From tjreedy at udel.edu Wed Jan 6 15:21:06 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Jan 2021 15:21:06 -0500 Subject: Tkinter menu item underline syntax In-Reply-To: References: Message-ID: On 1/6/2021 1:32 PM, Rich Shepard wrote: > My application's menu has lines like this: > ??????? file_menu.add_command( > ??????????? label = 'New', > ??????????? command = self.callbacks['file->new', underline 0], > ??????????? accelerator = 'Ctrl+N' > ??????? ) 'underline' has nothing to do with looking up the command in self.callbacks. It is a keyword parameter for the add_command method, and is handled like all other values passed by name, and as you did for the other arguments file_menu.add_command( label='New', underline=0, command=self.callbacks['file->new], accelerator='Ctrl+N' ) Note: PEP 8 style is no spaces around '=' used for keyword arguments. Here is an example from idlelib.editor, 978. menu.add_command(label=ulchars[i] + " " + file_name, command=callback, underline=0) -- Terry Jan Reedy From rshepard at appl-ecosys.com Wed Jan 6 15:42:36 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 6 Jan 2021 12:42:36 -0800 (PST) Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On Wed, 6 Jan 2021, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > For the sake of future generations who may run into this issue, can you > post the complete, correct call to file_menu.add_command? This is the working version of the stanza I initially posted: file_menu.add_command( label = 'New', command = self.callbacks['file->new', underline: 0], accelerator = 'Ctrl+N' ) The label line separated from the command with a comma. The underline option is a key and separated from its value with a colon. HTH, Rich From rosuav at gmail.com Wed Jan 6 15:51:57 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jan 2021 07:51:57 +1100 Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On Thu, Jan 7, 2021 at 7:43 AM Rich Shepard wrote: > This is the working version of the stanza I initially posted: > > file_menu.add_command( > label = 'New', > command = self.callbacks['file->new', underline: 0], > accelerator = 'Ctrl+N' > ) > > The label line separated from the command with a comma. The underline option > is a key and separated from its value with a colon. > Are you sure that this works? It's syntactically valid, but I don't think it means what you think it does. ChrisA From rshepard at appl-ecosys.com Wed Jan 6 16:03:02 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 6 Jan 2021 13:03:02 -0800 (PST) Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On Thu, 7 Jan 2021, Chris Angelico wrote: > Are you sure that this works? It's syntactically valid, but I don't > think it means what you think it does. ChrisA, I'm always open to learning. There's no error generated ... yet the application doesn' open so it's time to run it through pdb. Regards, Rich From rosuav at gmail.com Wed Jan 6 16:29:34 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jan 2021 08:29:34 +1100 Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On Thu, Jan 7, 2021 at 8:04 AM Rich Shepard wrote: > > On Thu, 7 Jan 2021, Chris Angelico wrote: > > > Are you sure that this works? It's syntactically valid, but I don't > > think it means what you think it does. > > ChrisA, > > I'm always open to learning. There's no error generated ... yet the > application doesn' open so it's time to run it through pdb. > Cool. Terry had something on the subject in the other thread; I think that's a good place to start. (I don't know much about Tkinter, this line of code just looked odd in general Python syntax.) ChrisA From rshepard at appl-ecosys.com Wed Jan 6 17:09:44 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 6 Jan 2021 14:09:44 -0800 (PST) Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On Thu, 7 Jan 2021, Chris Angelico wrote: > Cool. Terry had something on the subject in the other thread; I think > that's a good place to start. (I don't know much about Tkinter, this line > of code just looked odd in general Python syntax.) ChrisA, It's been a long time since I wrote any Python code. Assignments have spaces surrounding equal signs while values to options don't. I think I have the code cleaned now. Regards, Rich From grant.b.edwards at gmail.com Wed Jan 6 16:03:58 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 6 Jan 2021 21:03:58 -0000 (UTC) Subject: Tkinter menu item underline syntax [RESOLVED] References: Message-ID: On 2021-01-06, Rich Shepard wrote: > On Wed, 6 Jan 2021, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > >> For the sake of future generations who may run into this issue, can you >> post the complete, correct call to file_menu.add_command? > > This is the working version of the stanza I initially posted: > > file_menu.add_command( > label = 'New', > command = self.callbacks['file->new', underline: 0], > accelerator = 'Ctrl+N' > ) I'm completely baffled by that. Can somebody explain how this expression is evaluated? self.callbacks['file->new', underline: 0] It appears that the dict callbacks is being accessed with the key of a tuple comprising a string and a slice. Huh? From tjreedy at udel.edu Wed Jan 6 16:17:55 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Jan 2021 16:17:55 -0500 Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On 1/6/2021 4:03 PM, Rich Shepard wrote: > On Thu, 7 Jan 2021, Chris Angelico wrote: > >> Are you sure that this works? It's syntactically valid, but I don't >> think it means what you think it does. > > ChrisA, > > I'm always open to learning. There's no error generated ... yet the > application doesn' open so it's time to run it through pdb. See my response, sent an hour ago, for how to use 'underline. -- Terry Jan Reedy From rosuav at gmail.com Wed Jan 6 17:27:49 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jan 2021 09:27:49 +1100 Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On Thu, Jan 7, 2021 at 9:22 AM Grant Edwards wrote: > > On 2021-01-06, Rich Shepard wrote: > > On Wed, 6 Jan 2021, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > > > >> For the sake of future generations who may run into this issue, can you > >> post the complete, correct call to file_menu.add_command? > > > > This is the working version of the stanza I initially posted: > > > > file_menu.add_command( > > label = 'New', > > command = self.callbacks['file->new', underline: 0], > > accelerator = 'Ctrl+N' > > ) > > I'm completely baffled by that. Can somebody explain how this > expression is evaluated? > > self.callbacks['file->new', underline: 0] > > It appears that the dict callbacks is being accessed with the key of > a tuple comprising a string and a slice. > Heh, you had to try it to make sure it was valid? Me too. Here's how it's parsed: self.callbacks[ # this bit's non-controversial 'file->new' # string literal , # make tuple underline: 0 # slice(underline, 0, None) ] So it takes the name "underline", whatever that is, and it assumes you want a slice from underline to zero. That's all the second dimension of the indexing, where the first is a simple string literal. ChrisA From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Thu Jan 7 02:29:46 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Thu, 7 Jan 2021 07:29:46 +0000 Subject: Class and tkinter problem Message-ID: Hi! Does anybody know why cmd method isn't called when I change the button state (clicking on it) in this example? I know that this seems a weird class use. But why doesn't it work? Thanks. class C: from tkinter import Checkbutton import tkinter @staticmethod def cmd(): print("Test") top=tkinter.Tk() cb=Checkbutton(command=cmd) cb.pack() @staticmethod def loop(): C.top.mainloop() c=C() c.loop() From auriocus at gmx.de Thu Jan 7 02:42:34 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 7 Jan 2021 08:42:34 +0100 Subject: Class and tkinter problem In-Reply-To: References: Message-ID: Am 07.01.21 um 08:29 schrieb Paulo da Silva: > Does anybody know why cmd method isn't called when I change the button > state (clicking on it) in this example? > I know that this seems a weird class use. But why doesn't it work? > Thanks. > > class C: > from tkinter import Checkbutton > import tkinter > > @staticmethod ^^it works if you remove the staticmethod here > def cmd(): > print("Test") > Maybe there is a bug in tkinter, that it doesn't work with static methods? Christian From Bischoop at vimart.net Thu Jan 7 04:44:13 2021 From: Bischoop at vimart.net (Bischoop) Date: Thu, 7 Jan 2021 09:44:13 -0000 (UTC) Subject: primitive password cracker Message-ID: I was practising for educational purpose with simply password cracker. I know that I could use itertool but in my case when I'm learning I would miss facing problems and learning on them and indeed I've met one which is not giving me a peace. What I want to learn is if I need get for example four combinations, so how to get in a loop first letter 'a',then another step'a' and again 'a' and 'a', to have 'aaaa' later on'abaa' etc. So I wrote that: ------------------------------------------ import string passe = 'zulu' mylist = [] #letters = string.ascii_lowercase letters = ['a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'w', 'q', 'y', 'z'] mineset= set() for a in letters: for b in letters: for c in letters: for d in letters: s = a + b + c + b mylist.append(s) mineset=set(mylist) k = sorted(mineset) print(k) for i in k: if i == passe: print('got it: ', i ) print(passe in k) -------------------------------------- It works in someway but the problems are: Not all combination are made, I change password to: 'pass' and that combination is not in results. Another thing is, I had to made a set from list because combinations were repeated. And finally, I was struglling with making it in without creating four loops for four letters, something like that: To try to solve those I went with that approach: ------------- letters = ['a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'w', 'q', 'y', 'z'] password = 'pass' combin = '' lista=[] for x in range(4): for y in letters: combin +=y lista.append(combin) combin='' mineset=set(lista) print(mineset) for i in lista: if i == password: print('pass:', i) ------------------- But the results are disspainting: {'abc', 'a', 'ab', 'abcd', 'abcde'} I was seating on it for a long day but can't even closely achieve similar effect to 4 loops in previous code. -- Thanks From __peter__ at web.de Thu Jan 7 05:26:56 2021 From: __peter__ at web.de (Peter Otten) Date: Thu, 7 Jan 2021 11:26:56 +0100 Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On 06/01/2021 22:03, Rich Shepard wrote: > On Thu, 7 Jan 2021, Chris Angelico wrote: > >> Are you sure that this works? It's syntactically valid, but I don't >> think it means what you think it does. > > ChrisA, > > I'm always open to learning. There's no error generated ... yet the > application doesn' open so it's time to run it through pdb. Spoiler: unless the name 'underline' is defined you get a NameError: NameError: name 'underline' is not defined If it is defined and self.callbacks is a dict you get a TypeError: TypeError: unhashable type: 'slice' because that's what a colon means in a context like x[a:b] From what you posted I would guess that underline is most likely a keyword argument to the add_command() method: file_menu.add_command( label='New', command=self.callbacks['file->new'], underline=0, accelerator='Ctrl+N' ) From __peter__ at web.de Thu Jan 7 05:36:51 2021 From: __peter__ at web.de (Peter Otten) Date: Thu, 7 Jan 2021 11:36:51 +0100 Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On 06/01/2021 22:03, Grant Edwards wrote: > I'm completely baffled by that. Can somebody explain how this > expression is evaluated? > > self.callbacks['file->new', underline: 0] > > It appears that the dict callbacks is being accessed with the key of > a tuple comprising a string and a slice. > > Huh? You're completely right: >>> class C: def __getitem__(self, index): return index >>> c = C() >>> underline = 42 >>> c["foo", underline: 0] ('foo', slice(42, 0, None)) The OP's code will most certainly fail at runtime ;) From rosuav at gmail.com Thu Jan 7 06:56:58 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 7 Jan 2021 22:56:58 +1100 Subject: primitive password cracker In-Reply-To: References: Message-ID: On Thu, Jan 7, 2021 at 8:46 PM Bischoop wrote: > What I want to learn is if I need get for example four combinations, so > how to get in a loop first letter 'a',then another step'a' and again 'a' > and 'a', to have 'aaaa' later on'abaa' etc. So you want every possible four-letter combination? > So I wrote that: > ------------------------------------------ > import string > passe = 'zulu' > mylist = [] > #letters = string.ascii_lowercase > letters = ['a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'w', 'q', 'y', 'z'] I'd recommend having just a string, rather than a list; it'll behave identically for what you're doing, and it'll be a lot easier to see when you have all the right letters. I'd also recommend having the letters in some well-known order, such as lexicographic (aka "alphabetical order"), or running straight across the rows of your keyboard. Keyboards aren't all the same, but at least you'll know that your own keyboard is consistent. > mineset= set() > for a in letters: > for b in letters: > for c in letters: > for d in letters: > s = a + b + c + b Why is b at the end? :) That's why "zulu" could be found, but "pass" couldn't. > k = sorted(mineset) > print(k) > for i in k: > if i == passe: > print('got it: ', i ) > print(passe in k) > -------------------------------------- > It works in someway but the problems are: > Not all combination are made, I change password to: 'pass' and that combination is not in results. > Another thing is, I had to made a set from list because combinations > were repeated. Yep. I'd recommend looking at the original list rather than setting and sorting, and you might notice patterns that hint at problems. > for x in range(4): > for y in letters: > combin +=y > lista.append(combin) > combin='' Not entirely sure what your intended logic is here, but I'd advise planning things out in pseudocode and knowing what you're actually building. Debugging code can be very hard, especially if you don't know what it's doing. Fortunately, Python comes with a number of tools to help you figure out your code; the simplest is the print function - just add a few useful print calls to your code and trace through things that way. You can also look at the pdb module, and various other techniques. Explore your code, get to know how it works at each point, and you should be able to figure things out. Good luck, have fun! And remember IIDPIO: If In Doubt, Print It Out! ChrisA From mal at europython.eu Thu Jan 7 06:51:36 2021 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 7 Jan 2021 12:51:36 +0100 Subject: EuroPython 2021: Format Poll Message-ID: <91973040-dce1-3434-ddc0-3bc20d057935@europython.eu> We are currently working out the format for this year?s online EuroPython conference. The conference will be run using online conference tools during the week of July 26 - August 1 and we would like to learn about your preferences regarding the overall structure. For this reason, we?re running a poll to gather input from our (potential) attendees: * EuroPython 2021 Format Poll * https://forms.gle/V4oPEXWiexfVyH1S7 Please add any comments you may have to the comment field. We?d love to hear about new online conference platforms you may have seen (last year, we used Zoom and Discord), suggestions on social event formats, etc. Help spread the word -------------------- Please help us spread this message by sharing it on your social networks as widely as possible. Thank you ! Link to the blog post: https://blog.europython.eu/post/639651925251571712/europython-2021-format-poll Tweet: https://twitter.com/europython/status/1347146647403450370 Thanks, -- EuroPython 2021 Team https://www.europython-society.org/ From rshepard at appl-ecosys.com Thu Jan 7 08:32:37 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 7 Jan 2021 05:32:37 -0800 (PST) Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On Thu, 7 Jan 2021, Peter Otten wrote: > Spoiler: unless the name 'underline' is defined you get a NameError: > NameError: name 'underline' is not defined > If it is defined and self.callbacks is a dict you get a TypeError: > TypeError: unhashable type: 'slice' > because that's what a colon means in a context like > x[a:b] The template I used for the menu doesn't scale to my application so I'm re-writing it from scratch. Thanks, all, Rich From Bischoop at vimart.net Thu Jan 7 09:05:51 2021 From: Bischoop at vimart.net (Bischoop) Date: Thu, 7 Jan 2021 14:05:51 -0000 (UTC) Subject: primitive password cracker References: Message-ID: On 2021-01-07, Chris Angelico wrote: > > I'd recommend having just a string, rather than a list; it'll behave > identically for what you're doing, and it'll be a lot easier to see > when you have all the right letters. > Yes that's definitely better, I've done so. >> mineset= set() >> for a in letters: >> for b in letters: >> for c in letters: >> for d in letters: >> s = a + b + c + b > > Why is b at the end? :) That's why "zulu" could be found, but "pass" couldn't. > ha, that's typo I was working so long on it that got mixed up. and yes with 'd' it works :-) >> k = sorted(mineset) >> print(k) >> for i in k: >> if i == passe: >> print('got it: ', i ) >> print(passe in k) >> -------------------------------------- >> It works in someway but the problems are: >> Not all combination are made, I change password to: 'pass' and that combination is not in results. >> Another thing is, I had to made a set from list because combinations >> were repeated. > > Yep. I'd recommend looking at the original list rather than setting > and sorting, and you might notice patterns that hint at problems. > The problem was with that 'b' at the end, now it solved. >> for x in range(4): >> for y in letters: >> combin +=y >> lista.append(combin) >> combin='' > > Not entirely sure what your intended logic is here, but I'd advise > planning things out in pseudocode and knowing what you're actually > building. > Well :-) I tried to do shorter version of the previous code to do not do for loop for every character, range supposed to be for how long the password is, in this case four characters, once the 4character combination is made add it to the list, similarly to the previous code but.... my logic is wrong here. I don't have clue hot to tell: get a letter for 1 get for 2 get for 3 and get for 4. > Debugging code can be very hard, especially if you don't know what > it's doing. Fortunately, Python comes with a number of tools to help > you figure out your code; the simplest is the print function - just > add a few useful print calls to your code and trace through things > that way. You can also look at the pdb module, and various other > techniques. Explore your code, get to know how it works at each point, > and you should be able to figure things out. > > Good luck, have fun! And remember IIDPIO: If In Doubt, Print It Out! > For me is even not debbuging code is important but to do what I want and in that case is that what I mention earlier four letters picked and add them to the list, and today again I seat on it and just nothing lol. -- Thanks From tjreedy at udel.edu Wed Jan 6 20:44:45 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 6 Jan 2021 20:44:45 -0500 Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On 1/6/2021 4:17 PM, Terry Reedy wrote: > On 1/6/2021 4:03 PM, Rich Shepard wrote: >> On Thu, 7 Jan 2021, Chris Angelico wrote: >> >>> Are you sure that this works? It's syntactically valid, but I don't >>> think it means what you think it does. >> >> ChrisA, >> >> I'm always open to learning. There's no error generated ... yet the >> application doesn' open so it's time to run it through pdb. > > See my response, sent an hour ago, for how to use 'underline. Reposting: 'underline' has nothing to do with looking up the command in self.callbacks. It is a keyword parameter for the add_command method, and is handled like all other values passed by name, and as you did for the other arguments file_menu.add_command( label='New', underline=0, command=self.callbacks['file->new], accelerator='Ctrl+N' ) Note: PEP 8 style is no spaces around '=' used for keyword arguments. Here is an example from idlelib.editor, 978. menu.add_command(label=ulchars[i] + " " + file_name, command=callback, underline=0) -- Terry Jan Reedy From tjreedy at udel.edu Thu Jan 7 04:20:53 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 7 Jan 2021 04:20:53 -0500 Subject: Class and tkinter problem In-Reply-To: References: Message-ID: On 1/7/2021 2:42 AM, Christian Gollwitzer wrote: > Am 07.01.21 um 08:29 schrieb Paulo da Silva: > >> Does anybody know why cmd method isn't called when I change the button >> state (clicking on it) in this example? >> I know that this seems a weird class use. But why doesn't it work? >> Thanks. >> >> class C: >> ???? from tkinter import Checkbutton >> ???? import tkinter >> >> ???? @staticmethod > ^^it works if you remove the staticmethod here staticmethods are essentially useless in Python. What little was gained by their addition is partly offset by the introduced confusion. I am not sure is removing @staticmethod would have been sufficient in 2.x. >> ???? def cmd(): >> ???????? print("Test") >> top=tkinter.Tk() cb=Checkbutton(command=cmd) cb.pack() Button commands have to be tcl functions. Tkinter wraps Python functions as tcl function. Static methods also wrap python functions, as a .__func__ attribute. So the code if one passes cmd.__func__. > Maybe there is a bug in tkinter, that it doesn't work with static methods? One could propose that tkinter test whether callables are staticmethods and unwrap them when they are. Classmethods also do not work as is. By experiment, the following works. cb=Checkbutton(command=lambda: C.cmd.__func__(C)) But if the class were nested, it would be more complicated. -- Terry Jan Reedy From dario962004toywind at gmail.com Thu Jan 7 04:44:00 2021 From: dario962004toywind at gmail.com (Dario Dario) Date: Thu, 7 Jan 2021 15:14:00 +0530 Subject: Some problem in code execution in python Message-ID: Sir, I am one of the user of your python program, that is after completion of installation I got some statement like "you got code execution problem ". I don't know how to rectify this problem.so please help me to rectify this problem . You send me the solution in this email ID itself . From Bischoop at vimart.net Thu Jan 7 09:09:04 2021 From: Bischoop at vimart.net (Bischoop) Date: Thu, 7 Jan 2021 14:09:04 -0000 (UTC) Subject: primitive password cracker References: Message-ID: On 2021-01-07, Chris Angelico wrote: This could allow easy to change the number of characters in combination, just pass n argument to range where n is how many characters. From David.Raymond at tomtom.com Thu Jan 7 10:18:15 2021 From: David.Raymond at tomtom.com (David Raymond) Date: Thu, 7 Jan 2021 15:18:15 +0000 Subject: primitive password cracker In-Reply-To: References: Message-ID: I think you might want to check out itertools.product() https://docs.python.org/3.9/library/itertools.html#itertools.product import itertools import string passe = 'pass' for p in itertools.product(string.ascii_lowercase, repeat = 4): p = "".join(p) if p == passe: print("Found it:", p) break else: print("Didn't find it.") Or for different lengths: foundIt = False for repeat in range(1, 6): for p in itertools.product(string.ascii_lowercase, repeat = repeat): p = "".join(p) if p == passe: print("Found it:", p) foundIt = True break if foundIt: break else: print("Didn't find it.") From rosuav at gmail.com Thu Jan 7 10:25:30 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jan 2021 02:25:30 +1100 Subject: primitive password cracker In-Reply-To: References: Message-ID: On Fri, Jan 8, 2021 at 2:12 AM Bischoop wrote: > > On 2021-01-07, Chris Angelico wrote: > > This could allow easy to change the number of characters in > combination, just pass n argument to range where n is how many characters. > True. Unfortunately, it doesn't work, so what you'd have is something that can be easily parameterized to not work on other numbers of characters too. :) ChrisA From rshepard at appl-ecosys.com Thu Jan 7 10:56:07 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Thu, 7 Jan 2021 07:56:07 -0800 (PST) Subject: Tkinter menu item underline syntax [RESOLVED] In-Reply-To: References: Message-ID: On Wed, 6 Jan 2021, Terry Reedy wrote: > 'underline' has nothing to do with looking up the command in > self.callbacks. It is a keyword parameter for the add_command method, and > is handled like all other values passed by name, and as you did for the > other arguments > > file_menu.add_command( > label='New', > underline=0, > command=self.callbacks['file->new], > accelerator='Ctrl+N' > ) > > Note: PEP 8 style is no spaces around '=' used for keyword arguments. Here > is an example from idlelib.editor, 978. > > menu.add_command(label=ulchars[i] + " " + file_name, > command=callback, > underline=0) Thank you for the clarification. Rich From __peter__ at web.de Thu Jan 7 11:02:21 2021 From: __peter__ at web.de (Peter Otten) Date: Thu, 7 Jan 2021 17:02:21 +0100 Subject: Class and tkinter problem In-Reply-To: References: Message-ID: <3325a90f-58c5-3ad8-277b-8aeb7a7c3f34@web.de> On 07/01/2021 08:42, Christian Gollwitzer wrote: > Am 07.01.21 um 08:29 schrieb Paulo da Silva: > >> Does anybody know why cmd method isn't called when I change the button >> state (clicking on it) in this example? >> I know that this seems a weird class use. But why doesn't it work? >> Thanks. >> >> class C: >> ???? from tkinter import Checkbutton >> ???? import tkinter >> >> ???? @staticmethod > ^^it works if you remove the staticmethod here > >> ???? def cmd(): >> ???????? print("Test") >> > > Maybe there is a bug in tkinter, that it doesn't work with static methods? It has nothing to do with tkinter, a staticmethod object cannot be called directly: >>> class C: @staticmethod def cmd(): print("Hello") cmd() Traceback (most recent call last): File "", line 1, in class C: File "", line 4, in C cmd() TypeError: 'staticmethod' object is not callable You have to go through the descriptor protocol: >>> class C: @staticmethod def cmd(): print("Hello") >>> C.cmd() Hello I recommend that the OP use a more conventional stye and do the setup outside the class or, better, in an instance of the class. From __peter__ at web.de Thu Jan 7 11:02:21 2021 From: __peter__ at web.de (Peter Otten) Date: Thu, 7 Jan 2021 17:02:21 +0100 Subject: Class and tkinter problem In-Reply-To: References: Message-ID: <3325a90f-58c5-3ad8-277b-8aeb7a7c3f34@web.de> On 07/01/2021 08:42, Christian Gollwitzer wrote: > Am 07.01.21 um 08:29 schrieb Paulo da Silva: > >> Does anybody know why cmd method isn't called when I change the button >> state (clicking on it) in this example? >> I know that this seems a weird class use. But why doesn't it work? >> Thanks. >> >> class C: >> ???? from tkinter import Checkbutton >> ???? import tkinter >> >> ???? @staticmethod > ^^it works if you remove the staticmethod here > >> ???? def cmd(): >> ???????? print("Test") >> > > Maybe there is a bug in tkinter, that it doesn't work with static methods? It has nothing to do with tkinter, a staticmethod object cannot be called directly: >>> class C: @staticmethod def cmd(): print("Hello") cmd() Traceback (most recent call last): File "", line 1, in class C: File "", line 4, in C cmd() TypeError: 'staticmethod' object is not callable You have to go through the descriptor protocol: >>> class C: @staticmethod def cmd(): print("Hello") >>> C.cmd() Hello I recommend that the OP use a more conventional stye and do the setup outside the class or, better, in an instance of the class. From DomainAdmin at DancesWithMice.info Thu Jan 7 11:57:20 2021 From: DomainAdmin at DancesWithMice.info (David L Neil) Date: Fri, 8 Jan 2021 05:57:20 +1300 Subject: Some problem in code execution in python In-Reply-To: References: Message-ID: On 07/01/2021 22.44, Dario Dario wrote: > Sir, I am one of the user of your python program, that is after completion > of installation I got some statement like "you got code execution problem > ". I don't know how to rectify this problem.so please help me to rectify > this problem . > You send me the solution in this email ID itself . Welcome to the list, where Python users help each other. Please send more information: - which Operating System - which version of Python - from where Python was downloaded - copy-paste all of the error messages -- Regards =dn From Bischoop at vimart.net Thu Jan 7 11:55:37 2021 From: Bischoop at vimart.net (Bischoop) Date: Thu, 7 Jan 2021 16:55:37 -0000 (UTC) Subject: Some problem in code execution in python References: Message-ID: On 2021-01-07, Dario Dario wrote: > Sir, I am one of the user of your python program, that is after completion > of installation I got some statement like "you got code execution problem > ". I don't know how to rectify this problem.so please help me to rectify > this problem . > You send me the solution in this email ID itself . I'm not Window OS user but doesn't running program in Windows Command Shell tells also what's wrong? From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Thu Jan 7 12:18:49 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Thu, 7 Jan 2021 17:18:49 +0000 Subject: Class and tkinter problem References: Message-ID: ?s 07:42 de 07/01/21, Christian Gollwitzer escreveu: > Am 07.01.21 um 08:29 schrieb Paulo da Silva: > >> Does anybody know why cmd method isn't called when I change the button >> state (clicking on it) in this example? >> I know that this seems a weird class use. But why doesn't it work? >> Thanks. >> >> class C: >> ???? from tkinter import Checkbutton >> ???? import tkinter >> >> ???? @staticmethod > ^^it works if you remove the staticmethod here Yes, that's the coventional way. Thanks From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Thu Jan 7 12:28:20 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Thu, 7 Jan 2021 17:28:20 +0000 Subject: Class and tkinter problem References: Message-ID: ?s 09:20 de 07/01/21, Terry Reedy escreveu: > On 1/7/2021 2:42 AM, Christian Gollwitzer wrote: >> Am 07.01.21 um 08:29 schrieb Paulo da Silva: >> >>> Does anybody know why cmd method isn't called when I change the button >>> state (clicking on it) in this example? >>> I know that this seems a weird class use. But why doesn't it work? >>> Thanks. >>> >>> class C: >>> ???? from tkinter import Checkbutton >>> ???? import tkinter >>> >>> ???? @staticmethod >> ^^it works if you remove the staticmethod here > > staticmethods are essentially useless in Python.? What little was gained > by their addition is partly offset by the introduced confusion. It depends on what the classes are being used for. Sometimes I just want to use them as static wrappers. Of course I could use them in the conventional way for this purpose, but it's not so clean :-) ... > > Classmethods also do not work as is.? By experiment, the following works. > ??? cb=Checkbutton(command=lambda: C.cmd.__func__(C)) Why not just cb=Checkbutton(command=lambda : C.cmd()) ? Also works. BTW, just for curiosity, and for my personal learning ... What does "__func__" does? Thank you. From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Thu Jan 7 12:31:11 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Thu, 7 Jan 2021 17:31:11 +0000 Subject: Class and tkinter problem References: <3325a90f-58c5-3ad8-277b-8aeb7a7c3f34@web.de> Message-ID: ?s 16:02 de 07/01/21, Peter Otten escreveu: > On 07/01/2021 08:42, Christian Gollwitzer wrote: >> Am 07.01.21 um 08:29 schrieb Paulo da Silva: >> ... > > I recommend that the OP use a more conventional stye and do the setup > outside the class or, better, in an instance of the class. > There are lots of possible more conventional ways, of course. My purpose was only to understand what was wrong. Thanks anyway. From Bischoop at vimart.net Thu Jan 7 11:45:08 2021 From: Bischoop at vimart.net (Bischoop) Date: Thu, 7 Jan 2021 16:45:08 -0000 (UTC) Subject: primitive password cracker References: Message-ID: On 2021-01-07, David Raymond wrote: > I think you might want to check out itertools.product() > https://docs.python.org/3.9/library/itertools.html#itertools.product Thanks David for contribution I find it very convenient but not knowing how to solve solution without itertools for: for a i xxxx: for b in xxxx: for c in xxxx: for d in xxxx: doesn't give me a peace. -- Thanks From Bischoop at vimart.net Thu Jan 7 11:52:56 2021 From: Bischoop at vimart.net (Bischoop) Date: Thu, 7 Jan 2021 16:52:56 -0000 (UTC) Subject: primitive password cracker References: Message-ID: On 2021-01-07, Chris Angelico wrote: > > True. Unfortunately, it doesn't work, so what you'd have is something > that can be easily parameterized to not work on other numbers of > characters too. :) > My bad is I'm kinda maniac and have to know how to, I know best solution itertool but... I just must know, was thinking that studing the itertool code would give me an answer but found it's in C. Now I try list comprehension for it, so it's another day on it for me. -- Thanks From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Thu Jan 7 12:38:04 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Thu, 7 Jan 2021 17:38:04 +0000 Subject: Class and tkinter problem References: Message-ID: ?s 07:29 de 07/01/21, Paulo da Silva escreveu: > Hi! > > Does anybody know why cmd method isn't called when I change the button > state (clicking on it) in this example? > I know that this seems a weird class use. But why doesn't it work? > Thanks. > > class C: > from tkinter import Checkbutton > import tkinter > > @staticmethod > def cmd(): > print("Test") > > top=tkinter.Tk() > cb=Checkbutton(command=cmd) > cb.pack() > > @staticmethod > def loop(): > C.top.mainloop() > > c=C() > c.loop() > After some experiments I found two solutions: 1) class C: @staticmethod def cmd(): print("Test") class C: #@DuplicatedSignature from tkinter import Checkbutton import tkinter top=tkinter.Tk() cb=Checkbutton(command=C.cmd) cb.pack() @staticmethod def loop(): C.top.mainloop() c=C() c.loop() 2) class C: from tkinter import Checkbutton import tkinter @staticmethod def cmd(): print("Test") top=tkinter.Tk() cb=Checkbutton(command=lambda : C.cmd()) cb.pack() @staticmethod def loop(): C.top.mainloop() c=C() c.loop() This one as a sequence of the answer of Terry - thanks. BTW, does anyone know I can I get the arguments eventually passed by the Checkbutton event, or any other widget callback (*pargs, **kargs) using this "solution"? From Bischoop at vimart.net Thu Jan 7 12:39:36 2021 From: Bischoop at vimart.net (Bischoop) Date: Thu, 7 Jan 2021 17:39:36 -0000 (UTC) Subject: primitive password cracker References: Message-ID: On 2021-01-07, Bischoop wrote: > On 2021-01-07, Chris Angelico wrote: >> >> True. Unfortunately, it doesn't work, so what you'd have is something >> that can be easily parameterized to not work on other numbers of >> characters too. :) >> > > My bad is I'm kinda maniac and have to know how to, I know best solution > itertool but... I just must know, was thinking that studing the itertool > code would give me an answer but found it's in C. > Now I try list comprehension for it, so it's another day on it for me. > > So after checking itertools doc I found what itertools.product is quivalent for on: https://docs.python.org/3/library/itertools.html#itertools.product Now I'll sleep. -- Thanks From david at kolovratnik.net Thu Jan 7 12:56:49 2021 From: david at kolovratnik.net (David =?iso-8859-1?Q?Kolovratn=EDk?=) Date: Thu, 7 Jan 2021 18:56:49 +0100 Subject: primitive password cracker In-Reply-To: References: Message-ID: <20210107175648.GJ14929@crfreenet.org> I find a parallel to counting useful. Let letters be '0' to '9' and think of manual (in contrast to formatting range(0, 10)) construction of list of strings "0000" to "9999" Let's start with 0000. How do you compute the next item? Start looking from its end. I stop here in order to leave space for Bischoop's deliberation. To sum up in order words, the clue is to stop thinking of inner loops for each letter and find a way to get the next combination. Best, David On Thu, Jan 07, 2021 at 04:52:56PM -0000, Bischoop wrote: > On 2021-01-07, Chris Angelico wrote: > > > > True. Unfortunately, it doesn't work, so what you'd have is something > > that can be easily parameterized to not work on other numbers of > > characters too. :) > > > > My bad is I'm kinda maniac and have to know how to, I know best solution > itertool but... I just must know, was thinking that studing the itertool > code would give me an answer but found it's in C. > Now I try list comprehension for it, so it's another day on it for me. > > > -- > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list From PythonList at DancesWithMice.info Thu Jan 7 13:23:58 2021 From: PythonList at DancesWithMice.info (dn) Date: Fri, 8 Jan 2021 07:23:58 +1300 Subject: primitive password cracker In-Reply-To: References: Message-ID: On 08/01/2021 05.52, Bischoop wrote: > On 2021-01-07, Chris Angelico wrote: >> >> True. Unfortunately, it doesn't work, so what you'd have is something >> that can be easily parameterized to not work on other numbers of >> characters too. :) >> > > My bad is I'm kinda maniac and have to know how to, I know best solution > itertool but... I just must know, was thinking that studing the itertool > code would give me an answer but found it's in C. > Now I try list comprehension for it, so it's another day on it for me. BTW have you realised a second 'typo' - that there are only 24 letters in this 'alphabet'? It is not difficult to parametrise the building of a "password cracking dictionary"! (NB not same definition as a Python dictionary) Take it one step (one character) at a time... We start from our list of "letters". This is every permutation of the alphabet, taken one at a time. Call it the one_character_list. [Let's not distract from the problem by arguing about the definition of "permutation"!] Next, we'll take the one_character_list and permute that, with each of our letter[s]. Thus 'a, b, c' expands to 'aa, ab, ac, ... ba, bb, bc, ... ca, cb, cc, ...'. For every one of the 24 elements of the one_character_list we now have 24 elements in the two_character_list, ie len( two_character_list ) should be 24*24 (== 24**2) and each element should be unique (ie same rule as a set). NB above equation varies if the rule for what may be the first character of a password differs for the rule of which letters/characters may follow! Similarly, if we take the two_character_list, we can permute that (again/further) with each letter. Thus 'aaa, aab, aac, ...baa, bab, bac, ...'. Thus, len( three_character_list ) == 24 * 24 * 24 == 24 ** 3 == len( two_character_list ) * 24 == len( one_character_list ) * 24 * 24 Carrying-on we can build a "password cracking dictionary" of any length. NB the three-character_list contains exactly 'what it says on the tin' (English-English expression meaning that the label is entirely correct). Thus if the password rules say 'up to three characters in length', then the password-cracker would have to test each of the three lists in-turn too look for one-character passwords, then two-character passwords, and finally three...! Disclaimers: Permutations and combinations are an interesting [learning] exercise, and we're getting used to your preference for step-by-step experimentation and learning-mastery. That said, @David is correct - once understood, use the tool! Because these multiple loops are "expensive" (in terms of execution-time). Per @Chris and comments above, consider when and where to use character-strings, tuples, lists, and/or sets - for 'best results' and/or 'best practice'. Per @yourself, once you have coded, tested, and debugged a solution featuring explicit for-loops, it will be a valuable exercise to upgrade (the code and quite probably the execution speed) using comprehensions/expressions... Sample code: def permute_lists( existing_list:list, expansion_list:list )->list: '''Expand each of the existing list's elements with every element of a provided list. ''' permuted_list = list() for existing_element in existing_list: for expansion_element in expansion_list: permuted_list.append( existing_element + expansion_element ) return permuted_list # establish character-set to be used letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'w', 'q', 'y', 'z'] # taking each of the letters once is the character-set one_character_list = letters print( len( one_character_list ) ) print( one_character_list, end="\n" ) # taking the letters two at a time two_character_list = permute_lists( one_character_list, letters ) print( len( two_character_list ), len( one_character_list ) * len( letters ) ) print( two_character_list, end="\n" ) # taking the letters three at a time three_character_list = permute_lists( two_character_list, letters ) print( len( three_character_list ), len( two_character_list ) * len( letters ) ) print( three_character_list, end="\n" ) -- Regards =dn From tjreedy at udel.edu Thu Jan 7 15:35:47 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 7 Jan 2021 15:35:47 -0500 Subject: Class and tkinter problem In-Reply-To: References: Message-ID: On 1/7/2021 4:20 AM, Terry Reedy wrote: > On 1/7/2021 2:42 AM, Christian Gollwitzer wrote: >> Am 07.01.21 um 08:29 schrieb Paulo da Silva: >> >>> Does anybody know why cmd method isn't called when I change the button >>> state (clicking on it) in this example? >>> I know that this seems a weird class use. But why doesn't it work? >>> Thanks. >>> >>> class C: >>> ???? from tkinter import Checkbutton >>> ???? import tkinter >>> >>> ???? @staticmethod >> ^^it works if you remove the staticmethod here > > staticmethods are essentially useless in Python.? What little was gained > by their addition is partly offset by the introduced confusion. >>> ???? def cmd(): >>> ???????? print("Test") The confusion is that methods are callable, whereas 'staticmethods' are not. I was not completely aware of this until pointed out by Peter Otten with example " cmd() Traceback (most recent call last): File "", line 1, in class C: File "", line 4, in C cmd() TypeError: 'staticmethod' object is not callable You have to go through the descriptor protocol:" Indeed, dir(cmd) shows that it does not have a .__call__ attribute. > ??? top=tkinter.Tk() > ??? cb=Checkbutton(command=cmd) > Button commands have to be tcl functions.? Tkinter wraps Python > functions as tcl function.? Static methods also wrap python functions, > as a .__func__ attribute.? So the code if one passes cmd.__func__. "So the code works if one passes the callable cmd.__func__." >> Maybe there is a bug in tkinter, that it doesn't work with static >> methods? > > One could propose that tkinter test whether callables are staticmethods Command options, as documented, must be callables. Neither staticmethods nor classmethods are callable. > and unwrap them when they are. I would propose instead that if possible tkinter raise TypeError when passed a non-callable as a command. > Classmethods also do not work as is.? By experiment, the following works. > ??? cb=Checkbutton(command=lambda: C.cmd.__func__(C)) > But if the class were nested, it would be more complicated. -- Terry Jan Reedy From hatch4591 at gmail.com Thu Jan 7 15:48:47 2021 From: hatch4591 at gmail.com (Craig Hatch) Date: Thu, 7 Jan 2021 14:48:47 -0600 Subject: This is a test Message-ID: I have added you to the EMAIL list, so when I have questions. Just learn for fun. Craig Hatch From greg.ewing at canterbury.ac.nz Thu Jan 7 19:25:23 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 8 Jan 2021 13:25:23 +1300 Subject: primitive password cracker In-Reply-To: References: Message-ID: Another way to approach this problem is using recursion, e.g. def find_combinations(items, n, comb, result): if n == 0: result.append(comb) else: for item in items: find_combinations(items, n - 1, comb + [item], result) words = [] find_combinations(['a', 'b', 'c'], 3, [], words) print(words) For this particular problem it's less efficient than the technique used by itertools.product, because it generates sub-combinations multiple times. However, it's a useful technique to keep in mind whenever you have a "variable number of nested for-loops" kind of problem. -- Greg From rosuav at gmail.com Thu Jan 7 19:39:16 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 8 Jan 2021 11:39:16 +1100 Subject: primitive password cracker In-Reply-To: References: Message-ID: On Fri, Jan 8, 2021 at 11:31 AM Greg Ewing wrote: > > Another way to approach this problem is using recursion, e.g. > > def find_combinations(items, n, comb, result): > if n == 0: > result.append(comb) > else: > for item in items: > find_combinations(items, n - 1, comb + [item], result) > > words = [] > find_combinations(['a', 'b', 'c'], 3, [], words) > print(words) > True, but I'd much rather write it as a generator: def permute(items, n): if not n: yield "" return # Optional performance enhancement: if n == 1: return (yield from items) for item in items: for rest in permute(items, n - 1): yield item + rest words = list(permute("abc", 3)) I'm not sure how performance would go, but this is a lot cleaner. ChrisA From p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt Thu Jan 7 20:30:15 2021 From: p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt (Paulo da Silva) Date: Fri, 8 Jan 2021 01:30:15 +0000 Subject: Class and tkinter problem References: Message-ID: ?s 20:35 de 07/01/21, Terry Reedy escreveu: > On 1/7/2021 4:20 AM, Terry Reedy wrote: >> On 1/7/2021 2:42 AM, Christian Gollwitzer wrote: >>> Am 07.01.21 um 08:29 schrieb Paulo da Silva: >>> >>>> Does anybody know why cmd method isn't called when I change the button >>>> state (clicking on it) in this example? >>>> I know that this seems a weird class use. But why doesn't it work? >>>> Thanks. >>>> >>>> class C: >>>> ???? from tkinter import Checkbutton >>>> ???? import tkinter >>>> >>>> ???? @staticmethod >>> ^^it works if you remove the staticmethod here >> >> staticmethods are essentially useless in Python.? What little was >> gained by their addition is partly offset by the introduced confusion. > >>>> ???? def cmd(): >>>> ???????? print("Test") > > The confusion is that methods are callable, whereas 'staticmethods' are > not.? I was not completely aware of this until pointed out by Peter > Otten with example > > "??? cmd() > > Traceback (most recent call last): > ? File "", line 1, in > ??? class C: > ? File "", line 4, in C > ??? cmd() > TypeError: 'staticmethod' object is not callable > > You have to go through the descriptor protocol:" > > Indeed, dir(cmd) shows that it does not have a .__call__ attribute. > >> ???? top=tkinter.Tk() >> ???? cb=Checkbutton(command=cmd) > >> Button commands have to be tcl functions.? Tkinter wraps Python >> functions as tcl function.? Static methods also wrap python functions, >> as a .__func__ attribute.? So the code if one passes cmd.__func__. > > "So the code works if one passes the callable cmd.__func__." > >>> Maybe there is a bug in tkinter, that it doesn't work with static >>> methods? >> >> One could propose that tkinter test whether callables are staticmethods > > Command options, as documented, must be callables. Neither staticmethods > nor classmethods are callable. > >> and unwrap them when they are. > > ?I would propose instead that if possible tkinter raise TypeError when > passed a non-callable as a command. > Yes, that would be much better. Thanks. From wesjpeng at gmail.com Thu Jan 7 19:28:02 2021 From: wesjpeng at gmail.com (Wesley Peng) Date: Fri, 8 Jan 2021 08:28:02 +0800 Subject: This is a test In-Reply-To: References: Message-ID: Please don't send a test message to the public list which was read by thousands of people. thanks. On Fri, Jan 8, 2021 at 5:26 AM Craig Hatch wrote: > I have added you to the EMAIL list, so when I have questions. > > Just learn for fun. > > > Craig Hatch > -- > https://mail.python.org/mailman/listinfo/python-list > From unix.co at gmail.com Fri Jan 8 04:56:38 2021 From: unix.co at gmail.com (Umar Draz) Date: Fri, 8 Jan 2021 14:56:38 +0500 Subject: Remove duplicate values from dictionary without removing key Message-ID: I want to replace duplicate values with empty "" in my dictionary. Here is my original dictionary. items = [ {'client': 'xyz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 100}, {'client': 'xyz','name': "Abdelmadjid Tebboune", 'rating': 4.0, 'total': 100}, {'client': 'xyz','name': "Alexander Lukashenko", 'rating': 3.1, 'total': 100}, {'client': 'xyz', 'name': "Miguel D?az-Canel", 'rating': 0.32, 'total': 100}, {'client': 'udz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 150}, {'client': 'udz', 'name': "Abdelmadjid Tebboune", 'rating': 4.0, 'total': 100}, {'client': 'udz', 'name': "Alexander Lukashenko", 'rating': 3.1, 'total': 150}, {'client': 'udz', 'name': "Miguel D?az-Canel", 'rating': 0.32, 'total': 150} ] Now I want to create another dict with like this items = [ {'client': 'xyz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 100}, {'client': '','name': "Abdelmadjid Tebboune", 'rating': 4.0, 'total': ''}, {'client': '','name': "Alexander Lukashenko", 'rating': 3.1, 'total': ''}, {'client': '', 'name': "Miguel D?az-Canel", 'rating': 0.32, 'total': ''}, {'client': 'udz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 150}, {'client': '', 'name': "Abdelmadjid Tebboune", 'rating': 4.0, 'total': ''}, {'client': '', 'name': "Alexander Lukashenko", 'rating': 3.1, 'total': ''}, {'client': '', 'name': "Miguel D?az-Canel", 'rating': 0.32, 'total': ''} ] Would you please help me how I can do this? and if this is not the right place to ask this question then please help me where I can ask this? I had tried stackoverflow but that not worked. From a.h.jaffe at gmail.com Fri Jan 8 07:33:38 2021 From: a.h.jaffe at gmail.com (Andrew Jaffe) Date: Fri, 8 Jan 2021 12:33:38 +0000 Subject: better handling of "pinned" modules? Message-ID: Hi, I don't know if this makes more sense here or on "python-ideas" (or elsewhere?) but I'll try this first: I am starting to encounter more and more instances of packages requiring older, pinned, versions of modules, and this is occasionally actually starting to cause conflicts. It seems that the "official" way to handle this is through virtual environments, but this is not ideal for my workflow, which usually involves a lot of exploratory analysis -- I don't know which packages I'll need before I start (and, in any event, there's no guarantee I won't need conflicting packages). Are there any good workarounds, or proposals for actual solutions so that multiple versions of a package can be installed? I understand that this is not trivial. Where would the "pinning" happen? It could be in the source code, so that it would somehow happen in the `import` statement (e.g., by explicitly renaming the package in question to include a version number, or less likely, by a new `import` syntax)? Or it could happen in the structure of the way modules are stored so that, for example, any imports that happen within a specific package egg would be directed to a specific version stored within the egg or in some other known location? Is this an issue worth tackling? Or do we just have to rely on package developers to keep up with their dependencies? Yours, Andrew From rosuav at gmail.com Fri Jan 8 13:21:18 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 9 Jan 2021 05:21:18 +1100 Subject: better handling of "pinned" modules? In-Reply-To: References: Message-ID: On Sat, Jan 9, 2021 at 5:18 AM Andrew Jaffe wrote: > > Hi, > > I don't know if this makes more sense here or on "python-ideas" (or > elsewhere?) but I'll try this first: > > I am starting to encounter more and more instances of packages requiring > older, pinned, versions of modules, and this is occasionally actually > starting to cause conflicts. > The first thing to do is to see if those packages ACTUALLY need older versions of those dependencies. There's a good chance they don't. To avoid creating this sort of problem, don't depend on a highly specific version of things; just depend on a minimum version, and if there's a problem (ONLY if there's a problem), a maximum version. ChrisA From python at mrabarnett.plus.com Fri Jan 8 15:03:43 2021 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 8 Jan 2021 20:03:43 +0000 Subject: Remove duplicate values from dictionary without removing key In-Reply-To: References: Message-ID: On 2021-01-08 09:56, Umar Draz wrote: > I want to replace duplicate values with empty "" in my dictionary. Here is > my original dictionary. > > items = [ > {'client': 'xyz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 100}, > {'client': 'xyz','name': "Abdelmadjid Tebboune", 'rating': 4.0, > 'total': 100}, > {'client': 'xyz','name': "Alexander Lukashenko", 'rating': 3.1, > 'total': 100}, > {'client': 'xyz', 'name': "Miguel D?az-Canel", 'rating': 0.32, > 'total': 100}, > {'client': 'udz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 150}, > {'client': 'udz', 'name': "Abdelmadjid Tebboune", 'rating': 4.0, > 'total': 100}, > {'client': 'udz', 'name': "Alexander Lukashenko", 'rating': 3.1, > 'total': 150}, > {'client': 'udz', 'name': "Miguel D?az-Canel", 'rating': 0.32, 'total': 150} > ] > > > Now I want to create another dict with like this > > items = [ > {'client': 'xyz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 100}, > {'client': '','name': "Abdelmadjid Tebboune", 'rating': 4.0, 'total': ''}, > {'client': '','name': "Alexander Lukashenko", 'rating': 3.1, 'total': ''}, > {'client': '', 'name': "Miguel D?az-Canel", 'rating': 0.32, 'total': ''}, > {'client': 'udz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 150}, > {'client': '', 'name': "Abdelmadjid Tebboune", 'rating': 4.0, 'total': ''}, > {'client': '', 'name': "Alexander Lukashenko", 'rating': 3.1, 'total': ''}, > {'client': '', 'name': "Miguel D?az-Canel", 'rating': 0.32, 'total': ''} > ] > > > Would you please help me how I can do this? and if this is not the right > place to ask this question then please help me where I can ask this? I had > tried stackoverflow but that not worked. > Iterate through the list of dicts. If you've seen the client before, then set the appropriate value or values in the dict to ''. You can use a set to remember which clients you've already seen. From jbrown299 at yandex.com Fri Jan 8 14:53:35 2021 From: jbrown299 at yandex.com (James) Date: Fri, 8 Jan 2021 22:53:35 +0300 Subject: asyncio project code review Message-ID: <935ef843-f58d-a845-b20e-7c950ae4765a@yandex.com> Good day everyone. I have new asyncio project which use aiohttp connector and asyncio protocols/transports for tunneling packets through Tor Network cleanly. Project called aiotor: https://github.com/torpyorg/aiotor If someone with experience in asyncio field can make code review I will be appreciated for any comments. I prepared pull request to make it convenient to review and comment on the code: https://github.com/torpyorg/aiotor/pull/1 From jbrown299 at yandex.com Fri Jan 8 15:10:19 2021 From: jbrown299 at yandex.com (James) Date: Fri, 8 Jan 2021 23:10:19 +0300 Subject: Asyncio project code review Message-ID: <22214ba4-4ac0-0b48-d477-750ac3c1366b@yandex.com> Good day for everyone. I have new asyncio project which use aiohttp connector and asyncio protocols/transports for tunneling packets through Tor Network cleanly. Project called aiotor: https://github.com/torpyorg/aiotor If someone with experience in asyncio field can make code review I will be appreciated for any comments. I prepared pull request to make it convenient to review and comment on the code: https://github.com/torpyorg/aiotor/pull/1 Thanks in advance. From rshepard at appl-ecosys.com Fri Jan 8 16:47:35 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 8 Jan 2021 13:47:35 -0800 (PST) Subject: tkinter: creating/attaching menubar to top level window Message-ID: I'm using Chapter 9 in Mark Roseman's "Modern Tkinter for Busy Python Developers" to learn how to write a top level menu. MWE code is attached. Python3 tells me there's invalid syntax on line 42: self.['menu'] = menubar # attach it to the top level window ^ yet that's the syntax he prints on page 84 (and has in the book's code supplement). Why am I getting an invalid syntax error here? TIA, Rich -------------- next part -------------- #!/usr/bin/env python3 # main file to start application. from os import environ import sys import pdb from datetime import datetime import tkinter as tk from tkinter import ttk from tkinter import Menu from tkinter import filedialog from tkinter import messagebox from tkinter.font import nametofont from functools import partial import model as m import views as v import controller as c class Application(tk.Tk): """ Application root window """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # the top level frame holding menu, status bar, etc. self.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self.geometry('800x600') self.title("Frame title") self.resizable(width=True, height=True) datestring = datetime.today().strftime("%Y-%m-%d") # status bar self.status = tk.StringVar() self.statusbar = ttk.Label(self, textvariable=self.status) self.statusbar.grid(sticky="we", row=3, padx=10) # toplevel window menu menubar = Menu(self) # create a Menu widget self.['menu'] = menubar # attach it to the top level window """ Add menus to menubar """ self.menu_file = Menu(menubar, tearoff=0) self.menu_view = Menu(menubar, tearoff=0) self.menu_add = Menu(menubar, tearoff=0) self.menu_edit = Menu(menubar, tearoff=0) self.menu_report = Menu(menubar, tearoff=0) self.menu_help = Menu(menubar, tearoff=0) """ Add menu items to menus """ menubar.add_cascade(menu_file, label='File') menubar.add_cascade(menu_view, label='View') menubar.add_cascade(menu_add, label='Add') menubar.add_cascade(menu_edit, label='Edit') menubar.add_cascade(menu_report, label='Report') menubar.add_cascade(menu_help, label='Help') if __name__ == "__main__": app = Application() app.mainloop() From auriocus at gmx.de Fri Jan 8 17:14:57 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Fri, 8 Jan 2021 23:14:57 +0100 Subject: tkinter: creating/attaching menubar to top level window In-Reply-To: References: Message-ID: Am 08.01.21 um 22:47 schrieb Rich Shepard: > I'm using Chapter 9 in Mark Roseman's "Modern Tkinter for Busy Python > Developers" to learn how to write a top level menu. MWE code is attached. > > Python3 tells me there's invalid syntax on line 42: > ??? self.['menu'] = menubar # attach it to the top level window > ???????? ^ > yet that's the syntax he prints on page 84 (and has in the book's code > supplement). It is a simple typo, remove the dot. self['menu'] = menubar It will then stop at the add_cascade, fix it like this: menubar.add_cascade(menu=self.menu_file, label='File') and then it works, > Why am I getting an invalid syntax error here? Because the dot would indicate the access of an attribute. but no name follows. What it does here, instead, is indexing - the correct line is similar to setting a dict entry. Christian From Richard at Damon-Family.org Fri Jan 8 17:16:20 2021 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 8 Jan 2021 17:16:20 -0500 Subject: tkinter: creating/attaching menubar to top level window In-Reply-To: References: Message-ID: <67d6015c-61f8-a28e-f499-0d84acf80701@Damon-Family.org> On 1/8/21 4:47 PM, Rich Shepard wrote: > I'm using Chapter 9 in Mark Roseman's "Modern Tkinter for Busy Python > Developers" to learn how to write a top level menu. MWE code is attached. > > Python3 tells me there's invalid syntax on line 42: > ??? self.['menu'] = menubar # attach it to the top level window > ???????? ^ > yet that's the syntax he prints on page 84 (and has in the book's code > supplement). > > Why am I getting an invalid syntax error here? > > TIA, > > Rich Because it is the wrong syntax. It could be either: self.menu = menubar or self['menu'] = menubar -- Richard Damon From martin.schoon at gmail.com Fri Jan 8 17:17:11 2021 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 8 Jan 2021 22:17:11 GMT Subject: dayofyear is not great when going into a new year References: Message-ID: Den 2021-01-05 skrev Stefan Ram : > Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?= writes: >>I have had some Python fun with COVID-19 data. I have done >>some curve fitting and to make that easier I have transformed >>date to day of year. Come end of 2020 and beginning of 2021 >>and this idea falls on its face. > > import datetime > > continuous_day_of_the_year = \ > ( datetime.date.today() - datetime.date( 2020, 1, 1 )).days > > Thanks guys, you got me on the right track. After some further meandering I did something close to what Stefan suggest above. I added a column to my Pandas data frame and populated it with content of date column - datetime(2020, 1, 1) "regardless of what you have been told, recreational use of mathematics is harmless" I hope that is true for recreational programming as well :-) /Martin From greg.ewing at canterbury.ac.nz Fri Jan 8 17:34:55 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 9 Jan 2021 11:34:55 +1300 Subject: dayofyear is not great when going into a new year In-Reply-To: References: Message-ID: On 9/01/21 11:17 am, Martin Sch??n wrote: > "regardless of what you have been told, recreational use of > mathematics is harmless" > > I hope that is true for recreational programming as well :-) Mostly harmless, but it can be addictive! -- Greg From barpasc at yahoo.com Fri Jan 8 18:06:53 2021 From: barpasc at yahoo.com (pascal z) Date: Fri, 8 Jan 2021 15:06:53 -0800 (PST) Subject: learning python building 2nd app, need advices Message-ID: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> Hi, This is a python app I was working on, can you help making it a beautiful looking app like bleachbit or ccleaner? The whole code below (what it does: it lists all folders and files from a specified path and tells some infos like size in mb or gb... and export it to a csv file for further processing maybe with customized dashboard...the listing should will also be used to rename multiple files to help ordering and finding files because current renaming tools are difficult to use I find...) For now it just gives infos about folders and files and rename. Maybe a backup tool would be nice, please advise. But the code is opposiite to bullet proof and if could be more bullet proof, it would be a way to start and continue the messy code #!/usr/bin/env python3 # -*- coding: utf-8 -*- import locale import os import csv from tkinter import messagebox as msg try: from tkinter import * import ttk except: import tkinter as tk #GUI package from tkinter import ttk def fx_BasicListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv # tree.delete(*tree.get_children()) fx_browseFoldersZ(1) return def fx_AdvancedListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # fx_browseFoldersZ(2,"txt") # tree.destroy() #tree.delete(*tree.get_children()) fx_browseFoldersZ(2) return def fx_browseFoldersZ(argy): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv tree.delete(*tree.get_children()) fx_browseFolders(argy,"txt") ############################################################################### ############################################################################### ############################################################################### def fx_writeCSV(*arr): csv_file_title = 'csv_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w', newline ='\n') as f: write = csv.writer(f, doublequote=True, delimiter=';') for row in arr: write.writerows(row) def fx_writeCSV_str(txt_str): csv_file_title = 'csvtxt_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w') as f: f.write(txt_str) # fx_LoadCSV(CSV_FILE) with open(CSV_FILE, 'r') as f: reader = csv.DictReader(f, delimiter=';') for row in reader: col1 = row['Path'] col2 = row['Folder-file'] col3 = row['Size in Byte'] col4 = row['Size in Kb'] col5 = row['Size in Mb'] col6 = row['Size in Gb'] col7 = row['type'] tree.insert('', 'end', values=(col1, col2, col3, col4, col5, col6,col7)) return ############################################################################### ############################################################################### def fx_chkPath(xzPath): isxFile = os.path.isfile(xzPath) isxDir = os.path.isdir(xzPath) print("DOSSIER OUI????",isxDir) if isxDir: return elif not isxDir: msg.showwarning("Folder path", "WD Path entered not found") return ############################################################################### ############################################################################### ############################################################################### def fx_browseFolders(argz, tycsv): tree.delete(*tree.get_children()) # /// /// /// csv_txt = "" csv_contents = "" counterPath = 0 size = 0 f_size = 0 f_vscale = 0 # /// /// /// # path WD Lpath = vtxt_path.get() print('%s' % Lpath) # include files vvchkboxF = vchkboxF.get() # print("include files:::", vchkboxF.get()) # include modification date print(vchkboxD.get()) # include creation date print(vchkboxC.get()) # scale f_vscale = int(var_scale.get()) print(f_vscale) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] # isFile = os.path.isfile(Lpath) # print("fichier?",isFile) fx_chkPath(Lpath) counterPath = Lpath.count(os.path.sep) csv_contents = "Path;Folder-file;Size in Byte;Size in Kb;Size in Mb;Size in Gb;type\n" csv_txt = csv_contents # csv_contents # 1-FOLDER PATH # 2-FILENAME # 3-FOLDER PATH FULL # 4-Size in Byte # 5-Size in Kb # 6-Size in Mb # 7-Size in Gb # 8-type\n ### BASIC LISTING ######### if argz == 1: print("basic listing") file_paths = [] file_paths.append([csv_contents]) for root, dirs, files in os.walk(Lpath, topdown=True): for file in files: if tycsv == "csv": vfolder_path = root + os.sep vfile_name = "'" + file + "'" vfolder_path_full = root + os.sep + file csv_contents = "%s;%s;%s;%s;%s;%s;%s" % (vfolder_path, vfile_name , 'na', 'na', 'na','na', "folder") file_paths.append([csv_contents]) elif tycsv == "txt": vfolder_path = root + os.sep vfile_name = file vfolder_path_full = root + os.sep + file f_size = os.path.getsize(vfolder_path_full) csv_txt += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s" % (vfolder_path, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "file\n") # APPEL FONCTION ECRIT ARRAY TO CSV if tycsv == "csv": fx_writeCSV(file_paths) elif tycsv == "txt": # APPEL FONCTION ECRIT STR TO CSV fx_writeCSV_str(csv_txt) print("job basic listing ok") ### ADVANCED LISTING ######## elif argz == 2: print("advanced listing") if vvchkboxF == 0: # *** FOLDERS ONLY *** for root, dirs, files in os.walk(Lpath, topdown=False): ### calcul taille dossier f_size = 0 for x, y, z in os.walk(root): for i in z: ftmp_che = x + os.sep + i f_size += os.path.getsize(ftmp_che) ### ecriture taille dossier counter = root.count(os.path.sep) - counterPath vfile_name = root vfile_name = vfile_name + os.path.sep vfile_name = os.path.split(os.path.dirname(vfile_name))[1] vfile_name += os.path.sep if counter <= f_vscale: csv_txt += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s" % (root, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "folder\n") fx_writeCSV_str(csv_txt) print("job adv listing folders ok") elif vvchkboxF == 1: # *** FOLDERS AND FILES ONLY *** for root, dirs, files in os.walk(Lpath, topdown=False): ### calcul taille dossier size = 0 for x, y, z in os.walk(root): for i in z: ftmp_che = x + os.sep + i f_size += os.path.getsize(ftmp_che) ### ecriture taille dossier counter = root.count(os.path.sep) - counterPath vfile_name = root vfile_name = vfile_name + os.path.sep vfile_name = os.path.split(os.path.dirname(vfile_name))[1] vfile_name += os.path.sep if counter <= f_vscale: csv_contents += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s\n" % (root, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "folder") ### calcul +ecriture taille fichier for f in os.listdir(Lpath): path = os.path.join(Lpath, f) if os.path.isfile(path): f_size = 0 f_size = os.path.getsize(path) csv_contents += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s\n" % (path, f, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "file") fx_writeCSV_str(csv_contents) print("job adv listing files ok") return ############################################################################### ############################################################################### ############################################################################### #####################################GUI####################################### ############################################################################### ############################################################################### ############################################################################### locale.setlocale(locale.LC_ALL, "") ## MAIN WINDOW root = Tk() width = int(root.winfo_screenwidth()/1.3) height = int(root.winfo_screenheight()/1.29) positionRight = int(width/7) positionDown = int(height/8) root.geometry('%sx%s+%s+%s' % (width, height, positionRight, positionDown)) root.title("Folders and files tool") ### MAKE TABS tabCtrl = ttk.Notebook(root) tab1 = ttk.Frame(tabCtrl) tab2 = ttk.Frame(tabCtrl) tab3 = ttk.Frame(tabCtrl) tab4 = ttk.Frame(tabCtrl) tabCtrl.add(tab1, text =' Folders mgmt ') tabCtrl.add(tab2, text =' Renamer ') tabCtrl.add(tab3, text =' Something3 ') tabCtrl.add(tab4, text =' More infos ') tabCtrl.pack(expand = 1, fill ="both") ### Display Tabs global vtxt_path global var_scale global vchkboxF global vchkboxD global vchkboxC global vcsv_path #######################///...///...///...///...///####################### # TAB 1 # #######################///...///...///...///...///####################### ### FRAME GLOB frm10 = tk.Frame(tab1, bg="gray5") frm10.pack(expand = 1, fill ="both") # frm10.pack( side = LEFT, expand = True, fill = BOTH) ####################### ### FRAME 11 TOP LABEL frm11 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm11.place(width=475, height=140, x=20, y=20) # Top label title tk.Label(frm11,text ="Drive or folders", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL PATH entry box tk.Label(frm11, text="Enter Path (WD)", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER new_text = "/media/ananas/HDD_500B/TEST_APP3/" ### PATH ENTRY BOX vtxt_path=tk.StringVar(root,value=new_text) # Value saved here txt_path = tk.Entry(frm11,width=43, textvariable=vtxt_path, fg='green').place(width=320, height=30, x=140, y=50) # vtxt_path.set(new_text) # TEST FOLDER zzz ### LABEL PATH example tk.Label(frm11, text=r"Ex.: path for Windows: C:\Users\user\Documents\Dossier test", font=("Helvetica", 8, "italic"), fg='gray80', bg='gray5').place(width=320, height=30, x=130, y=80) tk.Label(frm11, text=r" path Linux: /home/user/Documents/Test dossier/", font=("Verdana", 8, "italic"), fg='gray80', bg='gray5').place(width=300, height=30, x=123, y=100) ### frame 11 ########################### ########################### ### FRAME 12 TOP BUTTON SCAN ALL frm12 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm12.place(width=150, height=40, x=494, y=20) ### button btn_scanALL = tk.Button(frm12, text="Basic listing", bg='lightblue4', font=("Verdana", 10,"normal")) btn_scanALL.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_scanALL['command'] = fx_BasicListing ### frame 12 ########################### ########################### ### FRAME 13 TOP BTN SCAN ADV + SLIDER frm13 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm13.place(width=540, height=100, x=494, y=60) btn_scanADV = tk.Button(frm13, text="Advanced listing", bg='ivory4', font=("Verdana", 10,"normal")) btn_scanADV.place(width=150, height=40, x=0, y=0) ### BUTTON BROWSE entry fx ADVANCED LISTING btn_scanADV['command'] = fx_AdvancedListing ### slider var_scale = tk.DoubleVar() tk.Label(frm13, text="Subfolders level", font=("Verdana", 8, "italic"), fg='gray80', bg='gray5').place(width=150, height=10, x=0, y=46) wslide = tk.Scale(frm13,bg='ivory4', fg='grey5', from_=0, to=10, variable = var_scale, orient=tk.HORIZONTAL) wslide.place(width=150, height=40, x=0, y=58) wslide.set(3) ### frame 13 ########################### ########################### ### FRAME 14 TOP BTN SCAN ADV + CHECKBUTTONS frm14 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm14.place(width=190, height=100, x=645, y=60) vchkboxF=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include files", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxF, offvalue=0, onvalue=1) chkbox.place(x=0, y=5) vchkboxD=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include modification date", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxD, offvalue=0, onvalue=1) chkbox.place(x=0, y=25) vchkboxC=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include creation date", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxC, offvalue=0, onvalue=1) chkbox.place(x=0, y=45) ### frame 14 ########################### ########################### ### FRAME 15 TREEVIEW frm15 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm15.place(width=1000, height=350, x=20, y=175) container = ttk.Frame(frm15) # container.place(width=1015, height=350, x=20, y=175) container.pack() style = ttk.Style() style.theme_use("clam") style.configure("Treeview", background="lemonchiffon3",font=('Tahoma', 9), fieldbackground="lemonchiffon3", foreground="grey10") style.configure("Treeview.Heading", font=('Tahoma', 10),foreground='orange4') tree = ttk.Treeview(frm15, columns=('1', '2', '3', '4', '5', '6', '7')) vsb = ttk.Scrollbar(orient="vertical", command=tree.yview) hsb = ttk.Scrollbar(orient="horizontal", command=tree.xview) vsb.place(x=1021, y=231,width=15, height=307,) hsb.place(x=22, y=540,width=1000, height=15,) tree.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set) container.grid_columnconfigure(0, weight=1) container.grid_rowconfigure(0, weight=1) tree.column('#1', width=180, stretch=YES) tree.column('#2', width=240, stretch=YES) tree.column('#3', width=10, stretch=YES) tree.column('#4', width=5, stretch=YES) tree.column('#5', width=5, stretch=YES) tree.column('#6', width=5, stretch=YES) tree.column('#7', width=25, stretch=YES) tree.heading('#1', text='Path') tree.heading('#2', text='Folder-file') tree.heading('#3', text='Byte') tree.heading('#4', text='Kb') tree.heading('#5', text='Mb') tree.heading('#6', text='Gb') tree.heading('#7', text='Object type') tree['show'] = 'headings' tree.pack(fill=BOTH,expand=1) ### frame 15 ########################### ########################### ### FRAME 16 CSV DIAL frm16 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm16.place(width=480, height=30, x=20, y=530) # csv lbl tk.Label(frm16,text ="Default folder for csv file (change...)", font=("Verdana", 8, "normal"), fg='gray80', bg='gray5').place(x=10, y=5) # csv folder entry box vcsv_path=tk.StringVar() # Value saved here txt_csv = tk.Entry(frm16,width=43, textvariable=vcsv_path, fg='green').place(width=265, x=210, y=3) full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep vcsv_path.set(new_text) ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### def fx_FileRen(): Lpath = vtxt_path3.get() print('%s' % Lpath) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] print('%s' % Lpath) msg.showwarning("File names", "File names changed") # with open(csv_file_title) as csvfile: # csvreader = csv.reader(csvfile, delimiter=';', quotechar='"') # for row in csvreader: # name = row[0] # new = row[1] # if os.path.exists(name): # os.rename(name, new) # else: # print(name + " does not exist") ############################################################################### def fx_FoldRen(): csv_file_title = 'csv_1_baselisting.csv' print('%s' % csv_file_title) # with open(CSV_FILE,'w', newline ='\n') as f: # write = csv.writer(f, doublequote=True, delimiter=';') # for row in arr: # write.writerows(row) msg.showwarning("Folder names", "Folders names changed") ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### #######################///...///...///...///...///####################### # TAB 2 # #######################///...///...///...///...///####################### ### FRAME GLOB frm20 = tk.Frame(tab2, bg="gray5") frm20.pack(expand = 1, fill ="both") # frm10.pack( side = LEFT, expand = True, fill = BOTH) ####################### ### FRAME 21a FOLDER PATH frm21a = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm21a.place(width=950, height=100, x=20, y=45) # Top label title tk.Label(frm21a,text ="Folder path to list folders files to csv", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) vtxt_path1a=tk.StringVar(root, value=new_text) # Value saved here txt_path1a = tk.Entry(frm21a,width=43, textvariable=vtxt_path1a, fg='blue').place(width=620, height=30, x=140, y=50) ####################### ### FRAME 21 LABEL FILES RENAME frm21 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm21.place(width=775, height=100, x=20, y=185) # Top label title tk.Label(frm21,text ="Rename files only from csv file below", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL FILES RENAME entry box tk.Label(frm21, text="CSV file path", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep + "csvtxt_1_filenamelisting.csv" # vtxt_path2.set(new_text) ### PATH ENTRY BOX vtxt_path2=tk.StringVar(root, value=new_text) # Value saved here txt_path2 = tk.Entry(frm21,width=43, textvariable=vtxt_path2, fg='blue').place(width=620, height=30, x=140, y=50) # TEST FOLDER zzz ########################### ### FRAME 22 TOP BUTTON FILE RENAME frm22 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm22.place(width=150, height=40, x=820, y=220) ### button btn_FileRen = tk.Button(frm22, text="Files rename", bg='lightblue4', font=("Verdana", 10,"normal")) btn_FileRen.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_FileRen['command'] = fx_FileRen ####################### ### FRAME 23 LABEL FOLDERS RENAME frm23 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm23.place(width=775, height=100, x=20, y=320) # Top label title tk.Label(frm23,text ="Rename folders only from csv file below", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL PATH entry box tk.Label(frm23, text="CSV file path", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep + "csvtxt_1_foldernamelisting.csv" # vtxt_path2.set(new_text) ### PATH ENTRY BOX vtxt_path3=tk.StringVar(root, value=new_text) # Value saved here txt_path3 = tk.Entry(frm23,width=43, textvariable=vtxt_path3, fg='brown').place(width=620, height=30, x=140, y=50) # TEST FOLDER zzz ########################### ### FRAME 24 BUTTON FOLDERS RENAME frm24 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm24.place(width=150, height=40, x=820, y=345) ### button btn_FoldRen = tk.Button(frm24, text="Folders rename", bg='brown', font=("Verdana", 10,"normal")) btn_FoldRen.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_FoldRen['command'] = fx_FoldRen #######################///...///...///...///...///####################### # TAB 3 # #######################///...///...///...///...///####################### #######################///...///...///...///...///####################### # zZZZz # #######################///...///...///...///...///####################### if __name__ == '__main__': root.mainloop() From barpasc at yahoo.com Fri Jan 8 18:10:40 2021 From: barpasc at yahoo.com (pascal z) Date: Fri, 8 Jan 2021 15:10:40 -0800 (PST) Subject: learning python building 2nd app, need advices In-Reply-To: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> Message-ID: <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> any way to attach a file because I loose indentation? From rshepard at appl-ecosys.com Fri Jan 8 18:16:23 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 8 Jan 2021 15:16:23 -0800 (PST) Subject: tkinter: creating/attaching menubar to top level window [RESOLVED] In-Reply-To: References: Message-ID: On Fri, 8 Jan 2021, Christian Gollwitzer wrote: > It is a simple typo, remove the dot. > self['menu'] = menubar > It will then stop at the add_cascade, fix it like this: Christian, Well, I totally missed that because I'm used to adding a period after each self. Your fresh eyes saw what I kept missing, > menubar.add_cascade(menu=self.menu_file, label='File') I was going to add the 'self' there when I found what stopped the processing before it. Many thanks. Stay well and carpe weekend, Rich From rshepard at appl-ecosys.com Fri Jan 8 18:17:28 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 8 Jan 2021 15:17:28 -0800 (PST) Subject: tkinter: creating/attaching menubar to top level window In-Reply-To: <67d6015c-61f8-a28e-f499-0d84acf80701@Damon-Family.org> References: <67d6015c-61f8-a28e-f499-0d84acf80701@Damon-Family.org> Message-ID: On Fri, 8 Jan 2021, Richard Damon wrote: > It could be either: > self.menu = menubar > or > self['menu'] = menubar Got it, Richard. Removed the period after 'self'. Thanks, Rich From barpasc at yahoo.com Fri Jan 8 18:18:54 2021 From: barpasc at yahoo.com (pascal z) Date: Fri, 8 Jan 2021 15:18:54 -0800 (PST) Subject: learning python building 2nd app, need advices In-Reply-To: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> Message-ID: <5e417ce3-3419-4beb-99de-fdd24dfa5d44n@googlegroups.com> And something important to this app, is about listing files, how to avoid listing small application files parts .ini and binary files so if it's an application it would tell the size of of the folder of this application and not list the content or make it optionnal? From greg.ewing at canterbury.ac.nz Fri Jan 8 19:16:40 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 9 Jan 2021 13:16:40 +1300 Subject: learning python building 2nd app, need advices In-Reply-To: <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> Message-ID: On 9/01/21 12:10 pm, pascal z wrote: > any way to attach a file because I loose indentation? Indentation usually makes it through here if you indent with spaces rather than tabs. -- Greg From Richard at Damon-Family.org Fri Jan 8 20:27:29 2021 From: Richard at Damon-Family.org (Richard Damon) Date: Fri, 8 Jan 2021 20:27:29 -0500 Subject: learning python building 2nd app, need advices In-Reply-To: <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> Message-ID: On 1/8/21 6:10 PM, pascal z via Python-list wrote: > any way to attach a file because I loose indentation? Don't post via googlegroups, it thinks the world is HTML, which treats spaces in a funny matter. -- Richard Damon From lkrupp at invalid.pssw.com.invalid Sat Jan 9 00:33:51 2021 From: lkrupp at invalid.pssw.com.invalid (Louis Krupp) Date: Fri, 8 Jan 2021 22:33:51 -0700 Subject: Remove duplicate values from dictionary without removing key In-Reply-To: References: Message-ID: <3fbKH.81490$ay6.60684@fx03.iad> On 1/8/2021 2:56 AM, Umar Draz wrote: > I want to replace duplicate values with empty "" in my dictionary. Here is > my original dictionary. > > items = [ > {'client': 'xyz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 100}, > {'client': 'xyz','name': "Abdelmadjid Tebboune", 'rating': 4.0, > 'total': 100}, > {'client': 'xyz','name': "Alexander Lukashenko", 'rating': 3.1, > 'total': 100}, > {'client': 'xyz', 'name': "Miguel D?az-Canel", 'rating': 0.32, > 'total': 100}, > {'client': 'udz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 150}, > {'client': 'udz', 'name': "Abdelmadjid Tebboune", 'rating': 4.0, > 'total': 100}, > {'client': 'udz', 'name': "Alexander Lukashenko", 'rating': 3.1, > 'total': 150}, > {'client': 'udz', 'name': "Miguel D?az-Canel", 'rating': 0.32, 'total': 150} > ] > > > Now I want to create another dict with like this > > items = [ > {'client': 'xyz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 100}, > {'client': '','name': "Abdelmadjid Tebboune", 'rating': 4.0, 'total': ''}, > {'client': '','name': "Alexander Lukashenko", 'rating': 3.1, 'total': ''}, > {'client': '', 'name': "Miguel D?az-Canel", 'rating': 0.32, 'total': ''}, > {'client': 'udz', 'name': "Ilir Meta", 'rating': 0.06, 'total': 150}, > {'client': '', 'name': "Abdelmadjid Tebboune", 'rating': 4.0, 'total': ''}, > {'client': '', 'name': "Alexander Lukashenko", 'rating': 3.1, 'total': ''}, > {'client': '', 'name': "Miguel D?az-Canel", 'rating': 0.32, 'total': ''} > ] > > > Would you please help me how I can do this? and if this is not the right > place to ask this question then please help me where I can ask this? I had > tried stackoverflow but that not worked. items isn't a dictionary; as MRAB mentioned, it's a list of dictionaries. Each dictionary in items looks like a database record with fields (client, name, rating, and total). When you say you want to replace duplicate client fields by "", it almost looks like you're getting ready to print a report that looks something like this: xyz??? Ilir Meta????????????????????????????? 0.06??? 100 ????????? Abdelmadjid Tebboune??? 4.00 ?? 100 ????????? Alexander Lukashenko???? 3.10 ... where the report will look better when duplicate client values aren't printed. If that's the case, there are almost certainly better ways to do it. Changing values in items might have unforeseen consequences, since once duplicate client fields have been wiped out, there's no way to retrieve items[1]["client"] without looking at items[0]. And if the list of items is ever reordered, some of the client fields will be lost for good. I hope this helps. Louis From a.h.jaffe at gmail.com Fri Jan 8 16:55:59 2021 From: a.h.jaffe at gmail.com (Andrew Jaffe) Date: Fri, 8 Jan 2021 21:55:59 +0000 Subject: better handling of "pinned" modules? In-Reply-To: References: Message-ID: On 08/01/2021 18:21, Chris Angelico wrote: > On Sat, Jan 9, 2021 at 5:18 AM Andrew Jaffe wrote: >> >> Hi, >> >> I don't know if this makes more sense here or on "python-ideas" (or >> elsewhere?) but I'll try this first: >> >> I am starting to encounter more and more instances of packages requiring >> older, pinned, versions of modules, and this is occasionally actually >> starting to cause conflicts. >> > > The first thing to do is to see if those packages ACTUALLY need older > versions of those dependencies. There's a good chance they don't. > > To avoid creating this sort of problem, don't depend on a highly > specific version of things; just depend on a minimum version, and if > there's a problem (ONLY if there's a problem), a maximum version. Well, sure. But there's still the "aesthetic" problem that `pip[3] check` reports a problem in such a case, and the real (albeit correctable) problem that `pip[3] install --upgrade` will occasionally automatically downgrade required packages. So perhaps my original query about whether there could be a way to actually solve this problem is still potentially interesting/useful. AndrewJ > ChrisA > From auriocus at gmx.de Sat Jan 9 02:51:51 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 9 Jan 2021 08:51:51 +0100 Subject: dayofyear is not great when going into a new year In-Reply-To: References: Message-ID: Am 05.01.21 um 23:56 schrieb Eli the Bearded: > Elijah > ------ > also finds "week starts on Monday" to be oddball about ISO-8601 > In Europe, the week starts on Monday - hence, Saturday and Sunday are the last days of the week or the "weekend". Starting on Sunday is weird for us, because then the weekend is split into the first and last day of the week (?) - even if, historically, the week was the time from Sunday to Sunday. Christian From mstemper at gmail.com Sat Jan 9 09:24:58 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Sat, 9 Jan 2021 08:24:58 -0600 Subject: primitive password cracker In-Reply-To: References: Message-ID: Is this "code golf"? Can anybody play? Here's another approach: Define a function like this: def embiggen(wordlist): alpha = 'abc' return [x for x in alpha] + [x+y for x in alpha for y in wordlist] It makes every word in its input one letter longer in each possible way, and returns all of the words thus created as well as all of the one-letter words. (I'm using a very short alphabet, due to the exponential growth.) In REPL: >>> words = [] >>> words = embiggen(words) >>> words ['a', 'b', 'c'] >>> words = embiggen(words) >>> words ['a', 'b', 'c', 'aa', 'ab', 'ac', 'ba', 'bb', 'bc', 'ca', 'cb', 'cc'] >>> words = embiggen(words) >>> words ['a', 'b', 'c', 'aa', 'ab', 'ac', 'aaa', 'aab', 'aac', 'aba', 'abb', 'abc', 'aca', 'acb', 'acc', 'ba', 'bb', 'bc', 'baa', 'bab', 'bac', 'bba', 'bbb', 'bbc', 'bca', 'bcb', 'bcc', 'ca', 'cb', 'cc', 'caa', 'cab', 'cac', 'cba', 'cbb', 'cbc', 'cca', 'ccb', 'ccc'] >>> words = embiggen(words) >>> len(words) 120 >>> It's obvious that this could be called from a for-loop with no modification, which I believe is what the OP wanted. -- Michael F. Stemper Deuteronomy 24:17 From mstemper at gmail.com Sat Jan 9 09:28:53 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Sat, 9 Jan 2021 08:28:53 -0600 Subject: dayofyear is not great when going into a new year In-Reply-To: References: Message-ID: On 09/01/2021 01.51, Christian Gollwitzer wrote: > Am 05.01.21 um 23:56 schrieb Eli the Bearded: >> Elijah >> ------ >> also finds "week starts on Monday" to be oddball about ISO-8601 >> > > In Europe, the week starts on Monday - hence, Saturday and Sunday are > the last days of the week or the "weekend". Starting on Sunday is weird > for us, because then the weekend is split into the first and last day of > the week (?) A week is like a piece of string. It has two ends. -- Michael F. Stemper Deuteronomy 24:17 From rosuav at gmail.com Sat Jan 9 11:40:39 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 10 Jan 2021 03:40:39 +1100 Subject: dayofyear is not great when going into a new year In-Reply-To: References: Message-ID: On Sun, Jan 10, 2021 at 1:31 AM Michael F. Stemper wrote: > > On 09/01/2021 01.51, Christian Gollwitzer wrote: > > Am 05.01.21 um 23:56 schrieb Eli the Bearded: > >> Elijah > >> ------ > >> also finds "week starts on Monday" to be oddball about ISO-8601 > >> > > > > In Europe, the week starts on Monday - hence, Saturday and Sunday are > > the last days of the week or the "weekend". Starting on Sunday is weird > > for us, because then the weekend is split into the first and last day of > > the week (?) > > A week is like a piece of string. It has two ends. > And a long weekend is like asking "how long is a piece of string"? ChrisA From Bischoop at vimart.net Sat Jan 9 22:29:37 2021 From: Bischoop at vimart.net (Bischoop) Date: Sun, 10 Jan 2021 03:29:37 -0000 (UTC) Subject: binascii.b2a vs ord() Message-ID: I wanted to learn about conversion string to Ascii. So I learn about binascii.b2a but because the output wasn't what I wanted got deeper and found out about ord(c) and actually that's what I'expected. So what's that binascii and why I cant convert ascii that I got from ord to string by using char, instead I'm getting some strings in weird coding. import binascii Ttext = b'This is a string' text2 = 'This is a string' data = binascii.b2a_uu(text) print(f' Conversion byte string to ascii by binascii:\n {data}') res = ' '.join(format(ord(i), 'b') for i in text2) print(f'Conversion string to Ascii by ord:\n {res}') b = binascii.a2b_uu(data) print(f' Conversion ascii to String by binascii:\n {b}') k= res.split(' ') for i in k: w= k.index(i) k[w]= int(i) c = ' '.join(chr(int(val)) for val in res.split(' ')) print(f'Conversion Ascii to string by chr: \n {c}') #output: Conversion byte string to ascii by binascii: b"05&AI References: Message-ID: On Sun, Jan 10, 2021 at 2:31 PM Bischoop wrote: > > I wanted to learn about conversion string to Ascii. > So I learn about binascii.b2a but because the output wasn't what I > wanted got deeper and found out about ord(c) and actually that's what > I'expected. > So what's that binascii and why I cant convert ascii that I got from ord > to string by using char, instead I'm getting some strings in weird > coding. > > > import binascii > Ttext = b'This is a string' > text2 = 'This is a string' > data = binascii.b2a_uu(text) > print(f' Conversion byte string to ascii by binascii:\n {data}') > res = ' '.join(format(ord(i), 'b') for i in text2) > print(f'Conversion string to Ascii by ord:\n {res}') > > b = binascii.a2b_uu(data) > print(f' Conversion ascii to String by binascii:\n {b}') > k= res.split(' ') > for i in k: > w= k.index(i) > k[w]= int(i) > > c = ' '.join(chr(int(val)) for val in res.split(' ')) > print(f'Conversion Ascii to string by chr: \n {c}') > > > #output: > Conversion byte string to ascii by binascii: > b"05&AI Conversion string to Ascii by ord: > 1010100 1101000 1101001 1110011 100000 1101001 1110011 100000 1100001 100000 1110011 1110100 1110010 1101001 1101110 1100111 > Conversion ascii to String by binascii: > b'This is a string' > Conversion Ascii to string by chr: > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? > Trace it through, step by step. You have a series of ASCII values, represented in binary, and then you call int() on each of them. What sort of numbers will you get? Then look at what chr() does when given those sorts of numbers. BTW, it may be helpful to look at the repr of the final string, rather than simply printing it out. (It also may be unhelpful. If so, don't worry about it.) Have fun! ChrisA From martin.schoon at gmail.com Sat Jan 9 17:51:09 2021 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 9 Jan 2021 22:51:09 GMT Subject: dayofyear is not great when going into a new year References: Message-ID: Den 2021-01-09 skrev Michael F. Stemper : > > A week is like a piece of string. It has two ends. > The control line of the main sheet traveler on my boat is spliced into an endless loop. http://hem.bredband.net/b262106/pages/controls/index.html I am glad work weeks are not like that :-) /Martin From greg.ewing at canterbury.ac.nz Sun Jan 10 05:09:14 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 10 Jan 2021 23:09:14 +1300 Subject: binascii.b2a vs ord() In-Reply-To: References: Message-ID: On 10/01/21 4:29 pm, Bischoop wrote: > So what's that binascii The binascii module contains implementations of various ways of encoding *binary* data as ascii text. The one you're using there is a format called "uuencode"; it was frequently used in the days before the WWW when people often sent arbitrary files to each other by email. There's another one called "base64" which is often used behind the scenes nowadays when you attach a file to an email message. If you're trying to convert between unicode strings (all text strings are unicode in Python 3) and ascii byte strings, the binascii module is NOT what you want. Instead, you should be using the encode and decode methods of the string objects themselves: Python 3.8.2 (default, Mar 23 2020, 11:36:18) [Clang 8.1.0 (clang-802.0.42)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> s = 'Hello World' >>> s 'Hello World' >>> b = s.encode('ascii') >>> b b'Hello World' >>> s2 = b.decode('ascii') >>> s2 'Hello World' -- Greg From Bischoop at vimart.net Sun Jan 10 10:39:56 2021 From: Bischoop at vimart.net (Bischoop) Date: Sun, 10 Jan 2021 15:39:56 -0000 (UTC) Subject: primitive password cracker References: Message-ID: On 2021-01-08, Stefan Ram wrote: > Bischoop writes: >>What I want to learn is if I need get for example four combinations, so >>how to get in a loop first letter 'a',then another step'a' and again 'a' >>and 'a', to have 'aaaa' later on'abaa' etc. > > I can only guess what you want, maybe something like > > word = [] > p = 0 > > def inc_at( position ): > word[ position ]= chr( ord( word[ position ])+ 1 ) > > while True: > if len( word )< p + 1: > word =[ "a" ]+ word > print( "".join( word )) > p = 0 > o = len( word )- 1 - p > inc_at( o ) > while p < len( word ) and word[ o ]== '{': > word[ o ]= "a" > p += 1 > o -= 1 > if p < len( word ): inc_at( o ) > > ? > > Yes, it must generate 4 characters long all combination of alphabet, equivalent to: s = list(''.join(seq) for seq initertools.product(string.ascii_lowercase, repeat=4)). I must say that's quite coding you've done. -- Thanks From redhog.org at gmail.com Sun Jan 10 13:59:33 2021 From: redhog.org at gmail.com (=?UTF-8?B?RWdpbCBNw7ZsbGVy?=) Date: Sun, 10 Jan 2021 10:59:33 -0800 (PST) Subject: Pieshell: Combination of the expressiveness of shell pipelines and the power of python iterators Message-ID: Hi! I've written a python package that lets you combine python code and shell pipelines: Pieshell is a Python shell environment that combines the expressiveness of shell pipelines with the prower of python iterators. It can be used in two major ways: As an interactive shell replacing e.g. bash As an ordinary python module replacing e.g. subprocess.Popen >>> list(ls("-a") | grep("-e", ".py")) ["foo.py", "bar.py"] Shell pipelines, like the one above, are ordinary Python iterator objects. Git repo: https://github.com/redhog/pieshell Installation: pip install pieshell Start the interactive shell: pieshell Hope you found this interesting, RedHog From Bischoop at vimart.net Sun Jan 10 09:16:26 2021 From: Bischoop at vimart.net (Bischoop) Date: Sun, 10 Jan 2021 14:16:26 -0000 (UTC) Subject: binascii.b2a vs ord() References: Message-ID: On 2021-01-10, Chris Angelico wrote: > > Trace it through, step by step. You have a series of ASCII values, > represented in binary, and then you call int() on each of them. What > sort of numbers will you get? > I'm kinda lost here about what sort of numbers I get, its class 'int'. > Then look at what chr() does when given those sorts of numbers. > > BTW, it may be helpful to look at the repr of the final string, rather > than simply printing it out. (It also may be unhelpful. If so, don't > worry about it.) > That was quite interesting text = b'This is a string' text2 = 'This is a string' res = ' '.join(format(ord(i), 'b') for i in text2) k= res.split(' ') for i in k: w= k.index(i) k[w]= int(i) s = k[0] print(type(s)) print(f'{s!r}') l = text[0] print(f'{l!r}') # output I've got: 1010100 84 -- Thanks From rosuav at gmail.com Sun Jan 10 15:24:46 2021 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jan 2021 07:24:46 +1100 Subject: binascii.b2a vs ord() In-Reply-To: References: Message-ID: On Mon, Jan 11, 2021 at 7:09 AM Dennis Lee Bieber wrote: > > On Sun, 10 Jan 2021 03:29:37 -0000 (UTC), Bischoop > declaimed the following: > > >I wanted to learn about conversion string to Ascii. > >So I learn about binascii.b2a but because the output wasn't what I > >wanted got deeper and found out about ord(c) and actually that's what > >I'expected. > >So what's that binascii and why I cant convert ascii that I got from ord > >to string by using char, instead I'm getting some strings in weird > >coding. > > > > > >import binascii > >Ttext = b'This is a string' > >text2 = 'This is a string' > > Item: this is a Unicode string. Python Unicode strings are only 1-byte > per character IF all characters are in the 7-bit ASCII range. If you have > any extended characters (which would, say, be one byte in ISO-Latin-1) they > could turn the entire Unicode string into 2-byte per character (and really > expanded sets could be 3 or 4 bytes per character). > Irrelevant - they're not "one byte per character" except in terms of memory usage, which isn't coming up here. When you call ord() on a character, you get the ordinal of that character, and the internal representation doesn't matter. ChrisA From rosuav at gmail.com Sun Jan 10 15:29:57 2021 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 11 Jan 2021 07:29:57 +1100 Subject: binascii.b2a vs ord() In-Reply-To: References: Message-ID: On Mon, Jan 11, 2021 at 7:09 AM Bischoop wrote: > > On 2021-01-10, Chris Angelico wrote: > > > > Trace it through, step by step. You have a series of ASCII values, > > represented in binary, and then you call int() on each of them. What > > sort of numbers will you get? > > > > I'm kinda lost here about what sort of numbers I get, its class 'int'. Yep. Here, let me walk through one of the examples. text2 = 'This is a string' res = ' '.join(format(ord(i), 'b') for i in text2) The first character is 'T', and ord('T') is 84. Formatting that in binary gives '1010100'. c = ' '.join(chr(int(val)) for val in res.split(' ')) You then convert the string '1010100' into an integer. That doesn't give you the integer 84; it gives you the integer 1010100 (a bit over a million). Then you call chr() on that, which gives you the character with the ordinal of 1,010,100 - or in hex, U+F69B4. That's not a well-defined character (it's actually in a private-use area), so it displays as a little box. To undo the conversion from integer to binary, you have to interpret the digits as binary. You can do that with int('1010100', base=2), which will give back the integer 84. Hope that helps! ChrisA From python at mrabarnett.plus.com Sun Jan 10 16:10:20 2021 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 10 Jan 2021 21:10:20 +0000 Subject: binascii.b2a vs ord() In-Reply-To: References: Message-ID: <841f149d-20ee-7937-8d62-37fabf17c704@mrabarnett.plus.com> On 2021-01-10 18:50, Dennis Lee Bieber wrote: > On Sun, 10 Jan 2021 03:29:37 -0000 (UTC), Bischoop > declaimed the following: > >>I wanted to learn about conversion string to Ascii. >>So I learn about binascii.b2a but because the output wasn't what I >>wanted got deeper and found out about ord(c) and actually that's what >>I'expected. >>So what's that binascii and why I cant convert ascii that I got from ord >>to string by using char, instead I'm getting some strings in weird >>coding. >> >> >>import binascii >>Ttext = b'This is a string' >>text2 = 'This is a string' > > Item: this is a Unicode string. Python Unicode strings are only 1-byte > per character IF all characters are in the 7-bit ASCII range. If you have > any extended characters (which would, say, be one byte in ISO-Latin-1) they > could turn the entire Unicode string into 2-byte per character (and really > expanded sets could be 3 or 4 bytes per character). > [snip] Are you confusing the internal representation in CPython 3.3+ with UTF-8? In CPython 3.3+, Unicode strings are stored as 1 byte per codepoint if all of the codepoints are U+0000..U+00FF, else as 2 bytes per codepoint if all are U+010000..U+10FFFF, else as 4 bytes per codepoint. But that's an implementation detail. From george at fischhof.hu Mon Jan 11 06:34:26 2021 From: george at fischhof.hu (George Fischhof) Date: Mon, 11 Jan 2021 12:34:26 +0100 Subject: [Python-authors] Query In-Reply-To: References: Message-ID: Eduardo Em?n Mu?oz ezt ?rta (id?pont: 2021. jan. 8., P, 17:23): > Dear Srs, > > I apologize if this is not the right place to ask this question, I am > Biologist teaching Python language (in spanish) focused in Molecular > Biology. > > People interested often ask me if my classes/course has a valid > certification and I have to say no, so my question is : > > What can I do for provide a valid diploma with the Python logo to my > students? I mean, how I would be allowed to give a valid > Python logo on my students diploma? I have tried to contact local > institutions like Biology's college, Education Ministry , etc but no > success at all. > > Many thanks for your time reading this email, sorry for my poor english > and thanks in advance. > > > _______________________________________________ > Python-authors mailing list > Python-authors at python.org > https://mail.python.org/mailman/listinfo/python-authors Hi, the good forum for similar questions is python-list at python.org mail list - I think ;-) Right _now_ Microsoft created a Python exam, I do not know how much is that appreciated, or accepted, but there is. As I know this is the only one somewhat standardised exam now. Of course there are several institutes holding Python course and exam BR, George From barpasc at yahoo.com Mon Jan 11 06:46:56 2021 From: barpasc at yahoo.com (pascal z) Date: Mon, 11 Jan 2021 03:46:56 -0800 (PST) Subject: learning python building 2nd app, need advices In-Reply-To: References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> Message-ID: <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> tab to space on linux is not something easy to do, I had to launch windows and use notepad++. Anyway, indentation should all be converted to spaces below #!/usr/bin/env python3 # -*- coding: utf-8 -*- import locale import os import csv from tkinter import messagebox as msg try: from tkinter import * import ttk except: import tkinter as tk #GUI package from tkinter import ttk def fx_BasicListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv # tree.delete(*tree.get_children()) fx_browseFoldersZ(1) return def fx_AdvancedListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # fx_browseFoldersZ(2,"txt") # tree.destroy() #tree.delete(*tree.get_children()) fx_browseFoldersZ(2) return def fx_browseFoldersZ(argy): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv tree.delete(*tree.get_children()) fx_browseFolders(argy,"txt") ############################################################################### ############################################################################### ############################################################################### def fx_writeCSV(*arr): csv_file_title = 'csv_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w', newline ='\n') as f: write = csv.writer(f, doublequote=True, delimiter=';') for row in arr: write.writerows(row) def fx_writeCSV_str(txt_str): csv_file_title = 'csvtxt_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w') as f: f.write(txt_str) # fx_LoadCSV(CSV_FILE) with open(CSV_FILE, 'r') as f: reader = csv.DictReader(f, delimiter=';') for row in reader: col1 = row['Path'] col2 = row['Folder-file'] col3 = row['Size in Byte'] col4 = row['Size in Kb'] col5 = row['Size in Mb'] col6 = row['Size in Gb'] col7 = row['type'] tree.insert('', 'end', values=(col1, col2, col3, col4, col5, col6,col7)) return ############################################################################### ############################################################################### def fx_chkPath(xzPath): isxFile = os.path.isfile(xzPath) isxDir = os.path.isdir(xzPath) print("DOSSIER OUI????",isxDir) if isxDir: return elif not isxDir: msg.showwarning("Folder path", "WD Path entered not found") return ############################################################################### ############################################################################### ############################################################################### def fx_browseFolders(argz, tycsv): tree.delete(*tree.get_children()) # /// /// /// csv_txt = "" csv_contents = "" counterPath = 0 size = 0 f_size = 0 f_vscale = 0 # /// /// /// # path WD Lpath = vtxt_path.get() print('%s' % Lpath) # include files vvchkboxF = vchkboxF.get() # print("include files:::", vchkboxF.get()) # include modification date print(vchkboxD.get()) # include creation date print(vchkboxC.get()) # scale f_vscale = int(var_scale.get()) print(f_vscale) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] # isFile = os.path.isfile(Lpath) # print("fichier?",isFile) fx_chkPath(Lpath) counterPath = Lpath.count(os.path.sep) csv_contents = "Path;Folder-file;Size in Byte;Size in Kb;Size in Mb;Size in Gb;type\n" csv_txt = csv_contents # csv_contents # 1-FOLDER PATH # 2-FILENAME # 3-FOLDER PATH FULL # 4-Size in Byte # 5-Size in Kb # 6-Size in Mb # 7-Size in Gb # 8-type\n ### BASIC LISTING ######### if argz == 1: print("basic listing") file_paths = [] file_paths.append([csv_contents]) for root, dirs, files in os.walk(Lpath, topdown=True): for file in files: if tycsv == "csv": vfolder_path = root + os.sep vfile_name = "'" + file + "'" vfolder_path_full = root + os.sep + file csv_contents = "%s;%s;%s;%s;%s;%s;%s" % (vfolder_path, vfile_name , 'na', 'na', 'na','na', "folder") file_paths.append([csv_contents]) elif tycsv == "txt": vfolder_path = root + os.sep vfile_name = file vfolder_path_full = root + os.sep + file f_size = os.path.getsize(vfolder_path_full) csv_txt += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s" % (vfolder_path, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "file\n") # APPEL FONCTION ECRIT ARRAY TO CSV if tycsv == "csv": fx_writeCSV(file_paths) elif tycsv == "txt": # APPEL FONCTION ECRIT STR TO CSV fx_writeCSV_str(csv_txt) print("job basic listing ok") ### ADVANCED LISTING ######## elif argz == 2: print("advanced listing") if vvchkboxF == 0: # *** FOLDERS ONLY *** for root, dirs, files in os.walk(Lpath, topdown=False): ### calcul taille dossier f_size = 0 for x, y, z in os.walk(root): for i in z: ftmp_che = x + os.sep + i f_size += os.path.getsize(ftmp_che) ### ecriture taille dossier counter = root.count(os.path.sep) - counterPath vfile_name = root vfile_name = vfile_name + os.path.sep vfile_name = os.path.split(os.path.dirname(vfile_name))[1] vfile_name += os.path.sep if counter <= f_vscale: csv_txt += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s" % (root, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "folder\n") fx_writeCSV_str(csv_txt) print("job adv listing folders ok") elif vvchkboxF == 1: # *** FOLDERS AND FILES ONLY *** for root, dirs, files in os.walk(Lpath, topdown=False): ### calcul taille dossier size = 0 for x, y, z in os.walk(root): for i in z: ftmp_che = x + os.sep + i f_size += os.path.getsize(ftmp_che) ### ecriture taille dossier counter = root.count(os.path.sep) - counterPath vfile_name = root vfile_name = vfile_name + os.path.sep vfile_name = os.path.split(os.path.dirname(vfile_name))[1] vfile_name += os.path.sep if counter <= f_vscale: csv_contents += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s\n" % (root, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "folder") ### calcul +ecriture taille fichier for f in os.listdir(Lpath): path = os.path.join(Lpath, f) if os.path.isfile(path): f_size = 0 f_size = os.path.getsize(path) csv_contents += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s\n" % (path, f, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "file") fx_writeCSV_str(csv_contents) print("job adv listing files ok") return ############################################################################### ############################################################################### ############################################################################### #####################################GUI####################################### ############################################################################### ############################################################################### ############################################################################### locale.setlocale(locale.LC_ALL, "") ## MAIN WINDOW root = Tk() width = int(root.winfo_screenwidth()/1.3) height = int(root.winfo_screenheight()/1.29) positionRight = int(width/7) positionDown = int(height/8) root.geometry('%sx%s+%s+%s' % (width, height, positionRight, positionDown)) root.title("Folders and files tool") ### MAKE TABS tabCtrl = ttk.Notebook(root) tab1 = ttk.Frame(tabCtrl) tab2 = ttk.Frame(tabCtrl) tab3 = ttk.Frame(tabCtrl) tab4 = ttk.Frame(tabCtrl) tabCtrl.add(tab1, text =' Folders mgmt ') tabCtrl.add(tab2, text =' Renamer ') tabCtrl.add(tab3, text =' Something3 ') tabCtrl.add(tab4, text =' More infos ') tabCtrl.pack(expand = 1, fill ="both") ### Display Tabs global vtxt_path global var_scale global vchkboxF global vchkboxD global vchkboxC global vcsv_path #######################///...///...///...///...///####################### # TAB 1 # #######################///...///...///...///...///####################### ### FRAME GLOB frm10 = tk.Frame(tab1, bg="gray5") frm10.pack(expand = 1, fill ="both") # frm10.pack( side = LEFT, expand = True, fill = BOTH) ####################### ### FRAME 11 TOP LABEL frm11 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm11.place(width=475, height=140, x=20, y=20) # Top label title tk.Label(frm11,text ="Drive or folders", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL PATH entry box tk.Label(frm11, text="Enter Path (WD)", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER new_text = "/media/ananas/HDD_500B/TEST_APP3/" ### PATH ENTRY BOX vtxt_path=tk.StringVar(root,value=new_text) # Value saved here txt_path = tk.Entry(frm11,width=43, textvariable=vtxt_path, fg='green').place(width=320, height=30, x=140, y=50) # vtxt_path.set(new_text) # TEST FOLDER zzz ### LABEL PATH example tk.Label(frm11, text=r"Ex.: path for Windows: C:\Users\user\Documents\Dossier test", font=("Helvetica", 8, "italic"), fg='gray80', bg='gray5').place(width=320, height=30, x=130, y=80) tk.Label(frm11, text=r" path Linux: /home/user/Documents/Test dossier/", font=("Verdana", 8, "italic"), fg='gray80', bg='gray5').place(width=300, height=30, x=123, y=100) ### frame 11 ########################### ########################### ### FRAME 12 TOP BUTTON SCAN ALL frm12 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm12.place(width=150, height=40, x=494, y=20) ### button btn_scanALL = tk.Button(frm12, text="Basic listing", bg='lightblue4', font=("Verdana", 10,"normal")) btn_scanALL.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_scanALL['command'] = fx_BasicListing ### frame 12 ########################### ########################### ### FRAME 13 TOP BTN SCAN ADV + SLIDER frm13 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm13.place(width=540, height=100, x=494, y=60) btn_scanADV = tk.Button(frm13, text="Advanced listing", bg='ivory4', font=("Verdana", 10,"normal")) btn_scanADV.place(width=150, height=40, x=0, y=0) ### BUTTON BROWSE entry fx ADVANCED LISTING btn_scanADV['command'] = fx_AdvancedListing ### slider var_scale = tk.DoubleVar() tk.Label(frm13, text="Subfolders level", font=("Verdana", 8, "italic"), fg='gray80', bg='gray5').place(width=150, height=10, x=0, y=46) wslide = tk.Scale(frm13,bg='ivory4', fg='grey5', from_=0, to=10, variable = var_scale, orient=tk.HORIZONTAL) wslide.place(width=150, height=40, x=0, y=58) wslide.set(3) ### frame 13 ########################### ########################### ### FRAME 14 TOP BTN SCAN ADV + CHECKBUTTONS frm14 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm14.place(width=190, height=100, x=645, y=60) vchkboxF=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include files", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxF, offvalue=0, onvalue=1) chkbox.place(x=0, y=5) vchkboxD=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include modification date", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxD, offvalue=0, onvalue=1) chkbox.place(x=0, y=25) vchkboxC=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include creation date", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxC, offvalue=0, onvalue=1) chkbox.place(x=0, y=45) ### frame 14 ########################### ########################### ### FRAME 15 TREEVIEW frm15 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm15.place(width=1000, height=350, x=20, y=175) container = ttk.Frame(frm15) # container.place(width=1015, height=350, x=20, y=175) container.pack() style = ttk.Style() style.theme_use("clam") style.configure("Treeview", background="lemonchiffon3",font=('Tahoma', 9), fieldbackground="lemonchiffon3", foreground="grey10") style.configure("Treeview.Heading", font=('Tahoma', 10),foreground='orange4') tree = ttk.Treeview(frm15, columns=('1', '2', '3', '4', '5', '6', '7')) vsb = ttk.Scrollbar(orient="vertical", command=tree.yview) hsb = ttk.Scrollbar(orient="horizontal", command=tree.xview) vsb.place(x=1021, y=231,width=15, height=307,) hsb.place(x=22, y=540,width=1000, height=15,) tree.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set) container.grid_columnconfigure(0, weight=1) container.grid_rowconfigure(0, weight=1) tree.column('#1', width=180, stretch=YES) tree.column('#2', width=240, stretch=YES) tree.column('#3', width=10, stretch=YES) tree.column('#4', width=5, stretch=YES) tree.column('#5', width=5, stretch=YES) tree.column('#6', width=5, stretch=YES) tree.column('#7', width=25, stretch=YES) tree.heading('#1', text='Path') tree.heading('#2', text='Folder-file') tree.heading('#3', text='Byte') tree.heading('#4', text='Kb') tree.heading('#5', text='Mb') tree.heading('#6', text='Gb') tree.heading('#7', text='Object type') tree['show'] = 'headings' tree.pack(fill=BOTH,expand=1) ### frame 15 ########################### ########################### ### FRAME 16 CSV DIAL frm16 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm16.place(width=480, height=30, x=20, y=530) # csv lbl tk.Label(frm16,text ="Default folder for csv file (change...)", font=("Verdana", 8, "normal"), fg='gray80', bg='gray5').place(x=10, y=5) # csv folder entry box vcsv_path=tk.StringVar() # Value saved here txt_csv = tk.Entry(frm16,width=43, textvariable=vcsv_path, fg='green').place(width=265, x=210, y=3) full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep vcsv_path.set(new_text) ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### def fx_FileRen(): Lpath = vtxt_path3.get() print('%s' % Lpath) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] print('%s' % Lpath) msg.showwarning("File names", "File names changed") # with open(csv_file_title) as csvfile: # csvreader = csv.reader(csvfile, delimiter=';', quotechar='"') # for row in csvreader: # name = row[0] # new = row[1] # if os.path.exists(name): # os.rename(name, new) # else: # print(name + " does not exist") ############################################################################### def fx_FoldRen(): csv_file_title = 'csv_1_baselisting.csv' print('%s' % csv_file_title) # with open(CSV_FILE,'w', newline ='\n') as f: # write = csv.writer(f, doublequote=True, delimiter=';') # for row in arr: # write.writerows(row) msg.showwarning("Folder names", "Folders names changed") ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### #######################///...///...///...///...///####################### # TAB 2 # #######################///...///...///...///...///####################### ### FRAME GLOB frm20 = tk.Frame(tab2, bg="gray5") frm20.pack(expand = 1, fill ="both") # frm10.pack( side = LEFT, expand = True, fill = BOTH) ####################### ### FRAME 21a FOLDER PATH frm21a = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm21a.place(width=950, height=100, x=20, y=45) # Top label title tk.Label(frm21a,text ="Folder path to list folders files to csv", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) vtxt_path1a=tk.StringVar(root, value=new_text) # Value saved here txt_path1a = tk.Entry(frm21a,width=43, textvariable=vtxt_path1a, fg='blue').place(width=620, height=30, x=140, y=50) ####################### ### FRAME 21 LABEL FILES RENAME frm21 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm21.place(width=775, height=100, x=20, y=185) # Top label title tk.Label(frm21,text ="Rename files only from csv file below", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL FILES RENAME entry box tk.Label(frm21, text="CSV file path", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep + "csvtxt_1_filenamelisting.csv" # vtxt_path2.set(new_text) ### PATH ENTRY BOX vtxt_path2=tk.StringVar(root, value=new_text) # Value saved here txt_path2 = tk.Entry(frm21,width=43, textvariable=vtxt_path2, fg='blue').place(width=620, height=30, x=140, y=50) # TEST FOLDER zzz ########################### ### FRAME 22 TOP BUTTON FILE RENAME frm22 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm22.place(width=150, height=40, x=820, y=220) ### button btn_FileRen = tk.Button(frm22, text="Files rename", bg='lightblue4', font=("Verdana", 10,"normal")) btn_FileRen.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_FileRen['command'] = fx_FileRen ####################### ### FRAME 23 LABEL FOLDERS RENAME frm23 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm23.place(width=775, height=100, x=20, y=320) # Top label title tk.Label(frm23,text ="Rename folders only from csv file below", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL PATH entry box tk.Label(frm23, text="CSV file path", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep + "csvtxt_1_foldernamelisting.csv" # vtxt_path2.set(new_text) ### PATH ENTRY BOX vtxt_path3=tk.StringVar(root, value=new_text) # Value saved here txt_path3 = tk.Entry(frm23,width=43, textvariable=vtxt_path3, fg='brown').place(width=620, height=30, x=140, y=50) # TEST FOLDER zzz ########################### ### FRAME 24 BUTTON FOLDERS RENAME frm24 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm24.place(width=150, height=40, x=820, y=345) ### button btn_FoldRen = tk.Button(frm24, text="Folders rename", bg='brown', font=("Verdana", 10,"normal")) btn_FoldRen.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_FoldRen['command'] = fx_FoldRen #######################///...///...///...///...///####################### # TAB 3 # #######################///...///...///...///...///####################### #######################///...///...///...///...///####################### # zZZZz # #######################///...///...///...///...///####################### if __name__ == '__main__': root.mainloop() From barpasc at yahoo.com Mon Jan 11 06:53:23 2021 From: barpasc at yahoo.com (pascal z) Date: Mon, 11 Jan 2021 03:53:23 -0800 (PST) Subject: learning python building 2nd app, need advices In-Reply-To: References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> Message-ID: <9d70c7a0-a72c-4476-94cc-d69ac154acd1n@googlegroups.com> tab to space on linux is not something easy to do, I had to launch windows and use notepad++. Anyway, indentation should all be converted to spaces below #!/usr/bin/env python3 # -*- coding: utf-8 -*- import locale import os import csv from tkinter import messagebox as msg try: from tkinter import * import ttk except: import tkinter as tk #GUI package from tkinter import ttk def fx_BasicListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv # tree.delete(*tree.get_children()) fx_browseFoldersZ(1) return def fx_AdvancedListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # fx_browseFoldersZ(2,"txt") # tree.destroy() #tree.delete(*tree.get_children()) fx_browseFoldersZ(2) return def fx_browseFoldersZ(argy): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv tree.delete(*tree.get_children()) fx_browseFolders(argy,"txt") ############################################################################### ############################################################################### ############################################################################### def fx_writeCSV(*arr): csv_file_title = 'csv_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w', newline ='\n') as f: write = csv.writer(f, doublequote=True, delimiter=';') for row in arr: write.writerows(row) def fx_writeCSV_str(txt_str): csv_file_title = 'csvtxt_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w') as f: f.write(txt_str) # fx_LoadCSV(CSV_FILE) with open(CSV_FILE, 'r') as f: reader = csv.DictReader(f, delimiter=';') for row in reader: col1 = row['Path'] col2 = row['Folder-file'] col3 = row['Size in Byte'] col4 = row['Size in Kb'] col5 = row['Size in Mb'] col6 = row['Size in Gb'] col7 = row['type'] tree.insert('', 'end', values=(col1, col2, col3, col4, col5, col6,col7)) return ############################################################################### ############################################################################### def fx_chkPath(xzPath): isxFile = os.path.isfile(xzPath) isxDir = os.path.isdir(xzPath) print("DOSSIER OUI????",isxDir) if isxDir: return elif not isxDir: msg.showwarning("Folder path", "WD Path entered not found") return ############################################################################### ############################################################################### ############################################################################### def fx_browseFolders(argz, tycsv): tree.delete(*tree.get_children()) # /// /// /// csv_txt = "" csv_contents = "" counterPath = 0 size = 0 f_size = 0 f_vscale = 0 # /// /// /// # path WD Lpath = vtxt_path.get() print('%s' % Lpath) # include files vvchkboxF = vchkboxF.get() # print("include files:::", vchkboxF.get()) # include modification date print(vchkboxD.get()) # include creation date print(vchkboxC.get()) # scale f_vscale = int(var_scale.get()) print(f_vscale) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] # isFile = os.path.isfile(Lpath) # print("fichier?",isFile) fx_chkPath(Lpath) counterPath = Lpath.count(os.path.sep) csv_contents = "Path;Folder-file;Size in Byte;Size in Kb;Size in Mb;Size in Gb;type\n" csv_txt = csv_contents # csv_contents # 1-FOLDER PATH # 2-FILENAME # 3-FOLDER PATH FULL # 4-Size in Byte # 5-Size in Kb # 6-Size in Mb # 7-Size in Gb # 8-type\n ### BASIC LISTING ######### if argz == 1: print("basic listing") file_paths = [] file_paths.append([csv_contents]) for root, dirs, files in os.walk(Lpath, topdown=True): for file in files: if tycsv == "csv": vfolder_path = root + os.sep vfile_name = "'" + file + "'" vfolder_path_full = root + os.sep + file csv_contents = "%s;%s;%s;%s;%s;%s;%s" % (vfolder_path, vfile_name , 'na', 'na', 'na','na', "folder") file_paths.append([csv_contents]) elif tycsv == "txt": vfolder_path = root + os.sep vfile_name = file vfolder_path_full = root + os.sep + file f_size = os.path.getsize(vfolder_path_full) csv_txt += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s" % (vfolder_path, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "file\n") # APPEL FONCTION ECRIT ARRAY TO CSV if tycsv == "csv": fx_writeCSV(file_paths) elif tycsv == "txt": # APPEL FONCTION ECRIT STR TO CSV fx_writeCSV_str(csv_txt) print("job basic listing ok") ### ADVANCED LISTING ######## elif argz == 2: print("advanced listing") if vvchkboxF == 0: # *** FOLDERS ONLY *** for root, dirs, files in os.walk(Lpath, topdown=False): ### calcul taille dossier f_size = 0 for x, y, z in os.walk(root): for i in z: ftmp_che = x + os.sep + i f_size += os.path.getsize(ftmp_che) ### ecriture taille dossier counter = root.count(os.path.sep) - counterPath vfile_name = root vfile_name = vfile_name + os.path.sep vfile_name = os.path.split(os.path.dirname(vfile_name))[1] vfile_name += os.path.sep if counter <= f_vscale: csv_txt += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s" % (root, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "folder\n") fx_writeCSV_str(csv_txt) print("job adv listing folders ok") elif vvchkboxF == 1: # *** FOLDERS AND FILES ONLY *** for root, dirs, files in os.walk(Lpath, topdown=False): ### calcul taille dossier size = 0 for x, y, z in os.walk(root): for i in z: ftmp_che = x + os.sep + i f_size += os.path.getsize(ftmp_che) ### ecriture taille dossier counter = root.count(os.path.sep) - counterPath vfile_name = root vfile_name = vfile_name + os.path.sep vfile_name = os.path.split(os.path.dirname(vfile_name))[1] vfile_name += os.path.sep if counter <= f_vscale: csv_contents += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s\n" % (root, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "folder") ### calcul +ecriture taille fichier for f in os.listdir(Lpath): path = os.path.join(Lpath, f) if os.path.isfile(path): f_size = 0 f_size = os.path.getsize(path) csv_contents += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s\n" % (path, f, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "file") fx_writeCSV_str(csv_contents) print("job adv listing files ok") return ############################################################################### ############################################################################### ############################################################################### #####################################GUI####################################### ############################################################################### ############################################################################### ############################################################################### locale.setlocale(locale.LC_ALL, "") ## MAIN WINDOW root = Tk() width = int(root.winfo_screenwidth()/1.3) height = int(root.winfo_screenheight()/1.29) positionRight = int(width/7) positionDown = int(height/8) root.geometry('%sx%s+%s+%s' % (width, height, positionRight, positionDown)) root.title("Folders and files tool") ### MAKE TABS tabCtrl = ttk.Notebook(root) tab1 = ttk.Frame(tabCtrl) tab2 = ttk.Frame(tabCtrl) tab3 = ttk.Frame(tabCtrl) tab4 = ttk.Frame(tabCtrl) tabCtrl.add(tab1, text =' Folders mgmt ') tabCtrl.add(tab2, text =' Renamer ') tabCtrl.add(tab3, text =' Something3 ') tabCtrl.add(tab4, text =' More infos ') tabCtrl.pack(expand = 1, fill ="both") ### Display Tabs global vtxt_path global var_scale global vchkboxF global vchkboxD global vchkboxC global vcsv_path #######################///...///...///...///...///####################### # TAB 1 # #######################///...///...///...///...///####################### ### FRAME GLOB frm10 = tk.Frame(tab1, bg="gray5") frm10.pack(expand = 1, fill ="both") # frm10.pack( side = LEFT, expand = True, fill = BOTH) ####################### ### FRAME 11 TOP LABEL frm11 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm11.place(width=475, height=140, x=20, y=20) # Top label title tk.Label(frm11,text ="Drive or folders", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL PATH entry box tk.Label(frm11, text="Enter Path (WD)", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER new_text = "/media/ananas/HDD_500B/TEST_APP3/" ### PATH ENTRY BOX vtxt_path=tk.StringVar(root,value=new_text) # Value saved here txt_path = tk.Entry(frm11,width=43, textvariable=vtxt_path, fg='green').place(width=320, height=30, x=140, y=50) # vtxt_path.set(new_text) # TEST FOLDER zzz ### LABEL PATH example tk.Label(frm11, text=r"Ex.: path for Windows: C:\Users\user\Documents\Dossier test", font=("Helvetica", 8, "italic"), fg='gray80', bg='gray5').place(width=320, height=30, x=130, y=80) tk.Label(frm11, text=r" path Linux: /home/user/Documents/Test dossier/", font=("Verdana", 8, "italic"), fg='gray80', bg='gray5').place(width=300, height=30, x=123, y=100) ### frame 11 ########################### ########################### ### FRAME 12 TOP BUTTON SCAN ALL frm12 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm12.place(width=150, height=40, x=494, y=20) ### button btn_scanALL = tk.Button(frm12, text="Basic listing", bg='lightblue4', font=("Verdana", 10,"normal")) btn_scanALL.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_scanALL['command'] = fx_BasicListing ### frame 12 ########################### ########################### ### FRAME 13 TOP BTN SCAN ADV + SLIDER frm13 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm13.place(width=540, height=100, x=494, y=60) btn_scanADV = tk.Button(frm13, text="Advanced listing", bg='ivory4', font=("Verdana", 10,"normal")) btn_scanADV.place(width=150, height=40, x=0, y=0) ### BUTTON BROWSE entry fx ADVANCED LISTING btn_scanADV['command'] = fx_AdvancedListing ### slider var_scale = tk.DoubleVar() tk.Label(frm13, text="Subfolders level", font=("Verdana", 8, "italic"), fg='gray80', bg='gray5').place(width=150, height=10, x=0, y=46) wslide = tk.Scale(frm13,bg='ivory4', fg='grey5', from_=0, to=10, variable = var_scale, orient=tk.HORIZONTAL) wslide.place(width=150, height=40, x=0, y=58) wslide.set(3) ### frame 13 ########################### ########################### ### FRAME 14 TOP BTN SCAN ADV + CHECKBUTTONS frm14 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm14.place(width=190, height=100, x=645, y=60) vchkboxF=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include files", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxF, offvalue=0, onvalue=1) chkbox.place(x=0, y=5) vchkboxD=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include modification date", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxD, offvalue=0, onvalue=1) chkbox.place(x=0, y=25) vchkboxC=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include creation date", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxC, offvalue=0, onvalue=1) chkbox.place(x=0, y=45) ### frame 14 ########################### ########################### ### FRAME 15 TREEVIEW frm15 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm15.place(width=1000, height=350, x=20, y=175) container = ttk.Frame(frm15) # container.place(width=1015, height=350, x=20, y=175) container.pack() style = ttk.Style() style.theme_use("clam") style.configure("Treeview", background="lemonchiffon3",font=('Tahoma', 9), fieldbackground="lemonchiffon3", foreground="grey10") style.configure("Treeview.Heading", font=('Tahoma', 10),foreground='orange4') tree = ttk.Treeview(frm15, columns=('1', '2', '3', '4', '5', '6', '7')) vsb = ttk.Scrollbar(orient="vertical", command=tree.yview) hsb = ttk.Scrollbar(orient="horizontal", command=tree.xview) vsb.place(x=1021, y=231,width=15, height=307,) hsb.place(x=22, y=540,width=1000, height=15,) tree.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set) container.grid_columnconfigure(0, weight=1) container.grid_rowconfigure(0, weight=1) tree.column('#1', width=180, stretch=YES) tree.column('#2', width=240, stretch=YES) tree.column('#3', width=10, stretch=YES) tree.column('#4', width=5, stretch=YES) tree.column('#5', width=5, stretch=YES) tree.column('#6', width=5, stretch=YES) tree.column('#7', width=25, stretch=YES) tree.heading('#1', text='Path') tree.heading('#2', text='Folder-file') tree.heading('#3', text='Byte') tree.heading('#4', text='Kb') tree.heading('#5', text='Mb') tree.heading('#6', text='Gb') tree.heading('#7', text='Object type') tree['show'] = 'headings' tree.pack(fill=BOTH,expand=1) ### frame 15 ########################### ########################### ### FRAME 16 CSV DIAL frm16 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm16.place(width=480, height=30, x=20, y=530) # csv lbl tk.Label(frm16,text ="Default folder for csv file (change...)", font=("Verdana", 8, "normal"), fg='gray80', bg='gray5').place(x=10, y=5) # csv folder entry box vcsv_path=tk.StringVar() # Value saved here txt_csv = tk.Entry(frm16,width=43, textvariable=vcsv_path, fg='green').place(width=265, x=210, y=3) full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep vcsv_path.set(new_text) ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### def fx_FileRen(): Lpath = vtxt_path3.get() print('%s' % Lpath) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] print('%s' % Lpath) msg.showwarning("File names", "File names changed") # with open(csv_file_title) as csvfile: # csvreader = csv.reader(csvfile, delimiter=';', quotechar='"') # for row in csvreader: # name = row[0] # new = row[1] # if os.path.exists(name): # os.rename(name, new) # else: # print(name + " does not exist") ############################################################################### def fx_FoldRen(): csv_file_title = 'csv_1_baselisting.csv' print('%s' % csv_file_title) # with open(CSV_FILE,'w', newline ='\n') as f: # write = csv.writer(f, doublequote=True, delimiter=';') # for row in arr: # write.writerows(row) msg.showwarning("Folder names", "Folders names changed") ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### #######################///...///...///...///...///####################### # TAB 2 # #######################///...///...///...///...///####################### ### FRAME GLOB frm20 = tk.Frame(tab2, bg="gray5") frm20.pack(expand = 1, fill ="both") # frm10.pack( side = LEFT, expand = True, fill = BOTH) ####################### ### FRAME 21a FOLDER PATH frm21a = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm21a.place(width=950, height=100, x=20, y=45) # Top label title tk.Label(frm21a,text ="Folder path to list folders files to csv", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) vtxt_path1a=tk.StringVar(root, value=new_text) # Value saved here txt_path1a = tk.Entry(frm21a,width=43, textvariable=vtxt_path1a, fg='blue').place(width=620, height=30, x=140, y=50) ####################### ### FRAME 21 LABEL FILES RENAME frm21 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm21.place(width=775, height=100, x=20, y=185) # Top label title tk.Label(frm21,text ="Rename files only from csv file below", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL FILES RENAME entry box tk.Label(frm21, text="CSV file path", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep + "csvtxt_1_filenamelisting.csv" # vtxt_path2.set(new_text) ### PATH ENTRY BOX vtxt_path2=tk.StringVar(root, value=new_text) # Value saved here txt_path2 = tk.Entry(frm21,width=43, textvariable=vtxt_path2, fg='blue').place(width=620, height=30, x=140, y=50) # TEST FOLDER zzz ########################### ### FRAME 22 TOP BUTTON FILE RENAME frm22 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm22.place(width=150, height=40, x=820, y=220) ### button btn_FileRen = tk.Button(frm22, text="Files rename", bg='lightblue4', font=("Verdana", 10,"normal")) btn_FileRen.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_FileRen['command'] = fx_FileRen ####################### ### FRAME 23 LABEL FOLDERS RENAME frm23 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm23.place(width=775, height=100, x=20, y=320) # Top label title tk.Label(frm23,text ="Rename folders only from csv file below", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL PATH entry box tk.Label(frm23, text="CSV file path", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep + "csvtxt_1_foldernamelisting.csv" # vtxt_path2.set(new_text) ### PATH ENTRY BOX vtxt_path3=tk.StringVar(root, value=new_text) # Value saved here txt_path3 = tk.Entry(frm23,width=43, textvariable=vtxt_path3, fg='brown').place(width=620, height=30, x=140, y=50) # TEST FOLDER zzz ########################### ### FRAME 24 BUTTON FOLDERS RENAME frm24 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm24.place(width=150, height=40, x=820, y=345) ### button btn_FoldRen = tk.Button(frm24, text="Folders rename", bg='brown', font=("Verdana", 10,"normal")) btn_FoldRen.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_FoldRen['command'] = fx_FoldRen #######################///...///...///...///...///####################### # TAB 3 # #######################///...///...///...///...///####################### #######################///...///...///...///...///####################### # zZZZz # #######################///...///...///...///...///####################### if __name__ == '__main__': root.mainloop() From loris.bennett at fu-berlin.de Mon Jan 11 07:00:10 2021 From: loris.bennett at fu-berlin.de (Loris Bennett) Date: Mon, 11 Jan 2021 13:00:10 +0100 Subject: learning python building 2nd app, need advices References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> Message-ID: <878s8zn0ol.fsf@hornfels.zedat.fu-berlin.de> pascal z writes: > tab to space on linux is not something easy to do I would argue that you are mistaken, although that depends somewhat on your definition of 'easy'. > , I had to launch windows and use notepad++. There is the Linux command 'expand' , which I have never used, but which sounds like it will do what you want: $ expand --help Usage: expand [OPTION]... [FILE]... Convert tabs in each FILE to spaces, writing to standard output. As an Emacs user, personally I would use the command M-x untabify within Emacs. I assume that Vim has something similar. Cheers, Loris -- This signature is currently under construction. From barpasc at yahoo.com Mon Jan 11 07:05:00 2021 From: barpasc at yahoo.com (pascal z) Date: Mon, 11 Jan 2021 04:05:00 -0800 (PST) Subject: learning python building 2nd app, need advices In-Reply-To: References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> Message-ID: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import locale import os import csv from tkinter import messagebox as msg try: from tkinter import * import ttk except: import tkinter as tk #GUI package from tkinter import ttk def fx_BasicListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv # tree.delete(*tree.get_children()) fx_browseFoldersZ(1) return def fx_AdvancedListing(): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # fx_browseFoldersZ(2,"txt") # tree.destroy() #tree.delete(*tree.get_children()) fx_browseFoldersZ(2) return def fx_browseFoldersZ(argy): #argx mode = 1 pour basic listing #argx mode = 2 pour adv listing # "txt" pour type enreg csv txt/csv tree.delete(*tree.get_children()) fx_browseFolders(argy,"txt") ############################################################################### ############################################################################### ############################################################################### def fx_writeCSV(*arr): csv_file_title = 'csv_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w', newline ='\n') as f: write = csv.writer(f, doublequote=True, delimiter=';') for row in arr: write.writerows(row) def fx_writeCSV_str(txt_str): csv_file_title = 'csvtxt_1_baselisting.csv' # csv path entry box CSV_FILE = vcsv_path.get() if not os.path.exists(CSV_FILE): os.makedirs(CSV_FILE) CSV_FILE += csv_file_title print('%s' % CSV_FILE) with open(CSV_FILE,'w') as f: f.write(txt_str) # fx_LoadCSV(CSV_FILE) with open(CSV_FILE, 'r') as f: reader = csv.DictReader(f, delimiter=';') for row in reader: col1 = row['Path'] col2 = row['Folder-file'] col3 = row['Size in Byte'] col4 = row['Size in Kb'] col5 = row['Size in Mb'] col6 = row['Size in Gb'] col7 = row['type'] tree.insert('', 'end', values=(col1, col2, col3, col4, col5, col6,col7)) return ############################################################################### ############################################################################### def fx_chkPath(xzPath): isxFile = os.path.isfile(xzPath) isxDir = os.path.isdir(xzPath) print("DOSSIER OUI????",isxDir) if isxDir: return elif not isxDir: msg.showwarning("Folder path", "WD Path entered not found") return ############################################################################### ############################################################################### ############################################################################### def fx_browseFolders(argz, tycsv): tree.delete(*tree.get_children()) # /// /// /// csv_txt = "" csv_contents = "" counterPath = 0 size = 0 f_size = 0 f_vscale = 0 # /// /// /// # path WD Lpath = vtxt_path.get() print('%s' % Lpath) # include files vvchkboxF = vchkboxF.get() # print("include files:::", vchkboxF.get()) # include modification date print(vchkboxD.get()) # include creation date print(vchkboxC.get()) # scale f_vscale = int(var_scale.get()) print(f_vscale) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] # isFile = os.path.isfile(Lpath) # print("fichier?",isFile) fx_chkPath(Lpath) counterPath = Lpath.count(os.path.sep) csv_contents = "Path;Folder-file;Size in Byte;Size in Kb;Size in Mb;Size in Gb;type\n" csv_txt = csv_contents # csv_contents # 1-FOLDER PATH # 2-FILENAME # 3-FOLDER PATH FULL # 4-Size in Byte # 5-Size in Kb # 6-Size in Mb # 7-Size in Gb # 8-type\n ### BASIC LISTING ######### if argz == 1: print("basic listing") file_paths = [] file_paths.append([csv_contents]) for root, dirs, files in os.walk(Lpath, topdown=True): for file in files: if tycsv == "csv": vfolder_path = root + os.sep vfile_name = "'" + file + "'" vfolder_path_full = root + os.sep + file csv_contents = "%s;%s;%s;%s;%s;%s;%s" % (vfolder_path, vfile_name , 'na', 'na', 'na','na', "folder") file_paths.append([csv_contents]) elif tycsv == "txt": vfolder_path = root + os.sep vfile_name = file vfolder_path_full = root + os.sep + file f_size = os.path.getsize(vfolder_path_full) csv_txt += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s" % (vfolder_path, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "file\n") # APPEL FONCTION ECRIT ARRAY TO CSV if tycsv == "csv": fx_writeCSV(file_paths) elif tycsv == "txt": # APPEL FONCTION ECRIT STR TO CSV fx_writeCSV_str(csv_txt) print("job basic listing ok") ### ADVANCED LISTING ######## elif argz == 2: print("advanced listing") if vvchkboxF == 0: # *** FOLDERS ONLY *** for root, dirs, files in os.walk(Lpath, topdown=False): ### calcul taille dossier f_size = 0 for x, y, z in os.walk(root): for i in z: ftmp_che = x + os.sep + i f_size += os.path.getsize(ftmp_che) ### ecriture taille dossier counter = root.count(os.path.sep) - counterPath vfile_name = root vfile_name = vfile_name + os.path.sep vfile_name = os.path.split(os.path.dirname(vfile_name))[1] vfile_name += os.path.sep if counter <= f_vscale: csv_txt += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s" % (root, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "folder\n") fx_writeCSV_str(csv_txt) print("job adv listing folders ok") elif vvchkboxF == 1: # *** FOLDERS AND FILES ONLY *** for root, dirs, files in os.walk(Lpath, topdown=False): ### calcul taille dossier size = 0 for x, y, z in os.walk(root): for i in z: ftmp_che = x + os.sep + i f_size += os.path.getsize(ftmp_che) ### ecriture taille dossier counter = root.count(os.path.sep) - counterPath vfile_name = root vfile_name = vfile_name + os.path.sep vfile_name = os.path.split(os.path.dirname(vfile_name))[1] vfile_name += os.path.sep if counter <= f_vscale: csv_contents += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s\n" % (root, vfile_name, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "folder") ### calcul +ecriture taille fichier for f in os.listdir(Lpath): path = os.path.join(Lpath, f) if os.path.isfile(path): f_size = 0 f_size = os.path.getsize(path) csv_contents += "%s;%s;%.0f;%.2f;%.2f;%.2f;%s\n" % (path, f, f_size, f_size/1024, f_size/1048576,f_size/1073741824, "file") fx_writeCSV_str(csv_contents) print("job adv listing files ok") return ############################################################################### ############################################################################### ############################################################################### #####################################GUI####################################### ############################################################################### ############################################################################### ############################################################################### locale.setlocale(locale.LC_ALL, "") ## MAIN WINDOW root = Tk() width = int(root.winfo_screenwidth()/1.3) height = int(root.winfo_screenheight()/1.29) positionRight = int(width/7) positionDown = int(height/8) root.geometry('%sx%s+%s+%s' % (width, height, positionRight, positionDown)) root.title("Folders and files tool") ### MAKE TABS tabCtrl = ttk.Notebook(root) tab1 = ttk.Frame(tabCtrl) tab2 = ttk.Frame(tabCtrl) tab3 = ttk.Frame(tabCtrl) tab4 = ttk.Frame(tabCtrl) tabCtrl.add(tab1, text =' Folders mgmt ') tabCtrl.add(tab2, text =' Renamer ') tabCtrl.add(tab3, text =' Something3 ') tabCtrl.add(tab4, text =' More infos ') tabCtrl.pack(expand = 1, fill ="both") ### Display Tabs global vtxt_path global var_scale global vchkboxF global vchkboxD global vchkboxC global vcsv_path #######################///...///...///...///...///####################### # TAB 1 # #######################///...///...///...///...///####################### ### FRAME GLOB frm10 = tk.Frame(tab1, bg="gray5") frm10.pack(expand = 1, fill ="both") # frm10.pack( side = LEFT, expand = True, fill = BOTH) ####################### ### FRAME 11 TOP LABEL frm11 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm11.place(width=475, height=140, x=20, y=20) # Top label title tk.Label(frm11,text ="Drive or folders", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL PATH entry box tk.Label(frm11, text="Enter Path (WD)", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER new_text = "/media/ananas/HDD_500B/TEST_APP3/" ### PATH ENTRY BOX vtxt_path=tk.StringVar(root,value=new_text) # Value saved here txt_path = tk.Entry(frm11,width=43, textvariable=vtxt_path, fg='green').place(width=320, height=30, x=140, y=50) # vtxt_path.set(new_text) # TEST FOLDER zzz ### LABEL PATH example tk.Label(frm11, text=r"Ex.: path for Windows: C:\Users\user\Documents\Dossier test", font=("Helvetica", 8, "italic"), fg='gray80', bg='gray5').place(width=320, height=30, x=130, y=80) tk.Label(frm11, text=r" path Linux: /home/user/Documents/Test dossier/", font=("Verdana", 8, "italic"), fg='gray80', bg='gray5').place(width=300, height=30, x=123, y=100) ### frame 11 ########################### ########################### ### FRAME 12 TOP BUTTON SCAN ALL frm12 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm12.place(width=150, height=40, x=494, y=20) ### button btn_scanALL = tk.Button(frm12, text="Basic listing", bg='lightblue4', font=("Verdana", 10,"normal")) btn_scanALL.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_scanALL['command'] = fx_BasicListing ### frame 12 ########################### ########################### ### FRAME 13 TOP BTN SCAN ADV + SLIDER frm13 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm13.place(width=540, height=100, x=494, y=60) btn_scanADV = tk.Button(frm13, text="Advanced listing", bg='ivory4', font=("Verdana", 10,"normal")) btn_scanADV.place(width=150, height=40, x=0, y=0) ### BUTTON BROWSE entry fx ADVANCED LISTING btn_scanADV['command'] = fx_AdvancedListing ### slider var_scale = tk.DoubleVar() tk.Label(frm13, text="Subfolders level", font=("Verdana", 8, "italic"), fg='gray80', bg='gray5').place(width=150, height=10, x=0, y=46) wslide = tk.Scale(frm13,bg='ivory4', fg='grey5', from_=0, to=10, variable = var_scale, orient=tk.HORIZONTAL) wslide.place(width=150, height=40, x=0, y=58) wslide.set(3) ### frame 13 ########################### ########################### ### FRAME 14 TOP BTN SCAN ADV + CHECKBUTTONS frm14 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm14.place(width=190, height=100, x=645, y=60) vchkboxF=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include files", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxF, offvalue=0, onvalue=1) chkbox.place(x=0, y=5) vchkboxD=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include modification date", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxD, offvalue=0, onvalue=1) chkbox.place(x=0, y=25) vchkboxC=tk.IntVar() chkbox=tk.Checkbutton(frm14, highlightthickness=0,bd=0,text="Include creation date", font=("Verdana", 9, "normal"), fg='gray80', bg='gray5', variable=vchkboxC, offvalue=0, onvalue=1) chkbox.place(x=0, y=45) ### frame 14 ########################### ########################### ### FRAME 15 TREEVIEW frm15 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm15.place(width=1000, height=350, x=20, y=175) container = ttk.Frame(frm15) # container.place(width=1015, height=350, x=20, y=175) container.pack() style = ttk.Style() style.theme_use("clam") style.configure("Treeview", background="lemonchiffon3",font=('Tahoma', 9), fieldbackground="lemonchiffon3", foreground="grey10") style.configure("Treeview.Heading", font=('Tahoma', 10),foreground='orange4') tree = ttk.Treeview(frm15, columns=('1', '2', '3', '4', '5', '6', '7')) vsb = ttk.Scrollbar(orient="vertical", command=tree.yview) hsb = ttk.Scrollbar(orient="horizontal", command=tree.xview) vsb.place(x=1021, y=231,width=15, height=307,) hsb.place(x=22, y=540,width=1000, height=15,) tree.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set) container.grid_columnconfigure(0, weight=1) container.grid_rowconfigure(0, weight=1) tree.column('#1', width=180, stretch=YES) tree.column('#2', width=240, stretch=YES) tree.column('#3', width=10, stretch=YES) tree.column('#4', width=5, stretch=YES) tree.column('#5', width=5, stretch=YES) tree.column('#6', width=5, stretch=YES) tree.column('#7', width=25, stretch=YES) tree.heading('#1', text='Path') tree.heading('#2', text='Folder-file') tree.heading('#3', text='Byte') tree.heading('#4', text='Kb') tree.heading('#5', text='Mb') tree.heading('#6', text='Gb') tree.heading('#7', text='Object type') tree['show'] = 'headings' tree.pack(fill=BOTH,expand=1) ### frame 15 ########################### ########################### ### FRAME 16 CSV DIAL frm16 = tk.Frame(frm10, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1, bd= 0) frm16.place(width=480, height=30, x=20, y=530) # csv lbl tk.Label(frm16,text ="Default folder for csv file (change...)", font=("Verdana", 8, "normal"), fg='gray80', bg='gray5').place(x=10, y=5) # csv folder entry box vcsv_path=tk.StringVar() # Value saved here txt_csv = tk.Entry(frm16,width=43, textvariable=vcsv_path, fg='green').place(width=265, x=210, y=3) full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep vcsv_path.set(new_text) ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### def fx_FileRen(): Lpath = vtxt_path3.get() print('%s' % Lpath) # path WD 2 if Lpath.endswith(os.path.sep): Lpath = Lpath[:-1] print('%s' % Lpath) msg.showwarning("File names", "File names changed") # with open(csv_file_title) as csvfile: # csvreader = csv.reader(csvfile, delimiter=';', quotechar='"') # for row in csvreader: # name = row[0] # new = row[1] # if os.path.exists(name): # os.rename(name, new) # else: # print(name + " does not exist") ############################################################################### def fx_FoldRen(): csv_file_title = 'csv_1_baselisting.csv' print('%s' % csv_file_title) # with open(CSV_FILE,'w', newline ='\n') as f: # write = csv.writer(f, doublequote=True, delimiter=';') # for row in arr: # write.writerows(row) msg.showwarning("Folder names", "Folders names changed") ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### ############################################################################### #######################///...///...///...///...///####################### # TAB 2 # #######################///...///...///...///...///####################### ### FRAME GLOB frm20 = tk.Frame(tab2, bg="gray5") frm20.pack(expand = 1, fill ="both") # frm10.pack( side = LEFT, expand = True, fill = BOTH) ####################### ### FRAME 21a FOLDER PATH frm21a = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm21a.place(width=950, height=100, x=20, y=45) # Top label title tk.Label(frm21a,text ="Folder path to list folders files to csv", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) vtxt_path1a=tk.StringVar(root, value=new_text) # Value saved here txt_path1a = tk.Entry(frm21a,width=43, textvariable=vtxt_path1a, fg='blue').place(width=620, height=30, x=140, y=50) ####################### ### FRAME 21 LABEL FILES RENAME frm21 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm21.place(width=775, height=100, x=20, y=185) # Top label title tk.Label(frm21,text ="Rename files only from csv file below", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL FILES RENAME entry box tk.Label(frm21, text="CSV file path", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep + "csvtxt_1_filenamelisting.csv" # vtxt_path2.set(new_text) ### PATH ENTRY BOX vtxt_path2=tk.StringVar(root, value=new_text) # Value saved here txt_path2 = tk.Entry(frm21,width=43, textvariable=vtxt_path2, fg='blue').place(width=620, height=30, x=140, y=50) # TEST FOLDER zzz ########################### ### FRAME 22 TOP BUTTON FILE RENAME frm22 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm22.place(width=150, height=40, x=820, y=220) ### button btn_FileRen = tk.Button(frm22, text="Files rename", bg='lightblue4', font=("Verdana", 10,"normal")) btn_FileRen.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_FileRen['command'] = fx_FileRen ####################### ### FRAME 23 LABEL FOLDERS RENAME frm23 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm23.place(width=775, height=100, x=20, y=320) # Top label title tk.Label(frm23,text ="Rename folders only from csv file below", font=("Tahoma", 14, "normal"), fg='gray80', bg='gray5').place(x=20, y=10) ### LABEL PATH entry box tk.Label(frm23, text="CSV file path", fg='gray80', bg='gray5').place(x=20, y=55) # TEST FOLDER full_path = os.path.realpath(__file__) new_text = os.path.dirname(full_path) + os.sep + 'csv_folder' + os.sep + "csvtxt_1_foldernamelisting.csv" # vtxt_path2.set(new_text) ### PATH ENTRY BOX vtxt_path3=tk.StringVar(root, value=new_text) # Value saved here txt_path3 = tk.Entry(frm23,width=43, textvariable=vtxt_path3, fg='brown').place(width=620, height=30, x=140, y=50) # TEST FOLDER zzz ########################### ### FRAME 24 BUTTON FOLDERS RENAME frm24 = tk.Frame(frm20, bg="gray5",highlightbackground="HoneyDew3", highlightcolor="HoneyDew3", highlightthickness=1) frm24.place(width=150, height=40, x=820, y=345) ### button btn_FoldRen = tk.Button(frm24, text="Folders rename", bg='brown', font=("Verdana", 10,"normal")) btn_FoldRen.pack(expand = 1, fill ="both",padx=0, pady=0) ### BUTTON BROWSE entry fx BASIC LISTING btn_FoldRen['command'] = fx_FoldRen #######################///...///...///...///...///####################### # TAB 3 # #######################///...///...///...///...///####################### #######################///...///...///...///...///####################### # zZZZz # #######################///...///...///...///...///####################### if __name__ == '__main__': root.mainloop() From barpasc at yahoo.com Mon Jan 11 07:12:40 2021 From: barpasc at yahoo.com (pascal z) Date: Mon, 11 Jan 2021 04:12:40 -0800 (PST) Subject: learning python building 2nd app, need advices In-Reply-To: <878s8zn0ol.fsf@hornfels.zedat.fu-berlin.de> References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> <878s8zn0ol.fsf@hornfels.zedat.fu-berlin.de> Message-ID: <54047773-adf2-4b9f-a465-6a040f773a42n@googlegroups.com> On Monday, January 11, 2021 at 12:00:28 PM UTC, Loris Bennett wrote: > pascal z writes: > > > tab to space on linux is not something easy to do > > I would argue that you are mistaken, although that depends somewhat on > your definition of 'easy'. > > > , I had to launch windows and use notepad++. > > There is the Linux command 'expand' , which I have never used, but which > sounds like it will do what you want: > > $ expand --help > Usage: expand [OPTION]... [FILE]... > Convert tabs in each FILE to spaces, writing to standard output. > > As an Emacs user, personally I would use the command > > M-x untabify > > within Emacs. I assume that Vim has something similar. > > Cheers, > > Loris > > -- > This signature is currently under construction. Thanks, I'm going to try As alternative, I pasted it into github and pasted it back into this page, it's ok when pasting but when posting it fails keeping spaces... Until I can find a way to do it, this is the github link https://github.com/barpasc/listfiles/blob/main/pyFilesGest_6B18.py From greg.ewing at canterbury.ac.nz Mon Jan 11 08:45:07 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 12 Jan 2021 02:45:07 +1300 Subject: learning python building 2nd app, need advices In-Reply-To: <54047773-adf2-4b9f-a465-6a040f773a42n@googlegroups.com> References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> <878s8zn0ol.fsf@hornfels.zedat.fu-berlin.de> <54047773-adf2-4b9f-a465-6a040f773a42n@googlegroups.com> Message-ID: On 12/01/21 1:12 am, pascal z wrote: > As alternative, I pasted it into github and pasted it back into this page, it's ok when pasting but when posting it fails keeping spaces... The indentation in your last three posts looks fine here in the comp.lang.python newsgroup. If it doesn't look right to you, it may be the fault of whatever you're using to read the group. -- Greg From barpasc at yahoo.com Mon Jan 11 08:58:32 2021 From: barpasc at yahoo.com (pascal z) Date: Mon, 11 Jan 2021 05:58:32 -0800 (PST) Subject: learning python building 2nd app, need advices In-Reply-To: References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> <878s8zn0ol.fsf@hornfels.zedat.fu-berlin.de> <54047773-adf2-4b9f-a465-6a040f773a42n@googlegroups.com> Message-ID: On Monday, January 11, 2021 at 1:45:31 PM UTC, Greg Ewing wrote: > On 12/01/21 1:12 am, pascal z wrote: > > As alternative, I pasted it into github and pasted it back into this page, it's ok when pasting but when posting it fails keeping spaces... > The indentation in your last three posts looks fine here in > the comp.lang.python newsgroup. If it doesn't look right to > you, it may be the fault of whatever you're using to read > the group. > > -- > Greg @Greg, then if you want, you can post these from what you're using. I tried sending a few times and it seemed it didn't work when refreshing the google group discussion page. However, just looking now at the discussion through emails, shows indentation right. I'm using firefox. I'll try using chromium for later posts if that makes things easier. From rosuav at gmail.com Mon Jan 11 09:05:07 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jan 2021 01:05:07 +1100 Subject: [Python-authors] Query In-Reply-To: References: Message-ID: On Mon, Jan 11, 2021 at 10:36 PM George Fischhof wrote: > > Eduardo Em?n Mu?oz ezt ?rta (id?pont: 2021. jan. 8., > P, 17:23): > > > Dear Srs, > > > > I apologize if this is not the right place to ask this question, I am > > Biologist teaching Python language (in spanish) focused in Molecular > > Biology. > > > > People interested often ask me if my classes/course has a valid > > certification and I have to say no, so my question is : > > > > What can I do for provide a valid diploma with the Python logo to my > > students? I mean, how I would be allowed to give a valid > > Python logo on my students diploma? I have tried to contact local > > institutions like Biology's college, Education Ministry , etc but no > > success at all. > > > > Many thanks for your time reading this email, sorry for my poor english > > and thanks in advance. > > > > > > _______________________________________________ > > Python-authors mailing list > > Python-authors at python.org > > https://mail.python.org/mailman/listinfo/python-authors > > > Hi, > > the good forum for similar questions is python-list at python.org mail list - > I think ;-) > > Right _now_ Microsoft created a Python exam, I do not know how much is that > appreciated, or accepted, but there is. > As I know this is the only one somewhat standardised exam now. > Of course there are several institutes holding Python course and exam > Sounds like a legal question regarding the use of the trademark? If so, contact psf-trademarks at python.org - they should be able to help you. ChrisA From rosuav at gmail.com Mon Jan 11 09:06:31 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jan 2021 01:06:31 +1100 Subject: learning python building 2nd app, need advices In-Reply-To: References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> <878s8zn0ol.fsf@hornfels.zedat.fu-berlin.de> <54047773-adf2-4b9f-a465-6a040f773a42n@googlegroups.com> Message-ID: On Tue, Jan 12, 2021 at 1:01 AM pascal z via Python-list wrote: > > On Monday, January 11, 2021 at 1:45:31 PM UTC, Greg Ewing wrote: > > On 12/01/21 1:12 am, pascal z wrote: > > > As alternative, I pasted it into github and pasted it back into this page, it's ok when pasting but when posting it fails keeping spaces... > > The indentation in your last three posts looks fine here in > > the comp.lang.python newsgroup. If it doesn't look right to > > you, it may be the fault of whatever you're using to read > > the group. > > > > -- > > Greg > > @Greg, then if you want, you can post these from what you're using. I tried sending a few times and it seemed it didn't work when refreshing the google group discussion page. However, just looking now at the discussion through emails, shows indentation right. I'm using firefox. I'll try using chromium for later posts if that makes things easier. > Easy fix: stop looking at the Google Group page. ChrisA From barpasc at yahoo.com Mon Jan 11 09:34:42 2021 From: barpasc at yahoo.com (pascal z) Date: Mon, 11 Jan 2021 06:34:42 -0800 (PST) Subject: learning python building 2nd app, need advices In-Reply-To: References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> <878s8zn0ol.fsf@hornfels.zedat.fu-berlin.de> <54047773-adf2-4b9f-a465-6a040f773a42n@googlegroups.com> Message-ID: On Monday, January 11, 2021 at 2:07:03 PM UTC, Chris Angelico wrote: > On Tue, Jan 12, 2021 at 1:01 AM pascal z via Python-list > wrote: > > > > On Monday, January 11, 2021 at 1:45:31 PM UTC, Greg Ewing wrote: > > > On 12/01/21 1:12 am, pascal z wrote: > > > > As alternative, I pasted it into github and pasted it back into this page, it's ok when pasting but when posting it fails keeping spaces... > > > The indentation in your last three posts looks fine here in > > > the comp.lang.python newsgroup. If it doesn't look right to > > > you, it may be the fault of whatever you're using to read > > > the group. > > > > > > -- > > > Greg > > > > @Greg, then if you want, you can post these from what you're using. I tried sending a few times and it seemed it didn't work when refreshing the google group discussion page. However, just looking now at the discussion through emails, shows indentation right. I'm using firefox. I'll try using chromium for later posts if that makes things easier. > > > Easy fix: stop looking at the Google Group page. > > ChrisA ok, emails show post fine. 10 years ago or something, I was quite involved to comp.lang.c and I don't remember having this issue. Of course, only Python needs formatting speficities but from what I can remember, indentation was working fine then. One more thing, is that there was a lot less ads than now. And comp.lang.python seems to show more ads than other groups like comp.lang.c From 2QdxY4RzWzUUiLuE at potatochowder.com Mon Jan 11 10:03:40 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Mon, 11 Jan 2021 09:03:40 -0600 Subject: learning python building 2nd app, need advices In-Reply-To: References: <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> <878s8zn0ol.fsf@hornfels.zedat.fu-berlin.de> <54047773-adf2-4b9f-a465-6a040f773a42n@googlegroups.com> Message-ID: On 2021-01-11 at 06:34:42 -0800, pascal z via Python-list wrote: > On Monday, January 11, 2021 at 2:07:03 PM UTC, Chris Angelico wrote: > > Easy fix: stop looking at the Google Group page. > > > > ChrisA > ok, emails show post fine. 10 years ago or something, I was quite > involved to comp.lang.c and I don't remember having this issue. Of > course, only Python needs formatting speficities but from what I can > remember, indentation was working fine then. One more thing, is that > there was a lot less ads than now. And comp.lang.python seems to show > more ads than other groups like comp.lang.c I read the mailing list. With an email client. No ads. Start at , join the mailing list, and stop using Google. From tjreedy at udel.edu Mon Jan 11 06:54:02 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 11 Jan 2021 06:54:02 -0500 Subject: learning python building 2nd app, need advices In-Reply-To: <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> Message-ID: On 1/11/2021 6:46 AM, pascal z via Python-list wrote: > tab to space on linux is not something easy to do, IDLE has a tab to spaces command on the format menu. -- Terry Jan Reedy From grant.b.edwards at gmail.com Mon Jan 11 10:34:32 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 11 Jan 2021 15:34:32 -0000 (UTC) Subject: learning python building 2nd app, need advices References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> Message-ID: On 2021-01-11, pascal z via Python-list wrote: > tab to space on linux is not something easy to do, Nonsense, there's a command _specifically_ for that: $ man expand -- Grant From grant.b.edwards at gmail.com Mon Jan 11 10:37:08 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 11 Jan 2021 15:37:08 -0000 (UTC) Subject: learning python building 2nd app, need advices References: <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> <878s8zn0ol.fsf@hornfels.zedat.fu-berlin.de> <54047773-adf2-4b9f-a465-6a040f773a42n@googlegroups.com> Message-ID: On 2021-01-11, 2QdxY4RzWzUUiLuE at potatochowder.com <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > On 2021-01-11 at 06:34:42 -0800, > pascal z via Python-list wrote: > >> On Monday, January 11, 2021 at 2:07:03 PM UTC, Chris Angelico wrote: > >> > Easy fix: stop looking at the Google Group page. >> >> ok, emails show post fine. 10 years ago or something, I was quite >> involved to comp.lang.c and I don't remember having this issue. Of >> course, only Python needs formatting speficities but from what I can >> remember, indentation was working fine then. One more thing, is that >> there was a lot less ads than now. And comp.lang.python seems to show >> more ads than other groups like comp.lang.c > > I read the mailing list. With an email client. No ads. > > Start at , join the mailing > list, and stop using Google. Or point your favorite NNTP client at nntp://news.gmane.io/gmane.comp.python.general Google Groops is definitely the wrong answer. -- Grant From don81846 at comcast.net.REMOVEME Mon Jan 11 15:37:58 2021 From: don81846 at comcast.net.REMOVEME (DonK) Date: Mon, 11 Jan 2021 15:37:58 -0500 Subject: A beginning beginner's question about input, output and . . . Message-ID: Hi, I'm thinking about learning Python but I'm 74 years old and will very likely not ever have a programming job again. I used to program in Visual Basic, C\C++, Delphi, etc. and some obscure "mainframe" languages. It's been about 18-19 years since my last programming job. I do understand programming concepts but I'm really not up on any of the more modern programming languages. I've installed Python 3.7, the PyCharm IDE and watched some Youtube tutorials but it's been stretched out over about 1.5 years so I'll probably need to go back to the beginning. My problem is that I don't understand how Python programs are used. (i.e user input and output) Is Python mainly used for backends? I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they look kinda like adding a family room onto a 1986 double wide mobile home, and they look even more complicated than creating a GUI from scratch in C++ with a message loop, raising events . . . So, what do you folks use Python for? Nowdays I mainly just use programming for rather small utilities for my personal use. Currently I'd like to write something to iterate through open windows and save them to different folders depending on if the titlebar contains certain strings. In the past I would probably have used Excel's VBA to do this but I no longer have Excel installed on my main computer. I'd like a bit of a challenge but I don't want to spin my wheels trying to learn something that will be a dead end for me. I know that this probably seems like a stupid post but your input will be useful. Thank you. Don I know that Python is a very popular language so I'm sorry if it sounds like I'm being critical. I really don't know enough about it to be critical. From rosuav at gmail.com Mon Jan 11 15:54:34 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jan 2021 07:54:34 +1100 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On Tue, Jan 12, 2021 at 7:41 AM DonK wrote: > > > Hi, I'm thinking about learning Python but I'm 74 years old and will > very likely not ever have a programming job again. I used to program > in Visual Basic, C\C++, Delphi, etc. and some obscure "mainframe" > languages. It's been about 18-19 years since my last programming job. > I do understand programming concepts but I'm really not up on any of > the more modern programming languages. > > I've installed Python 3.7, the PyCharm IDE and watched some Youtube > tutorials but it's been stretched out over about 1.5 years so I'll > probably need to go back to the beginning. My problem is that I don't > understand how Python programs are used. (i.e user input and output) > Is Python mainly used for backends? > Python is used in many different ways. I'd recommend focusing first on the simple console input and output, which are available as the input() and print() built-in functions; those are sufficient for a vast majority of situations. Beyond that, you run into what's best described as "inherent complexity"; building a good user interface is, by its nature, not simple. If it's easier, you can look into using a web browser as your user interface. Python is superb at building web servers and web applications, so you can easily design your app so the user interacts with it using a very simple browser-based front end - either with JavaScript or as a really easy form fill-out. ChrisA From PythonList at DancesWithMice.info Mon Jan 11 16:36:02 2021 From: PythonList at DancesWithMice.info (dn) Date: Tue, 12 Jan 2021 10:36:02 +1300 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: <12519996-c202-803e-87c3-704fa43e231d@DancesWithMice.info> On 12/01/2021 09.37, DonK wrote: > > Hi, I'm thinking about learning Python but I'm 74 years old and will > very likely not ever have a programming job again. I used to program > in Visual Basic, C\C++, Delphi, etc. and some obscure "mainframe" > languages. It's been about 18-19 years since my last programming job. > I do understand programming concepts but I'm really not up on any of > the more modern programming languages. > > I've installed Python 3.7, the PyCharm IDE and watched some Youtube > tutorials but it's been stretched out over about 1.5 years so I'll > probably need to go back to the beginning. My problem is that I don't > understand how Python programs are used. (i.e user input and output) > Is Python mainly used for backends? > > I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they > look kinda like adding a family room onto a 1986 double wide mobile > home, and they look even more complicated than creating a GUI from > scratch in C++ with a message loop, raising events . . . > > So, what do you folks use Python for? > > Nowdays I mainly just use programming for rather small utilities for > my personal use. Currently I'd like to write something to iterate > through open windows and save them to different folders depending on > if the titlebar contains certain strings. In the past I would probably > have used Excel's VBA to do this but I no longer have Excel installed > on my main computer. I'd like a bit of a challenge but I don't want to > spin my wheels trying to learn something that will be a dead end for > me. Your question is very broad. Python is used for an incredibly wide variety of purposes. Frankly, why worry about my uses for Python, the only important stuff is what you want to do with it! There are plenty of articles 'out there' which discuss using Excel [data] with Python, why one should prefer Python to Excel, etc. Try: https://info.cambridgespark.com/latest/python-vs-excel (BTW with Python and appropriate libraries, the Excel package itself is not required) One way to learn is to ask the question: how do I do xyz in Python? You have some background, so will be able to ask reasonably 'educated' and valid questions. This will feel faster, but is by definition a piece-meal approach. Us 'silver surfers' often prefer a more structured (and complete) approach, and preferably one which looks at the semantics of the language (in Python we talk of idioms and the "Zen of Python") not merely the syntax. Thus, I recommend (free or $) MOOCs on the edX or Coursera platforms (amongst others). As you say, the profession has 'moved on' and there are fresh approaches and new angles to get one's head around... So, it's not just "Python" then! PS you will likely find the Python-Tutor mailing list solid assistance. -- Regards =dn From cs at cskk.id.au Mon Jan 11 17:11:37 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 12 Jan 2021 09:11:37 +1100 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 11Jan2021 15:37, DonK wrote: >Hi, I'm thinking about learning Python but I'm 74 years old and will >very likely not ever have a programming job again. I used to program >in Visual Basic, C\C++, Delphi, etc. and some obscure "mainframe" >languages. Therefore you're happy with classes, and are presumably with a Windows background. (And, of course, the mainframe world.) >I've installed Python 3.7, the PyCharm IDE and watched some Youtube >tutorials but it's been stretched out over about 1.5 years so I'll >probably need to go back to the beginning. My problem is that I don't >understand how Python programs are used. (i.e user input and output) >Is Python mainly used for backends? My personal Python use is almost all backend, and on a personal basis I spend most of my time at a command prompt in a terminal window. However, you can write fully fledged GUI applications in Python. Without a GUI Python programmes tend to work off their input and write to their output (or other files) like any other command line programme. Chris mentioned input() for reading input and print() for writing output. input() is an interactive function (it accepts a prompt string and reads a single line of text). If you're writing something batchy, which might be in a pipeline or reading from a text file, then the standard input is sys.stdin and can be read in various ways - when that is text the typical way is just to iterate over it in a for-loop, which gets your lines of text. Trite example: import sys ........ ........ lineno = 0 for line in sys.stdin: lineno += 1 print("line number", lineno, "text =", line) >I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they >look kinda like adding a family room onto a 1986 double wide mobile >home, and they look even more complicated than creating a GUI from >scratch in C++ with a message loop, raising events . . . They aren't really. I've not use Tkinter, but I have used PyQt. You still have the usual framework: - contruct widgets (windows and other GUI elements) with the associated code which runs when you interact with them - an event loop (usually simply entered after constructing the main GUI component(s)) - it will run until told to stop - raising events - in PyQt these are called "signals" - you issue a signel/event with whatever information it uses and the event loop runs its handler in due course Part of the difficulty with PyQt (for me) is that it is a Python shim onto a quite large C++ widget library. Most of the actual doco seems to be the C++ side, and you need to infer some stuff to use it from Python. The shim is very one-to-one, so that works pretty well. I gather that Tkinter is easier to get off the ground with. >So, what do you folks use Python for? Personally, almost entirely command line stuff, and making libraries/modules/packages which implement what I need. >Nowdays I mainly just use programming for rather small utilities for >my personal use. Me too. >Currently I'd like to write something to iterate >through open windows and save them to different folders depending on >if the titlebar contains certain strings. In the past I would probably >have used Excel's VBA to do this but I no longer have Excel installed >on my main computer. I'd like a bit of a challenge but I don't want to >spin my wheels trying to learn something that will be a dead end for >me. This requires Windows specific knowledge, which I lack. Saving to folders etc is standard stuff, but the "iterate through open windows" and consulting their titlebar strings is platform, and maybe app, specific. I'm not a Windows person, alas. >I know that this probably seems like a stupid post but your input will >be useful. No, it's entirely reasonable. Getting off the ground with a useful-to-you task is always the first hurdle with a new language. Cheers, Cameron Simpson From rosuav at gmail.com Mon Jan 11 17:26:18 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jan 2021 09:26:18 +1100 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On Tue, Jan 12, 2021 at 7:41 AM DonK wrote: > Hi, I'm thinking about learning Python but I'm 74 years old and will > very likely not ever have a programming job again. I used to program > in Visual Basic, C\C++, Delphi, etc. and some obscure "mainframe" > languages. BTW, from my experience, there's very very few languages so obscure that not one person on this list has heard of them :) For example, I've used REXX, which is an IBM language found on some of the mainframes and also on OS/2, and I'm not the only person here who has. ChrisA From drsalists at gmail.com Mon Jan 11 18:52:55 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 11 Jan 2021 15:52:55 -0800 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On Mon, Jan 11, 2021 at 2:22 PM Cameron Simpson wrote: > >I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they > >look kinda like adding a family room onto a 1986 double wide mobile > >home, and they look even more complicated than creating a GUI from > >scratch in C++ with a message loop, raising events . . . > > They aren't really. I've not use Tkinter, but I have used PyQt. > Maybe compared to Java or C# they are, which come with almost the only GUI toolkit that gets used. But there's also a version of Qt for Java. Not sure about C#. I've mostly used GTK for GUI's and a little Tkinter for turtle graphics, both in Python. Both felt natural. From cs at cskk.id.au Mon Jan 11 18:59:22 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Tue, 12 Jan 2021 10:59:22 +1100 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 11Jan2021 15:52, Dan Stromberg wrote: >On Mon, Jan 11, 2021 at 2:22 PM Cameron Simpson wrote: >> >I've seen some Python gui frameworks like Tkinter, PyQt, etc. but >> >they >> >look kinda like adding a family room onto a 1986 double wide mobile >> >home, and they look even more complicated than creating a GUI from >> >scratch in C++ with a message loop, raising events . . . >> >> They aren't really. I've not use Tkinter, but I have used PyQt. > >Maybe compared to Java or C# they are, which come with almost the only GUI >toolkit that gets used. But there's also a version of Qt for Java. Not >sure about C#. Hmm, in the distant past I did write a small GUI app using Java. It was a little simpler than (current) Qt to my (fuzzy) recollection, but that might be partly because the toolkit itself was smaller. Unsure now. Cheers, Cameron Simpson From greg.ewing at canterbury.ac.nz Mon Jan 11 23:10:33 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 12 Jan 2021 17:10:33 +1300 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 12/01/21 9:37 am, DonK wrote: > > I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they > look kinda like adding a family room onto a 1986 double wide mobile > home, and they look even more complicated than creating a GUI from > scratch in C++ with a message loop, raising events . . . I'm surprised you find any of those toolkits more complicated to use than the raw Windows API, which last time I dabbled in it seemed fairly horrendous. Unfortunately there doesn't seem to be a really good way to easily make GUIs in Python. I tried to fill that gap a few years back with PyGUI: https://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ You might like to check that out, but be warned that a few bits of it are broken at the moment. It's badly in need of an overhaul, and I don't have time to devote to it right now. > So, what do you folks use Python for? Personal uses I can think of in recent times: * Command line tools for various small tasks, often parts of build systems for other projects. * Games, using pygame, pyopengl, numpy and various other libraries. > Currently I'd like to write something to iterate > through open windows and save them to different folders depending on > if the titlebar contains certain strings. That sounds like it should be doable if you can get access to the right Windows API functions. Check out the pywin32 package. If that doesn't provide what you need, there's always ctypes (part of the standard python distribution, gives low-level access to C library functions). -- Greg From rosuav at gmail.com Tue Jan 12 01:07:16 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jan 2021 17:07:16 +1100 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On Tue, Jan 12, 2021 at 3:16 PM Greg Ewing wrote: > > Currently I'd like to write something to iterate > > through open windows and save them to different folders depending on > > if the titlebar contains certain strings. > > That sounds like it should be doable if you can get access to the > right Windows API functions. Check out the pywin32 package. If that > doesn't provide what you need, there's always ctypes (part of the > standard python distribution, gives low-level access to C library > functions). > Sounds like an awful lot of work. On Linux, I'd just subprocess out to wmctrl and parse its output - way easier. ChrisA From arj.python at gmail.com Tue Jan 12 01:16:47 2021 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Tue, 12 Jan 2021 10:16:47 +0400 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: Greetings, Web with Python is really easy to get started with, here is a simple endpoint with a framework called Flask from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World? if __name__ == '__main__': app.run() As for Tkinter, it's really annoying. PyQt5 and others are a lot better. PyQt5 follows the Cpp function namings Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius On Tue, Jan 12, 2021 at 12:43 AM DonK wrote: > > Hi, I'm thinking about learning Python but I'm 74 years old and will > very likely not ever have a programming job again. I used to program > in Visual Basic, C\C++, Delphi, etc. and some obscure "mainframe" > languages. It's been about 18-19 years since my last programming job. > I do understand programming concepts but I'm really not up on any of > the more modern programming languages. > > I've installed Python 3.7, the PyCharm IDE and watched some Youtube > tutorials but it's been stretched out over about 1.5 years so I'll > probably need to go back to the beginning. My problem is that I don't > understand how Python programs are used. (i.e user input and output) > Is Python mainly used for backends? > > I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they > look kinda like adding a family room onto a 1986 double wide mobile > home, and they look even more complicated than creating a GUI from > scratch in C++ with a message loop, raising events . . . > > So, what do you folks use Python for? > > Nowdays I mainly just use programming for rather small utilities for > my personal use. Currently I'd like to write something to iterate > through open windows and save them to different folders depending on > if the titlebar contains certain strings. In the past I would probably > have used Excel's VBA to do this but I no longer have Excel installed > on my main computer. I'd like a bit of a challenge but I don't want to > spin my wheels trying to learn something that will be a dead end for > me. > > I know that this probably seems like a stupid post but your input will > be useful. > > Thank you. > > Don > > I know that Python is a very popular language so I'm sorry if it > sounds like I'm being critical. I really don't know enough about it to > be critical. > -- > https://mail.python.org/mailman/listinfo/python-list > From songbird at anthive.com Tue Jan 12 00:55:07 2021 From: songbird at anthive.com (songbird) Date: Tue, 12 Jan 2021 00:55:07 -0500 Subject: A beginning beginner's question about input, output and . . . References: Message-ID: DonK wrote: > > Hi, I'm thinking about learning Python but I'm 74 years old and will > very likely not ever have a programming job again. I used to program > in Visual Basic, C\C++, Delphi, etc. and some obscure "mainframe" > languages. It's been about 18-19 years since my last programming job. > I do understand programming concepts but I'm really not up on any of > the more modern programming languages. hi Don, you sound like you have a similar perspective to my own except i'm a bit younger. :) > I've installed Python 3.7, the PyCharm IDE and watched some Youtube > tutorials but it's been stretched out over about 1.5 years so I'll > probably need to go back to the beginning. My problem is that I don't > understand how Python programs are used. (i.e user input and output) > Is Python mainly used for backends? it can be used for pretty much anything except perhaps high pressure real time things, but i bet someone else will know that is being done too, i've just not heard of it. :) > I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they > look kinda like adding a family room onto a 1986 double wide mobile > home, and they look even more complicated than creating a GUI from > scratch in C++ with a message loop, raising events . . . i tried pyglet just because it was the first one that i could figure out without it being too complicated. > So, what do you folks use Python for? for me i used it to learn python and wrote a simple game which adapted an already existing game written in C to python. since i don't really understand python and have issues with some concepts it hasn't gone much further lately and i'm ok with that. > Nowdays I mainly just use programming for rather small utilities for > my personal use. Currently I'd like to write something to iterate > through open windows and save them to different folders depending on > if the titlebar contains certain strings. In the past I would probably > have used Excel's VBA to do this but I no longer have Excel installed > on my main computer. I'd like a bit of a challenge but I don't want to > spin my wheels trying to learn something that will be a dead end for > me. i am so familiar with Bash shell script language and C that either of those would normally be my first choice because i already have tools done for enough things and i know what i'm doing. for python i just spend too much time fumbling around and i don't really know what is current and if i'm using something that will be kept up for the future or if the project is going away or in a direction that i won't like (both KDE and Gnome desktops messed me up with what they did after i spent a lot of time finding them, getting them set up and then they changed and i switched only to have the other do the same to me so i switched again to Mate and that at least has been more stable to my style of doing things). uh, so, i think i do understand your aims and perspective and hope you can get further in your goals. :) > I know that this probably seems like a stupid post but your input will > be useful. > > Thank you. > > Don > > I know that Python is a very popular language so I'm sorry if it > sounds like I'm being critical. I really don't know enough about it to > be critical. heh, well, if you go back and read some of my previous posts here you'd see a lot of dumb things i've said too. don't worry. i'm sure i'll make other dumb posts too, but at the moment i'm mostly in a holding pattern for a while. i have a few other big projects i need to finish before i get back to python again. songbird From rosuav at gmail.com Tue Jan 12 01:34:10 2021 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 12 Jan 2021 17:34:10 +1100 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On Tue, Jan 12, 2021 at 5:26 PM songbird wrote: > for python i just spend too much time fumbling around > and i don't really know what is current and if i'm using > something that will be kept up for the future or if the > project is going away or in a direction that i won't like > (both KDE and Gnome desktops messed me up with what they > did after i spent a lot of time finding them, getting > them set up and then they changed and i switched only to > have the other do the same to me so i switched again to > Mate and that at least has been more stable to my style of > doing things). That's not really something Python can ever control, but I can say with some confidence that the big libraries like Qt and GTK are going to adapt, one way or another. And perhaps more importantly: Neither input()/print() nor web applications is going *anywhere*. You are ALWAYS going to have those two as options. ChrisA From grant.b.edwards at gmail.com Mon Jan 11 16:09:08 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 11 Jan 2021 21:09:08 -0000 (UTC) Subject: A beginning beginner's question about input, output and . . . References: Message-ID: On 2021-01-11, DonK wrote: > So, what do you folks use Python for? I mainly use it for writing command-line utilities. Many of them work on either Windows or Linux, but are mostly used on Linux: * Two-pass symbolic assembler and dissassembler for a proprietary communications controller. * Utilties to encrypt/decrypt files in proprietary formats. * Protocol dissector that prints the contents of network traffic for a couple different proprietary protocols. It will parse a file saved with Wireshark/tcpdump or it will display live traffic using libpcap. * A utility to discover and manage a couple different families of industrial products (discovery, configiration) using a proprietary UDP protocol. * Utilities to program firmware into various products and microprocessors. * Utilities to perform various operations (e.g. run-length encoding) on things like FPGA bitstream files. * Utilities that implement various serial protocols for testing devices that use those protocols. * Scraping my favorite comic strips from various web sites and compiling them into a local web page. * Utilties for working with industrial control devices using DeviceNet on CAN bus. * An email gateway daemon that accepted SMTP mail and relayed it to MS Exchange using WebDAV. * An email gateway daemon that fetched email from MS Exchnage using Outlook/DCOM and relayed to an SMTP server. * Custom SMTP servers used to test SMTP clients. I also wire the occasional GUI application: * A GTK "terminal" application that connects to a serial port. * A GTK IMAP mailbox notification app that monitors any number of IMAP mailboxes and notifies the user when there is new mail. * WxWindows and Tk applications to do various device management tasks for industrial equipment (update firmware, change configurations, etc.) via TCP and UDP network protocols. * WxWindows utilities for working with industrial control devices using DeviceNet on CAN bus. I've also written web "backend" code that gathers and archives data from my solar panels every 10 minutes and then produces graphs and charts on demand for AJAX web applications. Where I work we also use Python to run our production stations -- testing and programming circuit boards and assembled products. There are also a couple commercial applicatoins I use daily (but didn't write) that are written in Python: Hiri (email client) Plex (DVR and home theater application) From grant.b.edwards at gmail.com Tue Jan 12 10:18:05 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 12 Jan 2021 15:18:05 -0000 (UTC) Subject: A beginning beginner's question about input, output and . . . References: Message-ID: On 2021-01-12, songbird wrote: > it can be used for pretty much anything except perhaps > high pressure real time things, but i bet someone else will > know that is being done too, i've just not heard of it. :) AFAIK, Python can't be used to write device drivers for any popular OS (Linux, Unix, Windows, OSX). It also can't be used on small embedded systems (real-time or not). -- Grant From rosuav at gmail.com Tue Jan 12 11:32:56 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2021 03:32:56 +1100 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On Wed, Jan 13, 2021 at 3:18 AM Grant Edwards wrote: > > On 2021-01-12, songbird wrote: > > > it can be used for pretty much anything except perhaps > > high pressure real time things, but i bet someone else will > > know that is being done too, i've just not heard of it. :) > > AFAIK, Python can't be used to write device drivers for any popular OS > (Linux, Unix, Windows, OSX). It also can't be used on small embedded > systems (real-time or not). > Depends how small. An RPi has a full Linux system and can easily run Python scripts; and the pyboard runs a dedicated Python interpreter called MicroPython, broadly compatible with CPython 3.5, I think (some 3.x version, anyhow), albeit with a cut-down standard library. The pyboard is pretty tiny; according to the micropython.org blurb, it has 192KB RAM. ChrisA From rshepard at appl-ecosys.com Tue Jan 12 11:37:15 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 12 Jan 2021 08:37:15 -0800 (PST) Subject: Application window geometry specifier Message-ID: I want my application's window (main frame) to open centered on the monitor's screen. This code: # open application centered on screen; set window width and height self.appwidth = 600 self.appheight = 500 # get screen width and height self.scrwidth = self.winfo_screenwidth() self.scrheight = self.winfo_screenheight() # formula to find screen center self.xLeft = (self.scrwidth/2) - (self.appwidth/2) self.yTop = (self.scrheight/2) - (self.appheight/2) # set geometry self.geometry(str(self.appwidth) + "x" + str(self.appheight) + "+" + str(self.xLeft) + "+" + str(self.yTop)) generates this error when run: File "/usr/lib64/python3.9/tkinter/__init__.py", line 2036, in wm_geometry return self.tk.call('wm', 'geometry', self._w, newGeometry) _tkinter.TclError: bad geometry specifier "600x500+340.0+262.0" As the geometry string represents window width times window height plus x-offset plus y-offset I'm not seeing my error. Please show me what's wrong with specifier. TIA, Rich From rosuav at gmail.com Tue Jan 12 11:44:38 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2021 03:44:38 +1100 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: On Wed, Jan 13, 2021 at 3:38 AM Rich Shepard wrote: > > I want my application's window (main frame) to open centered on the > monitor's screen. This code: > # open application centered on screen; set window width and height > self.appwidth = 600 > self.appheight = 500 > # get screen width and height > self.scrwidth = self.winfo_screenwidth() > self.scrheight = self.winfo_screenheight() > # formula to find screen center > self.xLeft = (self.scrwidth/2) - (self.appwidth/2) > self.yTop = (self.scrheight/2) - (self.appheight/2) > # set geometry > self.geometry(str(self.appwidth) + "x" + str(self.appheight) + > "+" + str(self.xLeft) + "+" + str(self.yTop)) > > generates this error when run: > File "/usr/lib64/python3.9/tkinter/__init__.py", line 2036, in wm_geometry > return self.tk.call('wm', 'geometry', self._w, newGeometry) > _tkinter.TclError: bad geometry specifier "600x500+340.0+262.0" > > As the geometry string represents window width times window height plus x-offset > plus y-offset I'm not seeing my error. > Do the offsets need to be integers? ChrisA From mstemper at gmail.com Tue Jan 12 11:40:17 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Tue, 12 Jan 2021 10:40:17 -0600 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 11/01/2021 14.37, DonK wrote: > I've installed Python 3.7, the PyCharm IDE and watched some Youtube > tutorials I would suggest that instead of watching tutorials, you open up your IDE and start writing stuff. Get an introductory python book (I used the O'Reilly _Introducing Python_), start at the beginning, and type in each example. Then, tweak it to see what happens. > I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they > look kinda like adding a family room onto a 1986 double wide mobile > home, and they look even more complicated than creating a GUI from > scratch in C++ with a message loop, raising events . . . I haven't really got my head around GUI programming myself. I tried to write one with tkinter based on on-line examples, but didn't have any conceptual framekwork, so it didn't work too well. I saw in a post here that there are actually books on it, so I might pick one up and try again. > So, what do you folks use Python for? Since you asked: Various command-line utilities, including: - comparing the contents of two directories - ad-hoc linear regression - validation of DTDs - sanity check of nesting symbols in TeX files - ad-hoc plotting Maintaining and querying of data bases: - five-minute values of local temperatures - Action items for an organization of which I'm secretary - my own to-do list - non-isomorphic groups that have isomorphic character tables Modeling of electric power systems: - load behavior in response to conservation load reduction - generator and governor response to system load - economic dispatch of generators, including those with non-monotonic incremental cost curves (last two are very much works in progress) Mathematics: - experiments with number theory and combinatorics - composition of permutations of a set - properties of minimal paths through a C_m x C_n lattice - generating tikz commands for geometric diagrams in TeX documents - unstructured and uneducated exploration of Conway's Game of Life -- Michael F. Stemper 2 Chronicles 19:7 From ikorot01 at gmail.com Tue Jan 12 11:57:44 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 12 Jan 2021 10:57:44 -0600 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: Hi, On Tue, Jan 12, 2021 at 10:47 AM Chris Angelico wrote: > > On Wed, Jan 13, 2021 at 3:38 AM Rich Shepard wrote: > > > > I want my application's window (main frame) to open centered on the > > monitor's screen. Keep in mind that if you target Linux, the "modern" window server (Wayland) will not allow user code to decide the positioning and size of the TLW. Instead some renderer will make the decision for you and place it appropriately. So you may re-think that design. ;-) Thank you. >> This code: > > # open application centered on screen; set window width and height > > self.appwidth = 600 > > self.appheight = 500 > > # get screen width and height > > self.scrwidth = self.winfo_screenwidth() > > self.scrheight = self.winfo_screenheight() > > # formula to find screen center > > self.xLeft = (self.scrwidth/2) - (self.appwidth/2) > > self.yTop = (self.scrheight/2) - (self.appheight/2) > > # set geometry > > self.geometry(str(self.appwidth) + "x" + str(self.appheight) + > > "+" + str(self.xLeft) + "+" + str(self.yTop)) > > > > generates this error when run: > > File "/usr/lib64/python3.9/tkinter/__init__.py", line 2036, in wm_geometry > > return self.tk.call('wm', 'geometry', self._w, newGeometry) > > _tkinter.TclError: bad geometry specifier "600x500+340.0+262.0" > > > > As the geometry string represents window width times window height plus x-offset > > plus y-offset I'm not seeing my error. > > > > Do the offsets need to be integers? > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rshepard at appl-ecosys.com Tue Jan 12 12:37:50 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 12 Jan 2021 09:37:50 -0800 (PST) Subject: Application window geometry specifier [RESOLVED] In-Reply-To: References: Message-ID: On Wed, 13 Jan 2021, Chris Angelico wrote: > Do the offsets need to be integers? ChrisA, Yep. I totally missed that. Thanks for seeing it. Stay well, Rich From rshepard at appl-ecosys.com Tue Jan 12 12:38:56 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 12 Jan 2021 09:38:56 -0800 (PST) Subject: Application window geometry specifier In-Reply-To: References: Message-ID: On Tue, 12 Jan 2021, Igor Korot wrote: > Keep in mind that if you target Linux, the "modern" window server > (Wayland) will not allow user code to decide the positioning and size of > the TLW. Igor, I suspect that Slackware will continue with X11. Rich From python at mrabarnett.plus.com Tue Jan 12 12:35:58 2021 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 12 Jan 2021 17:35:58 +0000 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 2021-01-11 20:37, DonK wrote: > [snip] > > So, what do you folks use Python for? > Since we're sharing: - Personal information manager in the form of a tree of pages. Each page can have code associated with it which defines functions to call when shortcut keys are pressed, giving page-specific shortcuts for page-specific functionality. - Simple money manager. Both use tkinter. From mstemper at gmail.com Tue Jan 12 12:47:28 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Tue, 12 Jan 2021 11:47:28 -0600 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 12/01/2021 10.40, Michael F. Stemper wrote: > Modeling of electric power systems: > - load behavior in response to conservation load reduction Sorry, that should have been "conservation voltage reduction". -- Michael F. Stemper Psalm 82:1-4 From ikorot01 at gmail.com Tue Jan 12 12:56:01 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 12 Jan 2021 11:56:01 -0600 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: Hi, On Tue, Jan 12, 2021, 11:44 AM Rich Shepard wrote: > On Tue, 12 Jan 2021, Igor Korot wrote: > > > Keep in mind that if you target Linux, the "modern" window server > > (Wayland) will not allow user code to decide the positioning and size of > > the TLW. > > Igor, > > I suspect that Slackware will continue with X11. > Maybe. :-) But it looks Wayland becomes more and more popular. Thank you. > Rich > -- > https://mail.python.org/mailman/listinfo/python-list > From drp4kri at gmail.com Tue Jan 12 12:58:59 2021 From: drp4kri at gmail.com (Dhimant Patel) Date: Tue, 12 Jan 2021 09:58:59 -0800 (PST) Subject: argparse presence of switch Message-ID: <20f77a6a-0331-4455-a7bd-05901e014994n@googlegroups.com> Its what I searched for on this group. I want to have an argument's presence only - value is not required. For example, my program main.py needs to know if "-r" is present when program is invoked. So the value command line would be: (1) python3 main.py -r or... (1) python3 main.py I tried following: parser.add_argument('-r','--register', help='Register it') Since argument started with "-" it should be optional, but absence of it causes following error: main.py: error: argument -r/--register: expected one argument I added parser.add_argument('-r','--register', default=None, help='Register it') No avail - same error. If I apply -r on the command line, it still expects a value! Not sure what should I do? Any help appreciated- Thanks! From phoenix1987 at gmail.com Tue Jan 12 13:04:14 2021 From: phoenix1987 at gmail.com (Gabriele Tornetta) Date: Tue, 12 Jan 2021 10:04:14 -0800 (PST) Subject: [ANN] Austin -- CPython frame stack sampler v2.1.1 is now available Message-ID: <93769ab7-71f4-4058-8040-c04e4a2fb274n@googlegroups.com> I am delighted to announce the release 2.1.1 of Austin. If you haven't heard of Austin before, it is an open-source frame stack sampler for CPython, distributed under the GPLv3 license. It can be used to obtain statistical profiling data out of a running Python application without a single line of instrumentation. This means that you can start profiling a Python application straight away, even while it's running on a production environment, with minimal impact on performance. The simplest way of using Austin is by piping its output to FlameGraph or uploading it to speedscope.app for a quick and detailed representation of the collected samples. Austin is a pure C application that has no other dependencies other than the C standard library. Its source code is hosted on GitHub at https://github.com/P403n1x87/austin The README contains installation and usage details, as well as some examples of Austin in action. Details on how to contribute to Austin's development can be found at the bottom of the page. Austin can be installed easily on the following platforms and from the following sources: Linux: - Snap Store - Debian repositories - Conda Forge macOS: - Homebrew - Conda Forge Windows: - Chocolatey - Scoop Austin is also simple to compile from sources as it only depends on the standard C library, if you don't have access to the above-listed repositories. This new release of Austin brings enhanced support for many Python binary distributions across all the supported platforms, as well as a bugfix for the line number reporting. If you rely on Austin 2, upgrading to the latest version is strongly recommended. Let me also remind you of some of the other existing Python tools powered by Austin, which have also seen new releases in the past few days, and that are easily available from PyPI: https://github.com/P403n1x87/austin-tui https://github.com/P403n1x87/austin-web https://github.com/P403n1x87/pytest-austin These tools are built using the austin-python library, which is also available from PyPI, with source code hosted at https://github.com/P403n1x87/austin-python For anyone wishing to build their own Austin-powered tools, the austin-python documentation is hosted on RTD at https://austin-python.readthedocs.io/en/latest/ You can stay up-to-date with the project's development by following Austin on Twitter (https://twitter.com/AustinSampler). All the best, Gabriele

Austin 2.1.1 - frame stack sampler for CPython. (12-Jan-21)

From rosuav at gmail.com Tue Jan 12 13:13:29 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2021 05:13:29 +1100 Subject: argparse presence of switch In-Reply-To: <20f77a6a-0331-4455-a7bd-05901e014994n@googlegroups.com> References: <20f77a6a-0331-4455-a7bd-05901e014994n@googlegroups.com> Message-ID: On Wed, Jan 13, 2021 at 5:01 AM Dhimant Patel wrote: > > Its what I searched for on this group. > > I want to have an argument's presence only - value is not required. > For example, my program main.py needs to know if "-r" is present when program is invoked. > So the value command line would be: > (1) python3 main.py -r > or... > (1) python3 main.py > > I tried following: > parser.add_argument('-r','--register', help='Register it') > > Since argument started with "-" it should be optional, but absence of it causes following error: > > main.py: error: argument -r/--register: expected one argument This is what different actions are for. I'd probably use action="store_true" here; that should mean that args.register will be set to True if "-r" was passed, or False if it wasn't. ChrisA From david at lowryduda.com Tue Jan 12 13:18:48 2021 From: david at lowryduda.com (David Lowry-Duda) Date: Tue, 12 Jan 2021 13:18:48 -0500 Subject: argparse presence of switch In-Reply-To: <20f77a6a-0331-4455-a7bd-05901e014994n@googlegroups.com> References: <20f77a6a-0331-4455-a7bd-05901e014994n@googlegroups.com> Message-ID: <20210112181848.GB1789293@icerm-dld> > I want to have an argument's presence only - value is not required. > For example, my program main.py needs to know if "-r" is present when program is invoked. > So the value command line would be: > (1) python3 main.py -r > or... > (1) python3 main.py > > I tried following: > parser.add_argument('-r','--register', help='Register it') You should use the "store_true" action, or perhaps some other action. A complete minimal working sample is as follows. import argparse parser = argparse.ArgumentParser() parser.add_argument("-r", "--register", help="Register it", action="store_true") args = parser.parse_args() if args.register: print("Seen register") For more, I suggest reading the quick tutorial in the documentation, available at https://docs.python.org/3/howto/argparse.html#id1 Good luck! - DLD From grant.b.edwards at gmail.com Tue Jan 12 12:13:59 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 12 Jan 2021 17:13:59 -0000 (UTC) Subject: A beginning beginner's question about input, output and . . . References: Message-ID: On 2021-01-12, Chris Angelico wrote: > On Wed, Jan 13, 2021 at 3:18 AM Grant Edwards wrote: >> >> On 2021-01-12, songbird wrote: >> >> > it can be used for pretty much anything except perhaps >> > high pressure real time things, but i bet someone else will >> > know that is being done too, i've just not heard of it. :) >> >> AFAIK, Python can't be used to write device drivers for any popular OS >> (Linux, Unix, Windows, OSX). It also can't be used on small embedded >> systems (real-time or not). > > Depends how small. Of course. > An RPi has a full Linux system and can easily run Python scripts; > and the pyboard runs a dedicated Python interpreter called > MicroPython, broadly compatible with CPython 3.5, I think (some 3.x > version, anyhow), albeit with a cut-down standard library. The > pyboard is pretty tiny; according to the micropython.org blurb, it > has 192KB RAM. Yes, that's tiny compared to the desktop machine I'm posting from, but I work with ARM parts (that are in active production production and not EOL) with 2KB of RAM and 8KB of flash. -- Grant From * at eli.users.panix.com Tue Jan 12 13:33:35 2021 From: * at eli.users.panix.com (Eli the Bearded) Date: Tue, 12 Jan 2021 18:33:35 +0000 (UTC) Subject: Application window geometry specifier References: Message-ID: In comp.lang.python, Rich Shepard wrote: >> Keep in mind that if you target Linux, the "modern" window server >> (Wayland) will not allow user code to decide the positioning and size of > I suspect that Slackware will continue with X11. Even with traditional X11, geometry is "preferred" size and position[*], not a requirement. Window managers have always been able to override that if desired, and tiling window managers make that override a feature. There might not be a tiling window manager in Slack's standard packages, but there sure are in Slackbuilds. Elijah ------ [*] See GEOMETRY SPECIFICATIONS in "man X" From grant.b.edwards at gmail.com Tue Jan 12 13:43:39 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 12 Jan 2021 18:43:39 -0000 (UTC) Subject: Application window geometry specifier References: Message-ID: On 2021-01-12, Rich Shepard wrote: > On Tue, 12 Jan 2021, Igor Korot wrote: > >> Keep in mind that if you target Linux, the "modern" window server >> (Wayland) will not allow user code to decide the positioning and size of >> the TLW. > > Igor, > > I suspect that Slackware will continue with X11. And those X11 users will swear at you if you override their window managers configured window placement. Application code should not care about or try to control window geometry. Period. -- Grant From rosuav at gmail.com Tue Jan 12 13:45:40 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2021 05:45:40 +1100 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On Tue, Jan 12, 2021 at 7:41 AM DonK wrote: > So, what do you folks use Python for? > Since everyone else is, I'll add my list. * API lookups of various sorts (usually via HTTP requests) * Audio analysis. Calculate the maximum and average volume of each of many songs. * Code generation. The audio analysis output is in the form of a Lua script (a VLC extension); also I have Python scripts that generate SourcePawn code for CS:GO integration, and various other things. * Decoding and analyzing myriad formats of files, including Borderlands save files (now which character had that level 62 legendary weapon I wanted...) * Mathematical analysis and testing. Python has excellent arithmetical and higher mathematical tools. * Automated tidying up of files to eliminate spurious diffs (eg with OBS Studio's config files) * Web apps involving PostgreSQL databases, various API calls, etc, etc * Financial calculations - parse the downloaded transactions files from my bank, correlate with my client list, automatically mark invoices as paid * Command-line calculator - pressing Ctrl-Alt-P will open up a terminal with Python, and that's the normal way that I do quick calculations * And a ton of quick one-off scripts for a wide variety of jobs. Python's one of my favourite languages, and I use it a lot :) ChrisA From rshepard at appl-ecosys.com Tue Jan 12 13:46:23 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 12 Jan 2021 10:46:23 -0800 (PST) Subject: Application window geometry specifier In-Reply-To: References: Message-ID: On Tue, 12 Jan 2021, Igor Korot wrote: > Maybe. :-) > But it looks Wayland becomes more and more popular. Igor, What I've read from those struggling to use Wayland, it may turn out to be a popular as systemd. :-) It's important to remember that while all progress involves change, not all change involves progress. Regards, Rich From rshepard at appl-ecosys.com Tue Jan 12 13:59:34 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 12 Jan 2021 10:59:34 -0800 (PST) Subject: Binding menu accelerator to a callback Message-ID: Menu options work from the menu, but not from the accelerator associated with that menu item. My research suggests that while 'command' works for the menu item, 'bind' is required for the associated accelerator. For example, File -> Quit is defined this way: self.file_menu.add_command( label="Quit", command=self.fileQuit, underline=0, accelerator='Ctrl+Q' ) and works when I pull down the File menu and click on 'Quit.' I want to modify the menu items so the accelerator is bound to the same self.fileQuit() (in this case). My web research hasn't found a solution since examples for using bind() aren't in menus. Do I need another method that associates accelerators with the callbacks? Rich From rshepard at appl-ecosys.com Tue Jan 12 14:01:44 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Tue, 12 Jan 2021 11:01:44 -0800 (PST) Subject: Application window geometry specifier In-Reply-To: References: Message-ID: On Tue, 12 Jan 2021, Grant Edwards wrote: > And those X11 users will swear at you if you override their window > managers configured window placement. Application code should not care > about or try to control window geometry. Period. Grant, Since this application is my own business use those users can swear all they want. :-) If I decide to post all the code on github other can modify it to their heart's delight. They can even make it work on their wrist computer (formerly known as a wrist watch.) Regards, Rich From ikorot01 at gmail.com Tue Jan 12 14:16:45 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 12 Jan 2021 13:16:45 -0600 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: Hi, Grant, On Tue, Jan 12, 2021 at 12:47 PM Grant Edwards wrote: > > On 2021-01-12, Rich Shepard wrote: > > On Tue, 12 Jan 2021, Igor Korot wrote: > > > >> Keep in mind that if you target Linux, the "modern" window server > >> (Wayland) will not allow user code to decide the positioning and size of > >> the TLW. > > > > Igor, > > > > I suspect that Slackware will continue with X11. > > And those X11 users will swear at you if you override their window > managers configured window placement. Application code should not care > about or try to control window geometry. Period. I have a very strong argument against it!! Imagine you are developing an application that need to communicate with the database. Also imagine this application will be used by millions of users inside different companies. SInce the application will require DB access you will need a dialog to ask for credentials. I, personally, would be very surprised if such dialog would appear somewhere at the bottom of the screen, as dialogs ARE TLWs (top level windows). Wouldn't you? So why I somewhat agree with such a notion - it is not always a useful feature. Also, such an algorithm better allow me to save and restore the geometry of the TLW. Thank you. > > -- > Grant > > > > > > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Tue Jan 12 14:18:34 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 12 Jan 2021 13:18:34 -0600 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: Hi, Rich, On Tue, Jan 12, 2021 at 12:52 PM Rich Shepard wrote: > > On Tue, 12 Jan 2021, Igor Korot wrote: > > > Maybe. :-) > > But it looks Wayland becomes more and more popular. > > Igor, > > What I've read from those struggling to use Wayland, it may turn out to be a > popular as systemd. :-) > > It's important to remember that while all progress involves change, not all > change involves progress. 200% agree. See my reply to Grant. Thank you. > > Regards, > > Rich > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Jan 12 14:30:38 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2021 06:30:38 +1100 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: On Wed, Jan 13, 2021 at 6:18 AM Igor Korot wrote: > > Hi, Grant, > > On Tue, Jan 12, 2021 at 12:47 PM Grant Edwards > wrote: > > > > On 2021-01-12, Rich Shepard wrote: > > > On Tue, 12 Jan 2021, Igor Korot wrote: > > > > > >> Keep in mind that if you target Linux, the "modern" window server > > >> (Wayland) will not allow user code to decide the positioning and size of > > >> the TLW. > > > > > > Igor, > > > > > > I suspect that Slackware will continue with X11. > > > > And those X11 users will swear at you if you override their window > > managers configured window placement. Application code should not care > > about or try to control window geometry. Period. > > I have a very strong argument against it!! > > Imagine you are developing an application that need to communicate > with the database. > Also imagine this application will be used by millions of users inside > different companies. > > SInce the application will require DB access you will need a dialog to > ask for credentials. > > I, personally, would be very surprised if such dialog would appear > somewhere at the bottom of the screen, > as dialogs ARE TLWs (top level windows). > > Wouldn't you? Yes, I would too - because I have my window manager configured to place that dialog where *I* want it, not where the application developer chose to put it. > So why I somewhat agree with such a notion - it is not always a useful feature. > Also, such an algorithm better allow me to save and restore the > geometry of the TLW. Why save and restore the geometry when the window manager can do a better job of positioning it? Give the WM the hints it needs, then let it figure out the placement. Consider that the last time your window was opened, I might have had one 1366x768 monitor, but now I have four - 1920x1080, 1920x1080, 1280x1024, and 1600x900. Where should your dialog go? Not your problem, because my WM knows and understands. (That's actually a 100% realistic scenario, given that I'm usually on my desktop system, but occasionally I'll be on my laptop, SSH'd in with X11 forwarding.) ChrisA From ikorot01 at gmail.com Tue Jan 12 15:00:02 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 12 Jan 2021 14:00:02 -0600 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: Hi, Chris, On Tue, Jan 12, 2021 at 1:33 PM Chris Angelico wrote: > > On Wed, Jan 13, 2021 at 6:18 AM Igor Korot wrote: > > > > Hi, Grant, > > > > On Tue, Jan 12, 2021 at 12:47 PM Grant Edwards > > wrote: > > > > > > On 2021-01-12, Rich Shepard wrote: > > > > On Tue, 12 Jan 2021, Igor Korot wrote: > > > > > > > >> Keep in mind that if you target Linux, the "modern" window server > > > >> (Wayland) will not allow user code to decide the positioning and size of > > > >> the TLW. > > > > > > > > Igor, > > > > > > > > I suspect that Slackware will continue with X11. > > > > > > And those X11 users will swear at you if you override their window > > > managers configured window placement. Application code should not care > > > about or try to control window geometry. Period. > > > > I have a very strong argument against it!! > > > > Imagine you are developing an application that need to communicate > > with the database. > > Also imagine this application will be used by millions of users inside > > different companies. > > > > SInce the application will require DB access you will need a dialog to > > ask for credentials. > > > > I, personally, would be very surprised if such dialog would appear > > somewhere at the bottom of the screen, > > as dialogs ARE TLWs (top level windows). > > > > Wouldn't you? > > Yes, I would too - because I have my window manager configured to > place that dialog where *I* want it, not where the application > developer chose to put it. So, how do *you* distinguish between such dialog and all other dialogs an application might raise (open/save dialogs. font selection dialog, user warning thing). Because with my scenario there are 2 TLWs in the picture - main frame and dialog for credentials. Besides it looks like you are setting this dialog to appear at constant position anyway. Or am I missing smth? > > > So why I somewhat agree with such a notion - it is not always a useful feature. > > Also, such an algorithm better allow me to save and restore the > > geometry of the TLW. > > Why save and restore the geometry when the window manager can do a > better job of positioning it? Give the WM the hints it needs, then let > it figure out the placement. Because I want this application to appear at the same place every time? The first time it shows I may just drag it away or minimize it at some point or make it very small to clear the space. And the next time I want it to start at the same position. > > Consider that the last time your window was opened, I might have had > one 1366x768 monitor, but now I have four - 1920x1080, 1920x1080, > 1280x1024, and 1600x900. Where should your dialog go? Not your > problem, because my WM knows and understands. There is a notion of the "primary display" which is here for a reason. ;-) So you can attach/detach as many monitors as you want - in the end if the monitor is not available and that window will appear on the primary monitor. > > (That's actually a 100% realistic scenario, given that I'm usually on > my desktop system, but occasionally I'll be on my laptop, SSH'd in > with X11 forwarding.) Absolutely. I found myself in this situation recently - when I'm in the office I have 2 external monitors, and when I am at home - I only have a laptop. And windows are showing on the primary all the time. Thank you. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From cs at cskk.id.au Tue Jan 12 16:46:57 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jan 2021 08:46:57 +1100 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 12Jan2021 15:18, Grant Edwards wrote: >On 2021-01-12, songbird wrote: >> it can be used for pretty much anything except perhaps >> high pressure real time things, but i bet someone else will >> know that is being done too, i've just not heard of it. :) > >AFAIK, Python can't be used to write device drivers for any popular OS >(Linux, Unix, Windows, OSX). It also can't be used on small embedded >systems (real-time or not). Well, yes and no. Not a pure device driver. But there are systems like FUSE for hooking kernel level filesystem stuff to an external system programme. I've used the Python llfuse library to implement a filesystem in Python. Cheers, Cameron Simpson From cs at cskk.id.au Tue Jan 12 16:53:02 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 13 Jan 2021 08:53:02 +1100 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 12Jan2021 10:40, Michael F. Stemper wrote: >On 11/01/2021 14.37, DonK wrote: >>I've installed Python 3.7, the PyCharm IDE and watched some Youtube >>tutorials > >I would suggest that instead of watching tutorials, you open up your IDE >and start writing stuff. I would second that. Maybe this is a congnitive shortcoming on my part, but I find videos not useful for learning new programming. What they are great for is seeing explicit examples of something you are doing, particular if you hit some block and need to see someone _do_ what you're failing to do. They're great for physical repair though, which again is an explicit example of a particular fixed task. Repaired our stand mixer with reference to a good video. Would not want to use a video to learn the theory of stand mixer design. Cheers, Cameron Simpson From rosuav at gmail.com Tue Jan 12 17:02:18 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2021 09:02:18 +1100 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: On Wed, Jan 13, 2021 at 7:00 AM Igor Korot wrote: > > Hi, Chris, > > On Tue, Jan 12, 2021 at 1:33 PM Chris Angelico wrote: > > > > On Wed, Jan 13, 2021 at 6:18 AM Igor Korot wrote: > > > > > > Hi, Grant, > > > > > > On Tue, Jan 12, 2021 at 12:47 PM Grant Edwards > > > wrote: > > > > > > > > On 2021-01-12, Rich Shepard wrote: > > > > > On Tue, 12 Jan 2021, Igor Korot wrote: > > > > > > > > > >> Keep in mind that if you target Linux, the "modern" window server > > > > >> (Wayland) will not allow user code to decide the positioning and size of > > > > >> the TLW. > > > > > > > > > > Igor, > > > > > > > > > > I suspect that Slackware will continue with X11. > > > > > > > > And those X11 users will swear at you if you override their window > > > > managers configured window placement. Application code should not care > > > > about or try to control window geometry. Period. > > > > > > I have a very strong argument against it!! > > > > > > Imagine you are developing an application that need to communicate > > > with the database. > > > Also imagine this application will be used by millions of users inside > > > different companies. > > > > > > SInce the application will require DB access you will need a dialog to > > > ask for credentials. > > > > > > I, personally, would be very surprised if such dialog would appear > > > somewhere at the bottom of the screen, > > > as dialogs ARE TLWs (top level windows). > > > > > > Wouldn't you? > > > > Yes, I would too - because I have my window manager configured to > > place that dialog where *I* want it, not where the application > > developer chose to put it. > > So, how do *you* distinguish between such dialog and all other dialogs > an application might raise (open/save dialogs. font selection dialog, user > warning thing). > > Because with my scenario there are 2 TLWs in the picture - main frame and > dialog for credentials. > > Besides it looks like you are setting this dialog to appear at constant position > anyway. Or am I missing smth? Hmm, maybe I'm missing something. The initial window isn't a "dialog", it's an application window. They follow slightly different rules (mainly, they don't have a parent window), but they still follow *rules*. > > > So why I somewhat agree with such a notion - it is not always a useful feature. > > > Also, such an algorithm better allow me to save and restore the > > > geometry of the TLW. > > > > Why save and restore the geometry when the window manager can do a > > better job of positioning it? Give the WM the hints it needs, then let > > it figure out the placement. > > Because I want this application to appear at the same place every time? > The first time it shows I may just drag it away or minimize it at some point or > make it very small to clear the space. > > And the next time I want it to start at the same position. And I find that most apps that behave this way end up being more annoying than not. > > Consider that the last time your window was opened, I might have had > > one 1366x768 monitor, but now I have four - 1920x1080, 1920x1080, > > 1280x1024, and 1600x900. Where should your dialog go? Not your > > problem, because my WM knows and understands. > > There is a notion of the "primary display" which is here for a reason. ;-) > So you can attach/detach as many monitors as you want - in the end if > the monitor is not available and that window will appear on the primary monitor. In the second scenario, the primary monitor is at position (1920, 0). So you've just described exactly what a window manager does - follow rules to decide where the window appears - and NOT what happens if you remember geometry, which would be to put the window somewhere in the top left. You see the problem with remembering geometry? > > (That's actually a 100% realistic scenario, given that I'm usually on > > my desktop system, but occasionally I'll be on my laptop, SSH'd in > > with X11 forwarding.) > > Absolutely. > I found myself in this situation recently - when I'm in the office I > have 2 external > monitors, and when I am at home - I only have a laptop. > And windows are showing on the primary all the time. > Right! That's the WM's job. Let it do its job, and everyone's lives will be easier. ChrisA From grant.b.edwards at gmail.com Tue Jan 12 14:28:26 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 12 Jan 2021 19:28:26 -0000 (UTC) Subject: A beginning beginner's question about input, output and . . . References: Message-ID: On 2021-01-12, Chris Angelico wrote: > * Command-line calculator - pressing Ctrl-Alt-P will open up a > terminal with Python, and that's the normal way that I do quick > calculations I do that a lot too. -- Grant From ikorot01 at gmail.com Tue Jan 12 17:29:50 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 12 Jan 2021 16:29:50 -0600 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: Hi, Chris, On Tue, Jan 12, 2021 at 4:05 PM Chris Angelico wrote: > > On Wed, Jan 13, 2021 at 7:00 AM Igor Korot wrote: > > > > Hi, Chris, > > > > On Tue, Jan 12, 2021 at 1:33 PM Chris Angelico wrote: > > > > > > On Wed, Jan 13, 2021 at 6:18 AM Igor Korot wrote: > > > > > > > > Hi, Grant, > > > > > > > > On Tue, Jan 12, 2021 at 12:47 PM Grant Edwards > > > > wrote: > > > > > > > > > > On 2021-01-12, Rich Shepard wrote: > > > > > > On Tue, 12 Jan 2021, Igor Korot wrote: > > > > > > > > > > > >> Keep in mind that if you target Linux, the "modern" window server > > > > > >> (Wayland) will not allow user code to decide the positioning and size of > > > > > >> the TLW. > > > > > > > > > > > > Igor, > > > > > > > > > > > > I suspect that Slackware will continue with X11. > > > > > > > > > > And those X11 users will swear at you if you override their window > > > > > managers configured window placement. Application code should not care > > > > > about or try to control window geometry. Period. > > > > > > > > I have a very strong argument against it!! > > > > > > > > Imagine you are developing an application that need to communicate > > > > with the database. > > > > Also imagine this application will be used by millions of users inside > > > > different companies. > > > > > > > > SInce the application will require DB access you will need a dialog to > > > > ask for credentials. > > > > > > > > I, personally, would be very surprised if such dialog would appear > > > > somewhere at the bottom of the screen, > > > > as dialogs ARE TLWs (top level windows). > > > > > > > > Wouldn't you? > > > > > > Yes, I would too - because I have my window manager configured to > > > place that dialog where *I* want it, not where the application > > > developer chose to put it. > > > > So, how do *you* distinguish between such dialog and all other dialogs > > an application might raise (open/save dialogs. font selection dialog, user > > warning thing). > > > > Because with my scenario there are 2 TLWs in the picture - main frame and > > dialog for credentials. > > > > Besides it looks like you are setting this dialog to appear at constant position > > anyway. Or am I missing smth? > > Hmm, maybe I'm missing something. The initial window isn't a "dialog", > it's an application window. They follow slightly different rules > (mainly, they don't have a parent window), but they still follow > *rules*. Not sure I follow - frame is a TLW. Dialog is a TLW. Program flow is as follows: 1. Program starts with a frame 2. At some point the user asks to connect to the database. 3. Credentials dialog is shown. Now, while frame is TLW and may follow the renderer rules, the dialog that vask the user for credentials should not. Now, system dialog should probably follow the rules of the WM, but if I want my dialog to appear centered on the parent (not on the screen) - what right the WM have to override it? I also think that ALL dialogs are TLWs independently of whether they are created with the actual parent (frame) or a null-parent (desktop). In regards that they are not buttons/list controls/toolbars/etc. > > > > > So why I somewhat agree with such a notion - it is not always a useful feature. > > > > Also, such an algorithm better allow me to save and restore the > > > > geometry of the TLW. > > > > > > Why save and restore the geometry when the window manager can do a > > > better job of positioning it? Give the WM the hints it needs, then let > > > it figure out the placement. > > > > Because I want this application to appear at the same place every time? > > The first time it shows I may just drag it away or minimize it at some point or > > make it very small to clear the space. > > > > And the next time I want it to start at the same position. > > And I find that most apps that behave this way end up being more > annoying than not. Well its just a matter of opinion than. ;-) > > > > Consider that the last time your window was opened, I might have had > > > one 1366x768 monitor, but now I have four - 1920x1080, 1920x1080, > > > 1280x1024, and 1600x900. Where should your dialog go? Not your > > > problem, because my WM knows and understands. > > > > There is a notion of the "primary display" which is here for a reason. ;-) > > So you can attach/detach as many monitors as you want - in the end if > > the monitor is not available and that window will appear on the primary monitor. > > In the second scenario, the primary monitor is at position (1920, 0). > So you've just described exactly what a window manager does - follow > rules to decide where the window appears - and NOT what happens if you > remember geometry, which would be to put the window somewhere in the > top left. You see the problem with remembering geometry? Are you talking about geometry or a position? For me geometry is a complex thing - position, size of the window and the client size of the window (which is important especially in *nix). > > > > (That's actually a 100% realistic scenario, given that I'm usually on > > > my desktop system, but occasionally I'll be on my laptop, SSH'd in > > > with X11 forwarding.) > > > > Absolutely. > > I found myself in this situation recently - when I'm in the office I > > have 2 external > > monitors, and when I am at home - I only have a laptop. > > And windows are showing on the primary all the time. > > > > Right! That's the WM's job. Let it do its job, and everyone's lives > will be easier. Well, please re-read my initial statement. You can't decide where to put that credential dialog. It has to appear in the middle of the screen (if there is 1 - on it, if multiple - on the screen where the main frame is). DO you see the problem with that? Thank you. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Jan 12 17:35:32 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2021 09:35:32 +1100 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: On Wed, Jan 13, 2021 at 9:30 AM Igor Korot wrote: > > Not sure I follow - frame is a TLW. Dialog is a TLW. > Program flow is as follows: > > 1. Program starts with a frame > 2. At some point the user asks to connect to the database. > 3. Credentials dialog is shown. > > Now, while frame is TLW and may follow the renderer rules, the dialog > that vask the user for credentials should not. > > Now, system dialog should probably follow the rules of the WM, but if I want my > dialog to appear centered on the parent (not on the screen) - what > right the WM have > to override it? > > I also think that ALL dialogs are TLWs independently of whether they > are created with > the actual parent (frame) or a null-parent (desktop). > In regards that they are not buttons/list controls/toolbars/etc. In one sense you're right, but in another, the creation of a window with a parent is very different from the creation of a window without a parent. The WM will handle them differently because the user will expect them to behave differently. In fact, centering on the parent is a very likely position, so don't worry about it - just declare your parent correctly. > Are you talking about geometry or a position? > For me geometry is a complex thing - position, size of the window and > the client size > of the window (which is important especially in *nix). The size of the window is generally governed by its contents, so that's under the application's control (within limits set by the WM). The position, though, is up to the WM. > > > > (That's actually a 100% realistic scenario, given that I'm usually on > > > > my desktop system, but occasionally I'll be on my laptop, SSH'd in > > > > with X11 forwarding.) > > > > > > Absolutely. > > > I found myself in this situation recently - when I'm in the office I > > > have 2 external > > > monitors, and when I am at home - I only have a laptop. > > > And windows are showing on the primary all the time. > > > > > > > Right! That's the WM's job. Let it do its job, and everyone's lives > > will be easier. > > Well, please re-read my initial statement. > You can't decide where to put that credential dialog. It has to appear > in the middle > of the screen (if there is 1 - on it, if multiple - on the screen > where the main frame is). > > DO you see the problem with that? Yes, I see a problem with the application trying to remember where the dialog was last time. A MAJOR problem. Restoring the dialog's geometry might have it completely off screen, or at best, in a position that is decidedly unideal. But if you let the WM decide where the dialog should be placed, it's guaranteed to be where the user expects it (or more precisely, it's guaranteed to be consistent with every *other* application that also behaves like this, and the user has the power to configure this). ChrisA From ikorot01 at gmail.com Tue Jan 12 18:02:01 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 12 Jan 2021 17:02:01 -0600 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: Chris, On Tue, Jan 12, 2021 at 4:38 PM Chris Angelico wrote: > > On Wed, Jan 13, 2021 at 9:30 AM Igor Korot wrote: > > > > Not sure I follow - frame is a TLW. Dialog is a TLW. > > Program flow is as follows: > > > > 1. Program starts with a frame > > 2. At some point the user asks to connect to the database. > > 3. Credentials dialog is shown. > > > > Now, while frame is TLW and may follow the renderer rules, the dialog > > that vask the user for credentials should not. > > > > Now, system dialog should probably follow the rules of the WM, but if I want my > > dialog to appear centered on the parent (not on the screen) - what > > right the WM have > > to override it? > > > > I also think that ALL dialogs are TLWs independently of whether they > > are created with > > the actual parent (frame) or a null-parent (desktop). > > In regards that they are not buttons/list controls/toolbars/etc. > > In one sense you're right, but in another, the creation of a window > with a parent is very different from the creation of a window without > a parent. The WM will handle them differently because the user will > expect them to behave differently. In fact, centering on the parent is > a very likely position, so don't worry about it - just declare your > parent correctly. For the dialog (as well as any other TLW), it should be no difference. Because if I pass a "parent" as NULL, it means I have a parent as a "Desktop" window. That's why frames and dialogs are called TLWs - they don't have to have an "explicit" parent. > > > Are you talking about geometry or a position? > > For me geometry is a complex thing - position, size of the window and > > the client size > > of the window (which is important especially in *nix). > > The size of the window is generally governed by its contents, so > that's under the application's control (within limits set by the WM). > The position, though, is up to the WM. And what about client size? Because if we are talking about *nix (which I think we are) you should count decorations. > > > > > > (That's actually a 100% realistic scenario, given that I'm usually on > > > > > my desktop system, but occasionally I'll be on my laptop, SSH'd in > > > > > with X11 forwarding.) > > > > > > > > Absolutely. > > > > I found myself in this situation recently - when I'm in the office I > > > > have 2 external > > > > monitors, and when I am at home - I only have a laptop. > > > > And windows are showing on the primary all the time. > > > > > > > > > > Right! That's the WM's job. Let it do its job, and everyone's lives > > > will be easier. > > > > Well, please re-read my initial statement. > > You can't decide where to put that credential dialog. It has to appear > > in the middle > > of the screen (if there is 1 - on it, if multiple - on the screen > > where the main frame is). > > > > DO you see the problem with that? > > Yes, I see a problem with the application trying to remember where the > dialog was last time. A MAJOR problem. Restoring the dialog's geometry > might have it completely off screen, or at best, in a position that is > decidedly unideal. But if you let the WM decide where the dialog > should be placed, it's guaranteed to be where the user expects it (or > more precisely, it's guaranteed to be consistent with every *other* > application that also behaves like this, and the user has the power to > configure this). In this particular case there is no need to remember - credentials dialog need to appear at the center of the monitor 0 and they should be sized accordingly. Now here are the scenarios I'm looking at: 1. Program starts - credentials dialog is shown. The parent of this dialog is "Desktop" window. It is better to be displayed in the center of the "Monitor 0". 2. Program start - frame is shown. I agree that it is best to let the WM decide its position. At some point of time I need to connect to the DB and so credential dialog is shown. In this scenario this dialog should also be shown "Monitor 0" centered. 3. Start with scenario 2. Resize the frame and exit the application. Attach the new monitor. Start the application again. Frame will probably appear on "Monitor 0" (depending on the WM rules). Start the DB connection. The credentials dialog should appear centered on the screen where the frame is. As you can see none of those scenarios include system dialogs (open/save, font selection, etc). They has to follow system/WM rules and appear as appropriate. Because they are system based and user code shouldn't say anything about their positioning. But for my dialogs (especially for dialogs where I need to ask for credentials) - I don't think I want WM to do my job. Again - we are talking positioning here and not size/client size. Thank you. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Jan 12 18:07:23 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 13 Jan 2021 10:07:23 +1100 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: On Wed, Jan 13, 2021 at 10:02 AM Igor Korot wrote: > But for my dialogs (especially for dialogs where I need to ask for > credentials) - I don't think I want > WM to do my job. > > Again - we are talking positioning here and not size/client size. > And I don't think I want you to do the WM's job. You're welcome to keep going to great effort to do the wrong thing, but be aware that nobody will appreciate the work you're doing, and in fact are more likely to curse you for it. Just save yourself a LOT of hassle and let the WM do its job. It knows the user's wishes better than you do. ChrisA From greg.ewing at canterbury.ac.nz Wed Jan 13 00:16:34 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 13 Jan 2021 18:16:34 +1300 Subject: argparse presence of switch In-Reply-To: References: <20f77a6a-0331-4455-a7bd-05901e014994n@googlegroups.com> Message-ID: On 13/01/21 7:13 am, Chris Angelico wrote: > This is what different actions are for. I'd probably use > action="store_true" here; that should mean that args.register will be > set to True if "-r" was passed, or False if it wasn't. Yes, otherwise it expects another argument following -r containing a value. -- Greg From greg.ewing at canterbury.ac.nz Wed Jan 13 00:24:03 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Wed, 13 Jan 2021 18:24:03 +1300 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 13/01/21 4:18 am, Grant Edwards wrote: > AFAIK, Python can't be used to write device drivers for any popular OS At least not until some crazy person embeds Python in the Linux kernel... -- Greg From auriocus at gmx.de Wed Jan 13 01:57:21 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Wed, 13 Jan 2021 07:57:21 +0100 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: Am 13.01.21 um 06:24 schrieb Greg Ewing: > On 13/01/21 4:18 am, Grant Edwards wrote: > >> AFAIK, Python can't be used to write device drivers for any popular OS > > At least not until some crazy person embeds Python in the > Linux kernel... What do you mean, "until" ? https://medium.com/@yon.goldschmidt/running-python-in-the-linux-kernel-7cbcbd44503c http://www.kplugs.org/ Christian From grimble at nomail.afraid.org Wed Jan 13 10:31:44 2021 From: grimble at nomail.afraid.org (Grimble) Date: Wed, 13 Jan 2021 15:31:44 +0000 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 11/01/2021 20:37, DonK wrote: > > > > So, what do you folks use Python for? > > I've written a shopping list script with auto-completion and a couple of web-scraping applications that support a weather reporting application interfacing with various 1Wire sensors transcribed from an initial Ruby application. My largest GUI application is a database of personal contacts with input and output of data via vCards and .csv files (with a lot of mentoring from an American Gtk user!) I find this a fascinating news group - shame there's been no updates to Friday Finking recently -- Grimble Registered Linux User #450547 Machine 'Bach' running Plasma 5.15.4 on 5.7.19-desktop-3.mga7 kernel. Mageia release 7 (Official) for x86_64 From songbird at anthive.com Wed Jan 13 10:37:39 2021 From: songbird at anthive.com (songbird) Date: Wed, 13 Jan 2021 10:37:39 -0500 Subject: conceptual problem (was: A beginning beginner's question about input, output and . . . References: Message-ID: <3ng3dh-kha.ln1@anthive.com> Chris Angelico wrote: ...projects that fade... > That's not really something Python can ever control, but I can say > with some confidence that the big libraries like Qt and GTK are going > to adapt, one way or another. And perhaps more importantly: Neither > input()/print() nor web applications is going *anywhere*. You are > ALWAYS going to have those two as options. :) i hope so. :) at the moment i've only done things with GTK and pyglet. since i am way too new at python i can't say the code is pretty, but it does work. my momentary conceptual problem is that to me OOP means being able to encapsulate data structures and code from other parts of the program, but to me it doesn't look like that is how python is designed. this is probably a complete aside to this whole thread and perhaps even this newsgroup so i'll subthread this. songbird From songbird at anthive.com Wed Jan 13 10:24:21 2021 From: songbird at anthive.com (songbird) Date: Wed, 13 Jan 2021 10:24:21 -0500 Subject: A beginning beginner's question about input, output and . . . References: Message-ID: <5uf3dh-kha.ln1@anthive.com> Christian Gollwitzer wrote: > Am 13.01.21 um 06:24 schrieb Greg Ewing: >> On 13/01/21 4:18 am, Grant Edwards wrote: >> >>> AFAIK, Python can't be used to write device drivers for any popular OS >> >> At least not until some crazy person embeds Python in the >> Linux kernel... > > > What do you mean, "until" ? > > https://medium.com/@yon.goldschmidt/running-python-in-the-linux-kernel-7cbcbd44503c > > http://www.kplugs.org/ yes! haha! :) love it! wish i had time to play now. songbird From grimble at nomail.afraid.org Wed Jan 13 10:54:10 2021 From: grimble at nomail.afraid.org (Grimble) Date: Wed, 13 Jan 2021 15:54:10 +0000 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 11/01/2021 20:37, DonK wrote: > > Hi, I'm thinking about learning Python but I'm 74 years old and will > very likely not ever have a programming job again. At 83, I have no intention of having a programming job again! I last coded something professionally 45 years ago, but it hasn't lost its attraction. > So, what do you folks use Python for? > I have several scripts to help with activities for the charity that keeps me occupied. I've written a shopping list script with auto-completion and a couple of web-scraping applications that support a weather reporting application interfacing with various 1Wire sensors transcribed from an initial Ruby application. My largest GUI application is a database of personal contacts with input and output of data via vCards and .csv files (with a lot of mentoring from an American Gtk user!) I find this a fascinating news group - shame there's been no updates to Friday Finking recently! -- Grimble Registered Linux User #450547 Machine 'Bach' running Plasma 5.15.4 on 5.7.19-desktop-3.mga7 kernel. Mageia release 7 (Official) for x86_64 From pkpearson at nowhere.invalid Wed Jan 13 16:01:52 2021 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 13 Jan 2021 21:01:52 GMT Subject: A beginning beginner's question about input, output and . . . References: Message-ID: On Mon, 11 Jan 2021 15:37:58 -0500, DonK wrote: [snip] > > I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they > look kinda like adding a family room onto a 1986 double wide mobile > home, Agreed. Browsergui is not widely popular (I don't think anybody but me has mentioned it on this newsgroup), but it was written to be simple and Pythonic, and has served me well. Browsergui just uses your browser as its user interface. Grab it from https://github.com/speezepearson/browsergui then run "python -m browsergui.examples". (Disclaimer/boast: I'm related to Browsergui's author.) -- To email me, substitute nowhere->runbox, invalid->com. From cs at cskk.id.au Wed Jan 13 17:49:40 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Thu, 14 Jan 2021 09:49:40 +1100 Subject: conceptual problem (was: A beginning beginner's question about input, output and . . . In-Reply-To: <3ng3dh-kha.ln1@anthive.com> References: <3ng3dh-kha.ln1@anthive.com> Message-ID: On 13Jan2021 10:37, songbird wrote: > my momentary conceptual problem is that to me OOP means >being able to encapsulate data structures and code from >other parts of the program, but to me it doesn't look like >that is how python is designed. this is probably a complete >aside to this whole thread and perhaps even this newsgroup >so i'll subthread this. Python allows you to avoid mucking with the object internals from outside. But it doesn't prevent it. So you can (and often should) adopt an OOP approach - it reduces the dependencies between your classes, with the benefits that brings. The "pure" OOP approach, where method calls are used as messages to set or fetch aspects of the object, is usually does with getter and setter methods like: x = o.getX() o.setX(9) In Python this is less common. Simple things like that which do not intrude much on the conceptual model (i.e. if all such things will have an "X") are usually exposed as a public attribute which you can get or set directly: x = o.x o.x = 9 "Public" attributes in Python are just a convention: we name "private" attributes with a leading underscore and "public" attributes with leading letters and expect people using our classes to behave well. Sometime we _don't_ have a plain old attribute "x", but we do have a property of the object looking like it. Then you can implement something which looks like an attribute from outside: @property def x(self): # "x" if a derived value return self._a + self._b @x.setter def x(self, new_x): # setting "x" gets split between _a and _b x2 = x / 3 self._a = x2 # put some in _a self._b = x - x2 # put the rest in _b # you can still do this, but it calls methods now x = o.x o.x = 9 So Python supports OOP practices but doesn't enforce them. Adopt the degree of discipline you think best. Cheers, Cameron Simpson From philb at philb.ca Wed Jan 13 17:49:28 2021 From: philb at philb.ca (Phil Boutros) Date: Wed, 13 Jan 2021 22:49:28 -0000 (UTC) Subject: learning python building 2nd app, need advices References: <3170f050-4d37-4a64-96cb-f3718a3ef2aan@googlegroups.com> <6da92d5c-29c9-45b6-9078-5f1fef7a1b34n@googlegroups.com> <37329709-b300-4c1e-af88-8ed0d6de588bn@googlegroups.com> <878s8zn0ol.fsf@hornfels.zedat.fu-berlin.de> Message-ID: Loris Bennett wrote: > As an Emacs user, personally I would use the command > > M-x untabify > > within Emacs. I assume that Vim has something similar. It does. ':retab' is what you want. If you have tabstop set to a specific value, it'll use that. If not, you can do ':retab ', where is an integer defining how many spaces to replace a tab with. Don't add the quote symbols ('), I added it for readability! As others have mentionned, 'expand' from the shell also works. Phil -- AH#61 Wolf#14 BS#89 bus#1 CCB#1 SENS KOTC#4 philb at philb.ca http://philb.ca From PythonList at DancesWithMice.info Wed Jan 13 19:06:54 2021 From: PythonList at DancesWithMice.info (dn) Date: Thu, 14 Jan 2021 13:06:54 +1300 Subject: FridayFinking - Was: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 14/01/2021 04.54, Grimble wrote: > On 11/01/2021 20:37, DonK wrote: >> >> Hi, I'm thinking about learning Python but I'm 74 years old and will >> very likely not ever have a programming job again. > At 83, I have no intention of having a programming job again! I last > coded something professionally 45 years ago, but it hasn't lost its > attraction. Hey, some 'silver surfers' who have a few years on me! Concerning the definition of "old" - when I'm having a 'good day', it's anyone several years my senior (and above) - when I'm creaking and groaning, it's anyone remotely my age, and older. Of course, many of my colleagues have fairly similar understandings - for them anyone with the digit "3" (or greater) at the front of their age, is not so much old (saying that would be rude!), but "ancient"! That said, such young-bucks wrestling with cloud-concepts today, were totally nonplussed when I told them how (mainframe) computer bureaux used to work. The 'mechanics' may be different, but the management is little-changed! ... > I find this a fascinating news group - shame there's been no updates to > Friday Finking recently! With all due apologies! I work(ed) with a particular team in a mentoring r?le, handling reviews, walk-throughs, some design meetings, Python version-upgrades coaching, etc. One of these was a 'morning tea' meeting, when we would discuss/debate/argue 'Python best practice' topics, either raised by members or that arose from other meetings but were best not discussed there-and-then. If there was an interesting topic, or one that 'we' hadn't really settled satisfactorily within the group, I would try to re-frame the discussion, and consult 'the oracles' here. So, that's the raison d'?tre and motivation of the "Friday Finking" series.. Then along came COVID-19, and although this country's response was amongst the best in the world, the team (and its routines) all-but fell-apart. Firstly, we had to adjust to working remotely. The effort that went into 'Friday Finking' was quickly absorbed into figuring-out remote-techniques and maintaining the social component of the team's success. Then a bunch of us were 'released to other duties' and landed-in high-pressure projects to do with modelling pandemic response-options. Various other interventions, life moved-on, etc, etc - stories familiar to most, I'm sure. So, thank you for the gentle reminder. Even though that team is still not meeting as it once did, there's plenty of other 'inspiration', eg a parallel discussion 'here' about the virtues of a programmer positioning dialog(ue)s/windows or leaving it to the window manager... I'll give it some thought - as long as Fridays keep coming! -- Regards =dn From Bischoop at vimart.net Wed Jan 13 16:20:32 2021 From: Bischoop at vimart.net (Bischoop) Date: Wed, 13 Jan 2021 21:20:32 -0000 (UTC) Subject: count consecutive elements Message-ID: I want to to display a number or an alphabet which appears mostly consecutive in a given string or numbers or both Examples s= ' aabskaaabadcccc' output: c # c appears 4 consecutive times 8bbakebaoa output: b #b appears 2 consecutive times I thought about set the string then and for each element loop the string to check if equal with element set element if so count =+1 and check if next to it is not equal add counter value to list with same index as in set. However I'm fighting to code it and the counting numbers are not right: s = 'aabskaaabadcccc' c = 0 t = set(s) # set of characters in s li=[0,0,0,0,0,0] # list for counted repeats for x in t: h = t.index(x) for i in s: if i == x: m = s.index(i) c +=1 if s[m+1] != x: # if next element is not x if c > li[h]: li[h]= c c = 0 for i in t: n = t.index(i) print(i,li[n]) -- Thanks From grant.b.edwards at gmail.com Wed Jan 13 16:46:08 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 13 Jan 2021 21:46:08 -0000 (UTC) Subject: A beginning beginner's question about input, output and . . . References: Message-ID: On 2021-01-13, Peter Pearson wrote: > On Mon, 11 Jan 2021 15:37:58 -0500, DonK wrote: > [snip] >> >> I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they >> look kinda like adding a family room onto a 1986 double wide mobile >> home, > > Agreed. > > Browsergui is not widely popular (I don't think anybody but me has > mentioned it on this newsgroup), but it was written to be simple and > Pythonic, and has served me well. Browsergui just uses your browser as > its user interface. Grab it from > > https://github.com/speezepearson/browsergui I've been browsing through to documentation and examples, and I don't see any way to do any sort of modern flexible layout (e.g. nesting horizontal and vertical flexboxes) where you can control which elements grow/shrink when the window size changes. Is there a way to span columns/rows in a grid or control which columns grow/shrink? Have I missed something? -- Grant From Bischoop at vimart.net Wed Jan 13 16:48:26 2021 From: Bischoop at vimart.net (Bischoop) Date: Wed, 13 Jan 2021 21:48:26 -0000 (UTC) Subject: count consecutive elements References: Message-ID: On 2021-01-13, Bischoop wrote: > t = set(s) # set of characters in s I have this one changed to: t= list(set(s)) From grant.b.edwards at gmail.com Wed Jan 13 17:09:00 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 13 Jan 2021 22:09:00 -0000 (UTC) Subject: A beginning beginner's question about input, output and . . . References: Message-ID: On 2021-01-13, Dennis Lee Bieber wrote: > On Tue, 12 Jan 2021 15:18:05 -0000 (UTC), Grant Edwards > declaimed the following: >>On 2021-01-12, songbird wrote: >> >>> it can be used for pretty much anything except perhaps high >>> pressure real time things, but i bet someone else will know that >>> is being done too, i've just not heard of it. :) >> >>AFAIK, Python can't be used to write device drivers for any popular OS >>(Linux, Unix, Windows, OSX). It also can't be used on small embedded >>systems (real-time or not). > > MicroPython/Circuit Python. Native language for AdaFruit's Metro > boards. Those are very cool, and I've come this -><- close to ordering one in the past. Perhaps I need to recalibrate my adjectives, but with 256KB+ of flash and 32KB+ of RAM, I wouldn't call them "small" -- even though the Trinket M0 is physically tiny. But that may just be my age showing. I remember not _that_ long ago working on processors where the RAM was measured in hundreds of bytes. And I still maintain code for ARM parts with way less than 1/10 the memory of the Trinket M0. -- Grant From rshepard at appl-ecosys.com Wed Jan 13 19:26:46 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Wed, 13 Jan 2021 16:26:46 -0800 (PST) Subject: FridayFinking - Was: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On Thu, 14 Jan 2021, dn via Python-list wrote: > Concerning the definition of "old" > - when I'm having a 'good day', it's anyone several years my senior (and > above) > - when I'm creaking and groaning, it's anyone remotely my age, and older. About 45 years ago a 25-year-older friend of mine offered a great philosophy of life. "We can do nothing about growing older," she told me, "but we can do everything about growing old." How true. Rich From greg.ewing at canterbury.ac.nz Wed Jan 13 19:39:21 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 14 Jan 2021 13:39:21 +1300 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 13/01/21 7:57 pm, Christian Gollwitzer wrote: > ?What do you mean, "until" ? > > https://medium.com/@yon.goldschmidt/running-python-in-the-linux-kernel-7cbcbd44503c He's using Micropython. That's cheating! :-) -- Greg From python at bladeshadow.org Wed Jan 13 19:50:58 2021 From: python at bladeshadow.org (Python) Date: Wed, 13 Jan 2021 18:50:58 -0600 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: <20210114005058.GD31888@bladeshadow.org> On Wed, Jan 13, 2021 at 10:07:23AM +1100, Chris Angelico wrote: > On Wed, Jan 13, 2021 at 10:02 AM Igor Korot wrote: > > But for my dialogs (especially for dialogs where I need to ask for > > credentials) - I don't think I want > > WM to do my job. > > > > Again - we are talking positioning here and not size/client size. > > > > And I don't think I want you to do the WM's job. > > You're welcome to keep going to great effort to do the wrong thing, > but be aware that nobody will appreciate the work you're doing, and in > fact are more likely to curse you for it. Just save yourself a LOT of > hassle and let the WM do its job. It knows the user's wishes better > than you do. I think this is quite very, very far from true. It's been a while since I've used such tools, but I believe it is or was quite common for large, integrated applications like DAWs, graphical design software, etc. to remember where you placed your various floating toolbars and add-ons (and even much more detailed state about how you'd set the various widgets in them), and that users of such applications expect that. Obviously the software needs to be aware of, and compensate for, cases when the available display can't draw the various widgets in visible space on the desktop/canvas/whatever, but if the application wants to do all that, it seems like a perfectly wonderful feature to me. The last thing I want to do is spend 15 minutes to relocate and reconfgure UI elements to where and how I like them before I can even start working on a media project (or whatever). From rosuav at gmail.com Wed Jan 13 19:58:34 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2021 11:58:34 +1100 Subject: Application window geometry specifier In-Reply-To: <20210114005058.GD31888@bladeshadow.org> References: <20210114005058.GD31888@bladeshadow.org> Message-ID: On Thu, Jan 14, 2021 at 11:53 AM Python wrote: > > On Wed, Jan 13, 2021 at 10:07:23AM +1100, Chris Angelico wrote: > > On Wed, Jan 13, 2021 at 10:02 AM Igor Korot wrote: > > > But for my dialogs (especially for dialogs where I need to ask for > > > credentials) - I don't think I want > > > WM to do my job. > > > > > > Again - we are talking positioning here and not size/client size. > > > > > > > And I don't think I want you to do the WM's job. > > > > You're welcome to keep going to great effort to do the wrong thing, > > but be aware that nobody will appreciate the work you're doing, and in > > fact are more likely to curse you for it. Just save yourself a LOT of > > hassle and let the WM do its job. It knows the user's wishes better > > than you do. > > I think this is quite very, very far from true. It's been a while > since I've used such tools, but I believe it is or was quite common > for large, integrated applications like DAWs, graphical design > software, etc. to remember where you placed your various floating > toolbars and add-ons (and even much more detailed state about how > you'd set the various widgets in them), and that users of such > applications expect that. > Have you actually done any research by (a) asking people what they actually prefer, and better still (b) silently watching over someone's shoulder and seeing which one makes people more productive? The results will differ based on whether the user in question has basically just one primary application (an IDE, or some gigantic app like Adobe PhotoShop) that they spend all their time in, or if they're using myriad different applications. Especially in the latter case, it is far FAR better to put control in the user's hands than to try to make the monopoly position work. Of course, if you are a big enough name (like Apple, especially), you can do whatever you like, and people just have to accept it. That's a monopoly for you, and there's no evidence that it's better, just that people learn to live with it. ChrisA From greg.ewing at canterbury.ac.nz Wed Jan 13 20:01:57 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 14 Jan 2021 14:01:57 +1300 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: Message-ID: On 14/01/21 11:09 am, Grant Edwards wrote: > Perhaps I need to recalibrate my adjectives, but with > 256KB+ of flash and 32KB+ of RAM, I wouldn't call them "small" It's small by today's standards, when you consider that multiple GB of RAM is commonplace now in most "real" computers. -- Greg From python at bladeshadow.org Wed Jan 13 19:31:51 2021 From: python at bladeshadow.org (Python) Date: Wed, 13 Jan 2021 18:31:51 -0600 Subject: Application window geometry specifier In-Reply-To: References: Message-ID: <20210114003151.GC31888@bladeshadow.org> On Tue, Jan 12, 2021 at 06:43:39PM -0000, Grant Edwards wrote: > And those X11 users will swear at you if you override their window > managers configured window placement. Application code should not care > about or try to control window geometry. Period. I think this is just plain wrong. If you, the user, want to override what you, the user, configured your window manager to do, for WHATEVER reason your little heart may desire, then the application needs to give you an interface to request it, and rather importantly the WM must necessarily honor it. The policy reallly ought to be: - If the user took the time to specify a geometry, do what it says (i.e. honor the placement the application asks for) - If not but the window manager has something configured for that application/widget/whatever, do what it says - Otherwise, resort to the window manager's default policy Arguably there ought to also be a way for the application to *suggest* a default geometry that the WM can override, but obviously providing a way to force the geometry gives rise to the opportunity for abuse by badly behaved developers. Don't use those apps. Fortunately, at least historically, in practice most X11 window managers more or less did all that anyway. I recall that when I switched to Gnome I had some trouble with this (as in, it just didn't work, generally, even if the relevant app allowed you to specify --geometry or similar), but AFAICT Gnome has long held to the notion that Gnome Gnows better than you do how you should run your apps, so when using Gnome all bets are off. From python at bladeshadow.org Wed Jan 13 20:16:24 2021 From: python at bladeshadow.org (Python) Date: Wed, 13 Jan 2021 19:16:24 -0600 Subject: Application window geometry specifier In-Reply-To: References: <20210114005058.GD31888@bladeshadow.org> Message-ID: <20210114011624.GE31888@bladeshadow.org> On Thu, Jan 14, 2021 at 11:58:34AM +1100, Chris Angelico wrote: > On Thu, Jan 14, 2021 at 11:53 AM Python wrote: > Have you actually done any research by (a) asking people what they > actually prefer, and better still (b) silently watching over someone's > shoulder and seeing which one makes people more productive? As I said, though it's been a long while, I was actually a user of such applications myself. So I can tell you quite authoritatively that in those kinds of apps, *I* absolutely prefer that the app remember where my windows are and what's in them, no contest. And I would always use them alongside a slew of other apps--web browsers, text editors, mail clients, etc... most likely on a separate desktop, if I wasn't mobile, but necessarily on the same one if I was. > The results will differ based on whether the user in question has > basically just one primary application (an IDE, or some gigantic app > like Adobe PhotoShop) that they spend all their time in OK, so you admit that such apps do exist. But I guess you knew that the OP is not writing that sort of application, and know who its intended audience is, and their work habits and preferences... From ikorot01 at gmail.com Wed Jan 13 20:25:04 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 13 Jan 2021 19:25:04 -0600 Subject: Application window geometry specifier In-Reply-To: <20210114003151.GC31888@bladeshadow.org> References: <20210114003151.GC31888@bladeshadow.org> Message-ID: Hi, On Wed, Jan 13, 2021 at 7:12 PM Python wrote: > > On Tue, Jan 12, 2021 at 06:43:39PM -0000, Grant Edwards wrote: > > And those X11 users will swear at you if you override their window > > managers configured window placement. Application code should not care > > about or try to control window geometry. Period. > > I think this is just plain wrong. If you, the user, want to override > what you, the user, configured your window manager to do, for WHATEVER > reason your little heart may desire, then the application needs to > give you an interface to request it, and rather importantly the WM must > necessarily honor it. > > The policy reallly ought to be: > > - If the user took the time to specify a geometry, do what it says > (i.e. honor the placement the application asks for) > - If not but the window manager has something configured for that > application/widget/whatever, do what it says > - Otherwise, resort to the window manager's default policy > > Arguably there ought to also be a way for the application to *suggest* > a default geometry that the WM can override, but obviously providing a > way to force the geometry gives rise to the opportunity for abuse by > badly behaved developers. Don't use those apps. > > Fortunately, at least historically, in practice most X11 window > managers more or less did all that anyway. I recall that when I > switched to Gnome I had some trouble with this (as in, it just didn't > work, generally, even if the relevant app allowed you to specify > --geometry or similar), but AFAICT Gnome has long held to the notion > that Gnome Gnows better than you do how you should run your apps, so > when using Gnome all bets are off. Well, I am running GNOME 3 on top of X11. I didn't preselect or configure any windows positioning in there. My application that I'm developing will be connecting to the database to pull some data. When I tried to connect to Sybase ASE with their own ODBC driver the dialog that asks for credentials shows up in the center of the screen. And this is the position where (and I hope 99.99% of people) expect it to show up. Hopefully this number (99.99%) does include Mr. Angelico,. But my application is maximized right now, so maybe it is centered on the main frame. Anyway that dialog (TLW) is centered. Thank you. > > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Jan 13 20:27:19 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2021 12:27:19 +1100 Subject: Application window geometry specifier In-Reply-To: <20210114003151.GC31888@bladeshadow.org> References: <20210114003151.GC31888@bladeshadow.org> Message-ID: On Thu, Jan 14, 2021 at 12:11 PM Python wrote: > > On Tue, Jan 12, 2021 at 06:43:39PM -0000, Grant Edwards wrote: > > And those X11 users will swear at you if you override their window > > managers configured window placement. Application code should not care > > about or try to control window geometry. Period. > > I think this is just plain wrong. I love how "I think" is allowed to trump decades of usability research. ChrisA From ikorot01 at gmail.com Wed Jan 13 20:29:20 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 13 Jan 2021 19:29:20 -0600 Subject: Application window geometry specifier In-Reply-To: <20210114011624.GE31888@bladeshadow.org> References: <20210114005058.GD31888@bladeshadow.org> <20210114011624.GE31888@bladeshadow.org> Message-ID: Hi, On Wed, Jan 13, 2021 at 7:20 PM Python wrote: > > On Thu, Jan 14, 2021 at 11:58:34AM +1100, Chris Angelico wrote: > > On Thu, Jan 14, 2021 at 11:53 AM Python wrote: > > Have you actually done any research by (a) asking people what they > > actually prefer, and better still (b) silently watching over someone's > > shoulder and seeing which one makes people more productive? > > As I said, though it's been a long while, I was actually a user of > such applications myself. So I can tell you quite authoritatively > that in those kinds of apps, *I* absolutely prefer that the app > remember where my windows are and what's in them, no contest. And I > would always use them alongside a slew of other apps--web browsers, > text editors, mail clients, etc... most likely on a separate desktop, > if I wasn't mobile, but necessarily on the same one if I was. > > > The results will differ based on whether the user in question has > > basically just one primary application (an IDE, or some gigantic app > > like Adobe PhotoShop) that they spend all their time in > > OK, so you admit that such apps do exist. But I guess you knew that > the OP is not writing that sort of application, and know who its > intended audience is, and their work habits and preferences... Unfortunately, this is how Wayland behaves right now. When I tried to complain they said that saving/restoring perspective is in the works. But I sure hope that when people will switch to Wayland that DB credentials dialog I was talking about in the previous reply will still be positioned on the center of the screen. Or even better - on the center of the main frame and not somewhere else. Thank you. > > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Jan 13 20:29:39 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2021 12:29:39 +1100 Subject: Application window geometry specifier In-Reply-To: <20210114011624.GE31888@bladeshadow.org> References: <20210114005058.GD31888@bladeshadow.org> <20210114011624.GE31888@bladeshadow.org> Message-ID: On Thu, Jan 14, 2021 at 12:18 PM Python wrote: > > The results will differ based on whether the user in question has > > basically just one primary application (an IDE, or some gigantic app > > like Adobe PhotoShop) that they spend all their time in > > OK, so you admit that such apps do exist. But I guess you knew that > the OP is not writing that sort of application, and know who its > intended audience is, and their work habits and preferences... > The difference isn't in what's best, but in what people are willing to accept. Just because people roll over and accept the latest Windows, the latest Mac OS, the latest PhotoShop, the latest Gmail, the latest whatever else, doesn't mean that (a) they actually like it, nor (b) it's actually better. (Which are independent.) When someone spends all their life in a single app, they're more likely to learn its particular way of doing things and assume that that's "correct". But that doesn't make it so. ChrisA From ikorot01 at gmail.com Wed Jan 13 20:39:13 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 13 Jan 2021 19:39:13 -0600 Subject: Application window geometry specifier In-Reply-To: References: <20210114005058.GD31888@bladeshadow.org> <20210114011624.GE31888@bladeshadow.org> Message-ID: Chris, On Wed, Jan 13, 2021 at 7:33 PM Chris Angelico wrote: > > On Thu, Jan 14, 2021 at 12:18 PM Python wrote: > > > The results will differ based on whether the user in question has > > > basically just one primary application (an IDE, or some gigantic app > > > like Adobe PhotoShop) that they spend all their time in > > > > OK, so you admit that such apps do exist. But I guess you knew that > > the OP is not writing that sort of application, and know who its > > intended audience is, and their work habits and preferences... > > > > The difference isn't in what's best, but in what people are willing to > accept. Just because people roll over and accept the latest Windows, > the latest Mac OS, the latest PhotoShop, the latest Gmail, the latest > whatever else, doesn't mean that (a) they actually like it, nor (b) > it's actually better. (Which are independent.) > > When someone spends all their life in a single app, they're more > likely to learn its particular way of doing things and assume that > that's "correct". But that doesn't make it so. Correct. But when that same person goes to a different company where a different application is used, he expects it to behave the same. Because the functionality of such application is the same. Wouldn't you? It is called association. "I was working with Application A. Now I'm working with application AA. And application AA behaves very weirdly." Thank you. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Jan 13 20:42:38 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2021 12:42:38 +1100 Subject: Application window geometry specifier In-Reply-To: References: <20210114005058.GD31888@bladeshadow.org> <20210114011624.GE31888@bladeshadow.org> Message-ID: On Thu, Jan 14, 2021 at 12:39 PM Igor Korot wrote: > > Chris, > > On Wed, Jan 13, 2021 at 7:33 PM Chris Angelico wrote: > > > > On Thu, Jan 14, 2021 at 12:18 PM Python wrote: > > > > The results will differ based on whether the user in question has > > > > basically just one primary application (an IDE, or some gigantic app > > > > like Adobe PhotoShop) that they spend all their time in > > > > > > OK, so you admit that such apps do exist. But I guess you knew that > > > the OP is not writing that sort of application, and know who its > > > intended audience is, and their work habits and preferences... > > > > > > > The difference isn't in what's best, but in what people are willing to > > accept. Just because people roll over and accept the latest Windows, > > the latest Mac OS, the latest PhotoShop, the latest Gmail, the latest > > whatever else, doesn't mean that (a) they actually like it, nor (b) > > it's actually better. (Which are independent.) > > > > When someone spends all their life in a single app, they're more > > likely to learn its particular way of doing things and assume that > > that's "correct". But that doesn't make it so. > > Correct. > But when that same person goes to a different company where a > different application > is used, he expects it to behave the same. Because the functionality of such > application is the same. > > Wouldn't you? > > It is called association. > > "I was working with Application A. Now I'm working with application > AA. And application > AA behaves very weirdly." > Yes, association is correct. "I was working with Application A. Now I'm working with Application B. And it behaves very weirdly." It's entirely possible that App A was the bad one, and unfortunately, that does happen. But this is exactly why it's better to follow the standards. Unless you are so egotistical that you think your users won't need *any* other applications in their lives, follow the standards. ChrisA From greg.ewing at canterbury.ac.nz Wed Jan 13 20:48:44 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 14 Jan 2021 14:48:44 +1300 Subject: Application window geometry specifier In-Reply-To: References: <20210114005058.GD31888@bladeshadow.org> Message-ID: <45be434d-f22e-0ef5-cd7e-4488f6b7c09f@canterbury.ac.nz> On 14/01/21 1:58 pm, Chris Angelico wrote: > On Thu, Jan 14, 2021 at 11:53 AM Python wrote: >> >> I believe it is or was quite common >> for large, integrated applications like DAWs, graphical design >> software, etc. to remember where you placed your various floating >> toolbars and add-ons Not just large, integrated applications. If I open Intaglio (a modestly sized drawing app) on my Mac right now, the palettes are all where I left them last time. > The results will differ based on whether the user in question has > basically just one primary application (an IDE, or some gigantic app > like Adobe PhotoShop) that they spend all their time in, or if they're > using myriad different applications. Especially in the latter case, it > is far FAR better to put control in the user's hands I don't follow. If the app is just remembering where the user put things, then it *is* putting control in the user's hands. And I don't see what difference it makes how many different apps they use. Leaving things where the user put them seems like a good idea regardless. Ideally, the OS or window manager would do the remembering, but if it doesn't provide such a facility, I don't see any harm in allowing the app to *request* (not force) a certain position for a window. The app can of course abuse that privilege, but that's the fault of the app, not the feature. -- Greg From greg.ewing at canterbury.ac.nz Wed Jan 13 20:48:44 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Thu, 14 Jan 2021 14:48:44 +1300 Subject: Application window geometry specifier In-Reply-To: References: <20210114005058.GD31888@bladeshadow.org> Message-ID: <45be434d-f22e-0ef5-cd7e-4488f6b7c09f@canterbury.ac.nz> On 14/01/21 1:58 pm, Chris Angelico wrote: > On Thu, Jan 14, 2021 at 11:53 AM Python wrote: >> >> I believe it is or was quite common >> for large, integrated applications like DAWs, graphical design >> software, etc. to remember where you placed your various floating >> toolbars and add-ons Not just large, integrated applications. If I open Intaglio (a modestly sized drawing app) on my Mac right now, the palettes are all where I left them last time. > The results will differ based on whether the user in question has > basically just one primary application (an IDE, or some gigantic app > like Adobe PhotoShop) that they spend all their time in, or if they're > using myriad different applications. Especially in the latter case, it > is far FAR better to put control in the user's hands I don't follow. If the app is just remembering where the user put things, then it *is* putting control in the user's hands. And I don't see what difference it makes how many different apps they use. Leaving things where the user put them seems like a good idea regardless. Ideally, the OS or window manager would do the remembering, but if it doesn't provide such a facility, I don't see any harm in allowing the app to *request* (not force) a certain position for a window. The app can of course abuse that privilege, but that's the fault of the app, not the feature. -- Greg From python.list at tim.thechases.com Wed Jan 13 20:35:02 2021 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 13 Jan 2021 19:35:02 -0600 Subject: count consecutive elements In-Reply-To: References: Message-ID: <20210113193502.7d2d778b@bigbox.attlocal.net> On 2021-01-13 21:20, Bischoop wrote: > I want to to display a number or an alphabet which appears mostly > consecutive in a given string or numbers or both > Examples > s= ' aabskaaabadcccc' > output: c > # c appears 4 consecutive times > 8bbakebaoa > output: b > #b appears 2 consecutive times I'd break the problem into two parts: 1) iterate over your thing (in this case, a string) and emit the item and its correpsonding count of consecutive matches. 2) feed that into something that finds the longest run(s) output by that. So off the cuff, something like def consecutive_counter(seq): # I'm not sure if there's something # like this already in itertools cur = nada = object() count = 0 for x in seq: if x == cur: count += 1 else: if cur is not nada: yield cur, count cur = x count = 1 if cur is not nada: yield cur, count def longest(seq): results = [] biggest = 0 for item, count in seq: if count > biggest: results = [item] biggest = count elif count == biggest: results.append(item) return results, biggest for s in ( "", "a", "aaa", "aaabbb", "aabskaaabadcccc", "aabskaaakkkkkbadcccc", ): print("Testing %r" % s) print(repr(longest(consecutive_counter(s)))) -tkc From ikorot01 at gmail.com Wed Jan 13 21:05:27 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 13 Jan 2021 20:05:27 -0600 Subject: Application window geometry specifier In-Reply-To: References: <20210114005058.GD31888@bladeshadow.org> <20210114011624.GE31888@bladeshadow.org> Message-ID: Chris, On Wed, Jan 13, 2021 at 7:45 PM Chris Angelico wrote: > > On Thu, Jan 14, 2021 at 12:39 PM Igor Korot wrote: > > > > Chris, > > > > On Wed, Jan 13, 2021 at 7:33 PM Chris Angelico wrote: > > > > > > On Thu, Jan 14, 2021 at 12:18 PM Python wrote: > > > > > The results will differ based on whether the user in question has > > > > > basically just one primary application (an IDE, or some gigantic app > > > > > like Adobe PhotoShop) that they spend all their time in > > > > > > > > OK, so you admit that such apps do exist. But I guess you knew that > > > > the OP is not writing that sort of application, and know who its > > > > intended audience is, and their work habits and preferences... > > > > > > > > > > The difference isn't in what's best, but in what people are willing to > > > accept. Just because people roll over and accept the latest Windows, > > > the latest Mac OS, the latest PhotoShop, the latest Gmail, the latest > > > whatever else, doesn't mean that (a) they actually like it, nor (b) > > > it's actually better. (Which are independent.) > > > > > > When someone spends all their life in a single app, they're more > > > likely to learn its particular way of doing things and assume that > > > that's "correct". But that doesn't make it so. > > > > Correct. > > But when that same person goes to a different company where a > > different application > > is used, he expects it to behave the same. Because the functionality of such > > application is the same. > > > > Wouldn't you? > > > > It is called association. > > > > "I was working with Application A. Now I'm working with application > > AA. And application > > AA behaves very weirdly." > > > > Yes, association is correct. > > "I was working with Application A. Now I'm working with Application B. > And it behaves very weirdly." > > It's entirely possible that App A was the bad one, and unfortunately, > that does happen. But this is exactly why it's better to follow the > standards. Unless you are so egotistical that you think your users > won't need *any* other applications in their lives, follow the > standards. And you still don't say anything about my DB example. Normal DB application has to place credentials dialog center screen or center frame, depending when it shows. Otherwise they will popup all over the place wrecking havoc with the users. And so its better to show it centered, just like in my example above. And as I said - I hope you are inside this 99.99% of users/ developers. Thank you. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Jan 13 21:12:31 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2021 13:12:31 +1100 Subject: Application window geometry specifier In-Reply-To: References: <20210114005058.GD31888@bladeshadow.org> <20210114011624.GE31888@bladeshadow.org> Message-ID: On Thu, Jan 14, 2021 at 1:05 PM Igor Korot wrote: > > Chris, > > On Wed, Jan 13, 2021 at 7:45 PM Chris Angelico wrote: > > > > On Thu, Jan 14, 2021 at 12:39 PM Igor Korot wrote: > > > > > > Chris, > > > > > > On Wed, Jan 13, 2021 at 7:33 PM Chris Angelico wrote: > > > > > > > > On Thu, Jan 14, 2021 at 12:18 PM Python wrote: > > > > > > The results will differ based on whether the user in question has > > > > > > basically just one primary application (an IDE, or some gigantic app > > > > > > like Adobe PhotoShop) that they spend all their time in > > > > > > > > > > OK, so you admit that such apps do exist. But I guess you knew that > > > > > the OP is not writing that sort of application, and know who its > > > > > intended audience is, and their work habits and preferences... > > > > > > > > > > > > > The difference isn't in what's best, but in what people are willing to > > > > accept. Just because people roll over and accept the latest Windows, > > > > the latest Mac OS, the latest PhotoShop, the latest Gmail, the latest > > > > whatever else, doesn't mean that (a) they actually like it, nor (b) > > > > it's actually better. (Which are independent.) > > > > > > > > When someone spends all their life in a single app, they're more > > > > likely to learn its particular way of doing things and assume that > > > > that's "correct". But that doesn't make it so. > > > > > > Correct. > > > But when that same person goes to a different company where a > > > different application > > > is used, he expects it to behave the same. Because the functionality of such > > > application is the same. > > > > > > Wouldn't you? > > > > > > It is called association. > > > > > > "I was working with Application A. Now I'm working with application > > > AA. And application > > > AA behaves very weirdly." > > > > > > > Yes, association is correct. > > > > "I was working with Application A. Now I'm working with Application B. > > And it behaves very weirdly." > > > > It's entirely possible that App A was the bad one, and unfortunately, > > that does happen. But this is exactly why it's better to follow the > > standards. Unless you are so egotistical that you think your users > > won't need *any* other applications in their lives, follow the > > standards. > > And you still don't say anything about my DB example. > > Normal DB application has to place credentials dialog center > screen or center frame, depending when it shows. > > Otherwise they will popup all over the place wrecking havoc > with the users. > > And so its better to show it centered, just like in my example > above. And as I said - I hope you are inside this 99.99% of users/ > developers. > And isn't that exactly where the WM would put it by default too? The difference is, if the user wishes it to be somewhere else *for all applications*, s/he can reconfigure the WM, but it's an absolute pain if all these kinds of apps have to be independently reconfigured. The obvious defaults are obvious to the creators of WMs even more than app developers, AND you're not forcing people into your personal preferences. ChrisA From drsalists at gmail.com Wed Jan 13 21:20:11 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 13 Jan 2021 18:20:11 -0800 Subject: count consecutive elements In-Reply-To: <20210113193502.7d2d778b@bigbox.attlocal.net> References: <20210113193502.7d2d778b@bigbox.attlocal.net> Message-ID: On Wed, Jan 13, 2021 at 5:59 PM Tim Chase wrote: > On 2021-01-13 21:20, Bischoop wrote: > > I want to to display a number or an alphabet which appears mostly > > consecutive in a given string or numbers or both > > Examples > > s= ' aabskaaabadcccc' > > output: c > > # c appears 4 consecutive times > > 8bbakebaoa > > output: b > > #b appears 2 consecutive times > I'm kind of partial to: import collections import typing def get_longest(string: str) -> typing.Tuple[int, str]: """Get the longest run of a single consecutive character.""" dict_: typing.DefaultDict[str, int] = collections.defaultdict(int) for left_ch, right_ch in zip(string, string[1:]): if left_ch == right_ch: dict_[left_ch] += 1 maximum = max((value, key) for key, value in dict_.items()) return maximum HTH From robertvstepp at gmail.com Wed Jan 13 21:25:28 2021 From: robertvstepp at gmail.com (boB Stepp) Date: Wed, 13 Jan 2021 20:25:28 -0600 Subject: Application window geometry specifier In-Reply-To: References: <20210114003151.GC31888@bladeshadow.org> Message-ID: On Wed, Jan 13, 2021 at 7:28 PM Chris Angelico wrote: > I love how "I think" is allowed to trump decades of usability research. Can you recommend a good reference for someone relatively new to GUI programming that is based on such research? Book or web reference would be fine. Cheers! boB From DomainAdmin at DancesWithMice.info Wed Jan 13 22:21:30 2021 From: DomainAdmin at DancesWithMice.info (David L Neil) Date: Thu, 14 Jan 2021 16:21:30 +1300 Subject: Application window geometry specifier In-Reply-To: References: <20210114003151.GC31888@bladeshadow.org> Message-ID: <0250463f-c22b-43b9-c7cc-4be7f39e87b0@DancesWithMice.info> On 14/01/2021 15.25, boB Stepp wrote: > On Wed, Jan 13, 2021 at 7:28 PM Chris Angelico wrote: > >> I love how "I think" is allowed to trump decades of usability research. I'm just pleased that @Chris has found love! (not detracting from the point though) > Can you recommend a good reference for someone relatively new to GUI > programming that is based on such research? Book or web reference > would be fine. Most of my training-materials (certainly in this topic) are web-based - but the ideas are also common to Python. Nielsen-Norman Group do a lot of work in UX and offer a regular newsletter which is usually a good way to make the brain-cells work for their living: https://www.nngroup.com/ eg https://www.nngroup.com/articles/usability-101-introduction-to-usability/ A more applied view, courtesy of the New Zealand Government: https://www.digital.govt.nz/standards-and-guidance/nz-government-web-standards/web-usability-standard-1-3/ Some become confused between the two terms: Accessibility and Usability. Here's what the boss says: https://www.w3.org/WAI/fundamentals/accessibility-usability-inclusion/ This article clearly explains each and then offers a comparison. https://www.telerik.com/blogs/web-accessibility-vs-usability If you really want to dig-down, I know for-sure that IBM, Microsoft, Apple (and presumably others) have compiled style-guides about how various GUIs should work, starting from really basic matters such as when to use radio-buttons and when check-boxes. I can't tell you if the gtk, qt, or wx people offer something similar... -- Regards =dn From PythonList at DancesWithMice.info Wed Jan 13 22:22:50 2021 From: PythonList at DancesWithMice.info (dn) Date: Thu, 14 Jan 2021 16:22:50 +1300 Subject: Application window geometry specifier In-Reply-To: References: <20210114003151.GC31888@bladeshadow.org> Message-ID: On 14/01/2021 15.25, boB Stepp wrote: > On Wed, Jan 13, 2021 at 7:28 PM Chris Angelico wrote: > >> I love how "I think" is allowed to trump decades of usability research. I'm just pleased that @Chris has found love! (not detracting from the point though) > Can you recommend a good reference for someone relatively new to GUI > programming that is based on such research? Book or web reference > would be fine. Most of my training-materials (certainly in this topic) are web-based - but the ideas are also common to Python. Nielsen-Norman Group do a lot of work in UX and offer a regular newsletter which is usually a good way to make the brain-cells work for their living: https://www.nngroup.com/ eg https://www.nngroup.com/articles/usability-101-introduction-to-usability/ A more applied view, courtesy of the New Zealand Government: https://www.digital.govt.nz/standards-and-guidance/nz-government-web-standards/web-usability-standard-1-3/ Some become confused between the two terms: Accessibility and Usability. Here's what the boss says: https://www.w3.org/WAI/fundamentals/accessibility-usability-inclusion/ This article clearly explains each and then offers a comparison. https://www.telerik.com/blogs/web-accessibility-vs-usability If you really want to dig-down, I know for-sure that IBM, Microsoft, Apple (and presumably others) have compiled style-guides about how various GUIs should work, starting from really basic matters such as when to use radio-buttons and when check-boxes. I can't tell you if the gtk, qt, or wx people offer something similar... -- Regards =dn From ikorot01 at gmail.com Wed Jan 13 22:39:49 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 13 Jan 2021 21:39:49 -0600 Subject: Application window geometry specifier In-Reply-To: References: <20210114005058.GD31888@bladeshadow.org> <20210114011624.GE31888@bladeshadow.org> Message-ID: Chris, On Wed, Jan 13, 2021 at 8:12 PM Chris Angelico wrote: > > On Thu, Jan 14, 2021 at 1:05 PM Igor Korot wrote: > > > > Chris, > > > > On Wed, Jan 13, 2021 at 7:45 PM Chris Angelico wrote: > > > > > > On Thu, Jan 14, 2021 at 12:39 PM Igor Korot wrote: > > > > > > > > Chris, > > > > > > > > On Wed, Jan 13, 2021 at 7:33 PM Chris Angelico wrote: > > > > > > > > > > On Thu, Jan 14, 2021 at 12:18 PM Python wrote: > > > > > > > The results will differ based on whether the user in question has > > > > > > > basically just one primary application (an IDE, or some gigantic app > > > > > > > like Adobe PhotoShop) that they spend all their time in > > > > > > > > > > > > OK, so you admit that such apps do exist. But I guess you knew that > > > > > > the OP is not writing that sort of application, and know who its > > > > > > intended audience is, and their work habits and preferences... > > > > > > > > > > > > > > > > The difference isn't in what's best, but in what people are willing to > > > > > accept. Just because people roll over and accept the latest Windows, > > > > > the latest Mac OS, the latest PhotoShop, the latest Gmail, the latest > > > > > whatever else, doesn't mean that (a) they actually like it, nor (b) > > > > > it's actually better. (Which are independent.) > > > > > > > > > > When someone spends all their life in a single app, they're more > > > > > likely to learn its particular way of doing things and assume that > > > > > that's "correct". But that doesn't make it so. > > > > > > > > Correct. > > > > But when that same person goes to a different company where a > > > > different application > > > > is used, he expects it to behave the same. Because the functionality of such > > > > application is the same. > > > > > > > > Wouldn't you? > > > > > > > > It is called association. > > > > > > > > "I was working with Application A. Now I'm working with application > > > > AA. And application > > > > AA behaves very weirdly." > > > > > > > > > > Yes, association is correct. > > > > > > "I was working with Application A. Now I'm working with Application B. > > > And it behaves very weirdly." > > > > > > It's entirely possible that App A was the bad one, and unfortunately, > > > that does happen. But this is exactly why it's better to follow the > > > standards. Unless you are so egotistical that you think your users > > > won't need *any* other applications in their lives, follow the > > > standards. > > > > And you still don't say anything about my DB example. > > > > Normal DB application has to place credentials dialog center > > screen or center frame, depending when it shows. > > > > Otherwise they will popup all over the place wrecking havoc > > with the users. > > > > And so its better to show it centered, just like in my example > > above. And as I said - I hope you are inside this 99.99% of users/ > > developers. > > > > And isn't that exactly where the WM would put it by default too? The > difference is, if the user wishes it to be somewhere else *for all > applications*, s/he can reconfigure the WM, but it's an absolute pain > if all these kinds of apps have to be independently reconfigured. The > obvious defaults are obvious to the creators of WMs even more than app > developers, AND you're not forcing people into your personal > preferences. I don't know. Do you? Are you absolutely sure 100% it will put it there? Especially by default? Now here is the more interesting question: if I create such a dialog (meaning it will not be pulled from external library) what will happen? Can you guarantee that my dialog will be placed accordingly and if I call "dlg.Center()" it won't be ignored? Thank you. > > ChrisA From python at bladeshadow.org Wed Jan 13 22:41:26 2021 From: python at bladeshadow.org (Python) Date: Wed, 13 Jan 2021 21:41:26 -0600 Subject: Application window geometry specifier In-Reply-To: References: <20210114003151.GC31888@bladeshadow.org> Message-ID: <20210114034126.GF31888@bladeshadow.org> On Thu, Jan 14, 2021 at 12:27:19PM +1100, Chris Angelico wrote: > On Thu, Jan 14, 2021 at 12:11 PM Python wrote: > > > > On Tue, Jan 12, 2021 at 06:43:39PM -0000, Grant Edwards wrote: > > > And those X11 users will swear at you if you override their window > > > managers configured window placement. Application code should not care > > > about or try to control window geometry. Period. > > > > I think this is just plain wrong. As a side note, from a purely technical standpoint, Grant's point is demonstrably factually false. A GUI application necessarily must "care about or try to control window geometry" so that if the user moves or resizes the application, enables or disables additional widgets, etc., the widgets it contains are redrawn such that they remain usable, possibly expanding the canvas they're drawn on or adding new GUI elements like scrollbars to ensure that (at least it does if it wants to be useful). GUI frameworks may provide a core that automatically handles this for you, but that is not always the case (as an extreme example, if you're writing the whole app from scratch in assembly language), and in any event the framework is part of the application... not the window manager. Just because you didn't write that code doesn't mean your app doesn't need those facilities. > I love how "I think" is allowed to trump decades of usability research. I love how your complete dismissal of everything I said is allowed to replace logical counterargument, particuarly when you ignored the fact that absolutely nothing I said actually contradicts any such years of usability research IN ANY WAY--I merely pointed out that if the application were to have ADDITIONAL flexibility for expert users in regard to placing and sizing windows, the application must necessarily care about and be able to control its window geometry. All the other behaviors remain consistent with usability standards--assuming the vendor implemented them properly, which is a big assumption. In fact, providing such extra semantics may allow the user to overcome bad UI when the vendor failed. > it is far FAR better to put control in the user's hands I love how you dismissed that the semantics I described gives MORE control to the user, not less, without actually sacrificing anything. I love how you dismissed that not all computer users and not all humans are the same, that there are variances and outliers within all usability studies, and indeed all studies of human behavior, and that flexibility and configurability have value for that reason. I love how you dismissed the perpectives and motivations of posters in this thread without understanding or even hearing them. For all you know Rich may just be doing it as an academic exercise, in which case whether or not it conforms to usability best practices is utterly irrelevant, even if it weren't already the case that giving more control to the user--something you just claimed to value--requires giving control to the app. From ikorot01 at gmail.com Wed Jan 13 22:50:07 2021 From: ikorot01 at gmail.com (Igor Korot) Date: Wed, 13 Jan 2021 21:50:07 -0600 Subject: Application window geometry specifier In-Reply-To: <0250463f-c22b-43b9-c7cc-4be7f39e87b0@DancesWithMice.info> References: <20210114003151.GC31888@bladeshadow.org> <0250463f-c22b-43b9-c7cc-4be7f39e87b0@DancesWithMice.info> Message-ID: Hi, David, On Wed, Jan 13, 2021 at 9:24 PM David L Neil via Python-list wrote: > > On 14/01/2021 15.25, boB Stepp wrote: > > On Wed, Jan 13, 2021 at 7:28 PM Chris Angelico wrote: > > > >> I love how "I think" is allowed to trump decades of usability research. > > I'm just pleased that @Chris has found love! > (not detracting from the point though) > > > > Can you recommend a good reference for someone relatively new to GUI > > programming that is based on such research? Book or web reference > > would be fine. > > Most of my training-materials (certainly in this topic) are web-based - > but the ideas are also common to Python. > > > Nielsen-Norman Group do a lot of work in UX and offer a regular > newsletter which is usually a good way to make the brain-cells work for > their living: https://www.nngroup.com/ > > eg https://www.nngroup.com/articles/usability-101-introduction-to-usability/ > > > A more applied view, courtesy of the New Zealand Government: > https://www.digital.govt.nz/standards-and-guidance/nz-government-web-standards/web-usability-standard-1-3/ > > > Some become confused between the two terms: Accessibility and Usability. > > Here's what the boss says: > https://www.w3.org/WAI/fundamentals/accessibility-usability-inclusion/ > > This article clearly explains each and then offers a comparison. > https://www.telerik.com/blogs/web-accessibility-vs-usability > > > If you really want to dig-down, I know for-sure that IBM, Microsoft, > Apple (and presumably others) have compiled style-guides about how > various GUIs should work, starting from really basic matters such as > when to use radio-buttons and when check-boxes. I can't tell you if the > gtk, qt, or wx people offer something similar... Certainly not wx - because wx using native set of widgets and therefore relies on the OS UI guidelines. Thank you. > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Wed Jan 13 23:02:05 2021 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 14 Jan 2021 15:02:05 +1100 Subject: Application window geometry specifier In-Reply-To: <20210114034126.GF31888@bladeshadow.org> References: <20210114003151.GC31888@bladeshadow.org> <20210114034126.GF31888@bladeshadow.org> Message-ID: On Thu, Jan 14, 2021 at 2:43 PM Python wrote: > > it is far FAR better to put control in the user's hands > > I love how you dismissed that the semantics I described gives MORE > control to the user, not less, without actually sacrificing anything. Actually, you give control to the application, and then the application has to choose to give it to the user. But apparently, this thread has devolved to this kind of total dismissal, so I'm not going to respond further. Have fun building your app, do what you like with it, and I'll continue to use standards-compliant applications that actually behave correctly in all situations. ChrisA From python.list at tim.thechases.com Wed Jan 13 22:37:42 2021 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 13 Jan 2021 21:37:42 -0600 Subject: count consecutive elements In-Reply-To: References: <20210113193502.7d2d778b@bigbox.attlocal.net> Message-ID: <20210113213742.2275d553@bigbox.attlocal.net> On 2021-01-13 18:20, Dan Stromberg wrote: > I'm kind of partial to: > > import collections > import typing > > > def get_longest(string: str) -> typing.Tuple[int, str]: > """Get the longest run of a single consecutive character.""" > dict_: typing.DefaultDict[str, int] = > collections.defaultdict(int) for left_ch, right_ch in zip(string, > string[1:]): if left_ch == right_ch: > dict_[left_ch] += 1 > > maximum = max((value, key) for key, value in dict_.items()) > > return maximum seems to only return one value so seems to get odd results if I specify something like get_longest("aaabcccbbb") which at least here tells me that "c" is the longest run, even though aaa, bbb, and ccc are all runs of length 3. The OP didn't specify what should happen in that case, so it would need some clarification. -tkc From python at bladeshadow.org Wed Jan 13 23:32:33 2021 From: python at bladeshadow.org (Python) Date: Wed, 13 Jan 2021 22:32:33 -0600 Subject: Application window geometry specifier In-Reply-To: References: <20210114003151.GC31888@bladeshadow.org> <20210114034126.GF31888@bladeshadow.org> Message-ID: <20210114043233.GG31888@bladeshadow.org> On Thu, Jan 14, 2021 at 03:02:05PM +1100, Chris Angelico wrote: > On Thu, Jan 14, 2021 at 2:43 PM Python wrote: > > > it is far FAR better to put control in the user's hands > > > > I love how you dismissed that the semantics I described gives MORE > > control to the user, not less, without actually sacrificing anything. > > Actually, you give control to the application, and then the > application has to choose to give it to the user. Right, because unless the user can somehow execute instructions directly on the CPU via some sort of direct cerebral link, all control the user has over the behavior of the applications comes... from the applications. > But apparently, this thread has devolved to this kind of total > dismissal For which you are entirely the cause. I simply responded in kind. Apparently you don't like it any more than the rest of us do. From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Jan 13 23:18:14 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Wed, 13 Jan 2021 22:18:14 -0600 Subject: Application window geometry specifier In-Reply-To: <20210114034126.GF31888@bladeshadow.org> References: <20210114003151.GC31888@bladeshadow.org> <20210114034126.GF31888@bladeshadow.org> Message-ID: On 2021-01-13 at 21:41:26 -0600, Python wrote: > On Thu, Jan 14, 2021 at 12:27:19PM +1100, Chris Angelico wrote: > > On Thu, Jan 14, 2021 at 12:11 PM Python wrote: > > > > > > On Tue, Jan 12, 2021 at 06:43:39PM -0000, Grant Edwards wrote: > > > > And those X11 users will swear at you if you override their window > > > > managers configured window placement. Application code should not care > > > > about or try to control window geometry. Period. > > > > > > I think this is just plain wrong. > > As a side note, from a purely technical standpoint, Grant's point is > demonstrably factually false. A GUI application necessarily must > "care about or try to control window geometry" so that if the user > moves or resizes the application, enables or disables additional > widgets, etc., the widgets it contains are redrawn such that they > remain usable, possibly expanding the canvas they're drawn on or > adding new GUI elements like scrollbars to ensure that (at least it > does if it wants to be useful) ... A GUI application must care about the geometry (to react to changes made by the user or the window manager). OTOH, if I (the user) request a 80x24 character terminal window with a certain size glyph, and I get a terminal that isn't 80x24 and that glyph size, then at least one of the application, the window manager, or some other library is broken. Period. Go ahead, tell me, the *user*, that I shouldn't do that, or that I should reconsider my use case, or that such a request is too demanding for a modern computer system to honor. See also Extended Window Manager Hints,? with the emphasis on *hints*. > ... GUI frameworks may provide a core that automatically handles this > for you, but that is not always the case (as an extreme example, if > you're writing the whole app from scratch in assembly language) ... Define "from scratch." Why does the language in which I'm writing my application matter? ? https://en.wikipedia.org/wiki/Extended_Window_Manager_Hints From info at wingware.com Thu Jan 14 10:08:56 2021 From: info at wingware.com (Wingware) Date: Thu, 14 Jan 2021 10:08:56 -0500 Subject: ANN: Wing Python IDE 7.2.8 has been released Message-ID: <60005E88.2050304@wingware.com> Wing 7.2.8 fixes reformatting selections for PEP8, corrects completion of code reformatting in remote files when code is unchanged, fixes problems analyzing incomplete 'def async' statements, correctly handles refactor module rename when the target name exists, adds a preference to control the delay before tooltips are shown, reduces the default tooltips delay, shows a warning when a file exceeds the configured maximum size for running external code checkers, and makes a number of other usability improvements. Details: https://wingware.com/news/2021-01-12 Downloads: https://wingware.com/downloads == About Wing == Wing is a light-weight but full-featured Python IDE designed specifically for Python, with powerful editing, code inspection, testing, and debugging capabilities. Wing's deep code analysis provides auto-completion, auto-editing, and refactoring that speed up development. Its top notch debugger works with any Python code, locally or on a remote host. Wing also supports test-driven development, version control, UI color and layout customization, and includes extensive documentation and support. Wing is available in three product levels: Wing Pro is the full-featured Python IDE for professional developers, Wing Personal is a free Python IDE for students and hobbyists (omits some features), and Wing 101 is a very simplified free Python IDE for beginners (omits many features). Learn more at https://wingware.com/ From drsalists at gmail.com Thu Jan 14 10:47:41 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 14 Jan 2021 07:47:41 -0800 Subject: count consecutive elements In-Reply-To: References: <20210113193502.7d2d778b@bigbox.attlocal.net> Message-ID: On Wed, Jan 13, 2021 at 6:20 PM Dan Stromberg wrote: > On Wed, Jan 13, 2021 at 5:59 PM Tim Chase > wrote: > >> On 2021-01-13 21:20, Bischoop wrote: >> > I want to to display a number or an alphabet which appears mostly >> > consecutive in a given string or numbers or both >> > Examples >> > s= ' aabskaaabadcccc' >> > output: c >> > # c appears 4 consecutive times >> > 8bbakebaoa >> > output: b >> > #b appears 2 consecutive times >> > > I'm kind of partial to: > > import collections > import typing > > > def get_longest(string: str) -> typing.Tuple[int, str]: > I just realized this has a kinda big bug. Don't use! From mrd at redhat.com Wed Jan 13 20:26:32 2021 From: mrd at redhat.com (Matt Davis) Date: Wed, 13 Jan 2021 17:26:32 -0800 Subject: [ANN] PyYAML-5.4b1: Linux and Mac users, please test wheels! Message-ID: ======================= Announcing PyYAML-5.4b1 ======================= A beta release of PyYAML is now available: https://github.com/yaml/pyyaml/releases/tag/5.4b1 This release contains a security fix for CVE-2020-14343. It removes the python/module, python/object, and python/object/new tags from the FullLoader. YAML that uses these tags must be loaded by UnsafeLoader, or a custom loader that has explicitly enabled them. This beta release also adds Python wheels for manylinux1 (x86_64) and MacOS (x86_64) with the libyaml extension included (built on libyaml 0.2.5). We believe these wheels to be stable, but please take the opportunity to test against your local Linux and MacOS environments, and file any issues at https://github.com/yaml/pyyaml/issues. PyYAML 5.4 will be the last release to support Python 2.7. Changes ======= * https://github.com/yaml/pyyaml/pull/407 -- build modernization, remove distutils, fix metadata, build wheels, CI to GHA * https://github.com/yaml/pyyaml/pull/472 -- fix for CVE-2020-14343, moves arbitrary python tags to UnsafeLoader * https://github.com/yaml/pyyaml/pull/441 -- fix memory leak in implicit resolver setup * https://github.com/yaml/pyyaml/pull/392 -- fix py2 copy support for timezone objects * https://github.com/yaml/pyyaml/pull/378 -- fix compatibility with Jython Resources ========= PyYAML IRC Channel: #pyyaml on irc.freenode.net PyYAML homepage: https://github.com/yaml/pyyaml PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation Source and binary installers: https://pypi.org/project/PyYAML/ GitHub repository: https://github.com/yaml/pyyaml/ Bug tracking: https://github.com/yaml/pyyaml/issues YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML ============ YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistence. Example ======= >>> import yaml >>> yaml.full_load(""" ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: https://github.com/yaml/pyyaml ... keywords: [YAML, serialization, configuration, persistence, pickle] ... """) {'keywords': ['YAML', 'serialization', 'configuration', 'persistence', 'pickle'], 'homepage': 'https://github.com/yaml/pyyaml', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} >>> print(yaml.dump(_)) name: PyYAML homepage: https://github.com/yaml/pyyaml description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistence, pickle] Maintainers =========== The following people are currently responsible for maintaining PyYAML: * Ingy d?t Net * Matt Davis and many thanks to all who have contribributed! See: https://github.com/yaml/pyyaml/pulls Copyright ========= Copyright (c) 2017-2020 Ingy d?t Net Copyright (c) 2006-2016 Kirill Simonov The PyYAML module was written by Kirill Simonov . It is currently maintained by the YAML and Python communities. PyYAML is released under the MIT license. See the file LICENSE for more details. From Bischoop at vimart.net Wed Jan 13 21:06:33 2021 From: Bischoop at vimart.net (Bischoop) Date: Thu, 14 Jan 2021 02:06:33 -0000 (UTC) Subject: count consecutive elements References: Message-ID: On 2021-01-13, Bischoop wrote: I know what was wrong: > m = s.index(i) I forgot that m will return first index of i. So tried that way but still getting out of index although I that that I'm making sure not to get out of index. s = 'aabskaaabadcccch' c = 0 t = list(set(s)) # list of characters in s li=[0,0,0,0,0,0] # list for counted repeats print(t) for x in t: h = t.index(x) for index, i in enumerate(s): maximus = len(s) if i == x: c += 1 if index < maximus: if s[index +1] != x: # if next element is not x if c > li[h]: #update c if bigger than existing li[h] = c c = 0 else: if c > li[h]: li[h] = c for i in t: n = t.index(i) print(i,li[n]) print(f'{s[li.index(max(li))]} appears {max(li)} consecutive times') From tiscauk at gmail.com Thu Jan 14 01:52:17 2021 From: tiscauk at gmail.com (christine tiscareno) Date: Thu, 14 Jan 2021 06:52:17 +0000 Subject: Question - problem downloading Python Message-ID: I installed in my lap-top your latest version of Python (3.9.1), yet when I go to cmd.exe to check, I get that I have Python 22.7.17 ??? Why? What should I do to get the latest version? I tried going back to fix problems and it does not fix it, that is how I got your email. How can I get the latest Python version (3.9.1), instead of what I'm getting (22.7.17)? Thank you for your time. -- Kind regards, Christine Tiscareno From alan.gauld at yahoo.co.uk Thu Jan 14 11:01:20 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 14 Jan 2021 16:01:20 +0000 Subject: conceptual problem In-Reply-To: <3ng3dh-kha.ln1@anthive.com> References: <3ng3dh-kha.ln1@anthive.com> Message-ID: On 13/01/2021 15:37, songbird wrote: > my momentary conceptual problem is that to me OOP means > being able to encapsulate data structures and code from > other parts of the program, That's true, but encapsulation simply means that the data and functions are contained within a single entity - ie a capsule. It says nothing about whether you can access them directly or not. When OOP started the basic concept of having functions inside the same structure as the data that they operated on was so radical that encapsulation became a big topic. But over time it has gotten mixed up with data hiding and abstraction (also big topics back in the 70/80s) So the term encapsulation has tended to be used to cover abstraction and data hiding as well as simple(pure) encapsulation. > that is how python is designed. this is probably a complete > aside to this whole thread and perhaps even this newsgroup It is a long running(as in for decades!) sub-thread to the whole Python language. :-) -- 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 Thu Jan 14 11:12:24 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 14 Jan 2021 16:12:24 +0000 Subject: Exploring terminfo Message-ID: During lockdown I've been digging deeper into the curses module and lately into the tiXXXX family of functions that reside there. I've written a short program that is supposed to - *clear the screen*, - read some input - display the result in a message *highlighted in bold*. - get input to end the program The parts marked with ** use terminfo, or they should. My problem is that while the clear-screen part works the bold bit only appears in the final input(), not in the output message. Here is the code: ################# import curses as cur cur.setupterm() bold = cur.tigetstr('bold') cls = cur.tigetstr('clear') cur.putp(cls) name = input("Hello, what's your name? ") cur.putp(bold) print("Nice to meet you ", name) input("\nHit enter to exit") ############### I've tried variations on flush both inside and outside the print() - both before and after. I've tried writing to stdout instead of print, but nothing is working. The Hit enter... message is in bold but the Hello... line isn't. Does anyone know what's going on and how to fix it. I could, of course, jump into full curses but I wanted to see if I could use the terminfo stuff directly to retain use of regular input() and print() functions. -- 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 pkpearson at nowhere.invalid Thu Jan 14 12:04:33 2021 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 14 Jan 2021 17:04:33 GMT Subject: A beginning beginner's question about input, output and . . . References: Message-ID: On Wed, 13 Jan 2021 21:46:08 -0000 (UTC), Grant Edwards wrote: > On 2021-01-13, Peter Pearson wrote: [snip] >> Browsergui is not widely popular (I don't think anybody but me has >> mentioned it on this newsgroup), but it was written to be simple and >> Pythonic, and has served me well. Browsergui just uses your browser as >> its user interface. Grab it from >> >> https://github.com/speezepearson/browsergui > > I've been browsing through to documentation and examples, and I don't > see any way to do any sort of modern flexible layout (e.g. nesting > horizontal and vertical flexboxes) where you can control which > elements grow/shrink when the window size changes. > > Is there a way to span columns/rows in a grid or control which columns > grow/shrink? > > Have I missed something? I doubt you've missed anything important, though I'm not sure because I haven't done any of the things you mention. Browsergui is minimalist. If you've done the "python -m browsergui.examples" and don't see something like what you want, it's probably not there. I like Browsergui for simple tools that require a little more interaction than straight command-line utilities: exploring the effect of various value-settings on some curve on a graph, or exploring the ranges of values in a CSV file, or (most recently) rearranging the order of image files in a list. -- To email me, substitute nowhere->runbox, invalid->com. From denys.contant at gmail.com Thu Jan 14 12:44:24 2021 From: denys.contant at gmail.com (Denys Contant) Date: Thu, 14 Jan 2021 09:44:24 -0800 (PST) Subject: why sqrt is not a built-in function? Message-ID: I don't understand why sqrt is not a built-in function. Why do we have to first import the function from the math module? I use it ALL THE TIME! That felt good. Thank you. From nospam at please.ty Thu Jan 14 12:50:11 2021 From: nospam at please.ty (jak) Date: Thu, 14 Jan 2021 18:50:11 +0100 Subject: why sqrt is not a built-in function? References: Message-ID: Il 14/01/2021 18:44, Denys Contant ha scritto: > I don't understand why sqrt is not a built-in function. > Why do we have to first import the function from the math module? > I use it ALL THE TIME! > > That felt good. Thank you. > > > > > > > >>> val=16 >>> exp=2 >>> val ** (1/exp) 4.0 >>> From skip.montanaro at gmail.com Thu Jan 14 13:21:04 2021 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 14 Jan 2021 12:21:04 -0600 Subject: why sqrt is not a built-in function? In-Reply-To: References: Message-ID: > I don't understand why sqrt is not a built-in function. > Why do we have to first import the function from the math module? > I use it ALL THE TIME! For one, it's specific to numeric types. You might use it all the time, but I (for example) almost never need to use it, or to import the math module for my Python work/play. OTOH, I use stuff from the sys and csv modules (and lately, pandas) all the time. I import those modules when necessary. If you don't need them, I suspect you might grumble that they are useless for you. Requiring explicit module import gives programmers more control over the content of their module namespaces if the builtins don't include the kitchen sink. If you skim the output of import builtins dir(builtins) you should see that the two largest classes of builtin identifiers are exceptions (ZeroDivisionError, etc) and types (list, set, etc). Other classes include singleton constants (True, False, None) and general sequence operations (useful for loop control - reversed, iter, zip...). math.sqrt doesn't fit into those object classes. The remainder are a mixture of things, but generally aren't quite as special purpose as that. Granted, there are a couple which might be better left out (IMO), like round and pow, but I suspect their presence might simply be more a matter of them being present since Python's earliest days and reflect a tendency later to avoid gratuitous breakage of existing code. Finally, should have never considered it, I think you might want to study the output of import this Think on the second and last lines in particular. Skip From alan.gauld at yahoo.co.uk Thu Jan 14 12:54:55 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Thu, 14 Jan 2021 17:54:55 +0000 Subject: why sqrt is not a built-in function? In-Reply-To: References: Message-ID: On 14/01/2021 17:44, Denys Contant wrote: > I don't understand why sqrt is not a built-in function. > Why do we have to first import the function from the math module? > I use it ALL THE TIME! because pow() is a builtin function and root = pow(x,0.5) is the same as root = math.sqrt(x) As is root = x ** 0.5 which is also builtin. My question is: why do we even have a sqrt() in the math module given that pow() and ** are already there? -- 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 ethan at stoneleaf.us Thu Jan 14 13:41:24 2021 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 14 Jan 2021 10:41:24 -0800 Subject: why sqrt is not a built-in function? In-Reply-To: References: Message-ID: <3716ec87-4a74-8d3d-0bb5-a62bab48e9d1@stoneleaf.us> On 1/14/21 9:44 AM, Denys Contant wrote: > I don't understand why sqrt is not a built-in function. > Why do we have to first import the function from the math module? > I use it ALL THE TIME! And thousands, tens of thousands, and maybe hundreds of thousands don't. > That felt good. Thank you. Any time. ;-) -- ~Ethan~ From 2QdxY4RzWzUUiLuE at potatochowder.com Thu Jan 14 13:55:26 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Thu, 14 Jan 2021 12:55:26 -0600 Subject: why sqrt is not a built-in function? In-Reply-To: References: Message-ID: On 2021-01-14 at 17:54:55 +0000, Alan Gauld via Python-list wrote: > My question is: why do we even have a sqrt() in the > math module given that pow() and ** are already there? Probably because the standard C math library has such a function, and Python's math module is (or at least was) supposed be a thin wrapper around that library. For completeness, C doesn't have a exponentiation operator. From rosuav at gmail.com Thu Jan 14 14:01:18 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jan 2021 06:01:18 +1100 Subject: why sqrt is not a built-in function? In-Reply-To: References: Message-ID: On Fri, Jan 15, 2021 at 5:56 AM <2QdxY4RzWzUUiLuE at potatochowder.com> wrote: > > On 2021-01-14 at 17:54:55 +0000, > Alan Gauld via Python-list wrote: > > > My question is: why do we even have a sqrt() in the > > math module given that pow() and ** are already there? > > Probably because the standard C math library has such a function, and > Python's math module is (or at least was) supposed be a thin wrapper > around that library. > > For completeness, C doesn't have a exponentiation operator. Also, the math module works specifically with floats. Sometimes that's what you want, other times it's not. >>> pow(-2, 0.5) (8.659560562354934e-17+1.4142135623730951j) >>> (-2)**0.5 (8.659560562354934e-17+1.4142135623730951j) >>> from math import sqrt; sqrt(-2) Traceback (most recent call last): File "", line 1, in ValueError: math domain error >>> from cmath import sqrt; sqrt(-2) 1.4142135623730951j ChrisA From * at eli.users.panix.com Thu Jan 14 14:06:00 2021 From: * at eli.users.panix.com (Eli the Bearded) Date: Thu, 14 Jan 2021 19:06:00 +0000 (UTC) Subject: why sqrt is not a built-in function? References: Message-ID: In comp.lang.python, Skip Montanaro wrote: > Finally, should have never considered it, I think you might want to > study the output of > > import this > > Think on the second and last lines in particular. >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! >>> "There should be one-- and preferably only one --obvious way to do it." Meanwhile, Alan Gauld pointed out: AG> because pow() is a builtin function and AG> root = pow(x,0.5) AG> is the same as AG> root = math.sqrt(x) Plus the ** operation ("root = x ** 0.5"), that's now three ways. Elijah ------ python user, not python advocate From rosuav at gmail.com Thu Jan 14 14:13:53 2021 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 15 Jan 2021 06:13:53 +1100 Subject: why sqrt is not a built-in function? In-Reply-To: References: Message-ID: On Fri, Jan 15, 2021 at 6:11 AM Eli the Bearded <*@eli.users.panix.com> wrote: > > In comp.lang.python, Skip Montanaro wrote: > > Finally, should have never considered it, I think you might want to > > study the output of > > > > import this > > > > Think on the second and last lines in particular. > > >>> import this > The Zen of Python, by Tim Peters > > Beautiful is better than ugly. > Explicit is better than implicit. > Simple is better than complex. > Complex is better than complicated. > Flat is better than nested. > Sparse is better than dense. > Readability counts. > Special cases aren't special enough to break the rules. > Although practicality beats purity. > Errors should never pass silently. > Unless explicitly silenced. > In the face of ambiguity, refuse the temptation to guess. > There should be one-- and preferably only one --obvious way to do it. > Although that way may not be obvious at first unless you're Dutch. > Now is better than never. > Although never is often better than *right* now. > If the implementation is hard to explain, it's a bad idea. > If the implementation is easy to explain, it may be a good idea. > Namespaces are one honking great idea -- let's do more of those! > >>> > > "There should be one-- and preferably only one --obvious way to do it." > > Meanwhile, Alan Gauld pointed out: > > AG> because pow() is a builtin function and > AG> root = pow(x,0.5) > AG> is the same as > AG> root = math.sqrt(x) They're not the same. The math module is the one obvious way to do things that specifically involve floating point numbers and nothing else. ChrisA From ethan at stoneleaf.us Thu Jan 14 14:36:14 2021 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 14 Jan 2021 11:36:14 -0800 Subject: why sqrt is not a built-in function? In-Reply-To: References: Message-ID: On 1/14/21 11:06 AM, Eli the Bearded wrote: > "There should be one-- and preferably only one --obvious way to do it." > > Meanwhile, Alan Gauld pointed out: > > AG> because pow() is a builtin function and > AG> root = pow(x,0.5) > AG> is the same as > AG> root = math.sqrt(x) > > Plus the ** operation ("root = x ** 0.5"), that's now three ways. Yes, but which of those is obvious? -- ~Ethan~ From vincent.vandevyvre at oqapy.eu Thu Jan 14 14:51:02 2021 From: vincent.vandevyvre at oqapy.eu (vincent.vandevyvre at oqapy.eu) Date: Thu, 14 Jan 2021 14:51:02 -0500 (EST) Subject: Question - problem downloading Python Message-ID: <20210114204154.Gjhu240010ZUXkU06jhuqP@michel.telenet-ops.be> On 14/01/21 07:52, Christine Tiscareno wrote: >I installed in my lap-top your latest version of Python (3.9.1), yet when I >go to cmd.exe to check, I get that I have Python 22.7.17 ??? > >Why? What should I do to get the latest version? > I tried going back to fix problems and it does not fix it, that is how I >got your email. >How can I get the latest Python version (3.9.1), instead of what I'm >getting (22.7.17)? >Thank you for your time. Please, copy-paste all the content of your terminal (I presume this is wht you name cmd.exe). Vincent From barry at barrys-emacs.org Thu Jan 14 16:30:11 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 14 Jan 2021 21:30:11 +0000 Subject: Exploring terminfo In-Reply-To: References: Message-ID: > On 14 Jan 2021, at 16:12, Alan Gauld via Python-list wrote: > > During lockdown I've been digging deeper into the curses module > and lately into the tiXXXX family of functions that reside there. > > I've written a short program that is supposed to > - *clear the screen*, > - read some input > - display the result in a message *highlighted in bold*. > - get input to end the program It seems that curses does not allow you to mix raw stdin/stdout with its calls. (got that idea from a quick web search). If all you want is simple things like bold and clear I'd just use the ANSI escape sequences directly. Are there any terminals that do not understand ANSI escape sequences these days? Barry > > The parts marked with ** use terminfo, or they should. > My problem is that while the clear-screen part works the > bold bit only appears in the final input(), not in the > output message. > > Here is the code: > > ################# > import curses as cur > cur.setupterm() > > bold = cur.tigetstr('bold') > cls = cur.tigetstr('clear') > > cur.putp(cls) > name = input("Hello, what's your name? ") > > cur.putp(bold) > print("Nice to meet you ", name) > > input("\nHit enter to exit") > ############### > > I've tried variations on flush both inside and outside > the print() - both before and after. > I've tried writing to stdout instead of print, but nothing is working. > The Hit enter... message is in bold but the Hello... line isn't. > > Does anyone know what's going on and how to fix it. > > I could, of course, jump into full curses but I wanted to > see if I could use the terminfo stuff directly to retain > use of regular input() and print() functions. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > -- > https://mail.python.org/mailman/listinfo/python-list > From barry at barrys-emacs.org Thu Jan 14 16:39:14 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 14 Jan 2021 21:39:14 +0000 Subject: Question - problem downloading Python In-Reply-To: References: Message-ID: > On 14 Jan 2021, at 06:52, christine tiscareno wrote: > > I installed in my lap-top your latest version of Python (3.9.1), yet when I > go to cmd.exe to check, I get that I have Python 22.7.17 ??? > > Why? What should I do to get the latest version? > > I tried going back to fix problems and it does not fix it, that is how I > got your email. > > How can I get the latest Python version (3.9.1), instead of what I'm > getting (22.7.17)? I assume you typed "python". And I assume that it is because you have python 2.7.17 installed and its on your PATH. To run python 3.9.1 do this in cmd.exe py -3.9 It is also likely that just typing "py" will run python 3.9.1. Typing "py -2" will run python 2. Run this to find all the versions of python that you have available: py -0 Barry > > Thank you for your time. > > -- > Kind regards, Christine Tiscareno > -- > https://mail.python.org/mailman/listinfo/python-list > From wolfram.hinderer at googlemail.com Thu Jan 14 17:00:40 2021 From: wolfram.hinderer at googlemail.com (Wolfram Hinderer) Date: Thu, 14 Jan 2021 23:00:40 +0100 Subject: count consecutive elements In-Reply-To: References: Message-ID: <462c5e21-a3a8-e086-25d8-5fa9508a068a@gmail.com> Am 13.01.2021 um 22:20 schrieb Bischoop: > I want to to display a number or an alphabet which appears mostly > consecutive in a given string or numbers or both > Examples > s= ' aabskaaabadcccc' > output: c > # c appears 4 consecutive times > 8bbakebaoa > output: b > #b appears 2 consecutive times > > You can let itertools.groupy find the groups. max((len(tuple(group)), key) for key, group in itertools.groupby(s)) # (4, 'c') From * at eli.users.panix.com Thu Jan 14 17:10:16 2021 From: * at eli.users.panix.com (Eli the Bearded) Date: Thu, 14 Jan 2021 22:10:16 +0000 (UTC) Subject: Exploring terminfo References: Message-ID: In comp.lang.python, Barry Scott wrote: > Alan Gauld via Python-list wrote: >> I've written a short program that is supposed to >> - *clear the screen*, >> - read some input >> - display the result in a message *highlighted in bold*. >> - get input to end the program > It seems that curses does not allow you to mix raw stdin/stdout with its calls. This sounds very plausable. In C, in curses one uses printw() not printf(). > If all you want is simple things like bold and clear I'd just use the > ANSI escape sequences directly. > > Are there any terminals that do not understand ANSI escape sequences > these days? Probably, I hear tales of people using odd set-ups from time to time. But that could just be the circles I hang out in. When I've wanted to do simple things like bold and clear, I've used the tput(1) tool. You can capture stdout from the tool and use the output over and over. Typically I've done this in shell scripts: #!/bin/sh bold=$(tput smso) # set mode stand out nobold=$(tput rmso) # remove mode stand out clear=$(tput clear) # clear screen home=$(tput home) # home, without clear for word in Ten Nine Eight Seven Six Five Four Three Two One; do echo "${clear}${bold}${word}${nobold} ..." sleep 1 done echo "${home}Nothing happens." exit Elijah ------ adapting to python left as an excercise for the reader From grant.b.edwards at gmail.com Thu Jan 14 17:11:43 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 14 Jan 2021 22:11:43 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-14, Barry Scott wrote: > It seems that curses does not allow you to mix raw stdin/stdout with > its calls. (got that idea from a quick web search). That is definitely the case. Output in curses is done to an in-memory virtual terminal screen. Optimized output is then sent (at some point later) to update the physical terminal with any changes made in the virtual terminal since the last update. If you want to use ncurses, you can't mess with the physical terminal behind its back and expect anything to work. > If all you want is simple things like bold and clear I'd just use the > ANSI escape sequences directly. Or use a terminfo library: https://github.com/DirectXMan12/py-terminfo It _may_ be possible to use ncurses to get the terminfo strings required for various functions without actually having ncurses to any I/O, but I've never tried that... -- Grant From grant.b.edwards at gmail.com Thu Jan 14 18:08:38 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 14 Jan 2021 23:08:38 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-14, Eli the Bearded <*@eli.users.panix.com> wrote: > When I've wanted to do simple things like bold and clear, I've used the > tput(1) tool. You can capture stdout from the tool and use the output > over and over. Typically I've done this in shell scripts: > > #!/bin/sh > bold=$(tput smso) # set mode stand out > nobold=$(tput rmso) # remove mode stand out > [...] I was about to suggest using tput. https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x405.html https://linuxcommand.org/lc3_adv_tput.php https://martin-thoma.com/colorize-your-scripts-output/ >From python you could actually invoke the tput executable every time you wanted to do something, or you could cache the output strings produced by tput as demonstrated in the bash script above. Alternatively, I think you can use the ncurses library to retrieve the control strings (just don't use any ncurses input/output calls), like this example from https://stackoverflow.com/questions/6199285/tput-cup-in-python-on-the-commandline: from curses import * setupterm() cols = tigetnum("cols") lines = tigetnum("lines") print str(cols) + "x" + str(lines) place_begin = tparm(tigetstr("cup"), 15, 14) place_end = tparm(tigetstr("cup"), 50, 0) print place_begin + "-- some text --" + place_end From avigross at verizon.net Thu Jan 14 18:51:29 2021 From: avigross at verizon.net (Avi Gross) Date: Thu, 14 Jan 2021 18:51:29 -0500 Subject: why sqrt is not a built-in function? In-Reply-To: References: Message-ID: <0b0001d6ead0$2de55630$89b00290$@verizon.net> Ethan, if it is not obvious, then should we add the following functions just in case? cube_root() fourth_root() nth(root) two_thirds_root() e_th_root() pi_th_root() x_over_y_root() And so on. It is true that square roots are probably more commonly taken than many others above (I have never taken the pi_th root but you never know) and you can make a fourth root by taking the square root twice. There is nothing wrong with creating a convenience function but it needs to stop somewhere. The purpose of modules or packages and other add-ons is to supplement the base language that is loaded whether you want it or not. Some have argued to remove many current things from the base that THEY never use (or compiled their own such version) to make it smaller and faster. Given that, you can either import the sqrt function or make your own that just turns around and uses one of the methods that is built-in. But if you use all kinds of things regularly, consider importing them all at once by having your own module with some name that imports all of them and importing that and waiting as they all load. -----Original Message----- From: Python-list On Behalf Of Ethan Furman Sent: Thursday, January 14, 2021 2:36 PM To: python-list at python.org Subject: Re: why sqrt is not a built-in function? On 1/14/21 11:06 AM, Eli the Bearded wrote: > "There should be one-- and preferably only one --obvious way to do it." > > Meanwhile, Alan Gauld pointed out: > > AG> because pow() is a builtin function and > AG> root = pow(x,0.5) > AG> is the same as > AG> root = math.sqrt(x) > > Plus the ** operation ("root = x ** 0.5"), that's now three ways. Yes, but which of those is obvious? -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list From PythonList at DancesWithMice.info Thu Jan 14 19:43:03 2021 From: PythonList at DancesWithMice.info (dn) Date: Fri, 15 Jan 2021 13:43:03 +1300 Subject: Friday Finking: Abstract Base Classes - love or hate Message-ID: <7a8602e9-3054-5e7c-d549-e342f7bee8e2@etelligence.info> Do you make frequent use of Abstract Base Classes (ABCs), prefer to use an ordinary super-class for the same purpose, or steer-clear? Are they more-usually employed when the project includes an extensive design stage, and the meta-class integral to some hierarchy of entities? Previous Friday Finkings have arisen from in-house discussions within a Python dev.team which deserved a wider airing or debate. This contains (with due apologies) excessive personal reflection and comments abstracted from posts to this Discussion List. Many of us have used Python for years but never touched ABCs. Apparently then, we don't need to be aware of them! Colleagues 'here' have said "never used it" and/or "never seen the need", and similar. Often pythonista learn how to define class(es), and then to inherit or compose further classes. Everything works swimmingly. If it ain't broke, don't fix it! So, we have no reason to advance our programming capabilities/knowledge. Indeed an earlier post voiced the suggestion that we could get on quite happily without knowing about/using ABCs. Aside: Certainly the earliest iteration of Python meta-classes/ABCs (related, but confusingly different - am not going there!) 'arrived' at about the same time as did I - back at Python 1.n - but I've only ever/started using ABCs, since circa 3.5. Thus, from personal learning-experience: one can only understand and use abstract-classes after gaining a thorough understanding and facility with using (ordinary) class-es. (perhaps?) Conducting (what some people call) extensive research*, we will be told that an ABC is: "a way to overload isinstance() and issubclass()". When would we use those two functions which introspect a class-hierarchy? isinstance(object, classinfo) = is the object argument an instance of the classinfo argument issubclass(class, classinfo) = is the class argument a subclass of the classinfo argument (etc) Luv-a-duck! How does this fit with duck-typing and EAFP? (sorry, terrible attempt at a joke) Aren't we supposed to *presume* that we our sub-class/instance is just that, and we should just presume to use its data and methods (wrapped in a try...except in case 'forgiveness' might be necessary)? Perhaps with the increasing number of DataScience folk using Python (?), we do seem to be finding a reasonable proportion of Python improvements/updates seemingly heading in the LBYL direction... OK, let's go-with-the-flow. There are two 'problems' with the isinstance()/issubclass() approach: - it's not very duck-y - when it 'happens'. So, let's say we want to *execute* a particular method against the current data-structure. We can only do this if the class (or its hierarchy) includes said method. Thus: data.method( arguments... ) However, we are concerned that the instance may not be part of a hierarchy offering this method. What can we do? - EAFP: wrap in try...except - LBYL: check for method by assuring the hierarchy, eg isinstance() Each incurring the consequential-problem: but what then? The problem is not 'discovered' until execution-time - worst-case scenario: it is discovered by some user (who is no-longer our friend). If we are really going LBYL, surely we want to discover the problem as early as possible, ie preferably whilst coding+testing? Using an ABC we can do just that, because the presence/absence of methods is checked when the sub-class is defined. If it does not implement all of the required methods, the sub-class will fail. Yes, we could do that by coding a super-class with methods that contain only: raise NotImplementedError() but when would a sub-class's error in not implementing the method then be 'discovered'? Personal aside/illustration/confession: I implemented an application which used "plug-ins" - effectively filters/actions. The first couple of use-cases were easy - they were integral to the application-design. As is the way of these things, few months later a request arrived for another plug-in. Of course, I was very happy with the plug-in which I coded oh-so-quickly. Trouble is, I *forgot* to implement one of the required methods, and mis-spelled another. Yes, if I had a scrap of humility, I should have re-read my original code. Sigh! Forget the apocryphal "will your future self remember in six months' time", as I have aged (and most of us do!), I've moved my philosophy to one of trying to avoid having to remember - firstly in six *weeks'* time, and more recently: six *days'*! All was greatly improved by implementing an ABC as a guide, or a check-list, even, a template - as proven by later requests for yet more 'plug-ins'... Please remember that 'umble scribe is not an "OOP-native", starting this career way-back when mainframes were powered by dinosaurs in tread-mills. I am told this is what other languages refer to as an "interface". In some ways I visualise the ABC as a "mixin" - perhaps better-understood when the ABC does include an inheritable method. (feel free to add/discuss/correct...) Back to the "Finking": When faced with a 'green-field' project, and a dev.team sits down to create a solid overview design, I've noticed architects and experienced designers 'see' where meta-classes should be employed and specify (and are probably the ones to build), accordingly. My experience with smaller projects is that TDD directs us to develop one functional-step at a time. Once successfully tested, we re-factor and consider qualitative factors. Either the former or latter step may involve a decision to sub-class an existing structure, or similar. It is possible that such may include opportunity (even, highlight that it would be good sense) to employ an ABC and derive from there - because at this time we may better-appreciate opportunities for re-use, plus having the tests in-place reduces fear of breakage! However, as described, my usage seems to be less about data-structures and more like a check-list of functionality - which I might otherwise forget to implement in a sub-class. So, does that imply that when there is a wide and detailed design stage meta-classes may be employed 'from the word go'; whereas if we employ a more bottom-up approach, they only make an appearance as part of a 'make it better' process? Web.Refs: (warning - much of the stuff 'out there' on the web is dated and possibly even misleading to users of 'today's Python'!) https://www.python.org/dev/peps/pep-3119/ https://docs.python.org/3/library/abc.html https://docs.python.org/3/library/functions.html#isinstance https://docs.python.org/3/library/functions.html#issubclass https://idioms.thefreedictionary.com/Lord+love+a+duck! https://www.tutorialspoint.com/abstract-base-classes-in-python-abc https://devtut.github.io/python/abstract-base-classes-abc.html https://everyday.codes/python/abstract-classes-and-meta-classes-in-python/ * ie the top two 'hits' returned by DuckDuckGo - mere "research" involves only taking the first/"I feel lucky" Sample code: from abc import ABC, abstractmethod class Image( ABC ): def __init__( self, name )->None: self.name = name @abstractmethod def load( self, filename:str ): """Load image from file into working-memory.""" @abstractmethod def save( self, filename:str ): """Save edited image to file-system.""" try: i = Image() except TypeError: print( "Sorry, can't instantiate i/Image directly" ) class Non_Image( Image ): def load_file( self, filename:str ): """This looks reasonable.""" try: n = Non_Image( "Under Exposed" ) except TypeError: print( "Sorry, n/Non_Image does not look good" ) class PNG_Image( Image ): def load( self, filename:str ): """Load PNG file.""" def save( self, filename:str ): """Save to PNG file.""" p = PNG_Image( "Picture of the Artist as a Young Man" ) print( "p has instantiated successfully" ) -- Regards, =dn From * at eli.users.panix.com Thu Jan 14 20:11:00 2021 From: * at eli.users.panix.com (Eli the Bearded) Date: Fri, 15 Jan 2021 01:11:00 +0000 (UTC) Subject: why sqrt is not a built-in function? References: Message-ID: In comp.lang.python, Ethan Furman wrote: > On 1/14/21 11:06 AM, Eli the Bearded wrote: >> "There should be one-- and preferably only one --obvious way to do it." >> Plus the ** operation ("root = x ** 0.5"), that's now three ways. > Yes, but which of those is obvious? If it's up to me, the ** one. Elijah ------ using a syntax with "^" instead of "**" would be okay, too From greg.ewing at canterbury.ac.nz Fri Jan 15 00:13:36 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 15 Jan 2021 18:13:36 +1300 Subject: why sqrt is not a built-in function? In-Reply-To: References: <0b0001d6ead0$2de55630$89b00290$@verizon.net> Message-ID: Aother thing to consider is that math.sqrt is not the only sqrt function in Python. There is also one in cmath, and in the wider ecosystem, another one in numpy. Being explicit about which one you're using is a good thing. Concerning exponentiation, it can be used to achieve the same thing as sqrt, but the sqrt function probably uses a more efficient algorithm. Also, exponentiation assumes you're okay with getting a complex result: >>> (-27)**0.5 (3.181725716174721e-16+5.196152422706632j) So it's not quite the same thing as math.sqrt(). -- Greg From greg.ewing at canterbury.ac.nz Fri Jan 15 00:32:35 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 15 Jan 2021 18:32:35 +1300 Subject: conceptual problem (was: A beginning beginner's question about input, output and . . . In-Reply-To: References: <3ng3dh-kha.ln1@anthive.com> Message-ID: On 14/01/21 11:49 am, Cameron Simpson wrote: > The "pure" OOP approach, where method calls are used as messages to set > or fetch aspects of the object, is usually does with getter and setter > methods like: > > x = o.getX() > o.setX(9) People use get and set methods, not because it's somehow morally wrong to expose attributes directly, but as a workaround for the lack of a language feature. In C++ and Java, different calling syntax is required for direct access and access mediated by methods, so if you start out exposing something directly and then change your mind, all the code using it has to be changed. For this reason, people got into the habit of wrapping everything in get and set methods from the beginning, "just in case". Python doesn't have this problem -- you can turn an attribute into a property at any time, and nothing else needs to change. So get and set methods are unnecessary and actively discouraged in Python. (C#, if I understand correctly, gets this sort of half-right. You can turn an attribute into a property, and the calling *source* doesn't change, but it all has to be recompiled -- which kind of defeats the purpose.) -- Greg From rob.cliffe at btinternet.com Thu Jan 14 14:00:20 2021 From: rob.cliffe at btinternet.com (Rob Cliffe) Date: Thu, 14 Jan 2021 19:00:20 +0000 Subject: why sqrt is not a built-in function? In-Reply-To: References: Message-ID: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> On 14/01/2021 17:44, Denys Contant wrote: > I don't understand why sqrt is not a built-in function. > Why do we have to first import the function from the math module? > I use it ALL THE TIME! I agree that, especially if you have experience in other languages, this feels odd, and I have some sympathy for you.? I am not sure that I can give you a 100% satisfactory answer. But: ??? if the math module should be automatically imported, how many other modules that _somebody_ uses "all the time" should also be automatically be imported?? Python gives you a light-weight framework (fast to load a program) with the option to plug in whichever batteries you need, and it's not so terrible to remember to write "import math" or similar, especially after the first time. > > That felt good. Thank you. Although I hope you have other ways of venting your frustration than shouting at newsgroups.? Perhaps juggling balls? Best wishes Rob Cliffe From alan.gauld at yahoo.co.uk Thu Jan 14 19:47:02 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 15 Jan 2021 00:47:02 +0000 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 14/01/2021 21:30, Barry Scott wrote: >> During lockdown I've been digging deeper into the curses module >> and lately into the tiXXXX family of functions that reside there. > It seems that curses does not allow you to mix raw stdin/stdout with its calls. That's true of curses after you call initscr() But the while point of using the tiXXX terminfo functions is that you don't need to call initscr to use them, just setupterm() which does no take control in the same way. The problem is the tiXXX functions are not well documented and there are very few tutorials, even in C! > If all you want is simple things like bold and clear I'd just use the > ANSI escape sequences directly. The whole point of terminfo is to avoid having to use terminal specific control codes. > Are there any terminals that do not understand ANSI escape sequences Lots, most significantly the x3270 IBM mainframe terminals. Now, whether you can run curses and terminfo on a 3270 I don't know... But I suspect the Wyse family are non ANSI compliant too and there are still some of them around. And of course the standard xterm emulator supports the Tektronic graphics terminal emulation so there would definitely be a use there. But to be honest if I was doing this in anger I'd just use curses. This is more about exploring the module. The functions are there and so we should be able to use them and demonstrate them. But for that we need tutorials/HowTos etc that cover them. I've already written a curses HowTo, I'd like to extend it to cover the terminfo bits too. But for now I'm drawing a blank. -- 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 Thu Jan 14 19:49:06 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 15 Jan 2021 00:49:06 +0000 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 14/01/2021 22:11, Grant Edwards wrote: > Or use a terminfo library: > > https://github.com/DirectXMan12/py-terminfo > > It _may_ be possible to use ncurses to get the terminfo strings > required for various functions without actually having ncurses to any > I/O, but I've never tried that... That is precisely what the tiXXX family of functions in the curses module is supposed to enable. I'm just struggling to get anything other than very basic stuff working! -- 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 Thu Jan 14 19:56:05 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 15 Jan 2021 00:56:05 +0000 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 14/01/2021 23:08, Grant Edwards wrote: > Alternatively, I think you can use the ncurses library to retrieve the control > strings (just don't use any ncurses input/output calls), like this example from > https://stackoverflow.com/questions/6199285/tput-cup-in-python-on-the-commandline: > > from curses import * > setupterm() > > cols = tigetnum("cols") > lines = tigetnum("lines") > print str(cols) + "x" + str(lines) > > place_begin = tparm(tigetstr("cup"), 15, 14) > place_end = tparm(tigetstr("cup"), 50, 0) > > print place_begin + "-- some text --" + place_end That's exactly what I'm trying to do but with the character attributes rather than cursor positioning. I can retrieve values and I can clear the screeeen. But the bold(and inverse and underline etc) strings don;yt seem to affect print() or stdout.write(). But they do affect the input() prompt strings. What is different about the input() prompts? Why are they affected when print isn't? I've discovered that I can (sort of) get my code to work if I insert blank input statements between the various prints. But then I need to keep hitting return to get the display to show up - not exactly useful. But the point is that after an input() the subsequent print statements use the set attributes as desired. What can I insert to get the same effect without requiring the user to type input between prints? Or what parameter should I be setting where? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From alan.gauld at yahoo.co.uk Fri Jan 15 08:19:26 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 15 Jan 2021 13:19:26 +0000 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 14/01/2021 16:12, Alan Gauld via Python-list wrote: > ################# > import curses as cur > cur.setupterm() > > bold = cur.tigetstr('bold') > cls = cur.tigetstr('clear') > > cur.putp(cls) > name = input("Hello, what's your name? ") > > cur.putp(bold) > print("Nice to meet you ", name) > > input("\nHit enter to exit") > ############### > > I've tried variations on flush both inside and outside > the print() - both before and after. > I've tried writing to stdout instead of print, but nothing is working. > The "Hit enter..." message is in bold but the "Nice..." line isn't. A bit more exploration and I've got a C version of the same program to work (I'll spare you the #includes!): int main(void){ char line[20]; int err = 0; char *clr; char *bold; setupterm("xterm",1, &err); clr = tigetstr("clear"); bold = tigetstr("bold"); putp(clr); putp(bold); printf("Enter a name: "); fgets(line, sizeof(line),stdin); printf("Hello %s\n", line); exit(0); } So the native C functions work as expected. Why does the Python wrapper not? -- 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 Fri Jan 15 12:31:42 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 15 Jan 2021 17:31:42 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-15, Alan Gauld via Python-list wrote: > On 14/01/2021 16:12, Alan Gauld via Python-list wrote: > >> ################# >> import curses as cur >> cur.setupterm() >> >> bold = cur.tigetstr('bold') >> cls = cur.tigetstr('clear') >> >> cur.putp(cls) >> name = input("Hello, what's your name? ") >> >> cur.putp(bold) >> print("Nice to meet you ", name) >> >> input("\nHit enter to exit") >> ############### >> >> I've tried variations on flush both inside and outside >> the print() - both before and after. >> I've tried writing to stdout instead of print, but nothing is working. >> The "Hit enter..." message is in bold but the "Nice..." line isn't. > > A bit more exploration and I've got a C version of the same program > to work (I'll spare you the #includes!): > > int main(void){ > char line[20]; > int err = 0; > char *clr; > char *bold; > > setupterm("xterm",1, &err); > clr = tigetstr("clear"); > bold = tigetstr("bold"); > > putp(clr); > putp(bold); > printf("Enter a name: "); > fgets(line, sizeof(line),stdin); > > printf("Hello %s\n", line); > exit(0); > } > So the native C functions work as expected. > Why does the Python wrapper not? One difference is that the name prompt is being written to stdout in the C version and stderr in the Python version. But I don't see why that would matter. I suspect that the problem is that putp is writing to the libc "stdout" FILE stream that's declaredin . That stream layer/object has buffering that is invisible to Python. Python's sys.stdout.flush() is flushing the Python file object's output buffers to the standard output file descriptor(fd 2). It is not flushing the the libc FILE stream's output buffers. That apparently doesn't happen until input() is called (not sure why input() does that). If you omit the second input() call, and just write to sys.stdout, then the bold escape sequence doesn't get output until the program terminates. Now the question: is there a way to tell the curses module to flush its stdout FILE stream? -- Grant From grant.b.edwards at gmail.com Fri Jan 15 13:33:04 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 15 Jan 2021 18:33:04 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-15, Grant Edwards wrote: > I suspect that the problem is that putp is writing to the libc > "stdout" FILE stream that's declaredin . That stream > layer/object has buffering that is invisible to Python. Python's > sys.stdout.flush() is flushing the Python file object's output buffers > to the standard output file descriptor(fd 2). This problem probably didn't happen with older versions of python where python's stdout file object was on top of the libc stdout FILE stream, and calling sys.stdout.flush() flushed both layers of buffering out to the file descriptor. Starting in Python 3., python's stdio file objects are _not_ on top of the libc FILE streams: they're directly on top of the file descriptor. IOW, Python's stdout file object buffering and ncurses stdout FILE buffering are independent of each other. They reside "beside" each other, both writing to the file descriptor whenever they see fit with no coordination between the two. -- Grant From alan.gauld at yahoo.co.uk Fri Jan 15 13:36:20 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Fri, 15 Jan 2021 18:36:20 +0000 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 15/01/2021 17:31, Grant Edwards wrote: >>> cur.putp(cls) >>> name = input("Hello, what's your name? ") >>> >>> cur.putp(bold) >>> print("Nice to meet you ", name) >> putp(clr); >> putp(bold); >> printf("Enter a name: "); >> fgets(line, sizeof(line),stdin); >> >> printf("Hello %s\n", line); >> exit(0); > One difference is that the name prompt is being written to stdout in > the C version and stderr in the Python version. But I don't see why > that would matter. That could make a big difference, the putp() function specifically states that it writes to stdout. > I suspect that the problem is that putp is writing to the libc > "stdout" FILE stream that's declaredin . That stream > layer/object has buffering that is invisible to Python. That would indeed explain it. > Now the question: is there a way to tell the curses module to flush > its stdout FILE stream? Indeed. But unless it's trivial it rather defeats the concept of using the terminfo functions to create text effects without diving into full curses screen control! And that was what I was hoping to uncover. I wonder if I can use the os module to mess with the file descriptors.... hmmm. Thanks for that snippet, I had no idea that input() wrote to stderr nor that Python added a stdout layer on top of libc. Do you know where that is documented? I'd be interested in reading more. -- 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 Fri Jan 15 13:40:37 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 15 Jan 2021 18:40:37 -0000 (UTC) Subject: How to flush 's stdout stream? Message-ID: In Python 3.7+, how does one flush the stdout FILE stream? I mean the FILE *declared as 'stdio' in . I'm _not_ asking how to flush the Python file object sys.stdio. The problem is that some Python modules write to FILE *stdio, but don't flush the stream so that the data gets written to the standard output file descriptor (fd 1). If you need to interleave the output from those modules with writes from other Python code to fd 1 (via sys.stdout or whatever), you need a way to flush FILE *stdio. I know how to use ctypels to call fflush(), but I can't figure out how to get the FILE *stdio value to pass to fflush(). Is there some os.??? or sys.??? function that I've missed? From mstemper at gmail.com Fri Jan 15 14:16:02 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Fri, 15 Jan 2021 13:16:02 -0600 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: On 14/01/2021 13.00, Rob Cliffe wrote: > On 14/01/2021 17:44, Denys Contant wrote: >> I don't understand why sqrt is not a built-in function. >> Why do we have to first import the function from the math module? >> I use it ALL THE TIME! > I agree that, especially if you have experience in other languages, this > feels odd, and I have some sympathy for you. I cut my teeth on FORTRAN, which has SQRT() as part of the language. At least 3, 4, and 5 did; I never used later versions. Here's the status of the square root function in various languages, in the order that I encountered them: FORTRAN Part of the language Pascal Part of the language SNOBOL Part of the language c Need to #include clisp Part of the language EcmaScript Part of the language python Need to import from math Java Need to import from java.math The four that appear to be in the most use currently are c, EcmaScript, python, and Java. Of these, only EcmaScript has Math.sqrt() as part of the language, and that could be partly due to the fact that the language doesn't have any concept of "import" or "include". -- Michael F. Stemper This email is to be read by its intended recipient only. Any other party reading is required by the EULA to send me $500.00. From rosuav at gmail.com Fri Jan 15 15:02:39 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jan 2021 07:02:39 +1100 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: On Sat, Jan 16, 2021 at 6:21 AM Michael F. Stemper wrote: > Here's the status of the square root function in various languages, > in the order that I encountered them: > > FORTRAN Part of the language > Pascal Part of the language > SNOBOL Part of the language > c Need to #include > clisp Part of the language > EcmaScript Part of the language > python Need to import from math > Java Need to import from java.math > > The four that appear to be in the most use currently are c, > EcmaScript, python, and Java. Of these, only EcmaScript has > Math.sqrt() as part of the language, and that could be partly > due to the fact that the language doesn't have any concept of > "import" or "include". > Cool. Now tell me: Of all the languages that have a built-in global name SQRT (which does not include ECMAScript, and for the record, ES does have imports), how many of them have a built-in or syntax for dictionaries/mappings? I would put it to you that the ability to look up something by name in a tree, hashtable, or equivalent, is *at least* as useful as the ability to calculate a square root. Python gives you both (since you can raise something to the 0.5th power), JavaScript in a web browser gives you both, C gives you neither (you have to #include), and you can fill in the rest yourself. Languages differ. I don't see why it's so important to focus on just one thing - and to complain that, even though it's in the standard library, you have to use an import command to get it. ChrisA From mstemper at gmail.com Fri Jan 15 15:21:17 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Fri, 15 Jan 2021 14:21:17 -0600 Subject: why sqrt is not a built-in function? In-Reply-To: <8s89dh-ce07.ln1@esprimo.zbmc.eu> References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> <8s89dh-ce07.ln1@esprimo.zbmc.eu> Message-ID: On 15/01/2021 14.00, Chris Green wrote: > Michael F. Stemper wrote: >> On 14/01/2021 13.00, Rob Cliffe wrote: >>> On 14/01/2021 17:44, Denys Contant wrote: >> >>>> I don't understand why sqrt is not a built-in function. >>>> Why do we have to first import the function from the math module? >>>> I use it ALL THE TIME! >>> I agree that, especially if you have experience in other languages, this >>> feels odd, and I have some sympathy for you. >> >> I cut my teeth on FORTRAN, which has SQRT() as part of the >> language. At least 3, 4, and 5 did; I never used later versions. >> > Surely III, IV and V. I was definitely Fortran IV I think that the listings for my cross-compiles for the Cyber 1700 actually said "FORTRAN 3" at the top of each page, but that was over three decades back, so it's a little hazy. There weren't any standards for it anyway. You're spot-on for FORTRAN IV. A quick check of wikipedia shows that the last one was better referred to as FORTRAN 77, but I think that the NOS command to invoke the compiler was FTN5. -- Michael F. Stemper Galatians 3:28 From eryksun at gmail.com Fri Jan 15 15:31:31 2021 From: eryksun at gmail.com (Eryk Sun) Date: Fri, 15 Jan 2021 14:31:31 -0600 Subject: How to flush 's stdout stream? In-Reply-To: References: Message-ID: On 1/15/21, Grant Edwards wrote: > In Python 3.7+, how does one flush the stdout FILE stream? I mean the > FILE *declared as 'stdio' in . I'm _not_ asking how to flush the > Python file object sys.stdio. You can flush all output streams via C fflush(NULL). If it has to be just stdout, the code will vary by platform. As far as I know, there is no standard way at the ABI level to reference C stdin, stdout, and stderr. Typically these are macros at the API level. The macro might directly reference the FILE record, or maybe it calls an inline function that returns the reference. CPython doesn't have a common wrapper function for this. With ctypes, you'll have to special case common platform CRTs such as glibc in Linux and ucrt in Windows (possible, but undocumented). For example: import sys import time import ctypes if sys.platform == 'win32' and sys.version_info >= (3, 5): libc = ucrt = ctypes.CDLL('ucrtbase', use_errno=True) IOLBF = 0x0040 libc.__acrt_iob_func.restype = ctypes.c_void_p stdout = ctypes.c_void_p(libc.__acrt_iob_func(1)) elif sys.platform == 'linux': libc = cglobal = ctypes.CDLL(None, use_errno=True) IOLBF = 1 stdout = ctypes.c_void_p.in_dll(libc, 'stdout') # ensure that stdout is buffered for this test # has to be called before stdout is used libc.setvbuf(stdout, None, IOLBF, 4096) def test(flush=False): print(f'test with flush={flush}') libc.fwrite(b'spam', 1, 4, stdout) if flush: libc.fflush(stdout) time.sleep(5) libc.fflush(None) print() test(flush=False) test(flush=True) With flush=False, the test should wait 5 seconds before 'spam' is flushed to the console/terminal. With flush=True, there should be no delay. From cl at isbd.net Fri Jan 15 15:00:40 2021 From: cl at isbd.net (Chris Green) Date: Fri, 15 Jan 2021 20:00:40 +0000 Subject: why sqrt is not a built-in function? References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: <8s89dh-ce07.ln1@esprimo.zbmc.eu> Michael F. Stemper wrote: > On 14/01/2021 13.00, Rob Cliffe wrote: > > On 14/01/2021 17:44, Denys Contant wrote: > > >> I don't understand why sqrt is not a built-in function. > >> Why do we have to first import the function from the math module? > >> I use it ALL THE TIME! > > I agree that, especially if you have experience in other languages, this > > feels odd, and I have some sympathy for you. > > I cut my teeth on FORTRAN, which has SQRT() as part of the > language. At least 3, 4, and 5 did; I never used later versions. > Surely III, IV and V. I was definitely Fortran IV -- Chris Green ? From grant.b.edwards at gmail.com Fri Jan 15 15:32:59 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 15 Jan 2021 20:32:59 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-15, Alan Gauld via Python-list wrote: > On 15/01/2021 17:31, Grant Edwards wrote: > >> I suspect that the problem is that putp is writing to the libc >> "stdout" FILE stream that's declaredin . That stream >> layer/object has buffering that is invisible to Python. > > That would indeed explain it. > >> Now the question: is there a way to tell the curses module to flush >> its stdout FILE stream? > > Indeed. But unless it's trivial it rather defeats the concept of > using the terminfo functions to create text effects without > diving into full curses screen control! Indeed, that appears to be the case for Python 3.x (unless we can figure out a way to flush 's FILE *stdio stream from Python). I started a separate thread about that specific topic. > And that was what I was hoping to uncover. > > I wonder if I can use the os module to mess with the > file descriptors.... hmmm. > > Thanks for that snippet, I had no idea that input() wrote > to stderr nor that Python added a stdout layer on top of libc. Just to be clear, Python 3.7+ stdio,stdin,stderr layers are _not_ on top of libc's FILE *stdout, stdin, stderr streams and share nothing with them other than the spelling of the names and (by default) the underlying file descriptors. Python's input/output layers are on top of file descriptors 0, 1, 2. Older versions of Python had I/O layers that were on top of libc's FILE *stdin, *stdout, *stderr. > Do you know where that is documented? I'd be interested in > reading more. I can't find it at the moment. Unfortunately words like "file" and "stream" are too common for Google. From mstemper at gmail.com Fri Jan 15 15:39:43 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Fri, 15 Jan 2021 14:39:43 -0600 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: On 15/01/2021 14.02, Chris Angelico wrote: > On Sat, Jan 16, 2021 at 6:21 AM Michael F. Stemper wrote: >> Here's the status of the square root function in various languages, >> in the order that I encountered them: >> >> FORTRAN Part of the language >> Pascal Part of the language >> SNOBOL Part of the language >> c Need to #include >> clisp Part of the language >> EcmaScript Part of the language >> python Need to import from math >> Java Need to import from java.math >> >> The four that appear to be in the most use currently are c, >> EcmaScript, python, and Java. Of these, only EcmaScript has >> Math.sqrt() as part of the language, and that could be partly >> due to the fact that the language doesn't have any concept of >> "import" or "include". >> > > Cool. Now tell me: Of all the languages that have a built-in global > name SQRT (which does not include ECMAScript, I wasn't looking at how the various languages spell it, I was just looking at the fact that it could be used directly. Since ECMAScript has a function Math.sqrt(), I counted it as being a direct part of the language. > and for the record, ES > does have imports), I stand corrected. So I could say something like "import Math.*" and then use "sqrt()" directly? > how many of them have a built-in or syntax for > dictionaries/mappings? Beats me. That wasn't what the OP was complaining about. I just did this little ad-hoc survey to show that more modern languages don't have an "inherent" square root function, so python's hardly unique. > I would put it to you that the ability to look > up something by name in a tree, hashtable, or equivalent, is *at > least* as useful as the ability to calculate a square root. I don't think that I've used the square root function since I took a course in geometry in the fall of 2019, so I have no grounds to dispute. > Languages differ. I don't see why it's so important to focus on just > one thing - and to complain that, even though it's in the standard > library, you have to use an import command to get it. You should probably direct this to the person who complained rather than the person who showed that the complaint wasn't really consistent with modern language direction, while python's handling of the square root function is consistent. -- Michael F. Stemper Galatians 3:28 From rosuav at gmail.com Fri Jan 15 15:46:54 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jan 2021 07:46:54 +1100 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: On Sat, Jan 16, 2021 at 7:45 AM Michael F. Stemper wrote: > > Languages differ. I don't see why it's so important to focus on just > > one thing - and to complain that, even though it's in the standard > > library, you have to use an import command to get it. > > You should probably direct this to the person who complained rather than > the person who showed that the complaint wasn't really consistent with > modern language direction, while python's handling of the square root > function is consistent. > Sorry, you're right, it looked like I was focusing on you there. Your post was a convenient one to pick up on, since it had some data - that's all :) My point about complaining was aimed at the OP, who started this thread with a rant on the basis of having to "import math". No offense meant to anyone, least of all you. ChrisA From rshepard at appl-ecosys.com Fri Jan 15 15:51:19 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jan 2021 12:51:19 -0800 (PST) Subject: Writing a Python3 ttk.Notebook Message-ID: I want to replace the menu on my application with the more appropriate notebook. After looking at examples in my reference books and on the Web I still cannot get it working properly. Here's a small example (nbtest.py): ---8< ----------------------- #!/usr/bin/env python3 import tkinter as tk from tkinter import ttk from tkinter.ttk import Notebook as n class Test(tk.Tk): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # notebook n = ttk.Notebook(self) self.tab1 = ttk.Frame(n) # activities self.tab2 = ttk.Frame(n) # people self.tab3 = ttk.Frame(n) # locations self.tab4 = ttk.Frame(n) # organizations self.tab5 = ttk.Frame(n) # reports self.tab6 = ttk.Frame(n) # lookup tables self.add(tab1, text='Activities') self.add(tab2, text='People') self.add(tab3, text='Locations') self.add(tab4, text='Organizations') self.add(tab5, text='Reports') self.add(tab6, text='Lookups') n.pack(expand = 1, fill ="both") if __name__ == "__main__": app = Test() app.mainloop() ---->8 ------------------------- python-3.9.1 returns: $ ./nbtest.py Traceback (most recent call last): File "/home/rshepard/development/business_tracker/./nbtest.py", line 32, in app = Test() File "/home/rshepard/development/business_tracker/./nbtest.py", line 22, in __init__ self.add(tab1, text='Activities') File "/usr/lib64/python3.9/tkinter/__init__.py", line 2346, in __getattr__ return getattr(self.tk, attr) AttributeError: '_tkinter.tkapp' object has no attribute 'add' Explanation of the error and suggestions for ttk.notebook references are needed. TIA, Rich From mstemper at gmail.com Fri Jan 15 16:14:26 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Fri, 15 Jan 2021 15:14:26 -0600 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: On 15/01/2021 14.01, Stefan Ram wrote: > "Michael F. Stemper" writes: >> Of these, only EcmaScript has >> Math.sqrt() as part of the language, and that could be partly >> due to the fact that the language doesn't have any concept of >> "import" or "include". > > You do not need to use the import statement in Python, > but can also use the expression > > __import__( "math" ).sqrt( 4 ) I had no idea that syntax existed, and find it completely at odds with The Zen of Python. I'm torn between forgetting that I ever saw it and using it for some evilly-obfuscated code. I hope that it satisfies the OP. -- Michael F. Stemper I feel more like I do now than I did when I came in. From rosuav at gmail.com Fri Jan 15 16:20:50 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jan 2021 08:20:50 +1100 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: On Sat, Jan 16, 2021 at 8:16 AM Michael F. Stemper wrote: > > On 15/01/2021 14.01, Stefan Ram wrote: > > "Michael F. Stemper" writes: > > >> Of these, only EcmaScript has > >> Math.sqrt() as part of the language, and that could be partly > >> due to the fact that the language doesn't have any concept of > >> "import" or "include". > > > > You do not need to use the import statement in Python, > > but can also use the expression > > > > __import__( "math" ).sqrt( 4 ) > > I had no idea that syntax existed, and find it completely at odds > with The Zen of Python. I'm torn between forgetting that I ever saw > it and using it for some evilly-obfuscated code. > Hehe, it's really nothing to do with the Zen; it's playing around with internals, so you get whatever you get. I recommend option #2. It is incredibly good fun. For added bonus obscurity, don't import a module directly; import it from some unrelated module, such as "from ast import sys" or "from base64 import re". ChrisA From python at mrabarnett.plus.com Fri Jan 15 16:39:53 2021 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 15 Jan 2021 21:39:53 +0000 Subject: Writing a Python3 ttk.Notebook In-Reply-To: References: Message-ID: <65aba32e-dd59-f0bd-6f8c-4b584883bb10@mrabarnett.plus.com> On 2021-01-15 20:51, Rich Shepard wrote: > I want to replace the menu on my application with the more appropriate > notebook. After looking at examples in my reference books and on the Web I > still cannot get it working properly. > > Here's a small example (nbtest.py): > ---8< ----------------------- > #!/usr/bin/env python3 > > import tkinter as tk > from tkinter import ttk > from tkinter.ttk import Notebook as n > > class Test(tk.Tk): > > def __init__(self, *args, **kwargs): > super().__init__(*args, **kwargs) > > # notebook > n = ttk.Notebook(self) > > self.tab1 = ttk.Frame(n) # activities > self.tab2 = ttk.Frame(n) # people > self.tab3 = ttk.Frame(n) # locations > self.tab4 = ttk.Frame(n) # organizations > self.tab5 = ttk.Frame(n) # reports > self.tab6 = ttk.Frame(n) # lookup tables > > self.add(tab1, text='Activities') > self.add(tab2, text='People') > self.add(tab3, text='Locations') > self.add(tab4, text='Organizations') > self.add(tab5, text='Reports') > self.add(tab6, text='Lookups') > You should be adding the frames to the notebook. Also, the tabs are 'self.tab1', not 'tab1', etc: n.add(self.tab1, text='Activities') Similarly for the others. > n.pack(expand = 1, fill ="both") > > if __name__ == "__main__": > app = Test() > app.mainloop() > ---->8 ------------------------- > > python-3.9.1 returns: > $ ./nbtest.py > Traceback (most recent call last): > File "/home/rshepard/development/business_tracker/./nbtest.py", line 32, in > app = Test() > File "/home/rshepard/development/business_tracker/./nbtest.py", line 22, in __init__ > self.add(tab1, text='Activities') > File "/usr/lib64/python3.9/tkinter/__init__.py", line 2346, in __getattr__ > return getattr(self.tk, attr) > AttributeError: '_tkinter.tkapp' object has no attribute 'add' > > Explanation of the error and suggestions for ttk.notebook references are > needed. > From rshepard at appl-ecosys.com Fri Jan 15 16:51:34 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jan 2021 13:51:34 -0800 (PST) Subject: Writing a Python3 ttk.Notebook In-Reply-To: <65aba32e-dd59-f0bd-6f8c-4b584883bb10@mrabarnett.plus.com> References: <65aba32e-dd59-f0bd-6f8c-4b584883bb10@mrabarnett.plus.com> Message-ID: On Fri, 15 Jan 2021, MRAB wrote: > You should be adding the frames to the notebook. Also, the tabs are > 'self.tab1', not 'tab1', etc: > n.add(self.tab1, text='Activities') > Similarly for the others. Thanks. MRAB. This allows me to move on and put pre-built widget pages on the tabs. Regards, Rich From mstemper at gmail.com Fri Jan 15 16:49:52 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Fri, 15 Jan 2021 15:49:52 -0600 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: On 15/01/2021 15.26, Stefan Ram wrote: > "Michael F. Stemper" writes: >> On 15/01/2021 14.01, Stefan Ram wrote: >>> __import__( "math" ).sqrt( 4 ) >> I had no idea that syntax existed, and find it completely at odds >> with The Zen of Python. I'm torn between forgetting that I ever saw >> it and using it for some evilly-obfuscated code. > > When one collects snippets of Python code that are intended > to be inserted into programs, a snippet usually would have > to consist of two parts: One part to be inserted at the top > of the program, into the imports section, and then the actual > snippet. This statement led inevitably to: >>> sqrt = __import__("math").sqrt >>> sqrt(4) 2.0 >>> I don't know why; it just did. > "__import__" allows to write snippets that can be inserted > as they are without the need to do insertions at two different > places. (Possibly with a tool to later normalize the insertions > to the usual style.) That's much too mature. Es ist Feierabend! -- Michael F. Stemper 2 Chronicles 19:7 From rosuav at gmail.com Fri Jan 15 17:01:20 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jan 2021 09:01:20 +1100 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: On Sat, Jan 16, 2021 at 8:56 AM Michael F. Stemper wrote: > > On 15/01/2021 15.26, Stefan Ram wrote: > > "Michael F. Stemper" writes: > >> On 15/01/2021 14.01, Stefan Ram wrote: > >>> __import__( "math" ).sqrt( 4 ) > >> I had no idea that syntax existed, and find it completely at odds > >> with The Zen of Python. I'm torn between forgetting that I ever saw > >> it and using it for some evilly-obfuscated code. > > > > When one collects snippets of Python code that are intended > > to be inserted into programs, a snippet usually would have > > to consist of two parts: One part to be inserted at the top > > of the program, into the imports section, and then the actual > > snippet. > > "__import__" allows to write snippets that can be inserted > > as they are without the need to do insertions at two different > > places. (Possibly with a tool to later normalize the insertions > > to the usual style.) I'm not sure how that works. In Python, you can just put the imports where you want them - why would the __import__ function be needed? I am confuzzed. ChrisA From PythonList at DancesWithMice.info Fri Jan 15 17:12:51 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 16 Jan 2021 11:12:51 +1300 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: <163bec9a-bd50-b73d-2298-21ba0f2c093e@DancesWithMice.info> On 16/01/2021 10.49, Michael F. Stemper wrote: ... > Es ist Feierabend You had me there for a moment, because spotting a 'double meaning" (actually triple) my mind succumbing to dissonance, refused to translate (into English), instead latching onto the last two syllables:- At one time, tech-jargon included the term "abend". It meant "abnormal end", and was a more palatable term (to someone) for "crash" - a bit like the airline which talked of "non-operational termination" instead of using the same (unpalatable) word! Yes, not only might it have been literally the end of (your) day. This conversation does seem to have reached the point of reductio ad absurdum! -- Regards =dn From grant.b.edwards at gmail.com Fri Jan 15 15:58:05 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 15 Jan 2021 20:58:05 -0000 (UTC) Subject: How to flush 's stdout stream? References: Message-ID: On 2021-01-15, Eryk Sun wrote: > On 1/15/21, Grant Edwards wrote: >> In Python 3.7+, how does one flush the stdout FILE stream? I mean the >> FILE *declared as 'stdio' in . I'm _not_ asking how to flush the >> Python file object sys.stdio. > > You can flush all output streams via C fflush(NULL). Brilliant! I read through the fflush() man page earlier but missed that. fflush(NULL) should work. > If it has to be just stdout, the code will vary by platform. As far > as I know, there is no standard way at the ABI level to reference C > stdin, stdout, and stderr. Typically these are macros at the API > level. The macro might directly reference the FILE record, or maybe > it calls an inline function that returns the reference. That's what I was trying to figure out: whether 'stdio' was actually a global symbol. On Linux it appears to be. I was afraid it was a macro that referred indirectly to some per-thread storage or something... > CPython doesn't have a common wrapper function for this. With > ctypes, you'll have to special case common platform CRTs such as > glibc in Linux and ucrt in Windows (possible, but undocumented). For > example: > > import sys > import time > import ctypes > > if sys.platform == 'win32' and sys.version_info >= (3, 5): > libc = ucrt = ctypes.CDLL('ucrtbase', use_errno=True) > IOLBF = 0x0040 > libc.__acrt_iob_func.restype = ctypes.c_void_p > stdout = ctypes.c_void_p(libc.__acrt_iob_func(1)) > elif sys.platform == 'linux': > libc = cglobal = ctypes.CDLL(None, use_errno=True) > IOLBF = 1 > stdout = ctypes.c_void_p.in_dll(libc, 'stdout') That part I hadn't figured out. I've always used ctypes to call functions in .so libraries that were explicitly loaded by the Python app. From grant.b.edwards at gmail.com Fri Jan 15 16:17:22 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 15 Jan 2021 21:17:22 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-15, Alan Gauld via Python-list wrote: > On 15/01/2021 17:31, Grant Edwards wrote: > >>>> cur.putp(cls) >>>> name = input("Hello, what's your name? ") >>>> >>>> cur.putp(bold) >>>> print("Nice to meet you ", name) > > >>> putp(clr); >>> putp(bold); >>> printf("Enter a name: "); >>> fgets(line, sizeof(line),stdin); >>> >>> printf("Hello %s\n", line); >>> exit(0); > >> One difference is that the name prompt is being written to stdout in >> the C version and stderr in the Python version. But I don't see why >> that would matter. > > That could make a big difference, the putp() function specifically > states that it writes to stdout. > >> I suspect that the problem is that putp is writing to the libc >> "stdout" FILE stream that's declaredin . That stream >> layer/object has buffering that is invisible to Python. > > That would indeed explain it. > >> Now the question: is there a way to tell the curses module to flush >> its stdout FILE stream? > > Indeed. But unless it's trivial it rather defeats the concept of > using the terminfo functions to create text effects without > diving into full curses screen control! And that was what I > was hoping to uncover. > > I wonder if I can use the os module to mess with the > file descriptors.... hmmm. Yes, but that doesn't help. You need to flush the libc FILE *stdio not the underlying file descriptor. Here's how you do it: import os,ctypes,sys,time libc = ctypes.CDLL(None, use_errno=True) import curses as cur cur.setupterm() bold = cur.tigetstr('bold') norm = cur.tigetstr('sgr0') cls = cur.tigetstr('clear') cur.putp(cls) libc.fflush(None) name = input("Enter your name: ") cur.putp(bold) libc.fflush(None) sys.stdout.write("\nNice to meet you " + name + "\n") cur.putp(norm); libc.fflush(None) input("Hit enter to exit") The call to libc.fflush(None) flushes all output FILE * streams. If you really just want to flush stdout, to flush just stdout: import os,ctypes,sys,time libc = ctypes.CDLL(None, use_errno=True) stdout = ctypes.c_void_p.in_dll(libc, 'stdout') import curses as cur cur.setupterm() bold = cur.tigetstr('bold') norm = cur.tigetstr('sgr0') cls = cur.tigetstr('clear') cur.putp(cls) libc.fflush(stdout) name = input("Enter your name: ") cur.putp(bold) libc.fflush(stdout) sys.stdout.write("\nNice to meet you " + name + "\n") cur.putp(norm); libc.fflush(stdout) input("Hit enter to exit") I'd wrap cur.putp() to make it less ugly: import os,ctypes,sys,time libc = ctypes.CDLL(None, use_errno=True) stdout = ctypes.c_void_p.in_dll(libc, 'stdout') import curses as cur cur.setupterm() def putp(*args): sys.stderr.flush() sys.stdout.flush() cur.putp(*args) libc.fflush(stdout) bold = cur.tigetstr('bold') norm = cur.tigetstr('sgr0') cls = cur.tigetstr('clear') putp(cls) name = input("Enter your name: ") putp(bold) print("Nice to meet you",name) putp(norm); input("Hit enter to exit") From grant.b.edwards at gmail.com Fri Jan 15 17:09:06 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 15 Jan 2021 22:09:06 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-15, Grant Edwards wrote: > On 2021-01-15, Alan Gauld via Python-list wrote: >> On 15/01/2021 17:31, Grant Edwards wrote: >> >>> I suspect that the problem is that putp is writing to the libc >>> "stdout" FILE stream that's declaredin . That stream >>> layer/object has buffering that is invisible to Python. >> >> That would indeed explain it. >> >>> Now the question: is there a way to tell the curses module to flush >>> its stdout FILE stream? >> >> Indeed. But unless it's trivial it rather defeats the concept of >> using the terminfo functions to create text effects without >> diving into full curses screen control! > > Indeed, that appears to be the case for Python 3.x (unless we can > figure out a way to flush 's FILE *stdio stream from Python). > I started a separate thread about that specific topic. I've already posted code showing how to call fflush(FILE *stdio). An even cleaner solution is avoid using the libc FILE* stuff entirely. Just grab the strings you need from ncurses and output them via Pythons I/O streams: import curses curses.setupterm() bold = curses.tigetstr('bold').decode('ascii') norm = curses.tigetstr('sgr0').decode('ascii') cls = curses.tigetstr('clear').decode('ascii') print(cls,end='') name = input("enter name: ") print(f'{bold}Hi there {name}{norm}') input("press enter to exit: ") Though that seems to work fine with urxvt, it _might_ not be quite kosher according the ncurses man page, since it says: Parameterized strings should be passed through tparm to instantiate them. All terminfo strings (including the output of tparm) should be printed with tputs or putp. Apparently that's mainly so that it can "apply padding information". I have no idea what that means: The tputs routine applies padding information to the string str and outputs it: Entities that are parameterized (e.g. goto location) would need to be passed through curses.tiparm() before they're decoded and printed. I'm goign to try that next. From * at eli.users.panix.com Fri Jan 15 17:16:30 2021 From: * at eli.users.panix.com (Eli the Bearded) Date: Fri, 15 Jan 2021 22:16:30 +0000 (UTC) Subject: why sqrt is not a built-in function? References: Message-ID: In comp.lang.python, Chris Angelico wrote: > Michael F. Stemper wrote: >> On 15/01/2021 14.01, Stefan Ram wrote: >>> __import__( "math" ).sqrt( 4 ) >> I had no idea that syntax existed, and find it completely at odds >> with The Zen of Python. I'm torn between forgetting that I ever saw >> it and using it for some evilly-obfuscated code. > I recommend option #2. It is incredibly good fun. For added bonus > obscurity, don't import a module directly; import it from some > unrelated module, such as "from ast import sys" or "from base64 import > re". Is there an Obfuscated Python contest, like there is with C? I know the C ones are often quite interesting, like the 2020 entry that implements tic-tac-toe in "Turing complete" sub-language of printf() format strings. (Carlini, http://www.ioccc.org/years.html#2020 ) Elijah ------ with the complexity of fitting the 200k format into a 2k source file From rosuav at gmail.com Fri Jan 15 17:28:20 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jan 2021 09:28:20 +1100 Subject: why sqrt is not a built-in function? In-Reply-To: References: Message-ID: On Sat, Jan 16, 2021 at 9:25 AM Eli the Bearded <*@eli.users.panix.com> wrote: > > In comp.lang.python, Chris Angelico wrote: > > Michael F. Stemper wrote: > >> On 15/01/2021 14.01, Stefan Ram wrote: > >>> __import__( "math" ).sqrt( 4 ) > >> I had no idea that syntax existed, and find it completely at odds > >> with The Zen of Python. I'm torn between forgetting that I ever saw > >> it and using it for some evilly-obfuscated code. > > I recommend option #2. It is incredibly good fun. For added bonus > > obscurity, don't import a module directly; import it from some > > unrelated module, such as "from ast import sys" or "from base64 import > > re". > > Is there an Obfuscated Python contest, like there is with C? I know the > C ones are often quite interesting, like the 2020 entry that implements > tic-tac-toe in "Turing complete" sub-language of printf() format strings. > (Carlini, http://www.ioccc.org/years.html#2020 ) > No there isn't, but similar abominations have showed up in security testing. Attempts to (a) create a sandboxed Python, and then (b) break out of said sandbox, have produced some fairly terrifying (and quite awesome) demonstrations. ChrisA From rshepard at appl-ecosys.com Fri Jan 15 17:32:11 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jan 2021 14:32:11 -0800 (PST) Subject: Writing a Python3 ttk.Notebook In-Reply-To: References: Message-ID: On Fri, 15 Jan 2021, Dennis Lee Bieber wrote: > Off-hand, I'd suspect you should be adding these to the NOTEBOOK > object "n". Dennis, You're correct. The MWE didn't have the proper syntax. Now, the problem is the notebook doesn't display its tabs on the main window, while the proper syntax on a separate file opens a window with the tabs displayed. The file 'application.py' is attached. If I had better docs here I could probably work a lot of this out by myself. Regards, Rich -------------- next part -------------- #!/usr/bin/env python3 # main file to start application. from os import environ import sys from datetime import datetime import tkinter as tk from tkinter import ttk from tkinter.ttk import Notebook as nb from tkinter import filedialog from tkinter import messagebox from tkinter.font import nametofont from functools import partial import model as m import views as v import controller as c class Application(tk.Tk): """ Application root window """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # the top level frame holding notebook, status bar, etc. self.columnconfigure(0, weight=1) # helps with frame/app resizing on the fly self.rowconfigure(0, weight=1) # helps with frame/app resizing on the fly # open application centered on screen; set window width and height self.appwidth = 1000 self.appheight = 800 # get screen width and height self.scrwidth = self.winfo_screenwidth() self.scrheight = self.winfo_screenheight() # formula to find screen center self.xLeft = (self.scrwidth/2) - (self.appwidth/2) self.yTop = (self.scrheight/2) - (self.appheight/2) # set geometry self.geometry(str(self.appwidth) + "x" + str(self.appheight) + "+" + str(int(self.xLeft)) + "+" + str(int(self.yTop))) self.title("Main Window Title Goes Here") self.resizable(width=True, height=True) datestring = datetime.today().strftime("%Y-%m-%d") # variables for adjusting font size and style self.font_bold = tk.BooleanVar() self.font_size = tk.IntVar() def set_font(*args): self.font_spec = 'TkDefaultFont {size} {bold}'.format( size=font_size.get(), bold='bold' if font_bold.get() else '') self.label.config(font=font_spec) self.font_bold.trace('w', set_font) self.font_size.trace('w', set_font) # status bar self.status = tk.StringVar() self.statusbar = ttk.Label(self, textvariable=self.status) self.statusbar.grid(sticky="we", row=3, padx=10) # notebook nb = ttk.Notebook(self) self.tab1 = ttk.Frame(nb) # activities self.tab2 = ttk.Frame(nb) # people self.tab3 = ttk.Frame(nb) # locations self.tab4 = ttk.Frame(nb) # organizations self.tab5 = ttk.Frame(nb) # reports self.tab6 = ttk.Frame(nb) # lookup tables nb.add(self.tab1, text='Activities') nb.add(self.tab2, text='People') nb.add(self.tab3, text='Locations') nb.add(self.tab4, text='Organizationbs') nb.add(self.tab5, text='Reports') nb.add(self.tab6, text='Lookups') if __name__ == "__main__": app = Application() app.mainloop() From grant.b.edwards at gmail.com Fri Jan 15 17:29:46 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 15 Jan 2021 22:29:46 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-15, Grant Edwards wrote: > Entities that are parameterized (e.g. goto location) would need to be > passed through curses.tiparm() before they're decoded and printed. I'm > goign to try that next. The curses module doesn't expose tiparm, but you can use tparm instead: #!/usr/bin/python import curses,sys curses.setupterm() write = sys.stdout.write bold = curses.tigetstr('bold').decode('ascii') norm = curses.tigetstr('sgr0').decode('ascii') cls = curses.tigetstr('clear').decode('ascii') cup = curses.tigetstr('cup') def goto(row,column): write(curses.tparm(cup,row,column).decode('ascii')) def clear(): write(cls) clear() name = input("enter name: ") for row in [3,5,10,20]: goto(row, row+5) write(f'{bold}Hi there {name}{norm}') goto(row+1, row+6) write(f'Hi there {name}') goto(24,0) input("press enter to exit: ") clear() From PythonList at DancesWithMice.info Fri Jan 15 17:41:50 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 16 Jan 2021 11:41:50 +1300 Subject: why sqrt is not a built-in function? In-Reply-To: References: Message-ID: <374cc973-e18a-8880-a717-9de545d64ef3@DancesWithMice.info> On 15/01/2021 06.44, Denys Contant wrote: > I don't understand why sqrt is not a built-in function. > Why do we have to first import the function from the math module? > I use it ALL THE TIME! > > That felt good. Thank you. Are you 'venting', or do you have a specific frustration-induced question? Much of my training work centers on HTML5. An issue which you will have experienced as a user (if not an HTML5 coder), is how long it takes for certain pages to load or to respond to a 'click'. We talk of the "weight" of the page. Sadly, in a bid to "capture eye-balls" and/or to prove how much smarter 'I' am (than any other web-author/JavaScript-er), there are (far too) many reasons why web-pages are adorned and accompanied by myriad scripts (and likely, whole libraries/frameworks), and thus become slow (or 'heavy'). What does this have to do with Python? As an "interpreted language" Python will (tend to) execute slowly when compared with a "compiled language". (ignoring 'shades and grades', and purity of definition) Another form of delay/slow-ness, is how long it takes a program(me) to start (in the eyes of the user). Another form of 'weight', and component of start-up time is how much storage is required to hold the code (excluding any data). An advantage of Python is that it has a small 'core'. Mark Summerfield (author) refers to it as "Python's beautiful heart". The minimised core (or should that be "optimised"?) is fast to load, and occupies minimal resource. As a consequence, you and I may well grumble that we have to import the math library - every time we code some non-trivial calculation. However, in doing-so we (should) compute a conscious cost-benefit analysis: knowing that to include the library will incur a resource-cost, but that its facilities will improve the accuracy and/or efficiency (eg speed) of our work. OK, so sign me up! Contrarily, people who don't 'work with numbers', eg other threads 'here' discussing character manipulation; don't experience any longer waiting-time or 'suffer' extra resource-cost, due to loading the math library, from which they/their code will receive no benefit at all! Thus, one of the philosophies of Python I keenly appreciate (that makes me "[feel] good", to borrow your words), is that not only are "batteries included", but I don't have to carry-around any 'spare batteries' that I don't actually need right now! (even more applicable when using MicroPython, etc) -- Regards =dn From mstemper at gmail.com Fri Jan 15 17:40:00 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Fri, 15 Jan 2021 16:40:00 -0600 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: On 15/01/2021 16.01, Chris Angelico wrote: > On Sat, Jan 16, 2021 at 8:56 AM Michael F. Stemper wrote: >> >> On 15/01/2021 15.26, Stefan Ram wrote: >>> "Michael F. Stemper" writes: >>>> On 15/01/2021 14.01, Stefan Ram wrote: >>>>> __import__( "math" ).sqrt( 4 ) >>>> I had no idea that syntax existed, and find it completely at odds >>>> with The Zen of Python. I'm torn between forgetting that I ever saw >>>> it and using it for some evilly-obfuscated code. >>> >>> When one collects snippets of Python code that are intended >>> to be inserted into programs, a snippet usually would have >>> to consist of two parts: One part to be inserted at the top >>> of the program, into the imports section, and then the actual >>> snippet. >>> "__import__" allows to write snippets that can be inserted >>> as they are without the need to do insertions at two different >>> places. (Possibly with a tool to later normalize the insertions >>> to the usual style.) > > I'm not sure how that works. In Python, you can just put the imports > where you want them - why would the __import__ function be needed? I have no idea what PEP-8 has to say on the subject. However, my coding style *generally* puts all of the imports up front, right after the prologue (program description, revision history, uzw). > I am confuzzed. It's a common condition. -- Michael F. Stemper Life's too important to take seriously. From rosuav at gmail.com Fri Jan 15 17:57:28 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jan 2021 09:57:28 +1100 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: On Sat, Jan 16, 2021 at 9:47 AM Michael F. Stemper wrote: > > On 15/01/2021 16.01, Chris Angelico wrote: > > On Sat, Jan 16, 2021 at 8:56 AM Michael F. Stemper wrote: > >> > >> On 15/01/2021 15.26, Stefan Ram wrote: > >>> "Michael F. Stemper" writes: > >>>> On 15/01/2021 14.01, Stefan Ram wrote: > > >>>>> __import__( "math" ).sqrt( 4 ) > >>>> I had no idea that syntax existed, and find it completely at odds > >>>> with The Zen of Python. I'm torn between forgetting that I ever saw > >>>> it and using it for some evilly-obfuscated code. > >>> > >>> When one collects snippets of Python code that are intended > >>> to be inserted into programs, a snippet usually would have > >>> to consist of two parts: One part to be inserted at the top > >>> of the program, into the imports section, and then the actual > >>> snippet. > >>> "__import__" allows to write snippets that can be inserted > >>> as they are without the need to do insertions at two different > >>> places. (Possibly with a tool to later normalize the insertions > >>> to the usual style.) > > > > I'm not sure how that works. In Python, you can just put the imports > > where you want them - why would the __import__ function be needed? > > I have no idea what PEP-8 has to say on the subject. However, my coding > style *generally* puts all of the imports up front, right after the > prologue (program description, revision history, uzw). Sure, and that's how I'd normally code too. But if I give you a snippet like this: from collections import Counter ltr_weights = ''.join(Counter(text) & Counter(string.ascii_letters)).elements()) then it's absolutely fine to keep the import next to the code. There's no need to go to the hassle of splitting the snippet; if you want to, you can, but the snippet is still a single thing. The __import__ function doesn't add anything here. ChrisA From rshepard at appl-ecosys.com Fri Jan 15 18:09:24 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jan 2021 15:09:24 -0800 (PST) Subject: Writing a Python3 ttk.Notebook In-Reply-To: References: Message-ID: On Fri, 15 Jan 2021, Rich Shepard wrote: > The file 'application.py' is attached. If I had better docs here I could > probably work a lot of this out by myself. Progress: I didn't put the notebook on the main window using grid. Now I need to find how to specify the position so it's at the top of the window. I'll read the options on grid. Rich From PythonList at DancesWithMice.info Fri Jan 15 18:17:01 2021 From: PythonList at DancesWithMice.info (dn) Date: Sat, 16 Jan 2021 12:17:01 +1300 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: <4bc9c7bb-1bff-32da-4675-81955d0588b1@DancesWithMice.info> On 16/01/2021 11.40, Michael F. Stemper wrote: > On 15/01/2021 16.01, Chris Angelico wrote: >> On Sat, Jan 16, 2021 at 8:56 AM Michael F. Stemper >> wrote: >>> >>> On 15/01/2021 15.26, Stefan Ram wrote: >>>> "Michael F. Stemper" writes: >>>>> On 15/01/2021 14.01, Stefan Ram wrote: > >>>>>> __import__( "math" ).sqrt( 4 ) >>>>> I had no idea that syntax existed, and find it completely at odds >>>>> with The Zen of Python. I'm torn between forgetting that I ever saw >>>>> it and using it for some evilly-obfuscated code. >>>> >>>> ??? When one collects snippets of Python code that are intended >>>> ??? to be inserted into programs, a snippet usually would have >>>> ??? to consist of two parts: One part to be inserted at the top >>>> ??? of the program, into the imports section, and then the actual >>>> ??? snippet. >>>> ??? "__import__" allows to write snippets that can be inserted >>>> ??? as they are without the need to do insertions at two different >>>> ??? places. (Possibly with a tool to later normalize the insertions >>>> ??? to the usual style.) >> >> I'm not sure how that works. In Python, you can just put the imports >> where you want them - why would the __import__ function be needed? import is 'syntactic sugar' for __import__(). Have you not heard that "sugar is the new smoking"? We're being encouraged to cut-back or giving it up completely... More seriously, it's like creating a class object by MyClass = type('MyClass', (), {}) whereas it's far easier (for most of us) to use class MyClass( etc ) However, when the power and/or dynamic possibilities of the underlying code-construct is/are required... > I have no idea what PEP-8 has to say on the subject. However, my coding > style *generally* puts all of the imports up front, right after the > prologue (program description, revision history, uzw). This is indeed received-wisdom. However it does not disallow (yuk: double-negative!) coding an import statement elsewhere, eg a routine which is only executed during some invocations, but not others. What you may like to consider about "prolog[ue]s" is whether they belong 'in' the code (plenty of arguments 'for') or within the VCS (plenty of arguments here too)... eg1: how easy is it to establish when a particular decision/code-change was made (more than one week ago)? - particularly if changes were subsequent made 'on top of' that change? eg2: is it a good idea to use 'Python constants' to display the program(me) name and (perhaps) a version number on the terminal/application window? >> I am confuzzed. > > It's a common condition. There are three components: 1 From the Greek: "con" meaning 'against' or 'unable'. 2 From tech-jargon (and the Australian habit of shortening every word in the English language): "fuzz" is the contraction of two highly-technical terms, famously applied in intro courses and by naive job-interviewers. 3 From English: the suffix "ed" meaning past tense. Thus, (smirking!) "confuzzed" is the psychological term for people who have never been able to bend their minds around the "fizz-buzz" coding challenge. PS am running for cover before @Chris reads this... -- Regards =dn From rosuav at gmail.com Fri Jan 15 18:20:02 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jan 2021 10:20:02 +1100 Subject: why sqrt is not a built-in function? In-Reply-To: <4bc9c7bb-1bff-32da-4675-81955d0588b1@DancesWithMice.info> References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> <4bc9c7bb-1bff-32da-4675-81955d0588b1@DancesWithMice.info> Message-ID: On Sat, Jan 16, 2021 at 10:18 AM dn via Python-list wrote: > >> I am confuzzed. > > > > It's a common condition. > > There are three components: > 1 From the Greek: "con" meaning 'against' or 'unable'. > 2 From tech-jargon (and the Australian habit of shortening every word in > the English language): "fuzz" is the contraction of two highly-technical > terms, famously applied in intro courses and by naive job-interviewers. > 3 From English: the suffix "ed" meaning past tense. > > Thus, (smirking!) "confuzzed" is the psychological term for people who > have never been able to bend their minds around the "fizz-buzz" coding > challenge. > > > PS am running for cover before @Chris reads this... Good idea, you never know what I might have been drinking, and therefore what materials could have been sprayed across the screen when I read that! :D ChrisA From rshepard at appl-ecosys.com Fri Jan 15 19:16:32 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jan 2021 16:16:32 -0800 (PST) Subject: Writing a Python3 ttk.Notebook In-Reply-To: References: Message-ID: On Fri, 15 Jan 2021, Rich Shepard wrote: > Progress: I didn't put the notebook on the main window using grid. Now I > need to find how to specify the position so it's at the top of the window. > I'll read the options on grid. The notebook tabs are placed on the grid as nb.grid(row=0, column=0, columnspan=6). But, it's in the center of the main frame and small. All the references I've found in Tkinter books and on the web have small, stand-alone, samples of notebooks. Is the best and most complete reference for learning how to apply a ttk.Notebook? Regards, Rich From python at mrabarnett.plus.com Fri Jan 15 20:01:25 2021 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 16 Jan 2021 01:01:25 +0000 Subject: Writing a Python3 ttk.Notebook In-Reply-To: References: Message-ID: <1851f166-6d02-3969-88be-dfa22f1a15cb@mrabarnett.plus.com> On 2021-01-16 00:16, Rich Shepard wrote: > On Fri, 15 Jan 2021, Rich Shepard wrote: > >> Progress: I didn't put the notebook on the main window using grid. Now I >> need to find how to specify the position so it's at the top of the window. >> I'll read the options on grid. > > The notebook tabs are placed on the grid as nb.grid(row=0, column=0, > columnspan=6). But, it's in the center of the main frame and small. > The '.grid' method has a 'sticky' keyword parameter that controls the alignment within the grid cell. > All the references I've found in Tkinter books and on the web have small, > stand-alone, samples of notebooks. Is > the best and most > complete reference for learning how to apply a ttk.Notebook? > From tjreedy at udel.edu Fri Jan 15 19:57:21 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 15 Jan 2021 19:57:21 -0500 Subject: Writing a Python3 ttk.Notebook In-Reply-To: References: Message-ID: On 1/15/2021 3:51 PM, Rich Shepard wrote: > I want to replace the menu on my application with the more appropriate > notebook. After looking at examples in my reference books and on the Web I > still cannot get it working properly. IDLE's settings dialog uses a ttk.Notebook. The file is Lib/idlelib/configdialog.py. -- Terry Jan Reedy From greg.ewing at canterbury.ac.nz Fri Jan 15 21:31:23 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 16 Jan 2021 15:31:23 +1300 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 16/01/21 7:33 am, Grant Edwards wrote: > Starting in Python 3., python's stdio file objects are _not_ > on top of the libc FILE streams: they're directly on top of the file > descriptor. This sounds like rather a bad situation, because it means that any C library using stdio is going to interact badly with Python stdio. Can something be done about this? Maybe Python stdio objects should flush all the C stdio streams before writing anything? -- Greg From rosuav at gmail.com Fri Jan 15 21:37:50 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jan 2021 13:37:50 +1100 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On Sat, Jan 16, 2021 at 1:36 PM Greg Ewing wrote: > > On 16/01/21 7:33 am, Grant Edwards wrote: > > Starting in Python 3., python's stdio file objects are _not_ > > on top of the libc FILE streams: they're directly on top of the file > > descriptor. > > This sounds like rather a bad situation, because it means that > any C library using stdio is going to interact badly with Python > stdio. > > Can something be done about this? Maybe Python stdio objects > should flush all the C stdio streams before writing anything? > Surely it should be the other way around? If you use the C stdio streams, flush them after use. Like with everything else that you flush. ChrisA From greg.ewing at canterbury.ac.nz Fri Jan 15 21:41:03 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 16 Jan 2021 15:41:03 +1300 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> Message-ID: On 16/01/21 10:14 am, Michael F. Stemper wrote: > I had no idea that syntax existed, and find it completely at odds > with The Zen of Python. It's not an *obvious* way, so there's no Zen conflict. As for why it exists, it's part of the mechanism that implements imports -- 'import' statements get compiled into a call to __import__. It also provides a way of importing something specifed by a string at runtime, so it can be useful. -- Greg From cs at cskk.id.au Fri Jan 15 21:50:38 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 16 Jan 2021 13:50:38 +1100 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 15Jan2021 18:36, Alan Gauld wrote: >> One difference is that the name prompt is being written to stdout in >> the C version and stderr in the Python version. But I don't see why >> that would matter. > >That could make a big difference, the putp() function specifically >states that it writes to stdout. If you want an example of code using the curses.ti* functions with arbitrary Python files, have a gander at this: https://hg.sr.ht/~cameron-simpson/css/browse/lib/python/cs/upd.py?rev=tip It's on PyPI if you want easy installation in addition to the source: https://pypi.org/project/cs.upd/ I'm not (yet) doing colour with that, but I _am_ doing cursor motions etc, since that supports multiple lines of display (typical use case is multiple progress bars for parallel tasks). It looks up and uses a few things, like insert_line etc, since the interface with my logging goes: go to the top status line, insert a line, write the error message, resume. >> Now the question: is there a way to tell the curses module to flush >> its stdout FILE stream? > >Indeed. But unless it's trivial it rather defeats the concept of >using the terminfo functions to create text effects without >diving into full curses screen control! And that was what I >was hoping to uncover. > >I wonder if I can use the os module to mess with the >file descriptors.... hmmm. That is massive overkill. It is enough to write various strings to your desired output and flush it. As encountered earlier, curses strings are bytes, and need to be decodes as ASCII for str use. >Thanks for that snippet, I had no idea that input() wrote >to stderr Lots of things like to do that. It is a hack, but it does avoid polluting your stdout with prompts. (Taxonomy of Bugs: "plug: a message dropped in the middle of the output data stream".) >nor that Python added a stdout layer on top of libc. It might put its stdout layer directly on top of fd 1, rather than the C stdout system. That rings a bell with me. >Do you know where that is documented? I'd be interested in >reading more. The io module? Cheers, Cameron Simpson From greg.ewing at canterbury.ac.nz Fri Jan 15 22:10:20 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 16 Jan 2021 16:10:20 +1300 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 16/01/21 3:37 pm, Chris Angelico wrote: > Surely it should be the other way around? If you use the C stdio > streams, flush them after use. 1. You might not know that you're (implicitly) using C stdio. 2. There doesn't seem to be an easy way to flush C stdio from Python any more. -- Greg From rosuav at gmail.com Fri Jan 15 22:17:51 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 16 Jan 2021 14:17:51 +1100 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On Sat, Jan 16, 2021 at 2:16 PM Greg Ewing wrote: > > On 16/01/21 3:37 pm, Chris Angelico wrote: > > Surely it should be the other way around? If you use the C stdio > > streams, flush them after use. > > 1. You might not know that you're (implicitly) using C stdio. > > 2. There doesn't seem to be an easy way to flush C stdio from > Python any more. > But somewhere along the way, you're finding that there's a problem, which implies that SOMETHING is calling on C stdio. That thing, surely, should be the thing responsible for flushing? ChrisA From Bischoop at vimart.net Fri Jan 15 22:32:37 2021 From: Bischoop at vimart.net (Bischoop) Date: Sat, 16 Jan 2021 03:32:37 -0000 (UTC) Subject: count consecutive elements References: <20210113193502.7d2d778b@bigbox.attlocal.net> <20210113213742.2275d553@bigbox.attlocal.net> Message-ID: On 2021-01-14, Tim Chase wrote: > > seems to only return one value so seems to get odd results if I > specify something like > > get_longest("aaabcccbbb") > > which at least here tells me that "c" is the longest run, even though > aaa, bbb, and ccc are all runs of length 3. The OP didn't specify > what should happen in that case, so it would need some clarification. > > In that case maybe good solution would be to return three of them? -- Thanks From rshepard at appl-ecosys.com Fri Jan 15 22:45:07 2021 From: rshepard at appl-ecosys.com (Rich Shepard) Date: Fri, 15 Jan 2021 19:45:07 -0800 (PST) Subject: Writing a Python3 ttk.Notebook In-Reply-To: References: Message-ID: On Fri, 15 Jan 2021, Terry Reedy wrote: > IDLE's settings dialog uses a ttk.Notebook. The file is > Lib/idlelib/configdialog.py. Thanks, Terry! I completely forgot that. I'll study the IDLE's code and learn from that. Stay well, Rich From grant.b.edwards at gmail.com Fri Jan 15 21:30:18 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 16 Jan 2021 02:30:18 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-15, Grant Edwards wrote: > On 2021-01-15, Grant Edwards wrote: > >> Entities that are parameterized (e.g. goto location) would need to be >> passed through curses.tiparm() before they're decoded and printed. I'm >> goign to try that next. > > The curses module doesn't expose tiparm, but you can use tparm > instead NB: The example code below may fail to work properly if all of the below are true. * You're using a real, physical terminal * Connected to a real, physical serial port (not a pty) * Without flow control * And the terminal requires "pauses" to allow time for the terminal to execute the some commands before it can accept further data. The functionality that is added by tputs() is to insert "padding" (typically extra NUL bytes) before/after certain certain terminal operations. What I _don't_ know at this point is what happens if you're using a terminfo description that specifies padding, but you're not connected to a physical terminal via a real serial port. > #!/usr/bin/python > import curses,sys > > curses.setupterm() > > write = sys.stdout.write > > bold = curses.tigetstr('bold').decode('ascii') > norm = curses.tigetstr('sgr0').decode('ascii') > cls = curses.tigetstr('clear').decode('ascii') > cup = curses.tigetstr('cup') > > def goto(row,column): > write(curses.tparm(cup,row,column).decode('ascii')) > > def clear(): > write(cls) > > clear() > name = input("enter name: ") > > for row in [3,5,10,20]: > goto(row, row+5) > write(f'{bold}Hi there {name}{norm}') > goto(row+1, row+6) > write(f'Hi there {name}') > > goto(24,0) > input("press enter to exit: ") > clear() > From grant.b.edwards at gmail.com Fri Jan 15 21:43:40 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 16 Jan 2021 02:43:40 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-16, Greg Ewing wrote: > On 16/01/21 7:33 am, Grant Edwards wrote: > >> Starting in Python 3., python's stdio file objects are _not_ >> on top of the libc FILE streams: they're directly on top of the file >> descriptor. > > This sounds like rather a bad situation, because it means that > any C library using stdio is going to interact badly with Python > stdio. True, but how many Python programs use C libraries that write to FILE* streams and need to mix in Python "standard output"? > Can something be done about this? Maybe Python stdio objects > should flush all the C stdio streams before writing anything? There's probably a way to hack the sys.stdout object to make it write data to the FILE* stream using fwrite(), but it'd be ugly. -- Grant From grant.b.edwards at gmail.com Fri Jan 15 21:46:31 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 16 Jan 2021 02:46:31 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-16, Chris Angelico wrote: > On Sat, Jan 16, 2021 at 1:36 PM Greg Ewing wrote: > >> Can something be done about this? Maybe Python stdio objects >> should flush all the C stdio streams before writing anything? >> > > Surely it should be the other way around? If you use the C stdio > streams, flush them after use. Like with everything else that you > flush. If you want to be able to mix Python output and FILE* output, you have to flush either/both. You have to flush the Python output everytime you do a FILE* output, and you have to fflush the FILE* stream every time you do Python output. Or you have to keep track of which you did last time. It's very ugly. -- Grant From Bischoop at vimart.net Fri Jan 15 22:04:58 2021 From: Bischoop at vimart.net (Bischoop) Date: Sat, 16 Jan 2021 03:04:58 -0000 (UTC) Subject: binascii.b2a vs ord() References: Message-ID: On 2021-01-10, Chris Angelico wrote: > > Hope that helps! > Yep, now it seems more understandable what is going on. Thanks for you time. -- Thanks From grant.b.edwards at gmail.com Fri Jan 15 22:09:53 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 16 Jan 2021 03:09:53 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-16, Cameron Simpson wrote: > On 15Jan2021 18:36, Alan Gauld wrote: >>> One difference is that the name prompt is being written to stdout in >>> the C version and stderr in the Python version. But I don't see why >>> that would matter. >> >>That could make a big difference, the putp() function specifically >>states that it writes to stdout. > > If you want an example of code using the curses.ti* functions with > arbitrary Python files, have a gander at this: > > https://hg.sr.ht/~cameron-simpson/css/browse/lib/python/cs/upd.py?rev=tip I don't see how it deals with terminfo strings that have delay specifiers in them (e.g. vt100). Those delay specifiers need to be replaced by 0 or more 'pad' characters (default is NUL, but that too can be specified in the terminfo file). My initial plan was to call ncurses tputs() function and pass it a 'putchar' callback that passes the output bytes to sys.stdout.buffer.write(). I haven't gotten that working yet (it's going to require some cytyptes magic). -- Grant From python.list at tim.thechases.com Fri Jan 15 23:09:55 2021 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 15 Jan 2021 22:09:55 -0600 Subject: count consecutive elements In-Reply-To: References: <20210113193502.7d2d778b@bigbox.attlocal.net> <20210113213742.2275d553@bigbox.attlocal.net> Message-ID: <20210115220955.6d4452a0@bigbox.attlocal.net> On 2021-01-16 03:32, Bischoop wrote: >> The OP didn't specify what should happen in that case, so it would >> need some clarification. > > In that case maybe good solution would be to return three of them? That's the solution I chose in my initial reply, you get a tuple back of ([list of longest matches], length_of_longest_match) -tkc From grant.b.edwards at gmail.com Fri Jan 15 23:26:59 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 16 Jan 2021 04:26:59 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: My previous code didn't work if the terminfo entities contained delay specifiers because the delay specifier was left in the output datastream. The case where the terminfo description contains delays, but the delays aren't needed can be handled by simply removing the delay specifiers by wrapping ncurses.tigetstr as shown below. If you really _are_ using a physical terminal which requires delays and is connected to a real serial port, then I think the only practical solution is to replace sys.stdout.buffer with something that quacks like io.BufferedWriter and uses ctypes to call fwrite() and fflush() on FILE *stdout. That means you've got to do all the ncurses control via curses.putp() and you can't do things like embed control sequences in python strings like print(f'{bold}Hi there{norm}') #!/usr/bin/python import curses,sys,re curses.setupterm() write = sys.stdout.write def tigetstr(name): seq = curses.tigetstr(name) return re.sub(b'\$<[0-9.]+[\*/]{0,2}>', b'', seq) bold = tigetstr('bold').decode('ascii') norm = tigetstr('sgr0').decode('ascii') cls = tigetstr('clear').decode('ascii') cup = tigetstr('cup') def goto(row,column): write(curses.tparm(cup,row,column).decode('ascii')) def clear(): write(cls) clear() name = input("enter name: ") for row in [3,5,10,20]: goto(row, row+5) write(f'{bold}Hi there {name}{norm}') goto(row+1, row+6) write(f'Hi there {name}') goto(24,0) input("press enter to exit: ") clear() From luis2005sandoval at gmail.com Sat Jan 16 00:23:09 2021 From: luis2005sandoval at gmail.com (Z3PS1) Date: Fri, 15 Jan 2021 22:23:09 -0700 Subject: HEKLP Message-ID: <8709998B-275E-462E-BCC9-60CF8BCA6A27@hxcore.ol> NEED HELP WITH MY IDLE ? Sent from [1]Mail for Windows 10 ? References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 From tjreedy at udel.edu Sat Jan 16 01:34:20 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 Jan 2021 01:34:20 -0500 Subject: HEKLP In-Reply-To: <8709998B-275E-462E-BCC9-60CF8BCA6A27@hxcore.ol> References: <8709998B-275E-462E-BCC9-60CF8BCA6A27@hxcore.ol> Message-ID: On 1/16/2021 12:23 AM, Z3PS1 wrote: > NEED HELP WITH MY IDLE > Sent from [1]Mail for Windows 10 > References > > Visible links > 1. https://go.microsoft.com/fwlink/?LinkId=550986 I answer real IDLE questions, but this looks like spam to drive traffic to the hidden link, so I am ignoring it. -- Terry Jan Reedy From mstemper at gmail.com Sat Jan 16 09:25:31 2021 From: mstemper at gmail.com (Michael F. Stemper) Date: Sat, 16 Jan 2021 08:25:31 -0600 Subject: why sqrt is not a built-in function? In-Reply-To: References: <4f734c9c-0732-4239-daad-f9981fadc60e@btinternet.com> <4bc9c7bb-1bff-32da-4675-81955d0588b1@DancesWithMice.info> Message-ID: On 15/01/2021 17.17, dn wrote: > On 16/01/2021 11.40, Michael F. Stemper wrote: >> On 15/01/2021 16.01, Chris Angelico wrote: >>> On Sat, Jan 16, 2021 at 8:56 AM Michael F. Stemper >>> wrote: >>>> On 15/01/2021 15.26, Stefan Ram wrote: >>>>> "Michael F. Stemper" writes: >>>>>> On 15/01/2021 14.01, Stefan Ram wrote: >>>>>>> __import__( "math" ).sqrt( 4 ) >>>>>> I had no idea that syntax existed, and find it completely at odds >>>>>> with The Zen of Python. I'm torn between forgetting that I ever saw >>>>>> it and using it for some evilly-obfuscated code. >>>>> >>>>> ??? When one collects snippets of Python code that are intended >>>>> ??? to be inserted into programs, a snippet usually would have >>>>> ??? to consist of two parts: One part to be inserted at the top >>>>> ??? of the program, into the imports section, and then the actual >>>>> ??? snippet. >>>>> ??? "__import__" allows to write snippets that can be inserted >>>>> ??? as they are without the need to do insertions at two different >>>>> ??? places. (Possibly with a tool to later normalize the insertions >>>>> ??? to the usual style.) >>> >>> I'm not sure how that works. In Python, you can just put the imports >>> where you want them - why would the __import__ function be needed? > > import is 'syntactic sugar' for __import__(). And any high-level language is, from a certain point of view, syntactic sugar for entering the machine-language instructions using the toggle switches on the front panel. The way that Turing meant for us to do it. > More seriously, it's like creating a class object by > > MyClass = type('MyClass', (), {}) > > whereas it's far easier (for most of us) to use > > class MyClass( etc ) As well as far easier to comprehend and maintain. >> I have no idea what PEP-8 has to say on the subject. However, my coding >> style *generally* puts all of the imports up front, right after the >> prologue (program description, revision history, uzw). > > This is indeed received-wisdom. > > However it does not disallow (yuk: double-negative!) coding an import > statement elsewhere, eg a routine which is only executed during some > invocations, but not others. Hence the emphasized "generally". For instance, one of my programs has an option to plot its results. If that option is selected, matplotlib is imported -- way at the end, after all of the number-crunching. I think that we're in agreement here. > What you may like to consider about "prolog[ue]s" is whether they belong > 'in' the code (plenty of arguments 'for') or within the VCS (plenty of > arguments here too)... > > eg1: how easy is it to establish when a particular decision/code-change > was made (more than one week ago)? - particularly if changes were > subsequent made 'on top of' that change? > > eg2: is it a good idea to use 'Python constants' to display the > program(me) name and (perhaps) a version number on the > terminal/application window? Such as "%prog"? Or "sys.argv[0]"? Quite useful for help text and diagnostic messages, with no need to hard-code the program name into the program. Which would cause confusion if a user wanted to rename/alias the program. -- Michael F. Stemper What happens if you play John Cage's "4'33" at a slower tempo? From mohsen.shoushtari97 at gmail.com Sat Jan 16 10:30:06 2021 From: mohsen.shoushtari97 at gmail.com (mohsen shooshtari) Date: Sat, 16 Jan 2021 19:00:06 +0330 Subject: Issues with running python in Command prompt Message-ID: hello, Thanks in advance for your consideration. I install python3.8 and then install Pycharm but when I call python in Command prompt, followed by ( 'python' is not recognized as an internal or external command, operable program or batch file. what should I do to fix this problem? From grant.b.edwards at gmail.com Sat Jan 16 11:35:02 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 16 Jan 2021 16:35:02 -0000 (UTC) Subject: HEKLP References: <8709998B-275E-462E-BCC9-60CF8BCA6A27@hxcore.ol> Message-ID: Perhaps once you get your 'K' key fixed it'll work better. From alan.gauld at yahoo.co.uk Sat Jan 16 13:11:37 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sat, 16 Jan 2021 18:11:37 +0000 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 15/01/2021 21:41, Dennis Lee Bieber wrote: > On Fri, 15 Jan 2021 13:19:26 +0000, Alan Gauld via Python-list > declaimed the following: > >> So the native C functions work as expected. >> Why does the Python wrapper not? > > Are you running Python from a plain command shell, or from some sort of > IDE? Heh Dennis, you should know I'm strictly a vim and bash man ;-) -- 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 torque.india at gmail.com Sat Jan 16 13:45:04 2021 From: torque.india at gmail.com (OmPs) Date: Sun, 17 Jan 2021 00:15:04 +0530 Subject: Issues with running python in Command prompt In-Reply-To: References: Message-ID: On Sat, 16 Jan 2021, 23:51 mohsen shooshtari, wrote: > hello, > Thanks in advance for your consideration. I install python3.8 and then > install Pycharm but when I call python in Command prompt, followed by > ( 'python' > is not recognized as an internal or external command, operable program or > batch file. > You need to set the path in your batch file so the batch file knows where To look for python package. Search in google for setting up path in baychfile in windows. > what should I do to fix this problem? > -- > https://mail.python.org/mailman/listinfo/python-list > From mats at wichmann.us Sat Jan 16 13:52:42 2021 From: mats at wichmann.us (Mats Wichmann) Date: Sat, 16 Jan 2021 11:52:42 -0700 Subject: Issues with running python in Command prompt In-Reply-To: References: Message-ID: On 1/16/21 8:30 AM, mohsen shooshtari wrote: > hello, > Thanks in advance for your consideration. I install python3.8 and then > install Pycharm but when I call python in Command prompt, followed by > ( 'python' > is not recognized as an internal or external command, operable program or > batch file. > > what should I do to fix this problem? > Make sure you've read this page. There turn out to be a number of permutations depending on what you installed and how you installed it: https://docs.python.org/3/using/windows.html From don81846 at comcast.net.REMOVEME Sat Jan 16 14:51:19 2021 From: don81846 at comcast.net.REMOVEME (DonK) Date: Sat, 16 Jan 2021 14:51:19 -0500 Subject: A beginning beginner's question about input, output and . . . References: Message-ID: On Tue, 12 Jan 2021 09:26:18 +1100, Chris Angelico wrote: >On Tue, Jan 12, 2021 at 7:41 AM DonK wrote: >> Hi, I'm thinking about learning Python but I'm 74 years old and will >> very likely not ever have a programming job again. I used to program >> in Visual Basic, C\C++, Delphi, etc. and some obscure "mainframe" >> languages. > >BTW, from my experience, there's very very few languages so obscure >that not one person on this list has heard of them :) > >For example, I've used REXX, which is an IBM language found on some of >the mainframes and also on OS/2, and I'm not the only person here who >has. > >ChrisA Hi Chris, The mainframe language that I mentioned was/is? called KwikBasic. I don't remember if it was all one word or not. It's not to be confused with Microsoft's QuickBasic. KwikBasic ran on the Unix OS and was, hands down, the worst programming experience I've ever had. It was a Y2k fix for the reservation system of a large Fortune 500 real estate "timeshare" company. I probably shouldn't say that their name was Trendswest. The update had to be completed by the end of October 1998 because they would start taking reservations for 2000 in Nov, 1998. They hired me to manage the "reservation" part of their Y2k update in the Summer. (YES! It was late.) It turned out that KwikBasic was VERY much like the other versions of basic that I had used. Including MSDOS's QuickBasic and PDS. The two nutty things about it were that it had only 2 data types, if I remember corectly they were called number and string. The worst thing was that there was just one directory that contained 2,702 source files (I'll never forget that number) with names like 217h9436. There was no index to tell you what 217h9436 was, what it did, what part of the business it pertained to . . . nothing. There was also no notation in the files. You just had to open each one of them, read their code to find out what they did. Also, we had Windows computers on our desks with MS Office installed but the nearest computer that could run Kwikbasic was their UNIX mainframe in the main buildings about .25 to .50 miles away. We were supposed to write code at our desk with Windows Notepad and then, on Fridays, the IT manager would take our code over to compile it and would let us know of any error codes. They said they were going to buy some expensive workstation for our office, that would run RedHat, which they were told would then run Kwikbasic. IDunno! It would have been impossible to do the job as the IT mgr (Mike W.) envisioned it but I was able to write some simple MS Office code that searched all the source code files, in just a minute or 2, for any reference to "Date" functions. As I recall, there weren't that many. Anyway, Mike W. was a fool that spent all day, every day, screaming about, mostly, politics. I wound up quitting iafter less than 2 weeks. Thanks for replying and sorry for the long message. Don From don81846 at comcast.net.invalid Sat Jan 16 15:42:44 2021 From: don81846 at comcast.net.invalid (DonK) Date: Sat, 16 Jan 2021 15:42:44 -0500 Subject: A beginning beginner's question about input, output and . . . References: <87eeiqd7fj.fsf@nightsong.com> Message-ID: <3gh60g9dcotpsuln9rot5jn4rpl97bsb0v@4ax.com> On Mon, 11 Jan 2021 21:56:48 -0800, Paul Rubin wrote: >DonK writes: >> My problem is that I don't understand how Python programs are >> used. (i.e user input and output) Is Python mainly used for backends? >> I've seen some Python gui frameworks like Tkinter, PyQt, etc.... > >I would say at least for me, the i/o to my python programs tends to be >be either files or network sockets. I've written some fairly complex >tkinter apps in the past, but these days, desktop GUI's almost seem like >a 1990s thing. If you want an interactive program, either it's a mobile >app (Python is not so great at that, though see kivy.org) or a web app >(so the user interacts with it through a browser). > >> So, what do you folks use Python for? > >Pretty much everything unless a) it's someone else's application written >in another language so I have to use the other language; b) I need raw >performance (C, C++) or some other specialized feature; or c) I want to >get more practice with some other language (quite a few). > >> if the titlebar contains certain strings > >Yeah this sounds like a Windows thing. I don't have any idea what it >takes to make those Windows calls in Python since I'm mostly a Un*x >programmer. Yes, Windows. Iterating open windows with the Window's API is easy the hard (very hard) part is sending keystrokes to those windows to Save them. It's very tricky because the timing is critical. You have to use one of those "spy" utilities to get the name and classid for the controls that you want to send a command to, then use the Window's API functions SendMessage or PostMessage to send the message directly to the control or just put it in the message que. Like sending an "s" to the File menu to (S)ave. It's more complicated than you would think and it doesn't work very well. It's like pushing on a string. > >> I know that Python is a very popular language so I'm sorry if it >> sounds like I'm being critical. I really don't know enough about it to >> be critical. > >If you're familiar with Javascript or Visual Basic, my impression is >that Python is at about the same level, but with a (for me) subjectively >cleaner style. It doesn't have a static type system or a lot of >boilerplate, so it's easy to bang out small scripts; but the compiler >doesn't supply much long range error checking, so you have to be pretty >devoted to test automation if you're doing anything sizeable. There is >now a syntax for optional type annotations in Python, and a tool called >mypy for checking types based on the annotations. The Python compiler >itself ignores the annotations. I've been using them and like them. Hi Paul, I doubt that I'll be doing anything sizeable, mostly just a little learning and entertainment with an occasional small utility once in a while. But, who knows? For example, I've found a need to parse text documents quite a number of times over the years. Basic/VB is great at doing that. How's Python? Thanks, Don From 2QdxY4RzWzUUiLuE at potatochowder.com Sat Jan 16 15:56:37 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Sat, 16 Jan 2021 14:56:37 -0600 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: <3gh60g9dcotpsuln9rot5jn4rpl97bsb0v@4ax.com> References: <87eeiqd7fj.fsf@nightsong.com> <3gh60g9dcotpsuln9rot5jn4rpl97bsb0v@4ax.com> Message-ID: On 2021-01-16 at 15:42:44 -0500, DonK wrote: > Yes, Windows. Iterating open windows with the Window's API is easy the > hard (very hard) part is sending keystrokes to those windows to Save > them. It's very tricky because the timing is critical. > > You have to use one of those "spy" utilities to get the name and > classid for the controls that you want to send a command to, then use > the Window's API functions SendMessage or PostMessage to send the > message directly to the control or just put it in the message que. > > Like sending an "s" to the File menu to (S)ave. It's more complicated > than you would think and it doesn't work very well. It's like pushing > on a string. Then don't do that? ;-) I'm no Windows expert (nor even a user), but do those applications have a scripting interface? (DDE? OLE? COM? Do those letters ring a bell? The right bell? Are those technologies current?) What you're trying to do sounds like working *against* those applications rather than with them. > For example, I've found a need to parse text documents quite a number > of times over the years. Basic/VB is great at doing that. How's > Python? Python can do that. Can you expand on "parse" and "text documents"? From don81846 at comcast.net.invalid Sat Jan 16 16:04:09 2021 From: don81846 at comcast.net.invalid (DonK) Date: Sat, 16 Jan 2021 16:04:09 -0500 Subject: A beginning beginner's question about input, output and . . . References: Message-ID: On Tue, 12 Jan 2021 10:16:47 +0400, Abdur-Rahmaan Janhangeer wrote: >Greetings, > >Web with Python is really easy to get started with, here >is a simple endpoint with a framework called Flask > >from flask import Flask >app = Flask(__name__) > >@app.route('/') >def hello_world(): > return 'Hello World? > >if __name__ == '__main__': > app.run() > >As for Tkinter, it's really annoying. >PyQt5 and others are a lot better. >PyQt5 follows the Cpp function namings > >Kind Regards, > >Abdur-Rahmaan Janhangeer Someone else also suggested a web interface for i/o. If I get that far it seems like it will be something I'll need to take a look at. A lot of my early programming was command line BASIC apps running on MSDOS. Even some pretty BIG stuff. So, going back to that after 40+ years seems a little weird. :-) I looked at some Youtube videos about creating mobile apps with Java but that just didn't do it for me. As far as I've seen there isn't really a way to do the small "ad hoc" type of utilities on a smartphone that you can do on a desktop machine. Don't get me wrong, I love my smartphone. Thanks, Don From don81846 at comcast.net.invalid Sat Jan 16 17:46:13 2021 From: don81846 at comcast.net.invalid (DonK) Date: Sat, 16 Jan 2021 17:46:13 -0500 Subject: A beginning beginner's question about input, output and . . . References: <87eeiqd7fj.fsf@nightsong.com> <3gh60g9dcotpsuln9rot5jn4rpl97bsb0v@4ax.com> Message-ID: On Sat, 16 Jan 2021 14:56:37 -0600, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: >On 2021-01-16 at 15:42:44 -0500, >DonK wrote: > >> Yes, Windows. Iterating open windows with the Window's API is easy the >> hard (very hard) part is sending keystrokes to those windows to Save >> them. It's very tricky because the timing is critical. >> >> You have to use one of those "spy" utilities to get the name and >> classid for the controls that you want to send a command to, then use >> the Window's API functions SendMessage or PostMessage to send the >> message directly to the control or just put it in the message que. >> >> Like sending an "s" to the File menu to (S)ave. It's more complicated >> than you would think and it doesn't work very well. It's like pushing >> on a string. > >Then don't do that? ;-) > >I'm no Windows expert (nor even a user), but do those applications have >a scripting interface? (DDE? OLE? COM? Do those letters ring a bell? >The right bell? Are those technologies current?) What you're trying to >do sounds like working *against* those applications rather than with >them. No! I've used the interfaces that you mentioned (OLE and COM in particular) but that was for apps that I, or my colleagues, wrote (for an employer) "to expose their guts" many years ago. I've found few general use Windows apps that support any form of scripting. MS Office apps, famously, support OLE. Or they used to. My copy of Office is 2007 so I don't know about the newer versions. I think most of those technologies might have died a long time ago but I could be entirely wrong. Does Python use those methods to control Excel, etc?? There was a Windows Usenet app, that I was interested in, around 10, maybe 20 years ago that exposed a Pascal language like interface but there was no documentation and no support. I believe it only lasted a short time. I'm pretty sure that it's name started with a "D". It doesn't matter. I tried the method that I described above with the Forte Agent newsreader back in the dial-up days because people in one of the programming newsgroups wanted to be able to upload/dowanload (unattended) in the middle of the night. It might have been possible to get it to work reliably but I gave up on it. > >> For example, I've found a need to parse text documents quite a number >> of times over the years. Basic/VB is great at doing that. How's >> Python? > >Python can do that. Can you expand on "parse" and "text documents"? There's nothing that I have any particular need for at the moment but it is something that I've done a number of times over the years. I think it's a common need?? I've used Pascal and BASIC\VB for string parsing and BASIC\VB is much better. VB has all the string handling functions that you need built in but, for example, Pascal has some but you have to create others to be useful. Since I'm just beginning with Python I have no knowledge or criticism of how Python does this but I'm sure that it can. Since I've retired I've written parsers for my bank records, medical records and other personally useful things. I would categorize them as trivial but useful. i.e utility means useful When I was working, in the 1999-2001 range, I wrote a parser in VB that unscrambled corrupted "batch files" for credit card processing so that vendors didn't have to spend hours rebuilding them by hand. Some of those files had over 700 credit card transactions in them. That's one example. I'm looking forward to learning some Python, mostly for fun, but I'm sure that it will also be useful. Thank you Don From greg.ewing at canterbury.ac.nz Sat Jan 16 18:31:14 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 17 Jan 2021 12:31:14 +1300 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 16/01/21 4:17 pm, Chris Angelico wrote: > But somewhere along the way, you're finding that there's a problem, > which implies that SOMETHING is calling on C stdio. That thing, > surely, should be the thing responsible for flushing? The C library using stdio has no way of knowing that something else (e.g. Python) is bypassing stdio. That's an unusual thing to do in the C world, so you can't really blame the authors of the library for failing to anticipate it. It's also unreasonable to expect a C library to flush after every write, as that would defeat the purpose of stdio buffering. -- Greg From logandcranford at gmail.com Sat Jan 16 15:55:26 2021 From: logandcranford at gmail.com (Logan Cranford) Date: Sat, 16 Jan 2021 14:55:26 -0600 Subject: Python not Running Message-ID: I downloaded Python but when I try to run Idle it says it is not found and I should try to redownload it. When I try to do that all that comes up is a page that says modify, repair or uninstall. I have repaired several times but it still gives me the same message. Can anyone help me with this? From rosuav at gmail.com Sat Jan 16 18:40:59 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jan 2021 10:40:59 +1100 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On Sun, Jan 17, 2021 at 10:36 AM Greg Ewing wrote: > > On 16/01/21 4:17 pm, Chris Angelico wrote: > > But somewhere along the way, you're finding that there's a problem, > > which implies that SOMETHING is calling on C stdio. That thing, > > surely, should be the thing responsible for flushing? > > The C library using stdio has no way of knowing that something > else (e.g. Python) is bypassing stdio. That's an unusual thing > to do in the C world, so you can't really blame the authors > of the library for failing to anticipate it. > > It's also unreasonable to expect a C library to flush after > every write, as that would defeat the purpose of stdio buffering. > This is true. However, at some point, the boundary is crossed from Python into the C library. Something, at that point, knows. It's very common to have a flush option available, so it should be used. It's extremely uncommon for Python to call into C code that (a) uses C stdio, (b) shares the file handle with something else (eg stdout/stderr), and (c) doesn't have an option to flush its output. And when that happens, I would consider it a bug, not just because of the shared handle - if you're piping the output into something else, you might need to force it to flush its buffer. ChrisA From greg.ewing at canterbury.ac.nz Sat Jan 16 19:02:35 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sun, 17 Jan 2021 13:02:35 +1300 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 17/01/21 12:40 pm, Chris Angelico wrote: > This is true. However, at some point, the boundary is crossed from > Python into the C library. Something, at that point, knows. It's very > common to have a flush option available, so it should be used. I'm wondering whether the problem in this particular case stems from trying to use parts of curses without initialising it properly. I expect that initialising curses would put stdout into some kind of unbuffered mode, and the rest of it assumes that this has been done. -- Greg From rosuav at gmail.com Sat Jan 16 19:14:32 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 17 Jan 2021 11:14:32 +1100 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On Sun, Jan 17, 2021 at 11:06 AM Greg Ewing wrote: > > On 17/01/21 12:40 pm, Chris Angelico wrote: > > This is true. However, at some point, the boundary is crossed from > > Python into the C library. Something, at that point, knows. It's very > > common to have a flush option available, so it should be used. > > I'm wondering whether the problem in this particular case stems > from trying to use parts of curses without initialising it > properly. I expect that initialising curses would put stdout > into some kind of unbuffered mode, and the rest of it assumes > that this has been done. > I'm not familiar with the curses module, but that sounds extremely plausible. ChrisA From drsalists at gmail.com Sat Jan 16 20:15:40 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 16 Jan 2021 17:15:40 -0800 Subject: count consecutive elements In-Reply-To: <462c5e21-a3a8-e086-25d8-5fa9508a068a@gmail.com> References: <462c5e21-a3a8-e086-25d8-5fa9508a068a@gmail.com> Message-ID: On Thu, Jan 14, 2021 at 2:01 PM Wolfram Hinderer via Python-list < python-list at python.org> wrote: > Am 13.01.2021 um 22:20 schrieb Bischoop: > > I want to to display a number or an alphabet which appears mostly > > consecutive in a given string or numbers or both > > Examples > > s= ' aabskaaabadcccc' > > output: c > > # c appears 4 consecutive times > > 8bbakebaoa > > output: b > > #b appears 2 consecutive times > > > > > You can let itertools.groupy find the groups. > > max((len(tuple(group)), key) for key, group in itertools.groupby(s)) > # (4, 'c') > Does anyone else find the documentation on itertools.groupby kind of lacking? I think it makes sense now that I've played around with it though. Here's a revised solution: def get_longest(string: str) -> typing.Tuple[int, typing.List[str]]: """Get the longest run of a single consecutive character.""" if not string: return (0, []) grouped = itertools.groupby(string) grouped_with_lengths = [(len(list(value)), key) for key, value in grouped] max_count_and_letter = max(grouped_with_lengths) max_count = max_count_and_letter[0] result = (max_count, sorted(list_ for count, list_ in grouped_with_lengths if count == max_count)) return result From eryksun at gmail.com Sat Jan 16 21:01:06 2021 From: eryksun at gmail.com (Eryk Sun) Date: Sat, 16 Jan 2021 20:01:06 -0600 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 1/16/21, Greg Ewing wrote: > On 17/01/21 12:40 pm, Chris Angelico wrote: >> This is true. However, at some point, the boundary is crossed from >> Python into the C library. Something, at that point, knows. It's very >> common to have a flush option available, so it should be used. > > I'm wondering whether the problem in this particular case stems > from trying to use parts of curses without initialising it > properly. I expect that initialising curses would put stdout > into some kind of unbuffered mode, and the rest of it assumes > that this has been done. The buffering mode cannot be changed for an in-use stream: "setvbuf() ... may be used only after opening a stream and before any other operations have been performed on it". So it would have to open a new stream, which can only be done legitimately by device or file name via C freopen(). Code that overwrites the FILE record (e.g. *stdout = *stream) is not legitimate and cross-platform. You can force the interpreter to change stdout to unbuffered mode at startup via `-u` or the PYTHONUNBUFFERED environment variable. In Linux, there's also the `stdbuf` command (e.g. stdbuf -o0 python ....), which uses an LD_PRELOAD hook to inject a shared library that calls setvbuf() at process startup. There's no analog to that in Windows for various reasons. From 2QdxY4RzWzUUiLuE at potatochowder.com Sat Jan 16 21:17:46 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Sat, 16 Jan 2021 20:17:46 -0600 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: <87eeiqd7fj.fsf@nightsong.com> <3gh60g9dcotpsuln9rot5jn4rpl97bsb0v@4ax.com> Message-ID: On 2021-01-16 at 17:46:13 -0500, DonK wrote: > On Sat, 16 Jan 2021 14:56:37 -0600, 2QdxY4RzWzUUiLuE at potatochowder.com > wrote: > > >On 2021-01-16 at 15:42:44 -0500, > >DonK wrote: > >> For example, I've found a need to parse text documents quite a number > >> of times over the years. Basic/VB is great at doing that. How's > >> Python? > > > > >Python can do that. Can you expand on "parse" and "text documents"? > > There's nothing that I have any particular need for at the moment but > it is something that I've done a number of times over the years. I > think it's a common need?? Indeed. :-) In my experience, "parse" and "text documents" often mean different things to different people. > I've used Pascal and BASIC\VB for string parsing and BASIC\VB is much > better. VB has all the string handling functions that you need built > in but, for example, Pascal has some but you have to create others to > be useful. Since I'm just beginning with Python I have no knowledge or > criticism of how Python does this but I'm sure that it can. > > Since I've retired I've written parsers for my bank records, medical > records and other personally useful things. I would categorize them as > trivial but useful. i.e utility means useful > > When I was working, in the 1999-2001 range, I wrote a parser in VB > that unscrambled corrupted "batch files" for credit card processing so > that vendors didn't have to spend hours rebuilding them by hand. Some > of those files had over 700 credit card transactions in them. That's > one example. Sounds like you're parsing files composed of lines of plain text where each line represents some kind of record (as opposed to parsing a document containing programming code as a precursor to generating an executable, or looking through a word processing document for something important). A bare minimum skeleton might look something like this: with open(filename) as f: for line in f.readlines(): handle_one_line(f) Python has a capable string type for handling text; see . Or look into the fileinput module for a convenient way to run through a collection of files and/or standard input. > I'm looking forward to learning some Python, mostly for fun, but I'm > sure that it will also be useful. Absolutely! :-) Happy Hacking! From chuck.untulis at gmail.com Sat Jan 16 19:44:01 2021 From: chuck.untulis at gmail.com (Chuck Untulis) Date: Sat, 16 Jan 2021 16:44:01 -0800 Subject: Using plotly and getting "This site can't be reached" Message-ID: The Chrome browser on the machine shows "127.0.0.1 refused to connect" for various urls of the form 127.0.0.1:xxxxx where xxxxx are numbers like 64981, 65029,... About once in 20-40 attempts, the graphs appear. I ran the same code on a different machine and it created the plots in the Chrome browser every time. I ran a different Python plotly program on both machines with similar results. Everything else I navigate to in Chrome works as expected. No errors are reported by the plotly code shown below. I also ran the code in Visual Studio Code with the same results. I would like to see the information sent to the browser but I have not figured out how to do that yet. Any help would be appreciated. ===================================================== import pandas as pd df = pd.DataFrame({ "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"], "Contestant": ["Alex", "Alex", "Alex", "Jordan", "Jordan", "Jordan"], "Number Eaten": [2, 1, 3, 1, 3, 2], }) import plotly.express as px fig = px.bar(df, x="Fruit", y="Number Eaten", color="Contestant", barmode= "group") #print(""PLOT 1") # fig.show() import plotly.graph_objects as go fig = go.Figure() for contestant, group in df.groupby("Contestant"): fig.add_trace(go.Bar(x=group["Fruit"], y=group["Number Eaten"], name =contestant, hovertemplate="Contestant=%s
Fruit=%%{x}
Number Eaten=%%{y} "% contestant)) fig.update_layout(legend_title_text = "Contestant") fig.update_xaxes(title_text="Fruit") fig.update_yaxes(title_text="Number Eaten") print("PLOT 2") fig.show() From tjreedy at udel.edu Sat Jan 16 22:30:20 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 Jan 2021 22:30:20 -0500 Subject: Python not Running In-Reply-To: References: Message-ID: On 1/16/2021 3:55 PM, Logan Cranford wrote: > I downloaded Python but when I try to run Idle it says it is not found and From where? try how? what is 'it'? Read the section of https://docs.python.org/3/using/index.html appropriate for your system, likely Windows. > I should try to redownload it. When I try to do that all that comes up is a > page that says modify, repair or uninstall. I have repaired several times This sounds like you are rerunning the python installer, not python itself. Doing the latter depends on how you installed. Read the doc. > but it still gives me the same message. Can anyone help me with this? You can also read answers to similar posts at https://mail.python.org/pipermail/python-list/ -- Terry Jan Reedy From tjreedy at udel.edu Sat Jan 16 22:41:43 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 16 Jan 2021 22:41:43 -0500 Subject: A beginning beginner's question about input, output and . . . In-Reply-To: References: <87eeiqd7fj.fsf@nightsong.com> <3gh60g9dcotpsuln9rot5jn4rpl97bsb0v@4ax.com> Message-ID: On 1/16/2021 9:17 PM, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > A bare minimum skeleton might look something like this: > > with open(filename) as f: > for line in f.readlines(): > handle_one_line(f) f.readlines() reads the entire file into a list of lines (strings). If you do not need that, for line in f: is sufficient for iterating thru the file line by line. -- Terry Jan Reedy From omidmohammadi9124 at gmail.com Sun Jan 17 05:20:24 2021 From: omidmohammadi9124 at gmail.com (omid mohammadi) Date: Sun, 17 Jan 2021 02:20:24 -0800 (PST) Subject: open sentinel-2image python Message-ID: <59b289d3-31af-4da4-a52c-d72fcd87ee3en@googlegroups.com> Dear all , When I open the sentinel-2 image in Python, I get the following error: MemoryError: Unable to allocate 115. MiB for an array with shape (5490, 5490) and data type float32 How can I fix it? Thanks From Karsten.Hilbert at gmx.net Sun Jan 17 08:57:40 2021 From: Karsten.Hilbert at gmx.net (Karsten Hilbert) Date: Sun, 17 Jan 2021 14:57:40 +0100 Subject: open sentinel-2image python In-Reply-To: <59b289d3-31af-4da4-a52c-d72fcd87ee3en@googlegroups.com> References: <59b289d3-31af-4da4-a52c-d72fcd87ee3en@googlegroups.com> Message-ID: Am Sun, Jan 17, 2021 at 02:20:24AM -0800 schrieb omid mohammadi: > When I open the sentinel-2 image in Python, I get the following error: > > MemoryError: Unable to allocate 115. MiB for an array with shape (5490, 5490) and data type float32 > > How can I fix it? You can install more RAM. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B From alan.gauld at yahoo.co.uk Sun Jan 17 09:34:53 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Sun, 17 Jan 2021 14:34:53 +0000 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 17/01/2021 00:02, Greg Ewing wrote: > On 17/01/21 12:40 pm, Chris Angelico wrote: >> This is true. However, at some point, the boundary is crossed from >> Python into the C library. Something, at that point, knows. It's very >> common to have a flush option available, so it should be used. > > I'm wondering whether the problem in this particular case stems > from trying to use parts of curses without initialising it > properly. The problem is terminfo is not really part of curses. Curses is built on top of terminfo. > I expect that initialising curses would put stdout > into some kind of unbuffered mode, You can choose the mode, but once in curses all the standard input/output options cease to be usable, you have to use the curses functions such as addstr(), getch() etc. Its precisely because curses is such an all or nothing option that I wanted to see if I could create some kind of text attribute control outside of curses - which it seems is what Cameron has been up to independently! For example, it is difficult to call a Python function that has print statements in it (bad practice though it may be!) from within curses. You need to temporarily turn cures off, call he function then reinstate curses. It's doable but messy! If you don't need to create windows and move the cursor around and respond to mouse clicks etc then curses is a bit of overkill to just turn some text bold or inverse. That's where the terminfo functions come in and, as you saw from the C code, are fairly trivial to use in C. -- 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 __peter__ at web.de Sun Jan 17 12:50:17 2021 From: __peter__ at web.de (Peter Otten) Date: Sun, 17 Jan 2021 18:50:17 +0100 Subject: count consecutive elements In-Reply-To: References: <462c5e21-a3a8-e086-25d8-5fa9508a068a@gmail.com> Message-ID: On 17/01/2021 02:15, Dan Stromberg wrote: IMO a good set of tests is much more important than type annotations ;) > def get_longest(string: str) -> typing.Tuple[int, typing.List[str]]: > """Get the longest run of a single consecutive character.""" May I ask why you artificially limit the signature to str? If there were a signature, shouldn't it be something like Iterable[E] --> Tuple[int, List[E]] where E may be anything that has an equality operation? As someone who has not yet looked seriously into typing: is there a way to spell this? > if not string: > return (0, []) > grouped = itertools.groupby(string) > grouped_with_lengths = [(len(list(value)), key) for key, value in > grouped] > max_count_and_letter = max(grouped_with_lengths) > max_count = max_count_and_letter[0] > result = (max_count, sorted(list_ for count, list_ in > grouped_with_lengths if count == max_count)) > return result If you want to dabble some more here's a test case you might strive for your function to pass: """ >>> class A: ... def __init__(self, x): ... self.x = x ... def __eq__(self, other): ... return self.x == other.x ... def __repr__(self): ... return self.x >>> get_longest(map(A, "aaabbcccdaa")) (3, [a, c]) """ From __peter__ at web.de Sun Jan 17 12:50:17 2021 From: __peter__ at web.de (Peter Otten) Date: Sun, 17 Jan 2021 18:50:17 +0100 Subject: count consecutive elements In-Reply-To: References: <462c5e21-a3a8-e086-25d8-5fa9508a068a@gmail.com> Message-ID: On 17/01/2021 02:15, Dan Stromberg wrote: IMO a good set of tests is much more important than type annotations ;) > def get_longest(string: str) -> typing.Tuple[int, typing.List[str]]: > """Get the longest run of a single consecutive character.""" May I ask why you artificially limit the signature to str? If there were a signature, shouldn't it be something like Iterable[E] --> Tuple[int, List[E]] where E may be anything that has an equality operation? As someone who has not yet looked seriously into typing: is there a way to spell this? > if not string: > return (0, []) > grouped = itertools.groupby(string) > grouped_with_lengths = [(len(list(value)), key) for key, value in > grouped] > max_count_and_letter = max(grouped_with_lengths) > max_count = max_count_and_letter[0] > result = (max_count, sorted(list_ for count, list_ in > grouped_with_lengths if count == max_count)) > return result If you want to dabble some more here's a test case you might strive for your function to pass: """ >>> class A: ... def __init__(self, x): ... self.x = x ... def __eq__(self, other): ... return self.x == other.x ... def __repr__(self): ... return self.x >>> get_longest(map(A, "aaabbcccdaa")) (3, [a, c]) """ From python at mrabarnett.plus.com Sun Jan 17 13:01:26 2021 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 17 Jan 2021 18:01:26 +0000 Subject: open sentinel-2image python In-Reply-To: References: <59b289d3-31af-4da4-a52c-d72fcd87ee3en@googlegroups.com> Message-ID: <2b5b4ba0-d16e-f85c-3b8b-0c3981774a54@mrabarnett.plus.com> On 2021-01-17 13:57, Karsten Hilbert wrote: > Am Sun, Jan 17, 2021 at 02:20:24AM -0800 schrieb omid mohammadi: > >> When I open the sentinel-2 image in Python, I get the following error: >> >> MemoryError: Unable to allocate 115. MiB for an array with shape (5490, 5490) and data type float32 >> >> How can I fix it? > > You can install more RAM. > Or maybe the OP is running 32-bit Python but the code needs >2GB. If that's the case then using 64-bit Python might fix it, assuming that it's a 64-bit machine. From omidmohammadi9124 at gmail.com Sun Jan 17 14:12:26 2021 From: omidmohammadi9124 at gmail.com (omid mohammadi) Date: Sun, 17 Jan 2021 11:12:26 -0800 (PST) Subject: open sentinel-2image python In-Reply-To: References: <59b289d3-31af-4da4-a52c-d72fcd87ee3en@googlegroups.com> <2b5b4ba0-d16e-f85c-3b8b-0c3981774a54@mrabarnett.plus.com> Message-ID: <27d00fcc-0ef5-4ec6-809f-3163431b1696n@googlegroups.com> On Sunday, January 17, 2021 at 9:31:58 PM UTC+3:30, MRAB wrote: > On 2021-01-17 13:57, Karsten Hilbert wrote: > > Am Sun, Jan 17, 2021 at 02:20:24AM -0800 schrieb omid mohammadi: > > > >> When I open the sentinel-2 image in Python, I get the following error: > >> > >> MemoryError: Unable to allocate 115. MiB for an array with shape (5490, 5490) and data type float32 > >> > >> How can I fix it? > > > > You can install more RAM. > > > Or maybe the OP is running 32-bit Python but the code needs >2GB. If > that's the case then using 64-bit Python might fix it, assuming that > it's a 64-bit machine. Yes, it is 64. Excuse me, can you explain how I can fix it? From PythonList at DancesWithMice.info Sun Jan 17 14:28:13 2021 From: PythonList at DancesWithMice.info (dn) Date: Mon, 18 Jan 2021 08:28:13 +1300 Subject: open sentinel-2image python In-Reply-To: <27d00fcc-0ef5-4ec6-809f-3163431b1696n@googlegroups.com> References: <59b289d3-31af-4da4-a52c-d72fcd87ee3en@googlegroups.com> <2b5b4ba0-d16e-f85c-3b8b-0c3981774a54@mrabarnett.plus.com> <27d00fcc-0ef5-4ec6-809f-3163431b1696n@googlegroups.com> Message-ID: On 18/01/2021 08.12, omid mohammadi wrote: > On Sunday, January 17, 2021 at 9:31:58 PM UTC+3:30, MRAB wrote: >> On 2021-01-17 13:57, Karsten Hilbert wrote: >>> Am Sun, Jan 17, 2021 at 02:20:24AM -0800 schrieb omid mohammadi: >>> >>>> When I open the sentinel-2 image in Python, I get the following error: >>>> >>>> MemoryError: Unable to allocate 115. MiB for an array with shape (5490, 5490) and data type float32 >>>> >>>> How can I fix it? >>> >>> You can install more RAM. >>> >> Or maybe the OP is running 32-bit Python but the code needs >2GB. If >> that's the case then using 64-bit Python might fix it, assuming that >> it's a 64-bit machine. > > Yes, it is 64. > > Excuse me, can you explain how I can fix it? What is "64" - the machine or the Python package? >From where did you download Python? What is the code being used to read/load the image? What do you mean by "the sentinel-2 image" - most of the images (which I spotted in a *quick* survey) made available to the general public are of the order of tens of mega-bytes. (a URL might help people trying to replicate the problem!) Be advised that everyone 'here' is a volunteer. Please help us to help you! -- Regards =dn From python at mrabarnett.plus.com Sun Jan 17 14:42:50 2021 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 17 Jan 2021 19:42:50 +0000 Subject: open sentinel-2image python In-Reply-To: <27d00fcc-0ef5-4ec6-809f-3163431b1696n@googlegroups.com> References: <59b289d3-31af-4da4-a52c-d72fcd87ee3en@googlegroups.com> <2b5b4ba0-d16e-f85c-3b8b-0c3981774a54@mrabarnett.plus.com> <27d00fcc-0ef5-4ec6-809f-3163431b1696n@googlegroups.com> Message-ID: <23c7dca6-dab5-d92d-f641-b5f883762ba4@mrabarnett.plus.com> On 2021-01-17 19:12, omid mohammadi wrote: > On Sunday, January 17, 2021 at 9:31:58 PM UTC+3:30, MRAB wrote: >> On 2021-01-17 13:57, Karsten Hilbert wrote: >> > Am Sun, Jan 17, 2021 at 02:20:24AM -0800 schrieb omid mohammadi: >> > >> >> When I open the sentinel-2 image in Python, I get the following error: >> >> >> >> MemoryError: Unable to allocate 115. MiB for an array with shape (5490, 5490) and data type float32 >> >> >> >> How can I fix it? >> > >> > You can install more RAM. >> > >> Or maybe the OP is running 32-bit Python but the code needs >2GB. If >> that's the case then using 64-bit Python might fix it, assuming that >> it's a 64-bit machine. > > Yes, it is 64. > > Excuse me, can you explain how I can fix it? > Are you using a 32-bit version of Python or a 64-bit version of Python? If you're not sure, try this from Python: >>> import sys >>> sys.maxsize.bit_length() I get 63 because I'm running a 64-bit version of Python 3. On Windows you can install multiple versions of Python side-by-side. I don't know the procedure for Linux or MacOS. If you're currently using 32-bit Python, you can install the 64-bit version in a folder next to the folder of the 32-bit version (I have C:\Python39 and C:\Python39-32, for example). Then install any other packages you need for the new version. From robin at reportlab.com Sun Jan 17 11:16:32 2021 From: robin at reportlab.com (Robin Becker) Date: Sun, 17 Jan 2021 16:16:32 +0000 Subject: advice on debugging a segfault Message-ID: <1b1e536b-b90c-e734-48e3-1c0186e6efc9@everest.reportlab.co.uk> I have a segfault in the 3.10 alpha 4 when running the reportlab document generation; all the other tests seem to have worked. I would like to ask experts here how to approach getting the location of the problem. I run recent archlinux. Below is the output of a test run with -Xdev -Xtracemalloc; the main process is almost finished so the error appears to come from trying to free resources > $ python -Xdev -Xtracemalloc genuserguide.py > /home/robin/devel/reportlab/.py310/lib/python3.10/distutils/__init__.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses > import imp > Built story contains 1843 flowables... > Saved "/home/robin/devel/reportlab/REPOS/reportlab/docs/reportlab-userguide.pdf" > [ Top 10 ] > :630: size=10.5 MiB, count=105832, average=104 B > /home/robin/devel/reportlab/reportlab/lib/abag.py:19: size=7161 KiB, count=27126, average=270 B > /home/robin/devel/reportlab/reportlab/platypus/paraparser.py:3141: size=3364 KiB, count=5980, average=576 B > /home/robin/devel/reportlab/.py310/lib/python3.10/site-packages/pyphen/__init__.py:160: size=2905 KiB, count=41797, average=71 B > /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:776: size=1386 KiB, count=32208, average=44 B > /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:92: size=1384 KiB, count=26248, average=54 B > /home/robin/devel/reportlab/.py310/lib/python3.10/copy.py:280: size=1232 KiB, count=8827, average=143 B > /home/robin/devel/reportlab/reportlab/platypus/frames.py:155: size=1101 KiB, count=1173, average=962 B > :241: size=915 KiB, count=8146, average=115 B > /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:773: size=881 KiB, count=16104, average=56 B > sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='../images/replogo.gif'> > sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='../images/testimg.gif'> > Debug memory block at address p=0x5617c33effe0: API '' > 0 bytes originally requested > The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfd): > at p-7: 0x00 *** OUCH > at p-6: 0x00 *** OUCH > at p-5: 0x00 *** OUCH > at p-4: 0x00 *** OUCH > at p-3: 0x00 *** OUCH > at p-2: 0x00 *** OUCH > at p-1: 0x00 *** OUCH > Because memory is corrupted at the start, the count of bytes requested > may be bogus, and checking the trailing pad bytes may segfault. > The 8 pad bytes at tail=0x5617c33effe0 are not all FORBIDDENBYTE (0xfd): > at tail+0: 0x00 *** OUCH > at tail+1: 0x00 *** OUCH > at tail+2: 0x00 *** OUCH > at tail+3: 0x00 *** OUCH > at tail+4: 0x00 *** OUCH > at tail+5: 0x00 *** OUCH > at tail+6: 0x00 *** OUCH > at tail+7: 0x00 *** OUCH > > Enable tracemalloc to get the memory block allocation traceback > > Fatal Python error: _PyMem_DebugRawFree: bad ID: Allocated using API '', verified using API 'o' > Python runtime state: finalizing (tstate=0x5617c53c8b30) > > Current thread 0x00007fd5742b3740 (most recent call first): > > Aborted (core dumped) for comparison here is the 3.9.1 output> $ python -Xdev -Xtracemalloc genuserguide.py > /home/robin/devel/reportlab/.py39/lib/python3.9/distutils/__init__.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses > import imp > /home/robin/devel/reportlab/.py39/lib/python3.9/site-packages/fontTools/misc/py23.py:11: DeprecationWarning: The py23 module has been deprecated and will be removed in the next release. Please update your code. > warnings.warn( > Built story contains 1843 flowables... > Saved "/home/robin/devel/reportlab/REPOS/reportlab/docs/reportlab-userguide.pdf" > [ Top 10 ] > :587: size=12.4 MiB, count=128010, average=102 B > /home/robin/devel/reportlab/reportlab/lib/abag.py:19: size=7132 KiB, count=26951, average=271 B > /home/robin/devel/reportlab/reportlab/platypus/paraparser.py:3141: size=3364 KiB, count=5980, average=576 B > /home/robin/devel/reportlab/.py39/lib/python3.9/site-packages/pyphen/__init__.py:160: size=2905 KiB, count=41797, average=71 B > /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:776: size=1386 KiB, count=32208, average=44 B > /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:92: size=1384 KiB, count=26248, average=54 B > /home/robin/devel/reportlab/.py39/lib/python3.9/copy.py:279: size=1230 KiB, count=8827, average=143 B > /home/robin/devel/reportlab/reportlab/platypus/frames.py:155: size=1039 KiB, count=957, average=1112 B > :228: size=959 KiB, count=8503, average=116 B > /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:773: size=881 KiB, count=16104, average=56 B > sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='../images/replogo.gif'> > sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='../images/testimg.gif'> From grant.b.edwards at gmail.com Sun Jan 17 13:03:42 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 17 Jan 2021 18:03:42 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-17, Greg Ewing wrote: > On 17/01/21 12:40 pm, Chris Angelico wrote: >> This is true. However, at some point, the boundary is crossed from >> Python into the C library. Something, at that point, knows. It's very >> common to have a flush option available, so it should be used. > > I'm wondering whether the problem in this particular case stems > from trying to use parts of curses without initialising it > properly. No. > I expect that initialising curses would put stdout into some kind of > unbuffered mode, and the rest of it assumes that this has been done. No. -- Grant From barry at barrys-emacs.org Sun Jan 17 16:24:59 2021 From: barry at barrys-emacs.org (Barry) Date: Sun, 17 Jan 2021 21:24:59 +0000 Subject: advice on debugging a segfault In-Reply-To: <1b1e536b-b90c-e734-48e3-1c0186e6efc9@everest.reportlab.co.uk> References: <1b1e536b-b90c-e734-48e3-1c0186e6efc9@everest.reportlab.co.uk> Message-ID: <76AEA799-04E1-44E3-8936-C1DA790D62BB@barrys-emacs.org> Run python under gdb and when the segv happens use the gdb bt command to get a stack trace. Also if gdb says that it needs debug symbols install you will need to do that. Otherwise the not will not contain symbols. Barry > On 17 Jan 2021, at 19:58, Robin Becker wrote: > > ?I have a segfault in the 3.10 alpha 4 when running the reportlab document generation; all the other tests seem to have worked. I would like to ask experts here how to approach getting the location of the problem. I run recent archlinux. > > Below is the output of a test run with -Xdev -Xtracemalloc; the main process is almost finished so the error appears to come from trying to free resources > >> $ python -Xdev -Xtracemalloc genuserguide.py /home/robin/devel/reportlab/.py310/lib/python3.10/distutils/__init__.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses >> import imp >> Built story contains 1843 flowables... >> Saved "/home/robin/devel/reportlab/REPOS/reportlab/docs/reportlab-userguide.pdf" >> [ Top 10 ] >> :630: size=10.5 MiB, count=105832, average=104 B >> /home/robin/devel/reportlab/reportlab/lib/abag.py:19: size=7161 KiB, count=27126, average=270 B >> /home/robin/devel/reportlab/reportlab/platypus/paraparser.py:3141: size=3364 KiB, count=5980, average=576 B >> /home/robin/devel/reportlab/.py310/lib/python3.10/site-packages/pyphen/__init__.py:160: size=2905 KiB, count=41797, average=71 B >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:776: size=1386 KiB, count=32208, average=44 B >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:92: size=1384 KiB, count=26248, average=54 B >> /home/robin/devel/reportlab/.py310/lib/python3.10/copy.py:280: size=1232 KiB, count=8827, average=143 B >> /home/robin/devel/reportlab/reportlab/platypus/frames.py:155: size=1101 KiB, count=1173, average=962 B >> :241: size=915 KiB, count=8146, average=115 B >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:773: size=881 KiB, count=16104, average=56 B >> sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='../images/replogo.gif'> >> sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='../images/testimg.gif'> >> Debug memory block at address p=0x5617c33effe0: API '' >> 0 bytes originally requested >> The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfd): >> at p-7: 0x00 *** OUCH >> at p-6: 0x00 *** OUCH >> at p-5: 0x00 *** OUCH >> at p-4: 0x00 *** OUCH >> at p-3: 0x00 *** OUCH >> at p-2: 0x00 *** OUCH >> at p-1: 0x00 *** OUCH >> Because memory is corrupted at the start, the count of bytes requested >> may be bogus, and checking the trailing pad bytes may segfault. >> The 8 pad bytes at tail=0x5617c33effe0 are not all FORBIDDENBYTE (0xfd): >> at tail+0: 0x00 *** OUCH >> at tail+1: 0x00 *** OUCH >> at tail+2: 0x00 *** OUCH >> at tail+3: 0x00 *** OUCH >> at tail+4: 0x00 *** OUCH >> at tail+5: 0x00 *** OUCH >> at tail+6: 0x00 *** OUCH >> at tail+7: 0x00 *** OUCH >> Enable tracemalloc to get the memory block allocation traceback >> Fatal Python error: _PyMem_DebugRawFree: bad ID: Allocated using API '', verified using API 'o' >> Python runtime state: finalizing (tstate=0x5617c53c8b30) >> Current thread 0x00007fd5742b3740 (most recent call first): >> >> Aborted (core dumped) > > > for comparison here is the 3.9.1 output> $ python -Xdev -Xtracemalloc genuserguide.py >> /home/robin/devel/reportlab/.py39/lib/python3.9/distutils/__init__.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses >> import imp >> /home/robin/devel/reportlab/.py39/lib/python3.9/site-packages/fontTools/misc/py23.py:11: DeprecationWarning: The py23 module has been deprecated and will be removed in the next release. Please update your code. >> warnings.warn( >> Built story contains 1843 flowables... >> Saved "/home/robin/devel/reportlab/REPOS/reportlab/docs/reportlab-userguide.pdf" >> [ Top 10 ] >> :587: size=12.4 MiB, count=128010, average=102 B >> /home/robin/devel/reportlab/reportlab/lib/abag.py:19: size=7132 KiB, count=26951, average=271 B >> /home/robin/devel/reportlab/reportlab/platypus/paraparser.py:3141: size=3364 KiB, count=5980, average=576 B >> /home/robin/devel/reportlab/.py39/lib/python3.9/site-packages/pyphen/__init__.py:160: size=2905 KiB, count=41797, average=71 B >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:776: size=1386 KiB, count=32208, average=44 B >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:92: size=1384 KiB, count=26248, average=54 B >> /home/robin/devel/reportlab/.py39/lib/python3.9/copy.py:279: size=1230 KiB, count=8827, average=143 B >> /home/robin/devel/reportlab/reportlab/platypus/frames.py:155: size=1039 KiB, count=957, average=1112 B >> :228: size=959 KiB, count=8503, average=116 B >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:773: size=881 KiB, count=16104, average=56 B >> sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='../images/replogo.gif'> >> sys:1: ResourceWarning: unclosed file <_io.BufferedReader name='../images/testimg.gif'> > > > -- > https://mail.python.org/mailman/listinfo/python-list > From stestagg at gmail.com Sun Jan 17 16:35:56 2021 From: stestagg at gmail.com (Stestagg) Date: Sun, 17 Jan 2021 21:35:56 +0000 Subject: advice on debugging a segfault In-Reply-To: <76AEA799-04E1-44E3-8936-C1DA790D62BB@barrys-emacs.org> References: <1b1e536b-b90c-e734-48e3-1c0186e6efc9@everest.reportlab.co.uk> <76AEA799-04E1-44E3-8936-C1DA790D62BB@barrys-emacs.org> Message-ID: I would normally agree, except... This is a refcount issue (I was able to reproduce the problem, gbd shows a free error ) And I wouldn't recommend DGBing a refcount issue as a beginner to debugging. The other mailing list identified a PIL bug that messes up the refcount for True, but this refcount issue is for some tuple object, so may possibly be a different problem. Steve On Sun, Jan 17, 2021 at 9:27 PM Barry wrote: > Run python under gdb and when the segv happens use > the gdb bt command to get a stack trace. > > Also if gdb says that it needs debug symbols install you will need to > do that. Otherwise the not will not contain symbols. > > Barry > > > On 17 Jan 2021, at 19:58, Robin Becker wrote: > > > > ?I have a segfault in the 3.10 alpha 4 when running the reportlab > document generation; all the other tests seem to have worked. I would like > to ask experts here how to approach getting the location of the problem. I > run recent archlinux. > > > > Below is the output of a test run with -Xdev -Xtracemalloc; the main > process is almost finished so the error appears to come from trying to free > resources > > > >> $ python -Xdev -Xtracemalloc genuserguide.py > /home/robin/devel/reportlab/.py310/lib/python3.10/distutils/__init__.py:1: > DeprecationWarning: the imp module is deprecated in favour of importlib; > see the module's documentation for alternative uses > >> import imp > >> Built story contains 1843 flowables... > >> Saved > "/home/robin/devel/reportlab/REPOS/reportlab/docs/reportlab-userguide.pdf" > >> [ Top 10 ] > >> :630: size=10.5 MiB, > count=105832, average=104 B > >> /home/robin/devel/reportlab/reportlab/lib/abag.py:19: size=7161 KiB, > count=27126, average=270 B > >> /home/robin/devel/reportlab/reportlab/platypus/paraparser.py:3141: > size=3364 KiB, count=5980, average=576 B > >> > /home/robin/devel/reportlab/.py310/lib/python3.10/site-packages/pyphen/__init__.py:160: > size=2905 KiB, count=41797, average=71 B > >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:776: > size=1386 KiB, count=32208, average=44 B > >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:92: > size=1384 KiB, count=26248, average=54 B > >> /home/robin/devel/reportlab/.py310/lib/python3.10/copy.py:280: > size=1232 KiB, count=8827, average=143 B > >> /home/robin/devel/reportlab/reportlab/platypus/frames.py:155: size=1101 > KiB, count=1173, average=962 B > >> :241: size=915 KiB, count=8146, > average=115 B > >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:773: > size=881 KiB, count=16104, average=56 B > >> sys:1: ResourceWarning: unclosed file <_io.BufferedReader > name='../images/replogo.gif'> > >> sys:1: ResourceWarning: unclosed file <_io.BufferedReader > name='../images/testimg.gif'> > >> Debug memory block at address p=0x5617c33effe0: API '' > >> 0 bytes originally requested > >> The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfd): > >> at p-7: 0x00 *** OUCH > >> at p-6: 0x00 *** OUCH > >> at p-5: 0x00 *** OUCH > >> at p-4: 0x00 *** OUCH > >> at p-3: 0x00 *** OUCH > >> at p-2: 0x00 *** OUCH > >> at p-1: 0x00 *** OUCH > >> Because memory is corrupted at the start, the count of bytes > requested > >> may be bogus, and checking the trailing pad bytes may segfault. > >> The 8 pad bytes at tail=0x5617c33effe0 are not all FORBIDDENBYTE > (0xfd): > >> at tail+0: 0x00 *** OUCH > >> at tail+1: 0x00 *** OUCH > >> at tail+2: 0x00 *** OUCH > >> at tail+3: 0x00 *** OUCH > >> at tail+4: 0x00 *** OUCH > >> at tail+5: 0x00 *** OUCH > >> at tail+6: 0x00 *** OUCH > >> at tail+7: 0x00 *** OUCH > >> Enable tracemalloc to get the memory block allocation traceback > >> Fatal Python error: _PyMem_DebugRawFree: bad ID: Allocated using API > '', verified using API 'o' > >> Python runtime state: finalizing (tstate=0x5617c53c8b30) > >> Current thread 0x00007fd5742b3740 (most recent call first): > >> > >> Aborted (core dumped) > > > > > > for comparison here is the 3.9.1 output> $ python -Xdev -Xtracemalloc > genuserguide.py > >> > /home/robin/devel/reportlab/.py39/lib/python3.9/distutils/__init__.py:1: > DeprecationWarning: the imp module is deprecated in favour of importlib; > see the module's documentation for alternative uses > >> import imp > >> > /home/robin/devel/reportlab/.py39/lib/python3.9/site-packages/fontTools/misc/py23.py:11: > DeprecationWarning: The py23 module has been deprecated and will be removed > in the next release. Please update your code. > >> warnings.warn( > >> Built story contains 1843 flowables... > >> Saved > "/home/robin/devel/reportlab/REPOS/reportlab/docs/reportlab-userguide.pdf" > >> [ Top 10 ] > >> :587: size=12.4 MiB, > count=128010, average=102 B > >> /home/robin/devel/reportlab/reportlab/lib/abag.py:19: size=7132 KiB, > count=26951, average=271 B > >> /home/robin/devel/reportlab/reportlab/platypus/paraparser.py:3141: > size=3364 KiB, count=5980, average=576 B > >> > /home/robin/devel/reportlab/.py39/lib/python3.9/site-packages/pyphen/__init__.py:160: > size=2905 KiB, count=41797, average=71 B > >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:776: > size=1386 KiB, count=32208, average=44 B > >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:92: > size=1384 KiB, count=26248, average=54 B > >> /home/robin/devel/reportlab/.py39/lib/python3.9/copy.py:279: size=1230 > KiB, count=8827, average=143 B > >> /home/robin/devel/reportlab/reportlab/platypus/frames.py:155: size=1039 > KiB, count=957, average=1112 B > >> :228: size=959 KiB, count=8503, > average=116 B > >> /home/robin/devel/reportlab/reportlab/platypus/paragraph.py:773: > size=881 KiB, count=16104, average=56 B > >> sys:1: ResourceWarning: unclosed file <_io.BufferedReader > name='../images/replogo.gif'> > >> sys:1: ResourceWarning: unclosed file <_io.BufferedReader > name='../images/testimg.gif'> > > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From grant.b.edwards at gmail.com Sun Jan 17 16:56:45 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 17 Jan 2021 21:56:45 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-17, Grant Edwards wrote: > On 2021-01-17, Greg Ewing wrote: >> On 17/01/21 12:40 pm, Chris Angelico wrote: >>> This is true. However, at some point, the boundary is crossed from >>> Python into the C library. Something, at that point, knows. It's very >>> common to have a flush option available, so it should be used. >> >> I'm wondering whether the problem in this particular case stems >> from trying to use parts of curses without initialising it >> properly. > > No. > >> I expect that initialising curses would put stdout into some kind of >> unbuffered mode, and the rest of it assumes that this has been done. > > No. I should clarify. The case in question isn't using curses. It's only using the terminfo calls, and the terminfo stuff is being properly initialized. As I previously explained, the problem with the OP's code is that ncurses.putp() is writing to libc's FILE *stdout (which does buffering). Python's stdout/stderr objects do not use FILE *stdout/*stderr, but instead do their own buffering before writing to the file descriptors. There are three ways to do what the OP is trying to do: 1. Use ctypes to call fflush(stdout) before doing a print() or sys.stdout.write(), and call sys.stdout.flush() before calling curses.putp(). 2. Don't use putp(). Use the terminfo calls to construct the escape sequences and then write them with print() or sys.stdout.write(). 3. Replace sys.stdout.buffer and sys.stderr.buffer with a custom objects that uses ctypes to call fwrite() instead of writing directly to the file descriptor. I've posted examples of #1 and #2, I'll try #3 when I have more spare time. I thought it might be possible to use curses.tputs() with a callback that writes to sys.stdout, but the curses module doesn't provide tput, it only provides putp (which is far less flexible). -- Grant From greg.ewing at canterbury.ac.nz Sun Jan 17 19:23:53 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 18 Jan 2021 13:23:53 +1300 Subject: Exploring terminfo In-Reply-To: References: Message-ID: On 18/01/21 3:34 am, Alan Gauld wrote: > The problem is terminfo is not really part of curses. > Curses is built on top of terminfo. As far as I can tell from the man pages, terminfo itself is just a file format. The only programmatic interfaces I can find for it *are* part of curses: del_curterm(3x), mvcur(3x), putp(3x), restartterm(3x), set_curterm(3x), setterm(3x), setupterm(3x), tigetflag(3x), tigetnum(3x), tigetstr(3x), tparm(3x), tputs(3x), vid_attr(3x), vid_puts(3x), vidattr(3x), vidputs(3x) - curses interfaces to terminfo database tgetent(3x), tgetflag(3x), tgetnum(3x), tgetstr(3x), tgoto(3x), tputs(3x) - direct curses interface to the terminfo capability database -- Greg From robin at reportlab.com Mon Jan 18 03:36:38 2021 From: robin at reportlab.com (Robin Becker) Date: Mon, 18 Jan 2021 08:36:38 +0000 Subject: advice on debugging a segfault In-Reply-To: References: <1b1e536b-b90c-e734-48e3-1c0186e6efc9@everest.reportlab.co.uk> <76AEA799-04E1-44E3-8936-C1DA790D62BB@barrys-emacs.org> Message-ID: On 17/01/2021 21:35, Stestagg wrote: > I would normally agree, except... > > This is a refcount issue (I was able to reproduce the problem, gbd shows a > free error ) > > And I wouldn't recommend DGBing a refcount issue as a beginner to debugging. > > The other mailing list identified a PIL bug that messes up the refcount for > True, but this refcount issue is for some tuple object, so may possibly be > a different problem. > > Steve .......... thanks for all the advice and apologies for the noise. It turns out that Victor Stinner's recommendation in the dev list was the solution as I don't see the segfault with pillow built from latest git Pillow @ git+git://github.com/python-pillow/pillow.git at 8dc5f692dbd9a418d8c441f0e2aa09a3f5c03508 I did realize that this must be a late issue in the process as the pdf was being produced and written as expected and that is normally the end of things -- not segfaulting-ly yrs Robin Becker From robin at reportlab.com Mon Jan 18 03:36:38 2021 From: robin at reportlab.com (Robin Becker) Date: Mon, 18 Jan 2021 08:36:38 +0000 Subject: advice on debugging a segfault In-Reply-To: References: <1b1e536b-b90c-e734-48e3-1c0186e6efc9@everest.reportlab.co.uk> <76AEA799-04E1-44E3-8936-C1DA790D62BB@barrys-emacs.org> Message-ID: On 17/01/2021 21:35, Stestagg wrote: > I would normally agree, except... > > This is a refcount issue (I was able to reproduce the problem, gbd shows a > free error ) > > And I wouldn't recommend DGBing a refcount issue as a beginner to debugging. > > The other mailing list identified a PIL bug that messes up the refcount for > True, but this refcount issue is for some tuple object, so may possibly be > a different problem. > > Steve .......... thanks for all the advice and apologies for the noise. It turns out that Victor Stinner's recommendation in the dev list was the solution as I don't see the segfault with pillow built from latest git Pillow @ git+git://github.com/python-pillow/pillow.git at 8dc5f692dbd9a418d8c441f0e2aa09a3f5c03508 I did realize that this must be a late issue in the process as the pdf was being produced and written as expected and that is normally the end of things -- not segfaulting-ly yrs Robin Becker From random832 at fastmail.com Mon Jan 18 17:14:48 2021 From: random832 at fastmail.com (Random832) Date: Mon, 18 Jan 2021 17:14:48 -0500 Subject: Exploring terminfo In-Reply-To: References: Message-ID: <2c14f8fc-55d6-4d3f-bd46-9ef4e225acf7@www.fastmail.com> On Fri, Jan 15, 2021, at 13:36, Alan Gauld via Python-list wrote: > That could make a big difference, the putp() function specifically > states that it writes to stdout. I think there is a reasonable argument that this is a deficiency of the curses module. I think that the curses module should A) expose a version of tputs that accepts a python callback to process each output byte B) expose a version of putp that uses python's stdout[.buffer].write rather than C's putchar. From grant.b.edwards at gmail.com Mon Jan 18 18:00:59 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 18 Jan 2021 23:00:59 -0000 (UTC) Subject: Exploring terminfo References: <2c14f8fc-55d6-4d3f-bd46-9ef4e225acf7@www.fastmail.com> Message-ID: On 2021-01-18, Random832 wrote: > On Fri, Jan 15, 2021, at 13:36, Alan Gauld via Python-list wrote: >> That could make a big difference, the putp() function specifically >> states that it writes to stdout. > > I think there is a reasonable argument that this is a deficiency of > the curses module. > > I think that the curses module should A) expose a version of tputs > that accepts a python callback to process each output byte B) expose > a version of putp that uses python's stdout[.buffer].write rather > than C's putchar. Agreed. I tried to use ctypes to call tputs with a Python callback that wrote to sys.stdout, but was unable to get it to work. FWIW, I've written up notes on the problem and provided demos of various solutions: https://github.com/GrantEdwards/Python-curses-and-terminfo From alan.gauld at yahoo.co.uk Mon Jan 18 20:34:35 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Tue, 19 Jan 2021 01:34:35 +0000 Subject: Exploring terminfo In-Reply-To: <2c14f8fc-55d6-4d3f-bd46-9ef4e225acf7@www.fastmail.com> References: <2c14f8fc-55d6-4d3f-bd46-9ef4e225acf7@www.fastmail.com> Message-ID: On 18/01/2021 22:14, Random832 wrote: > On Fri, Jan 15, 2021, at 13:36, Alan Gauld via Python-list wrote: >> That could make a big difference, the putp() function specifically >> states that it writes to stdout. > > I think there is a reasonable argument that this is a deficiency of the curses module. > > I think that the curses module should ..> B) expose a version of putp that uses pthon's stdout[.buffer].write rather than C's putchar. To be fair that's a limitation of the C curses library. putp() is a wrapper around tputs() even there, and you can't change what it does. The gap in the curses module is that it doesn't offer the tputs() option as an alternative. But there are quite a lot of gaps in the curses module it's just that most folks don't use them so nobody complains or takes action to add them. I've been using curses (C and python) for nearly 30 years and this is the first time I've ever used the tiXXX functions, and it was mainly just out of curiosity rather than real need. -- 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 mgogala at yahoo.com Mon Jan 18 22:26:50 2021 From: mgogala at yahoo.com (Mladen Gogala) Date: Tue, 19 Jan 2021 03:26:50 +0000 (UTC) Subject: Python not Running References: Message-ID: On Sat, 16 Jan 2021 14:55:26 -0600, Logan Cranford wrote: > I downloaded Python but when I try to run Idle it says it is not found > and I should try to redownload it. When I try to do that all that comes > up is a page that says modify, repair or uninstall. I have repaired > several times but it still gives me the same message. Can anyone help > me with this? Have you tried with Perl? What is your OS and how are you trying to run it? I would suggest doing "sudo bash" and on the root prompt do this: dnf -y install python3 When you type "which python", your OS should tell you where your Python is: [mgogala at umajor tmp]$ which python /usr/bin/python You can further test by echoing Python version: [mgogala at umajor tmp]$ python -V Python 3.9.1 If you see something like C:\ prompt, then install Cygwin and use your Python from Cygwin. Your goal is have bash and vi editor. If that is an option, reformat your boot drive and install Ubuntu, Mint or Fedora. [mgogala at umajor tmp]$ cat /etc/redhat-release Fedora release 33 (Thirty Three) [mgogala at umajor tmp]$ Visual studio code is available both on Linux and Windows and is freaking awesome. No need to run Idle. Idle is a flint ax when compared to VSCode. VSCode supports auto-completion, formatting and many other things that you cannot even dream of in Idle. PS: Since you're most probably using Winduhs, use regedit and modify your PATH variable. Your python will be in c:\Program Files if you installed 64 bit version, which you should have done. Otherwise, it will be in C:\Program Files(x86). Your "idle" program will be in your "start menu" which came back in Winduhs 10. You would probably never have guessed, but I'm not particularly fond of Winduhs. -- Mladen Gogala Database Consultant http://mgogala.byethost5.com From Bischoop at vimart.net Mon Jan 18 22:45:45 2021 From: Bischoop at vimart.net (Bischoop) Date: Tue, 19 Jan 2021 03:45:45 -0000 (UTC) Subject: count consecutive elements References: Message-ID: On 2021-01-14, Stefan Ram wrote: > > If you want to know why, maybe you should insert print > statements to see the values of critical variables and > expression, especially in loops. > > Then compare the printed values with your expectations. > > Also, decompose into meaningful functions and test each > function separately. > > I sat to it again and solved it. import timeit run1 = ''' s = 'aabskaaaabadcccc' lil = tuple(set(s)) # list of characters in s li=[0,0,0,0,0,0] # list for counted repeats for i in lil: c = 0 h= lil.index(i) for letter in s: if letter == i: c += 1 if c > li[lil.index(letter)]: li[lil.index(letter)] = c else: c=0 continue m = max(li) for index, j in enumerate(li): if li[index] == m: print(f'{lil[index]} appears {m} consecutive times') ''' print(timeit.timeit(stmt=run1, number=1)) output: c appears 4 consecutive times a appears 4 consecutive times 0.00013008200039621443 From greg.ewing at canterbury.ac.nz Tue Jan 19 00:01:12 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 19 Jan 2021 18:01:12 +1300 Subject: Exploring terminfo In-Reply-To: References: <2c14f8fc-55d6-4d3f-bd46-9ef4e225acf7@www.fastmail.com> Message-ID: <4743b864-24c6-ab70-f5dc-e81c4bc8e112@canterbury.ac.nz> On 19/01/21 2:34 pm, Alan Gauld wrote: > To be fair that's a limitation of the C curses library. putp() is a > wrapper around tputs() even there, and you can't change what it does. > The gap in the curses module is that it doesn't offer the tputs() > option as an alternative. Seems to me it would be useful to have something that returns what tputs() would have output, as a string, so you can send it where you want. -- Greg From greg.ewing at canterbury.ac.nz Tue Jan 19 00:01:12 2021 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Tue, 19 Jan 2021 18:01:12 +1300 Subject: Exploring terminfo In-Reply-To: References: <2c14f8fc-55d6-4d3f-bd46-9ef4e225acf7@www.fastmail.com> Message-ID: <4743b864-24c6-ab70-f5dc-e81c4bc8e112@canterbury.ac.nz> On 19/01/21 2:34 pm, Alan Gauld wrote: > To be fair that's a limitation of the C curses library. putp() is a > wrapper around tputs() even there, and you can't change what it does. > The gap in the curses module is that it doesn't offer the tputs() > option as an alternative. Seems to me it would be useful to have something that returns what tputs() would have output, as a string, so you can send it where you want. -- Greg From __peter__ at web.de Tue Jan 19 03:51:16 2021 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Jan 2021 09:51:16 +0100 Subject: count consecutive elements In-Reply-To: References: Message-ID: On 19/01/2021 04:45, Bischoop wrote: > I sat to it again and solved it. Congratulations! > lil = tuple(set(s)) # list of characters in s > > li=[0,0,0,0,0,0] # list for counted repeats I see a minor problem here. What happens if s contains more than len(li) characters? > import timeit Since you seem interested in performance: imagine that the input is a very long string. Let's call the length N. How often do you iterate over its characters? How often does Tim's solution? From __peter__ at web.de Tue Jan 19 03:51:16 2021 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Jan 2021 09:51:16 +0100 Subject: count consecutive elements In-Reply-To: References: Message-ID: On 19/01/2021 04:45, Bischoop wrote: > I sat to it again and solved it. Congratulations! > lil = tuple(set(s)) # list of characters in s > > li=[0,0,0,0,0,0] # list for counted repeats I see a minor problem here. What happens if s contains more than len(li) characters? > import timeit Since you seem interested in performance: imagine that the input is a very long string. Let's call the length N. How often do you iterate over its characters? How often does Tim's solution? From Bischoop at vimart.net Tue Jan 19 04:42:09 2021 From: Bischoop at vimart.net (Bischoop) Date: Tue, 19 Jan 2021 09:42:09 -0000 (UTC) Subject: count consecutive elements References: Message-ID: On 2021-01-19, Peter Otten <__peter__ at web.de> wrote: > On 19/01/2021 04:45, Bischoop wrote: > >> I sat to it again and solved it. > > Congratulations! > > > lil = tuple(set(s)) # list of characters in s > > > > li=[0,0,0,0,0,0] # list for counted repeats > > I see a minor problem here. What happens if s contains more than len(li) > characters? > Thanks, I've created it when came to idea how to solve the problem and then forgot that part, will have to update it with two additional line of code. >> import timeit > > Since you seem interested in performance: imagine that the input is a > very long string. Let's call the length N. > > How often do you iterate over its characters? > Does it take time :-) I actually left it because seen guy in thread were comparing their time results, I'm pretty much aware that mine solution is time consuming and there are better ways to do it but I wanted to finish what I started without any additional libraries like itertools etc in the way that my knowledge allows. The idea with for this tuple just came up in a first seconds when I look at that and was not bothering about time or performance especially that later on as you seen I had different problem to solve and which took me quite a time and when I look at it today I think how couldn't I came with it earlier and let myself stuck on it. I'm happy that despite I've asked here I've finish it practically wthout additional help and yeah ( Thanks to Stefan who just pointed me to look at it from different prespective instead pointing what was wrong), I'll iterate here n = x [x for x in lil], with big string it can make difference. Now, when you asked me that question I came indeed for better idea to do this. One loop during which I can append character if not in lil. > How often does Tim's solution? oh here Im stuck and dont understand what you mean? -- Thanks From __peter__ at web.de Tue Jan 19 05:50:31 2021 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Jan 2021 11:50:31 +0100 Subject: count consecutive elements In-Reply-To: References: Message-ID: <44a0aa48-0ddc-7679-8d0b-ff08132a205f@web.de> On 19/01/2021 10:42, Bischoop wrote: > On 2021-01-19, Peter Otten <__peter__ at web.de> wrote: >> On 19/01/2021 04:45, Bischoop wrote: >> >>> I sat to it again and solved it. >> >> Congratulations! >> >>> lil = tuple(set(s)) # list of characters in s >>> >>> li=[0,0,0,0,0,0] # list for counted repeats >> >> I see a minor problem here. What happens if s contains more than len(li) >> characters? >> > > Thanks, I've created it when came to idea how to solve the problem and > then forgot that part, will have to update it with two additional line > of code. > >>> import timeit >> >> Since you seem interested in performance: imagine that the input is a >> very long string. Let's call the length N. >> >> How often do you iterate over its characters? >> > > Does it take time :-) I actually left it because seen guy in thread > were comparing their time results, I'm pretty much aware that mine > solution is time consuming and there are better ways to do it but > I wanted to finish what I started without any additional libraries > like itertools etc in the way that my knowledge allows. The idea with > for this tuple just came up in a first seconds when I look at that > and was not bothering about time or performance especially that later > on as you seen I had different problem to solve and which took me quite > a time and when I look at it today I think how couldn't I came with it > earlier and let myself stuck on it. > > I'm happy that despite I've asked here I've finish it practically wthout > additional help and yeah ( Thanks to Stefan who just pointed me to look > at it from different prespective instead pointing what was wrong), > I'll iterate here n = x [x for x in lil], with big string it can make > difference. Now, when you asked me that question I came indeed for better > idea to do this. One loop during which I can append character if not in lil. > >> How often does Tim's solution? > > oh here Im stuck and dont understand what you mean? [Tim Chase] > def consecutive_counter(seq): > # I'm not sure if there's something > # like this already in itertools > cur = nada = object() > count = 0 > for x in seq: > if x == cur: > count += 1 > else: > if cur is not nada: > yield cur, count > cur = x > count = 1 > if cur is not nada: > yield cur, count > > def longest(seq): > results = [] > biggest = 0 > for item, count in seq: > if count > biggest: > results = [item] > biggest = count > elif count == biggest: > results.append(item) > return results, biggest Tim's code iterates over the string once whereas you iterate multiple times. While this is mainly a question of elegance performance is affected when you have *nested* loops: > for i in lil: > c = 0 > h= lil.index(i) > for letter in s: If you are unlucky and run into a string with 1000 different characters the code in your inner loop will execute 1000*1000 times while Tim's will run 1000 times. This is called O(N*N) and O(N). Not all loops are obvious, > lil.index(letter) contains another loop, and you now have O(N*N*N) behavior. This is the worst case, usually the alphabet (li1) will be smaller, but avoiding nested loops when possible is still a good habit to get into. From __peter__ at web.de Tue Jan 19 05:50:31 2021 From: __peter__ at web.de (Peter Otten) Date: Tue, 19 Jan 2021 11:50:31 +0100 Subject: count consecutive elements In-Reply-To: References: Message-ID: <44a0aa48-0ddc-7679-8d0b-ff08132a205f@web.de> On 19/01/2021 10:42, Bischoop wrote: > On 2021-01-19, Peter Otten <__peter__ at web.de> wrote: >> On 19/01/2021 04:45, Bischoop wrote: >> >>> I sat to it again and solved it. >> >> Congratulations! >> >>> lil = tuple(set(s)) # list of characters in s >>> >>> li=[0,0,0,0,0,0] # list for counted repeats >> >> I see a minor problem here. What happens if s contains more than len(li) >> characters? >> > > Thanks, I've created it when came to idea how to solve the problem and > then forgot that part, will have to update it with two additional line > of code. > >>> import timeit >> >> Since you seem interested in performance: imagine that the input is a >> very long string. Let's call the length N. >> >> How often do you iterate over its characters? >> > > Does it take time :-) I actually left it because seen guy in thread > were comparing their time results, I'm pretty much aware that mine > solution is time consuming and there are better ways to do it but > I wanted to finish what I started without any additional libraries > like itertools etc in the way that my knowledge allows. The idea with > for this tuple just came up in a first seconds when I look at that > and was not bothering about time or performance especially that later > on as you seen I had different problem to solve and which took me quite > a time and when I look at it today I think how couldn't I came with it > earlier and let myself stuck on it. > > I'm happy that despite I've asked here I've finish it practically wthout > additional help and yeah ( Thanks to Stefan who just pointed me to look > at it from different prespective instead pointing what was wrong), > I'll iterate here n = x [x for x in lil], with big string it can make > difference. Now, when you asked me that question I came indeed for better > idea to do this. One loop during which I can append character if not in lil. > >> How often does Tim's solution? > > oh here Im stuck and dont understand what you mean? [Tim Chase] > def consecutive_counter(seq): > # I'm not sure if there's something > # like this already in itertools > cur = nada = object() > count = 0 > for x in seq: > if x == cur: > count += 1 > else: > if cur is not nada: > yield cur, count > cur = x > count = 1 > if cur is not nada: > yield cur, count > > def longest(seq): > results = [] > biggest = 0 > for item, count in seq: > if count > biggest: > results = [item] > biggest = count > elif count == biggest: > results.append(item) > return results, biggest Tim's code iterates over the string once whereas you iterate multiple times. While this is mainly a question of elegance performance is affected when you have *nested* loops: > for i in lil: > c = 0 > h= lil.index(i) > for letter in s: If you are unlucky and run into a string with 1000 different characters the code in your inner loop will execute 1000*1000 times while Tim's will run 1000 times. This is called O(N*N) and O(N). Not all loops are obvious, > lil.index(letter) contains another loop, and you now have O(N*N*N) behavior. This is the worst case, usually the alphabet (li1) will be smaller, but avoiding nested loops when possible is still a good habit to get into. From python at mrabarnett.plus.com Tue Jan 19 11:05:27 2021 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 19 Jan 2021 16:05:27 +0000 Subject: Python not Running In-Reply-To: References: Message-ID: On 2021-01-19 03:26, Mladen Gogala via Python-list wrote: [snip] > Since you're most probably using Winduhs, use regedit and modify your PATH > variable. Your python will be in c:\Program Files if you installed 64 bit > version, which you should have done. Otherwise, it will be in C:\Program > Files(x86). Your "idle" program will be in your "start menu" which came > back in Winduhs 10. You would probably never have guessed, but I'm not > particularly fond of Winduhs. > [snip] I wouldn't use regedit to edit the PATH variable. It's an environment variable, so I'd use the System Properties dialog (the Advanced tab). From grant.b.edwards at gmail.com Tue Jan 19 10:16:40 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Jan 2021 15:16:40 -0000 (UTC) Subject: Exploring terminfo References: <2c14f8fc-55d6-4d3f-bd46-9ef4e225acf7@www.fastmail.com> <4743b864-24c6-ab70-f5dc-e81c4bc8e112@canterbury.ac.nz> Message-ID: On 2021-01-19, Greg Ewing wrote: > On 19/01/21 2:34 pm, Alan Gauld wrote: >> To be fair that's a limitation of the C curses library. putp() is a >> wrapper around tputs() even there, and you can't change what it does. >> The gap in the curses module is that it doesn't offer the tputs() >> option as an alternative. > > Seems to me it would be useful to have something that returns > what tputs() would have output, as a string, so you can send it > where you want. I tried to do that using ctypes by passing tputs() a Python "putc" callback, but I couldn't get it to work (the callback never got called). -- Grant From grant.b.edwards at gmail.com Tue Jan 19 10:15:31 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Jan 2021 15:15:31 -0000 (UTC) Subject: Exploring terminfo References: <2c14f8fc-55d6-4d3f-bd46-9ef4e225acf7@www.fastmail.com> Message-ID: On 2021-01-19, Alan Gauld via Python-list wrote: > On 18/01/2021 22:14, Random832 wrote: >> On Fri, Jan 15, 2021, at 13:36, Alan Gauld via Python-list wrote: >>> That could make a big difference, the putp() function specifically >>> states that it writes to stdout. >> >> I think there is a reasonable argument that this is a deficiency of >> the curses module. >> >> I think that the curses module should .. >> B) expose a version of putp that uses pthon's stdout[.buffer].write >> rather than C's putchar. > > To be fair that's a limitation of the C curses library. putp() is a > wrapper around tputs() even there, and you can't change what it does. > The gap in the curses module is that it doesn't offer the tputs() > option as an alternative. If the curses module provided a tputs binding, then the user could write a useful putp(), or better yet a function that just does the padding and returns a new bytestring. > I've been using curses (C and python) for nearly 30 years and > this is the first time I've ever used the tiXXX functions, and it > was mainly just out of curiosity rather than real need. Same here. -- Grant From shurph at gmail.com Tue Jan 19 10:48:47 2021 From: shurph at gmail.com (Mikalai Saskavets) Date: Tue, 19 Jan 2021 18:48:47 +0300 Subject: PyConBY (Belarus) 2021 Online. Call for Proposals In-Reply-To: References: Message-ID: Hi All! I am on a program committee of the PyCon Belarus team. Our team is happy to announce that PyCon Belarus 2021 https://by.pycon.org/ will be held on March 13. We made it online and free for everyone. 500+ Python developers of all levels will join us remotely. Call for Proposals is now open and we are accepting submissions till February 12. Please find all the details about the CFP here: https://forms.gle/fNsJbwU53kjGhsrh8 Warmest regards, Mikalai Saskavets PyCon Belarus Program Committee Co-Chair Engineering Manager at iTechArt From * at eli.users.panix.com Tue Jan 19 16:54:47 2021 From: * at eli.users.panix.com (Eli the Bearded) Date: Tue, 19 Jan 2021 21:54:47 +0000 (UTC) Subject: Exploring terminfo References: Message-ID: In comp.lang.python, Greg Ewing wrote: > On 18/01/21 3:34 am, Alan Gauld wrote: >> The problem is terminfo is not really part of curses. >> Curses is built on top of terminfo. > As far as I can tell from the man pages, terminfo itself > is just a file format. The only programmatic interfaces I > can find for it *are* part of curses: Putting my Unix hat on, curses is a "friendly" library around creating text-windowed applications. Programs like mutt use curses rather than raw terminal operations, programs like vi use raw terminal operations. Either curses or raw terminal operations will (should) consult a terminal capabilities database to figure out what can be done and how to do it. The two competing database formats for that are termcap and terminfo, where terminfo is the newer, better one. Termcap used a single large text file for all terminals types. Terminfo uses a directory tree full of small files, one per type. I'm pretty sure both include the ability to say something along the lines of "start with this one terminal, and then change these bits". So that starts to get complicated without a library. Or maybe I'm wrong, and vi uses curses. I'm not really sure how vi reads the term info files. Okay, checking the source to the only vi I have lying around[*], it uses a few curses calls, apparently only these: int tgetent(char *bp, const char *name); int tgetflag(char *id); int tgetnum(char *id); char *tgetstr(char *id, char **area); char *tgoto(const char *cap, int col, int row); int tputs(const char *str, int affcnt, int (*putc)(int)); My local manpage calles this set the "direct curses interface to the terminfo capability database" whereas things I think of as "curses" programs use calls like: WINDOW *initscr(void); int cbreak(void); int start_color(void); int noecho(void); int move(int y, int x); int attr_set(attr_t attrs, short pair, void *opts); int getch(void); int addch(const chtype ch); int printw(const char *fmt, ...); The vi method relies on the programmer knowing what attributes are wanted and how to use them, and how to use alternatives when the first choices aren't provided. The curses method relies on the programmer knowing which of a hundred different library functions to use for any given output. :^) [*] It's ex-1.1, an "heirloom" source package that has possibly been brushed up just enough to compile on a modern system. ex-1.1 is by most reckoning, the first vi. It won't start in vi mode though, you need to run ex, then begin the visual mode. It is recongizable as vi to me, but a somewhat different experience. Elijah ------ has modified C curses programs, but not written one from scratch From grant.b.edwards at gmail.com Tue Jan 19 17:42:26 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Jan 2021 22:42:26 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-19, Eli the Bearded <*@eli.users.panix.com> wrote: > Putting my Unix hat on, curses is a "friendly" library around creating > text-windowed applications. Programs like mutt use curses rather than > raw terminal operations, programs like vi use raw terminal operations. > Either curses or raw terminal operations will (should) consult a > terminal capabilities database to figure out what can be done and how to > do it. The two competing database formats for that are termcap and > terminfo, where terminfo is the newer, better one. Back in the day, weren't the termcap/terminfo libraries maintained and installed seperately from curses? I would have sworn that only a few years ago terminfo and ncurses libraries were seperate -- though recently both were provided by ncurses, IIRC. [...] > Okay, checking the source to the only vi I have lying around[*], it uses > a few curses calls, apparently only these: > > int tgetent(char *bp, const char *name); > int tgetflag(char *id); > int tgetnum(char *id); > char *tgetstr(char *id, char **area); > char *tgoto(const char *cap, int col, int row); > int tputs(const char *str, int affcnt, int (*putc)(int)); In my mind, those are curses library calls, they're termcap/terminfo library calls. [I can't recall whether terminfo and termcap APIs were compatible or not.] > My local manpage calles this set the "direct curses interface to the > terminfo capability database" whereas things I think of as "curses" > programs use calls like: > > WINDOW *initscr(void); > int cbreak(void); > int start_color(void); > int noecho(void); > int move(int y, int x); > int attr_set(attr_t attrs, short pair, void *opts); > int getch(void); > int addch(const chtype ch); > int printw(const char *fmt, ...); Exactly. _Those_ are curses library calls. -- Grant From grant.b.edwards at gmail.com Tue Jan 19 18:24:22 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 19 Jan 2021 23:24:22 -0000 (UTC) Subject: Exploring terminfo References: Message-ID: On 2021-01-19, Grant Edwards wrote: >> >> int tgetent(char *bp, const char *name); >> int tgetflag(char *id); >> int tgetnum(char *id); >> char *tgetstr(char *id, char **area); >> char *tgoto(const char *cap, int col, int row); >> int tputs(const char *str, int affcnt, int (*putc)(int)); > > In my mind, those are curses library calls, they're termcap/terminfo aren't curses Sorry about that... From mrd at redhat.com Tue Jan 19 20:07:54 2021 From: mrd at redhat.com (Matt Davis) Date: Tue, 19 Jan 2021 17:07:54 -0800 Subject: [ANN] PyYAML-5.4 Released Message-ID: ===================== Announcing PyYAML-5.4 ===================== A new release of PyYAML is now available: https://github.com/yaml/pyyaml/releases/tag/5.4 This release contains a security fix for CVE-2020-14343. It removes the python/module, python/object, and python/object/new tags from the FullLoader. YAML that uses these tags must be loaded by UnsafeLoader, or a custom loader that has explicitly enabled them. This release also adds Python wheels for manylinux1 (x86_64) and MacOS (x86_64) with the libyaml extension included (built on libyaml 0.2.5). PyYAML 5.4 will be the last release to support Python 2.7 (except for possible critical bug fix releases). Changes ======= * https://github.com/yaml/pyyaml/pull/407 -- build modernization, remove distutils, fix metadata, build wheels, CI to GHA * https://github.com/yaml/pyyaml/pull/472 -- fix for CVE-2020-14343, moves arbitrary python tags to UnsafeLoader * https://github.com/yaml/pyyaml/pull/441 -- fix memory leak in implicit resolver setup * https://github.com/yaml/pyyaml/pull/392 -- fix py2 copy support for timezone objects * https://github.com/yaml/pyyaml/pull/378 -- fix compatibility with Jython Resources ========= PyYAML IRC Channel: #pyyaml on irc.freenode.net PyYAML homepage: https://github.com/yaml/pyyaml PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation Source and binary installers: https://pypi.org/project/PyYAML/ GitHub repository: https://github.com/yaml/pyyaml/ Bug tracking: https://github.com/yaml/pyyaml/issues YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML ============ YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistence. Example ======= ``` >>> import yaml >>> yaml.full_load(""" ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: https://github.com/yaml/pyyaml ... keywords: [YAML, serialization, configuration, persistence, pickle] ... """) {'keywords': ['YAML', 'serialization', 'configuration', 'persistence', 'pickle'], 'homepage': 'https://github.com/yaml/pyyaml', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} >>> print(yaml.dump(_)) name: PyYAML homepage: https://github.com/yaml/pyyaml description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistence, pickle] ``` Maintainers =========== The following people are currently responsible for maintaining PyYAML: * Ingy d?t Net * Matt Davis and many thanks to all who have contributed! See: https://github.com/yaml/pyyaml/pulls Copyright ========= Copyright (c) 2017-2021 Ingy d?t Net Copyright (c) 2006-2016 Kirill Simonov The PyYAML module was written by Kirill Simonov . It is currently maintained by the YAML and Python communities. PyYAML is released under the MIT license. See the file LICENSE for more details. From samuelmarks at gmail.com Tue Jan 19 22:05:15 2021 From: samuelmarks at gmail.com (Samuel Marks) Date: Wed, 20 Jan 2021 14:05:15 +1100 Subject: Force Python ast to emit lines no longer than $length Message-ID: I've written a library that works at the ast level. Sometimes the generated output goes over the linter line length limit. "foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz" How do I generate this kind of code instead? "foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_" "foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz" (also happy with the \ and parenthesised variants) [cross-posted: stackoverflow.com/q/65800797] The only thing I can think of doing?retaining support for 3.6, 3.7, 3.8, 3.9, and 3.10a4?is to contribute to both astor and the builtin ast.unparse? From mgogala at yahoo.com Wed Jan 20 00:14:04 2021 From: mgogala at yahoo.com (Mladen Gogala) Date: Wed, 20 Jan 2021 05:14:04 +0000 (UTC) Subject: open sentinel-2image python References: <59b289d3-31af-4da4-a52c-d72fcd87ee3en@googlegroups.com> <2b5b4ba0-d16e-f85c-3b8b-0c3981774a54@mrabarnett.plus.com> Message-ID: On Sun, 17 Jan 2021 18:01:26 +0000, MRAB wrote: > On 2021-01-17 13:57, Karsten Hilbert wrote: >> Am Sun, Jan 17, 2021 at 02:20:24AM -0800 schrieb omid mohammadi: >> >>> When I open the sentinel-2 image in Python, I get the following error: >>> >>> MemoryError: Unable to allocate 115. MiB for an array with shape >>> (5490, 5490) and data type float32 >>> >>> How can I fix it? >> >> You can install more RAM. >> > Or maybe the OP is running 32-bit Python but the code needs >2GB. If > that's the case then using 64-bit Python might fix it, assuming that > it's a 64-bit machine. Or there may be an OS limitation on the size of the address space. I would check the OS log first, then do "ulimit -a". If there are sar or vmstat on the system, I would definitely use them. Running out of memory is an OS error and should be checked on the OS level. -- Mladen Gogala Database Consultant http://mgogala.byethost5.com From mgogala at yahoo.com Wed Jan 20 00:40:16 2021 From: mgogala at yahoo.com (Mladen Gogala) Date: Wed, 20 Jan 2021 05:40:16 +0000 (UTC) Subject: Issues with running python in Command prompt References: Message-ID: On Sat, 16 Jan 2021 19:00:06 +0330, mohsen shooshtari wrote: > hello, > Thanks in advance for your consideration. I install python3.8 and then > install Pycharm but when I call python in Command prompt, followed by ( > 'python' > is not recognized as an internal or external command, operable program > or batch file. > > what should I do to fix this problem? Make sure that OS recognizes it as a command. That usually means putting the directory where your Python resides into the path. I generally advise using Cygwin and installing the Cygwin version of Python. Your OS will look like a POSIX compatible system, and you will be able to use Unix/ Linux tools like bash, less. vi, awk, grep and alike. You will also be able to use "/" as a directory separator which is really helpful when it comes to regular expressions. Another option is to install Ubuntu on top of your Windows 10. I am no fan of Ubuntu but it's still much better than Windows. All scripting languages (PHP, Perl, Python, Go and JavaScript to mention only the most popular ones) are all written with Linux/Unix in mind. There are Windows ports but using the Linux or Cygwin version is typically much easier and more natural. -- Mladen Gogala Database Consultant https://dbwhisperer.wordpress.com From nulla.epistola at web.de Wed Jan 20 10:21:56 2021 From: nulla.epistola at web.de (Sibylle Koczian) Date: Wed, 20 Jan 2021 16:21:56 +0100 Subject: Python not Running In-Reply-To: <9m2e0ghjo0cijmstt5gbbrj8crvjbmafls@4ax.com> References: <9m2e0ghjo0cijmstt5gbbrj8crvjbmafls@4ax.com> Message-ID: Am 19.01.2021 um 17:48 schrieb Dennis Lee Bieber: > On Tue, 19 Jan 2021 03:26:50 +0000 (UTC), Mladen Gogala via Python-list > declaimed the following: > >> Since you're most probably using Winduhs, use regedit and modify your PATH > > You don't need to use regedit to modify environment variables. > > Right click "This PC" (Win10), Properties, Advance System Settings > (respond to UAC prompt), [Environment Variables] > > This presents a window with "user" (the admin account being used after > the UAC authorization) and "system" which are the environment variables > that apply to all users. > > To change regular user environment variables, open old-style control > panel, drill down in "User Accounts" until your get to your account, and > there will be an option on the left for editing environment variables. > > It's not necessary to have Python in the path - it may perhaps be a little more comfortable, but not much. The file extensions .py and .pyw can be associated with python and pythonw, there is the Python Launcher, and for things like pip you can always change into your Python directory. But pip works just as well with the Launcher. From nulla.epistola at web.de Wed Jan 20 10:21:56 2021 From: nulla.epistola at web.de (Sibylle Koczian) Date: Wed, 20 Jan 2021 16:21:56 +0100 Subject: Python not Running In-Reply-To: <9m2e0ghjo0cijmstt5gbbrj8crvjbmafls@4ax.com> References: <9m2e0ghjo0cijmstt5gbbrj8crvjbmafls@4ax.com> Message-ID: Am 19.01.2021 um 17:48 schrieb Dennis Lee Bieber: > On Tue, 19 Jan 2021 03:26:50 +0000 (UTC), Mladen Gogala via Python-list > declaimed the following: > >> Since you're most probably using Winduhs, use regedit and modify your PATH > > You don't need to use regedit to modify environment variables. > > Right click "This PC" (Win10), Properties, Advance System Settings > (respond to UAC prompt), [Environment Variables] > > This presents a window with "user" (the admin account being used after > the UAC authorization) and "system" which are the environment variables > that apply to all users. > > To change regular user environment variables, open old-style control > panel, drill down in "User Accounts" until your get to your account, and > there will be an option on the left for editing environment variables. > > It's not necessary to have Python in the path - it may perhaps be a little more comfortable, but not much. The file extensions .py and .pyw can be associated with python and pythonw, there is the Python Launcher, and for things like pip you can always change into your Python directory. But pip works just as well with the Launcher. From torriem at gmail.com Wed Jan 20 10:33:40 2021 From: torriem at gmail.com (Michael Torrie) Date: Wed, 20 Jan 2021 08:33:40 -0700 Subject: Issues with running python in Command prompt In-Reply-To: References: Message-ID: On 1/19/21 10:40 PM, Mladen Gogala via Python-list wrote: > I generally advise > using Cygwin and installing the Cygwin version of Python. Your OS will > look like a POSIX compatible system, and you will be able to use Unix/ > Linux tools like bash, less. vi, awk, grep and alike. You will also be > able to use "/" as a directory separator which is really helpful when it > comes to regular expressions. I've used cygwin for many years. I would not use cygin if I were the OP. This is probably for more advanced users with particular needs. I recommend sticking to the official windows version of Python, and following the detailed instructions on the web page Mats Wichmann referred to. You can use escape characters in regular expression on any platform Python runs on. Python has a whole host of features to deal with the directory separator differences on Windows vs everybody else. From cnweike at gmail.com Wed Jan 20 14:54:39 2021 From: cnweike at gmail.com (panfei) Date: Wed, 20 Jan 2021 11:54:39 -0800 (PST) Subject: sqlite3 cannot detect the version of compiled sqlite version at some point in runtime. Message-ID: System environment: Cent OS 7 Sqlite3 3.34.0 (Compile from source) Python 3.9.1 (Compile from source) Django 3.1.5 (Pip install) 1. Compile sqlite3: ./configure --prefix=/home/felix/.local/sqlite/sqlite-3.34.0 make && make install 2. Add sqlite3 lib to lib search path: export LD_LIBRARY_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/lib export LD_RUN_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/lib 3. Compile Python 3.9.1 C_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ LD_RUN_PATH=/home/felix/.local/sqlite/default/lib ./configure --prefix=/home/felix/.local/python/python-3.9.1 --enable-optimizations make && make install 4. Test sqlite3 Python 3.9.1 (default, Jan 20 2021, 14:32:50) [GCC 10.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> conn = sqlite3.connect(':memory:') >>> conn.create_function('f', 2, lambda *args: None, deterministic=True) Traceback (most recent call last): File "", line 1, in sqlite3.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher >>> sqlite3.sqlite_version '3.34.0' >>> sqlite3.version '2.6.0' >>> It reports "deterministic=True requires SQLite 3.8.3 or higher", but when execute sqlite3.sqlite_version it returns 3.34.0 which higher than 3.8.3. Is there any advice on this issue? thanks. From ben.usenet at bsb.me.uk Wed Jan 20 15:09:46 2021 From: ben.usenet at bsb.me.uk (Ben Bacarisse) Date: Wed, 20 Jan 2021 20:09:46 +0000 Subject: sqlite3 cannot detect the version of compiled sqlite version at some point in runtime. References: Message-ID: <87o8hj2wvp.fsf@bsb.me.uk> panfei writes: > 4. Test sqlite3 > Python 3.9.1 (default, Jan 20 2021, 14:32:50) > [GCC 10.2.0] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import sqlite3 >>>> conn = sqlite3.connect(':memory:') >>>> conn.create_function('f', 2, lambda *args: None, deterministic=True) > Traceback (most recent call last): > File "", line 1, in > sqlite3.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher >>>> sqlite3.sqlite_version > '3.34.0' >>>> sqlite3.version > '2.6.0' >>>> > > It reports "deterministic=True requires SQLite 3.8.3 or higher", but > when execute sqlite3.sqlite_version it returns 3.34.0 which higher > than 3.8.3. > > Is there any advice on this issue? thanks. Sorry, no, but I can add a data point. It works for me on my Ubuntu system with these versions: $ python3 Python 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> sqlite3.sqlite_version '3.31.1' >>> sqlite3.version '2.6.0' >>> conn = sqlite3.connect(':memory:') >>> conn.create_function('f', 2, lambda *args: None, deterministic=True) >>> -- Ben. From random832 at fastmail.com Wed Jan 20 16:45:54 2021 From: random832 at fastmail.com (Random832) Date: Wed, 20 Jan 2021 16:45:54 -0500 Subject: =?UTF-8?Q?Re:_sqlite3_cannot_detect_the_version_of_compiled_sqlite_versi?= =?UTF-8?Q?on_at_some_point_in_runtime.?= In-Reply-To: References: Message-ID: <12a307a2-e2ee-451d-bf2f-eee320629840@www.fastmail.com> On Wed, Jan 20, 2021, at 14:54, panfei wrote: > 3. Compile Python 3.9.1 > C_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ > CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ > LD_RUN_PATH=/home/felix/.local/sqlite/default/lib ./configure > --prefix=/home/felix/.local/python/python-3.9.1 --enable-optimizations > make && make install How *exactly* did you compile python? i.e. what specific commands, to make it pick up those include paths? Because from the symptoms you are reporting, it sounds like it was not compiled against the correct version of sqlite. From barry at barrys-emacs.org Wed Jan 20 16:53:16 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 20 Jan 2021 21:53:16 +0000 Subject: sqlite3 cannot detect the version of compiled sqlite version at some point in runtime. In-Reply-To: References: Message-ID: <3DD6F30B-924B-467D-8D21-3339FC291333@barrys-emacs.org> > On 20 Jan 2021, at 19:54, panfei wrote: > > System environment: > > Cent OS 7 > Sqlite3 3.34.0 (Compile from source) > Python 3.9.1 (Compile from source) > Django 3.1.5 (Pip install) > > > 1. Compile sqlite3: > ./configure --prefix=/home/felix/.local/sqlite/sqlite-3.34.0 > make && make install > > 2. Add sqlite3 lib to lib search path: > > export LD_LIBRARY_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/lib > export LD_RUN_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/lib > > 3. Compile Python 3.9.1 > C_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ LD_RUN_PATH=/home/felix/.local/sqlite/default/lib ./configure --prefix=/home/felix/.local/python/python-3.9.1 --enable-optimizations > make && make install > > 4. Test sqlite3 > Python 3.9.1 (default, Jan 20 2021, 14:32:50) > [GCC 10.2.0] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import sqlite3 >>>> conn = sqlite3.connect(':memory:') >>>> conn.create_function('f', 2, lambda *args: None, deterministic=True) > Traceback (most recent call last): > File "", line 1, in > sqlite3.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher >>>> sqlite3.sqlite_version > '3.34.0' >>>> sqlite3.version > '2.6.0' >>>> > > It reports "deterministic=True requires SQLite 3.8.3 or higher", but when execute sqlite3.sqlite_version it returns 3.34.0 which higher than 3.8.3. > > Is there any advice on this issue? thanks. My guess is that at runtime the systems old sqlite3 is used and not your new one. is LD_LIBRARY_PATH setup correctly when you run python3.9? You can check this by doing the following: $ gdb python3.9 (gdb) run >>> import sqlite3 Ctrl-C (gdb) info shared Below is that I get on a Fedora 33 system by way of example output: $ gdb python3.9 GNU gdb (GDB) Fedora 10.1-2.fc33 Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from python3.9... Reading symbols from .gnu_debugdata for /usr/bin/python3.9... (No debugging symbols found in .gnu_debugdata for /usr/bin/python3.9) Missing separate debuginfos, use: dnf debuginfo-install python3-3.9.1-1.fc33.x86_64 (gdb) run Starting program: /usr/bin/python3.9 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Python 3.9.1 (default, Dec 8 2020, 00:00:00) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> Program received signal SIGINT, Interrupt. 0x00007ffff7b7ff4a in select () from /lib64/libc.so.6 (gdb) i sh From To Syms Read Shared Object Library 0x00007ffff7fd2090 0x00007ffff7ff2f96 Yes (*) /lib64/ld-linux-x86-64.so.2 0x00007ffff7caed30 0x00007ffff7e58c7d Yes (*) /lib64/libpython3.9.so.1.0 0x00007ffff7aad690 0x00007ffff7bfa69d Yes (*) /lib64/libc.so.6 0x00007ffff7a6ca90 0x00007ffff7a7b125 Yes (*) /lib64/libpthread.so.0 0x00007ffff7a60270 0x00007ffff7a611c9 Yes (*) /lib64/libdl.so.2 0x00007ffff7a5a3f0 0x00007ffff7a5adb0 Yes (*) /lib64/libutil.so.1 0x00007ffff79223d0 0x00007ffff79bd718 Yes (*) /lib64/libm.so.6 0x00007ffff7fbca50 0x00007ffff7fbe310 Yes (*) /usr/lib64/python3.9/lib-dynload/readline.cpython-39-x86_64-linux-gnu.so 0x00007fffea1dc270 0x00007fffea204587 Yes (*) /lib64/libreadline.so.8 0x00007fffea1a3470 0x00007fffea1afb8c Yes (*) /lib64/libtinfo.so.6 0x00007fffea22ba70 0x00007fffea2316ef Yes (*) /usr/lib64/python3.9/lib-dynload/math.cpython-39-x86_64-linux-gnu.so 0x00007fffea13ead0 0x00007fffea149d8c Yes (*) /usr/lib64/python3.9/lib-dynload/_datetime.cpython-39-x86_64-linux-gnu.so 0x00007ffff7fb2170 0x00007ffff7fb318b Yes (*) /usr/lib64/python3.9/lib-dynload/_heapq.cpython-39-x86_64-linux-gnu.so 0x00007fffea128510 0x00007fffea1308ee Yes (*) /usr/lib64/python3.9/lib-dynload/_sqlite3.cpython-39-x86_64-linux-gnu.so 0x00007fffe9fd79b0 0x00007fffea0c7024 Yes (*) /lib64/libsqlite3.so.0 0x00007fffe9fb05f0 0x00007fffe9fbdb2b Yes (*) /lib64/libz.so.1 (*): Shared library is missing debugging information. (gdb) You can see that the python module is: /usr/lib64/python3.9/lib-dynload/_sqlite3.cpython-39-x86_64-linux-gnu.so and that libsqlite3 comes from: /lib64/libsqlite3.so.0 Barry > -- > https://mail.python.org/mailman/listinfo/python-list > From random832 at fastmail.com Wed Jan 20 16:57:03 2021 From: random832 at fastmail.com (Random832) Date: Wed, 20 Jan 2021 16:57:03 -0500 Subject: =?UTF-8?Q?Re:_sqlite3_cannot_detect_the_version_of_compiled_sqlite_versi?= =?UTF-8?Q?on_at_some_point_in_runtime.?= In-Reply-To: <12a307a2-e2ee-451d-bf2f-eee320629840@www.fastmail.com> References: <12a307a2-e2ee-451d-bf2f-eee320629840@www.fastmail.com> Message-ID: On Wed, Jan 20, 2021, at 16:45, Random832 wrote: > On Wed, Jan 20, 2021, at 14:54, panfei wrote: > > 3. Compile Python 3.9.1 > > C_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ > > CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ > > LD_RUN_PATH=/home/felix/.local/sqlite/default/lib ./configure > > --prefix=/home/felix/.local/python/python-3.9.1 --enable-optimizations > > make && make install > > How *exactly* did you compile python? i.e. what specific commands, to > make it pick up those include paths? Because from the symptoms you are > reporting, it sounds like it was not compiled against the correct > version of sqlite. Oh, sorry, I missed "./configure" on that line. So, it looks like you had the environment variables set when you ran configure, but not make. I don't think this is a common way to set include paths, by the way. The usual way is with pkg-config, but I'm not sure how to add your .local sqlite directory to it. Does your sqlite installation include a file called "sqlite3.pc"? If so, try adding the directory containing it to PKG_CONFIG_PATH when running configure. If not... well, export the environment variables or add them when running make and hope for the best From mrd at redhat.com Wed Jan 20 17:13:48 2021 From: mrd at redhat.com (Matt Davis) Date: Wed, 20 Jan 2021 14:13:48 -0800 Subject: [ANN] PyYAML-5.4.1 Released Message-ID: ======================= Announcing PyYAML-5.4.1 ======================= A new release of PyYAML is now available: https://github.com/yaml/pyyaml/releases/tag/5.4.1 This release contains a fix for AttributeError during module import in some mixed version installations. PyYAML 5.4.1 will be the last release to support Python 2.7 (except for possible critical bug fix releases). Changes ======= * https://github.com/yaml/pyyaml/pull/480 -- Fix stub compat with older pyyaml versions that may unwittingly load it Resources ========= PyYAML IRC Channel: #pyyaml on irc.freenode.net PyYAML homepage: https://github.com/yaml/pyyaml PyYAML documentation: http://pyyaml.org/wiki/PyYAMLDocumentation Source and binary installers: https://pypi.org/project/PyYAML/ GitHub repository: https://github.com/yaml/pyyaml/ Bug tracking: https://github.com/yaml/pyyaml/issues YAML homepage: http://yaml.org/ YAML-core mailing list: http://lists.sourceforge.net/lists/listinfo/yaml-core About PyYAML ============ YAML is a data serialization format designed for human readability and interaction with scripting languages. PyYAML is a YAML parser and emitter for Python. PyYAML features a complete YAML 1.1 parser, Unicode support, pickle support, capable extension API, and sensible error messages. PyYAML supports standard YAML tags and provides Python-specific tags that allow to represent an arbitrary Python object. PyYAML is applicable for a broad range of tasks from complex configuration files to object serialization and persistence. Example ======= ``` >>> import yaml >>> yaml.full_load(""" ... name: PyYAML ... description: YAML parser and emitter for Python ... homepage: https://github.com/yaml/pyyaml ... keywords: [YAML, serialization, configuration, persistence, pickle] ... """) {'keywords': ['YAML', 'serialization', 'configuration', 'persistence', 'pickle'], 'homepage': 'https://github.com/yaml/pyyaml', 'description': 'YAML parser and emitter for Python', 'name': 'PyYAML'} >>> print(yaml.dump(_)) name: PyYAML homepage: https://github.com/yaml/pyyaml description: YAML parser and emitter for Python keywords: [YAML, serialization, configuration, persistence, pickle] ``` Maintainers =========== The following people are currently responsible for maintaining PyYAML: * Ingy d?t Net * Matt Davis and many thanks to all who have contributed! See: https://github.com/yaml/pyyaml/pulls Copyright ========= Copyright (c) 2017-2021 Ingy d?t Net Copyright (c) 2006-2016 Kirill Simonov The PyYAML module was written by Kirill Simonov . It is currently maintained by the YAML and Python communities. PyYAML is released under the MIT license. See the file LICENSE for more details. From mgogala at yahoo.com Wed Jan 20 21:10:44 2021 From: mgogala at yahoo.com (Mladen Gogala) Date: Thu, 21 Jan 2021 02:10:44 +0000 (UTC) Subject: Issues with running python in Command prompt References: Message-ID: On Wed, 20 Jan 2021 08:33:40 -0700, Michael Torrie wrote: > You can use escape characters in regular expression on any platform > Python runs on. Python has a whole host of features to deal with the > directory separator differences on Windows vs everybody else. I am probably slightly biased. I am an old Unix hack who has learned Perl4 in the early 90's and was using it until 2019 when I was told that Perl is not an approved language in the company and that I have to learn Python. So I did. I was a VAX/VMS system admin and instructor from 1987 - 1996. After 1993 I was working for a SGI distributor, using Irix. I have worked with HP-UX, AIX, AT&T Unix, Wyse Unix, SCO Unix and, eventually, Linux, among other things. I might be slightly biased against Windows. -- Mladen Gogala Database Consultant https://dbwhisperer.wordpress.com From cnweike at gmail.com Wed Jan 20 21:43:50 2021 From: cnweike at gmail.com (panfei) Date: Wed, 20 Jan 2021 18:43:50 -0800 (PST) Subject: sqlite3 cannot detect the version of compiled sqlite version at some point in runtime. In-Reply-To: References: <3DD6F30B-924B-467D-8D21-3339FC291333@barrys-emacs.org> Message-ID: HI Barry, Thanks for the suggestions, this is my output: [felix at localhost Downloads]$ gdb /home/felix/.local/python/python-3.9.1/bin/python3 GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /home/felix/.local/python/python-3.9.1/bin/python3.9...done. (gdb) run Starting program: /home/felix/.local/python/python-3.9.1/bin/python3 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Python 3.9.1 (default, Jan 21 2021, 02:04:50) [GCC 10.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> Program received signal SIGINT, Interrupt. 0x00007ffff6a15983 in __select_nocancel () from /lib64/libc.so.6 Missing separate debuginfos, use: debuginfo-install glibc-2.17-317.el7.x86_64 ncurses-libs-5.9-14.20130511.el7_4.x86_64 nss-softokn-freebl-3.53.1-6.el7_9.x86_64 readline-6.2-11.el7.x86_64 zlib-1.2.7-18.el7.x86_64 (gdb) info shared >From To Syms Read Shared Object Library 0x00007ffff7ddbaf0 0x00007ffff7df7060 Yes (*) /lib64/ld-linux-x86-64.so.2 0x00007ffff78af410 0x00007ffff7a7fd82 Yes /home/felix/.local/python/python-3.9.1/lib/libpython3.9.so.1.0 0x00007ffff7613e30 0x00007ffff7618cec Yes (*) /lib64/libcrypt.so.1 0x00007ffff73fc8f0 0x00007ffff7407db1 Yes (*) /lib64/libpthread.so.0 0x00007ffff71f3e50 0x00007ffff71f494e Yes (*) /lib64/libdl.so.2 0x00007ffff6ff0e90 0x00007ffff6ff17a4 Yes (*) /lib64/libutil.so.1 0x00007ffff6cf3350 0x00007ffff6d5e316 Yes (*) /lib64/libm.so.6 0x00007ffff693f9f0 0x00007ffff6a8f9cf Yes (*) /lib64/libc.so.6 0x00007ffff671db80 0x00007ffff671e1fb Yes (*) /lib64/libfreebl3.so 0x00007fffeffd50b0 0x00007fffeffd6952 Yes /home/felix/.local/python/python-3.9.1/lib/python3.9/lib-dynload/readline.cpython-39-x86_64-linux-gnu.so 0x00007fffefda0de0 0x00007fffefdbf775 Yes (*) /lib64/libreadline.so.6 0x00007fffefb6ee40 0x00007fffefb7abb8 Yes (*) /lib64/libtinfo.so.5 0x00007fffef9557c0 0x00007fffef95c9b2 Yes /home/felix/.local/python/python-3.9.1/lib/python3.9/lib-dynload/math.cpython-39-x86_64-linux-gnu.so 0x00007fffef6f4cd0 0x00007fffef7080b8 Yes /home/felix/.local/python/python-3.9.1/lib/python3.9/lib-dynload/_datetime.cpython-39-x86_64-linux-gnu.so 0x00007fffef4e8c40 0x00007fffef4ebd13 Yes /home/felix/.local/python/python-3.9.1/lib/python3.9/lib-dynload/_heapq.cpython-39-x86_64-linux-gnu.so 0x00007fffef2d7180 0x00007fffef2e08ba Yes /home/felix/.local/python/python-3.9.1/lib/python3.9/lib-dynload/_sqlite3.cpython-39-x86_64-linux-gnu.so 0x00007fffeefadf00 0x00007fffef096c00 Yes /home/felix/.local/sqlite/default/lib/libsqlite3.so.0 0x00007fffeed8b110 0x00007fffeed97698 Yes (*) /lib64/libz.so.1 (*): Shared library is missing debugging information. (gdb) I created a symbol link to specific version of sqlite3 and set LD_LIBRARY_PATH: [felix at localhost sqlite]$ ll total 0 lrwxrwxrwx 1 felix felix 6 Feb 18 2020 default -> latest lrwxrwxrwx 1 felix felix 13 Jan 20 12:51 latest -> sqlite-3.34.0 drwxrwxr-x 6 felix felix 52 Feb 18 2020 sqlite-3.31.1 drwxrwxr-x 6 felix felix 52 Jan 20 12:51 sqlite-3.34.0 [felix at localhost sqlite]$ pwd /home/felix/.local/sqlite [felix at localhost sqlite]$ env | grep LD_ LD_LIBRARY_PATH=/home/felix/.local/mpfr/default/lib/:/home/felix/.local/gmp/default/lib/:/home/felix/.local/mpc/default/lib/:/home/felix/.local/sqlite/default/lib:/home/felix/.local/mysql/default/lib LD_RUN_PATH=/home/felix/.local/sqlite/default/lib ? 2021?1?21???? UTC+8 ??5:53:38? ??? > > On 20 Jan 2021, at 19:54, panfei wrote: > > > > System environment: > > > > Cent OS 7 > > Sqlite3 3.34.0 (Compile from source) > > Python 3.9.1 (Compile from source) > > Django 3.1.5 (Pip install) > > > > > > 1. Compile sqlite3: > > ./configure --prefix=/home/felix/.local/sqlite/sqlite-3.34.0 > > make && make install > > > > 2. Add sqlite3 lib to lib search path: > > > > export LD_LIBRARY_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/lib > > export LD_RUN_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/lib > > > > 3. Compile Python 3.9.1 > > C_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ LD_RUN_PATH=/home/felix/.local/sqlite/default/lib ./configure --prefix=/home/felix/.local/python/python-3.9.1 --enable-optimizations > > make && make install > > > > 4. Test sqlite3 > > Python 3.9.1 (default, Jan 20 2021, 14:32:50) > > [GCC 10.2.0] on linux > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import sqlite3 > >>>> conn = sqlite3.connect(':memory:') > >>>> conn.create_function('f', 2, lambda *args: None, deterministic=True) > > Traceback (most recent call last): > > File "", line 1, in > > sqlite3.NotSupportedError: deterministic=True requires SQLite 3.8.3 or higher > >>>> sqlite3.sqlite_version > > '3.34.0' > >>>> sqlite3.version > > '2.6.0' > >>>> > > > > It reports "deterministic=True requires SQLite 3.8.3 or higher", but when execute sqlite3.sqlite_version it returns 3.34.0 which higher than 3.8.3. > > > > Is there any advice on this issue? thanks. > My guess is that at runtime the systems old sqlite3 is used and not your new one. > is LD_LIBRARY_PATH setup correctly when you run python3.9? > > You can check this by doing the following: > > $ gdb python3.9 > (gdb) run > >>> import sqlite3 > Ctrl-C > (gdb) info shared > > Below is that I get on a Fedora 33 system by way of example output: > > $ gdb python3.9 > GNU gdb (GDB) Fedora 10.1-2.fc33 > Copyright (C) 2020 Free Software Foundation, Inc. > License GPLv3+: GNU GPL version 3 or later > This is free software: you are free to change and redistribute it. > There is NO WARRANTY, to the extent permitted by law. > Type "show copying" and "show warranty" for details. > This GDB was configured as "x86_64-redhat-linux-gnu". > Type "show configuration" for configuration details. > For bug reporting instructions, please see: > . > Find the GDB manual and other documentation resources online at: > . > > For help, type "help". > Type "apropos word" to search for commands related to "word"... > Reading symbols from python3.9... > Reading symbols from .gnu_debugdata for /usr/bin/python3.9... > (No debugging symbols found in .gnu_debugdata for /usr/bin/python3.9) > Missing separate debuginfos, use: dnf debuginfo-install python3-3.9.1-1.fc33.x86_64 > (gdb) run > Starting program: /usr/bin/python3.9 > [Thread debugging using libthread_db enabled] > Using host libthread_db library "/lib64/libthread_db.so.1". > Python 3.9.1 (default, Dec 8 2020, 00:00:00) > [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import sqlite3 > >>> > Program received signal SIGINT, Interrupt. > 0x00007ffff7b7ff4a in select () from /lib64/libc.so.6 > (gdb) i sh > From To Syms Read Shared Object Library > 0x00007ffff7fd2090 0x00007ffff7ff2f96 Yes (*) /lib64/ld-linux-x86-64.so.2 > 0x00007ffff7caed30 0x00007ffff7e58c7d Yes (*) /lib64/libpython3.9.so.1.0 > 0x00007ffff7aad690 0x00007ffff7bfa69d Yes (*) /lib64/libc.so.6 > 0x00007ffff7a6ca90 0x00007ffff7a7b125 Yes (*) /lib64/libpthread.so.0 > 0x00007ffff7a60270 0x00007ffff7a611c9 Yes (*) /lib64/libdl.so.2 > 0x00007ffff7a5a3f0 0x00007ffff7a5adb0 Yes (*) /lib64/libutil.so.1 > 0x00007ffff79223d0 0x00007ffff79bd718 Yes (*) /lib64/libm.so.6 > 0x00007ffff7fbca50 0x00007ffff7fbe310 Yes (*) /usr/lib64/python3.9/lib-dynload/readline.cpython-39-x86_64-linux-gnu.so > 0x00007fffea1dc270 0x00007fffea204587 Yes (*) /lib64/libreadline.so.8 > 0x00007fffea1a3470 0x00007fffea1afb8c Yes (*) /lib64/libtinfo.so.6 > 0x00007fffea22ba70 0x00007fffea2316ef Yes (*) /usr/lib64/python3.9/lib-dynload/math.cpython-39-x86_64-linux-gnu.so > 0x00007fffea13ead0 0x00007fffea149d8c Yes (*) /usr/lib64/python3.9/lib-dynload/_datetime.cpython-39-x86_64-linux-gnu.so > 0x00007ffff7fb2170 0x00007ffff7fb318b Yes (*) /usr/lib64/python3.9/lib-dynload/_heapq.cpython-39-x86_64-linux-gnu.so > 0x00007fffea128510 0x00007fffea1308ee Yes (*) /usr/lib64/python3.9/lib-dynload/_sqlite3.cpython-39-x86_64-linux-gnu.so > 0x00007fffe9fd79b0 0x00007fffea0c7024 Yes (*) /lib64/libsqlite3.so.0 > 0x00007fffe9fb05f0 0x00007fffe9fbdb2b Yes (*) /lib64/libz.so.1 > (*): Shared library is missing debugging information. > (gdb) > > You can see that the python module is: > /usr/lib64/python3.9/lib-dynload/_sqlite3.cpython-39-x86_64-linux-gnu.so > > and that libsqlite3 comes from: > /lib64/libsqlite3.so.0 > > Barry > > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > From cnweike at gmail.com Wed Jan 20 21:46:45 2021 From: cnweike at gmail.com (panfei) Date: Wed, 20 Jan 2021 18:46:45 -0800 (PST) Subject: sqlite3 cannot detect the version of compiled sqlite version at some point in runtime. In-Reply-To: References: <12a307a2-e2ee-451d-bf2f-eee320629840@www.fastmail.com> Message-ID: <4bdbc59d-87c1-4868-b84e-a1d78d872392n@googlegroups.com> Hi Random: Thanks for the suggestion, I will test it right now. there is a file called sqlite3.pc in my installation. [felix at localhost pkgconfig]$ ll total 4 -rw-r--r-- 1 felix felix 315 Jan 20 12:51 sqlite3.pc [felix at localhost pkgconfig]$ pwd /home/felix/.local/sqlite/default/lib/pkgconfig ? 2021?1?21???? UTC+8 ??5:57:43? ??? > On Wed, Jan 20, 2021, at 16:45, Random832 wrote: > > On Wed, Jan 20, 2021, at 14:54, panfei wrote: > > > 3. Compile Python 3.9.1 > > > C_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ > > > CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ > > > LD_RUN_PATH=/home/felix/.local/sqlite/default/lib ./configure > > > --prefix=/home/felix/.local/python/python-3.9.1 --enable-optimizations > > > make && make install > > > > How *exactly* did you compile python? i.e. what specific commands, to > > make it pick up those include paths? Because from the symptoms you are > > reporting, it sounds like it was not compiled against the correct > > version of sqlite. > Oh, sorry, I missed "./configure" on that line. > > So, it looks like you had the environment variables set when you ran configure, but not make. I don't think this is a common way to set include paths, by the way. The usual way is with pkg-config, but I'm not sure how to add your .local sqlite directory to it. Does your sqlite installation include a file called "sqlite3.pc"? If so, try adding the directory containing it to PKG_CONFIG_PATH when running configure. > > If not... well, export the environment variables or add them when running make and hope for the best From cnweike at gmail.com Wed Jan 20 22:04:33 2021 From: cnweike at gmail.com (panfei) Date: Wed, 20 Jan 2021 19:04:33 -0800 (PST) Subject: sqlite3 cannot detect the version of compiled sqlite version at some point in runtime. In-Reply-To: References: <12a307a2-e2ee-451d-bf2f-eee320629840@www.fastmail.com> Message-ID: <0d4afcd9-5093-4f47-9a58-75cdf43411d8n@googlegroups.com> 1033 C_INCLUDE_PATH=/home/felix/.local/sqlite/default/include/ CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/default/include/ LD_RUN_PATH=/home/felix/.local/sqlite/default/lib ./configure --prefix=/home/felix/.local/python/python-3.9.1 --enable-optimizations 1034 C_INCLUDE_PATH=/home/felix/.local/sqlite/default/include/ CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/default/include/ LD_RUN_PATH=/home/felix/.local/sqlite/default/lib make 1035 make clean 1036 C_INCLUDE_PATH=/home/felix/.local/sqlite/default/include/ CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/default/include/ LD_RUN_PATH=/home/felix/.local/sqlite/default/lib ./configure --prefix=/home/felix/.local/python/python-3.9.1 --enable-optimizations 1037 C_INCLUDE_PATH=/home/felix/.local/sqlite/default/include/ CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/default/include/ LD_RUN_PATH=/home/felix/.local/sqlite/default/lib make 1038 C_INCLUDE_PATH=/home/felix/.local/sqlite/default/include/ CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/default/include/ LD_RUN_PATH=/home/felix/.local/sqlite/default/lib make install 1039 /home/felix/.local/python/python-3.9.1/bin/python3 1040 history [felix at localhost Python-3.9.1]$ /home/felix/.local/python/python-3.9.1/bin/python3 Python 3.9.1 (default, Jan 21 2021, 10:58:50) [GCC 10.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> conn = sqlite3.connect(':memory:') >>> conn.create_function('f', 2, lambda *args: None, deterministic=True) >>> Thanks very ! Every step in compilation should be with the same environment variable. Thanks again! ? 2021?1?21???? UTC+8 ??5:57:43? ??? > On Wed, Jan 20, 2021, at 16:45, Random832 wrote: > > On Wed, Jan 20, 2021, at 14:54, panfei wrote: > > > 3. Compile Python 3.9.1 > > > C_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ > > > CPLUS_INCLUDE_PATH=/home/felix/.local/sqlite/sqlite-3.34.0/include/ > > > LD_RUN_PATH=/home/felix/.local/sqlite/default/lib ./configure > > > --prefix=/home/felix/.local/python/python-3.9.1 --enable-optimizations > > > make && make install > > > > How *exactly* did you compile python? i.e. what specific commands, to > > make it pick up those include paths? Because from the symptoms you are > > reporting, it sounds like it was not compiled against the correct > > version of sqlite. > Oh, sorry, I missed "./configure" on that line. > > So, it looks like you had the environment variables set when you ran configure, but not make. I don't think this is a common way to set include paths, by the way. The usual way is with pkg-config, but I'm not sure how to add your .local sqlite directory to it. Does your sqlite installation include a file called "sqlite3.pc"? If so, try adding the directory containing it to PKG_CONFIG_PATH when running configure. > > If not... well, export the environment variables or add them when running make and hope for the best From frank at chagford.com Thu Jan 21 01:22:08 2021 From: frank at chagford.com (Frank Millman) Date: Thu, 21 Jan 2021 08:22:08 +0200 Subject: etree, gzip, and BytesIO Message-ID: Hi all This question is mostly to satisfy my curiosity. In my app I use xml to represent certain objects, such as form definitions and process definitions. They are stored in a database. I use etree.tostring() when storing them and etree.fromstring() when reading them back. They can be quite large, so I use gzip to compress them before storing them as a blob. The sequence of events when reading them back is - - select gzip'd data from database - run gzip.decompress() to convert to a string - run etree.fromstring() to convert to an etree object I was wondering if I could avoid having the unzipped string in memory, and create the etree object directly from the gzip'd data. I came up with this - - select gzip'd data from database - create a BytesIO object - fd = io.BytesIO(data) - use gzip to open the object - gf = gzip.open(fd) - run etree.parse(gf) to convert to an etree object It works. But I don't know what goes on under the hood, so I don't know if this achieves anything. If any of the steps involves decompressing the data and storing the entire string in memory, I may as well stick to my present approach. Any thoughts? Frank Millman From plushmario0122 at gmail.com Thu Jan 21 06:19:03 2021 From: plushmario0122 at gmail.com (TheGemmyGuy) Date: Thu, 21 Jan 2021 06:19:03 -0500 Subject: Mailing Message-ID: A quick question; for mailing, do I send a message through e-mail or the Python Mailman page? Thank you From teoenming.dec2020 at gmail.com Thu Jan 21 09:39:10 2021 From: teoenming.dec2020 at gmail.com (Turritopsis Dohrnii Teo En Ming) Date: Thu, 21 Jan 2021 22:39:10 +0800 Subject: Can I earn a lot of money by learning and mastering the Python programming language? Message-ID: Subject: Can I earn a lot of money by learning and mastering the Python programming language? Good day from Singapore, I am an IT consultant with a System Integrator (SI)/computer firm in Singapore, specializing in Systems/Infrastructure and Computer Networking. I am thinking of creating an extra avenue/stream of income by learning extra skills and becoming a programmer or software developer/engineer. I hope it is not too late for a person of my age. Can I earn a lot of money by learning and mastering the Python programming language? Thought I would like to find out first before I jump into the bandwagon and investing my time into learning Python. Besides Python, what other programming languages can make me earn a lot of money? Are Python, Java and C++ the most popular and most sought after (by employers) programming languages in the world? I am looking forward to your advice. Thank you very much. Mr. Turritopsis Dohrnii Teo En Ming, 42 years old as of 21 Jan 2021 Thursday, is a TARGETED INDIVIDUAL living in Singapore. He is an IT Consultant with a System Integrator (SI)/computer firm in Singapore. He is an IT enthusiast. -----BEGIN EMAIL SIGNATURE----- The Gospel for all Targeted Individuals (TIs): [The New York Times] Microwave Weapons Are Prime Suspect in Ills of U.S. Embassy Workers Link: https://www.nytimes.com/2018/09/01/science/sonic-attack-cuba-microwave.html ******************************************************************************************** Singaporean Targeted Individual Mr. Turritopsis Dohrnii Teo En Ming's Academic Qualifications as at 14 Feb 2019 and refugee seeking attempts at the United Nations Refugee Agency Bangkok (21 Mar 2017), in Taiwan (5 Aug 2019) and Australia (25 Dec 2019 to 9 Jan 2020): [1] https://tdtemcerts.wordpress.com/ [2] https://tdtemcerts.blogspot.sg/ [3] https://www.scribd.com/user/270125049/Teo-En-Ming -----END EMAIL SIGNATURE----- From kushal at locationd.net Thu Jan 21 10:57:03 2021 From: kushal at locationd.net (Kushal Kumaran) Date: Thu, 21 Jan 2021 07:57:03 -0800 Subject: etree, gzip, and BytesIO In-Reply-To: (Frank Millman's message of "Thu, 21 Jan 2021 08:22:08 +0200") References: Message-ID: <87v9bqxoz4.fsf@copper.locationd.net> On Thu, Jan 21 2021 at 08:22:08 AM, Frank Millman wrote: > Hi all > > This question is mostly to satisfy my curiosity. > > In my app I use xml to represent certain objects, such as form > definitions and process definitions. > > They are stored in a database. I use etree.tostring() when storing > them and etree.fromstring() when reading them back. They can be quite > large, so I use gzip to compress them before storing them as a blob. > > The sequence of events when reading them back is - > - select gzip'd data from database > - run gzip.decompress() to convert to a string > - run etree.fromstring() to convert to an etree object > > I was wondering if I could avoid having the unzipped string in memory, > and create the etree object directly from the gzip'd data. I came up > with this - > > - select gzip'd data from database > - create a BytesIO object - fd = io.BytesIO(data) > - use gzip to open the object - gf = gzip.open(fd) > - run etree.parse(gf) to convert to an etree object > > It works. > > But I don't know what goes on under the hood, so I don't know if this > achieves anything. If any of the steps involves decompressing the data > and storing the entire string in memory, I may as well stick to my > present approach. > > Any thoughts? > etree.parse will hold the entire uncompressed content in memory regardless of how you supply it input. If your question is whether you can avoid holding an extra copy in memory, you can take a look at the ElementTree code in https://github.com/python/cpython/blob/3.9/Lib/xml/etree/ElementTree.py (linked from the documentation of the library module). The parse method appears to read 64k at a time from the underlying stream, so using the gzip.open stream instead of gzip.decompress should limit the duplicated data being held in memory. It is possible to use the XMLPullParser or iterparse etree features to incrementally parse XML without ever holding the entire content in memory. But that will not give you an ElementTree object, and might not be feasible without an entire rewrite of the rest of the code. -- regards, kushal From david at lowryduda.com Thu Jan 21 11:32:18 2021 From: david at lowryduda.com (David Lowry-Duda) Date: Thu, 21 Jan 2021 11:32:18 -0500 Subject: Mailing In-Reply-To: References: Message-ID: On Thu, Jan 21, 2021 at 06:19:03AM -0500, TheGemmyGuy wrote: > A quick question; for mailing, do I send a message through e-mail or the > Python Mailman page? Whatever you did here works. I use email. - DLD From grant.b.edwards at gmail.com Thu Jan 21 15:31:46 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 21 Jan 2021 20:31:46 -0000 (UTC) Subject: Mailing References: Message-ID: On 2021-01-21, David Lowry-Duda wrote: > On Thu, Jan 21, 2021 at 06:19:03AM -0500, TheGemmyGuy wrote: >> A quick question; for mailing, do I send a message through e-mail or the >> Python Mailman page? > > Whatever you did here works. I use email. - DLD NNTP client (slrn) via nntp://news.gmane.io/gmane.comp.python.general -- Grant From drsalists at gmail.com Thu Jan 21 18:37:16 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Thu, 21 Jan 2021 15:37:16 -0800 Subject: Python flask logging: two different formats, but want one format Message-ID: I am working on a REST API using Flask. The API is currently divided across two Python 3.6 modules: update.py and vmware_exporters_support.py. update.py logs the way I want. vmware_exporters_support.py does not log the way I want. I want vmware_exporters_support.py to use update.py's logging format without logging things twice. In update.py, the logging is set up with: from flask.logging import create_logger app = Flask('collector_api') logger = create_logger(app) import vmware_exporters_support And create_logger, which is part of Flask, is at https://github.com/pallets/flask/blob/1.1.x/src/flask/logging.py Then in vmware_exporters_support.py I'm setting up logging with: logger = logging.getLogger() It seems like this should just get the root logger from update.py, but I'm not sure it does really considering how differently it's acting. An illustrative log snippet looks like: [2021-01-21 12:12:29,810] INFO in update: Writing container yaml /data/vmware-exporter/vmware_exporter_1 2021-01-21.12:12:29 INFO Writing container yaml /data/vmware-exporter/vmware_exporter_1 The [2021-01-21 12:12:29,810] (with the square brackets) is coming from update.py, and the 2021-01-21.12:12:29 (without the square brackets) is coming from vmware_exporters_support.py What do I need to do to get vmware_exporters_support.py to use the same logging format as update.py? BTW, update.py is the __main__, not vmware_exporters_support.py. And I'm using Flask 1.1.2. Thanks in advance! From cs at cskk.id.au Thu Jan 21 19:51:06 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Fri, 22 Jan 2021 11:51:06 +1100 Subject: Python flask logging: two different formats, but want one format In-Reply-To: References: Message-ID: On 21Jan2021 15:37, Dan Stromberg wrote: >I am working on a REST API using Flask. > >The API is currently divided across two Python 3.6 modules: update.py and >vmware_exporters_support.py. > >update.py logs the way I want. vmware_exporters_support.py does not log the >way I want. I want vmware_exporters_support.py to use update.py's logging >format without logging things twice. > >In update.py, the logging is set up with: > from flask.logging import create_logger > app = Flask('collector_api') > logger = create_logger(app) > import vmware_exporters_support > >And create_logger, which is part of Flask, is at >https://github.com/pallets/flask/blob/1.1.x/src/flask/logging.py > >Then in vmware_exporters_support.py I'm setting up logging with: > logger = logging.getLogger() > >It seems like this should just get the root logger from update.py, but I'm >not sure it does really considering how differently it's acting. Is logger-from_flask and logger_in_vmware_exporters_support the same using "is"? Have you printed them? Usually loggers have names indicating their position in a logger tree - print should show this. Loggers have handlers to deal with log requests, and it is the handlers which have the formats attached. Can you see the handlers for the root logger (which looks to be what vmware_exporters_support uses) and for the one from flask? It doesn't seem documents, but dir() on a Logger shows a .handlers attribute which is a list of Handlers. >The [2021-01-21 12:12:29,810] (with the square brackets) is coming from >update.py, and the 2021-01-21.12:12:29 (without the square brackets) is >coming from vmware_exporters_support.py > >What do I need to do to get vmware_exporters_support.py to use the same >logging format as update.py? > >BTW, update.py is the __main__, not vmware_exporters_support.py. Can you pass the logger you get from create_logger(app) to the vmware_exporters_support setup function? That way you could tell it to use your preferred logger. Cheers, Cameron Simpson From samuelmarks at gmail.com Fri Jan 22 01:58:56 2021 From: samuelmarks at gmail.com (Samuel Marks) Date: Fri, 22 Jan 2021 17:58:56 +1100 Subject: Force Python ast to emit lines no longer than $length In-Reply-To: References: Message-ID: I ended up adding word-wrap support directly to my code-generation: https://github.com/SamuelMarks/doctrans/commit/6147b21e168b66623aa1be95cb38b1969daa5147 Samuel Marks Charity | consultancy | open-source | LinkedIn On Wed, Jan 20, 2021 at 2:05 PM Samuel Marks wrote: > I've written a library that works at the ast level. Sometimes the > generated output goes over the linter line length limit. > > > "foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz" > > How do I generate this kind of code instead? > > "foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_" > "foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz" > > (also happy with the \ and parenthesised variants) [cross-posted: > stackoverflow.com/q/65800797] > > The only thing I can think of doing?retaining support for 3.6, 3.7, > 3.8, 3.9, and 3.10a4?is to contribute to both astor and the builtin > ast.unparse? > From mstfmoradian at gmail.com Fri Jan 22 09:29:50 2021 From: mstfmoradian at gmail.com (Mostafa Moradian) Date: Fri, 22 Jan 2021 15:29:50 +0100 Subject: Django-saml2-auth 3.0.0 Released Message-ID: Hello, I am pleased to announce the release of django-saml2-auth, which includes 71 commits, 92 lines of commit messages and 3 separate reviews and reviewers. The project is originally developed by Li Fang , but is forked and currently maintained by Mostafa Moradian < https://github.com/mostafa> and sponsored by Load Impact AB (https://k6.io). This release is backward incompatible with older versions: 1.x.x and 2.x.x, and includes heavy refactoring, improving code readability (docstrings, annotations, ...), tests, new shiny features and the like. You can read more about the details in the PR description: https://github.com/loadimpact/django-saml2-auth/pull/14. The biggest change so far was adding tests and enabling GitHub Actions as CI, plus the introduction of SP-initiated SSO. The exception and error handling is also greatly improved. Mostafa Moradian. Project homepage: https://github.com/loadimpact/django-saml2-auth P.S. It is not published to pypi yet, because of naming issues with the original package. From ast at invalid Sat Jan 23 02:54:18 2021 From: ast at invalid (ast) Date: Sat, 23 Jan 2021 08:54:18 +0100 Subject: list() strange behaviour In-Reply-To: References: Message-ID: <600bd62a$0$4029$426a74cc@news.free.fr> Le 20/12/2020 ? 21:00, danilob a ?crit?: > > > b = ((x[0] for x in a)) > There is a useless pair of parenthesis b = (x[0] for x in a) b is a GENERATOR expression first list(b) calls next method on b repetedly until b is empty. So it provides the "content" of b second list(b) provides nothing since b is empty (there is no reset on generators) From tjreedy at udel.edu Sat Jan 23 09:43:45 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 23 Jan 2021 09:43:45 -0500 Subject: list() strange behaviour In-Reply-To: <600bd62a$0$4029$426a74cc@news.free.fr> References: <600bd62a$0$4029$426a74cc@news.free.fr> Message-ID: On 1/23/2021 2:54 AM, Unknown wrote: > Le 20/12/2020 ? 21:00, danilob a ?crit?: > >> >> >> b = ((x[0] for x in a)) >> > > There is a useless pair of parenthesis > > b = (x[0] for x in a) > > b is a GENERATOR expression > > first list(b) calls next method on b repetedly until b is empty. > So it provides the "content" of b > > second list(b) provides nothing since b is empty > (there is no reset on generators) There is for generator *functions*, which some people also call generators. For generator expressions, the interpreter makes an anonymous generator function, calls it, keeping the returned generator. It deletes the function and 'returns' the generator as the value of the function. If one want to iterator twice, write a proper named generator function with a docstring. In this case def gf(a): "Return a generator that yields the first item of each sequence in a." for x in a: yield x[0] -- Terry Jan Reedy From avigross at verizon.net Sat Jan 23 12:20:12 2021 From: avigross at verizon.net (Avi Gross) Date: Sat, 23 Jan 2021 12:20:12 -0500 Subject: list() strange behaviour In-Reply-To: <600bd62a$0$4029$426a74cc@news.free.fr> References: <600bd62a$0$4029$426a74cc@news.free.fr> Message-ID: <034101d6f1ac$02551e50$06ff5af0$@verizon.net> I am wondering how hard it would be to let some generators be resettable? I mean if you have a generator with initial conditions that change as it progresses, could it cache away those initial conditions and upon some signal, simply reset them? Objects of many kinds can be set up with say a reinit() method. I am not saying Python needs such a language change for generators as in many programs you could just recreate a new instance of a generator. But there may be places where by the time the generator is used, the original is not known. Or, there are places where you want to lengthen something to match another by repeatedly copying the same sequence as many times as needed. If a generator finishes, you want it to restart with the same sequence until you stop asking. This is just a thought, not a request for such a feature. -----Original Message----- From: Python-list On Behalf Of ast Sent: Saturday, January 23, 2021 2:54 AM To: python-list at python.org Subject: Re: list() strange behaviour Le 20/12/2020 ? 21:00, danilob a ?crit?: > > > b = ((x[0] for x in a)) > There is a useless pair of parenthesis b = (x[0] for x in a) b is a GENERATOR expression first list(b) calls next method on b repetedly until b is empty. So it provides the "content" of b second list(b) provides nothing since b is empty (there is no reset on generators) -- https://mail.python.org/mailman/listinfo/python-list From cs at cskk.id.au Sat Jan 23 16:47:48 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 24 Jan 2021 08:47:48 +1100 Subject: list() strange behaviour In-Reply-To: <034101d6f1ac$02551e50$06ff5af0$@verizon.net> References: <034101d6f1ac$02551e50$06ff5af0$@verizon.net> Message-ID: On 23Jan2021 12:20, Avi Gross wrote: >I am wondering how hard it would be to let some generators be resettable? > >I mean if you have a generator with initial conditions that change as it >progresses, could it cache away those initial conditions and upon some >signal, simply reset them? Objects of many kinds can be set up with say a >reinit() method. On reflection I'd do this with a class: class G: def __init__(self, length): self.length = length self.pos = 0 def __next__(self): pos = self.pos if pos >= length: raise StopIteration() self.pos += 1 return pos def __iter__(self): return self then: g = G(9) for x in g: print(x) if x == 5: g.pos = 7 You could either fiddle the iterable class instance attributes directly as above or provide a reset method of some kind. If you don't need to fiddle/reset you can just write: for x in G(9): The two step above is so we have "g" to hand to do the fiddling. Cheers, Cameron Simpson From rosuav at gmail.com Sat Jan 23 16:55:10 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 24 Jan 2021 08:55:10 +1100 Subject: list() strange behaviour In-Reply-To: References: <034101d6f1ac$02551e50$06ff5af0$@verizon.net> Message-ID: On Sun, Jan 24, 2021 at 8:49 AM Cameron Simpson wrote: > > On 23Jan2021 12:20, Avi Gross wrote: > >I am wondering how hard it would be to let some generators be resettable? > > > >I mean if you have a generator with initial conditions that change as it > >progresses, could it cache away those initial conditions and upon some > >signal, simply reset them? Objects of many kinds can be set up with say a > >reinit() method. > > On reflection I'd do this with a class: > > class G: > def __init__(self, length): > self.length = length > self.pos = 0 > > def __next__(self): > pos = self.pos > if pos >= length: > raise StopIteration() > self.pos += 1 > return pos > > def __iter__(self): > return self > Yep, or more conveniently: class G: def __init__(self, length): self.length = length self.pos = 0 def __iter__(self): while self.pos < self.length: yield self.pos self.pos += 1 The only significant part is the fact that your generator function has *external* state, which is what allows you to manipulate it. Generator functions are still way cleaner for most purposes than handwritten iterator classes. ChrisA From barry at barrys-emacs.org Sat Jan 23 17:54:24 2021 From: barry at barrys-emacs.org (Barry) Date: Sat, 23 Jan 2021 22:54:24 +0000 Subject: list() strange behaviour In-Reply-To: <034101d6f1ac$02551e50$06ff5af0$@verizon.net> References: <034101d6f1ac$02551e50$06ff5af0$@verizon.net> Message-ID: <58E4A594-AF4B-4056-A25A-41D8F2D9942F@barrys-emacs.org> > On 23 Jan 2021, at 17:23, Avi Gross via Python-list wrote: > > ?I am wondering how hard it would be to let some generators be resettable? That is generally thought to be a bad thing in OOD. Classes that reset are usually a code smell and often a source of bugs. Why not just assign a new generate into the variable that is used to access the generator. The avoids the need for the complications of reset logic. Barry > > I mean if you have a generator with initial conditions that change as it > progresses, could it cache away those initial conditions and upon some > signal, simply reset them? Objects of many kinds can be set up with say a > reinit() method. > > I am not saying Python needs such a language change for generators as in > many programs you could just recreate a new instance of a generator. But > there may be places where by the time the generator is used, the original is > not known. Or, there are places where you want to lengthen something to > match another by repeatedly copying the same sequence as many times as > needed. If a generator finishes, you want it to restart with the same > sequence until you stop asking. > > This is just a thought, not a request for such a feature. > > -----Original Message----- > From: Python-list On > Behalf Of ast > Sent: Saturday, January 23, 2021 2:54 AM > To: python-list at python.org > Subject: Re: list() strange behaviour > >> Le 20/12/2020 ? 21:00, danilob a ?crit : >> b = ((x[0] for x in a)) > > There is a useless pair of parenthesis > > b = (x[0] for x in a) > > b is a GENERATOR expression > > first list(b) calls next method on b repetedly until b is empty. > So it provides the "content" of b > > second list(b) provides nothing since b is empty (there is no reset on > generators) > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- > https://mail.python.org/mailman/listinfo/python-list From nospam at please.ty Sun Jan 24 04:49:34 2021 From: nospam at please.ty (jak) Date: Sun, 24 Jan 2021 10:49:34 +0100 Subject: list() strange behaviour References: Message-ID: Il 20/12/2020 21:00, danilob ha scritto: > Hi, > I'm an absolute beginner in Python (and in English too ;-) > Running this code: > > > -------------- > # Python 3.9.0 > > a = [[1, 2, 0, 3, 0], > ???? [0, 4, 5, 0, 6], > ???? [7, 0, 8, 0, 9], > ???? [2, 3, 0, 0, 1], > ???? [0, 0, 1, 8, 0]] > > > b = ((x[0] for x in a)) > > print(list(b)) > print(list(b)) > --------------- > > > I get this output: > > [1, 0, 7, 2, 0] > [] > > > I don't know why the second print() output shows an empty list. > Is it possible that the first print() call might have changed the value > of "b"? > > Thank you in advance. You should see a generator as a container emptying while you are reading it, so you should recreate it every time: ################################ # Python 3.9.0 a = [[1, 2, 0, 3, 0], [0, 4, 5, 0, 6], [7, 0, 8, 0, 9], [2, 3, 0, 0, 1], [0, 0, 1, 8, 0]] b = lambda : (x[0] for x in a) print(list(b())) print(list(b())) output: [1, 0, 7, 2, 0] [1, 0, 7, 2, 0] ################################ From martin.schoon at gmail.com Sun Jan 24 16:43:54 2021 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 24 Jan 2021 21:43:54 GMT Subject: Jupyter notebooks to A4 (again) Message-ID: Hello all, Some years ago I asked about exporting notebooks to pdf in A4 rather than US Letter. I got help, rather detailed instructions from you in general and Piet von Oostrum in particular. Following the advice helped and I was happy. Now it does not work any longer: nbconvert failed: A4article I am stumped. I have not changed anything and all looks OK. Today I tried up-dating all things Python and Jupyter but that did not help. I have also tried removing the A4 stuff and after restarting Jupyter I can export to PDF and get US Letter paper format. A quick and (obviously) not very clever internet search yielded nothing helpful. Any ideas? /Martin From bluebox03 at gmail.com Mon Jan 25 09:35:23 2021 From: bluebox03 at gmail.com (tommy yama) Date: Mon, 25 Jan 2021 23:35:23 +0900 Subject: Jupyter notebooks to A4 (again) In-Reply-To: References: Message-ID: Hi Martin, I noticed that i did use the same , formats are mentioned in git already. https://github.com/jupyter/nbconvert On Mon, Jan 25, 2021 at 6:47 AM Martin Sch??n wrote: > Hello all, > > Some years ago I asked about exporting notebooks to pdf in > A4 rather than US Letter. I got help, rather detailed > instructions from you in general and Piet von Oostrum in > particular. Following the advice helped and I was happy. > > Now it does not work any longer: > > nbconvert failed: A4article > > I am stumped. I have not changed anything and all > looks OK. > > Today I tried up-dating all things Python and Jupyter > but that did not help. > > I have also tried removing the A4 stuff and after > restarting Jupyter I can export to PDF and get US Letter > paper format. > > A quick and (obviously) not very clever internet search > yielded nothing helpful. > > Any ideas? > > /Martin > -- > https://mail.python.org/mailman/listinfo/python-list > From gri6507 at gmail.com Tue Jan 26 09:35:48 2021 From: gri6507 at gmail.com (Paul Grinberg) Date: Tue, 26 Jan 2021 06:35:48 -0800 (PST) Subject: c bindings with non-python thread callback while python exits Message-ID: <5ad34f0c-7585-4035-a641-726d024de2b4n@googlegroups.com> I have a C++ library (luckily with source code, so I know what's going on) to which I wrote c bindings. The library internally starts an event pthread which generates callbacks back into python. The c binding for processing these callbacks look like this (simplified for convenience): PyGILState_STATE gstate; gstate = PyGILState_Ensure(); PyObject_CallObject(cb, arglist); PyGILState_Release(gstate); This works perfectly while the python program using this c binding is running. However, when the program terminates normally and there happens to be one last callback underway, the c bindings hang. When viewed with GDB, I can see that the callback thread callstack looks like this: futex_abstimed_wait_cancelable() _pthread_cond_wait_common() __pthread_cond_timedwait() PyCOND_TIMEDWAIT() take_gil() PyEval_RestoreThread() PyGILState_Ensure() c_bindings_callback() cpp_library_callback() and the main thread callstack, which is where the python interpreter was running, looks like this __pthread_clockjoin_ex () std::thread::join() cpp_library_static_singleton_class_destructor () __run_exit_handlers () __GI_exit () __libc_start_main () _start () in other words, the program hangs because the main thread is waiting for the event pthread to join, but that thread is stuck in a callback waiting for the GIL. What is the right way to prevent this problem from happening? Thank you in advance, Paul. P.S. I am running on Linux: ubuntu 18.04 with python 3.6.9, also reproduced with python 3.7.5, as well as ubuntu 20.04 with python 3.8.5 From mazyar.gh9 at gmail.com Tue Jan 26 04:01:59 2021 From: mazyar.gh9 at gmail.com (Maziar Ghasemi) Date: Tue, 26 Jan 2021 12:31:59 +0330 Subject: help In-Reply-To: References: Message-ID: Hi help me to repair this erorr: Warning: translation file 'git_en_US' could not be loaded. Using default. and download python39.dll On 1/26/21, Maziar Ghasemi wrote: > Hi > help me to repair this erorr: > Warning: translation file 'git_en_US' could not be loaded. > Using default. > and download python39.dll > -- > mazyar ghasemi > MS student of Razi university > -- mazyar ghasemi MS student of Razi university From tjreedy at udel.edu Tue Jan 26 12:05:12 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 26 Jan 2021 12:05:12 -0500 Subject: help In-Reply-To: References: Message-ID: On 1/26/2021 4:01 AM, Maziar Ghasemi wrote: > Hi > help me to repair this erorr: > Warning: translation file 'git_en_US' could not be loaded. > Using default. > and download python39.dll Please do not repost, especially the same day. > On 1/26/21, Maziar Ghasemi wrote: >> Hi >> help me to repair this erorr: >> Warning: translation file 'git_en_US' could not be loaded. >> Using default. >> and download python39.dll You ran some python software that wants a missing translation file. Ask the help forum for that software. If you ran Eric IDE, perhaps https://tracker.die-offenbachs.homelinux.org/eric/issue293 will help. I found this by searching the web (google) for 'git_en_us'. -- Terry Jan Reedy From ethan at stoneleaf.us Tue Jan 26 12:30:15 2021 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 26 Jan 2021 09:30:15 -0800 Subject: help In-Reply-To: References: Message-ID: On 1/26/21 9:05 AM, Terry Reedy wrote: > On 1/26/2021 4:01 AM, Maziar Ghasemi wrote: >> ... > > Please do not repost, especially the same day. Maziar Ghasemi appears to be a new user, and had to sign up to the Python List mailing list. Are you seeing his request twice because you use gmane? -- ~Ethan~ From barry at barrys-emacs.org Tue Jan 26 16:25:04 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Tue, 26 Jan 2021 21:25:04 +0000 Subject: c bindings with non-python thread callback while python exits In-Reply-To: <5ad34f0c-7585-4035-a641-726d024de2b4n@googlegroups.com> References: <5ad34f0c-7585-4035-a641-726d024de2b4n@googlegroups.com> Message-ID: > On 26 Jan 2021, at 14:35, Paul Grinberg wrote: > > I have a C++ library (luckily with source code, so I know what's going on) to which I wrote c bindings. The library internally starts an event pthread which generates callbacks back into python. The c binding for processing these callbacks look like this (simplified for convenience): > > PyGILState_STATE gstate; > gstate = PyGILState_Ensure(); > PyObject_CallObject(cb, arglist); > PyGILState_Release(gstate); > > This works perfectly while the python program using this c binding is running. However, when the program terminates normally and there happens to be one last callback underway, the c bindings hang. When viewed with GDB, I can see that the callback thread callstack looks like this: > > futex_abstimed_wait_cancelable() > _pthread_cond_wait_common() > __pthread_cond_timedwait() > PyCOND_TIMEDWAIT() > take_gil() > PyEval_RestoreThread() > PyGILState_Ensure() > c_bindings_callback() > cpp_library_callback() > > and the main thread callstack, which is where the python interpreter was running, looks like this > > __pthread_clockjoin_ex () > std::thread::join() > cpp_library_static_singleton_class_destructor () > __run_exit_handlers () > __GI_exit () > __libc_start_main () > _start () > > in other words, the program hangs because the main thread is waiting for the event pthread to join, but that thread is stuck in a callback waiting for the GIL. > > What is the right way to prevent this problem from happening? As you say you have dead locked. My guess is that you have to shutdown your extension before you quit python. You might find pycxx interesting if you are wrapping C++ code for use with python. http://cxx.sourceforge.net/ Barry > Thank you in advance, > Paul. > > P.S. I am running on Linux: ubuntu 18.04 with python 3.6.9, also reproduced with python 3.7.5, as well as ubuntu 20.04 with python 3.8.5 > -- > https://mail.python.org/mailman/listinfo/python-list > From tmrsg11 at gmail.com Tue Jan 26 14:00:00 2021 From: tmrsg11 at gmail.com (C W) Date: Tue, 26 Jan 2021 14:00:00 -0500 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. Message-ID: Hello everyone, I'm a long time Matlab and R user working on data science. How do you troubleshooting/debugging in Python? I ran into this impossible situation to debug: class person: def __init__(self, id, created_at, name, attend_date, distance): """Create a new `person`. """ self._id = id self.created_at = created_at self.name = name self.attend_date = attend_date self.distance = distance @classmethod def get_person(self, employee): """Find and return a person by. """ return person(employee['created_at'], employee['id'], employee['name'], employee['attend_date'], employee['distance'] ) I got an error message saying id was 'str', but expecting 'int'. In R, I use the interactive IDE with console. Wherever the error interrupts the code, I just evaluate that line in the console. Very convenient! If this error was in R, I would have tried: > self._id = 123 But, I can't do that here! What do I do? Do I HAVE TO instantiate an object first? It's not convenient if I have 10 of these objects around. I need to instantiate 10 objects. I know hardcore computer scientists would tell me about Python debugger. R also has one, but nobody ever uses it. I don't find them user-friendly! Thanks a lot, Mike From grant.b.edwards at gmail.com Tue Jan 26 19:16:03 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 27 Jan 2021 00:16:03 -0000 (UTC) Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. References: Message-ID: On 2021-01-26, C W wrote: > How do you troubleshooting/debugging in Python? Mostly I read exception trace and read the code and think about it. If that doesn't work, I add some print() or syslog() calls. If I really get stuck, I try to write as small a program as possible that demonstrates the problem. > I know hardcore computer scientists would tell me about Python debugger. I've been writing Python for 20+ years. I've never tried a debugger. -- Grant From skip.montanaro at gmail.com Tue Jan 26 19:52:07 2021 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 26 Jan 2021 18:52:07 -0600 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: CW> How do you troubleshooting/debugging in Python? GE> Mostly I read exception trace and read the code and think about it. GE> If that doesn't work, I add some print() or syslog() calls. CW> I know hardcore computer scientists would tell me about Python debugger. GE> I've been writing Python for 20+ years. I've never tried a debugger. Agree with Grant on these points. I certainly use gdb to debug C code (like the interpreter), but for Python code, tracebacks and print statements pretty much take care of things. I know pdb has been around for a long while and many people like IDEs, but I've not generally found them all that useful. I'm stuck in the 90s I guess. Skip From cs at cskk.id.au Tue Jan 26 19:57:35 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 27 Jan 2021 11:57:35 +1100 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: On 26Jan2021 14:00, C W wrote: >I'm a long time Matlab and R user working on data science. How do you >troubleshooting/debugging in Python? > >I ran into this impossible situation to debug: >class person: >def __init__(self, id, created_at, name, attend_date, distance): >"""Create a new `person`. >""" Your mailer has removed all the indenting. See if it has a mode for code. Often just making sure all the code is itself indented will do, eg: some indented code here >I got an error message saying id was 'str', but expecting 'int'. There should have been a complete traceback with that error, showing which line triggered the exception and how it was called. Here, we don't know from your description what happened or where. >If this error was in R, I would have tried: >> self._id = 123 Well, provided "self" already existed, that would work in Python but tell you almost nothing, because any variable may reference a value of any type. (Python variables are not typed, but the values _are_.) >But, I can't do that here! What do I do? Do I HAVE TO instantiate an >object >first? Well, "self" is the instantiaited object. The __init__ function does more setup (completing what you might call "normal" instantiation). >It's not convenient if I have 10 of these objects around. I need to >instantiate 10 objects. Your environment isn't clear to me. >I know hardcore computer scientists would tell me about Python debugger. R >also has one, but nobody ever uses it. I don't find them user-friendly! Me either. Like grant, i fall into the "look at the stack trace and think a bit, then put in print() calls or similar to show me whether things are what I expect them to be when the code runs". I actually have a Computer Science degree, but I think there are definition those who like debuggers and those who tend not to. I'm in the latter camp. Preferences like that affact how you _choose_ to debug. Usually I have the code in a file in one window and a command line in another, and go: python my_code_file.py ... to test when debugging. Cheers, Cameron Simpson From wrw at mac.com Tue Jan 26 20:28:31 2021 From: wrw at mac.com (William Ray Wing) Date: Tue, 26 Jan 2021 20:28:31 -0500 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: <65AEDEA1-1A99-4FB9-8527-9447093F0856@mac.com> > On Jan 26, 2021, at 2:00 PM, C W wrote: > > Hello everyone, > > I'm a long time Matlab and R user working on data science. How do you > troubleshooting/debugging in Python? > Another approach is to run the code in an IDE. I happen to use Wing, but that is a coincidence. But almost ANY IDE will let you set a break point, then single-step through your code starting at the break point and examine the values of your variables at each step. Sometimes this is an awfully big hammer for what is a head-slapping mistake. But it has never failed me. Good luck, Bill From ed at leafe.com Tue Jan 26 21:41:33 2021 From: ed at leafe.com (Ed Leafe) Date: Tue, 26 Jan 2021 20:41:33 -0600 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: <9B50E52F-F565-4C78-B736-A7589DE5A433@leafe.com> On Jan 26, 2021, at 18:16, Grant Edwards wrote: > >> How do you troubleshooting/debugging in Python? > > Mostly I read exception trace and read the code and think about it. > > If that doesn't work, I add some print() or syslog() calls. > > If I really get stuck, I try to write as small a program as possible > that demonstrates the problem. I do the first two, but if I get really stuck, I use the pudb debugger (https://pypi.org/project/pudb/). Using that, I can see all the locals, jump to any point in the stack and see the locals there, or shell into ipython if I need to run some quick code. For me, this is much faster than trying to write an additional program that is close enough to the problem code to be useful. -- Ed Leafe From tmrsg11 at gmail.com Tue Jan 26 22:37:30 2021 From: tmrsg11 at gmail.com (C W) Date: Tue, 26 Jan 2021 22:37:30 -0500 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: <9B50E52F-F565-4C78-B736-A7589DE5A433@leafe.com> References: <9B50E52F-F565-4C78-B736-A7589DE5A433@leafe.com> Message-ID: Thanks for your replies. My apologies for the poor indent. I'm rewriting the code below. class NEODatabase: def __init__(self, id, created_at, name, attend_date, distance): self._id = id self.created_at = created_at self.name = name self.attend_date = attend_date self.distance = distance @classmethod def get_person(self, employee): return PERSONDatabase(employee['created_at'], employee['id'], employee['name'], employee['attend_date'], employee['distance']) I have a naive question. How do I use traceback or trace the stack? In particular, I'm using VS Code with Python interactive console. Say, I want to print the value of employee['name']. Can I do it? My understanding is that these classes are just "skeletons". I must create an instance, assign values, then test? Thanks so much, Mike On Tue, Jan 26, 2021 at 9:55 PM Ed Leafe wrote: > On Jan 26, 2021, at 18:16, Grant Edwards > wrote: > > > >> How do you troubleshooting/debugging in Python? > > > > Mostly I read exception trace and read the code and think about it. > > > > If that doesn't work, I add some print() or syslog() calls. > > > > If I really get stuck, I try to write as small a program as possible > > that demonstrates the problem. > > I do the first two, but if I get really stuck, I use the pudb debugger ( > https://pypi.org/project/pudb/). > > Using that, I can see all the locals, jump to any point in the stack and > see the locals there, or shell into ipython if I need to run some quick > code. For me, this is much faster than trying to write an additional > program that is close enough to the problem code to be useful. > > -- Ed Leafe > > > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > From grant.b.edwards at gmail.com Tue Jan 26 22:30:27 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 27 Jan 2021 03:30:27 -0000 (UTC) Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. References: Message-ID: On 2021-01-27, Cameron Simpson wrote: > Me either. Like grant, i fall into the "look at the stack trace and > think a bit, then put in print() calls or similar to show me whether > things are what I expect them to be when the code runs". > > I actually have a Computer Science degree, but I think there are > definition those who like debuggers and those who tend not to. Me too (MS in CSci), but I can't remember the last time I used a debugger. It may help that I "grow" my apps. I don't sit down, write a 3000 line program, and then try to debug the program. That just doesn't work. It doesn't matter how much UML you can point to if a couple of your basic assumptions turned out to be wrong. Write small funtions, and add small chunks of code, and test as you go to make sure things work the way you thought they were going to. If it used to work, you've only added 5 lines of code, and now it doesn't work, it's usually not hard to figure out what's wrong. And don't be afraid to refactor stuff when your original approach starts to smell -- if you just keep going it will only get worse. Source control can also be a lifesaver if you get really confused. -- Grant From drsalists at gmail.com Tue Jan 26 23:13:48 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 26 Jan 2021 20:13:48 -0800 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: On Tue, Jan 26, 2021 at 4:01 PM C W wrote: > Hello everyone, > > I'm a long time Matlab and R user working on data science. How do you > troubleshooting/debugging in Python? > I frequently read tracebacks and think about what's up in the code. I also often add print functions or logging - empiricism often beats theorizing when the problems are weird. And once in a while I will use pudb - it's probably a pretty good fit for a vim user like me, both being curses-based. pdb is sad. There are other debuggers for Python: https://wiki.python.org/moin/PythonDebuggingTools From drsalists at gmail.com Tue Jan 26 23:17:30 2021 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 26 Jan 2021 20:17:30 -0800 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: On Tue, Jan 26, 2021 at 8:13 PM Dan Stromberg wrote: > > On Tue, Jan 26, 2021 at 4:01 PM C W wrote: > >> Hello everyone, >> >> I'm a long time Matlab and R user working on data science. How do you >> troubleshooting/debugging in Python? >> > > I frequently read tracebacks and think about what's up in the code. > > I also often add print functions or logging - empiricism often beats > theorizing when the problems are weird. > > And once in a while I will use pudb - it's probably a pretty good fit for > a vim user like me, both being curses-based. pdb is sad. There are other > debuggers for Python: > https://wiki.python.org/moin/PythonDebuggingTools > BTW, there's a new tool I haven't tried yet, that sounds pretty interesting, especially for newcomers: It's called "friendly traceback" and can be found at https://pypi.org/project/friendly-traceback/ Oh, and of course google search is a terrific tool for deciphering error messages. From torriem at gmail.com Wed Jan 27 00:07:39 2021 From: torriem at gmail.com (Michael Torrie) Date: Tue, 26 Jan 2021 22:07:39 -0700 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: <9B50E52F-F565-4C78-B736-A7589DE5A433@leafe.com> Message-ID: <667489a6-2322-42f8-3feb-719c0adeb906@gmail.com> On 1/26/21 8:37 PM, C W wrote: > I have a naive question. How do I use traceback or trace the stack? In > particular, I'm using VS Code with Python interactive console. Show us the traceback here and we can help you interpret it. Copy and paste it from the VS Code console. > Say, I want to print the value of employee['name']. Can I do it? Yes I would think so. > My understanding is that these classes are just "skeletons". I must > create an instance, assign values, then test? Can't you just do something like this? class NEODatabase: def __init__(self, id, created_at, name, attend_date, distance): self._id = id self.created_at = created_at self.name = name self.attend_date = attend_date self.distance = distance @classmethod def get_person(self, employee): print (employee['name']) return PERSONDatabase(employee['created_at'], employee['id'], employee['name'], employee['attend_date'], employee['distance']) From torriem at gmail.com Wed Jan 27 00:10:25 2021 From: torriem at gmail.com (Michael Torrie) Date: Tue, 26 Jan 2021 22:10:25 -0700 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: On 1/26/21 8:30 PM, Grant Edwards wrote: > Me too (MS in CSci), but I can't remember the last time I used a > debugger. I use a debugger frequency in C++, and sometimes C. Even running a debugger on an attached device like an Arduino is sometimes very useful. Good debuggers let you do things like conditional breakpoints and watch expressions. Helpful for tracking down hard-to-find and less frequent conditions. Sure you could print stuff out, which I do, but sometimes it's more convenient to do it with the debugger. From tmrsg11 at gmail.com Wed Jan 27 00:19:35 2021 From: tmrsg11 at gmail.com (C W) Date: Wed, 27 Jan 2021 00:19:35 -0500 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: <667489a6-2322-42f8-3feb-719c0adeb906@gmail.com> References: <9B50E52F-F565-4C78-B736-A7589DE5A433@leafe.com> <667489a6-2322-42f8-3feb-719c0adeb906@gmail.com> Message-ID: Hi Michael, Here's the code again, class should be called PERSONDatabase, misspelled earlier: class PERSONDatabase: def __init__(self, id, created_at, name, attend_date, distance): self._id = id self.created_at = created_at self.name= name self.attend_date = attend_date self.distance = distance @classmethod def get_person(self, employee): return PERSONDatabase(employee['created_at'], employee['id'], employee['name'], employee['attend_date'], employee['distance']) The PERSONDatabase class is called from main. This is the trace back I got from the VS code: Traceback (most recent call last): File "/Users/Mike/Documents/Mike/main.py", line 95, in main() File "/Users/Mike/Documents/Mike/main.py", line 86, in main args = get_feed() File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed result = [PERSONatabase.get_person(raw_person) for raw_neo in raw_objects] File "/Users/Mike/Documents/Mike/main.py", line 32, in result = [NEODatabase.get_person(raw_person) for raw_neo in raw_objects] File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person return PERSONDatabase(person['created_at'], KeyError: 'created_at' Thank you very much! On Wed, Jan 27, 2021 at 12:10 AM Michael Torrie wrote: > On 1/26/21 8:37 PM, C W wrote: > > I have a naive question. How do I use traceback or trace the stack? In > > particular, I'm using VS Code with Python interactive console. > > Show us the traceback here and we can help you interpret it. Copy and > paste it from the VS Code console. > > > Say, I want to print the value of employee['name']. Can I do it? > > Yes I would think so. > > > My understanding is that these classes are just "skeletons". I must > > create an instance, assign values, then test? > > Can't you just do something like this? > > class NEODatabase: > def __init__(self, id, created_at, name, attend_date, distance): > self._id = id > self.created_at = created_at > self.name = name > self.attend_date = attend_date > self.distance = distance > > @classmethod > def get_person(self, employee): > print (employee['name']) > > return PERSONDatabase(employee['created_at'], > employee['id'], > employee['name'], > employee['attend_date'], > employee['distance']) > > -- > https://mail.python.org/mailman/listinfo/python-list > From joepareti54 at gmail.com Wed Jan 27 00:52:10 2021 From: joepareti54 at gmail.com (joseph pareti) Date: Wed, 27 Jan 2021 06:52:10 +0100 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: <9B50E52F-F565-4C78-B736-A7589DE5A433@leafe.com> <667489a6-2322-42f8-3feb-719c0adeb906@gmail.com> Message-ID: To debug python code I use spyder from the anaconda distribution Am Mittwoch, 27. Januar 2021 schrieb C W : > Hi Michael, > Here's the code again, class should be called PERSONDatabase, misspelled > earlier: > class PERSONDatabase: > def __init__(self, id, created_at, name, attend_date, distance): > self._id = id > self.created_at = created_at > self.name= name > self.attend_date = attend_date > self.distance = distance > > @classmethod > def get_person(self, employee): > return PERSONDatabase(employee['created_at'], > employee['id'], > employee['name'], > employee['attend_date'], > employee['distance']) > > The PERSONDatabase class is called from main. This is the trace back I got > from the VS code: > > Traceback (most recent call last): > File "/Users/Mike/Documents/Mike/main.py", line 95, in > main() > File "/Users/Mike/Documents/Mike/main.py", line 86, in main > args = get_feed() > File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed > result = [PERSONatabase.get_person(raw_person) for raw_neo in > raw_objects] > File "/Users/Mike/Documents/Mike/main.py", line 32, in > result = [NEODatabase.get_person(raw_person) for raw_neo in > raw_objects] > File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person > return PERSONDatabase(person['created_at'], > KeyError: 'created_at' > > Thank you very much! > > On Wed, Jan 27, 2021 at 12:10 AM Michael Torrie wrote: > > > On 1/26/21 8:37 PM, C W wrote: > > > I have a naive question. How do I use traceback or trace the stack? In > > > particular, I'm using VS Code with Python interactive console. > > > > Show us the traceback here and we can help you interpret it. Copy and > > paste it from the VS Code console. > > > > > Say, I want to print the value of employee['name']. Can I do it? > > > > Yes I would think so. > > > > > My understanding is that these classes are just "skeletons". I must > > > create an instance, assign values, then test? > > > > Can't you just do something like this? > > > > class NEODatabase: > > def __init__(self, id, created_at, name, attend_date, distance): > > self._id = id > > self.created_at = created_at > > self.name = name > > self.attend_date = attend_date > > self.distance = distance > > > > @classmethod > > def get_person(self, employee): > > print (employee['name']) > > > > return PERSONDatabase(employee['created_at'], > > employee['id'], > > employee['name'], > > employee['attend_date'], > > employee['distance']) > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > 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 cs at cskk.id.au Wed Jan 27 00:55:08 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Wed, 27 Jan 2021 16:55:08 +1100 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: On 27Jan2021 00:19, C W wrote: >Here's the code again, class should be called PERSONDatabase, >misspelled >earlier: >class PERSONDatabase: > def __init__(self, id, created_at, name, attend_date, distance): > self._id = id > self.created_at = created_at > self.name= name > self.attend_date = attend_date > self.distance = distance Here's you're setting attributes (which is a very normal thing to do). > @classmethod > def get_person(self, employee): > return PERSONDatabase(employee['created_at'], > employee['id'], > employee['name'], > employee['attend_date'], > employee['distance']) I think this "employee" is called "person" in the code the traceback came from. It is better when these two things match. >The PERSONDatabase class is called from main. This is the trace back I got >from the VS code: > >Traceback (most recent call last): > File "/Users/Mike/Documents/Mike/main.py", line 95, in > main() > File "/Users/Mike/Documents/Mike/main.py", line 86, in main > args = get_feed() > File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed > result = [PERSONatabase.get_person(raw_person) for raw_neo in >raw_objects] > File "/Users/Mike/Documents/Mike/main.py", line 32, in > result = [NEODatabase.get_person(raw_person) for raw_neo in >raw_objects] > File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person > return PERSONDatabase(person['created_at'], >KeyError: 'created_at' Here's you're trying to index another object using a string, which seems to resemble the .created_at attribute in your PERSONDatabase object. I would presume from this that the "person" object at the bottom of the traceback is the "raw_person" called above it. But I do not see raw_person defined anywhere. Are you sure you didn't mean to pass "raw_neo" instead of "raw_person"? That would be more normal, since you're iterating over "raw_objects". Cheers, Cameron Simpson From mazyar.gh9 at gmail.com Wed Jan 27 03:09:26 2021 From: mazyar.gh9 at gmail.com (Maziar Ghasemi) Date: Wed, 27 Jan 2021 11:39:26 +0330 Subject: error Message-ID: Hi i`m use eric6 to python 3.9.1 . when open eric see this: Warning: translation file 'git_en_US' could not be loaded. Using default. and when i try to do repair`s python I see: "C:/user/mazya/AppData/Local/programs/python/python39/python39.dll Verify that you have access to that directory." Please advise me how to resolve this error -- mazyar ghasemi MS student of Razi university From cl at isbd.net Wed Jan 27 04:12:43 2021 From: cl at isbd.net (Chris Green) Date: Wed, 27 Jan 2021 09:12:43 +0000 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. References: Message-ID: Skip Montanaro wrote: > CW> How do you troubleshooting/debugging in Python? > > GE> Mostly I read exception trace and read the code and think about it. > GE> If that doesn't work, I add some print() or syslog() calls. > > CW> I know hardcore computer scientists would tell me about Python debugger. > > GE> I've been writing Python for 20+ years. I've never tried a debugger. > > Agree with Grant on these points. I certainly use gdb to debug C code > (like the interpreter), but for Python code, tracebacks and print > statements pretty much take care of things. I know pdb has been around > for a long while and many people like IDEs, but I've not generally > found them all that useful. I'm stuck in the 90s I guess. > Me too! :-) I tend to use multiple terminal windows so I have the code being edited in one window, run the code in another window and sometimes a third window for looking at configuration etc. Add print statement etc. for debugging. -- Chris Green ? From rosuav at gmail.com Wed Jan 27 04:34:17 2021 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 27 Jan 2021 20:34:17 +1100 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: On Wed, Jan 27, 2021 at 8:21 PM Chris Green wrote: > > Skip Montanaro wrote: > > CW> How do you troubleshooting/debugging in Python? > > > > GE> Mostly I read exception trace and read the code and think about it. > > GE> If that doesn't work, I add some print() or syslog() calls. > > > > CW> I know hardcore computer scientists would tell me about Python debugger. > > > > GE> I've been writing Python for 20+ years. I've never tried a debugger. > > > > Agree with Grant on these points. I certainly use gdb to debug C code > > (like the interpreter), but for Python code, tracebacks and print > > statements pretty much take care of things. I know pdb has been around > > for a long while and many people like IDEs, but I've not generally > > found them all that useful. I'm stuck in the 90s I guess. > > > Me too! :-) > Me three :) I'm of the opinion that everyone should get some experience with the most fundamental form of debugging: trigger the problem with logging active. Sometimes that means reproducing a known problem, other times it means predicting an unknown problem and just always having some useful logging. (That's why your boot sequence inevitably creates a bunch of logs of various forms.) IIDPIO: If In Doubt, Print It Out... just keep that console noisy until you're certain the information won't help you. Some problems are easy to reproduce. You figure out how to make it happen, you adjust your code, you tinker. Sometimes the tinkering will involve a debug harness (like pdb), other times it just requires a few more print() calls, and either way, great! But other problems aren't. Try debugging a weird issue with your web site that shows up only once every two weeks (or worse), and only ever occurs once. You can't run your web server in a debug harness because the problem simply doesn't happen on your local computer. Your only option is to try to log more stuff and wait for the problem to happen again... ChrisA From Bischoop at vimart.net Wed Jan 27 09:30:33 2021 From: Bischoop at vimart.net (Bischoop) Date: Wed, 27 Jan 2021 14:30:33 -0000 (UTC) Subject: imalib cant get From: adresses Message-ID: I don't have much experience with imaplib and for a few days can't manage to get properly, I followed also some tutorial but also met few problems. What I want is to get email addresses from emails I do have in gmail inbox. The code below gets them but then pops an error. When I change the part "for i in range()" as in commented line it gets just the last email. Anybody familiar here with imaplib? import getpass, imaplib import email from email.header import decode_header M = imaplib.IMAP4_SSL('imap.gmail.com') M.login(u, p) M.select() status, messages = M.select("INBOX") di={} # number of top emails to fetch N = 100 # total number of emails messages = int(messages[0]) for i in range(messages, messages-N,-1): #for i in range(messages, N): # fetch the email message by ID res, msg = M.fetch(str(i), "(RFC822)") for response in msg: if isinstance(response, tuple): # parse a bytes email into a message object msg = email.message_from_bytes(response[1]) From, encoding = decode_header(msg.get("From"))[0] if isinstance(From, bytes): From = From.decode(encoding) print("From:", From) print(type(From)) print("="*100) if '<'in From: s = From.index('<') d = From.index('>') q = From[s + 1:d] w = From[0:s - 1] if q in di.values(): pass else: di[w] = q else: if q not in di.values(): b = sum(1 for key in di if key.startswith('Friend')) di[f'Friend{b+1}']=From # close the connection and logout M.close() M.logout() print(di) for i in di.keys(): if 'Friend' in i: print(From,'\n',i,di[i]) b = sum(1 for key in di if key.startswith('Friend')) print(b) raise self.error('%s command error: %s %s' % (name, typ, data)) imaplib.error: FETCH command error: BAD [b'Could not parse command'] Process finished with exit code 1 ======================== From David.Raymond at tomtom.com Wed Jan 27 10:08:31 2021 From: David.Raymond at tomtom.com (David Raymond) Date: Wed, 27 Jan 2021 15:08:31 +0000 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: In regards to the various comments about adding in print() calls what I've found myself doing is to basically always use the logging module, and use logging.debug() for those. Somewhere at the top of the script I'll have a line like... DEBUG = False ...and when initializing the handler to stdout I'll do something like this... toScreen = logging.StreamHandler(sys.stdout) toScreen.setLevel(logging.DEBUG if DEBUG else logging.INFO) That way I can sprinkle in logging.debug("Some message here") in various spots. If things are going wrong I can change DEBUG to True to see them on screen, and when I've fixed it I can just set DEBUG back to False. That way I don't have to try finding all those print() statements that were only there for debugging and comment them out or remove them. As a bonus, if you also set a file logger for example with its level set to logging.DEBUG, then you can have those go into the log file without them cluttering the screen output. As a side effect to using logging I found I also like having the timestamp automatically prepended to my output by the logger. I'd find myself checking in on something I left running in the background and thinking it's been on that step for "a while", but I have no idea how long "a while" really is. So the timestamps help quickly show "been stuck there for 3 hours" vs "just got to that step 3 seconds before I switched to its window" I don't claim these are the best practices :) But figured I'd offer another take on it. From torriem at gmail.com Wed Jan 27 10:49:44 2021 From: torriem at gmail.com (Michael Torrie) Date: Wed, 27 Jan 2021 08:49:44 -0700 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: <9B50E52F-F565-4C78-B736-A7589DE5A433@leafe.com> <667489a6-2322-42f8-3feb-719c0adeb906@gmail.com> Message-ID: On 1/26/21 10:19 PM, C W wrote: > Traceback (most recent call last): > File "/Users/Mike/Documents/Mike/main.py", line 95, in > main() > File "/Users/Mike/Documents/Mike/main.py", line 86, in main > args = get_feed() > File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed > result = [PERSONatabase.get_person(raw_person) for raw_neo in > raw_objects] > File "/Users/Mike/Documents/Mike/main.py", line 32, in > result = [NEODatabase.get_person(raw_person) for raw_neo in > raw_objects] > File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person > return PERSONDatabase(person['created_at'], > KeyError: 'created_at' The actual error is the last part, which is a KeyError on line 24. A key error usually is from a dictionary-like object and it means the requested key is not found in that object. In other words, this person object has no "created_at" key. Hope that makes sense. I do not know why the code you posted refers to "employee" but the traceback refers to "person." In any case the trace back shows you what called what until the error occurred. You can trace the execution of the code simply by following it. main() called get_feed() which set up a list comprehension, which calls get_person() which is where the error is occurring. I'm not following the list comprehension stuff; I don't know why python is first referring to PERSONatabase and then refers to NEODatabase. From tmrsg11 at gmail.com Wed Jan 27 11:21:58 2021 From: tmrsg11 at gmail.com (C W) Date: Wed, 27 Jan 2021 11:21:58 -0500 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: Hi Cameron, Yes, you are correct in all above. There's a mistake in my copy paste. Thanks for pointing that out! On Wed, Jan 27, 2021 at 12:58 AM Cameron Simpson wrote: > On 27Jan2021 00:19, C W wrote: > >Here's the code again, class should be called PERSONDatabase, > >misspelled > >earlier: > >class PERSONDatabase: > > def __init__(self, id, created_at, name, attend_date, distance): > > self._id = id > > self.created_at = created_at > > self.name= name > > self.attend_date = attend_date > > self.distance = distance > > Here's you're setting attributes (which is a very normal thing to do). > > > @classmethod > > def get_person(self, employee): > > return PERSONDatabase(employee['created_at'], > > employee['id'], > > employee['name'], > > employee['attend_date'], > > employee['distance']) > > I think this "employee" is called "person" in the code the traceback > came from. It is better when these two things match. > > >The PERSONDatabase class is called from main. This is the trace back I got > >from the VS code: > > > >Traceback (most recent call last): > > File "/Users/Mike/Documents/Mike/main.py", line 95, in > > main() > > File "/Users/Mike/Documents/Mike/main.py", line 86, in main > > args = get_feed() > > File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed > > result = [PERSONatabase.get_person(raw_person) for raw_neo in > >raw_objects] > > File "/Users/Mike/Documents/Mike/main.py", line 32, in > > result = [NEODatabase.get_person(raw_person) for raw_neo in > >raw_objects] > > File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person > > return PERSONDatabase(person['created_at'], > >KeyError: 'created_at' > > Here's you're trying to index another object using a string, which seems > to resemble the .created_at attribute in your PERSONDatabase object. > > I would presume from this that the "person" object at the bottom of the > traceback is the "raw_person" called above it. But I do not see > raw_person defined anywhere. Are you sure you didn't mean to pass > "raw_neo" instead of "raw_person"? That would be more normal, since > you're iterating over "raw_objects". > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > From paston.cooper at gmail.com Wed Jan 27 11:52:06 2021 From: paston.cooper at gmail.com (Justin Paston-Cooper) Date: Wed, 27 Jan 2021 19:52:06 +0300 Subject: asyncio: Gather over growing list of tasks Message-ID: Hello, Let's say I have a loop where at each iteration, a task which makes an HTTP request to some endpoint is generated, and then the loop sleeps for n seconds. These tasks may throw exceptions. I can call asyncio.gather on these tasks once the loop has finished, but I actually want to stop the loop immediately if an exception is thrown. Is there a solution that would allow me to stop this loop as soon as an exception is thrown by any of these request tasks? Thanks. From flaskee at protonmail.com Wed Jan 27 13:32:07 2021 From: flaskee at protonmail.com (flaskee) Date: Wed, 27 Jan 2021 18:32:07 +0000 Subject: IDE tools to debug in Python? Message-ID: <88OB0d-SjSbvDOqJJmhHDs3oC4IH82IeBifbF3ppQZesLwSjeociw8RZlTQ-6F0YgWpX7pTp3S0soL28Fn9N326EX_jjw20VO3hhwxTZhQA=@protonmail.com> While print() is groovy and all, if anyone runs across a non-pdb python debugger (standalone or IDE-based) please let me know. I too was blessed with IDE-based debugging (in the 90's!) * where you can set break point(s); * have the program stop right before a suspected failure point; * check the contents of ALL variables, and choose whether to restart; * or skip a few lines before restarting; * or change a variable (hot, move back a few lines and restart, etc. * Some, would even let you alter the code a bit before restarting. I too, miss this. Hopefully I did not miss someone mentioning such a python tool in the prior thread. Thanks! From tmrsg11 at gmail.com Wed Jan 27 13:42:56 2021 From: tmrsg11 at gmail.com (C W) Date: Wed, 27 Jan 2021 13:42:56 -0500 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: <9B50E52F-F565-4C78-B736-A7589DE5A433@leafe.com> <667489a6-2322-42f8-3feb-719c0adeb906@gmail.com> Message-ID: For learning purposes, here's the files: https://www.dropbox.com/sh/a3iy40rcvib4uvj/AAADmlM2i6NquWC1SV0nZfnDa?dl=0 Yes, you are correct about "employee" and "person" discrepancies. For now, the list comprehension is where I get stuck. I'd like to know how the experts on here are approaching and debugging this. Bonus if no debugger or breakpoint. Just the good ol' run the function and evaluate/print output for problems. Thanks so much, Mike On Wed, Jan 27, 2021 at 10:53 AM Michael Torrie wrote: > On 1/26/21 10:19 PM, C W wrote: > > Traceback (most recent call last): > > File "/Users/Mike/Documents/Mike/main.py", line 95, in > > main() > > File "/Users/Mike/Documents/Mike/main.py", line 86, in main > > args = get_feed() > > File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed > > result = [PERSONatabase.get_person(raw_person) for raw_neo in > > raw_objects] > > File "/Users/Mike/Documents/Mike/main.py", line 32, in > > result = [NEODatabase.get_person(raw_person) for raw_neo in > > raw_objects] > > File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person > > return PERSONDatabase(person['created_at'], > > KeyError: 'created_at' > > The actual error is the last part, which is a KeyError on line 24. A > key error usually is from a dictionary-like object and it means the > requested key is not found in that object. In other words, this person > object has no "created_at" key. Hope that makes sense. > > I do not know why the code you posted refers to "employee" but the > traceback refers to "person." > > In any case the trace back shows you what called what until the error > occurred. You can trace the execution of the code simply by following > it. main() called get_feed() which set up a list comprehension, which > calls get_person() which is where the error is occurring. I'm not > following the list comprehension stuff; I don't know why python is first > referring to PERSONatabase and then refers to NEODatabase. > -- > https://mail.python.org/mailman/listinfo/python-list > From swistakm at gmail.com Wed Jan 27 13:51:00 2021 From: swistakm at gmail.com (=?utf-8?Q?Micha=C5=82_Jaworski?=) Date: Wed, 27 Jan 2021 19:51:00 +0100 Subject: IDE tools to debug in Python? Message-ID: ?PyCharm has all these debugging capabilities and there is a community edition that you can use for free. If you earn for the living with Python it is worth investing in professional edition though. Micha? Jaworski > Wiadomo?? napisana przez flaskee via Python-list w dniu 27.01.2021, o godz. 19:32: > > ? > While print() is groovy and all, > if anyone runs across a non-pdb python debugger (standalone or IDE-based) > please let me know. > > I too was blessed with IDE-based debugging (in the 90's!) > * where you can set break point(s); > * have the program stop right before a suspected failure point; > * check the contents of ALL variables, and choose whether to restart; > * or skip a few lines before restarting; > * or change a variable (hot, move back a few lines and restart, etc. > * Some, would even let you alter the code a bit before restarting. > > I too, miss this. > > > Hopefully I did not miss someone mentioning > such a python tool in the prior thread. > > Thanks! > > -- > https://mail.python.org/mailman/listinfo/python-list From zljubisic at gmail.com Wed Jan 27 14:04:04 2021 From: zljubisic at gmail.com (Zoran) Date: Wed, 27 Jan 2021 11:04:04 -0800 (PST) Subject: How to accept argparse.log_level parameter and propagate its value to all other modules Message-ID: In the same folder I have three files: main.py, app_logger.py and mymodule.py with their contents: # main.py import argparse import app_logger import mymodule import logging logger = app_logger.get_logger(__name__) def log_some_messages(): logger.debug(f'{__name__} - debug message') logger.info(f'{__name__} - info message') logger.warning(f'{__name__} - warning message') if __name__ == '__main__': parser = argparse.ArgumentParser(description="Script for executing data quality checks.") parser.add_argument("--log-level", default='info', choices=['notset', 'debug', 'info', 'warning', 'error', 'critical'], help="set log level") args = parser.parse_args() logger.setLevel(eval(f"logging.{args.log_level.upper()}")) log_some_messages() mymodule.log_some_messages() #mymodule.py import logging from script_logging import app_logger logger = app_logger.get_logger(__name__) def log_some_messages(): logger.debug(f'{__name__} - debug message') logger.info(f'{__name__} - info message') logger.warning(f'{__name__} - warning message') #app_logger.py import logging _log_format = f"%(asctime)s - [%(levelname)s] - %(name)s - (%(filename)s).%(funcName)s(%(lineno)d) - %(message)s" _log_level = logging.DEBUG def get_stream_handler(): stream_handler = logging.StreamHandler() stream_handler.setLevel(_log_level) stream_handler.setFormatter(logging.Formatter(_log_format)) return stream_handler def get_logger(name): logger = logging.getLogger(name) logger.setLevel(_log_level) logger.addHandler(get_stream_handler()) return logger When I run it with main.py --log-level debug I get the following output: 2021-01-25 13:21:01,151 - [DEBUG] - __main__ - (main.py).log_some_messages(10) - __main__ - debug message 2021-01-25 13:21:01,151 - [INFO] - __main__ - (main.py).log_some_messages(11) - __main__ - info message 2021-01-25 13:21:01,152 - [WARNING] - __main__ - (main.py).log_some_messages(12) - __main__ - warning message 2021-01-25 13:21:01,152 - [DEBUG] - mymodule - (mymodule.py).log_some_messages(10) - mymodule - debug message 2021-01-25 13:21:01,152 - [INFO] - mymodule - (mymodule.py).log_some_messages(11) - mymodule - info message 2021-01-25 13:21:01,152 - [WARNING] - mymodule - (mymodule.py).log_some_messages(12) - mymodule - warning message which is OK. If I change --log-level parameter to 'warning', than output is the following: 2021-01-25 13:22:12,760 - [WARNING] - __main__ - (main.py).log_some_messages(12) - __main__ - warning message 2021-01-25 13:22:12,760 - [DEBUG] - mymodule - (mymodule.py).log_some_messages(10) - mymodule - debug message 2021-01-25 13:22:12,761 - [INFO] - mymodule - (mymodule.py).log_some_messages(11) - mymodule - info message 2021-01-25 13:22:12,761 - [WARNING] - mymodule - (mymodule.py).log_some_messages(12) - mymodule - warning message As you can see, in main.py log level is set correctly, but in mymodule.py it is not. How to accept argparse.log_level parameter in if __name__ == '__main__': and propagate its value to all other modules? From tmrsg11 at gmail.com Wed Jan 27 14:07:38 2021 From: tmrsg11 at gmail.com (C W) Date: Wed, 27 Jan 2021 14:07:38 -0500 Subject: IDE tools to debug in Python? In-Reply-To: References: Message-ID: I'm not expert in Python, but I sure tried many IDEs to kick off Python programming. I started with PyCharm, but I had a problem with it constantly scanning the background, even after I turned that feature off. My favorite (I'm using now) is VS Code with Python extension, it's very light. Recently also started background scanning, but that's generally done in 30 seconds. On Wed, Jan 27, 2021 at 1:51 PM Micha? Jaworski wrote: > PyCharm has all these debugging capabilities and there is a community > edition that you can use for free. If you earn for the living with Python > it is worth investing in professional edition though. > > Micha? Jaworski > > > Wiadomo?? napisana przez flaskee via Python-list > w dniu 27.01.2021, o godz. 19:32: > > > > ? > > While print() is groovy and all, > > if anyone runs across a non-pdb python debugger (standalone or IDE-based) > > please let me know. > > > > I too was blessed with IDE-based debugging (in the 90's!) > > * where you can set break point(s); > > * have the program stop right before a suspected failure point; > > * check the contents of ALL variables, and choose whether to restart; > > * or skip a few lines before restarting; > > * or change a variable (hot, move back a few lines and restart, etc. > > * Some, would even let you alter the code a bit before restarting. > > > > I too, miss this. > > > > > > Hopefully I did not miss someone mentioning > > such a python tool in the prior thread. > > > > Thanks! > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > From maillist at schwertberger.de Wed Jan 27 14:34:27 2021 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Wed, 27 Jan 2021 20:34:27 +0100 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: <87b26d73-399b-67f7-7660-92ab67bedf15@schwertberger.de> On 27.01.2021 01:52, Skip Montanaro wrote: > Agree with Grant on these points. I certainly use gdb to debug C code > (like the interpreter), but for Python code, tracebacks and print > statements pretty much take care of things. I thought so for the first 12 year of using Python. For the last 12 years I have been using an IDE/debugger with built-in console. It boosted productivity by at least a factor of two. Sometimes "python -i ..." and "import pdb" is good enough, being able to inspect variables after an exception. I have the impression that pdb as post mortem debugger is not well known... Regards, Dietmar From maillist at schwertberger.de Wed Jan 27 14:27:54 2021 From: maillist at schwertberger.de (Dietmar Schwertberger) Date: Wed, 27 Jan 2021 20:27:54 +0100 Subject: IDE tools to debug in Python? In-Reply-To: References: Message-ID: <403a855f-e0fa-36a9-d570-d4c480291553@schwertberger.de> On 27.01.2021 20:07, C W wrote: > I'm not expert in Python, but I sure tried many IDEs to kick off Python > programming. > > I started with PyCharm, but I had a problem with it constantly scanning the > background, even after I turned that feature off. > > My favorite (I'm using now) is VS Code with Python extension, it's very > light. Recently also started background scanning, but that's generally done > in 30 seconds. There's also Wing IDE (Pro). The best is to try at least PyCharm and Wing IDE (Pro) and maybe one or more of the others. Besides the debugger experience from the 90's please note that stepping through a program is not the most valuable feature of the Python debuggers: Python is an interactive language. You can develop a lot while working on a Python console. Then copy and paste into a program. Especially for hardware control, network programming and GUI development I find that the most valuable feature of Python. (Maybe you have used Forth in the 90s as well, then you will know this feature.) The better debuggers have a built-in console. See here for a screenshot of Wing's debug console exploring GUI code: http://wxglade.sourceforge.net/docs/_images/Calculator_Debugger.png Regards, Dietmar From flaskee at protonmail.com Wed Jan 27 14:44:28 2021 From: flaskee at protonmail.com (flaskee) Date: Wed, 27 Jan 2021 19:44:28 +0000 Subject: IDE tools to debug in Python? In-Reply-To: References: Message-ID: <8-obA2Uq5NWJNhaLeSIPjkHM9SWwWm20X7KVD21lvpUqEWjlgDybhp8GwoXo1MZ4umyd6LyhvxRkTlBFWf5EGCEoiA5x-lpe56BDh-TjjAg=@protonmail.com> " also started background scanning, but that's generally done in 30 seconds." Do we know what PyCharm is background scanning for? Do we know what VS Code is scanning for? I've been leery of VS* things since 2013, when Microsoft (secretly) changed their VS compiler, so that every single .exe, .dll, etc that was compiled; included a tiny API call, that dialed back to Microsoft. Even a Hello-World.exe would get this telemetry API embedded. So, if you distributed executables -- MS knew right where they went to, when the user ran them. There was "outrage" when Microsoft was finally caught; and they backed off of this in the next version (I do not know if they've snuck it in again or not). But it did not raise my confidence in tools from Microsoft all that much. I love Python. I just want to add a real debugger ;-) Sent with [ProtonMail](https://protonmail.com) Secure Email. ??????? Original Message ??????? On Wednesday, January 27, 2021 2:07 PM, C W wrote: > I'm not expert in Python, but I sure tried many IDEs to kick off Python programming. > > I started with PyCharm, but I had a problem with it constantly scanning the background, even after I turned that feature off. > > My favorite (I'm using now) is VS Code with Python extension, it's very light. Recently also started background scanning, but that's generally done in 30 seconds. > > On Wed, Jan 27, 2021 at 1:51 PM Micha? Jaworski wrote: > >> PyCharm has all these debugging capabilities and there is a community edition that you can use for free. If you earn for the living with Python it is worth investing in professional edition though. >> >> Micha? Jaworski >> >>> Wiadomo?? napisana przez flaskee via Python-list w dniu 27.01.2021, o godz. 19:32: >>> >>> ? >>> While print() is groovy and all, >>> if anyone runs across a non-pdb python debugger (standalone or IDE-based) >>> please let me know. >>> >>> I too was blessed with IDE-based debugging (in the 90's!) >>> * where you can set break point(s); >>> * have the program stop right before a suspected failure point; >>> * check the contents of ALL variables, and choose whether to restart; >>> * or skip a few lines before restarting; >>> * or change a variable (hot, move back a few lines and restart, etc. >>> * Some, would even let you alter the code a bit before restarting. >>> >>> I too, miss this. >>> >>> >>> Hopefully I did not miss someone mentioning >>> such a python tool in the prior thread. >>> >>> Thanks! >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list From Bischoop at vimart.net Wed Jan 27 14:49:54 2021 From: Bischoop at vimart.net (Bischoop) Date: Wed, 27 Jan 2021 19:49:54 -0000 (UTC) Subject: imalib cant get From: adresses References: Message-ID: On 2021-01-27, Bischoop wrote: Solved using IMAP4.uid. From grant.b.edwards at gmail.com Wed Jan 27 15:17:01 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 27 Jan 2021 20:17:01 -0000 (UTC) Subject: IDE tools to debug in Python? References: Message-ID: On 2021-01-27, C W wrote: > I'm not expert in Python, but I sure tried many IDEs to kick off Python > programming. > > I started with PyCharm, but I had a problem with it constantly scanning the > background, even after I turned that feature off. What is it scanning? > My favorite (I'm using now) is VS Code with Python extension, it's very > light. Recently also started background scanning, but that's generally done > in 30 seconds. Same question, what is it scanning? -- Grant From tmrsg11 at gmail.com Wed Jan 27 15:36:12 2021 From: tmrsg11 at gmail.com (C W) Date: Wed, 27 Jan 2021 15:36:12 -0500 Subject: IDE tools to debug in Python? In-Reply-To: References: Message-ID: I don't know exactly, but it shows as inspection on the bottom left corner. I believe it's indexing in the background. On Wed, Jan 27, 2021 at 3:25 PM Grant Edwards wrote: > On 2021-01-27, C W wrote: > > I'm not expert in Python, but I sure tried many IDEs to kick off Python > > programming. > > > > I started with PyCharm, but I had a problem with it constantly scanning > the > > background, even after I turned that feature off. > > What is it scanning? > > > My favorite (I'm using now) is VS Code with Python extension, it's very > > light. Recently also started background scanning, but that's generally > done > > in 30 seconds. > > Same question, what is it scanning? > > -- > Grant > > -- > https://mail.python.org/mailman/listinfo/python-list > From tmrsg11 at gmail.com Wed Jan 27 15:36:48 2021 From: tmrsg11 at gmail.com (C W) Date: Wed, 27 Jan 2021 15:36:48 -0500 Subject: IDE tools to debug in Python? In-Reply-To: References: Message-ID: I meant bottom right corner, not left. opps! On Wed, Jan 27, 2021 at 3:36 PM C W wrote: > I don't know exactly, but it shows as inspection on the bottom left corner. > > I believe it's indexing in the background. > > On Wed, Jan 27, 2021 at 3:25 PM Grant Edwards > wrote: > >> On 2021-01-27, C W wrote: >> > I'm not expert in Python, but I sure tried many IDEs to kick off Python >> > programming. >> > >> > I started with PyCharm, but I had a problem with it constantly scanning >> the >> > background, even after I turned that feature off. >> >> What is it scanning? >> >> > My favorite (I'm using now) is VS Code with Python extension, it's very >> > light. Recently also started background scanning, but that's generally >> done >> > in 30 seconds. >> >> Same question, what is it scanning? >> >> -- >> Grant >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From pbryan at anode.ca Wed Jan 27 15:44:40 2021 From: pbryan at anode.ca (Paul Bryan) Date: Wed, 27 Jan 2021 20:44:40 +0000 Subject: IDE tools to debug in Python? In-Reply-To: References: Message-ID: <010d01774597504d-7a6fa983-caef-461b-95d0-7180103a763f-000000@ca-central-1.amazonses.com> My experience with IntelliJ (related to PyCharm): it scans all source files in the project, compiles them, graphs all dependencies, compiles those (if necessary) or inspects their class bytecode, and so on to build a full graph in memory to support showing errors in real time (highlighting in source) and autocomplete when user is typing. In my experience, it's heavyweight, and creates more reliance on the features of an IDE than I feel is healthy (IDE becomes a crutch). I suspect PyCharm is doing much of the same. On Wed, 2021-01-27 at 15:36 -0500, C W wrote: > I don't know exactly, but it shows as inspection on the bottom left > corner. > > I believe it's indexing in the background. > > On Wed, Jan 27, 2021 at 3:25 PM Grant Edwards > > wrote: > > > On 2021-01-27, C W wrote: > > > I'm not expert in Python, but I sure tried many IDEs to kick off > > > Python > > > programming. > > > > > > I started with PyCharm, but I had a problem with it constantly > > > scanning > > the > > > background, even after I turned that feature off. > > > > What is it scanning? > > > > > My favorite (I'm using now) is VS Code with Python extension, > > > it's very > > > light. Recently also started background scanning, but that's > > > generally > > done > > > in 30 seconds. > > > > Same question, what is it scanning? > > > > -- > > Grant > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > From jpic at yourlabs.org Wed Jan 27 16:09:43 2021 From: jpic at yourlabs.org (J. Pic) Date: Wed, 27 Jan 2021 22:09:43 +0100 Subject: IDE tools to debug in Python? In-Reply-To: <010d01774597504d-7a6fa983-caef-461b-95d0-7180103a763f-000000@ca-central-1.amazonses.com> References: <010d01774597504d-7a6fa983-caef-461b-95d0-7180103a763f-000000@ca-central-1.amazonses.com> Message-ID: Thonny, winpdb/winpdb-rebord, eric4, pudb, web-pdb, vy, mu, netbeans, eclipse, pdbpp... Also see: https://wiki.python.org/moin/PythonDebuggingTools "Changing a variable" -> that's basically evaluating code ? -> supported in all debuggers I suppose From barry at barrys-emacs.org Wed Jan 27 16:29:50 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 27 Jan 2021 21:29:50 +0000 Subject: imalib cant get From: adresses In-Reply-To: References: Message-ID: <41FB96D3-AA2D-4A8B-B2D4-0833539311B1@barrys-emacs.org> Sigh you use a damaged email address for reply does not work. > On 27 Jan 2021, at 14:30, Bischoop wrote: > > > I don't have much experience with imaplib and for a few days can't > manage to get properly, I followed also some tutorial but also met few > problems. > What I want is to get email addresses from emails I do have in gmail > inbox. The code below gets them but then pops an error. > When I change the part "for i in range()" as in commented line it gets > just the last email. > > Anybody familiar here with imaplib? You have assumed that message ID are integers and in order. Where as they are assigned by the IMAP server and are not in order. I'm not even sure that they need to be integers. You need to search the for the messages you want to get back a list of msg_id's. The you can use the loop over the msg id doing operations on them. After you M.select() call M.search() with appropriate params. search is very powerful and will get you only the messages you are interested in. Here is a fragment of some of my code to show the idea: folder_info = self.server.select_folder( folder, readonly=True ) msg_ids = self.server.search( ['ALL'] ) print( msg_ids ) all_msg_info = self.server.fetch( msg_ids, ['FLAGS','ENVELOPE'] ) for msg_id in all_msg_info: msg_info = all_msg_info[ msg_id ] print( '%-40s %s %s' % (msg_info[b'FLAGS'], msg_info[b'ENVELOPE'].date, msg_info[b'ENVELOPE'].subject) ) Barry > > > import getpass, imaplib > import email > from email.header import decode_header > > M = imaplib.IMAP4_SSL('imap.gmail.com') > M.login(u, p) > M.select() > status, messages = M.select("INBOX") > di={} > > # number of top emails to fetch > N = 100 > > # total number of emails > messages = int(messages[0]) > > for i in range(messages, messages-N,-1): > #for i in range(messages, N): > # fetch the email message by ID > res, msg = M.fetch(str(i), "(RFC822)") > for response in msg: > if isinstance(response, tuple): > # parse a bytes email into a message object > msg = email.message_from_bytes(response[1]) > > > From, encoding = decode_header(msg.get("From"))[0] > if isinstance(From, bytes): > From = From.decode(encoding) > print("From:", From) > print(type(From)) > > > print("="*100) > if '<'in From: > s = From.index('<') > d = From.index('>') > q = From[s + 1:d] > w = From[0:s - 1] > if q in di.values(): > pass > else: > di[w] = q > else: > if q not in di.values(): > > b = sum(1 for key in di if key.startswith('Friend')) > di[f'Friend{b+1}']=From > # close the connection and logout > M.close() > M.logout() > > print(di) > for i in di.keys(): > if 'Friend' in i: > print(From,'\n',i,di[i]) > > b = sum(1 for key in di if key.startswith('Friend')) > print(b) > > raise self.error('%s command error: %s %s' % (name, typ, data)) > imaplib.error: FETCH command error: BAD [b'Could not parse command'] > > Process finished with exit code 1 > > > > ======================== > > > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Wed Jan 27 16:59:23 2021 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 Jan 2021 22:59:23 +0100 Subject: How to accept argparse.log_level parameter and propagate its value to all other modules In-Reply-To: References: Message-ID: On 27/01/2021 20:04, Zoran wrote: > In the same folder I have three files: main.py, app_logger.py and mymodule.py with their contents: > > # main.py > import argparse > import app_logger > import mymodule > import logging > > logger = app_logger.get_logger(__name__) > > def log_some_messages(): > logger.debug(f'{__name__} - debug message') > logger.info(f'{__name__} - info message') > logger.warning(f'{__name__} - warning message') > > if __name__ == '__main__': > parser = argparse.ArgumentParser(description="Script for executing data quality checks.") > parser.add_argument("--log-level", default='info', choices=['notset', 'debug', 'info', 'warning', 'error', 'critical'], help="set log level") > args = parser.parse_args() > > logger.setLevel(eval(f"logging.{args.log_level.upper()}")) > > log_some_messages() > mymodule.log_some_messages() > > > #mymodule.py > import logging > > from script_logging import app_logger > > logger = app_logger.get_logger(__name__) > > > def log_some_messages(): > logger.debug(f'{__name__} - debug message') > logger.info(f'{__name__} - info message') > logger.warning(f'{__name__} - warning message') > > > #app_logger.py > import logging > > _log_format = f"%(asctime)s - [%(levelname)s] - %(name)s - (%(filename)s).%(funcName)s(%(lineno)d) - %(message)s" > _log_level = logging.DEBUG > > def get_stream_handler(): > stream_handler = logging.StreamHandler() > stream_handler.setLevel(_log_level) > stream_handler.setFormatter(logging.Formatter(_log_format)) > return stream_handler > > def get_logger(name): > logger = logging.getLogger(name) > logger.setLevel(_log_level) > logger.addHandler(get_stream_handler()) > return logger > > When I run it with main.py --log-level debug I get the following output: > > 2021-01-25 13:21:01,151 - [DEBUG] - __main__ - (main.py).log_some_messages(10) - __main__ - debug message > 2021-01-25 13:21:01,151 - [INFO] - __main__ - (main.py).log_some_messages(11) - __main__ - info message > 2021-01-25 13:21:01,152 - [WARNING] - __main__ - (main.py).log_some_messages(12) - __main__ - warning message > 2021-01-25 13:21:01,152 - [DEBUG] - mymodule - (mymodule.py).log_some_messages(10) - mymodule - debug message > 2021-01-25 13:21:01,152 - [INFO] - mymodule - (mymodule.py).log_some_messages(11) - mymodule - info message > 2021-01-25 13:21:01,152 - [WARNING] - mymodule - (mymodule.py).log_some_messages(12) - mymodule - warning message > > which is OK. If I change --log-level parameter to 'warning', than output is the following: > > 2021-01-25 13:22:12,760 - [WARNING] - __main__ - (main.py).log_some_messages(12) - __main__ - warning message > 2021-01-25 13:22:12,760 - [DEBUG] - mymodule - (mymodule.py).log_some_messages(10) - mymodule - debug message > 2021-01-25 13:22:12,761 - [INFO] - mymodule - (mymodule.py).log_some_messages(11) - mymodule - info message > 2021-01-25 13:22:12,761 - [WARNING] - mymodule - (mymodule.py).log_some_messages(12) - mymodule - warning message > > As you can see, in main.py log level is set correctly, but in mymodule.py it is not. > > How to accept argparse.log_level parameter in if __name__ == '__main__': and propagate its value to all other modules? You just have to set the level in the root logger. The easiest way to achieve that is to forget about your app_logger wrapper around logging and call logging.basicConfig(level=yourlevel, format=yourformat) in main.py and to create the loggers in main and mymodule with logger = logging.getLogger(__name__) From __peter__ at web.de Wed Jan 27 16:59:23 2021 From: __peter__ at web.de (Peter Otten) Date: Wed, 27 Jan 2021 22:59:23 +0100 Subject: How to accept argparse.log_level parameter and propagate its value to all other modules In-Reply-To: References: Message-ID: On 27/01/2021 20:04, Zoran wrote: > In the same folder I have three files: main.py, app_logger.py and mymodule.py with their contents: > > # main.py > import argparse > import app_logger > import mymodule > import logging > > logger = app_logger.get_logger(__name__) > > def log_some_messages(): > logger.debug(f'{__name__} - debug message') > logger.info(f'{__name__} - info message') > logger.warning(f'{__name__} - warning message') > > if __name__ == '__main__': > parser = argparse.ArgumentParser(description="Script for executing data quality checks.") > parser.add_argument("--log-level", default='info', choices=['notset', 'debug', 'info', 'warning', 'error', 'critical'], help="set log level") > args = parser.parse_args() > > logger.setLevel(eval(f"logging.{args.log_level.upper()}")) > > log_some_messages() > mymodule.log_some_messages() > > > #mymodule.py > import logging > > from script_logging import app_logger > > logger = app_logger.get_logger(__name__) > > > def log_some_messages(): > logger.debug(f'{__name__} - debug message') > logger.info(f'{__name__} - info message') > logger.warning(f'{__name__} - warning message') > > > #app_logger.py > import logging > > _log_format = f"%(asctime)s - [%(levelname)s] - %(name)s - (%(filename)s).%(funcName)s(%(lineno)d) - %(message)s" > _log_level = logging.DEBUG > > def get_stream_handler(): > stream_handler = logging.StreamHandler() > stream_handler.setLevel(_log_level) > stream_handler.setFormatter(logging.Formatter(_log_format)) > return stream_handler > > def get_logger(name): > logger = logging.getLogger(name) > logger.setLevel(_log_level) > logger.addHandler(get_stream_handler()) > return logger > > When I run it with main.py --log-level debug I get the following output: > > 2021-01-25 13:21:01,151 - [DEBUG] - __main__ - (main.py).log_some_messages(10) - __main__ - debug message > 2021-01-25 13:21:01,151 - [INFO] - __main__ - (main.py).log_some_messages(11) - __main__ - info message > 2021-01-25 13:21:01,152 - [WARNING] - __main__ - (main.py).log_some_messages(12) - __main__ - warning message > 2021-01-25 13:21:01,152 - [DEBUG] - mymodule - (mymodule.py).log_some_messages(10) - mymodule - debug message > 2021-01-25 13:21:01,152 - [INFO] - mymodule - (mymodule.py).log_some_messages(11) - mymodule - info message > 2021-01-25 13:21:01,152 - [WARNING] - mymodule - (mymodule.py).log_some_messages(12) - mymodule - warning message > > which is OK. If I change --log-level parameter to 'warning', than output is the following: > > 2021-01-25 13:22:12,760 - [WARNING] - __main__ - (main.py).log_some_messages(12) - __main__ - warning message > 2021-01-25 13:22:12,760 - [DEBUG] - mymodule - (mymodule.py).log_some_messages(10) - mymodule - debug message > 2021-01-25 13:22:12,761 - [INFO] - mymodule - (mymodule.py).log_some_messages(11) - mymodule - info message > 2021-01-25 13:22:12,761 - [WARNING] - mymodule - (mymodule.py).log_some_messages(12) - mymodule - warning message > > As you can see, in main.py log level is set correctly, but in mymodule.py it is not. > > How to accept argparse.log_level parameter in if __name__ == '__main__': and propagate its value to all other modules? You just have to set the level in the root logger. The easiest way to achieve that is to forget about your app_logger wrapper around logging and call logging.basicConfig(level=yourlevel, format=yourformat) in main.py and to create the loggers in main and mymodule with logger = logging.getLogger(__name__) From flaskee at protonmail.com Wed Jan 27 17:03:47 2021 From: flaskee at protonmail.com (flaskee) Date: Wed, 27 Jan 2021 22:03:47 +0000 Subject: IDE tools to debug in Python? In-Reply-To: References: <010d01774597504d-7a6fa983-caef-461b-95d0-7180103a763f-000000@ca-central-1.amazonses.com> Message-ID: Thank you J. Pic. Out of everything today, (and given my priority is Python/Flask debugging) it looks like Wing IDE is something to dig into. Thanks Sent with ProtonMail Secure Email. ??????? Original Message ??????? On Wednesday, January 27, 2021 4:09 PM, J. Pic wrote: > Thonny, winpdb/winpdb-rebord, eric4, pudb, web-pdb, vy, mu, netbeans, > eclipse, pdbpp... > > Also see: https://wiki.python.org/moin/PythonDebuggingTools > > "Changing a variable" -> that's basically evaluating code ? -> supported in > > all debuggers I suppose > > ------------------------ > > https://mail.python.org/mailman/listinfo/python-list From Irv at furrypants.com Wed Jan 27 17:21:36 2021 From: Irv at furrypants.com (Irv Kalb) Date: Wed, 27 Jan 2021 14:21:36 -0800 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: <65AEDEA1-1A99-4FB9-8527-9447093F0856@mac.com> References: <65AEDEA1-1A99-4FB9-8527-9447093F0856@mac.com> Message-ID: <6197C046-B7E5-47F0-A1A4-95549852EAAF@furrypants.com> On Jan 26, 2021, at 5:28 PM, William Ray Wing via Python-list wrote: > > > >> On Jan 26, 2021, at 2:00 PM, C W wrote: >> >> Hello everyone, >> >> I'm a long time Matlab and R user working on data science. How do you >> troubleshooting/debugging in Python? >> > > Another approach is to run the code in an IDE. I happen to use Wing, but that is a coincidence. But almost ANY IDE will let you set a break point, then single-step through your code starting at the break point and examine the values of your variables at each step. Sometimes this is an awfully big hammer for what is a head-slapping mistake. But it has never failed me. > > I'm happy with the PyCharm IDE. I created a video showing how to use the debugger in that environment. It's available on YouTube here: https://www.youtube.com/watch?v=cxAOSQQwDJ4 Irv From kevinmwilson1956 at yahoo.com Wed Jan 27 16:19:44 2021 From: kevinmwilson1956 at yahoo.com (Kevin M. Wilson) Date: Wed, 27 Jan 2021 21:19:44 +0000 (UTC) Subject: For example: Question, moving a folder (T061RR7N1) containing a Specific file (ReadCMI), to folder: C:\\...\DUT0 References: <668571509.358864.1611782384113.ref@mail.yahoo.com> Message-ID: <668571509.358864.1611782384113@mail.yahoo.com> for path, dir, files in os.walk(myDestinationFolder): # for path, dir, files in os.walk(destfolder): print('The path is %s: ', path) print(files) os.chdir(mySourceFolder) if not os.path.isfile(myDestinationFolder + file): # if not os.path.isfile(destfolder + file): print('The file is %s: ', file) shutil.copytree(mySourceFolder, myDestinationFolder) # os.rename(path + '\\' + file, myDestinationFolder + file) # os.rename(path + '\\' + file, destfolder + file) os.rename(path + '\\' + file, myDestinationFolder + file) elif os.path.isfile(myDestinationFolder + file): # os.rename(path + '\\' + file, destfolder + file) shutil.copytree(mySourceFolder, myDestinationFolder) So I would very much appreciate your ideas on the above statements!Because...I think I've got the wrong function (os.path.isfile), when I should be (s/b) using a stepped approach!Note: program allows input of ID =?T061RR7N1 (for example)1) find the folder containing "file": where folder =?T061RR7N1, and file is "ReadCMI";?if TRUE, shutil.copytree C:\\...\T061RR7N1\ReadCMI (TO) C:\\...\DUT[?], where [?] is a num from 0 - 15.2) append to?C:\\...\DUT[?]\T061RR7N1, which contains "ReadCMI"! and would you mind telling me why this works (in every example I've found on the internet): r'C:\\anyfolder\\anyotherfolder\\'...what does the "r" signify? If it's 'read', why can't I use the 'a' for append? KMW "The only way to have experience is by?having?the experience"! From tmrsg11 at gmail.com Wed Jan 27 17:41:52 2021 From: tmrsg11 at gmail.com (C W) Date: Wed, 27 Jan 2021 17:41:52 -0500 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: <6197C046-B7E5-47F0-A1A4-95549852EAAF@furrypants.com> References: <65AEDEA1-1A99-4FB9-8527-9447093F0856@mac.com> <6197C046-B7E5-47F0-A1A4-95549852EAAF@furrypants.com> Message-ID: Great tutorial Irv, very simple with if-else example, gets the point across. My main takeaway from the discussion so far is that: you can't troubleshoot Python without some kind of breakpoint or debugger. I suppose I can't take the functional programming debugger style like C, Matlab, or R, and apply it to a OOP language like Python. On Wed, Jan 27, 2021 at 5:26 PM Irv Kalb wrote: > On Jan 26, 2021, at 5:28 PM, William Ray Wing via Python-list < > python-list at python.org> wrote: > > > > > > > >> On Jan 26, 2021, at 2:00 PM, C W wrote: > >> > >> Hello everyone, > >> > >> I'm a long time Matlab and R user working on data science. How do you > >> troubleshooting/debugging in Python? > >> > > > > Another approach is to run the code in an IDE. I happen to use Wing, > but that is a coincidence. But almost ANY IDE will let you set a break > point, then single-step through your code starting at the break point and > examine the values of your variables at each step. Sometimes this is an > awfully big hammer for what is a head-slapping mistake. But it has never > failed me. > > > > > > I'm happy with the PyCharm IDE. I created a video showing how to use the > debugger in that environment. It's available on YouTube here: > > https://www.youtube.com/watch?v=cxAOSQQwDJ4 > > > Irv > > -- > https://mail.python.org/mailman/listinfo/python-list > From jpic at yourlabs.org Wed Jan 27 17:47:20 2021 From: jpic at yourlabs.org (J. Pic) Date: Wed, 27 Jan 2021 23:47:20 +0100 Subject: IDE tools to debug in Python? In-Reply-To: References: <010d01774597504d-7a6fa983-caef-461b-95d0-7180103a763f-000000@ca-central-1.amazonses.com> Message-ID: You're most welcome flaskee, however I would recommend you try them all. Thonny in particular because it distinguishes line from expression which I believe is a unique feature. Personally I have learned to love just pdb, and a whiteboard! Le mer. 27 janv. 2021 ? 23:03, flaskee a ?crit : > > Thank you J. Pic. > > Out of everything today, > (and given my priority is Python/Flask debugging) > it looks like Wing IDE is something to dig into. > > Thanks > > > Sent with ProtonMail Secure Email. > > ??????? Original Message ??????? > On Wednesday, January 27, 2021 4:09 PM, J. Pic wrote: > > > Thonny, winpdb/winpdb-rebord, eric4, pudb, web-pdb, vy, mu, netbeans, > > eclipse, pdbpp... > > > > Also see: https://wiki.python.org/moin/PythonDebuggingTools > > > > "Changing a variable" -> that's basically evaluating code ? -> supported > in > > > > all debuggers I suppose > > > > ------------------------ > > > > https://mail.python.org/mailman/listinfo/python-list > > > From 2QdxY4RzWzUUiLuE at potatochowder.com Wed Jan 27 18:04:12 2021 From: 2QdxY4RzWzUUiLuE at potatochowder.com (2QdxY4RzWzUUiLuE at potatochowder.com) Date: Wed, 27 Jan 2021 17:04:12 -0600 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: <65AEDEA1-1A99-4FB9-8527-9447093F0856@mac.com> <6197C046-B7E5-47F0-A1A4-95549852EAAF@furrypants.com> Message-ID: On 2021-01-27 at 17:41:52 -0500, C W wrote: > Great tutorial Irv, very simple with if-else example, gets the point > across. Disclaimer: I did not watch the video. > My main takeaway from the discussion so far is that: you can't > troubleshoot Python without some kind of breakpoint or debugger. I disagree. :-) Having spent a long time developing and debugging embedded systems (some soft- or hard- real time), I believe that you can troubleshoot programs (regardless of source language) without debuggers. If a system can generate output, then I (the programmer) can change that output, observe the results, and figure out what's working and what's not. Yes, some systems are more painful than others, but yes, some debugging environments are more painful than others, too. A well placed call to print (they're not "print statements" anymore!) can be much more enlightening and much faster than single stepping through code in a debugger, and seeing the output from the same print statement inside a loop can be much better than manually examining variables iteration after iteration and trying to remember what the value was before. The best debugging tool, however, remains your brain. Way before I add a call to print or you set up your debugger, thinking about what went wrong and where to look can solve the problems without resorting to external tools. :-) From duncan at invalid.invalid Wed Jan 27 18:41:18 2021 From: duncan at invalid.invalid (duncan smith) Date: Wed, 27 Jan 2021 23:41:18 +0000 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: <65AEDEA1-1A99-4FB9-8527-9447093F0856@mac.com> <6197C046-B7E5-47F0-A1A4-95549852EAAF@furrypants.com> Message-ID: On 27/01/2021 22:41, C W wrote: > Great tutorial Irv, very simple with if-else example, gets the point > across. > > My main takeaway from the discussion so far is that: you can't troubleshoot > Python without some kind of breakpoint or debugger. > [snip] Really? Duncan From jpic at yourlabs.org Wed Jan 27 19:03:05 2021 From: jpic at yourlabs.org (J. Pic) Date: Thu, 28 Jan 2021 01:03:05 +0100 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: <65AEDEA1-1A99-4FB9-8527-9447093F0856@mac.com> <6197C046-B7E5-47F0-A1A4-95549852EAAF@furrypants.com> Message-ID: Also - https://github.com/cool-RR/pysnooper - https://github.com/andy-landy/traceback_with_variables From torriem at gmail.com Wed Jan 27 19:56:26 2021 From: torriem at gmail.com (Michael Torrie) Date: Wed, 27 Jan 2021 17:56:26 -0700 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: <9B50E52F-F565-4C78-B736-A7589DE5A433@leafe.com> <667489a6-2322-42f8-3feb-719c0adeb906@gmail.com> Message-ID: <38e75399-da5f-5f81-37b7-273b02599d3c@gmail.com> On 1/27/21 11:42 AM, C W wrote: > For learning purposes, here's the files: > https://www.dropbox.com/sh/a3iy40rcvib4uvj/AAADmlM2i6NquWC1SV0nZfnDa?dl=0 > > Yes, you are correct about "employee" and "person" discrepancies. For now, > the list comprehension is where I get stuck. > > I'd like to know how the experts on here are approaching and debugging > this. > > Bonus if no debugger or breakpoint. Just the good ol' run the function and > evaluate/print output for problems. Like I said, the key is in the traceback. It told you exactly what the problem was. And seeing your full code I can now tell you why. There is no "created_at" field in the person dict (I noticed it's now called neo in the code you just posted). The dict is created directly from JSON and there is no "created_at field anywhere in the JSON, which is why you're getting that error. I don't really understand much of the code you posted. There doesn't seem to be any link between the MySQL database and the NEODatabase class and instances. Something is missing and it looks vaguely java-esque, which may not be your best way to work in Python. I'm not sure what you're trying to do so I can't really say much about it. If you want to play with a database abstraction, there are several libraries available, including SQLchemy. From alan.gauld at yahoo.co.uk Wed Jan 27 18:32:59 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 27 Jan 2021 23:32:59 +0000 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: <9B50E52F-F565-4C78-B736-A7589DE5A433@leafe.com> <667489a6-2322-42f8-3feb-719c0adeb906@gmail.com> Message-ID: On 27/01/2021 18:42, C W wrote: > I'd like to know how the experts on here are approaching and debugging > this. > > Bonus if no debugger or breakpoint. Just the good ol' run the function and > evaluate/print output for problems. One option you may like and nobody seems to have mentioned yet is to use the interactive prompt. Simply run the program with the -i flag and the program will stay in the interpreter at the >>> prompt. Similar to what you seem to be used to doing in R... >From there you can print the current value of variables, inspect objects etc. I find it useful sometimes when I'm not on my desktop PC, although usually I jump into winpdb or similar if I need that kind of support. dubuggers and breakpoints combined with watchpoints are very powerful tools and easy to learn. (Although I may be pre-disposed since my first job after uni' was to white-box test 500K lines of C using a VAX command line debugger in batch mode. I wrote over 100K lines of debugger commands!) -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From alan.gauld at yahoo.co.uk Wed Jan 27 18:39:35 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 27 Jan 2021 23:39:35 +0000 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: <65AEDEA1-1A99-4FB9-8527-9447093F0856@mac.com> <6197C046-B7E5-47F0-A1A4-95549852EAAF@furrypants.com> Message-ID: On 27/01/2021 23:04, 2QdxY4RzWzUUiLuE at potatochowder.com wrote: > systems are more painful than others, but yes, some debugging > environments are more painful than others, too. Very true! but a good debugger is a godsend. Howevder... > A well placed call to print (they're not "print statements" anymore!) > can be much more enlightening and much faster than single stepping > through code in a debugger, If you are single stepping more than 2 or 3 lines then you aren't using the debugger properly! Use breakpoints(selected by brain power!) and watches. The watches are like print statements but don;t modify the source code (nothing to remove later!) Anytime I find myself hitting the step button more that a few times I know I'm not using the debugger effectively and rethink. > and seeing the output from the same print > statement inside a loop can be much better than manually examining > variables iteration after iteration and trying to remember what the > value was before. So don't do that, use the debugger. Most of them have conditional breakpoints that will stop only when you need to. > The best debugging tool, however, remains your brain. Amen to that, regardless of any software tool used. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos From alan.gauld at yahoo.co.uk Wed Jan 27 18:44:01 2021 From: alan.gauld at yahoo.co.uk (Alan Gauld) Date: Wed, 27 Jan 2021 23:44:01 +0000 Subject: IDE tools to debug in Python? In-Reply-To: <403a855f-e0fa-36a9-d570-d4c480291553@schwertberger.de> References: <403a855f-e0fa-36a9-d570-d4c480291553@schwertberger.de> Message-ID: On 27/01/2021 19:27, Dietmar Schwertberger wrote: > Python is an interactive language. You can develop a lot while working > on a Python console. Then copy and paste into a program. Absolutely, the humble interactive prompt is often overlooked as a development tool. It's not as good as the "evaluate expression" tool in the Smalltalk workspace, say, but it's close. I habitually use 3 windows: - an editor, a shell command line (to execute the code) and an interactive Python prompt. -- 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 jsf80238 at gmail.com Wed Jan 27 22:33:48 2021 From: jsf80238 at gmail.com (Jason Friedman) Date: Wed, 27 Jan 2021 20:33:48 -0700 Subject: For example: Question, moving a folder (T061RR7N1) containing a Specific file (ReadCMI), to folder: C:\\...\DUT0 In-Reply-To: <668571509.358864.1611782384113@mail.yahoo.com> References: <668571509.358864.1611782384113.ref@mail.yahoo.com> <668571509.358864.1611782384113@mail.yahoo.com> Message-ID: > > > for path, dir, files in os.walk(myDestinationFolder): > # for path, dir, files in os.walk(destfolder): > print('The path is %s: ', path) > print(files) > os.chdir(mySourceFolder) > if not os.path.isfile(myDestinationFolder + file): > # if not os.path.isfile(destfolder + file): > print('The file is %s: ', file) > shutil.copytree(mySourceFolder, myDestinationFolder) > # os.rename(path + '\\' + file, myDestinationFolder + file) > # os.rename(path + '\\' + file, destfolder + file) > os.rename(path + '\\' + file, myDestinationFolder + file) > elif os.path.isfile(myDestinationFolder + file): > # os.rename(path + '\\' + file, destfolder + file) > shutil.copytree(mySourceFolder, myDestinationFolder) > So I would very much appreciate your ideas on the above > statements!Because...I think I've got the wrong function (os.path.isfile), > when I should be (s/b) using a stepped approach!Note: program allows input > of ID = T061RR7N1 (for example)1) find the folder containing "file": where > folder = T061RR7N1, and file is "ReadCMI"; if TRUE, shutil.copytree > C:\\...\T061RR7N1\ReadCMI (TO) C:\\...\DUT[?], where [?] is a num from 0 - > 15.2) append to C:\\...\DUT[?]\T061RR7N1, which contains "ReadCMI"! > > and would you mind telling me why this works (in every example I've found > on the internet): r'C:\\anyfolder\\anyotherfolder\\'...what does the "r" > signify? If it's 'read', why can't I use the 'a' for append? > A few answers and then a question ... "r" in this context is a raw literal, see for example https://www.journaldev.com/23598/python-raw-string. And you probably don't need it. Python and Windows are happy with "c:/path/to/file.txt" for a file path. Some of your code might look end up looking like: full_path = parent + "/" + file See also the os.path.join method ( https://docs.python.org/3/library/os.path.html#os.path.join) and the pathlib module ( https://docs.python.org/3/library/pathlib.html#module-pathlib). If you truly want to move the folder, as opposed to copying it, you can use shutil.move. Does the target folder already exist? What is the rule for determining what the target folder should be named? From zljubisic at gmail.com Thu Jan 28 00:41:40 2021 From: zljubisic at gmail.com (Zoran) Date: Wed, 27 Jan 2021 21:41:40 -0800 (PST) Subject: How to accept argparse.log_level parameter and propagate its value to all other modules In-Reply-To: References: Message-ID: <07f90418-5db2-44b2-b880-5ee0062ec6e9n@googlegroups.com> Yes you are right. I changed the files: # main.py import argparse import mymodule import logging logger = logging.getLogger(__name__) def log_some_messages(): logger.debug(f'{__name__} - debug message') logger.info(f'{__name__} - info message') logger.warning(f'{__name__} - warning message') if __name__ == '__main__': parser = argparse.ArgumentParser(description="Script for executing data quality checks.") parser.add_argument("--log-level", default='info', choices=['notset', 'debug', 'info', 'warning', 'error', 'critical'], help="set log level") args = parser.parse_args() log_level = logging.getLevelName(args.log_level.upper()) logging.basicConfig(level=log_level, format=f"%(asctime)s - [%(levelname)s] - %(name)s - (%(filename)s).%(funcName)s(%(lineno)d) - %(message)s") logger.setLevel(log_level) log_some_messages() mymodule.log_some_messages() #mymodule.py import logging logger = logging.getLogger(__name__) def log_some_messages(): logger.debug(f'{__name__} - debug message') logger.info(f'{__name__} - info message') logger.warning(f'{__name__} - warning message') and everything works as it should. I was milsleaded by this article https://towardsdatascience.com/8-advanced-python-logging-features-that-you-shouldnt-miss-a68a5ef1b62d Thanks. From grant.b.edwards at gmail.com Wed Jan 27 22:09:12 2021 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 28 Jan 2021 03:09:12 -0000 (UTC) Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. References: <65AEDEA1-1A99-4FB9-8527-9447093F0856@mac.com> <6197C046-B7E5-47F0-A1A4-95549852EAAF@furrypants.com> Message-ID: On 2021-01-27, C W wrote: > My main takeaway from the discussion so far is that: you can't troubleshoot > Python without some kind of breakpoint or debugger. How odd. I do it all the time. -- Grant From antoon.pardon at vub.be Thu Jan 28 02:50:14 2021 From: antoon.pardon at vub.be (Antoon Pardon) Date: Thu, 28 Jan 2021 08:50:14 +0100 Subject: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb. In-Reply-To: References: Message-ID: Op 27/01/21 om 05:17 schreef Dan Stromberg: > On Tue, Jan 26, 2021 at 8:13 PM Dan Stromberg wrote: > >> On Tue, Jan 26, 2021 at 4:01 PM C W wrote: >> >>> Hello everyone, >>> >>> I'm a long time Matlab and R user working on data science. How do you >>> troubleshooting/debugging in Python? >>> >> I frequently read tracebacks and think about what's up in the code. >> >> I also often add print functions or logging - empiricism often beats >> theorizing when the problems are weird. >> >> And once in a while I will use pudb - it's probably a pretty good fit for >> a vim user like me, both being curses-based. pdb is sad. There are other >> debuggers for Python: >> https://wiki.python.org/moin/PythonDebuggingTools >> > BTW, there's a new tool I haven't tried yet, that sounds pretty > interesting, especially for newcomers: It's called "friendly traceback" and > can be found at https://pypi.org/project/friendly-traceback/ > > Oh, and of course google search is a terrific tool for deciphering error > messages. I had a look at that and I think I still would prefer this recipe: https://code.activestate.com/recipes/52215-get-more-information-from-tracebacks/ From pieter-l at vanoostrum.org Thu Jan 28 04:20:02 2021 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Thu, 28 Jan 2021 10:20:02 +0100 Subject: Jupyter notebooks to A4 (again) References: Message-ID: Martin Sch??n writes: > Hello all, > > Some years ago I asked about exporting notebooks to pdf in > A4 rather than US Letter. I got help, rather detailed > instructions from you in general and Piet von Oostrum in Who now calls himself Pieter van Oostrum, just like his passport says :) -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From skip.montanaro at gmail.com Thu Jan 28 06:27:58 2021 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Thu, 28 Jan 2021 05:27:58 -0600 Subject: IDE tools to debug in Python? In-Reply-To: References: <403a855f-e0fa-36a9-d570-d4c480291553@schwertberger.de> Message-ID: > > > Python is an interactive language. You can develop a lot while working > > on a Python console. Then copy and paste into a program. > > Absolutely, the humble interactive prompt is often overlooked > as a development tool. It's not as good as the "evaluate > expression" tool in the Smalltalk workspace, say, but it's close. > In an earlier reply I failed to mention Jupyter. It's a pretty awesome environment. Sort of takes the whole concept of "just insert prints" to a new level. I started using it a bit at my last job for financial stuff, and still mostly use it for that, but it's another viable option. Skip > From mal at europython.eu Thu Jan 28 06:55:33 2021 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 28 Jan 2021 12:55:33 +0100 Subject: EuroPython 2021: Getting ready Message-ID: <0fe9d035-d68b-53eb-5e5b-640de0c73c36@europython.eu> We're happy to announce the pre-launch website for this year's EuroPython 2021: * EuroPython 2021 * https://ep2021.europython.eu/ The site comes with an FAQ page, which lists all the information we have for you at the moment. We're repeating the most important part here: EuroPython 2021 will be held online from July 26 - August 1, 2021, using the following structure: - two workshop/training days (July 26 - 27) - three conference days (July 28 - 30) - two sprint days (July 31 - August 1) The next steps are preparing the main conference website, adding content, organizing the call for papers (CFP), setting up the ticket system, the financial aid program, getting everything tested and deployed. Want to join the fun ? ---------------------- We'll have busy weeks ahead of us. If you want to help, please consider contacting us with details on where you would like to contribute. Please write to volunteers at europython.eu. Distributed conferencing ------------------------ We are also looking into setting up, what we call EuroPython Nodes, where attendees can join small groups around the world to attend EuroPython 2021 together. Please see our FAQ entry for details. The idea is still in flux and we'd like to get some feedback from user groups or companies interested in participating: https://ep2021.europython.eu/faq/#nodes PS: We have also moved our blog off of Tumblr and onto our own infrastructure. Hope you like the new design. 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-getting-ready/ Tweet: https://twitter.com/cargodusoir/status/1354756310328356865 Enjoy, -- EuroPython 2021 Team https://www.europython-society.org/ From robin at reportlab.com Thu Jan 28 05:53:51 2021 From: robin at reportlab.com (Robin Becker) Date: Thu, 28 Jan 2021 10:53:51 +0000 Subject: idlelib re-use Message-ID: <1dca24e6-3d43-4cd5-be6d-29e8e29097c0@everest.reportlab.co.uk> I googled in vain for instances where parts of idlelib are re-used in a simplistic way. I would like to use the editor functionality in a tkinter window and also probably run code in a subprocess. Are there any examples around that do these sorts of things? -- Robin Becker From kladit at arcor.de Thu Jan 28 04:48:34 2021 From: kladit at arcor.de (Klaus Dittrich) Date: Thu, 28 Jan 2021 10:48:34 +0100 Subject: _Py_FatalErrorFunc not found Message-ID: <4a643ebd-0e5d-4853-72fc-7f4f449a7295@arcor.de> I need some help. hplip as of late complains : File "/usr/bin/hp-scan", line 40, in import scanext ImportError: /usr/lib/python3.9/site-packages/scanext.so: undefined symbol: _Py_FatalErrorFunc Which module defines this _Py_FatalErrorFunc? Or has the name of this function changed in python-3.9.1? If yes what is its name now? hplip version is the latest, hplip-3.20.11, but they have not taken notice of the problem as far as i know. Any help is much appreciated -- Klaus From barry at barrys-emacs.org Thu Jan 28 15:49:05 2021 From: barry at barrys-emacs.org (Barry Scott) Date: Thu, 28 Jan 2021 20:49:05 +0000 Subject: _Py_FatalErrorFunc not found In-Reply-To: <4a643ebd-0e5d-4853-72fc-7f4f449a7295@arcor.de> References: <4a643ebd-0e5d-4853-72fc-7f4f449a7295@arcor.de> Message-ID: > On 28 Jan 2021, at 09:48, Klaus Dittrich wrote: > > > I need some help. > > hplip as of late complains : > > File "/usr/bin/hp-scan", line 40, in > import scanext > ImportError: /usr/lib/python3.9/site-packages/scanext.so: undefined symbol: _Py_FatalErrorFunc > > Which module defines this _Py_FatalErrorFunc? Python itself defines this. Given this message you have installed scannext.so that was not built against python3.9. Get a python 3.9 version of the package. > > Or has the name of this function changed in python-3.9.1? > If yes what is its name now? Is this code you compiled? If so when you compile against pyton 3.9 dev files you will see errors. > > hplip version is the latest, hplip-3.20.11, but they have not taken notice of the problem as far as i know. > > Any help is much appreciated Barry > -- > Klaus > -- > https://mail.python.org/mailman/listinfo/python-list > From martin.schoon at gmail.com Thu Jan 28 16:41:04 2021 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 28 Jan 2021 21:41:04 GMT Subject: Jupyter notebooks to A4 (again) References: Message-ID: Den 2021-01-28 skrev Pieter van Oostrum : > Martin Sch??n writes: > >> Hello all, >> >> Some years ago I asked about exporting notebooks to pdf in >> A4 rather than US Letter. I got help, rather detailed >> instructions from you in general and Piet von Oostrum in > > Who now calls himself Pieter van Oostrum, just like his passport says :) Sorry, my bad. Any ideas regarding my question? /Martin From martin.schoon at gmail.com Thu Jan 28 16:49:40 2021 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 28 Jan 2021 21:49:40 GMT Subject: Jupyter notebooks to A4 (again) References: Message-ID: Den 2021-01-25 skrev tommy yama : > Hi Martin, > > I noticed that i did use the same , > formats are mentioned in git already. > > https://github.com/jupyter/nbconvert > Are you telling me there are instruction for how to get A4paper format there? I have looked around but... /Martin From tjreedy at udel.edu Thu Jan 28 14:57:31 2021 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 28 Jan 2021 14:57:31 -0500 Subject: idlelib re-use In-Reply-To: <1dca24e6-3d43-4cd5-be6d-29e8e29097c0@everest.reportlab.co.uk> References: <1dca24e6-3d43-4cd5-be6d-29e8e29097c0@everest.reportlab.co.uk> Message-ID: On 1/28/2021 5:53 AM, Robin Becker wrote: > I googled in vain for instances where parts of idlelib are re-used in a > simplistic way. I would like to use the editor functionality in a > tkinter window and also probably run code in a subprocess. > > Are there any examples around that do these sorts of things? turtledemo reuses IDLE's colorizer and read-only textviews. I have seen occasional hints on stackoverflow of other such uses. One barrier to reuse is that the parts are highly interconnected, with numerous import loops. (Changing the form of some imports from 'import x' to 'from x import y' can make IDLE startup fail.) Some objects, like EditorWindow, are too monolithic. You cannot put a toplevel inside another toplevel. Another, for those thinking long term, is that implementation modules in idlelib are defined as private since 3.6 (PEP-434, idlelib.__init__). I pushed for this in order to be able to refactor to reduce interconnections, and break some things apart, and also to switch to ttk widgets. For instance, breaking EditorFrame apart from EditorWindow would allow me to put multiple editors on multiple tabs of a notebook in an application window. It would also allow others to put an editor window in their tkinter window. -- Terry Jan Reedy From bluebox03 at gmail.com Fri Jan 29 02:35:13 2021 From: bluebox03 at gmail.com (tommy yama) Date: Fri, 29 Jan 2021 16:35:13 +0900 Subject: Jupyter notebooks to A4 (again) In-Reply-To: References: Message-ID: Hi, A4article is not indicated in git as you had a look. :( Maybe that format (A4article) was depreciated already? On Fri, Jan 29, 2021 at 6:52 AM Martin Sch??n wrote: > Den 2021-01-25 skrev tommy yama : > > Hi Martin, > > > > I noticed that i did use the same , > > formats are mentioned in git already. > > > > https://github.com/jupyter/nbconvert > > > Are you telling me there are instruction for how to get A4paper > format there? I have looked around but... > > /Martin > -- > https://mail.python.org/mailman/listinfo/python-list > From robin at reportlab.com Fri Jan 29 08:01:42 2021 From: robin at reportlab.com (Robin Becker) Date: Fri, 29 Jan 2021 13:01:42 +0000 Subject: idlelib re-use In-Reply-To: References: <1dca24e6-3d43-4cd5-be6d-29e8e29097c0@everest.reportlab.co.uk> Message-ID: <7c5f8bec-6ac5-4734-bdd5-c4d251be51b6@everest.reportlab.co.uk> Thanks, On 28/01/2021 19:57, Terry Reedy wrote: > On 1/28/2021 5:53 AM, Robin Becker wrote: >> I googled in vain for instances where parts of idlelib are re-used in a simplistic way. I would like to use the editor >> functionality in a tkinter window and also probably run code in a subprocess. >> >> Are there any examples around that do these sorts of things? > > turtledemo reuses IDLE's colorizer and read-only textviews.? I have seen occasional hints on stackoverflow of other such > uses. > > One barrier to reuse is that the parts are highly interconnected, with numerous import loops.? (Changing the form of > some imports from 'import x' to 'from x import y' can make IDLE startup fail.)? Some objects, like EditorWindow, are too > monolithic.? You cannot put a toplevel inside another toplevel. > yes I found this out trying to reuse the editor window and shell. > Another, for those thinking long term, is that implementation modules in idlelib are defined as private since 3.6 > (PEP-434, idlelib.__init__).? I pushed for this in order to be able to refactor to reduce interconnections, and break > some things apart, and also to switch to ttk widgets. > > For instance, breaking EditorFrame apart from EditorWindow would allow me to put multiple editors on multiple tabs of a > notebook in an application window.? It would also allow others to put an editor window in their tkinter window. +1 -- Robin Becker From rlleravega at gmail.com Fri Jan 29 13:29:59 2021 From: rlleravega at gmail.com (Rafael Llera) Date: Fri, 29 Jan 2021 14:29:59 -0400 Subject: Reinstalling Message-ID: Good day; I installed Python3.9.1 and PyCharm two days ago and did a basic tutorial and all went well. My laptop got glitchy and I decided to uninstall and reinstall both apps (don't ask). Now I am having problems starting a project with the interpreter, I cannot find python3. I just uninstalled both apps again and found a lot of *.pyc files, my questions would it help to delete them all before reinstalling again, or is this a different issue. thank you in advance. best regards, Rafael From mats at wichmann.us Fri Jan 29 15:14:54 2021 From: mats at wichmann.us (Mats Wichmann) Date: Fri, 29 Jan 2021 13:14:54 -0700 Subject: Reinstalling In-Reply-To: References: Message-ID: On 1/29/21 11:29 AM, Rafael Llera wrote: > Good day; > > I installed Python3.9.1 and PyCharm two days ago and did a basic tutorial > and all went well. My laptop got glitchy and I decided to uninstall and > reinstall both apps (don't ask). > > Now I am having problems starting a project with the interpreter, I cannot > find python3. > > I just uninstalled both apps again and found a lot of *.pyc files, my > questions would it help to delete them all before reinstalling again, or is > this a different issue. thank you in advance. different issue. not finding the interpreter is pretty much always a path issue. You don't say which operating system you're using. There are pages for the three main ones in the docs that might help, linked off of here: https://docs.python.org/3/using/ If this is a problem *inside* PyCharm, you probably just have to re-teach it where to find an interpreter, whether to use a virtualenv, etc. PyCharm has decent enough docs on that if you just look for interpreter. From Bischoop at vimart.net Sat Jan 30 11:50:07 2021 From: Bischoop at vimart.net (Bischoop) Date: Sat, 30 Jan 2021 16:50:07 -0000 (UTC) Subject: Response for PING in ircbot. Message-ID: Got problem with responding for Ping, tried so many ways to response and always end up with time out or other error. This time: ERROR :(Ping timeout: 264 seconds) Traceback (most recent call last): s.send(bytes('PONG ' + data.split()[1], 'UTF-8')) BrokenPipeError: [Errno 32] Broken pipe while True: time.sleep(2) data=s.recv(2040).decode('utf8') data = data.strip("\n\r") print(data) if data.find ("PING :"): s.send(bytes('PONG ' + data.split()[1], 'UTF-8')) -- Thanks From chomssky2001 at yahoo.co.uk Sat Jan 30 08:56:38 2021 From: chomssky2001 at yahoo.co.uk (jackson kwame) Date: Sat, 30 Jan 2021 13:56:38 +0000 (UTC) Subject: Python lunch and file accessing challenges References: <566294276.635428.1612014998967.ref@mail.yahoo.com> Message-ID: <566294276.635428.1612014998967@mail.yahoo.com> ?Hi I'm new to Python and currently taking part in a Data Science course. Python is the main coding/programming language for the course. We were guided to download the Python application through Anaconda which worked. I have been using Jupyther through a browser to practice Python exercises. However anytime we are given an assignment in Python and I download, it doesn't open in Python.? How can I lunch Python on my PC and secondly how can I open Python files on my PC.?? Thank you. David From rosuav at gmail.com Sat Jan 30 13:31:06 2021 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 31 Jan 2021 05:31:06 +1100 Subject: Python lunch and file accessing challenges In-Reply-To: <566294276.635428.1612014998967@mail.yahoo.com> References: <566294276.635428.1612014998967.ref@mail.yahoo.com> <566294276.635428.1612014998967@mail.yahoo.com> Message-ID: On Sun, Jan 31, 2021 at 5:26 AM jackson kwame via Python-list wrote: > > Hi > > I'm new to Python and currently taking part in a Data Science course. Python is the main coding/programming language for the course. We were guided to download the Python application through Anaconda which worked. I have been using Jupyther through a browser to practice Python exercises. However anytime we are given an assignment in Python and I download, it doesn't open in Python. > > > How can I lunch Python on my PC and secondly how can I open Python files on my PC. > I would recommend looking in your Start menu for Idle, for a start. There are quite a few ways to have lunch with Python, although most of them would end up with the python having lunch with you. So I would recommend looking through your course's instructions for how they advise you to run things. Are you supposed to use a text editor and then run a script? Are you supposed to work interactively? ChrisA From cs at cskk.id.au Sat Jan 30 16:24:45 2021 From: cs at cskk.id.au (Cameron Simpson) Date: Sun, 31 Jan 2021 08:24:45 +1100 Subject: Response for PING in ircbot. In-Reply-To: References: Message-ID: On 30Jan2021 16:50, Bischoop wrote: >Got problem with responding for Ping, tried so many ways to response >and always end up with time out or other error. This time: > >ERROR :(Ping timeout: 264 seconds) >Traceback (most recent call last): > s.send(bytes('PONG ' + data.split()[1], 'UTF-8')) >BrokenPipeError: [Errno 32] Broken pipe This says you're getting EPIPE trying to send. What that means may depend on how your socket was set up, which you do not show. Is it a stream or a datagram, for example? Let's look at the documentation for "send". No, not the docs.python.org documentation, but the underlying system call because the Python socket module is a very thin wrapper for the operating system socket operations. I do not know your operating system, so I'm looking on a Linux system using the command "man 2 send" (which might be spelled "man -s 2 send" on some platforms): Right off the bat it says: The send() call may be used only when the socket is in a connected state (so that the intended recipient is known). The send() call may be used only when the socket is in a onnected state (so that the intended recipient is known). The only difference between send() and write(2) is the presence of flags. With a zero flags argument, send() is equivalent to write(2). Also, the following call send(sockfd, buf, len, flags); is equivalent to sendto(sockfd, buf, len, flags, NULL, 0); where the "NULL, 0" represents "no target address". In Python you have a socket object "s" so that: s.send(... it equivalent to the C code: send(s, ... shown above. So, to your error: you're getting EPIPE (that's the OS error behind BrokenPipeError), and looking in the manual page in the ERRORS section: EPIPE The local end has been shut down on a connection oriented socket. In this case, the process will also receive a SIGPIPE unless MSG_NOSIGNAL is set. and in BUGS: Linux may return EPIPE instead of ENOTCONN. so also looking for ENOTCONN: If sendto() is used on a connection-mode (SOCK_STREAM, SOCK_SEQPACKET) socket, the arguments dest_addr and addrlen are ignored (and the error EISCONN may be returned when they are not NULL and 0), and the error ENOTCONN is returned when the socket was not actually connected. and again in the ERRORS section: ENOTCONN The socket is not connected, and no target has been given. We're back to: what kind of socket it this? A datagram socket (eg UDP) normally requires a target address, typically the address from which you received the first packet (the ping). A stream connection (eg TCP) needs to be connected. If you're got a stream connection, getting a message implies that the connection has been established, and maybe the connection was closed before you sent your reply. More detail needed, particularly: how is the socket set up, and what's doing the sending of the "ping"? Cheers, Cameron Simpson From auriocus at gmx.de Sat Jan 30 17:03:55 2021 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 30 Jan 2021 23:03:55 +0100 Subject: idlelib re-use In-Reply-To: References: <1dca24e6-3d43-4cd5-be6d-29e8e29097c0@everest.reportlab.co.uk> Message-ID: Am 28.01.21 um 20:57 schrieb Terry Reedy: > On 1/28/2021 5:53 AM, Robin Becker wrote: >> I googled in vain for instances where parts of idlelib are re-used in >> a simplistic way. I would like to use the editor functionality in a >> tkinter window and also probably run code in a subprocess. >> >> Are there any examples around that do these sorts of things? > > turtledemo reuses IDLE's colorizer and read-only textviews.? I have seen > occasional hints on stackoverflow of other such uses. > > One barrier to reuse is that the parts are highly interconnected, with > numerous import loops.? (Changing the form of some imports from 'import > x' to 'from x import y' can make IDLE startup fail.)? Some objects, like > EditorWindow, are too monolithic.? You cannot put a toplevel inside > another toplevel. Yes, you can. There are two possiblities, the one is converting the toplevel into a frame with wm_forget(), after which you can simply pack it into another frame. The second one is configuring a frame as a container, which allows to even embed a window from a foreign application. I'm not sure this works on all platforms, though. Christian From pieter-l at vanoostrum.org Sun Jan 31 14:55:02 2021 From: pieter-l at vanoostrum.org (Pieter van Oostrum) Date: Sun, 31 Jan 2021 20:55:02 +0100 Subject: Jupyter notebooks to A4 (again) References: Message-ID: Martin Sch??n writes: > Hello all, > > Some years ago I asked about exporting notebooks to pdf in > A4 rather than US Letter. I got help, rather detailed > instructions from you in general and Piet von Oostrum in > particular. Following the advice helped and I was happy. > > Now it does not work any longer: > > nbconvert failed: A4article > > I am stumped. I have not changed anything and all > looks OK. > > Today I tried up-dating all things Python and Jupyter > but that did not help. > > I have also tried removing the A4 stuff and after > restarting Jupyter I can export to PDF and get US Letter > paper format. > > A quick and (obviously) not very clever internet search > yielded nothing helpful. The template system has changed in nbconvert version 6, so the original templates don't work anymore. And they still haven't supplied standard provisions for A4 paper (like an option or so). Probably a mild case of cultural blindness. I found out how to do it in the new template system, however, there is a bug that gives some troubles. To get all your latex (and therefore also PDF) output in A4 format: Find out where nbconvert expects user templates. Issue the shell command: bash-3.2$ jupyter --paths Look up the data part: ... data: /Users/pieter/Library/Jupyter ... The first one is your personal directory in my case ~/Library/Jupyter. In this directory create the directory nbconvert/templates/latex In this directory create these two files: conf.json -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: conf.json URL: -------------- next part -------------- index.tex.j2 -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: index.tex.j2 URL: -------------- next part -------------- Now jupyter nbconvert --to latex my_nb.ipynb will generate latex with a4paper. If you don't want this to be the default, but you want a special template, let's say A4article, to do this, place these files in a directory .../nbconvert/templates/A4article rather than .../nbconvert/templates/latex. Then you would use jupyter nbconvert --to latex --template A4article my_nb.ipynb However, due to a bug this won't work unless you patch the nbconvert export code. This is a simple one-line patch. See https://github.com/jupyter/nbconvert/pull/1496/commits/a61a2241a87912005720d3412ccd7ef7b5fce6dd -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8DAE142BE17999C4] From pa.daher at icloud.com Sat Jan 30 16:58:53 2021 From: pa.daher at icloud.com (Philipp Daher) Date: Sat, 30 Jan 2021 22:58:53 +0100 Subject: Pyautogui troubles Message-ID: Dear Python-Team, I have just repaired python after running my program which imports pyautogui, closing and reopening it and then getting this: ModuleNotFoundError: No module named ?pyautogui?. Repairing didn?t work and I still get that message. All I did was closing the perfectly working program in 3.9.1 and reopening it in 3.9.1, but after the reopen I got the message. I?ve tried looking for solutions in at least seven developer forums, nothing worked. If it helps, I have Python 3.8 installed on my PC also. I hope you can fix my troubles. Thank you in advance, your help seeker. From torriem at gmail.com Sun Jan 31 20:24:02 2021 From: torriem at gmail.com (Michael Torrie) Date: Sun, 31 Jan 2021 18:24:02 -0700 Subject: Pyautogui troubles In-Reply-To: References: Message-ID: <1c6ac040-d93e-39ac-65f7-ec2bd81ddc44@gmail.com> On 1/30/21 2:58 PM, Philipp Daher via Python-list wrote: > Dear Python-Team, > > I have just repaired python after running my program which imports pyautogui, closing and reopening it and then getting this: ModuleNotFoundError: No module named ?pyautogui?. Repairing didn?t work and I still get that message. All I did was closing the perfectly working program in 3.9.1 and reopening it in 3.9.1, but after the reopen I got the message. I?ve tried looking for solutions in at least seven developer forums, nothing worked. If it helps, I have Python 3.8 installed on my PC also. > > I hope you can fix my troubles. I've never heard of pyautogui. It's not something that ships with Python if I'm not mistaken. Is this something you installed? Note that just because you installed a module under 3.8 does not mean it will automatically be available in 3.9.1. You'll probably have to install it using 3.9.1's pip. From mats at wichmann.us Sun Jan 31 21:41:05 2021 From: mats at wichmann.us (Mats Wichmann) Date: Sun, 31 Jan 2021 19:41:05 -0700 Subject: Pyautogui troubles In-Reply-To: References: Message-ID: On 1/30/21 2:58 PM, Philipp Daher via Python-list wrote: > Dear Python-Team, > > I have just repaired python after running my program which imports pyautogui, closing and reopening it and then getting this: ModuleNotFoundError: No module named ?pyautogui?. Repairing didn?t work and I still get that message. All I did was closing the perfectly working program in 3.9.1 and reopening it in 3.9.1, but after the reopen I got the message. I?ve tried looking for solutions in at least seven developer forums, nothing worked. If it helps, I have Python 3.8 installed on my PC also. > > I hope you can fix my troubles. We can't fix it, but maybe point you to some things to let you fix it :) Sorry if you've already seen this. Remember: a missing module is a path problem. The module is either someplace, or it isn't ("not actually installed" happens often, but apparently isn't your case since things worked previously). And your Python isn't looking in the place the module is (or isn't). Find where the module is installed. Ask Python where it's looking. Here's a sample interactive session: $ python Python 3.8.7 (default, Dec 22 2020, 00:00:00) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.path ['', '/usr/lib64/python38.zip', '/usr/lib64/python3.8', '/usr/lib64/python3.8/lib-dynload', '/home/mats/.local/lib/python3.8/site-packages', '/usr/lib64/python3.8/site-packages', '/usr/lib/python3.8/site-packages'] This article might be a starting point (it's not actually a great article IMO, but it's referenced from several places on the net and it does cover a lot of the topics): https://coderslegacy.com/python-no-module-named-import-error/