开发者

How do i correct a files extension?

开发者 https://www.devze.com 2023-01-26 08:25 出处:网络
I started programming in Python a couple of days ago and I have a problem I couldn\'t solve yet. I want to correct a files file extension by guessing its mimetype.

I started programming in Python a couple of days ago and I have a problem I couldn't solve yet. I want to correct a files file extension by guessing its mimetype. I tried this:

new_file_name = mimetypes.guess_extension(mimetypes.guess_type开发者_如何转开发(file_name)))
os.rename(file_name, new_file_name)

Why doesnt it work?


mimetypes uses the existing extension to guess the file type. Use magic instead to examine the contents.

0

精彩评论

暂无评论...
验证码 换一张
取 消