If you've been looking for a post to link your pathlib-curious/confused coworkers to, I'm hoping this will help. #Python
pym.dev/pathlib-module
If you've been looking for a post to link your pathlib-curious/confused coworkers to, I'm hoping this will help. #Python
pym.dev/pathlib-module
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
I prefer this:
BASE_DIR = pathlib.Path(__file__).resolve().parent.parent
For more on the magic of #Python's #pathlib, check out the article I published last week:
One nice thing about finally publishing in text form: #Python folks happily provide (frequently) constructive feedback so I can immediately iterate. 💗
pym.dev/pathlib-module
One nice thing about finally publishing in text form: #Python folks happily provide (frequently) constructive feedback so I can immediately iterate. 💗
pym.dev/pathlib-module
>>> old_path.with_stem("README")
PosixPath('uvrs/README.rst')
And to replace the whole name, there's with_name:
>>> old_path.with_name("Read Me.txt")
PosixPath('uvrs/Read Me.txt')
>>> old_path.with_stem("README")
PosixPath('uvrs/README.rst')
And to replace the whole name, there's with_name:
>>> old_path.with_name("Read Me.txt")
PosixPath('uvrs/Read Me.txt')
The entire Python tutorial ecosystem is ahead of the curve on this one
The entire Python tutorial ecosystem is ahead of the curve on this one
Change file extensions with with_suffix. 🧵
A ".rst" file path that needs to turn into a ".md" file path:
>>> from pathlib import Path
>>> old_path = Path("uvrs/readme.rst")
>>> old_path.with_suffix(".md")
PosixPath('uvrs/readme.md')
#Python #DailyPythonTip
Change file extensions with with_suffix. 🧵
A ".rst" file path that needs to turn into a ".md" file path:
>>> from pathlib import Path
>>> old_path = Path("uvrs/readme.rst")
>>> old_path.with_suffix(".md")
PosixPath('uvrs/readme.md')
#Python #DailyPythonTip
Pro-tip: Use `pathlib` for cross-platform file handling in your IR scripts. Stop reinventing the wheel! 🐍🛡️
#PythonSecurity #InfoSec #Automation
Pro-tip: Use `pathlib` for cross-platform file handling in your IR scripts. Stop reinventing the wheel! 🐍🛡️
#PythonSecurity #InfoSec #Automation
If you just want help adopting pathlib in general, use this cheat sheet instead:
pym.dev/pathlib-modu...
This week's tips are all about pathlib patterns & anti-patterns.
If you just want help adopting pathlib in general, use this cheat sheet instead:
pym.dev/pathlib-modu...
This week's tips are all about pathlib patterns & anti-patterns.
Check out #Python's pathlib module.
It's great for splitting/joining paths, finding files by filename patterns, renaming files, and more.
pym.dev/pathlib-module
Check out #Python's pathlib module.
It's great for splitting/joining paths, finding files by filename patterns, renaming files, and more.
pym.dev/pathlib-module
the Pure / Concrete split is quite useful, and std already implements most/all of it but you just don't get access to it
the Pure / Concrete split is quite useful, and std already implements most/all of it but you just don't get access to it
If you're using #Python and not using the pathlib module, check it out. I think that it's one of the most underused modules in the Python standard library.
cool story: renpy hard rejects paths containing backslashes, presumably so windows devs don't make stuff that needlessly fails on unix. But i used pathlib, which produces the native separator,
cool story: renpy hard rejects paths containing backslashes, presumably so windows devs don't make stuff that needlessly fails on unix. But i used pathlib, which produces the native separator,
#Python
#Python
Path().path().le.join()
Path().path().le.join()
Python: Type hints, proper exceptions, pathlib, context managers
JavaScript/TypeScript: const/let, async/await, strict mode, input validation
Go: Check errors, use context.Context, defer for cleanup
Python: Type hints, proper exceptions, pathlib, context managers
JavaScript/TypeScript: const/let, async/await, strict mode, input validation
Go: Check errors, use context.Context, defer for cleanup
Pro-tip: Use `pathlib` for cross-platform file handling in your scripts to avoid headaches. 🐍
#InfoSec #Python #Automation
Pro-tip: Use `pathlib` for cross-platform file handling in your scripts to avoid headaches. 🐍
#InfoSec #Python #Automation
C++ has its own entirely different thing in std::filesystem::path.
github.com/netanel-habe...
C++ has its own entirely different thing in std::filesystem::path.
github.com/netanel-habe...
Well, unlike with strings:
1. It's hard to get yourself into trouble with pathlib.Path
2. When I see a pathlib.Path object, I know we're representing a path
I have a whole talk that might help convince you: trey.io/pathlib-talk
Well, unlike with strings:
1. It's hard to get yourself into trouble with pathlib.Path
2. When I see a pathlib.Path object, I know we're representing a path
I have a whole talk that might help convince you: trey.io/pathlib-talk