多谢指点!

多谢指点!

想将字符串转换为utf8编码格式,请问有函数吗?
找了很久,没找到。。。。
好冷啊
Unicode字符串可以用多种方式编码为普通字符串, 依照你所选择的编码(encoding):

<!-- Inject Script Filtered --> Toggle line numbers
   1 #将Unicode转换成普通的Python字符串:"编码(encode)"
   2 unicodestring = u"Hello world"
   3 utf8string = unicodestring.encode("utf-8"
   4 asciistring = unicodestring.encode("ascii"
   5 isostring = unicodestring.encode("ISO-8859-1"
   6 utf16string = unicodestring.encode("utf-16"
   7
   8
   9 #将普通的Python字符串转换成Unicode: "解码(decode)"
  10 plainstring1 = unicode(utf8string, "utf-8"
  11 plainstring2 = unicode(asciistring, "ascii"
  12 plainstring3 = unicode(isostring, "ISO-8859-1"
  13 plainstring4 = unicode(utf16string, "utf-16"

不知道这个行不.
unicodestring = u"Hello world"
如何将变量做这种处理呢?
比如说:a = "hello world"
unicodestring = .............????
unicode跟GB不是中文之间的转换吗?