Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python pathlib

import pathlib

# path of the given file
print(pathlib.Path("my_file.txt").parent.absolute())

# current working directory
print(pathlib.Path().absolute())
Comment

python module path

import module_name
path = os.path.dirname(module_name.__file__)
Comment

python pathlib os module

import os

# path of the given file
print(os.path.dirname(os.path.abspath("my_file.txt")))

# current working directory
print(os.path.abspath(os.getcwd()))
Comment

os.path module in python 3

import os.path
Comment

pathlib Path python

from pathlib import Path
>>> p = r"C:UsersshaliOneDrivecodesetTheory.pdf"
>>> Path(p).anchor
'C:'
>>> Path(p).parent
WindowsPath('C:/Users/shali/OneDrive/code')
>>> Path(p).name
'setTheory.pdf'
>>> Path(p).stem
'setTheory'
>>> Path(p).suffixes
['.pdf']
Comment

PREVIOUS NEXT
Code Example
Python :: rolling std dev of a pandas series 
Python :: tkinter insert value box 
Python :: change folder name python 
Python :: How to calculate accuracy with two lists in python 
Python :: pandas trim string of all cells 
Python :: convert all columns to float pandas 
Python :: install python to linux 
Python :: how to take first half of list python 
Python :: ocaml returns the last element of a list 
Python :: fill_between matplotlib 
Python :: websocket api python on close 
Python :: how to get the end of a item in a python array 
Python :: pandas change string column to datetime 
Python :: django get all model fields 
Python :: how to save brake lines on textarea in django 
Python :: how to open youtube from google chrome browser instead of internet explorerwhen coding in python 
Python :: python colored text in console 
Python :: django log queryset 
Python :: Dictionary Cache 
Python :: make virtual environment python 
Python :: python trim zero off end of list 
Python :: Get text without inner tags text in selenium 
Python :: tkinter video 
Python :: series object has no attribute split 
Python :: python how to end while loop 
Python :: switch case python 3.10 
Python :: Model In View Django 
Python :: NumPy bitwise_and Syntax 
Python :: numpy arange 
Python :: drop the first 10 values of list python 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =