如何使用iptcinfo3(Python)在添加元数据时从图像中移除尾部?

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

How to remove tails from images when adding metadata with iptcinfo3 (python)?

问题

我使用 iptcinfo3 中的 IPTCInfo 进行工作。当我保存元数据到图像时,使用以下代码:

info = IPTCInfo(image_file, force=True)

添加元数据后:

...

然后我保存:

info.save()

这时会创建一个带有 ~ 的新文件。这些文件在我打开文件夹时是不可见的,但如果我进入终端并键入 ls,我可以看到这些文件,而且这些文件占用了我的空间。在终端中,我看到的情况如下:

image1.jpg
image1.jpg~
image2.jpg
image2.jpg~
image3.jpg
image3.jpg~
image4.jpg
image4.jpg~
image5.jpg
image5.jpg~
image6.jpg
image6.jpg~

如何删除带有 ~ 的文件,或者如何更改代码以防止创建这些文件?

提前感谢!

英文:

I'm working with from iptcinfo3, IPTCInfo. When I save metadata to the image, code below...

info = IPTCInfo(image_file, force=True)

adding metadata...

...

after that I save...
info.save()

and this is when new file is created that has ~. These files are not visible when I open folder, but if I go to terminal - and type ls, I can see these files, also these files are taking my space. I see this like this in my terminal;

image1.jpg
image1.jpg~
image2.jpg
image2.jpg~
image3.jpg
image3.jpg~
image4.jpg
image4.jpg~
image5.jpg
image5.jpg~
image6.jpg
image6.jpg~

How to delete files with ~, or change code that these are not created?

Thanks in advance!

答案1

得分: 1

你需要在你的 save 函数中设置 overwrite 选项。

info.save(options='overwrite')

如果你想要删除以 ~ 结尾的文件,运行:

rm *~
英文:

You need to set the overwrite option in your save function.

info.save(options='overwrite')

If you want to delete the files that end with ~, run:

rm *~

huangapple
  • 本文由 发表于 2023年6月19日 00:30:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76501537.html
匿名

发表评论

匿名网友

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

确定