Export coordinates

Hello. I need help. I write python script in which I give G-code M114. It is successfully printing the coordinates in OctoPrint terminal depending on what M114 returns but I need these coordinates to store them in a variable and then export it to a .txt file. How can I do that? Thank you.

EventHandlerPlugin mixin + PositionUpdate event