convert pgsql int array into python array
<p>I have numeric data (int) stored in pgsql as arrays. These are <code>x,y,w,h</code> for rectangles in an image e.g. <code>{(248,579),(1,85)}</code></p>

<p>When reading to my python code (using psycopg) I get it as a string (?). I am now trying to find the best way to obtain a python array of ints from that string. 
Is there a better way than to split the string on ',' and so on...</p>

<p>p.s. I did try <code>.astype(int)</code> construct but that wouldn't work in this instance.</p>

<p>Assuming that you wouldn't be able to change the input format, you could remove any unneeded characters, then split on the <code>,</code>'s or do the opposite order.</p>

<pre><code>data = '{(248,579),(1,85)}'
data.translate(None, '{}()').split(',')
</code></pre>

<p>will get you a list of strings.</p>

<p>And</p>

<pre><code>[int(x) for x in data.translate(None, '{}()').split(',')]
</code></pre>

<p>will translate them to integers as well.</p>

python arrays postgresql psycopg2