2

In python what is actual difference between unicodecsv package and csv package? while printing elements in csv file when imported by unicodecsv it is printed along with character u

import unicodecsv
ion = []
f = open('csvlear.csv','r')
pop = unicodecsv.DictReader(f)
for i in pop:
    ion.append(i)
    print(i)
f.close()

output:

{u'age': u'1'}
{u'age': u'2'}
{u'age': u'3'}
{u'age': u'4'}

instead of importing unicode if csv package is imported, the character u is omitted.what is the difference

Learner
  • 21
  • 3
  • Seems like the real question you have is what is the difference between `unicode` and `str`. Check [this](https://stackoverflow.com/a/18034409/2715819) out. – RishiG May 16 '18 at 05:53
  • In python 2, `str` is a single byte string of characters or binary bytes, while `unicode` is a larger Unicode string that supports a vast number of character sets for languages across the world. In python 2, `csv` doesn't support Unicode but the `unicodecsv` extension module does. – tdelaney May 16 '18 at 06:03
  • 4
    The real question is why learn python 2? Python 3 has been out a long time, it has integrated Unicode and it is much better platform for internationalized programs. – tdelaney May 16 '18 at 06:03

1 Answers1

1

If you are using Python 2 for some reasons then you need unicodecsv because it can read all the unicode characters used by different human languages. The csv module in Python2 did not support those. So basically it is a replacement for csv module in Python 2.7. However in Python 3, the unicodes are supported by default and hence the csv module works fine.

Moby Khan
  • 5,016
  • 3
  • 13
  • 16