Hi all,

the init.xml file has among its lines, one line as <guid>5934</guid>


I need to increment the guid every time I modify the file. Could any one please tell me how to do that.


Edited by mike_2000_17: Fixed formatting

6 Years
Discussion Span
Last Post by jcao219
Featured Replies
  • [QUOTE=griswolf;1272831] If you need to allow people to edit the file by hand; [/QUOTE] Heh, in my opinion, [URL="http://docs.djangobrasil.org/topics/templates.html"]"Making humans edit XML is sadistic!"[/URL] - Django Philosophy Read More


You can use Regular Expressions.
Search the file for that pattern, get the "guid" number, increment it by one, then write it.
I haven't done regex in a while, so I'm not sure about the syntax.


Well, the first thing is that [URL="http://dirtsimple.org/2004/12/python-is-not-java.html"]"XML is not the answer"[/URL]. If you need to allow people to edit the file by hand; or if you are supporting an existing system, then maybe. Otherwise, I strongly suggest you use something else (pickle file? Python format config file?, simple ini type layout?).

Assuming you are stuck with this, I would either use an xml parser or a regular expression to find and replace the guid value. Be aware that since this is a text file, users [B]can[/B] hand edit it, so you cannot count on the exact format (there might be an added or missing line break, extra white space, comments ...)

Edited by Nick Evan: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.