<div dir="ltr">In effetti ho bisogno di qualcosa di pių robusto, ho creato questo:<div><br></div><div><div>#!/usr/bin/python</div><div><br></div><div>import xml.etree.cElementTree as ET</div><div>import string</div><div>import sys</div>
<div><br></div><div>infile = open(sys.argv[1], 'r') </div><div><br></div><div>resources = ET.Element("resorurces")</div><div><br></div><div>for line in infile.readlines():</div><div> if line.strip():</div>
<div> name, value = [ word.strip() for word in line.split("=",1) ]</div><div> string = ET.SubElement(resources,"string")</div><div> string.set("name", name)</div><div> string.text = value</div>
<div><br></div><div>infile.close()</div><div><br></div><div>tree = ET.ElementTree(resources)</div><div>tree.write(sys.argv[2])</div></div><div><br></div><div>ma non va...</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
2014-02-24 21:12 GMT+01:00 Diego Barrera <span dir="ltr"><<a href="mailto:diegonebarrera@yahoo.it" target="_blank">diegonebarrera@yahoo.it</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><div class="">
<div>On 24/02/2014 20:48, Dante Loi wrote:</div>
<blockquote type="cite">
<div dir="ltr"><br>
<div>
<div>
<pre style="margin-top:0px;margin-bottom:0px;padding:15px;border:0px;outline:0px;font-size:13px;vertical-align:baseline;background-color:transparent;font-family:monospace,sans-serif;word-wrap:normal;overflow:auto;color:rgb(85,85,85);line-height:18px">
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(64,128,128);font-style:italic">#!/usr/bin/python</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,128,0)">import</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,255);font-weight:bold">string</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,128,0)">import</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,0,255);font-weight:bold">sys</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">infile</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">=</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,128,0)">open</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">sys</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">argv</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">[</span><span>1</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">],</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">'r'</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">)</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">outfile</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">=</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,128,0)">open</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">sys</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">argv</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">[</span><span>2</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">],</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">'w'</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">)</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">outfile</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">write</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"<?xml version=</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(187,102,34);font-weight:bold">\"</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">1.0</span><span style="margin:0px;padding:0 px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(187,102,34);font-weight:bold">\"</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)"> encoding=</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(187,102,34);font-weight:bold">\"</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">utf-8</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(187,102,34);font-weight:bold">\"</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">?></span><span>\n</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)"><resources></span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(187,102,34);font-weight:bold">\n</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">)</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,128,0);font-weight:bold">for</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">line</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(170,34,255);font-weight:bold">in</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">infile</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">readlines</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">():</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,128,0);font-weight:bold">if</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">line</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">strip</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">():</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">name</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">,</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">value</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">=</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">[</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">word</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">strip</span><span>()</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,128,0);font-weight:bold">for</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">word</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(170,34,255);font-weight:bold">in</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">line</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">split</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span>"="</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">,</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(102,102,102)">1</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">)</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">]</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">outfile</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">write</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(187,102,34);font-weight:bold">\t</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)"><string name=</span><span>\"</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">+</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">name</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">+</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(187,102,34);font-weight:bold">\"</span><span>>"</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">+</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">value</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">+</span> <span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</string></span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(187,102,34);font-weight:bold">\n</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</span><span>)</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">outfile</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">write</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</resources>"</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">)</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">infile</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">close</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">()</span>
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">outfile</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">close</span><span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">()</span></pre>
<pre style="margin-top:0px;margin-bottom:0px;padding:15px;border:0px;outline:0px;font-size:13px;vertical-align:baseline;background-color:transparent;font-family:monospace,sans-serif;word-wrap:normal;overflow:auto;color:rgb(85,85,85);line-height:18px">
<span style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">se volete proporre qualche miglioria č ben'accetta comunque funziona alla perfezione!</span>
</pre>
</div>
</div>
</div>
</blockquote></div>
Per l'output puoi dare un'occhiata a format:<br>
<a href="http://docs.python.org/2.7/library/stdtypes.html?highlight=format#str.format" target="_blank">http://docs.python.org/2.7/library/stdtypes.html?highlight=format#str.format</a><br>
<br>
Ciao<span class="HOEnZb"><font color="#888888"><br>
diego<br>
</font></span></div>
<br>_______________________________________________<br>
Python mailing list<br>
<a href="mailto:Python@lists.python.it">Python@lists.python.it</a><br>
<a href="http://lists.python.it/mailman/listinfo/python" target="_blank">http://lists.python.it/mailman/listinfo/python</a><br>
<br></blockquote></div><br></div>