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.

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

ThePSF,
@ThePSF@fosstodon.org avatar

There are still a few days left to take advantage of the latest #HumbleBundle 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
#python
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 #Python 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 and heads, here's a little puzzle for you to ponder.

I tried implementing the square root estimation algorithm from 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 🗳️
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 #python 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

ehmatthes,
@ehmatthes@fosstodon.org avatar

I updated simple_deploy's test suite to use uv if it's available, and fall back to pip if uv isn't available.

A uv-enabled run takes about 17.5s on my main system. A pip-based run takes about 45s.

On my Windows VM, a uv-enabled run takes about 55s. A pip-based run takes 175s.

webology,
@webology@mastodon.social avatar

@ehmatthes it's about 2x to 3x faster for me too. Switching from "pip-tools compile" to "uv pip compile" is a made-up 10x faster.

I also noticed a huge speed-up when re-installing via uv over pip. Same with the --upgrade flag.

nedbat,
@nedbat@hachyderm.io avatar

Nested loops can sometimes be replaced by one itertools.product() from the #Python stdlib:

nedbat,
@nedbat@hachyderm.io avatar

Are you sure you know how #Python decorators work? This should be no problem! 😈 🤯 🤓

e_nomem,
@e_nomem@hachyderm.io avatar

@nedbat It took me a moment to remember that the execution happens at load but yeah, you can do some pretty bonkers stuff with decorators.

brohrer,
@brohrer@recsys.social avatar
villares, Portuguese
@villares@pynews.com.br avatar
hugovk,
@hugovk@mastodon.social avatar

📣🐍📚 Calling all Python library maintainers!

Python 3.13 is now in beta, with the second of four beta releases out later today!

It's now time to start testing your libraries with 3.13 and report any problems back to CPython so they can be fixed before the big October release. And make any updates you need to upgrade your library; keep an eye out for removals and deprecations.

Here's how to test 3.13 on GitHub Actions:

https://dev.to/hugovk/help-test-python-313-14j1

hynek,
@hynek@mastodon.social avatar

@hugovk My understanding is they already fixed it months ago. Guessing their release process is painful.

cfbolz,
@cfbolz@mastodon.social avatar

@hynek @hugovk I think it's mainly undermaintained (just like everything else) :-(

Posit,
@Posit@fosstodon.org avatar

posit::conf(2024) virtual tickets are now available!
Join us on August 12-14—from all over the world—to live stream the incredible talks and keynotes that will be taking place in Seattle.

We understand that not everyone will be able to make the trip to Seattle this year, so we’re excited to offer a fully virtual offering for everyone as an alternate option.
REGISTER: https://posit.co/conference/

#posit #rstats #python #pydata #DataScience

Posit,
@Posit@fosstodon.org avatar

And if you’re available on June 6, join the Data Science Hangout where you can ask any questions you may have about posit::conf(2024) directly to the conf committee including Hadley Wickham, Posit’s Chief Scientist. https://posit.co/data-science-hangout/

pytexas,
@pytexas@fosstodon.org avatar

Reminder that the PyTexas Meetup is tonight! Come by and chat, hangout, and hear about a journey building an AI app. We'll get started chatting around 7:30pm CST and move on to the main presentation at 8:00pm.

See y'all there!

https://pytexas.org/meetup/join

#PyTexas
#Python
#Meetup
#pythonprogramming

desertplains,
@desertplains@mastodon.social avatar

I wonder if there's a more efficient way of implementing decimal to conversion in

Without recursion, it's ok, but there will be variable assignments operations, which seems to me as something not so efficient, comparing with recursion...

image/png

desertplains,
@desertplains@mastodon.social avatar

@tshirtman @diazona humm interesting. I hope I'm not abusing from your good will but, would you mind to elaborate a bit more, or even send some article for reference? I got curious with the "arbitrarily large numbers". Tks.

tshirtman,
@tshirtman@mas.to avatar

@desertplains
https://docs.python.org/3/library/stdtypes.html#typesnumeric says "Integers have unlimited precision" which is to mean it can use as much memory as needed to store bigger values (until your operating system refuses to give more memory to your process). it's not like the C int type, for example, which will have minimum and maximum possible values.
@diazona

treyhunner, (edited )
@treyhunner@mastodon.social avatar

New article on Python's many command-line tools 📣

Did you know that 3.12 comes bundled with 50 command-line tools? 😮

An HTTP server, a sqlite prompt, a code profiler, and so much more! ✨

https://pym.dev/cli-tools/

hugovk,
@hugovk@mastodon.social avatar

@treyhunner Coming soon in 3.13: a random CLI! 🎲

$ python -m random curry "fish n chips" tacos
curry

$ python -m random 6
6

https://docs.python.org/3.13/library/random.html#random-cli

treyhunner,
@treyhunner@mastodon.social avatar

@hugovk Ooh! I missed this new feature!

This one actually seems really handy 💖

$ python3.13 -m random 6
1
$ python3.13 -m random 3.14159
3.0145311549545397
$ python3.13 -m random this is great
is

I will definitely be updating this article before October. 😁

villares, Portuguese
@villares@pynews.com.br avatar
cheukting_ho,
@cheukting_ho@fosstodon.org avatar

Hey, do you want to vote in the upcoming @ThePSF elections? Don't forget to affirm your intention to vote (please check your email, including spam). Deadline: June 25th 2024. Not a member yet? Check how you can become a voting member here: https://buff.ly/3X2cLhL #Python

leahawasser,
@leahawasser@fosstodon.org avatar

I wrote an overview of @pyOpenSci s second (and my second) experience at https://www.pyopensci.org/blog/recap-pyos-pyconus-2024.html

we had a great time with a record amount of sprinters, open space attendees AND i gave my first talk! I can't wait for next year!

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