Why am I getting 'str' object is not callable?

60142
1
Jump to solution
11-28-2017 12:01 PM
Labels (1)
PaulHuffman
Occasional Contributor III

I got this to work but I still can't see what the problem was with my original python syntax.

I wanted to run some surface water analysis on several proposed changes in a area to see how well we could prevent flooding,  so I got a python script from a project from 2015 and modified it to run in a different workspace to help me run these steps on several different surfaces. 

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Fill2Stream.py
# Created on: 2015-03-06 10:28:41.00000
#   (generated by ArcGIS/ModelBuilder)
# Description: to generate flow direction and accumulation grids from an elevation raster.  
# Modified 2017-11-28 by PH to run these steps on Mud Lake spillway analysis
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
from arcpy.sa import *


# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

arcpy.env.workspace = "G:/elevation/lidar_2005/MudLake/MudLakeTerrians.gdb"
arcpy.env.overwrite = "True"

# Local variables:
#DEMrs = "G:\\elevation\\lidar_2005\\MudLake\\MudLakeTerrians\\DEMFloodway"
DEMrs = "G:\elevation\lidar_2005\MudLake\MudLakeTerrians.gdb\DEMFloodway"
#DEMrs = "DEMFloodway"
Fill = "DEMFWfill"
flowdir = "DEMFWdir"
drop_raster = "DEMFWDrop"
Accum = "DEMFWaccum"

print DEMrs
#Process: Fill
#outFill = Fill(DEMrs)
#outFill.save(Fill)
arcpy.gp.Fill_sa(DEMrs, Fill, "")

# Process: Flow Direction
arcpy.gp.FlowDirection_sa(Fill, flowdir, "NORMAL", drop_raster)

# Process: Flow Accumulation
arcpy.gp.FlowAccumulation_sa(flowdir, Accum, "", "FLOAT")

#  Process stream line rasters
strm = Con(Raster(Accum) > 200000, 1,0)
strm10 = Con(Raster(Accum) > 10000, 1,0)
strm.save("FWstrm")
strm10.save("FWstrm10")

Yet each time I ran this I got "line 32, in <module>
    outFill = Fill(DEMrs)
TypeError: 'str' object is not callable"

So I tried setting DEMrs with and without the full path, changing the name of the variable from DEM to DEMrs in case DEM was reserved, changing the name of the variable Fill to outFill, changing the direction of the directory slashes from / to \ and to \\,  and nothing seemed to work until I changed the form of the call of the fill tool from outFill = Fill(DEMrs)   to arcpy.gp.Fill_sa(DEMrs, Fill, "").  I'm puzzled my that was necessary since the Help seems to show the Fill tool  in a python script like

outFill = Fill(inSurfaceRaster, zLimit)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

Because on line 25 you defined Fill as a string

Fill = "DEMFWfill"

Then you tried to call it on line 32

outFill = Fill(DEMrs)

because you overwrote the function 'Fill' with a string

View solution in original post

1 Reply
DanPatterson_Retired
MVP Emeritus

Because on line 25 you defined Fill as a string

Fill = "DEMFWfill"

Then you tried to call it on line 32

outFill = Fill(DEMrs)

because you overwrote the function 'Fill' with a string