【发布时间】:2021-01-16 03:06:37
【问题描述】:
在这段代码中,如果用户决定使用默认值并单击回车,我想让函数使用默认参数,这会导致输入为空字符串。
但是,就我而言;它只是使用空字符串作为参数运行代码。
arc = ArcGIS()
def mapMaker(country, zoom = 4, location = "~/Desktop/", name = "Untitled"):
loc = arc.geocode(country)
countryLat = loc.latitude
countryLon = loc.longitude
map = folium.Map(location=[countryLat, countryLon], zoom_start=zoom, min_zoom=2)
map.save("%s.html" % location + name)
mapZoom = input("Choose Your Map's Starting Zoom:(Default = 4) ")
mapLoc = input("Choose Where Your Map File Will Be Created:(Default = ~/Desktop) ")
mapName = input("Choose Your Map's Name:(Default = Untitled) ")
mapMaker(userin, zoom = mapZoom, location = mapLoc, name = mapName )
PS:我知道之前有人问过类似的问题,但我无法使用这段代码让它工作,因为这个函数有更多的参数。
【问题讨论】:
-
这能回答你的问题吗? Default values on empty user input
-
是的!最后,我能够让代码正常工作。
标签: python python-3.x function