r3bol 0 Newbie Poster
import ConfigParser
replace_name = "Bob"
replace_comment = "Bob was here"
parser = ConfigParser.RawConfigParser()
parser.optionxform = str # make option names case sensitive
parser.read("/home/asdf/Dev/python/info_icons/test.desktop")

parser.set("Desktop Entry", "Name", replace_name)
parser.set("Desktop Entry", "Comment", replace_comment)
parser.write(open("modified.desktop", "w"))

The code above reads and writes changes to a configuration style file in Linux (actually the one used for desktop icons). Problem is, it doesn't write back any commented lines and also treats the important executable line, #!/usr/bin/env xdg-open
as a comment.
I guess the comments aren't so important but, the exec line is. What would be the best practice to make sure the line #!/usr/bin/env xdg-open is included when writing back changes made by configParser?

Many thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.