Hi Rida,

I ran here’s a snippet to help you collect the notes attached in form of a 
pastebin link

You see what’s happening is you’re trying to print the note of each line 
present in each transaction in the nested for loop which is why it’s returning 
you None for the lines which have comments missing (I’m assuming you’re marking 
comments using semicolons ; )

Try out the code snippet linked below

https://pastebin.com/CpgK8iiv

It will print out all the comments in each of your journal posts , you just 
need to filter out the None lines and just append the ones which have a comment 
,


Also if you want to check what attributes a post object has that you can play 
with and __dict__ shows you blank , try out the

dir(post) command , it will show you both the functions you can call and the 
variables present in the object ,  to print it out simple
Use a for loop to print the attributes
Something like ,

for attribute in dir(post):
    print(
        attribute,
        "value=",
         getattr(post,attribute))


If you face any issue with getting the notes using the script I gave you in 
pastebin , let me know I’ll try to help out , I tested the code out on my 
ledger file and it worked pretty well


On 8 Jun 2021, 6:59 PM +0530, ra <[email protected]>, wrote:
> How can can I print comments e.g. "MD5Sum: 4d296..." in python?
>
> The *working* bash equivalent is ` ledger -f file.dat csv --csv-format 
> "%(join(note | xact.note))"`
>
> Tried this snippet so far:
>
> ```python
> import ledger
>
> for xact in ledger.read_journal("file.dat").xacts():
> for post in xact.posts():
> print(post.date, post.amount, post.account)
> # print(post.note) # Returns None
> # print(post.__dict__) # Attempting to print all key:values...returns empty
> ```
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups 
> "Ledger" 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/ledger-cli/878s3k5vtu.fsf%40notebox.ch.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" 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/ledger-cli/01090179ef1f65cf-972cd846-88af-411b-81e3-5b60a6b360c7-000000%40ap-south-1.amazonses.com.

Reply via email to