Pylance在此上下文中不允许进行解压缩操作



我有一个这样的函数:

def post(self, request):
submitted_form = ProfileForm(request.POST, request.FILES)
content = ''
apples_royal_gala = 'Appels Royal Gala 13kg 60/65 Generica PL Klasse I'
ananas_crownless = 'Ananas Crownless 14kg 10 Sweet CR Klasse I'
peen_waspeen = 'Peen Waspeen 14x1lkg 200-400 Generica BE Klasse I'
if submitted_form.is_valid():
uploadfile = UploadFile(image=request.FILES["upload_file"])
name_of_file = str(request.FILES['upload_file'])
uploadfile.save()
print('path of the file is:::', uploadfile.image.name)          
with open(os.path.join(settings.MEDIA_ROOT,
f"{uploadfile.image}"), 'r') as f:
print("Now its type is ", type(name_of_file))
print(uploadfile.image.path)
# reading PDF file
if name_of_file.endswith('.pdf'):
pdfFile = wi(filename=uploadfile.image.path,
resolution=300)
text_factuur_verdi = []
image = pdfFile.convert('jpeg')
imageBlobs = []
for img in image.sequence:
imgPage = wi(image=img)
imageBlobs.append(imgPage.make_blob('jpeg'))
for imgBlob in imageBlobs:
image = Image.open(io.BytesIO(imgBlob))
text = pytesseract.image_to_string(image, lang='eng')
text_factuur_verdi.append(text)
totalString = re.findall(ExtractingTextFromFile.make_pattern(
apples_royal_gala), (*text_factuur_verdi[0])) + re.findall(ExtractingTextFromFile.make_pattern(
ananas_crownless), (*text_factuur_verdi[0]))
content = totalString
# ENDING Reading pdf file
else:
content = f.read()
print(content)
return render(request, "main/create_profile.html", {
'form': ProfileForm(),
"content": content
})
return render(request, "main/create_profile.html", {
"form": submitted_form,
})

输出是这样的:

['3.304,08', '3.962,00']

但我希望值不带括号('[]'(。

因此,我尝试用"*"来解压缩列表中的值。

但后来我得到了这个错误:

Unpack operation not allowed in this context  Pylance

所以我的问题是:如何解决这个问题?

join就是您要查找的:

...
output = ['3.304,08', '3.962,00']
unpacked = ", ".join(output)
print(unpacked)
> '3.304,08, 3.962,00'

如果你想要"'3.304,08', '3.962,00'"作为输出,你需要做

unpacked = ", ".join(["'"+e+"'" for e in output])

最新更新