Python – How do I modify a file in Python

How do I modify a file in Python… here is a solution to the problem.

How do I modify a file in Python

I created a

python package install with and I want it to copy a data file in the folder (created for this) ~/.did. The problem is that I have to call with sudo permissions because it is in /usr/local/… .

Then I decided to add a call to os.chmod() after the setup() function, but I was wondering if anyone had a more concise way to do that.

Here is my file:

#!/usr/bin/env python

from distutils.core import setup
import os


      description='Daily Image Downloader',
      author='Luc Mazon',
      author_email='[email protected]',
      license='GNU GPL v3',
                  ('/usr/share/man/man1', ['doc/did.1.gz']),
                  (home+'/.did', ['did.xml'])

os.chmod(home+'/.did/did.xml', 0666)

Since did.xml is not a python file, I also created an file with the following line:

include did.xml

The global structure of my package is as follows:

 | didlib
 |  |
 |  |
 | .doc
 |  |-did.1.gz
 | did.xml
 | did


I think it would be better and more accustomed to not writing any config files to the installer’s home directory at all. What about other users? A better approach is to check your code at initialization time, add a new file if the file exists on the user running it, and if not, just add a new file.

Related Problems and Solutions