Now this is an interesting #Python problem. I don't know if it's a #bug, but it's a change in behaviour that I don't see documented.

I upgraded from #Debian 12/Bookworm to 13/Trixie, so the default Python3 changed from 3.11 to 3.13. A script of mine broke, because `pathlib.Path.is_mount()` changed behaviour when the path is a symlink (at least to a directory).

i.e. I'm testing a path that is a symlink. The symlink points to a directory. That directory *is* a mountpoint. The `.is_mount()` test in 3.11 returned True, while in 3.13 it returns False.

This seems wrong to me. Most path-manipulation functions transparently treat symlinks as if they were the pointed-to object unless you pass an option/flag specifically to say you want the symlink itself.

Gonna have to dig to see what else I can find.

#pathlib #path #is_mount #stdlib #behaviour #symlink #filesystem #mountpoint #mount

🐍 Python + Windows + Lecteurs mappés = 💥

Le bug qui m'a pris 4 versions

❌ Path.mkdir() → G:\\
✅ os.makedirs() → G:\

Sur Windows, pathlib crée un double backslash
avec les lecteurs (G:, H:, ...)

Debug story complète 👉 https://www.syslibre.fr/blog/migration-robotask-python-dpd.html

#Python #Windows #pathlib

Migration RoboTask Python : Le Cauchemar du Double Backslash Windows

4 itérations pour résoudre un bug insidieux avec Path et les lecteurs Windows. Retour d'expérience complet avec solutions.

Join Paths via 3 Methods

Join Paths via 3 Methods This content explores interesting aspects of this topic. The information provided offers valuable insights and perspectives. Understanding this reveals how everyday things are more thoughtful than they appear. Next time you'll notice this detail. This fascinating detail shows how much thought goes into things we take for granted.

#python #coding #programming #tutorial #path #join #pathlib

https://www.youtube.com/watch?v=P4W-CbmGm2c

Join Paths via 3 Methods #join

YouTube

Using #Python's #pathlib to compare two repos and get back some missing files from a "recovered" version of a repo (mostly stuff in .gitignore that is handy not to discard right now).

from pathlib import Path

a = Path('sketch-a-day')
b = Path('sketch-a-day_broken')

files_a = {p.relative_to(a) for p in a.rglob('*')
if '.git' not in str(p)
if 'cache' not in str(p)
if 'checkpoint' not in str(p)
}
files_b = {p.relative_to(b) for p in b.rglob('*')
if '.git' not in str(p)
if 'cache' not in str(p)
if 'checkpoint' not in str(p)
}
missing = files_b - files_a

for p in missing:
(b / p).rename((a / p))

Изучаем Python: модуль pathlib для начинающих с домашним заданием

Забудьте о ручном склеивании строк: с pathlib пути элегантно конструируются с помощью оператора /. Проверка существования, чтение, получение родительской директории — всё это становится методами и атрибутами самого объекта. В результате код получается не просто чище и читабельнее, он становится более надежным и по-настоящему "питоничным" (Pythonic).

https://habr.com/ru/articles/960440/

#pathlib #python #python_для_начинающих #python_для_школьников

Изучаем Python: модуль pathlib для начинающих с домашним заданием

1. Введение: Почему os.path — это прошлое, а pathlib — настоящее и будущее Если вы работаете с файлами в Python, ваша мышечная память, скорее всего, заставляет вас писать import os . Десятилетиями...

Хабр

I’m still a strong believer in PBD - print-based-debugging — but I hate getting stumped for two days because the value I’m printing automatically prints a string, but the value != an actual string so an equality test fails

#python #pathlib

The wonders of #Python on #Windows (via #MSYS2)...

If you run your Python script using "./script.py", then `Path` from #pathlib becomes `PosixPath`.

If you run the same script using "python script.py" instead, then `Path` becomes `WindowsPath`.

Chers!

My Python is a bit rusty, but I came across this today:

envfile = self.doctreedir / ENV_PICKLE_FILENAME

🤣 Go home pathlib, you're drunk.

I mean, I get it. "/" is the directory separator character so let's use the division operator to build pathnames is a thought that someone could have.

#Python #pathlib

Pure Evil
24%
Pure Genius
76%
Poll ended at .
So I mentioned that my project was at the point of being ready to demo…

It kinda is (after fixing some leftover bugs this morning/noon), but there is one thing I still have to be care of because it was functionally a directory traversal vulnerability (not super critical, given the use-case, but then again really not something that should be shipped, even as an MVP), so I’m still working on that…

That said: Python pathlib, WTF is wrong with you for not supporting preventing this
much better‽ Where are methods like .contains_double_dots(), .remove_double_dots(), … and all of those things‽
And no,
.resolve() is not an adequate substitute for so many reasons.

I’m calling it now: A
ton of python projects using pathlib are vulnerable to directory-traversal.

Seriously, this is an issue and I’m shocked that I have never heard anyone bringing it up anywhere!

#python #pathlib #itsec

🦾 - GenAI for Software Engineers Webinar : https://www.eventbrite.com/e/genai-for-software-professionals-tickets-1202810050239?aff=mst
- Using LangChain
- PathLib for File Operations
- When to use range() and slice()
- Usefulness of __init__.py files

Latest My Voyage of Discovery: http://eepurl.com/i7WTrM
Subscribe for more at: http://eepurl.com/iu6PFU

#python #chatgpt #LLm #GenAI #PathLib #range #init #LangChain #MyVOD

GenAI for Software Professionals

Online Webinar on using GenAI as your buddy in Software Development / Analytics activities to improve your productivity.

Eventbrite