To get the current folder path in Python, you can use the os
module as well as the pathlib
module. Here are two examples using each module:
main.py92 chars5 lines
main.py117 chars5 lines
Both of these snippets will print out the current folder path. The first one uses the getcwd()
method from the os
module to get the current working directory, while the second one uses the Path
class from the pathlib
module to create a POSIX-compliant path to the current directory and then resolves any symlinks or relative paths.
gistlibby LogSnag