python - Backslash-n not interpreted as newline when printed? -


given simple map:

combinations  = {'a':11, 'b': 12, 'c': 13} 

let print entries on separate lines:

print('combinations: ', '\n'.join(str(c) c in combinations.iteritems())) 

.. or maybe not ..

('combinations: ', "('a', 11)\n('c', 13)\n('b', 12)") 

why \n not interpreted newline here?

you’re using python 2 rather python 3, print printing tuple. converting tuple string applies repr elements.

either

  • switch python 3,

  • use __future__ print function in python 2,

    from __future__ import print_function 
  • or remove tuple.

    print 'combinations: ', '\n'.join(str(c) c in combinations.iteritems()) 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -