[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Any Python gurus online? I've been wracking my brain around

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 9
Thread images: 2

File: 62050764.png (361KB, 858x725px) Image search: [Google]
62050764.png
361KB, 858x725px
Any Python gurus online?

I've been wracking my brain around this for days now....

I'm not sure if many would be familiar with arcpy. I'm trying to use the ADMINAREA field in TWB_Suburbs_layer to fill the LOCALITY field in TWB_Property_Layer.
The issue is somewhere in this segment. Assuming indentation is correct...

for counter in range(0,len(localityList)):
localityQuery = '"ADMINAREA" = ' + '\''+ str(localityList[indexCounter]) + '\''
arcpy.MakeFeatureLayer_management("TWB_Suburbs", "TWB_Suburbs_Layer", localityQuery)
location = arcpy.SelectLayerByLocation_management("TWB_Property_Layer", "WITHIN", "TWB_Suburbs_Layer")


with arcpy.da.UpdateCursor(fc, field) as cursor:
for row in cursor:
if row[0] == '':
row[0] = 'TESTVALUE'
cursor.updateRow(row)


del row
arcpy.Delete_management("TWB_Suburbs_Layer")
counter += 1
indexCounter += 1
print "pass"
>>
Whoops, I'll try this again with the correct code

print localityList
for counter in range(0,len(localityList)):
localityQuery = '"ADMINAREA" = ' + '\''+ localityList[indexCounter] + '\''
localityLayer = arcpy.MakeFeatureLayer_management("TWB_Suburbs", "TWB_Suburbs_Layer", localityQuery)
arcpy.SelectLayerByLocation_management("TWB_Property_Layer", "WITHIN", "TWB_Suburbs_Layer")

parcelList = []
sRows = arcpy.SearchCursor("TWB_Property_Layer")
sRow = sRows.next()

while sRow:
parcelList.append(sRow)
sRow = sRows.next()
print ("There are " + str(len(parcelList)) + " empty locality fields in " + localityList[indexCounter])
cursor = arcpy.UpdateCursor(fc)
uRow = cursor.next()
for uRow in cursor:
if uRow.LOCALITY == '':
uRow.LOCALITY = str(localityList[indexCounter])
cursor.updateRow(uRow)
uRow = cursor.next()

arcpy.Delete_management("TWB_Suburbs_Layer")
counter += 1
indexCounter += 1
>>
I was gonna ask you to upload the properly indented code to pastebin or the like and have a look, but

>Any Python gurus online?
>pepe shit
Just go ask reddit.
>>
>>126271
That's helpful, thanks.
>>
>>126269
>>126268
1) Just copy it and paste into irfanview, then post the picture.
2) You don't need to ask for a "Python Guru": profunctional OO code is profunctional OO code. There are many profunctional OO languages, and unless your problem is a failure to compile/interpret, your problem is unlikely to be Python-specific
3) You never actually posted a question; you just threw code over the wall and left us to assume it was broken somehow.
>>
File: Clipboard01.jpg (38KB, 797x245px) Image search: [Google]
Clipboard01.jpg
38KB, 797x245px
>>126276
No errors, program runs to completion.
However the fields remain unchanged.

I need to change the LOCALITY field in TWB_Property_Layer to match the ADMINAREA field found in TWB_Suburbs_Layer.
I'm not sure if I'm using selectLayerByLocation properly, and obviously my updateCursor isn't implemented properly either.

I broke the segment down a bit further.
>>
>>126287
Right off the bat, you're using a foreach loop and then incrementing your iterator at the end of it, so you ignore every other row.
>>
>>126293
So it will increment without counter += 1?
>>
>>126302
In Python, when you use "for X in Y" on anything iterable, it updates X automatically every time it loops.

If you were using "while X" you'd have to increment it manually.
Thread posts: 9
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.