I am building a code to hold any command made by the keyboard, they will be published in a ROS structure topic to control a mobile robot. I'm not very familiar with Python, the most I've achieved regarding data storage was the code below ... For example, let's assume the left directional is typed, I need to store it it was pressed to only inform the robot he should move in such a way.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
arq = open('/home/lucas/Área de Trabalho/robosmoveis2018/dados.txt', 'w')
text = """
Lista
---
1
2
3
"""
arq.write(text)
arq.close()