path-manipulation

How to get only the last part of a path in Python?

How to get only the last part of a path in Python? Question: In python, suppose I have a path like this: /folderA/folderB/folderC/folderD/ How can I get just the folderD part? Asked By: pepero || Source Answers: You could do >>> import os >>> os.path.basename(‘/folderA/folderB/folderC/folderD’) UPDATE1: This approach works in case you give it /folderA/folderB/folderC/folderD/xx.py. …

Total answers: 10

Python os.path.join on Windows

Python os.path.join on Windows Question: I am trying to learn python and am making a program that will output a script. I want to use os.path.join, but am pretty confused. According to the docs if I say: os.path.join(‘c:’, ‘sourcedir’) I get “C:sourcedir”. According to the docs, this is normal, right? But when I use the …

Total answers: 14