Search Cursor Return Value based on User Input

330
1
Jump to solution
07-16-2020 02:47 PM
ModernElectric
Occasional Contributor III

Good Afternoon:

    I believe what I am asking if an elementary level Python code. However, my intention is to run thru a File GDB Feature Class to identify a value from a different field in the same row. Basically, looking for the User to add the value from the field "TWACS_NUMBER" and use the SearchCursor feature to identify the value in the XFMR_BANK_ID field of the same row. I have figured out the User Input portion of the script, but the SearchCursor feature is giving me a hard time with too many example online. Any starting points would help.

Thank You

0 Kudos
1 Solution

Accepted Solutions
RandyBurton
MVP Alum

A simple search cursor example:

fc = 'feature or table to search'

fields = ['TWACS_NUMBER', 'XFMR_BANK_ID']

where = "TWACS_NUMBER = 'some value'" # if string wrap value in single quotes; if number then no single quotes

with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    for row in cursor:
        print('TWACS_NUMBER: {0}   XFMR_BANK_ID: {1}'.format(row[0], row[1]))

View solution in original post

1 Reply
RandyBurton
MVP Alum

A simple search cursor example:

fc = 'feature or table to search'

fields = ['TWACS_NUMBER', 'XFMR_BANK_ID']

where = "TWACS_NUMBER = 'some value'" # if string wrap value in single quotes; if number then no single quotes

with arcpy.da.SearchCursor(fc, fields, where) as cursor:
    for row in cursor:
        print('TWACS_NUMBER: {0}   XFMR_BANK_ID: {1}'.format(row[0], row[1]))