0
votes

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() 
3
this is not the same code that you got an error in, correct? - thebjorn

3 Answers

2
votes

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.

0
votes

Try using the built in csv library:

import csv

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

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.