title: Doing the ls output magic in python
body: <p>I want to have the same output as ls creates in a bash or python script.
  I don't mean listing directories, but the thing ls does to be able to be "loopable". Example:</p>
  
  <pre><code># ls
  a b c d
  
  # ls | head -n 1
  a
  
  # for i in $(ls); do echo "file: $i"; done
  file: a
  file: b
  file: c
  file: d
  </code></pre>
  
  <p>How can ls be like that and still display everything in one line when calling it?</p>
  
  <p>Using tabs doesn't work.. Newlines just force it to be multiple lines. \000 doesn't work.</p>
  
  <pre><code># echo -e "a\tb\tc\td" | head -n 1
  a    b    c    d
  
  echo -e "a\000b\000c\000d" | head -n 1
  abcd
  </code></pre>
  
  <p>cat -A doesn't give me much info...</p>
  
  <pre><code># cat -A &lt;(ls --color=no)
  a$
  b$
  c$
  d$
  
  # cat -A &lt;(echo -e "a\nb\nc\nd")
  a$
  b$
  c$
  d$
  </code></pre>
  
  <p>So.. How can I generate the same type of output does in my scripts? Is there any control characters I am missing here?</p>