Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
27970 มุมมอง

Hi,

I have customize the sale and purchase report but while printing the report I am getting error "UnboundLocalError: local variable 'filepart' referenced before assignment". and I have installed  "prt_report_attachment_preview" OCA module.

I am not getting why I am getting this error. Could anyone help me to resolve this error.

Thanks in advance!

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

First you have to define the variable. See the example given in this answer:  local variable referenced before assignment

Thanks

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

The Unboundlocalerror: local variable referenced before assignment is raised when you try to use a variable before it has been assigned in the local context. Python doesn't have variable declarations , so it has to figure out the scope of variables itself. It does so by a simple rule: If there is an assignment to a variable inside a function, that variable is considered local .   To solve this problem, you can explicitly say it's a global by putting global declaration in your function. The global statement does not have to be at the beginning of the function definition, but that is where it is usually placed. Wherever it is placed, the global declaration makes a variable to global variable everywhere in the function.

http://net-informations.com/python/err/local.htm



อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ธ.ค. 20
3066
2
ก.ย. 20
3312
1
ก.พ. 20
3087
Return multiply pdfs for products แก้ไขแล้ว
1
ต.ค. 19
2533
0
มี.ค. 22
2525