Python check type of file




















Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New.

Most popular in Python. As it turned out, various projects are faced with the need to recognize the file format, so I decided to release my solution in open-source as a module for Python called fleep link to the GitHub page. Also there are examples of usage and a complete list of supported file formats on the GitHub project page.

I improve fleep every day, adding new features and formats. You can use it in your project :. I would be glad to hear your opinion about my module. English is not my native language, so, excuse me for any mistakes :. Instagram Ads in Which Perform Better? Interview Decentralized Interview. Site Color. For any other feedbacks or questions you can either use the comments section or contact me form. Save my name and email in this browser for the next time I comment.

Notify me via e-mail if anyone answers my comment. Table of Contents. Name Type Mutable? Related Posts. Didn't find what you were looking for? Assuming m is a string, you can use endswith : if m. To be case-insensitive, and to eliminate a potentially large else-if chain: m. Improve this answer. Or is rpartition really high efficiency? Stevoisiak, I think you misplaced your comment as this solution works even in the case you point out — JayTuma.

This doesn't account for folder names with periods. You can confirm if it is a file or folder with os. JayTuma Thanks for pointing that out, I fixed my comment — Stevoisiak. Acorn Acorn This is however the way a leading space should be treated. You can exclude those with os.

Use pathlib From Python3. Greg Greg 1, 15 15 silver badges 11 11 bronze badges. Stevoisiak what do you mean? In what was does it not account for that? I just tried and. If there is a folder named folder. Look at module fnmatch.



0コメント

  • 1000 / 1000