ecapsul
V2EX  ›  Python

python3 求助

By ecapsul at 2015 年 7 月 17 日 · 4000 次点击

初学py3,

import urllib.request
def getHtml(url):
page=urllib.request.urlopen(url)
html=page.read()
return html
print getHtml('http://tieba.baidu.com')

运行提示出错,不知道错在哪儿,求教
print getHtml('http://tieba.baidu.com')
^
SyntaxError: invalid syntax

4 条回复  •  2015-07-17 12:39:44 +08:00
bidu
   1
bidu  
   2015 年 7 月 17 日
print(getHtml('http://tieba.baidu.com'))试试?
Sylv
   2
Sylv  
   2015 年 7 月 17 日 via iPhone   ❤️ 1
Python 3 要用 print(getHtml('http://tieba.baidu.com'))
print 不加括号是 Python 2 的语法
ecapsul
   3
ecapsul  
OP
   2015 年 7 月 17 日
了解了,谢谢各位
jas0ndyq
   4
jas0ndyq  
   2015 年 7 月 17 日
doge
推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
© 2026 V2EX · 33ms · 3.9.8.5