copy directory name and placing it into a variable (python) -


i new python , struggling accomplish simple ask. trying copy current directory name , placing variable. dont need contents of directory, or path directory. need name of current directory placed variable.

thank you

for current working directory:

import os cdir=os.getcwd().split(os.sep)[-1] print cdir 

for script directory:

import os sdir=os.path.dirname(os.path.abspath(__file__)).split(os.sep)[-1] print sdir 

Comments