Popular recipes tagged "write"http://code.activestate.com/recipes/tags/write/popular/2010-04-18T17:18:50-07:00ActiveState Code RecipesFile read/write routines (Python)
2010-04-18T17:18:50-07:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/577199-file-readwrite-routines/
<p style="color: grey">
Python
recipe 577199
by <a href="/recipes/users/57155/">Denis Barmenkov</a>
(<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/read/">read</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/write/">write</a>).
Revision 2.
</p>
<p>For small dirty hacks in Perl has a module File::Slurp.
I wrote two simple functions when I moving from Perl to Python - one for reading files and second for writing files. Valuable data is list of lines or blob (additionally specified argument binmode=1).</p>
Arbitrary order attribute writing with ElementTree (Python)
2008-08-01T19:24:34-07:00Orri Ganelhttp://code.activestate.com/recipes/users/2259404/http://code.activestate.com/recipes/576403-arbitrary-order-attribute-writing-with-elementtree/
<p style="color: grey">
Python
recipe 576403
by <a href="/recipes/users/2259404/">Orri Ganel</a>
(<a href="/recipes/tags/attribute/">attribute</a>, <a href="/recipes/tags/element/">element</a>, <a href="/recipes/tags/elementtree/">elementtree</a>, <a href="/recipes/tags/element_tree/">element_tree</a>, <a href="/recipes/tags/etree/">etree</a>, <a href="/recipes/tags/order/">order</a>, <a href="/recipes/tags/sort/">sort</a>, <a href="/recipes/tags/write/">write</a>, <a href="/recipes/tags/writing/">writing</a>, <a href="/recipes/tags/xml/">xml</a>).
Revision 5.
</p>
<p>Modified version of ElementTree with two additional parameters to the write() method: "sortflag" and "sortcmp". "sortflag" defaults to "default", which results in unmodified behavior. "sortcmp" defaults to None, which results in unmodified behavior. See discussion for usage and justification. Changes made begin on line 655.</p>
<p>EDIT: in most cases, unless sortflag happened to be intended for the root, it would be ignored; added sortflag and sortcmp to self._write() call on line 724. Expect another revision in the near future to allow for specifying different orders for different xml tags.</p>
<p>EDIT, the second: Added tag-specific ordering.</p>