Python - Glob without absolute path
I am using glob to get the image pair names for a lot of images. The only problem is I am getting the absolute path and I don't want that, I only want the image names. How can i do this?
import glob
A=sorted(glob.glob('/media/test/A*.png'))
B=sorted(glob.glob('/media/test/B*.png'))
NumbSeq=len(A)
for i in range(0,NumbSeq):
print "\"%s\",\"%s\","%(A[i],B[i])
I get:
"/media/test/A170900_85495.460376.png","/media/test/B170900_85495.460376.png"
I need to:
"A170900_85495.460376.png","B170900_85495.460376.png"
+3
source to share
3 answers
try it
os.path.basename(A[i])
this will only return the filename.
import glob
import os
A=sorted(glob.glob('/media/test/A*.png'))
B=sorted(glob.glob('/media/test/B*.png'))
NumbSeq=len(A)
for i in range(0,NumbSeq):
print '"%s","%s"'%(os.path.basename(A[i]),os.path.basename(B[i]))
This will give you
"A170900_85495.460376.png","B170900_85495.460376.png"
+1
user1846747
source
to share