All things Python

CyrilBrulebois, avatar

Just reminded that #Python's considerations to anything packaging-related is a trashfire: deprecating distutils, including distutils.version, pointing to an external module that provides “Reusable core utilities for various Python Packaging interoperability specifications.”

CyrilBrulebois, avatar

Brought to you by which handwaves:

“For these modules or types, use the standards-defined Python Packaging Authority packages specified:

distutils.version — use the packaging package”

A link to was also too much.

o76923, avatar

I still think it's nuts that #Python's best solutions for rendering #SVG are a bunch of wrappers around CairoSVG with the two next best solutions being use Inkscape from the command line and wand, a wrapper around ImageMagick.

nedbat, avatar

@o76923 Can you say more about why it's nuts to wrap CairoSVG? Is there something wrong with it?

treyhunner, avatar

I made a decorator that immediately calls the function it decorates within a loop.

I do not regret my decision.


glyph, avatar

@treyhunner I do this all the time. Literally today, even :-)

ramikrispin, avatar

(1/5) 𝐇𝐚𝐩𝐩𝐲 𝐒𝐚𝐭𝐮𝐫𝐝𝐚𝐲! ☀️
Here are a few steps you can take to reduce your Python 🐍 image size 👇🏼

TLDR - Using slim image and multi-stage build

#mlops #python #datascience #docker

ramikrispin, avatar

(2/5) 𝐒𝐥𝐢𝐦 𝐢𝐦𝐚𝐠𝐞
Typically, I use the Python official image as the baseline for setting up a dockerized Python environment. The official Python image offers multiple images for different Linux flavors and CPU architectures. The default image (e.g., 𝘱𝘺𝘵𝘩𝘰𝘯:𝘭𝘢𝘵𝘦𝘴𝘵) has comprehensive supporting tools that impact the image size - 1 GB.

A simple way to reduce the image size is to replace the default image with a slim version that is 150 MB (compared to 1GB) 🚀.

davidism, (edited ) avatar

Announcing Flask-SQLAlchemy-Lite, a new lightweight replacement for Flask-SQLAlchemy that provides engine configuration and session lifetime, but none of the other custom stuff in the prior extension. It works with Flask and Quart, sync and async. I figured out the core idea on the flight to PyCon US, teased it during FlaskCon, and now it's available! Check out the docs to get started! #Python #Flask #SQLAlchemy

ThePSF, avatar

There are still a few days left to take advantage of the latest package from @nostarch: Dive into DevOps!
You can pick up 5 great titles for just $1, or go up to $35 for all 22 items in this "indispensable IT library".
Either way, be sure to use "Adjust Donation" to choose how much of your purchase goes to the PSF🐍❤️

bbelderbos, avatar

@treyhunner does a deep dive of #Python's many command-line utilities. 🙏 🔥

First of all it's good to know that you can use -m to run a Python module as if it were a script 💡

There are some nifty ones like inspect / json.tool / zipapp. You'll surely pick up new ones ... 💪

shaft, (edited ) French avatar

Ah mais 3.10 ajoute une déclaration "match" qui permet d'éviter les longues liste de "if...elif...elif..."

À la place on met:

match la_variable:
\t case "a":
\t case "b":
\t case _:
Ici un "catch-all"

shaft, avatar

@CM63 Le serpent met du temps à digérer et donc assimiler ce qui ce fait ailleurs :)

shaft, (edited ) avatar

Haaaan et on peut faire:

case "truc" if bidule:

Ex, sur un parser d'enregistrement DNS

match rr_type: 46 if dnssec:

(Le type de Resource Record 46 étant RRSIG)

J'aurai du avant moi

dragfyre, (edited ) avatar

Alright #python and #CS heads, here's a little puzzle for you to ponder.

I tried implementing the square root estimation algorithm from #SICP Lecture 1A in Python just for fun (my Lisp skills are weak).

Code: (also, see image.)

Notably, I made the precision variable so that I could see how precise a value I could get. I tried it at lower precision at first and it worked, so I bumped it up. Seemed to work fine, until I got past 16 significant digits... (1/3)

dragfyre, avatar

At that point, I noticed that the values started to diverge at around the 16th decimal place, and it didn't get better as precision increased. In fact, I checked the answer against a calculator app and got a different answer, with completely different digits after the 16th place. So I thought, OK, it's a hardware precision issue.

BUT THEN I tried to estimate the square roots of other numbers (ex.: 1.7, 13, 33) and the difference was ZERO. That is, ONLY the square root of 2 diverged. (2/3)

loke, (edited ) avatar

@dragfyre There is nothing wrong with your algorithm. It gives the correct result within the precision of the number representation you're using.

In your case, you're hitting the limits of 64-bit floating point, and the reason you are getting different results is because the implementation of sqrt that Python uses (which appears to be the default libc implementation) is more accurate than yours for some specific inputs.

I took the libery to do an almost 1-to-1 port of your code to Kap, which allows you to try the same thing using rational arithmetic. When you do so, you get a value that is as precise as you tolerance value:

Click "send" to run the code.

Kap version of the code which supports both types of numbers

I also took your code and tested it on a 100 different values (0 to 5 with a step length of 0.05, and it gives you several other values for which your algorithm gives an imprecise value with floating point arithmetic:

code that computes imprecise guesses

hugovk, avatar

🎉 We just had 3 successful core dev votes in parallel!

Each dev focuses on different yet important areas, reflecting the size & breadth of the CPython project.

Please give a big welcome to:

🍏 @freakboy3742 added iOS support ()

🐛 Tian Gao works on the pdb debugger

🏎️ @mdboom works on benchmarking in the Faster CPython team

That's 5 new so far this year, same as last year 🚀

retiolus, avatar
ThePSF, avatar

We want your vote! Every voting-eligible PSF Member (Supporting, Managing, Contributing, and Fellow) needs to affirm their membership to vote in this year’s Board election to ensure that we meet quorum as required by our bylaws 🗳️ #python

nedbat, avatar

Mostly you shouldn't subclass built-in types. But if you do, dict subclasses can define missing: it's called when a key is missing. Instead of hiding a dict in a function as a cache, how about hiding a function in a dict!? A Fibonacci dictionary:

leahawasser, avatar

i wrote another blog post on my personal experiences with packaging as a teacher, a user and a maintainer. And how giving a tech talk on a big stage felt! (hint: scary!)

i'm curious if others have experienced imposter syndrome and/or challenges navigating our packaging ecosystem / data science ecosystem! let me know what you think. 💗

phildini, avatar

Oh this is extremely handy... someone on the core team seems to be really focusing on CLI utilities and I love this

  • All
  • Subscribed
  • Moderated
  • Favorites
  • python
  • DreamBathrooms
  • ngwrru68w68
  • tester
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • InstantRegret
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • mdbf
  • tacticalgear
  • JUstTest
  • osvaldo12
  • normalnudes
  • cubers
  • cisconetworking
  • everett
  • GTA5RPClips
  • ethstaker
  • Leos
  • provamag3
  • anitta
  • modclub
  • megavids
  • lostlight
  • All magazines