I have made some edits in your script. I changed the For cycle into Copy Layer method. Try it if you want. This method preserve the attributes as you want. import ogr,os,sys Datasource_Parks = 'ArcCR500_v32/ChranenaUzemi.shp' Direction_Result_Shp = 'ArcCR500_v32/Result.shp' Direction_Result_Dbf="ArcCR500_v32/Table.dbf" Open_Parks = ogr.Open(Datasource_Parks) layer_park = Open_Parks.GetLayer(0) ############################## add variable 'location' into SQL location = 'Krkonossky narodni park' SQL = "NAZEV_ASCI = " + locaion layer_park.SetAttributeFilter(SQL) Number_Of_Park = layer_park.GetFeatureCount() ############################## edit ####### make output variable (only first word) output_file = "output_" + location.split(" ")[0] + ".shp" driver_out = ogr.GetDriverByName("ESRI Shapefile") ds_out = driver_out.CreateDataSource(output_file) lyr_out = ds_out.CopyLayer(layer_park, output_file.split(".")[0]) lyr_out.SyncToDisk() ds_out.SyncToDisk() ############################## end Dataset.Destroy()