Re: A question about unicode() function
- From: "Felipe Almeida Lessa" <felipe.lessa@xxxxxxxxx>
- Date: Sun, 31 Dec 2006 11:30:44 -0200
On 31 Dec 2006 05:20:10 -0800, JTree <eastera@xxxxxxxxx> 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.
.
- References:
- A question about unicode() function
- From: JTree
- A question about unicode() function
- Prev by Date: Re: Are all classes new-style classes in 2.4+?
- Next by Date: Re: WebCrawler (was: 'Question concerning this list')
- Previous by thread: A question about unicode() function
- Next by thread: py2exe 0.6.6 released
- Index(es):
Relevant Pages
|