<div dir="auto"><div>it's QgsEditException. The edit(layer) statement is working just fine.<br><br><div class="gmail_quote"><div dir="ltr">On Thu, Jun 14, 2018, 8:11 PM Thomas Baumann <<a href="mailto:rdbath.regiodata@gmail.com">rdbath.regiodata@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hello,</div><div>isnt it "QgsEditError" instead of "QgsEditException"?</div><div><br></div><div>regards,</div><div>Thomas</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">Am Do., 14. Juni 2018 um 03:26 Uhr schrieb Zhang Qun <<a href="mailto:zhangq.rhy@gmail.com" target="_blank" rel="noreferrer">zhangq.rhy@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi Matthias</div><div><br></div><div>I follow the steps in the link you posted and get the following errors when trying to import <br></div><div><br></div><div>
<p style="margin:0px;white-space:pre-wrap"><span style="font-family:"Courier New,courier"">ImportError: cannot import name QgsEditException</span></p></div><div><br></div><div>Do I have to install some modules? Didn't find any luck on google.<br></div><div><br></div><div>Best regards,</div><div>Zhang Qun<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 13, 2018 at 6:16 PM, Matthias Kuhn <span dir="ltr"><<a href="mailto:matthias@opengis.ch" target="_blank" rel="noreferrer">matthias@opengis.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Glad you like it :)<br>
<br>
Forwading this answer also to the mailing list for future reference,<br>
Ethan, you need to use "reply to all" in your mail application or other<br>
are not able to follow our conversation (which would be a pity ;) ).<br>
<br>
Best regards<br>
Matthias<br>
<span><br>
On 06/13/2018 12:13 PM, Zhang Qun wrote:<br>
> Wow, i was about to look into the with() statement. It looks much<br>
> better. Many thanks for the link. <br>
> <br>
> Regards,<br>
> Ethan<br>
> <br>
> <br>
> On Wed, Jun 13, 2018, 6:03 PM Matthias Kuhn <<a href="mailto:matthias@opengis.ch" target="_blank" rel="noreferrer">matthias@opengis.ch</a><br>
</span><span>> <mailto:<a href="mailto:matthias@opengis.ch" target="_blank" rel="noreferrer">matthias@opengis.ch</a>>> wrote:<br>
> <br>
> Hi Ethan,<br>
> <br>
> there are of course advantages and disadvantages of both methods, but in<br>
> most cases the QgsVectorLayer ones just "do the right thing", especially<br>
> when used with a `with` block, see also this post:<br>
> <br>
> <a href="http://www.opengis.ch/2015/08/12/with-edit-layer/" rel="noreferrer noreferrer" target="_blank">http://www.opengis.ch/2015/08/12/with-edit-layer/</a><br>
> <br>
> Cheers<br>
> Matthias<br>
> <br>
> On 06/13/2018 11:59 AM, Zhang Qun wrote:<br>
> > Hi Matthias,<br>
> ><br>
> > Thanks very much for the instruction. I will try it out. The<br>
> > dataProvider method seems simpler to me and it can set attributes in<br>
> > batch as it takes a list as input. The layer method seems only<br>
> takes one<br>
> > input. If i want to change 10 attributes of a feature, i have to issue<br>
> > 10 commands.<br>
> ><br>
> > Best regards,<br>
> > Ethan<br>
> ><br>
> ><br>
> > On Wed, Jun 13, 2018, 5:45 PM Matthias Kuhn <<a href="mailto:matthias@opengis.ch" target="_blank" rel="noreferrer">matthias@opengis.ch</a><br>
> <mailto:<a href="mailto:matthias@opengis.ch" target="_blank" rel="noreferrer">matthias@opengis.ch</a>><br>
</span><div><div class="m_7560285752112896280m_-1792566118288974340h5">> > <mailto:<a href="mailto:matthias@opengis.ch" target="_blank" rel="noreferrer">matthias@opengis.ch</a> <mailto:<a href="mailto:matthias@opengis.ch" target="_blank" rel="noreferrer">matthias@opengis.ch</a>>>> wrote:<br>
> ><br>
> > Hi Ethan<br>
> ><br>
> > On 06/13/2018 11:18 AM, Zhang Qun wrote:<br>
> > > Hi everyone, i"m using QGIS2.18, and trying to change feature<br>
> > attributes<br>
> > > using the following two methods:<br>
> > ><br>
> > > *dataProvider:*<br>
> > ><br>
> > > |attrs<br>
> > ={0:"hello",1:123}layer.dataProvider().changeAttributeValues({fid<br>
> > > :attrs })|<br>
> > ><br>
> > > *layer object:*<br>
> > ><br>
> > ><br>
> > <br>
> |layer.startEditing()layer.changeAttributeValue(fid,fieldIndex,value)layer.commitChanges()|<br>
> > ><br>
> > > I keep the attribute table open, and monitor the changes.<br>
> The first<br>
> > > method dataProvider is not able to update the attribute<br>
> table on the<br>
> > > fly, even the "reload table" button on the top menu of the<br>
> table does<br>
> > > not work. I have to re-open the table to see the changes.<br>
> The second<br>
> > > method is working, the attribute table gets instantly updated.<br>
> > ><br>
> > > I would like to stay with the dataProvider method but not<br>
> sure how to<br>
> > > get instantly updated attribute table?<br>
> ><br>
> > The provider's dataChanged() signal needs to be emitted, I<br>
> think you can<br>
> > directly emit that or call `dataProvider().forceReload()`.<br>
> ><br>
> > Out of curiosity, why would you like to stay with the<br>
> dataProvider <br>
> > method?<br>
> ><br>
> > Bests<br>
> > Matthias<br>
> ><br>
> ><br>
> > ><br>
> > > Thanks.<br>
> > ><br>
> > > Best regards,<br>
> > > Ethan<br>
> > ><br>
> > ><br>
> > > _______________________________________________<br>
> > > QGIS-Developer mailing list<br>
> > > <a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank" rel="noreferrer">QGIS-Developer@lists.osgeo.org</a><br>
> <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank" rel="noreferrer">QGIS-Developer@lists.osgeo.org</a>><br>
</div></div>> <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank" rel="noreferrer">QGIS-Developer@lists.osgeo.org</a><br>
<span>> <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank" rel="noreferrer">QGIS-Developer@lists.osgeo.org</a>>><br>
> > > List info:<br>
> <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> > > Unsubscribe:<br>
> <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> > ><br>
> > _______________________________________________<br>
> > QGIS-Developer mailing list<br>
> > <a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank" rel="noreferrer">QGIS-Developer@lists.osgeo.org</a><br>
> <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank" rel="noreferrer">QGIS-Developer@lists.osgeo.org</a>><br>
</span>> <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank" rel="noreferrer">QGIS-Developer@lists.osgeo.org</a><br>
<div class="m_7560285752112896280m_-1792566118288974340HOEnZb"><div class="m_7560285752112896280m_-1792566118288974340h5">> <mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank" rel="noreferrer">QGIS-Developer@lists.osgeo.org</a>>><br>
> > List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> > Unsubscribe:<br>
> <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
> ><br>
> <br>
</div></div></blockquote></div><br></div>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank" rel="noreferrer">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></blockquote></div>
</blockquote></div></div></div>