best way to get an integer from string without using regex
<p>I would like to get some integers from a string (the 3rd one). Preferable without using regex. </p>

<p>I saw a lot of stuff.</p>

<p>my string:</p>

<pre><code>xp = '93% (9774/10500)'
</code></pre>

<p>So i would like the code to return a list with integers from a string. So the desired output would be: <code>[93, 9774, 10500]</code></p>

<p>Some stuff like this doesn't work:</p>

<pre><code>&gt;&gt;&gt; new = [int(s) for s in xp.split() if s.isdigit()]
&gt;&gt;&gt; print new
[]
&gt;&gt;&gt; int(filter(str.isdigit, xp))
93977410500
</code></pre>

<p>Since the <em>format is fixed</em>, you can use consecutive <code>split()</code>.
It's not very pretty, or general, but sometimes the direct and "stupid" solution is not so bad:</p>

<pre><code>a, b = xp.split("%")
x = int(a)
y = int(b.split("/")[0].strip()[1:])
z = int(b.split("/")[1].strip()[:-1])
print(x, y, z) # prints "93 9774 10500"
</code></pre>

<p><strong>Edit</strong>: Clarified that the poster specifically said that his format is <strong>fixed</strong>. This solution is not very pretty, but it does what it's supposed to.</p>

python string int