请教python中点中文字符处理

软件和网站开发以及相关技术探讨
回复
头像
planwolf
帖子: 721
注册时间: 2008-08-22 10:47
来自: dg

请教python中点中文字符处理

#1

帖子 planwolf » 2008-12-26 17:45

代码: 全选

#!/usr/bin/env python
#
# _*_ coding: utf-8 _*_
import Tkinter
top=Tkinter.Tk()
quit=Tkinter.Button(top,text='hello你好 world',command=top.quit)
quit.pack()
Tkinter.mainloop()
运行结果
err_2.png
这样又行,为什么阿,怎么处理
error_1.png
上次由 planwolf 在 2008-12-26 17:47,总共编辑 1 次。
头像
planwolf
帖子: 721
注册时间: 2008-08-22 10:47
来自: dg

Re: 请教python中点中文字符处理

#2

帖子 planwolf » 2008-12-26 17:46

error_3.png
error_4.png
上次由 planwolf 在 2008-12-26 17:50,总共编辑 1 次。
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

Re: 请教python中点中文字符处理

#3

帖子 BigSnake.NET » 2008-12-26 17:48

代码: 全选

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
planwolf
帖子: 721
注册时间: 2008-08-22 10:47
来自: dg

Re: 请教python中点中文字符处理

#4

帖子 planwolf » 2008-12-27 9:19

谢谢
但有点不明白,
# -*- coding: UTF-8 -*-
用#开头? 写在注释里面
narky
帖子: 42
注册时间: 2006-12-13 22:20

Re: 请教python中点中文字符处理

#5

帖子 narky » 2008-12-27 19:43

planwolf 写了:谢谢
但有点不明白,
# -*- coding: UTF-8 -*-
用#开头? 写在注释里面
没错。写在头部就可以了。虽然是#开头,也算是注释,你可以把他当作特殊的注释,它是用来标记文档编码类型的。
或者
#-*-encoding:utf-8-*-

如果你觉得这个方式比较奇怪,他也有很多种格式
#coding:utf-8 或者 #coding=utf-8 都是正确的

另外在字符串前面用u标记是unicode字符也是可以的,比如
self.title=u"这是是中文字符"
头像
planwolf
帖子: 721
注册时间: 2008-08-22 10:47
来自: dg

Re: 请教python中点中文字符处理

#6

帖子 planwolf » 2009-01-03 16:17

:em01
头像
planwolf
帖子: 721
注册时间: 2008-08-22 10:47
来自: dg

Re: 请教python中点中文字符处理

#7

帖子 planwolf » 2009-01-06 11:09

:em20 :em20
头像
kukat
帖子: 266
注册时间: 2006-06-14 6:12
联系:

Re: 请教python中点中文字符处理

#8

帖子 kukat » 2009-01-08 19:54

代码: 全选

#!/bin/env python
# -*- coding: utf-8 -*-

import sys
reload(sys)
sys.setdefaultencoding("utf-8")
This APT has Super Cow Powers
=======================
Asus G1s: t7500 + 2g ddr667 + 8600mgt with 256ddr3 + 500g sata
Asus G51JX-A1: i7 720 + 8G DDR3 + GTS360 + 500G
MacBook Pro 13"
=======================
头像
junxiang
帖子: 317
注册时间: 2006-09-07 13:44

Re: 请教python中点中文字符处理

#9

帖子 junxiang » 2009-01-10 9:45

代码: 全选

#!/usr/bin/python
# -*- coding: utf-8 -*-

print 'Hi,Python!\n我喜欢Python~'
:em11
自在的风~
头像
ws_105
帖子: 313
注册时间: 2008-10-24 8:02

Re: 请教python中点中文字符处理

#10

帖子 ws_105 » 2009-01-10 11:11

planwolf 写了:谢谢
但有点不明白,
# -*- coding: UTF-8 -*-
用#开头? 写在注释里面
一定要写在前两行才可以
Ubuntu 8.04 @ Intel Pentium D 925 + Intel 945G Chipset + DDR2 1.0G + SATA 160G
http://hi.baidu.com/ws_105
头像
gaint_star
帖子: 413
注册时间: 2008-02-20 0:09
来自: 深圳
联系:

Re: 请教python中点中文字符处理

#11

帖子 gaint_star » 2009-01-13 8:47

生活就像对待Linux一样,要敢于折腾也要学会折腾。
──────────────────────────────────
@picobird
回复