“variable for pdf file is referenced before assignment” 变量在赋值之前被引用。

huangapple go评论48阅读模式
英文:

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()

huangapple
  • 本文由 发表于 2023年4月4日 08:37:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75924676.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定