-3

我编写代码视图html。但结果为无。

# coding: UTF-8

import urllib

class View_html:
    def __init__(self):
        url = "http://www.yahoo.com/"
        self.data = urllib.urlopen(url)

    def html(self):
        self.data.read()

if __name__=="__main__":
    a = View_html()
    print a.html()

结果

None

如何更改此代码?

4

1 回答 1

2

您忘记了return关键字:

def html(self):
    return self.data.read()
于 2013-03-02T15:25:18.200 回答