Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a file of Type file in python

Tags:

python

I have few mail files stored without any extension:

mail files

how to open them??

like image 506
Prashant Vikram Singh Avatar asked Jan 04 '23 10:01

Prashant Vikram Singh


2 Answers

with open('1', 'r') as fp:
    content = fp.read()

This way, the file will always be closed.

like image 77
math2001 Avatar answered Jan 16 '23 22:01

math2001


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)
like image 22
Pike D. Avatar answered Jan 16 '23 20:01

Pike D.