0

I opened a file through python. So, i did a lsof on the python process. output of lsof has the following line

COMMAND   PID    USER   FD   TYPE DEVICE SIZE/OFF       NODE NAME
python  15855 inaflash    3w   REG   0,25        0 4150810088 /home/inaflash/he.txt

Thing is, it has 3w. which means that the file is open for writing. But, i actually opened the file as follows

a = open('he.txt','r')

I read that, w means file is open for write. Can anyone help me understand why its w instead of r

rawwar
  • 4,834
  • 9
  • 32
  • 57

1 Answers1

1

I tried the same code in Python 3 and my file is opened in read mode.

enter image description here

enter image description here

Are you sure your file is the same opened with python and same python process ? Maybe you forgot to close the file somewhere in your code after opened it in write mode.

Edit: Also tried in Python 2, same result (read mode)

Alekos
  • 368
  • 2
  • 8
  • Thanks, Actually.. i first opened the file in write mode. Then closed it and then opened the same file in read mode. Then this happened – rawwar Oct 17 '19 at 09:02