Select to view content in your preferred language

How to return a list of layers in a webmap as a CSV?

1250
2
Jump to solution
12-12-2022 04:41 AM
DaveK
by
Occasional Contributor

Hello, 

I'm trying to create an expression that will return the list of layers that are in a webmap.

So far I have this 

from arcgis.gis import GIS
from arcgis.mapping import WebMap
gis = GIS("home")
wmItemId = "" #put the id of the webmap in here
wmItem = gis.content.get(wmItemId)
wm = WebMap(wmItem)for lyr in wm.layers:
print(lyr.title)‍‍‍‍‍‍‍‍

But get this error after running (when I have the webmap ID included) 

Input In [1]
    print(lyr.title)‍‍‍‍‍‍‍‍
                    ^
SyntaxError: invalid non-printable character U+200D

 What could be causing this error? Also, is it possible to have the expression automatically generate a CSV file with the list instead of printing one? Any help is appreciated. 

Thanks. 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

When I paste your code, I see this:

jcarlson_0-1670855235918.png

Somehow, you've got a 'non-printable character' in there, the zero-width joiner: "‍" U+200D: Zero Width Joiner (Unicode Character) (unicodeplus.com)

Try just re-typing that line manually. I'm assuming this was pasted from some other code snippet somewhere? Not sure how else that character would've gotten in. When I run your same code, but typed instead of pasted, it works fine.

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

When I paste your code, I see this:

jcarlson_0-1670855235918.png

Somehow, you've got a 'non-printable character' in there, the zero-width joiner: "‍" U+200D: Zero Width Joiner (Unicode Character) (unicodeplus.com)

Try just re-typing that line manually. I'm assuming this was pasted from some other code snippet somewhere? Not sure how else that character would've gotten in. When I run your same code, but typed instead of pasted, it works fine.

- Josh Carlson
Kendall County GIS
DaveK
by
Occasional Contributor

That worked! Super weird. 

Thanks for the help. 

0 Kudos