I am using a library that specifically needs me to provide arguments as strings one by one. However, different combinations are possible. Right now I am using a bunch of elif:
def get_all_users(times=False, groups=False, ips=False):
"""Get a list of all users online"""
if times and groups and ips:
return ts3conn.exec_("clientlist", "times", "groups", "ips")
elif times and groups:
return ts3conn.exec_("clientlist", "times", "groups")
elif times and ips:
return ts3conn.exec_("clientlist", "times", "ips")
elif groups and ips:
return ts3conn.exec_("clientlist", "groups", "ips")
elif times:
return ts3conn.exec_("clientlist", "times")
elif groups:
return ts3conn.exec_("clientlist", "groups")
elif ips:
return ts3conn.exec_("clientlist", "ip")
else:
return ts3conn.exec_("clientlist")
But I am wondering if this could be improved.
NOTE: I tried if I could use tuples but it won't work:
stuff = (times, groups, ips)
return ts3conn.exec_("clientlist", stuff)
>>> TypeError: can only concatenate str (not "tuple") to str
Update:
Library is at: https://github.com/benediktschmitt/py-ts3/blob/v2/ts3/query_builder.py
The code raises error on function compile:
for option in options:
res += " -" + option
ts3connobject, whatever it is? \$\endgroup\$ts3.query.TS3ServerConnectionobject. \$\endgroup\$ts3conn.exec_('clientlist', *stuff)(tuple splatting). But this is off topic for CR, as this isn't about improving working code. Rather, your attempt to use tuples yields an error, which is a question that is on topic for StackOverflow. \$\endgroup\$