I have a table loaded in QGIS from spatialite DB. When i see the layer properties it is dbname='/home/farook/Spatialite/Cities.sqlite' table="cities" sql=. Now i want the dbname alone (i.e) the entire path '/home/farook/Spatialite/Cities.sqlite' for whatever layer loaded inside QGIS dynamically using PyQGIS. Is there any options for the same?


These two code statements will provide the table path to the db name:

print iface.activeLayer().dataProvider().dataSourceUri().split('|')[0]


print lyr.dataProvider().dataSourceUri().split('|')[0]
  • I tried but its prints dbname='/home/farook/Spatialite/Cities.sqlite' table="cities" (geometry) sql= instead of dbname='/home/farook/Spatialite/Cities.sqlite' – User123 Apr 13 '16 at 5:20
  • For your case you may have to split at the empty space character between Cities.sqlite' and table instead of the pipe character e.g. .split(' ')[0] – artwork21 Apr 13 '16 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.