parse a string (Cadence Allegro Netlist) to dictionary

L

Leland

Hi,

I always use readline(), strip(), split() and so on to parse a string.
Is there some elegant way to parse the following string into a
dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}?

NET_NAME
'50MHZ_CLK_SRC'
'@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC':
C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\';
NODE_NAME U122 2
'@TEST_LIB.TEST(SCH_1):pAGE92_I223@INF_LOGIC.CY2305(CHIPS)':
'CLK2': CDS_PINID='CLK2';
NODE_NAME R1395 1
'@TEST_LIB.TEST(SCH_1):pAGE92_I232@INF_RESISTORS.RESISTOR(CHIPS)':
'A': CDS_PINID='A';

Thanks,
Leland
 
E

Emile van Sebille

On 11/5/2009 12:02 PM Leland said...
Hi,

I always use readline(), strip(), split() and so on to parse a string.
Is there some elegant way to parse the following string into a
dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}?

NET_NAME
'50MHZ_CLK_SRC'
'@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC':
C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\';
NODE_NAME U122 2
'@TEST_LIB.TEST(SCH_1):pAGE92_I223@INF_LOGIC.CY2305(CHIPS)':
'CLK2': CDS_PINID='CLK2';
NODE_NAME R1395 1
'@TEST_LIB.TEST(SCH_1):pAGE92_I232@INF_RESISTORS.RESISTOR(CHIPS)':
'A': CDS_PINID='A';

Thanks,
Leland

This does it, but not very elegantly...

mydict = dict( (kk[0].replace("'",""),",".join(kk[1:]))
for kk in [ [ [ jj for jj in ii.split("\n") if jj.strip() ][0]
for ii in txt.split("_NAME")[1:] ] ])

Emile
 
M

metal

Hi,

I always use readline(), strip(), split() and so on to parse a string.
Is there some elegant way to parse the following string into a
dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}?

NET_NAME
'50MHZ_CLK_SRC'
'@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC':
C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\';
NODE_NAME U122 2
'@TEST_LIB.TEST(SCH_1):pAGE92_I223@INF_LOGIC.CY2305(CHIPS)':
'CLK2': CDS_PINID='CLK2';
NODE_NAME R1395 1
'@TEST_LIB.TEST(SCH_1):pAGE92_I232@INF_RESISTORS.RESISTOR(CHIPS)':
'A': CDS_PINID='A';

Thanks,
Leland

not very elegantly too.

x = re.findall("_NAME[\n\s']+((?<=').+(?=')|\w+\s+\w+)", s)
"""
print {x[0]: x[1:]}
{'50MHZ_CLK_SRC': ['U122 2', 'R1395 1']}
"""
 
J

Joel Davis

I always use readline(), strip(), split() and so on to parse a string.
Is there some elegant way to parse the following string into a
dictionary {'50MHZ_CLK_SRC' : 'U122.2, R1395.1'}?
NET_NAME
'50MHZ_CLK_SRC'
'@TEST_LIB.TEST(SCH_1):50MHZ_CLK_SRC':
C_SIGNAL='@test_lib.test(sch_1):\50mhz_clk_src\';
NODE_NAME U122 2
'@TEST_LIB.TEST(SCH_1):pAGE92_I223@INF_LOGIC.CY2305(CHIPS)':
'CLK2': CDS_PINID='CLK2';
NODE_NAME R1395 1
'@TEST_LIB.TEST(SCH_1):pAGE92_I232@INF_RESISTORS.RESISTOR(CHIPS)':
'A': CDS_PINID='A';
Thanks,
Leland

not very elegantly too.

x = re.findall("_NAME[\n\s']+((?<=').+(?=')|\w+\s+\w+)", s)
"""
print {x[0]: x[1:]}>>> {'50MHZ_CLK_SRC': ['U122 2', 'R1395 1']}

"""

@metal

Apparently you and I differ considerably on our conceptions of
elegance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top