I keep getting an error in Python when I try to split a single word. From what I read, this is because the default split() command looks for whitespace. The problem is, I want the second assigned variable (asset in this case) to return nothing or null. This is what I am working with:
slack_text.startswith("!help"):
command, asset = slack_text.split()
if asset != "":
if asset == "commandlist":
slack_reply = "Available Commands: !addme, !getBalance, !buy <asset> <quantity>"
elif asset == "ships":
slack_reply = getAllShips()
elif asset == "buildings":
slack_reply = getAllBuildings()
elif shipExists(asset):
slack_reply = getShip(asset)
elif buildingExists(asset):
slack_reply = getBuilding(asset)
else:
slack_reply = "Not a valid asset."
else:
slack_reply = "Available help modifiers are: commandlist, <ship_name>, <building_name>. (!help <modifier>)"
So with this code, I can type '!help ships' in Slack and cast no error and return the getAllShips() function. But if I type simply '!help', Python casts an error.
I basically want to be able to return a statement if there is no modifier. However, not having a modifier casts an error. Is there something else I can do to approach this problem? Can someone point me in the right direction here?