A question about unicode() function
Felipe Almeida Lessa
felipe.lessa at gmail.com
Sun Dec 31 08:30:44 EST 2006
On 31 Dec 2006 05:20:10 -0800, JTree <eastera at gmail.com> wrote:
> def funUrlFetch(url):
> lambda url:urllib.urlopen(url).read()
This function only creates a lambda function (that is not used or
assigned anywhere), nothing more, nothing less. Thus, it returns None
(sort of "void") no matter what is its argument. Probably you meant
something like
def funUrlFetch(url):
return urllib.urlopen(url).read()
or
funUrlFetch = lambda url:urllib.urlopen(url).read()
> objUrl = raw_input('Enter the Url:')
> content = funUrlFetch(objUrl)
content gets assigned None. Try putting "print content" before the unicode line.
> content = unicode(content,"gbk")
This, equivalent to unicode(None, "gbk"), leads to
> TypeError: coercing to Unicode: need string or buffer, NoneType found
None's are not strings nor buffers, so unicode() complains.
See ya,
--
Felipe.
More information about the Python-list
mailing list