I have 2 shapefiles, each one placed in a different folder:
- "C:\...\Folder O\Germany (O).shp"
- "C:\...\Folder P\Germany Berlin (P).shp"
The following script finds the shapefiles and contains a couple of
if conditions. The first
if condition strips the "(O).shp" and "(P).shp" from the shapefiles. This works perfectly.
I want to set up a second
if condition whereby the first name of both shapefiles matches, so in this case it would be "Germany". I thought the string.split method would be ideal but I'm clearly not implementing it correctly.
Could someone kindly point out my mistake please?
def run(): for o in glob.glob("C:\Users\me\Desktop\Test\Folder O" + "\*.shp"): for p in glob.glob("C:\Users\me\Desktop\Test\Folder P" + "\*.shp"): if os.path.basename(o).rstrip("(O).shp") == os.path.basename(p).rstrip("(P).shp"): print p # works perfectly up to here if os.path.basename(o).split(o[]) == os.path.basename(p).split(p]): print p