Python - Removing \n when using default split()?
<p>I'm working on strings where I'm taking input from the command line. For example, with this input:</p>

<pre><code>format driveName "datahere"
</code></pre>

<p>when I go string.split(), it comes out as:</p>

<pre><code>&gt;&gt;&gt; input.split()
['format, 'driveName', '"datahere"']
</code></pre>

<p>which is what I want.</p>

<p>However, when I specify it to be string.split(" ", 2), I get:</p>

<pre><code>&gt;&gt;&gt; input.split(' ', 2)
['format\n, 'driveName\n', '"datahere"']
</code></pre>

<p>Does anyone know why and how I can resolve this? I thought it could be because I'm creating it on Windows and running on Unix, but the same problem occurs when I use nano in unix.</p>

<p>The third argument (data) could contain newlines, so I'm cautious not to use a sweeping newline remover. </p>

<p>Default separator in <code>split()</code> is all whitespace which includes newlines <code>\n</code> and spaces. </p>

<p>Here is what the <a href="https://docs.python.org/2/library/stdtypes.html#str.split" rel="nofollow">docs on split</a> say:</p>

<pre><code>str.split([sep[, maxsplit]])

If sep is not specified or is None, a different splitting algorithm is 
applied: runs of consecutive whitespace are regarded as a single 
separator, and the result will contain no empty strings at the start 
or end if the string has leading or trailing whitespace. 
</code></pre>

<p>When you define a new <code>sep</code> it only uses that separator to <code>split</code> the strings.  </p>

python