Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get directory of file python

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))
Comment

python find directory of file

import os
  
print('File name :    ', os.path.basename(__file__))
print('Directory Name:     ', os.path.dirname(__file__))
Comment

python file directory

from os import path
dir_path = path.dirname(__file__)
Comment

python working with files and dirs

from pathlib import Path
import shutil

tmp = Path("/tmp")

src = tmp.joinpath("src")
src.mkdir()
src.joinpath("src.txt").touch()
# /tmp/src
# /tmp/src/src.txt

dst = tmp.joinpath("dst")
dst.mkdir()
# /tmp/dst

shutil.copytree(src, dst)
# FileExistsError: [Errno 17] File exists: '/tmp/dst'
shutil.copytree(src, dst, dirs_exist_ok=True)
# PosixPath('/tmp/dst')
Comment

PREVIOUS NEXT
Code Example
Python :: open word from python 
Python :: connect to spark cluster 
Python :: python hide print output 
Python :: pandas check match string lowercase 
Python :: pandas earliest date in column 
Python :: virtualenv specify python version 
Python :: python bit shift by 3 
Python :: docker django 
Python :: python list fill nan 
Python :: python find string 
Python :: ignore pytest errors or warnings 
Python :: scikit learn pca 
Python :: download python 2.7 for windows 10 
Python :: sum first 100 integers in python 
Python :: python array extend 
Python :: two dimensional array python 
Python :: Python3 boto3 put and put_object to s3 
Python :: how to access dataframe row by datetime index 
Python :: python count variable and put the count in a column of data frame 
Python :: python isinstance list 
Python :: increase axis ticks pyplot 
Python :: select columns to include in new dataframe in python 
Python :: if name 
Python :: numpy array split 
Python :: Python Changing Directory 
Python :: python filter data from list 
Python :: pyspark dataframe to parquet 
Python :: escape character in python 
Python :: python offline translate pypi 
Python :: open file in python directory 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =