How to get the field values from vector layer in the list using gdal
<p>I have a list with the field names and i am trying to get the field values using the code snippet:</p>

<pre><code>from osgeo import osr,ogr, gdal
shp="filepath"
driver = ogr.GetDriverByName('ESRI Shapefile')
dataSource = driver.Open(shp,0)
layer=dataSource.GetLayer()
list=['field1','field2','field3']
for i in layer:
    ValList = [i.GetField(j) for j in list]
</code></pre>

<p>i am getting the following error:</p>

<pre><code>raise ValueError("Illegal field requested in GetField()")
ValueError: Illegal field requested in GetField()
</code></pre>

<p>So what i have to do if i want to get the values in the list?</p>