How To Delete The "u And ' ' " Before The Of Database Table Display By Python
I am trying to use python to create a database and then insert data and display it. However, the output adds a u before every string. What should I do, how can I delete the 'u'? th
Solution 1:
You are looking at whole tuples with unicode strings; the u''
is normal when showing you a tuple with unicode values inside:
>>> printu'Hello World!'
Hello World!
>>> print (u'Hello World',)
(u'Hello World',)
You want to format each row:
printu' {:<15} {:<8} {:<6}'.format(*row)
See the str.format()
documentation, specifically the Format Syntax reference; the above formats 3 values with field widths, left-aligning each value into their assigned width.
The widths are approximate (I didn't count the number of spaces in your post exactly), but should be easy to adjust to fit your needs.
Demo:
>>>row = (u'31/05/2013', u'11:10', u'$487')>>>printu' {:<15} {:<8} {:<6}'.format(*row)
31/05/2013 11:10 $487
or, using a loop and a sequence of row entries:
>>>rows = [...(u'31/05/2013', u'11:10', u'$487'),...(u'31/05/2013', u'11:11', u'$487'),...(u'31/05/2013', u'11:13', u'$487'),...(u'31/05/2013', u'11:19', u'$487'),...]>>>for row in rows:...printu' {:<15} {:<8} {:<6}'.format(*row)...
31/05/2013 11:10 $487
31/05/2013 11:11 $487
31/05/2013 11:13 $487
31/05/2013 11:19 $487
Post a Comment for "How To Delete The "u And ' ' " Before The Of Database Table Display By Python"