[Qgis-developer] QgsVectorLayer: how does it work?

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Thu Apr 2 10:12:35 EDT 2009


On Thu, Apr 2, 2009 at 1:03 PM,  <luca_manganelli at comune.trento.it> wrote:
>
> Hi, I'm trying to add a simple vector layer, but with no success.
>
> I use this python code:
>
>       layer = QgsVectorLayer("D:\temp\circoscr.shp", "circoscr", "ogr")

 Backslashes are escape characters in python. Try with forward
slashes, or doubled-backslashes:

 QgsVectorLayer("D:\\temp\\circoscr.shp",...etc...)

 QgsVectorLayer("D:/temp/circoscr.shp",...etc)

I'm sure we've all made this mistake more than once....

Note that if you are doing file and dir operations in python you
should be using the os.path module, and not stringing together strings
with things like: path = dirName + "/" + filename + "." +
fileExtension - the os.path module provides routines for doing this
kind of thing in a platform-independent way.

Barry


More information about the Qgis-developer mailing list