Re: [Python] regex per modificare una stringa
On 11/11/12 19:26, Daniele Zambelli wrote: Il giorno 11 novembre 2012 19:11, Manlio Perillo manlio.peri...@gmail.com mailto:manlio.peri...@gmail.com ha scritto: [...] Perchè mai vorresti utilizzare le regex invece di un parser XML? Mi sembrava potesse essere più semplice per questa operazione, ma mi sono scontrato con il problema che ho esposto e quindi mi è sorto il dubbio. Tu quindi mi consigli di lavorare sull'albero XML. Fin'ora ho lavorato con alberi XML in sola lettura qui si tratta di modificarli... Non sono pratico, ma farò un po' di tentativi Potresti cominciare da qui: http://wiki.python.org/moin/PythonXml Io personalmente trovo sempre lxml [1] ottimo per lavorare con XML. Lorenzo [1] http://lxml.de/ ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
[Python] Somma da linea di comando
Salve a tutti, utilizzo python 2.7.2 in windows. Spesso uso l'interprete da shell come calcolatrice e poco fa ho notato un comportato strano facendo delle somme: C:\Users\maxpython Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. a = 12.20 b = 9.20 c = 4.20 print a + b + c 25.6 12.20 + 9.20 + 4.20 25.598 per quale motivo sommando direttamente gli addendi ottengo un risultato non corretto? E' un problema dell'interprete secondo voi? MC ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Somma da linea di comando
Il 12/11/2012 21:47, Massimo Capanni ha scritto: print a + b + c 25.6 12.20 + 9.20 + 4.20 25.598 per quale motivo sommando direttamente gli addendi ottengo un risultato non corretto? E' un problema dell'interprete secondo voi? trovi una risposta qui: http://docs.python.org/2/tutorial/floatingpoint.html ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Somma da linea di comando
2012/11/12 Massimo Capanni massimo.capa...@gmail.com: utilizzo python 2.7.2 in windows. Spesso uso l'interprete da shell come calcolatrice e poco fa ho notato un comportato strano facendo delle somme: C:\Users\maxpython Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. a = 12.20 b = 9.20 c = 4.20 print a + b + c 25.6 12.20 + 9.20 + 4.20 25.598 per quale motivo sommando direttamente gli addendi ottengo un risultato non corretto? E' un problema dell'interprete secondo voi? Curioso. Il mio python, 2.7.3 su linux, ha il comportamento diametralmente opposto. miron@aspie:~$ python Python 2.7.3 (default, Aug 1 2012, 05:16:07) [GCC 4.6.3] on linux2 Type help, copyright, credits or license for more information. a = 12.20 b = 9.20 c = 4.20 a + b + c 25.598 print 12.20 + 9.20 + 4.20 25.6 PS: http://docs.python.it/html/tut/node15.html MC © -- R K-M-S L ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Somma da linea di comando
Il giorno 12 novembre 2012 21:47, Massimo Capanni massimo.capa...@gmail.com ha scritto: Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. a = 12.20 b = 9.20 c = 4.20 print a + b + c 25.6 12.20 + 9.20 + 4.20 25.59 A dire il vero da me si comporta esattamente al contrario: Python 2.7.1 Type help, copyright, credits or license for more information. a = 12.20 b = 9.20 c = 4.20 a + b + c 25.598 print 12.20 + 9.20 + 4.20 25.6 Ciao.. ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Somma da linea di comando
Il giorno 12 novembre 2012 22:04, Carlo Miron mi...@python.it ha scritto: Curioso. Il mio python, 2.7.3 su linux, ha il comportamento diametralmente opposto. Scusa Carlo, non avevo visto la tua risposta... Ciao ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Somma da linea di comando
On Mon, Nov 12, 2012 at 10:10 PM, Daniele Palmese pal...@gmail.com wrote: A dire il vero da me si comporta esattamente al contrario: Toccati il naso, Daniele. © -- R K-M-S L ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Somma da linea di comando
Il 12/11/2012 22:10, Daniele Palmese ha scritto: A dire il vero da me si comporta esattamente al contrario: Python 2.7.1 Type help, copyright, credits or license for more information. a = 12.20 b = 9.20 c = 4.20 a + b + c 25.598 print 12.20 + 9.20 + 4.20 25.6 scusate, io sto appena muovendo i primi passi e magari mi sfugge qualcosa... però non mi sembra il contrario di quel che succede a Massimo il float è arrotondato quando si usa print quando invece si fa l'addizione è completo e la spiegazione sta nel link che ho incollato prima: http://docs.python.org/2/tutorial/floatingpoint.html e precisamente qui: It’s easy to forget that the stored value is an approximation to the original decimal fraction, because of the way that floats are displayed at the interpreter prompt. Python only prints a decimal approximation to the true decimal value of the binary approximation stored by the machine. If Python were to print the true decimal value of the binary approximation stored for 0.1, it would have to display 0.1 0.155511151231257827021181583404541015625 That is more digits than most people find useful, so Python keeps the number of digits manageable by displaying a rounded value instead 0.1 0.1 It’s important to realize that this is, in a real sense, an illusion: the value in the machine is not exactly 1/10, you’re simply rounding the display of the true machine value. This fact becomes apparent as soon as you try to do arithmetic with these values 0.1 + 0.2 0.30004 Note that this is in the very nature of binary floating-point: this is not a bug in Python, and it is not a bug in your code either. You’ll see the same kind of thing in all languages that support your hardware’s floating-point arithmetic (although some languages may not display the difference by default, or in all output modes). ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Somma da linea di comando
Dunque, mi sono accorto di una cosa (che forse genera diversità di risultato): print 12.20 + 9.20 + 4.20 25.6 12.20 + 9.20 + 4.20 25.598 print 12.20 + 9.20 + 4.20 25.6 a = 12.20 b = 9.20 c = 4.20 a+b+c 25.598 mi sembra di capire che la print tolga l'imbarazzo dell'approssimazione ... o ho capito male? 2012/11/12 Carlo Miron mi...@python.it On Mon, Nov 12, 2012 at 10:10 PM, Daniele Palmese pal...@gmail.com wrote: A dire il vero da me si comporta esattamente al contrario: Toccati il naso, Daniele. © -- R K-M-S L ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Somma da linea di comando
2012/11/12 Massimo Capanni massimo.capa...@gmail.com: Dunque, mi sono accorto di una cosa (che forse genera diversità di risultato): No, nessuna diversita` di risultato. Solo di presentazione. [snip] mi sembra di capire che la print tolga l'imbarazzo dell'approssimazione ... o ho capito male? Piu` che toglierlo, lo nasconde. Ma sotto sotto c'e` ancora. © -- R K-M-S L ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python