0

I found a .py script which export attachments from a feature class (here)

But it doesn't work with Cyrillic symbols in name of attachments. How to specify the value of the encoding in the script and correct the error?

import arcpy
from arcpy import da
import os

inTable = arcpy.GetParameterAsText(0)
fileLocation = arcpy.GetParameterAsText(1)

with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:
for item in cursor:
    attachment = item[0]
    filenum = "ATT" + str(item[2]) + "_"
    filename = filenum + str(item[1])
    open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
    del item
    del filenum
    del filename
    del attachment
1
with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor: 
    for item in cursor:
        attachment = item[0] filenum = u"ATT" + unicode(item[2]) + u"_"
        filename = filenum + unicode(item[1])
        open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.