在camelot
Python 中只接受当前目录。如果临时添加文件,则不被接受。有什么解决办法吗?
我收到以下错误:
File "/home/arun/.local/lib/python3.5/site-packages/PyPDF2/pdf.py", line 1689, in read
stream.seek(-1, 2)
OSError: [Errno 22] Invalid argument
如何添加正确的路径?请用一个例子来解释这一点:这将对我有所帮助。
def generate_pdf_csv(self):
file_name = self.pdf_name
attachment_dict = {
'name': file_name,
'datas': self.file_upload_pdf,
'datas_fname': file_name,
'res_model': self._name,
'res_id': self.id,
'type': 'binary',
}
attachment_id =
self.env['ir.attachment'].sudo().create(attachment_dict)
temp_dir = tempfile.gettempdir()
temp_path = os.path.join(temp_dir, file_name)
pdf_file = temp_path
tables = camelot.read_pdf(pdf_file, pages='all')
csv_file = 'FOLLL123.csv'
tables.export(csv_file, f='csv', compress=True)
tables[0].to_csv(csv_file)