Os curdir python 3

Содержание
  1. Python os.curdir
  2. Example
  3. Related

Python os.curdir

The constant string used by the operating system to refer to the current directory.

Also available via os.path.

Example

Examples for Python function os.curdir():

import os# w w w . d e m o 2 s. c om # Path path = "/home/User/Desktop/file.txt" # Path of Start directory start = "/home/User" # Compute the relative file path to the given path from the # the given start directory. relative_path = os.path.relpath(path, start) print(relative_path) path = "/home/User/Desktop/file.txt" # Compute the relative file path # to the given path from the # the current directory. # if we do not specify the start # parameter it will default to # os.curdir i.e current directory relative_path = os.path.relpath(path) print(relative_path) # Path path = "/home/User/Desktop/file.txt" start = "test/home" # Compute the relative file path to the given path from the # the given start directory. relative_path = os.path.relpath(path, start) # Print the relative file path # to the given path from the # the given start directory. print(relative_path) # Path path = "/home/User/Desktop/file.txt" # Path of Start directory start = "/home/User/demo/file.txt" # Compute the relative file path to the given path from the # the given start directory. relative_path = os.path.relpath(path, start) print(relative_path)

demo2s.com | Email: | Demo Source and Support. All rights reserved.

Источник

Читайте также:  Модуль copy python 3
Оцените статью