Python: Append a list with a newline
<p>In the following code I am updating a list with two items by appending to it from within a for loop. I need a newline to be added after appending each string but I can't seem to be able to do it.</p>

<p>I thought it would have been:</p>

<pre><code>lines = []
for i in range(10):

    line = ser.readline()
    if line:
        lines.append(line + '\n')             #'\n' newline 
        lines.append(datetime.now())
</code></pre>

<p>But this only adds the '\n' as a string. I have also tried the same without without the quotes, but no luck.</p>

<p>I am getting this:</p>

<pre><code>['leftRaw; 928090;   0;  0.00;  0.00;  0.00;  0.00;  0.00;  0.00;      0.00;  0.00;\n', datetime.datetime(2016, 8, 25, 23, 48, 4, 517000), '\r\x00rightRaw; 928090;   0;  0.00;  0.00;  0.00;  0.00;  0.00;  0.00;  0.00;  0.00;\n', datetime.datetime(2016, 8, 25, 23, 48, 4, 519000), '\r\x00leftRaw; 928091;   0;  0.00;  0.00;  0.00;  0.00;  0.00;  0.00)]
</code></pre>

<p>But I want this:</p>

<pre><code>['leftRaw; 928090;   0;  0.00;  0.00;  0.00;  0.00;  0.00;  0.00;  0.00;  0.00;\n', 
datetime.datetime(2016, 8, 25, 23, 48, 4, 517000), 
'\r\x00rightRaw; 928090;   0;  0.00;  0.00;  0.00;  0.00;  0.00;  0.00;  0.00;  0.00;\n', 
datetime.datetime(2016, 8, 25, 23, 48, 4, 519000)]
</code></pre>

<p>Any ideas?</p>

<p>It looks like the <code>lines</code> list is simple being printed in its entirety. The <code>\n</code> you see is only printing as an indicator that there are in fact new-lines. See this smaller example:</p>

<pre><code>In [18]: print ['asdf' + '\n\n'] + [datetime.now()],
['asdf\n\n', datetime.datetime(2016, 8, 25, 15, 32, 5, 955895)]
In [19]: a = ['asdf' + '\n\n', datetime.now()]
In [20]: print a[0]
asdf

In [21]: print a
['asdf\n\n', datetime.datetime(2016, 8, 25, 15, 37, 14, 330440)]

In [22]:
</code></pre>

python