0

I tried to run following programme in ubuntu terminal but I am getting some error. But it is not giving any error in jupyter notebook

File "imsl.py", line 5 SyntaxError: Non-ASCII character '\xe2' in file imsl.py on line 5, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

import numpy
import matplotlib.pyplot


data_file ​= open("mnist_train_100.csv",'r') 
data_list ​=  ​data_file.readlines() 
data_file.close() 
1
  • 3
    this is not the same code that you got an error in, correct? Commented Aug 7, 2017 at 19:10

3 Answers 3

2

You've got a stray byte floating around. You can find it by running

with open("imsl.py") as fp:
    for i, line in enumerate(fp):
        if "\xe2" in line:
            print i, repr(line)

You'll see the line number and the offending line(s). You can then delete the line and recreate it to remove the stray byte.

You could also add # -*- coding: utf-8 -*- to the top of the file to enforce encoding, as per your link.

Sign up to request clarification or add additional context in comments.

Comments

0

Try using the built in csv library:

import csv

data_file = list(csv.reader(open('mnist_train_100.csv')))

1 Comment

The built in csv library can only handle ASCII, you can try pypi.python.org/pypi/unicodecsv/0.9.0 if you need a unicode CSV reader.
0

You have a stray Unicode byte in the places where ? is in this code:

import numpy
import matplotlib.pyplot


data_file ?= open("mnist_train_100.csv",'r') 
data_list ?=  ?data_file.readlines() 
data_file.close() 

Correct it, and you're good to go.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.