我正在尝试用Python 3.4学习pdfcrowd,因此我查看了他们的网站并复制了以下示例:
import pdfcrowd
try:
# create an API client instance
client = pdfcrowd.Client("username", "apikey")
# convert a web page and store the generated PDF into a pdf variable
pdf = client.convertURI('http://www.google.com')
# convert an HTML string and save the result to a file
output_file = open('html.pdf', 'wb')
html="<head></head><body>My HTML Layout</body>"
client.convertHtml(html, output_file)
output_file.close()
# convert an HTML file
output_file = open('file.pdf', 'wb')
client.convertFile('/path/to/MyLayout.html', output_file)
output_file.close()
except pdfcrowd.Error, why:
print('Failed: {}'.format(why))
当我尝试运行它时,出现以下错误:
File "pf.py" line 21
except pdfcrowd.Error, why:
^
SyntaxError: invalid syntax
谁能告诉我怎么修这个吗?你知道吗
这意味着将错误分配给变量
why
。这在Python2中是有效的语法,但在Python3中不是。改用except pdfcrowd.Error as why:
。这在Python2和Python3中是有效的语法相关问题 更多 >
编程相关推荐