On Sat, Sep 27, 2008 at 3:42 PM, Michael Crute <mc****@gmail.c omwrote:
On Sat, Sep 27, 2008 at 5:43 PM, A. Joseph <jo******@gmail .comwrote:
>What should I look for in a file to determine whether or not it is a MS Word file or an Excel file or a PDF file, etc., etc.? including Zip files
I don`t want to check for file extension. os.path.splite xt('Filename.jp g') will produce a tuple of filename and extension, but some file don`t even have extension and can still be read by MS Word or NotePad. i want to be 100% sure of the file.
You could use the mimetypes module...
<<< import mimetypes
<<< mimetypes.guess _type("LegalNot ices.pdf")
>>>('applicatio n/pdf', None)
Looking at the docs for the mimetypes module, it just guesses based on
the filename (and extension), not the actual contents of the file, so
it doesn't really help the OP, who wants to make sure their program
isn't misled by an inaccurate extension.
Regards,
Chris
--
Follow the path of the Iguana... http://rebertia.com
>
-mike
--
_______________ _______________ __
Michael E. Crute http://mike.crute.org
God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
-- http://mail.python.org/mailman/listinfo/python-list 1 3867
On Sep 27, 4:01*pm, "Chris Rebert" <c...@rebertia. comwrote:
On Sat, Sep 27, 2008 at 3:42 PM, Michael Crute <mcr...@gmail.c omwrote:
On Sat, Sep 27, 2008 at 5:43 PM, A. Joseph <joefa...@gmail .comwrote:
What should I look for in a file to determine whether or not it is a
MS Word file or an Excel file or a PDF file, etc., etc.? including Zip
files
I don`t want to check for file extension.
os.path.splitex t('Filename.jpg ') will produce a tuple of filename and
extension, but some file don`t even have extension and can still be read by
MS Word or NotePad. i want to be 100% sure of the file.
You could use the mimetypes module...
<<< import mimetypes
<<< mimetypes.guess _type("LegalNot ices.pdf")
>>('applicati on/pdf', None)
Looking at the docs for the mimetypes module, it just guesses based on
the filename (and extension), not the actual contents of the file, so
it doesn't really help the OP, who wants to make sure their program
isn't misled by an inaccurate extension.
Regards,
Chris
--
Follow the path of the Iguana...http://rebertia.com
-mike
--
_______________ _______________ __
Michael E. Crute http://mike.crute.org
God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
-- http://mail.python.org/mailman/listinfo/python-list
Check http://sourceforge.net/project/showf...group_id=23617
for the 'file' command for Windows.
~Sean This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: CR |
last post by:
having a problem with the final strcpy of filename from *argv into a
structure containing an array with 20 elements called fname
It seems that strcpy & strncpy aren't stopping after null is found but
appending other trash overwriting the array possibly?
Any help would be appreciated!
(if you need all the code let me know)
int main(int argc, char *argv)
{
int *arg_chk;
int i; int j=0;
|
by: giftson.john |
last post by:
Hi,
I am creating an application which migrates all documents from one
repository to another repository. Before migration i have to verify
all the documents are unique. No duplicates has to be uploaded. Event
the document created date, modified date, filename can be different.
How to find the document is duplidate.
What i did is, i created a file and did save as and saved into another
location. I am not able to find that the document...
|
by: Chris Rebert |
last post by:
On Sat, Sep 27, 2008 at 2:43 PM, A. Joseph <joefazee@gmail.comwrote:
Well, if you're on unix, you could run the 'file' command and check
its output using the 'subprocess' module, but it sounds like you're on
Windows...
Regards,
Chris
--
Follow the path of the Iguana...
|
by: Michael Crute |
last post by:
On Sat, Sep 27, 2008 at 5:43 PM, A. Joseph <joefazee@gmail.comwrote:
You could use the mimetypes module...
<<< import mimetypes
<<< mimetypes.guess_type("LegalNotices.pdf")
-mike
--
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |