0

clients.to_csv('Machine Testing Database.csv',index=False)

I need the end result csv file in Read only mode, is there any way?

SarangP
  • 3
  • 2
  • 1
    Does this answer your question? [Change file to read-only mode in Python](https://stackoverflow.com/questions/28492685/change-file-to-read-only-mode-in-python) – Edo Akse Jul 28 '22 at 09:32

1 Answers1

1

"df.to_csv" cannot do this, but you can use "os.chmod" to change the file's mode to "readonly" after do "df.to_csv".

you can do it like:

import os
import stat
import pandas as pd

df = pd.DataFrame({'name': ['Raphael', 'Donatello'],
                   'mask': ['red', 'purple'],
                   'weapon': ['sai', 'bo staff']})
filepath = 'test.txt'
df.to_csv(filepath, index=None)
os.chmod(filepath, stat.S_IREAD) # change the file's mode to readonly