0

In this code, I want to make the function use default parameters if the user decides to use the defaults and clicks enter, which leads the input to be an empty string.

However, in my case; it just runs the code with empty strings used as parameters.

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: I know a similar question has been asked before but I wasn't able to get it working with this code since this function has much more parameters.

1 Answers1

0

I would approach this by using a dictionary instead of the parameters, this way, you could set the parameter to default on the go. It would look like this:

def mapMaker(myDict):
    #access the arguments via mydict['your_argument']


myDict = {}
myDict['mapZoom'] = int(input("Choose Your Map's Starting Zoom:(Default = 4) ") or 4)})
myDict['mapLoc'] = str(input("Choose Where Your Map File Will Be Created:(Default = ~/Desktop) ") or '~/Desktop')
myDict['mapName'] = str(input("Choose Your Map's Name:(Default = Untitled) ") or 'Untitled')
mapMaker(myDict)
Gamopo
  • 1,600
  • 1
  • 14
  • 22