英文:
variable for pdf file is referenced before assignment
问题
以下是翻译好的部分:
"我尝试运行我的代码,出现了以下错误消息,请帮忙。这是错误消息:
Traceback (most recent call last):
File "C:/Users/tauau/OneDrive/Desktop/IS104/Assignment/Assign1_S11151996_2.py", line 34, in
generate_invoice(client_name, project_name, estimated_hours, hourly_rate)
File "C:/Users/tauau/OneDrive/Desktop/IS104/Assignment/Assign1_S11151996_2.py", line 13, in generate_invoice
pdf_file = pdf_file.pdf()
UnboundLocalError: local variable 'pdf_file' referenced before assignment"
英文:
Ive tried running my code and this error message comes up, please help. This is the error message:
Traceback (most recent call last):
File "C:/Users/tauau/OneDrive/Desktop/IS104/Assignment/Assign1_S11151996_2.py", line 34, in \<module\>
generate_invoice(client_name, project_name, estimated_hours, hourly_rate)
File "C:/Users/tauau/OneDrive/Desktop/IS104/Assignment/Assign1_S11151996_2.py", line 13, in generate_invoice
pdf_file = pdf_file.pdf()
UnboundLocalError: local variable 'pdf_file' referenced before assignment
答案1
得分: 1
你会看到错误信息说“引用了未分配的变量'pdf_file'”。
这意味着你在告诉Pythonpdf_file
是什么之前尝试使用它。
错误消息还告诉你错误发生的地方。
Assign1_S11151996_2.py, line 13, in generate_invoice
。
pdf_file = pdf_file.pdf()
我最好的猜测是你尝试将某个文件转换为PDF,然后存储在pdf_file
中。如果是这样,你可能想这样做
pdf_file = {插入正确的文件变量}.pdf()
英文:
You'll see that your error says "variable 'pdf_file' referenced before assignment".
This means that you tried to use the pdf_file
before you told python what pdf_file
is.
The error message also tells you exactly where the error occurred.
Assign1_S11151996_2.py, line 13, in generate_invoice
.
pdf_file = pdf_file.pdf()
My best guess is that you're trying to convert some file into a pdf and then store it inside pdf_file
. If so, you probably want to do this
pdf_file = {insert the correct file variable}.pdf()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论