“Python Current Working Directory” Code-Antworten

Holen Sie sich WD in Python

import os

path = os.getcwd()

print(path)
# /Users/mbp/Documents/my-project/python-snippets/notebook

print(type(path))
# <class 'str'>
Happy Hawk

Python bekommt aktuelles Verzeichnis

import os

print(os.getcwd())
Busy Bat

Arbeitsverzeichnis Python

import os
cwd = os.getcwd()
Happy Hawk

Holen Sie sich eine Datei -Python -Verzeichnis

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))
Agreeable Ape

OS erhalten Sie aktuelles Verzeichnis

import os

#Get Current working Directory
currentDirectory = os.getcwd()

#Change the Current working Directory
os.chdir('/home/varun')
Agreeable Alpaca

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)
Cheerful Chipmunk

Ähnliche Antworten wie “Python Current Working Directory”

Fragen ähnlich wie “Python Current Working Directory”

Weitere verwandte Antworten zu “Python Current Working Directory” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen