Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd keep this as simple as possible:</p> <pre><code>entries = [] for line in inputsource: entries.append(map(str.strip, line.strip().strip('{}').split(', '))) </code></pre> <p>So, for each line, strip whitespace then curly braces, then split on the comma-plus-space separating the commands and store the whitespace-stripped results.</p> <p>This relies on the fact that the commands are separated by a comma plus a space, while the arguments in your sample only use commas without spaces. If you have anything that violates that difference, then you do need to resort to a regular expression. I'd limit it to the split only though:</p> <pre><code>import re commandsep = re.compile(r'(?&lt;=\)),\s*') for line in inputsource: entries.append(map(str.strip, commandsep.split(line.strip().strip('{}')))) </code></pre> <p>The <code>commandsep</code> expression splits on any comma-plus-optional-whitespace, provided it was preceded by a <code>)</code> closing parenthesis (using a look-behind assertion).</p> <p>For your input that results in:</p> <pre><code>&gt;&gt;&gt; entries [['topic.equals(org.fedoraproject.prod.bodhi.buildroot_override.tag)', 'foo.notequals(bar)'], ['topic.in(1,2,3)', 'foo.equals(baz)']] </code></pre> <p>If these entries are embedded in a larger body of text, then a regular expression might help, but only to find the curly-brace-delimited values:</p> <pre><code>import re expression = re.compile(r'{[^{}]+}') inputsource = expression.findall(largerbodyoftext) </code></pre> <p>where <code>expression</code> will find any text delimited by curly braces (no nesting).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload