1:源代码
#!/usr/bin/env python name = raw_input('请输入您的姓名:') print 'Hello,', name
运行时出错:
y@y:~/my_note/my_python$ python 5.py File "5.py", line 3 SyntaxError: Non-ASCII character '\xe8' in file 5.py on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
2:修改后
#!/usr/bin/env python
#coding=utf-8
name = raw_input('请输入您的姓名:')
print 'Hello,', name
运行结果:
y@y:~/my_note/my_python$ python 5.py 请输入您的姓名:张三 Hello, 张三
也可以这么写:
#-*-coding:utf-8-*-
#!/usr/bin/env python #-*-coding:utf-8-*- name = raw_input('请输入您的姓名:') print 'Hello,', name