Python - CalculateField using CodeBlock contained in another Python Script

173
1
05-05-2022 08:41 AM
Labels (1)
KimGarbade
Occasional Contributor III

I have a python script that corrects ALL CAPS into sentence case (Lets call it "SentCase.py" in this example) and includes a list of exceptions specific to my local area (I.E. "NAS THISCITY" becomes "NAS Thiscity" and not "Nas thiscity", etc).  

I want to call SentCase.py from another python script that will step through 20+ feature classes and use SentCase to correct a "Notes" field in each.

What I have is some form of this, but (as you might have guessed already) it fails.  The message I receive is "NameError: name 'subsmade' is not defined".

arcpy.env.workspace = CGIntegrationsde
featClasses = arcpy.ListFeatureClasses('*Spatial*ET','','')
for fc in featClasses:
    arcpy.management.CalculateField(fc,'Notes','subsmade(!Notes!)','PYTHON3', 'import SentCase.subsmade')

 

SentCase.py is in the same directory as the called python script and I have tried to import SentCase into the calling script.  Also "subsmade" is a function in SentCase.py. It is the only function in SentCase.py as a matter of fact.

KimGarbade_0-1651765268422.png

Any help would be appreciated.

K

0 Kudos
1 Reply
KimGarbade
Occasional Contributor III

Sorry for the short lived post, but I solved it....

I was using incorrect syntax.  The syntax should have been:

arcpy.management.CalculateField(fc,'Notes','SentenceCase.subsmade(!Notes!)','PYTHON3', 'import SentenceCase')

 

0 Kudos