I have just started using Python3. I am trying to open a csv file using Rodeo IDE
fp = open('Proteomics_Data.csv') # open file on read mode
lines = fp.read().split("\n") # create a list containing all lines
I am getting an error I paste it below.
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-347-aebf19dd596a> in <module>()
----> 1 lines = fp.read().split("\n")
/Users/alessandro/anaconda/lib/python3.6/encodings/ascii.py in decode(self, input, final)
24 class IncrementalDecoder(codecs.IncrementalDecoder):
25 def decode(self, input, final=False):
---> 26 return codecs.ascii_decode(input, self.errors)[0]
27
28 class StreamWriter(Codec,codecs.StreamWriter):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)
What I have found so far is the terminal not being set to UTF-8, but apparently Python 3 does not need UTF-8. I am not sure tif this could be a problem related to the IDE?
When I save a file as
CSV
I actually get two options:CSV UTF-8 (Comma delimited)(.csv)
andComma Separated Values(.csv)
If I save with the second option (Comma Separated Values) I don't need to add
encoding='utf-8'
Try specifying the encoding in the
open
function call.