read bash array from property file into a script
<ol>
<li><p>I've a property file abc.prop that contains the following.</p>

<pre><code>x=(A B)
y=(C D)
</code></pre></li>
<li><p>I've a python script abc.py which is able to load the property file abc.prop.
But I'm not able to iterate and convert both the arrays from abc.prop as follows,</p>

<pre><code>x_array=['A','B']
y_array=['C','D']
</code></pre>

<ol start="3">
<li>I tried the following, but I want to know if there's a better way of doing it, instead of using replace() and stripping off braces.</li>
</ol>

<p><code>importConfigFile = "abc.prop"
propInputStream = FileInputStream(importConfigFile)
configProps = Properties()
configProps.load(propInputStream)
x_str=configProps.get("x")
x_str=x_str.replace("(","")
x_str=x_str.replace(")","")
x_array=x_str.split(' ')</code></p></li>
</ol>

<p>Please suggest a way to achieve this.</p>

<p>I'm not aware of any special bash to python data structure converters. And I doubt there are any. The only thing I may suggest is a little bit cleaner and dynamic way of doing this.</p>

<pre><code>data = {}
with open('abc.prop', 'r') as f:
    for line in f:
        parts = line.split('=')
        key = parts[0].strip()
        value = parts[1].strip('()\n')
        values = value.split()
        data[key] = [x.strip() for x in values]
print(data)
</code></pre>

python