Python编码西班牙语
on line 18, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
解决办法:
可以使用
#coding: iso-8859-15
或者使用
#coding: latin-1
来编码西班牙语
此行必须位于第一行或者第二行
例如:
#!/usr/bin/python3 #coding: iso-8859-15 import PyPDF2 # pip install PyPDF2 def get_number_of_page(pdf_src): with open(pdf_src, 'rb') as f: pdf = PyPDF2.PdfFileReader(f) info = pdf.getDocumentInfo() number_of_pages = pdf.getNumPages() print(f'{pdf_src} >>>> {number_of_pages}') print(info) print('\n\n\n') pdf_list = ['PARTE 2 Cómo funcionan los mercados_70.pdf'] for item in pdf_list: get_number_of_page(item)
# -*- coding: iso-8859-15 -*- # -*- coding: latin-1 -*-
参考:https://www.python.org/dev/peps/pep-0263/