Python问题:SyntaxError: Non-ASCII character '\xe2' in file
代码如下#!/usr/bin/pythonclassEmployee:'thebaseclassofeveryemployee'empCount=0def_init_(s...
代码如下
#!/usr/bin/python
class Employee:
'the base class of every employee'
empCount = 0
def _init_(self,name,salary):
self.name=name
self.salary=salary
Employee.empCount +=1
def displayCount(self):
print 'total employee is %d' % Employee.empCount
def displayEmp(self):
print 'Name :',self.name,'Salary :',self.salary
t1 = input ‘please enter a name’
t2 = input 'please enter salary'
emp1 = Employee(t1,t2)
emp1.displayCount
emp1.displayEmp
结果:
File "C:\Users\i319594\Desktop\Python\employee.py", line 19
SyntaxError: Non-ASCII character '\xe2' in file C:\Users\i319594\Desktop\Python\
employee.py on line 19, but no encoding declared;
想问下有人知道这是什么原因吗? 展开
#!/usr/bin/python
class Employee:
'the base class of every employee'
empCount = 0
def _init_(self,name,salary):
self.name=name
self.salary=salary
Employee.empCount +=1
def displayCount(self):
print 'total employee is %d' % Employee.empCount
def displayEmp(self):
print 'Name :',self.name,'Salary :',self.salary
t1 = input ‘please enter a name’
t2 = input 'please enter salary'
emp1 = Employee(t1,t2)
emp1.displayCount
emp1.displayEmp
结果:
File "C:\Users\i319594\Desktop\Python\employee.py", line 19
SyntaxError: Non-ASCII character '\xe2' in file C:\Users\i319594\Desktop\Python\
employee.py on line 19, but no encoding declared;
想问下有人知道这是什么原因吗? 展开
展开全部
第19行是哪一行? 你是不是输入中文了?
在文件头加
#!/usr/bin/python
#-*-coding:utf-8-*-
试试
在文件头加
#!/usr/bin/python
#-*-coding:utf-8-*-
试试
更多追问追答
追问
加了以后是这样
File "C:\Users\i319594\Desktop\Python\employee.py", line 20
t1 = raw_input 'please enter a name'
^
SyntaxError: invalid syntax
追答
你用的python版本是多少
raw_input('please enter a name')
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在你的views.py文件第一行写入#coding=utf-8,再运行就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询