Reputation: 101
I have few mail files
stored without any extension:
how to open them??
Upvotes: 4
Views: 5397
Reputation: 2985
Yet another way:
import os
import glob
files = filter(os.path.isfile, glob.glob("./[0-9]*"))
for name in files:
with open(name) as fh:
contents = fh.read()
# do something with contents (parse email format)
Upvotes: 2
Reputation: 691
To add on to @math2001's answer, you could do something like this:
numOfFiles = #int
data = []
for files in range(1, numOfFiles+1):
with open(str(files), 'r') as f:
// do whatever data processing you need to do
fileData = f.read()
data.append(fileData)
Upvotes: 3
Reputation: 4500
with open('1', 'r') as fp:
content = fp.read()
This way, the file will always be closed.
Upvotes: 4