to change topics a little bit... :) 

is there a way to get the match to for 'type' to work on a 
substring starting the line instead of having to match the whole 
string? exit at the first match found. i do not care about 
performance or how fast it works. 

if you make your list then using the longer lines first then 
it will do what you need for it to do and not mean having to 
special case each and every type of description. 


for example: 


i have currently: 

'CASH ALTERNATIVES DIVIDENDS (12345)': 'dividends', 
'CASH ALTERNATIVES DIVIDENDS (ABC45)': 'dividends', 
'CASH ALTERNATIVES DIVIDENDS (123)': 'dividends', 
'CASH ALTERNATIVES DIVIDENDS': 'dividends', 


when it would be more concise if i could write it: 
'CASH ALTERNATIVES DIVIDENDS (': 'dividends-ticker', 
'CASH ALTERNATIVES DIVIDENDS': 'dividends-no-ticker', 


this is only one type but there are many more that work the 
same way and having to write a new line for each variant is 
making this go a lot longer.

 Yes! A contributor just ran into the same situation a couple days ago and 
used a neat solution using petl.capture(). See here 
<https://github.com/redstreet/beancount_reds_importers/blob/dabcb455b6a4fc776b2fcfea24e64a41ca819acb/beancount_reds_importers/importers/fidelity/fidelity_cma_csv.py#L44>.
 
You can split your description field into the type for the first 3 words 
(if that's valid), and then use the remaining for the memo (or throw it 
away). It'll look something like this (untested code!):

rdr = rdr.capture('Description', '(?:\\s)(?:\\w*)(.*)', ['type', 'memo'])

More info is in the petl reference 
<https://petl.readthedocs.io/en/stable/transform.html>.

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/7ad94a46-32be-4b8b-a980-f41e5b54c480n%40googlegroups.com.

Reply via email to