Python Forum
portable way to get current directory - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: portable way to get current directory (/thread-19059.html)



portable way to get current directory - Skaperen - Jun-12-2019

does Python have a portable way to get the path of the current (working) directory?


RE: portable way to get current directory - SheeppOSU - Jun-12-2019

Yes, I use it all the time
from pathlib import Path
current_directory = Path(__file__).parent



RE: portable way to get current directory - metulburr - Jun-12-2019

import os
cwd = os.getcwd()



RE: portable way to get current directory - Skaperen - Jun-12-2019

os stuff even works on Windows?


RE: portable way to get current directory - perfringo - Jun-12-2019

From documentation

Output:
os — Miscellaneous operating system interfaces Source code: Lib/os.py This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see open(), if you want to manipulate paths, see the os.path module, and if you want to read all the lines in all the files on the command line see the fileinput module. For creating temporary files and directories see the tempfile module, and for high-level file and directory handling see the shutil module.



RE: portable way to get current directory - Skaperen - Jun-12-2019

what if i want to os.dup2() a file descriptor? i didn't know Windows had file descriptors.