Select to view content in your preferred language

Unsupported operand error writing to file

1275
2
Jump to solution
12-13-2013 05:43 AM
Zeke
by
Honored Contributor
In the code below, I get a "TypeError: unsupported operand type(s) for +: 'NoneType and 'str'" on the f.write line. If I don't concatenate, it runs fine, but all the layer names run together.

I understand what the error means, but not why I'm getting a NoneType. I've tried casting lyr.name to str, same result. All I'm trying to do is write out a text file of layer names. Any idea what's causing this and how to get around it? Thanks.

for lyr in arcpy.mapping.ListLayers(mxd, "", df):         f.write(lyr.name) + "\n"         count += 1
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JoshuaChisholm
Frequent Contributor
Hey Greg,

Looks like a simple typo to me. The new line is on the wrong side of the bracket. Try this:
for lyr in arcpy.mapping.ListLayers(mxd, "", df):         f.write(lyr.name + "\n")         count += 1

Good luck!
~Josh

View solution in original post

0 Kudos
2 Replies
JoshuaChisholm
Frequent Contributor
Hey Greg,

Looks like a simple typo to me. The new line is on the wrong side of the bracket. Try this:
for lyr in arcpy.mapping.ListLayers(mxd, "", df):         f.write(lyr.name + "\n")         count += 1

Good luck!
~Josh
0 Kudos
Zeke
by
Honored Contributor
You are right, that was a dumb mistake. Thanks.
0 Kudos