Re: Optimizing Small Python Code
Kais Ayadi wrote at 2021-6-22 08:03 -0700: >Hi There! >this is a small python code executed in 61 steps > >for n in range(1, 7): >print (n) >for x in range(0, n): >print(" ", x) > >can this code be more optimised? You should proceed as follows: implement a task in the most straightforward way possible. Only if you hit a problem look for optimizations -- to solve the problem. Small pieces of code rarely need optimizations -- unless they are called very often. Optimizations often aim to reduce runtime. In your code, the runtime is dominated by the output. Output speed is mostly outside your control. Do not try to optimize the code above for runtime. -- Dieter -- https://mail.python.org/mailman/listinfo/python-list
Re: Optimizing Small Python Code
On 23/06/2021 08.17, Stefan Ram wrote: "Avi Gross" writes: This can be made a one-liner too! LOL! print( '1\n 0\n2\n 0\n 1\n3\n 0\n 1\n 2\n4\n 0\n 1\n 2\n 3\n5\n 0\n 1\n 2\n 3\n 4\n6\n 0\n 1\n 2\n 3\n 4\n 5\n' ) Unless I'm figuring ot wrong, you just took it from O(n^2) to O(1). That deserves a Turing award or something. -- Michael F. Stemper You can lead a horse to water, but you can't make him talk like Mr. Ed by rubbing peanut butter on his gums. -- https://mail.python.org/mailman/listinfo/python-list
Uninstall and Re-install Python - Windows 10 issues
After I uninstalled Python 3.7and Python 3.9 and installed Python 3.9.5 and is displayed in Apps & features: Python 3.9.5 Python 3.9.5 (64-bit), size 101 MB, and Python Launcher, size 1.80 MB Upon checking the python version, I get the following error message: C:\>python --version Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases. In the Start Menu, Python 3.9 shortcut is present, and when I click on that it takes me to Python 3.9(64-bit) CMD. Just to test, I add a print statement. Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print("This is Tuesday") This is Tuesday >>> Python 3.9.5 was installed in the C:\Python3.9.5 folder and it seems that not all the files were downloaded and for some reason, old files were added. On the Local Disk (C:) > Python3.9.5 and the folder created for the installation displays: Folders - DLLs, Doc, include, Lib, libs, Scripts, tcl, Tools The date on the above-mentioned folders is the same date as when Python 3.9.5 was installed (2021/06/21) however, the dates are displayed (2021/05/03) on the rest of the files as below: Text Document - LICENSE, NEWS, Application - python, pythonw Application extention - python3.dll, python39.dll, vcruntime140.dll, vcruntime140_1.dll The dates are different from the date of Python 3.9.5 installation I have no way of fully uninstalling the separate python installations and install a new python version. Can someone kindly assist or direct me to where I can find a solution for this? Thank you, Suretha -- https://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 213, Issue 24
Thank you it worked using the code you gave!!! On Tue, Jun 22, 2021 at 9:33 PM wrote: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-requ...@python.org > > You can reach the person managing the list at > python-list-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > Today's Topics: > >1. Re: PYTHON (Peter Pearson) >2. Re: create an empty RGB image with specified number of cells > (rows, columns) (Dan Stromberg) >3. Re: Subpixel positioning on Tk canvas (Christian Gollwitzer) >4. IDLE is not working after Python installation . (Ayaana Soni) >5. Re: create an empty RGB image with specified number of cells > (rows, columns) (Arak Rachael) >6. Re: create an empty RGB image with specified number of cells > (rows, columns) (Arak Rachael) >7. Re: IDLE is not working after Python installation . (Terry Reedy) >8. Re: IDLE is not working after Python installation . > (Mats Wichmann) > > > > -- Forwarded message -- > From: Peter Pearson > To: python-list@python.org > Cc: > Bcc: > Date: 21 Jun 2021 14:27:05 GMT > Subject: Re: PYTHON > On Mon, 21 Jun 2021 10:33:26 +0530, Ayaana Soni > wrote: > > have installed python from your site. After installation my IDLE doesn't > > work. IDLE is not in my search list. Plz help!! > > "Your site" is ambiguous. > > Does your computer run Windows, Linux, Apple something, ... ? > > -- > To email me, substitute nowhere->runbox, invalid->com. > > > > > -- Forwarded message -- > From: Dan Stromberg > To: Arak Rachael > Cc: Python List > Bcc: > Date: Mon, 21 Jun 2021 12:19:45 -0700 > Subject: Re: create an empty RGB image with specified number of cells > (rows, columns) > I don't know about OpenCV, but here's a way of creating a ppm image file of > arbitrary size and arbitrary solid color: > https://stromberg.dnsalias.org/svn/solid/trunk > > On Mon, Jun 21, 2021 at 4:01 AM Arak Rachael > wrote: > > > Hi guys! > > > > Does anyone know how to do this, if possible with OpenCv? > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > -- Forwarded message -- > From: Christian Gollwitzer > To: python-list@python.org > Cc: > Bcc: > Date: Mon, 21 Jun 2021 23:37:42 +0200 > Subject: Re: Subpixel positioning on Tk canvas > Am 20.06.21 um 01:49 schrieb Terry Reedy: > > On 6/19/2021 12:42 AM, Christian Gollwitzer wrote: > >> Sorry for that answer, but Tkinter does not support many of the most > >> useful extensions for Tcl/Tk, because someone has to write the > >> wrappers. It only supports what is provided by base Tk. Among those I > >> consider useful and use in almost any application are: > > > > Are these extensions included with the tcl/tk distribution, or otherwise > > available from active state? Are this extensions included with Linux > > installations of tcl/tk? Or easily installed? > > Since ActiveState has pulled out the developers of Tcl a few years ago, > I haven't used ActiveTcl anymore. I was surprised to see that they > actually offer a fairly recent version, but it also cannot be simply > downloaded, one has to register. It was unclear to me if it costs money. > > Other people have stepped in to provide Tcl distributions where tese > extensions are included; notable exanples are BAWT by Paul Obermeier > http://www.bawt.tcl3d.org/download.html which offers all of the > mentioned packages (and many more), Androwish/Undroidwish by Christian > Werner which was originally developed for Android, but now works on te > major desktop platforms, http://androwish.org/home/wiki?name=undroidwish > and even kbskit can be mentioned, started by Rene Zaumseil and now > updated in irregular intervals by me https://github.com/auriocus/kbskit > > I haven't checked the major linux distros, but they also might ship with > some of these extensions. > > Concerning installation, it differs. Tablelist (also part of tklib) and > pdf4tcl are pure-Tcl packages and therefore easily installed. > TkDnD, TkTable and tkTreeCtrl are compiled extensions and therefore more > difficult - however, due to the stubs mechanism of Tcl, the version > number of Tcl and C compiler do NOT need to match. Typically a binary > downloaded for the right OS and bitness will work, and compilation from > source works with an autoconf-based configure script. > > Due to ActiveState's failure with the teapot, the Tcl world does now not > any longer have a central repository tool like "pip" which works for > everyone. This has just recently been discussed on comp.lang.tcl, but it > is unlikely to happen in the near future. > > It is of course unrealistic to expect that Tkinte
creating raw AWS log event
When an AWS cloudwatch event is passed to a consumer it looks like this: { "awslogs": { "data": "ewogICAgIm1l..." } } To get the actual message I do this: def _decode(data): compressed_payload = b64decode(data) json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) return json.loads(json_payload) message = _decode(json.dumps(event['awslogs']['data'])) This returns the log message as a string. For my unit tests I need to reverse this - given a message as a string I want to generate the compressed, encoded event structure. I have not been able to get this to work. I have this: message = b'test message' compressed= zlib.compress(message) event['awslogs']['data'] = str(compressed) message = _decode(json.dumps(event['awslogs']['data'])) Traceback (most recent call last): File "", line 1, in File "", line 3, in _decode zlib.error: Error -3 while decompressing data: incorrect header check Anyone see how to make this work? TIA! -- https://mail.python.org/mailman/listinfo/python-list
Re: Uninstall and Re-install Python - Windows 10 issues
Disclaimer: I am no Python or programming expert! However, I recently installed Python 3.9.5 on my Windows 10 laptop, so I may be able to help with some things. On Wed, Jun 23, 2021 at 11:29 AM Suretha Weweje wrote: > > After I uninstalled Python 3.7and Python 3.9 and installed Python 3.9.5 and > is displayed in Apps & features: > > Python 3.9.5 Python 3.9.5 (64-bit), size 101 MB, and > Python Launcher, size 1.80 MB > > Upon checking the python version, I get the following error message: > C:\>python --version > Python was not found; run without arguments to install from the Microsoft > Store, or disable this shortcut from Settings > Manage App Execution > Aliases. Unless you checked the checkbox to add Python to your path in the installer then this is normal. To check your version, instead type: PS C:\Users\boB> py --version Python 3.9.5 If you did not add Python 3.9.5 to your path you will need to use "py" wherever you think you would use "python" to launch whatever, for instance py -m pip install ... if you were going to install a package. BTW, if you *want* to add Python 3.9.5 to your path it is not very difficult to do so. Search online if you do not know how. > In the Start Menu, Python 3.9 shortcut is present, and when I click on that > it takes me to Python 3.9(64-bit) CMD. Just to test, I add a print > statement. > > Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 > bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> print("This is Tuesday") > This is Tuesday > >>> > > Python 3.9.5 was installed in the C:\Python3.9.5 folder and it seems that > not all the files were downloaded and for some reason, old files were added. > > On the Local Disk (C:) > Python3.9.5 and the folder created for the > installation displays: > > Folders - DLLs, Doc, include, Lib, libs, Scripts, tcl, Tools > > The date on the above-mentioned folders is the same date as when Python > 3.9.5 was installed (2021/06/21) however, the dates are displayed > (2021/05/03) on the rest of the files as below: > > Text Document - LICENSE, NEWS, > Application - python, pythonw > Application extention - python3.dll, python39.dll, vcruntime140.dll, > vcruntime140_1.dll > The dates are different from the date of Python 3.9.5 installation I believe these differing dates are normal as I show similar results. For instance the individual files you mention all have the same date of "5/3/2021 5:35 PM" on my laptop. However, the folders all have a date of "5/12/2021 7:25 (or 7:24)PM" with one exception, the "Scripts" folder which has a date of "5/28/2021 9:52 PM". This makes sense to me. The heading for this date/time column in the file explorer is "Date modified". Neither of us have "modified" the dll's for instance. The date of release of Python 3.9.5 was, in fact, "5/3/2021", so that checks out. OTOH, after installing Python 3.9.5 I *later* installed (using pip) pytest and spacy. The most recent of these two installations reflects the "Scripts" folder's date modified stamp. If I go into the "Scripts" folder I do in fact see that pytest was installed earlier and its date modified reflects that correct date and time. As for the other folders I believe (Someone correct me if I am mistaken.) that the folder dates normally reflect the installation date by you as that is when those folders were created. However, if you open one of them and examine the contents you will see that the individual files have the Python 3.9.5 release date since you have not modified those files. > I have no way of fully uninstalling the separate python installations and > install a new python version. As for your Python 3.7 installation still being around it all depends. You will get different results when you originally installed Python 3.7.x if you (1) install for all users; (2) install with administrative privileges; or (3) install just for the current user. For instance I had Python 3.7.x installed prior to installing 3.9.5. I uninstalled Python 3.7.x. But it is still available! If I run "py -3.7 --version" I see it is still there. If I look in my Windows Start folder there is an entry for Python 3.7. What gives? In my case my son also uses my laptop and *he* installed his own version of Python 3.7.x as a *user*. My uninstalling *my* installation of Python 3.7.x did not affect his installation. And since my laptop account has administrator privileges I can still see it in the Start Menu, but *not* in the settings uninstall programs list. Perhaps you are experiencing something similar? I don't fully understand how Windows implements user privileges and the full details of what an administrator account can and cannot see. Wiser heads than mine will have to chime in and explain as needed. HTH! boB Stepp -- https://mail.python.org/mailman/listinfo/python-list
Re: Uninstall and Re-install Python - Windows 10 issues
On 6/23/21 6:47 AM, Suretha Weweje wrote: After I uninstalled Python 3.7and Python 3.9 and installed Python 3.9.5 and is displayed in Apps & features: Python 3.9.5 Python 3.9.5 (64-bit), size 101 MB, and Python Launcher, size 1.80 MB Upon checking the python version, I get the following error message: C:\>python --version Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases. In the Start Menu, Python 3.9 shortcut is present, and when I click on that it takes me to Python 3.9(64-bit) CMD. Just to test, I add a print statement. Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. print("This is Tuesday") This is Tuesday In other words, your Python installation is working fine. So what's the problem? Can someone kindly assist or direct me to where I can find a solution python itself isn't normally in the path. this is in common with every app you install on Windows, where they all go to their own place. some installers force-add their path to the environment, Python gives you a choice, which you can go back to the installer to activate. More commonly, if you use the python.org installer, you also install the Python Launcher which helps with a variety of problems, in particular with making sense of when you have multiple Python versions installed. If you installed that, launch Python by typing "py" (rather than "python"). See here for some more reading: https://docs.python.org/3/using/windows.html -- https://mail.python.org/mailman/listinfo/python-list
RE: Optimizing Small Python Code
Yes, I agree that if you do not need to show your work to a human, then the problem specified could be solved beforeand and a simple print statement would suffice. Ideally you want to make a problem harder such as by specifying an N that varies then testing it with an arbitrary N. But I suggest the item below is not minimal. You can store the printout more compactly as the only symbols out put are tabs, newlines and seven digits. If your language supported some function that expanded a binary string that used say 4 bytes per symbol so it could be printed, or accepted a compressed form of the string and uncompressed it, you might have code like: print(unzip("n*n&&S!~se")) -Original Message- From: Python-list On Behalf Of Michael F. Stemper Sent: Wednesday, June 23, 2021 10:23 AM To: python-list@python.org Subject: Re: Optimizing Small Python Code On 23/06/2021 08.17, Stefan Ram wrote: > "Avi Gross" writes: >> This can be made a one-liner too! LOL! > > print( '1\n 0\n2\n 0\n 1\n3\n 0\n 1\n 2\n4\n 0\n 1\n 2\n 3\n5\n 0\n 1\n 2\n 3\n 4\n6\n 0\n 1\n 2\n 3\n 4\n 5\n' ) Unless I'm figuring ot wrong, you just took it from O(n^2) to O(1). That deserves a Turing award or something. -- Michael F. Stemper You can lead a horse to water, but you can't make him talk like Mr. Ed by rubbing peanut butter on his gums. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: creating raw AWS log event
On Wed, Jun 23, 2021 at 7:05 PM Dennis Lee Bieber wrote: > > On Wed, 23 Jun 2021 10:42:42 -0700, Larry Martell > declaimed the following: > > >def _decode(data): > >compressed_payload = b64decode(data) > >json_payload = zlib.decompress(compressed_payload, 16+zlib.MAX_WBITS) > >return json.loads(json_payload) > > > > >message = b'test message' > >compressed= zlib.compress(message) > >event['awslogs']['data'] = str(compressed) > > Where do you perform a B64 ENCODE operation? > > str() doesn't do that, it just converts the argument to a string which > may mean using escapes for non-printable bytes. B64 converts everything to > printable characters. Copy/paste fail. This is actually the code I tried: message = b'test message' compressed= zlib.compress(message) encoded = b64encode(compressed) event['awslogs']['data'] = str(encoded) message = _decode(json.dumps(event['awslogs']['data'])) -- https://mail.python.org/mailman/listinfo/python-list