All things Python

CyrilBrulebois,
@CyrilBrulebois@mamot.fr 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,
@CyrilBrulebois@mamot.fr avatar

Brought to you by https://peps.python.org/pep-0632/ 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 https://pypi.org/project/packaging/ was also too much.

o76923,
@o76923@kitty.social 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,
@nedbat@hachyderm.io avatar

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

treyhunner,
@treyhunner@mastodon.social avatar

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

I do not regret my decision.

https://treyhunner.com/2024/06/a-beautiful-python-monstrosity/

#Python

glyph,
@glyph@mastodon.social avatar

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

ramikrispin,
@ramikrispin@mstdn.social 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,
@ramikrispin@mstdn.social 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 )
@davidism@mas.to 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! https://flask-sqlalchemy-lite.readthedocs.io #Python #Flask #SQLAlchemy

ThePSF,
@ThePSF@fosstodon.org 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🐍❤️

https://www.humblebundle.com/books/dive-into-dev-ops-no-starch-books

https://www.humblebundle.com/books/dive-into-dev-ops-no-starch-books

bbelderbos,
@bbelderbos@fosstodon.org 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
@shaft@piaille.fr 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"

https://docs.python.org/3/tutorial/controlflow.html#match-statements

shaft,
@shaft@piaille.fr avatar

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

shaft, (edited )
@shaft@piaille.fr avatar

Haaaan et on peut faire:

case "truc" if bidule:

Ex, sur un parser d'enregistrement DNS

match rr_type:
....case 46 if dnssec:
...

(Le type de Resource Record 46 étant RRSIG)

J'aurai du avant moi

dragfyre, (edited )
@dragfyre@mastodon.sandwich.net 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: https://cryptpad.fr/code/#/2/code/view/W2yHJixW0qyk1BnUcxIwGtxAKszQ54qPngLI9ztwfx8/ (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,
@dragfyre@mastodon.sandwich.net 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 )
@loke@functional.cafe 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,
@hugovk@mastodon.social 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 ()
https://discuss.python.org/t/vote-to-promote-russell-keith-magee/53821

🐛 Tian Gao works on the pdb debugger
https://discuss.python.org/t/vote-to-promote-tian-gao/53895

🏎️ @mdboom works on benchmarking in the Faster CPython team
https://discuss.python.org/t/vote-to-promote-michael-droettboom/54227

That's 5 new so far this year, same as last year 🚀
https://hugovk.github.io/python-core-devs/by-year.html

retiolus,
@retiolus@mamot.fr avatar
ThePSF,
@ThePSF@fosstodon.org 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
https://pyfound.blogspot.com/2024/06/affirm-your-psf-membership-voting-status.html

nedbat,
@nedbat@hachyderm.io 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,
@leahawasser@fosstodon.org 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. 💗

https://www.pyopensci.org/blog/python-packaging-friends-dont-let-friends-package-alone.html

phildini,
@phildini@wandering.shop avatar

Oh this is extremely handy... someone on the core team seems to be really focusing on CLI utilities and I love this
https://mastodon.social/@treyhunner/112554261035770847

  • 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