Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

facing issue when using dictionary in my code #55

Open
sanrajbhar opened this issue Jul 29, 2020 · 1 comment
Open

facing issue when using dictionary in my code #55

sanrajbhar opened this issue Jul 29, 2020 · 1 comment

Comments

@sanrajbhar
Copy link

sanrajbhar commented Jul 29, 2020

I want read n update existing metadata replacing some value from external csv file based on fc name as common id between Featureclasses and csv file(3 columns). but whenever I use dict in my code. it is throwing error

import arcpy_metadata as md
import datetime
import arcpy
import os

workspace ='C:\xxx\AssetID_to_Shapefile_Script_Output_V1'

csvpath=r"C:\xxx\test_metadata\test\meta_batch14.csv"


d = {}
with open(csvpath) as f:
    for line in f:
        (key, AccesWidth,drwgNo) = line.split(',')
        d[(key)] = AccesWidth  #EaseWidth
print d




walk = arcpy.da.Walk(workspace, datatype="FeatureClass")
for dirpath, dirnames, filenames in walk:
    for filename in filenames:
        fc=(os.path.join(dirpath, filename))

        
        metadata = md.MetadataEditor(fc)
        print (fun_csvtodict(csvpath))
        fcname=filename[:-4]

        print fcname+'\n' +'\t'+ metadata.abstract



metadata.finish()  
print "~~~~~~~~~~~~~~~~~~~~~~~Finished~~~~~~~~~~~~~~~~~"

NameError: name 'metadata' is not defined

@thomas-maschler
Copy link
Collaborator

thomas-maschler commented Aug 7, 2020

You call metadata.finish() outside the for loop.
You have to call it for each MetadataEditor instance inside the inner loop.

You might get this error b/c no MetadataEditor instance was ever created? Check if your walk function actually finds any FeatureClasses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants