Following your comment of getting a pattern like ('tool', ('-a', 'param'), ('-b', 'param_2'), ('-c', ('param_3', 'param_4'))), it seems like you want to read the file as a collection of strings, which follow the pattern of a command in each line, and separate them into an organized list or tuple.
In that case, you could use regular expressions to help you segment each line into the sections you expect from such pattern. For example:
# Compiled regular expression for the command/tool name
regex_command = re.compile("^(\w+)", re.IGNORECASE)
# Compiled regex for -option_name params
regex_options = re.compile("[/s]*(?:-[\w]+)[\s]*[(?:\w+)[\,]*[\s]*]*[$]*",
re.IGNORECASE)
# This will hold the found commands/tools in each line
parsed_tools = []
# Loop through each line of the file (this may be, ie. f.readline() or other)
for line in text.split("\n"):
# This will hold the found tool/command in the current line
parsed_tool = []
# Append the command/tool name found at the start of the line
parsed_tool.append(regex_command.match(line).group(0))
# Find the line's options and their parameters with the second regex
options = regex_options.findall(line)
# Loop through the found matches
for option in options:
# Separate the line of options and parameters by white spaces
segments = option.split()
# The first found group is the name of the option
option_name = segments[0]
# The rest may be parameters, if any
option_params = segments[1:] if len(segments) > 1 else None
# The parameters may be joined by commas, so attempt to separate them
# even further; otherwise only append the option name
parsed_tool.append((option_name,
tuple(str(option_params).split(",")))
if option_params else option_name)
# Append each parsed_tool into the overall list
parsed_tools.append(parsed_tool)
In the code above, I'm using compiled regular expressions from the re module, with an added parameter of not being case-sensitive, to find a match of the tool name at the very start of the line (the group() method gives me the only result I'm expecting), and another one to "find all" matches of "-option_name params", where I loop through all the possible results and divide them by spaces and commas.
You can start learning more about regular expressions here. Adjust the regular expressions to suit the patterns you expect from the file.