import arcpy with arcpy.da.SearchCursor( 'C:/Temp/foo.shp' , [ "*" ] ) as cursor: for row in cursor: print row[0]
import arcpy def main(): fc = r"C:\TestData\500ft_Grid.shp" fields = ["*"] with arcpy.da.SearchCursor(fc, fields) as cursor: for row in cursor: print(row) if __name__ == '__main__': main()
fc = r"C:\TestData\500ft_Grid.shp" fields = ["*"] with arcpy.da.SearchCursor(fc, fields) as cursor: for row in cursor: print(row)
Bug BUG-000083762: In each cursor documentation, specify the type of lock being closed and released, as a shared lock is still present in the geodatabase after the 'with' statement executes.
I did some quick testing here and I confirmed what Luke found: running the with statement in a function removes the locks while running it alone (outside a function) leaves the locks. However, if you run the with statement outside of a function, the locks only remain until you close the IDE (I was using PyScripter). Same thing if you just run the .py file with python.exe, the locks are removed when the script has finished running.
Lucas Danzinger addressed this behavior in one of his earlier replies to this thread, i.e., the locks are removed by the Python interpreter when the cursor objects go out of scope by either having the function end or having the IDE/interpreter closed out.
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.