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 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

pathy python

pip install pathy
pip install pathy==0.1.3
Comment

path in python

data_folder = "source_data/text_files/"

file_to_open = data_folder + "raw_data.txt"

f = open(file_to_open)

print(f.read())
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 :: Got AttributeError when attempting to get a value for field `name` on serializer 
Python :: change data type python 
Python :: # read the JSON file and also print the file content in JSON format. 
Python :: python re.search() 
Python :: python input character limit 
Python :: add a new column to numpy array 
Python :: sorting algorithms in python 
Python :: make venv 
Python :: get the invite url of server disc.py 
Python :: discord.py message user 
Python :: bracket balanced or not in python 
Python :: creating new virtual environment in python 
Python :: how get 1st column in all rows of a 2d matrix in python 
Python :: csv download django 
Python :: How do you create an matrix of random integers in Numpy? 
Python :: python extract email attachment 
Python :: python heatmap 
Python :: print colored text to console python 
Python :: Write byte data in file python 
Python :: django dumpdata specific app 
Python :: python timedelta years 
Python :: spark.read.load 
Python :: merge two netcdf files using xarray 
Python :: django validators import 
Python :: dictionary python values 
Python :: What does if __name_=="_main__": do? 
Python :: if condition in print statement python 
Python :: np.arange in python 
Python :: python basic flask web 
Python :: download unsplash images python no api 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =