I have a very specific problem. I have six lists that I need to combine into one big string. Every list will be enclosed inside a bracket () in final big string.
For example, I have declared six lists as below:
primaryP=['PSUP']
primaryG=['NSUP']
primaryAin=['IBIAS_200N','VREF']
primaryAout=['IOUTN','IOUTP','IBIAS_OUT<1:0>','ICAL<1:0>']
primaryDin=['DN', 'DNB', 'EN', 'FAST_START', 'RESET', 'UP', 'UPB', 'DEGEN_TRIM<2:0>']
primaryDout=[]
Now I want to combine all six lists into one big string as shown below:
CSRPGPrimary='//CSRPG PRIMARY ("PSUP") ("NSUP") ("IBIAS_200N" "VREF") ("IOUTN" "IOUTP" "IBIAS_OUT<1>" "IBIAS_OUT<0>" "ICAL<1>" "ICAL<0>") ("DN" "DNB" "EN" "FAST_START" "RESET" "UP" "UPB" "DEGEN_TRIM<2>" "DEGEN_TRIM<1>" "DEGEN_TRIM<0>") ()'
Notice how I want every list inside individual brackets () and each element in double quotes "". Also I want to split bus/vector bits individually in final string as shown above.
Here is what I tried so far:
primaryP=['PSUP']
primaryG=['NSUP']
primaryAin=['IBIAS_200N','VREF']
primaryAout=['IOUTN','IOUTP','IBIAS_OUT<1:0>','ICAL<1:0>']
primaryDin=['DN', 'DNB', 'EN', 'FAST_START', 'RESET', 'UP', 'UPB', 'DEGEN_TRIM<3:0>']
primaryDout=[]
primaryMaster=[primaryP, primaryG, primaryAin, primaryAout, primaryDin, primaryDout]
CSRPGPrimary=['("'+' '.join(item)+'")' if item else '()' for item in primaryMaster]
CSRPGPrimary="//CSRPG PRIMARY " + ' '.join(CSRPGPrimary)
print("CSRPGPrimary=", CSRPGPrimary)
But final output is not as I wanted:
Final output:
('CSRPGPrimary=', '//CSRPG PRIMARY ("PSUP") ("NSUP") ("IBIAS_200N VREF") ("IOUTN IOUTP IBIAS_OUT<1:0> ICAL<1:0>") ("DN DNB EN FAST_START RESET UP UPB DEGEN_TRIM<1:0> GAIN_SEL<1:0> GAIN_TRIM<3:0> OFFSET_MODE<1:0> OFFSET_TRIM<3:0> RES_TRIM<4:0> SEL_IRN<1:0> SEL_IRP<1:0>") ()')
Desired output:
('CSRPGPrimary=', '//CSRPG PRIMARY ("PSUP") ("NSUP") ("IBIAS_200N" "VREF") ("IOUTN" "IOUTP" "IBIAS_OUT<1>" "IBIAS_OUT<0>" "ICAL<1>" "ICAL<0>") ("DN" "DNB" "EN" "FAST_START" "RESET" "UP" "UPB" "DEGEN_TRIM<2>" "DEGEN_TRIM<1>" "DEGEN_TRIM<0>") ()')
any suggestions, especially what is best way to split vector/bus bits?
"-wrapping to each of the elements you join, but your code is doing it to the result of the join. It's just a matter of swapping that order."IBIAS"_"200N"instead of"IBIAS_200N"? If so, what's the rule for that? Split on non-alpha characters, quote the bits, and rejoin? Or…?