Trouble writing lines into file with line feeds- Python Newb

Jussi Piitulainen jpiitula at ling.helsinki.fi
Mon Dec 23 04:57:28 EST 2013


daniel.t.healy at gmail.com writes:
- -
> Problem: The file only contains P2. It always overwrites the first
> line. I can send 20 strings and the file will always contain the
> last string received.
- -
> while True:
>         rawcode=ser.readline()
>         codelog=open('/home/pi/avdms/codes.log','w')
- -

That's what file mode 'w' does. Use 'a'.

Also consider the logging module.

See <http://docs.python.org/3/library/functions.html#open> for open.

See <http://docs.python.org/3/library/logging.html> for logging.



More information about the Python-list mailing list