Answer by Louis Maddox for Asynchronous requests with Python's Requests
I second Uri's suggestion to use HTTPX, but I often use it in a different way so am adding my answer.I personally use asyncio.run (introduced in Python 3.7) rather than asyncio.gather and also prefer...
View ArticleComment by Louis Maddox on What is the best way to dewarp pages with Python?
Hey, page-dewarp maintainer here, apologies your question didn’t receive a reply for 15 months! I’ve put a lot of effort into improving the docs and I hope my belated reply in this issue resolved it...
View ArticleAnswer by Louis Maddox for Ho to get final SQL query from diesel
It will vary by dialect but here is a little demo of 'compiling' Diesel ORM to SQL(ite)Self-contained Rust script: https://gist.github.com/lmmx/3a712c79f55d84971addea08d4dee953use...
View ArticleAnswer by Louis Maddox for pathlib.Path().glob() and multiple file extension
You can use a function to filter a recursive glob with pathlib.Path.rglobhttps://docs.python.org/3/library/pathlib.html#pathlib-pattern-languagelist(filter(lambda p: p.suffix in [".xls", ".txt"],...
View ArticleHow to match comments on an image using kix anchor (or not) in Google Docs
It's possible to retrieve elements of an open Google Docs document, starting fromDocumentApp.openById(doc_id, folder_id)but the comments on a document are retrieved through the Drive API, with...
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 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 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 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 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 Pandas read_sql() - AttributeError: 'Engine'...
Known bug in 2.2 github.com/pandas-dev/pandas/issues/57049
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 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 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 how to grep ASCII control character
As suggested here, awk portably finds control charactersawk '/\01/'
View ArticleAnswer 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 Counting commas in a line in bash
An example Python command you could run (since it's going to be installed on most modern shells) is:python -c "import pathlib; print({l.count(',') for l in...
View ArticleCreate a new file in git bash
I've got Git for Windows running, I'm not sure if it's supposed to function as a text editor though?I think I installed it with the Vim editor, but in a Git Bash shell how do I create a file, such as...
View ArticlePiping Rscript gives error after output
I wrote a small R script to read JSON, which works fine but upon piping withRscript myscript.R | headthe (full, expected) output comes back with an errorError: ignoring SIGPIPE signalExecution...
View ArticleHow to see logs of Dockerfile build when using custom AWS Lambda container image
AWS Lambda supports container images rather than using the standard Amazon Linux (2) image, but I can't figure out where the logs from the Dockerfile build are stored.I can find and see the logs for...
View Article