Answer by Louis Maddox for Convert text to bytes from Bash shell?
I adapted Machinexa's nice answer a little for my needsencoding="utf-8" is the default so no need to passmore concise to just import sys and use directlyHere I'm looking to make a unique set not a list...
View ArticleAnswer by Louis Maddox for how to grep ASCII control character
As suggested here, awk portably finds control charactersawk '/\01/'
View ArticleAnswer by Louis Maddox for python3 dataclass with **kwargs(asterisk)
All of these changes are well-meaning but pretty clearly against the spirit of dataclasses, which is to avoid writing a bunch of boilerplate to set up a class.Python 3.10 introduces the match statement...
View ArticleAnswer by Louis Maddox for Parse mailto urls in Python
I like Alexander's answer but it is in Python 2! We now get urlparse() and parse_qs() from urllib.parse. Also note that sorting the header in reverse puts it in the order: to, from, body.from...
View ArticleAnswer by Louis Maddox for Create a field which is immutable after being set
You now do this (in Pydantic v2) with the Field(frozen=True) kwarg (docs)Immutability ¶The parameter frozen is used to emulate the [frozen dataclass]behaviour. It is used to prevent the field from...
View ArticleComment by Louis Maddox on Pandas read_sql() - AttributeError: 'Engine'...
Known bug in 2.2 github.com/pandas-dev/pandas/issues/57049
View ArticleComment by Louis Maddox on how to install devtoolset-8 / GCC 8 on Amazon Linux 2
The URL is now 404, archived, I changed them to the current ones but the repo no longer works when used as shown
View ArticleComment by Louis Maddox on How can I update Google Colab's Python version?
Not working for Python 3.12, crashes and won't connect on refresh, I had to hard refresh. Appears to have broken something in Colab for this specific notebook! The message says something about not...
View ArticleComment by Louis Maddox on How to maintain Polars DataFrame metadata through...
This does not persist, with_columns (github.com/pola-rs/polars/blob/…) calls a classmethod (github.com/pola-rs/polars/blob/…) which calls __new__ not __init__
View ArticleAnswer by Louis Maddox for Polars: How to reorder columns in a specific order?
I wrote a plugin for this (on GitHub here), please try it out:pip install polars-permutePolars Permute PluginA Polars plugin for easily reordering DataFrame columns.Supports column permutations like...
View ArticleAnswer by Louis Maddox for Does Polars support creating a dataframe from a...
Interesting notes above, I had a look at how you do this and what the considerations are - I wrote a couple of notebooks on it:Notes on tree nestingReading highly nested tree data as Polars...
View Article