<div dir="ltr">Vi ringrazio, <div><br></div><div>in fin dei conti, nel file da formattare non ci sono caratteri particolari, per cui ho deciso di non allargarmi in altri moduli!<div><br></div><div>ecco il codice risultante: </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 class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,128,0)">import</span> <span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,128,0)">import</span> <span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">infile</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">=</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,128,0)">open</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">sys</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">argv</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">[</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(102,102,102)">1</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">],</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">'r'</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">)</span>
<span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">outfile</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">=</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(0,128,0)">open</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">sys</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">argv</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">[</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(102,102,102)">2</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">],</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">'w'</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">)</span>
<span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">outfile</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">write</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"<?xml version=</span><span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">1.0</span><span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)"> encoding=</span><span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">utf-8</span><span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">?></span><span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)"><resources></span><span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">)</span>
<span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">line</span> <span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">infile</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">readlines</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">():</span>
<span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">line</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">strip</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">():</span>
<span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">name</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">,</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">value</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">=</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">[</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">word</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">strip</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">()</span> <span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">word</span> <span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">line</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">split</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"="</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">,</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(102,102,102)">1</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">)</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">]</span>
<span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">outfile</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">write</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</span><span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)"><string name=</span><span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">+</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">name</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">+</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</span><span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">>"</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">+</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">value</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">+</span> <span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</string></span><span class="" 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 class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">)</span>
<span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">outfile</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">write</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">(</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent;color:rgb(186,33,33)">"</resources>"</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">)</span>
<span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">infile</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">close</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;background-color:transparent">()</span>
<span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">outfile</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline;color:rgb(102,102,102)">.</span><span class="" style="margin:0px;padding:0px;border:0px;outline:0px;vertical-align:baseline">close</span><span class="" 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 class="" 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>
<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">
Dante.</pre></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-02-24 13:47 GMT+01:00 Dario Bertini <span dir="ltr"><<a href="mailto:berdario@gmail.com" target="_blank">berdario@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">.split(maxsplit=2)<br>
<br>
comunque, se il file di input è un .ini, c'è già il modulo configparser:<br>
<a href="http://docs.python.org/3.3/library/configparser.html" target="_blank">http://docs.python.org/3.3/library/configparser.html</a><br>
<br>
e per generare l'xml, ci sono già diversi moduli che lo fanno correttamente:<br>
<a href="http://docs.python.org/3.3/library/xml.html" target="_blank">http://docs.python.org/3.3/library/xml.html</a><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
xmpp: <a href="mailto:berdario@gmail.com">berdario@gmail.com</a><br>
bitmessage: BM-2cTYXfGiSTsnx3righ6aHcJSWe4MV17jDP<br>
gpg fingerprint: 3F8D53518012716C4EEF7DF67B498306B3BF75A0 (used just<br>
for signing commits)<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<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>
</div></div></blockquote></div><br></div>