Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62601
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-12-22 16:55 -0800 |
| Message-ID | <f4f962d9-0e23-4b33-ba88-ce61afbb3418@googlegroups.com> (permalink) |
| Subject | 2nd Try: Trouble writing lines to file that include line feeds - Newbie |
| From | Dan Healy <daniel.t.healy@gmail.com> |
Overview: I'm attempting to read strings from a serial port. Each string ends with a carriage return and line feed. I want to write those strings to a file, like a log file. So, if I send P1 and the P2 on a new line, I would expect to open this file and find (line 1) P1 (line 2) P2.
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.
Code:
#Import the serial module
import serial
#Open the serial port w/ settings
ser=serial.Serial(
port="/dev/ttyUSB0",
baudrate=9600,
timeout=None)
#Print data received on the serial port after removing the CR and LF characters
while True:
rawcode=ser.readline()
codelog=open('/home/pi/avdms/codes.log','w')
codelog.write(rawcode)
codelog.close()
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
2nd Try: Trouble writing lines to file that include line feeds - Newbie Dan Healy <daniel.t.healy@gmail.com> - 2013-12-22 16:55 -0800 Re: 2nd Try: Trouble writing lines to file that include line feeds - Newbie Gary Herron <gary.herron@islandtraining.com> - 2013-12-23 00:33 -0800
csiph-web