4

I am writing a python module that writes data into an XML file. The piece of code that handles the write is:

from xml.dom.minidom import Document
#using DOMXml

main = Document() #create an XML Document

toFile = open('output.xml','w')

main.writexml(toFile, indent ='    ', newl="\n")
#writexml() is the operation from Document that was imported

toFile.close()

The final output.xml has the size of 422 bytes onto Gentoo OS. Given the default blocksize of Gentoo is 1024 bytes. I am wondering how many writes to disk that piece of code would generate (since it's dependant on the file operation).

Thank you!

Tu Hoang
  • 4,622
  • 13
  • 35
  • 48
  • It completely depends on what code is in the method `main.writexml()`. You could be doing a write for each byte for all we know. – Rafe Kettler Jun 28 '11 at 16:23
  • Oh my bad. Let me clarify my question further. – Tu Hoang Jun 28 '11 at 16:27
  • 2
    This is *way* below the level you should or can think about when writing Python. Heck, it's even below the level many C programmers think! –  Jun 28 '11 at 16:31
  • 1
    It may also depend on the file system (journalled or not) and whether the file exists already (the file name itself must be written somewhere). Also, file attributes may be changed depending on the file system. – extraneon Jun 28 '11 at 16:40

1 Answers1

3

Run the program under strace to find out.

Igor Nazarenko
  • 2,184
  • 13
  • 10