ClickHouse CI · @ClickHouseCI
25 followers · 288 posts · Server hostux.social

.Path in can not only lead the `Path('.') / file`, bu be at any place in the expression

In [42]: 'tmp' / Path('build_report_some_name.json')
Out[42]: PosixPath('tmp/build_report_some_name.json')

In [43]: 'tmp' / Path('build_report_some_name.json') / 'some_another_part'
Out[43]: PosixPath('tmp/build_report_some_name.json/some_another_part')

#til #pathlib #python

Last updated 1 year ago

C. · @cazabon
151 followers · 3456 posts · Server mindly.social

@hexylena

I get not liking the "clever" overloading of the division operator. Luckily, you don't have to use it - you can pass a full path as a single string, or a list of strings, and it will Do The Right Thing:

>>> Path("/usr", "lib", "grub")
PosixPath('/usr/lib/grub')

>>> Path("/usr/lib/grub")
PosixPath('/usr/lib/grub')

pathlib is nice because it gives some better, high-level abstractions. Things like `path.relative_to(other_path)` are very natural to read.

[...]

#python #pathlib

Last updated 1 year ago

· @multimeric
359 followers · 377 posts · Server genomic.social

Day 3,406 of wishing Python's tempfile module returned pathlib.Path objects instead of str.

#python #pathlib

Last updated 1 year ago

Edward · @cosmoscalibur
8 followers · 97 posts · Server col.social

La clase del módulo facilita la manipulación de rutas y archivos en . Crea una ruta así: 'ruta = Path('directorio/archivo.txt')'. Interactúa con el sistema de de forma intuitiva y segura

#path #pathlib #python #archivos

Last updated 1 year ago

Anubhav · @anubhav
10 followers · 342 posts · Server hachyderm.io

In a a recent (3.6) program used ".Path" to munge paths. It was a pleasant change from the "str.join" and (fair) "str.split" functions.

#python #pathlib #eye_poking

Last updated 1 year ago

parv · @parvXm
66 followers · 2214 posts · Server mastodon.social

@brettcannon @nedbat Nice (for "[] picking up os.walk()"), as I had wanted that in it in 3.{[89],10} not too long ago.

#pathlib #python

Last updated 2 years ago

aegilops :github::microsoft: · @aegilops
46 followers · 172 posts · Server fosstodon.org

@brettcannon thanks for your work on pathlib!

I used that just yesterday in a project instead of os.path.

#python #pathlib #thankadeveloper

Last updated 2 years ago

Serge Matveenko ♻️☮️Ⓐ · @lig
198 followers · 2464 posts · Server fosstodon.org

Python stdlib's `pathlib.Path.with_suffix` is
utterly broken.

#python #stdlib #pathlib

Last updated 2 years ago

Python Morsels 🐍🍪 · @PythonMorsels
442 followers · 385 posts · Server mastodon.social

RT @treyhunner@twitter.com

Before

import glob

code = []
for name in glob.iglob('**/*.py', recursive=True):
with open(name) as py_f:
code.append(py_f.read())

After ✨

from pathlib import Path

code = [
path.read_text()
for path in Path.cwd().rglob('*.py')
]

🐦🔗: twitter.com/treyhunner/status/

#pathlib

Last updated 2 years ago

Python Morsels 🐍🍪 · @PythonMorsels
442 followers · 385 posts · Server mastodon.social

RT @treyhunner@twitter.com

Before

import os.path
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES_DIR = os.path.join(BASE_DIR, 'templates')

After ✨

from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATES_DIR = BASE_DIR / 'templates'

🐦🔗: twitter.com/treyhunner/status/

#pathlib

Last updated 2 years ago

Trey Hunner 🐍 · @treyhunner
957 followers · 1063 posts · Server mastodon.social

Before

import glob

code = []
for name in glob.iglob('**/*.py', recursive=True):
with open(name) as py_f:
code.append(py_f.read())

After ✨

from pathlib import Path

code = [
path.read_text()
for path in Path.cwd().rglob('*.py')
]

#pathlib

Last updated 2 years ago

Trey Hunner 🐍 · @treyhunner
957 followers · 1063 posts · Server mastodon.social

Before

import os.path
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES_DIR = os.path.join(BASE_DIR, 'templates')

After ✨

from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATES_DIR = BASE_DIR / 'templates'

#pathlib

Last updated 2 years ago

Bite Code · @bitecode
121 followers · 4883 posts · Server framapiaf.org

RT @python_tip@twitter.com

Path.stat().st_size prints size of the file in bytes

docs.python.org/3/library/path

🐦🔗: twitter.com/python_tip/status/

#pathlib

Last updated 5 years ago