-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow querying a Path's mime-type #79107
Comments
How about adding basic "mime_type" method to "pathlib.Path" ? Code would do something like: import mimetypes
def mime_type(name):
"""Mime-type of the file."""
find = name.rfind('.')
ext = '' if find == -1 else name[find:]
return mimetypes.types_map.get(ext, 'application/octet-stream') Users would use it like so: import pathlib
file = pathlib.Path('hello_world.py')
print(file.mime_type) # 'text/x-python' |
-0 There is some value in having a separation of responsibilities and in not adding another dependency. On the other hand, I can see how this would sometimes be convenient. Assigning to Antoine to make the decision. |
Thanks for the report. There was a similar request to add pathlib.rmtree (bpo-33498) and adding more methods as Raymond mentioned might be convenient but there is a maintenance cost (msg316517) since there is a consensus that pathlib should do everything os.path does. It's up to Antoine to decide on this. |
I would rather have the mimetypes module improved to accept Path-like objects, so that the following works: >>> p = Path('LICENSE.txt')
>>> mimetypes.guess_type(p)
('text/plain', None) It should be quite simple to implement as well. |
As part of triaging, I am closing this since this was merged with doc changes and there was no back port done since it's an enhancement. Antoine, feel free to reopen this if there are any changes left. Thanks everybody for the feedback and review. |
No, I simply forgot to close it. Thank you! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: