If you are a programmer, you must have come across a requirement wherein you need to access the current working directory. The current working directory is the folder where your application is running from.
In this article, I’ll show you three different ways to get current working directory using Python.
Using os.getcwd
Using pathlib.Path.cwd
Using os.path
Here, the __file__ is a special Python build-in variable which contains the path to the currently running script. The os.path.dirname returns the directory name of the given path and the normpath(...) normalizes a path name by collapsing redundant separators.
I hope you enjoyed reading this article. You can also check out the recording of this article on my YouTube channel named Shweta Lodha.
Comments
Post a Comment