Answers for "python print current path"

17

python get current directory

import os

print(os.getcwd())
Posted by: Guest on March-02-2021
11

python get current file location

import os
os.path.dirname(os.path.abspath(__file__))
Posted by: Guest on May-11-2020
7

python get full path

import os
# you have to be in the same directory as the file
file = 'myfile.txt'
# or also
file = 'directory/to/myfile.txt'

path = os.path.abspath(file)
Posted by: Guest on May-16-2020
1

sys get current pythonpath

import sys
print(sys.version)
print(sys.path)
Posted by: Guest on February-08-2021
1

python current working directory

# If by "current working directory" you mean 
# the directory in which is saved the script in execution, then:
import os
cwd = os.path.dirname(os.path.realpath(__file__))
print(cwd)
Posted by: Guest on August-24-2021
2

python get path of current file

import pathlib
pathlib.Path(__file__).parent.absolute()
Posted by: Guest on April-04-2020

Code answers related to "python print current path"

Python Answers by Framework

Browse Popular Code Answers by Language