title: Why do printed characters disappear in this python code?
body: <p>(This question rised from an attempt to get around <a href="https://stackoverflow.com/questions/40346430/how-do-i-keep-python-from-printing-type-information">this problem</a>)</p>
  
  <p>I'm trying to print a list of dictionaries in python.
  Since I can't find a real function which is able to convert a python object to a string (no, json.dumps doesn't work), I thought to write a simple printing script.</p>
  
  <p>Unfortunately characters at the beginning of the line simply disappear...
  Now, I'm probably no expert in python, but this behavior looks nonsense to me.</p>
  
  <pre><code># The out object is returned by a library (rekall) 
  # and it is a list of dictionaries.
  import rekall
  out = rekall.a_modified_module.calculate()
  
  print '[',
  for ps in out:
      first = True
      print '{',
      for info in ps:
          if first:
              first = False
          else:
              print '\'%s\':\'%s\',' % (info, ps[info]),
      print '}',
  print ']'
  </code></pre>
  
  <p>I would expect the output to be:</p>
  
  <pre><code>[{'pid':'2040', 'name':'leon.exe', 'offset':'2234185984',}]
  </code></pre>
  
  <p>Instead I get this:</p>
  
  <pre><code>'pid':'2040', 'name':'leon.exe', 'offset':'2234185984',}]
  </code></pre>
  
  <p>Can you please explain me what's happening here? (I'm skipping first line in the loop because it contains another dictionary and the output gets even crazier, with mixed parts of the output)</p>
  
  <p>P.S.: if you have a valid option for printing a generic python object (something comparable to JSON.stringify in javascript, but without having to deal with JSON objects) please tell me.</p>
  
  <p>EDIT: My question aims at explaining this strange (to me) behavior,
  where the output depends on what is printed after the brackets.
  In fact, if I remove the inner for loop ("for info in ps"), the initial brackets are printed correctly.
  Also, if I create a pipe to send the output to another program, that program will receive the output correctly, starting from the brackets.</p>
  
  <p>EDIT: To help understanding the nature of the problem, and the type of the 'out' object, this is the output using the 'pprint' module:</p>
  
  <pre><code>[{'name':  [String:ImageFileName]: 'leon.exe\x00',
    'offset': 2236079360,
    'pid':  [unsigned int:UniqueProcessId]: 0x000007FC,
    'psscan': {'CSRSS': False,
               'Handles': False,
               'PsActiveProcessHead': True,
               'PspCidTable': True,
               'Sessions': True}}]
  </code></pre>