Trey Hunner 🐍 on Nostr: In Python, instead of this: BASE_DIR = ...
In Python, instead of this:
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 module, check out the article I published last week:
https://pym.dev/pathlib-module#Python #pathlib
Published at
2024-11-26 03:09:00 UTCEvent JSON
{
"id": "654568b9414673b1bccc58c0ae174b1ffd4d1fcada54a3ac4c3d38d2502dfd85",
"pubkey": "7e9159fbfd5526415c8d2de2e4c7654e3660883f9ccae720a70fa3c1f3cf1f45",
"created_at": 1732590540,
"kind": 1,
"tags": [
[
"proxy",
"https://mastodon.social/@treyhunner/113547053646307508",
"web"
],
[
"t",
"pathlib"
],
[
"t",
"python"
],
[
"proxy",
"https://mastodon.social/users/treyhunner/statuses/113547053646307508",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://mastodon.social/users/treyhunner/statuses/113547053646307508",
"pink.momostr"
],
[
"-"
]
],
"content": "In Python, instead of this:\n\nBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) \n\nI prefer this:\n\nBASE_DIR = pathlib.Path(__file__).resolve().parent.parent\n\nFor more on the magic of Python's pathlib module, check out the article I published last week: https://pym.dev/pathlib-module\n\n#Python #pathlib",
"sig": "ff4046cd31434780117019cfde7239a338402e53d44fa48bcfa17ebf7c236d4ced1aa273c9949326da0051a4c6e6385ee9e74eafbf44b7a4088d6d68f9f91040"
}