Re: [Python] uso di str.format
Il giorno gio, 03/05/2018 alle 11.20 +0200, Massimiliano Rosi ha scritto: > Ciao a tutta la lista, > vi chiedo un consulto, sull'utilizzo di str.format, cioè: > > '{:.2f}'.format(55.6789) > ritorna: > '55.68' > > è possibile modificare a runtime quante cifre dopo la virgola > visualizzare? Ho tentato (sicuramente sbagliando), ad utilizzare > qualcosa del tipo: > > '{:g}'.format(55.6789, g=':.2f') > il cui risultato è: > 55.6789 Dovrai fare due chiamate credo: In [1]: '{{:.{}f}}'.format(5).format(55.6789) Out[1]: '55.67890' Pietro ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] uso di str.format
2018-05-03 12:24 GMT+02:00 Alessandro Dentella: > > Format specifiers can themselves contain replacement fields. For example, a > field whose field width is itself a parameter could be specified via: > > > In [3]: "{0:.{1}f}".format(3.14185, 2) > Out[3]: '3.14' > > > La frase è presa da qui: https://www.python.org/dev/peps/pep-3101/ > > sandro > *:-) > Grazie Sandro, avevop googlato per cercare la documentazione che tu hai linkato, ma non avevo trovato questo esempio. Ciao. M. ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] uso di str.format
Il 3 maggio 2018 12:21, Carlo Mironha scritto: '{0:.{1}f}'.format(55.6789, 2) > '55.68' '{0:.{1}f}'.format(55.6789, 3) > '55.679' '{0:.{1}f}'.format(55.6789, 4) > '55.6789' > ``` > > ㎝ Grazie Carlo, è proprio la soluzione che tentavo di raggiungere senza trovare il bandolo! Ciao. M. ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] uso di str.format
2018-05-03 11:20 GMT+02:00 Massimiliano Rosi: > Ciao a tutta la lista, > vi chiedo un consulto, sull'utilizzo di str.format, cioè: > > '{:.2f}'.format(55.6789) > ritorna: > '55.68' > > è possibile modificare a runtime quante cifre dopo la virgola > visualizzare? Ho tentato (sicuramente sbagliando), ad utilizzare > qualcosa del tipo: > > '{:g}'.format(55.6789, g=':.2f') > il cui risultato è: > 55.6789 > Se proprio vuoi farti del male prova cosi' o qualcosa di simile: >>> from math import pi >>> template = '{:.%df}' >>> [(template % i).format(pi) for i in range(5)] ['3', '3.1', '3.14', '3.142', '3.1416'] Se tieni a te stesso e a quelli che leggeranno il tuo codice in futuro prova cosi': >>> str(round(pi, 3)) '3.142' Ciao -- http://alepisa.blogspot.com Esalando Prassi ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] uso di str.format
On Thu, May 03, 2018 at 11:20:04AM +0200, Massimiliano Rosi wrote: > Ciao a tutta la lista, > vi chiedo un consulto, sull'utilizzo di str.format, cioè: > > '{:.2f}'.format(55.6789) > ritorna: > '55.68' > > è possibile modificare a runtime quante cifre dopo la virgola > visualizzare? Ho tentato (sicuramente sbagliando), ad utilizzare > qualcosa del tipo: > > '{:g}'.format(55.6789, g=':.2f') > il cui risultato è: > 55.6789 Format specifiers can themselves contain replacement fields. For example, a field whose field width is itself a parameter could be specified via: In [3]: "{0:.{1}f}".format(3.14185, 2) Out[3]: '3.14' La frase è presa da qui: https://www.python.org/dev/peps/pep-3101/ sandro *:-) -- Sandro Dentella *:-) http://trepalchi.itIl portale degli artisti http://www.reteisi.org Soluzioni libere per le scuole http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] uso di str.format
2018-05-03 12:08 GMT+02:00 Massimiliano Rosi: > come indicavo nella mail precedente, l'utilizzo classico di str.format > mi è chiaro, infatti riportavo l'esempio: > '{:.2f}'.format(55.6789) il cui output è '55.68' > > ma chiedevo se era possibile modificare il parametro di conversione a > runtime, durante l'esecuzione del programma, in modo da poter > convertire il float in base ad un valore diverso di volta in volta. > > Dal mio esempio: > '{:g}'.format(55.6789, g=':.2f') ``` >>> '{0:.{1}f}'.format(55.6789, 2) '55.68' >>> '{0:.{1}f}'.format(55.6789, 3) '55.679' >>> '{0:.{1}f}'.format(55.6789, 4) '55.6789' ``` ㎝ -- | THE -WARE LICENSE (Revision ㊷) | -- | wrote this mail. As long as you retain | this notice you can do whatever you want with this stuff. | If we meet some day, and you think this stuff is worth it, | you can buy me a in return. -- Carlo Miron ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] uso di str.format
> Se ho capito bene hai provato questo? '{:.2f}'.format(55.6789) > '55.68' '{:.3f}'.format(55.6789) > '55.679' '{:.4f}'.format(55.6789) > '55.6789' > > Ciao > Marcello Ciao Marcello, come indicavo nella mail precedente, l'utilizzo classico di str.format mi è chiaro, infatti riportavo l'esempio: '{:.2f}'.format(55.6789) il cui output è '55.68' ma chiedevo se era possibile modificare il parametro di conversione a runtime, durante l'esecuzione del programma, in modo da poter convertire il float in base ad un valore diverso di volta in volta. Dal mio esempio: '{:g}'.format(55.6789, g=':.2f') pensando al parametro g come ad un valore che può cambiare durante l'esecuzione. Grazie. Massimiliano ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
Re: [Python] uso di str.format
Il giorno 3 maggio 2018 11:20, Massimiliano Rosi < massimiliano.r...@gmail.com> ha scritto: > Ciao a tutta la lista, > vi chiedo un consulto, sull'utilizzo di str.format, cioè: > > '{:.2f}'.format(55.6789) > ritorna: > '55.68' > > Se ho capito bene hai provato questo? >>> '{:.2f}'.format(55.6789) '55.68' >>> '{:.3f}'.format(55.6789) '55.679' >>> '{:.4f}'.format(55.6789) '55.6789' >>> Ciao Marcello ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
[Python] uso di str.format
Ciao a tutta la lista, vi chiedo un consulto, sull'utilizzo di str.format, cioè: '{:.2f}'.format(55.6789) ritorna: '55.68' è possibile modificare a runtime quante cifre dopo la virgola visualizzare? Ho tentato (sicuramente sbagliando), ad utilizzare qualcosa del tipo: '{:g}'.format(55.6789, g=':.2f') il cui risultato è: 55.6789 Grazie in anticipo. M. ___ Python mailing list Python@lists.python.it https://lists.python.it/mailman/listinfo/python
[Python] Uso di __getattr__ e old style class e new style class
Buongiorno a tutti Dato il seguente codice : class TestClassOldStyle(): def __init__(self): self.store = dict() def __getattr__(self,name): print '__getattr__ :' ,name if not hasattr(dict,name): raise AttributeError(dict has no attribute '%s' % name) return getattr(self.store,name) class TestClassNewStyle(object): def __init__(self): self.store = dict() def __getattr__(self,name): print '__getattr__ :' ,name if not hasattr(dict,name): raise AttributeError(dict has no attribute '%s' % name) return getattr(self.store,name) def test(factory): x = factory() x['foo'] = 21 print x['foo'] print len(x) if __name__==__main__: print ' - TestClassOldStyle --' test(TestClassOldStyle) print '\n\n\n - TestClassNewStyle --' test(TestClassNewStyle) Risultato : - TestClassOldStyle -- __getattr__ : __setitem__ __getattr__ : __getitem__ 21 __getattr__ : __len__ 1 - TestClassNewStyle -- Traceback (most recent call last): File /Users/fporcari/Downloads/pyro_test/testobject.py, line 38, in module test(TestClassNewStyle) File /Users/fporcari/Downloads/pyro_test/testobject.py, line 27, in test x['foo'] = 21 TypeError: 'TestClassNewStyle' object does not support item assignment In pratica vorrei che per ogni attributo che è definito in dict mi venisse restituita la chiamata su self.store mentre ogni attributo non definito in dict dovrebbe generare un attribute error. Magari è una cosa banale ma ora come ora non vedo perchè con le new style class non funzioni e non funzioni al punto di non mettere nemmeno le print di debug... Grazie :) G ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di __getattr__ e old style class e new style class
On 09/10/2013 16:26, Giovanni Porcari wrote: Buongiorno a tutti [...] class TestClassNewStyle(object): def __init__(self): self.store = dict() def __getattr__(self,name): print '__getattr__ :' ,name if not hasattr(dict,name): raise AttributeError(dict has no attribute '%s' % name) return getattr(self.store,name) def test(factory): x = factory() x['foo'] = 21 print x['foo'] print len(x) [...] test(TestClassNewStyle) [...] - TestClassNewStyle -- Traceback (most recent call last): File /Users/fporcari/Downloads/pyro_test/testobject.py, line 38, in module test(TestClassNewStyle) File /Users/fporcari/Downloads/pyro_test/testobject.py, line 27, in test x['foo'] = 21 TypeError: 'TestClassNewStyle' object does not support item assignment In pratica vorrei che per ogni attributo che è definito in dict mi venisse restituita la chiamata su self.store mentre ogni attributo non definito in dict dovrebbe generare un attribute error. http://docs.python.org/2.7/reference/datamodel.html#special-method-lookup-for-new-style-classes Ciao Manlio ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di __getattr__ e old style class e new style class
Il giorno 09/ott/2013, alle ore 17:07, Manlio Perillo manlio.peri...@gmail.com ha scritto: On 09/10/2013 16:26, Giovanni Porcari wrote: Buongiorno a tutti [...] class TestClassNewStyle(object): def __init__(self): self.store = dict() def __getattr__(self,name): print '__getattr__ :' ,name if not hasattr(dict,name): raise AttributeError(dict has no attribute '%s' % name) return getattr(self.store,name) def test(factory): x = factory() x['foo'] = 21 print x['foo'] print len(x) [...] test(TestClassNewStyle) [...] - TestClassNewStyle -- Traceback (most recent call last): File /Users/fporcari/Downloads/pyro_test/testobject.py, line 38, in module test(TestClassNewStyle) File /Users/fporcari/Downloads/pyro_test/testobject.py, line 27, in test x['foo'] = 21 TypeError: 'TestClassNewStyle' object does not support item assignment In pratica vorrei che per ogni attributo che è definito in dict mi venisse restituita la chiamata su self.store mentre ogni attributo non definito in dict dovrebbe generare un attribute error. http://docs.python.org/2.7/reference/datamodel.html#special-method-lookup-for-new-style-classes Ciao Manlio ___ Grazie Manlio. Sei sempre una certezza :) G ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di __getattr__ e old style class e new style class
On Wed, Oct 9, 2013 at 5:23 PM, Giovanni Porcari giovanni.porc...@softwell.it wrote: Grazie Manlio. Sei sempre una certezza :) +1 :-) -- http://beri.it/ - Un blog http://beri.it/i-miei-libri/ - Qualche libro ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di __getattr__ e old style class e new style class
On 09/10/2013 17:43, Marco Beri wrote: On Wed, Oct 9, 2013 at 5:23 PM, Giovanni Porcari giovanni.porc...@softwell.it mailto:giovanni.porc...@softwell.it wrote: Grazie Manlio. Sei sempre una certezza :) +1 E se io sono una certezza, tu che scrivi libri che sei, un dogma? :) Ciao Manlio ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di __getattr__ e old style class e new style class
On Wed, Oct 9, 2013 at 6:33 PM, Manlio Perillo manlio.peri...@gmail.com wrote: On 09/10/2013 17:43, Marco Beri wrote: E se io sono una certezza si tu che scrivi libri che sei, un dogma? :) si :) -- Gian Mario Tagliaretti GNOME Foundation member gia...@gnome.org ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di __getattr__ e old style class e new style class
On Wed, Oct 9, 2013 at 6:33 PM, Manlio Perillo manlio.peri...@gmail.comwrote: E se io sono una certezza, tu che scrivi libri che sei, un dogma? :) Solo uno che sa scrivere più o meno correttamente in italiano e che rispetta (quasi sempre) le scadenze dell'editore :-) Chi sa fa, chi non sa... ecc. Ciao. Marco. ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di __getattr__ e old style class e new style class
2013/10/9 Marco Beri marcob...@gmail.com Chi sa fa, chi non sa... ecc. nun ce provà sempre a rubà la palla agli insegnanti di educazione fisica ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di with
Il 14/06/2012 17:08, Lorenzo Sutton ha scritto: vorrebbe una PEP per includerla nelle eccezioni predefinite :) Lorenzo. +1 ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
[Python] Uso di with
Non riesco a capire l'uso dello statement with... potreste spiegarmelo in maniera semplice, magari con un esempio? Grazie!___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di with
2012/6/14 piergiorgio pancino piert...@yahoo.it Non riesco a capire l'uso dello statement with... potreste spiegarmelo in maniera semplice, magari con un esempio? with google is better :) http://effbot.org/zone/python-with-statement.htm ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di with
io ho trovato questo... http://www.webmasterwords.com/python-with-statement sempre with google... Certo che Marco è proprio un fulmine ;-)) 2012/6/14 Marco Beri marcob...@gmail.com 2012/6/14 piergiorgio pancino piert...@yahoo.it Non riesco a capire l'uso dello statement with... potreste spiegarmelo in maniera semplice, magari con un esempio? with google is better :) http://effbot.org/zone/python-with-statement.htm ___ 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] Uso di with
with vuole un context manager un context manager è un ogetto che si occupa di fare qualcosa prima del tuo codice e dopo.. una sorta di il CM fa qualcosa... try: il tuo codice finally: il CM fa o chiude qualcosa con with tu scrivi solo with CM: tuo codice ad esempio per aprire/chiudere una connessione o un file è molto comodo ciao S 2012/6/14 piergiorgio pancino piert...@yahoo.it Non riesco a capire l'uso dello statement with... ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di with
ho provato a creare questa classe per provare with, ... class provaWith(object): def __init__(self): print(Init eseguito) self.data=[1,2,3,4,5,6] def __enter__(self): print(Enter eseguito) def __exit__(self, exc_type, exc_value, traceback): print (exit eseguito) def funzione(self): return Sto eseguendo if __name__==__main__: a=provaWith() with a: for i in range(5): print(a.funzione()) che mi da come risultato: Init eseguito Enter eseguito Sto eseguendo Sto eseguendo Sto eseguendo Sto eseguendo Sto eseguendo exit eseguito quindi direi missione compiuta :)___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di with
2012/6/14 piergiorgio pancino piert...@yahoo.it ho provato a creare questa classe per provare with, ... che mi da come risultato: Init eseguito Enter eseguito Sto eseguendo Sto eseguendo Sto eseguendo Sto eseguendo Sto eseguendo exit eseguito oppure, sfruttando yield, potresti fare una cosa del genere... from contextlib import contextmanager @contextmanager def prova_with(): print(init eseguito) yield print (exit eseguito) def funzione(): return sto eseguendo with prova_with(): for idx in range(5): print(funzione()) non è esattamente equivalente al tuo, però mostra un uso di yield associato a with Marco ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di with
On Thu, Jun 14, 2012 at 4:20 PM, piergiorgio pancino piert...@yahoo.itwrote: quindi direi missione compiuta :) :-) Prova a cambiare il corpo del main così: if __name__==__main__: print Inizio a=provaWith() with a: for i in range(5): if i == 3: raise Exception(Azz!) print(a.funzione()) print Fine Secondo te cosa stampa? ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di with
On 14/06/12 16:41, Marco Beri wrote: [...] raise Exception(Azz!) Ci vorrebbe una PEP per includerla nelle eccezioni predefinite :) Lorenzo. ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
[Python] Uso di PyCurl
Un saluto a tutta la lista Sono nuovissimo sia della lista che dell'uso di python, ora come progetto per realizzare il mio secondo eseguibile in Py. vorrei riscrivere uno script Bash in questo linguaggio. Questo script controlla un certo file in internet e quando nota che viene aggiornato lo scarica. Per fare ciò in bash usavo il comando: curl -Ikis URL Ora vorrei riscrivere lo stesso comando con pycurl, ma non ho capito in quale modo passo le varie opzioni (-Ikis). Un saluto a Voi. Tiziano. ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di PyCurl
Scusate, ma come si crea un eseguibile? Cioè un programma che posso installarlo, dove lo posso leggere? Grazie Il giorno 29/mag/09, alle ore 18:26, Tiziano ha scritto: Un saluto a tutta la lista Sono nuovissimo sia della lista che dell'uso di python, ora come progetto per realizzare il mio secondo eseguibile in Py. vorrei riscrivere uno script Bash in questo linguaggio. Questo script controlla un certo file in internet e quando nota che viene aggiornato lo scarica. Per fare ciò in bash usavo il comando: curl -Ikis URL Ora vorrei riscrivere lo stesso comando con pycurl, ma non ho capito in quale modo passo le varie opzioni (-Ikis). Un saluto a Voi. Tiziano. ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python -- Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f Sponsor: Per il ponte del 2 giugno scegli le offerte speciali dei Riccione Family Hotels! Bimbi gratis, spiaggia, baby menu, miniclub, parchi divertimento. Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid72d)-5 ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di PyCurl
On Fri, 29 May 2009 18:26:13 +0200, Tiziano teb...@alice.it wrote: Questo script controlla un certo file in internet e quando nota che viene aggiornato lo scarica. Per fare ciò in bash usavo il comando: curl -Ikis URL Ora vorrei riscrivere lo stesso comando con pycurl, ma non ho capito in quale modo passo le varie opzioni (-Ikis). Non conosco la libreria, ma mi sembra con setopt(): vedi http://pycurl.sourceforge.net/doc/curlobject.html Poi devi vedere in http://curl.haxx.se/libcurl/c/curl_easy_setopt.html come le opzioni di riga di comando vengono mappate in argomenti: mi sembra siano: -i = CURLOPT_HEADER -s = CURLOPT_NOPROGRESS -I = CURLOPT_NOBODY -k = CURLOPT_SSL_VERIFYPEER (vedi http://curl.haxx.se/docs/sslcerts.html) Non ho testato niente, eh! -- Daniele Varrazzo - Develer S.r.l. http://www.develer.com ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di PyCurl
On Fri, 29 May 2009 18:42:02 +0200, nuvolare nuvol...@email.it wrote: Scusate, ma come si crea un eseguibile? Cioè un programma che posso installarlo, dove lo posso leggere? http://www.pyinstaller.org/ è la soluzione più completa che conosco. Puoi vedere le slide del Pycon per la descrizione di come usarlo: http://www.pycon.it/static/stuff/slides/distribuire-programmi-python-con-pyinstaller.pdf Ce ne sono altri (e.g. py2exe) ma PyInstaller l'ho usato e so che funziona bene. Nota che il nome è fuorviante: crea un eseguibile, non un installer! Per fare gli installer ci sono tante soluzioni indipentendi da Python (inno setup etc.) -- Daniele Varrazzo - Develer S.r.l. http://www.develer.com ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] Uso di PyCurl
2009/5/29 Daniele Varrazzo p...@develer.com Nota che il nome è fuorviante: crea un eseguibile, non un installer! Per fare gli installer ci sono tante soluzioni indipentendi da Python (inno setup etc.) Io andrei sicuramente di Inno Setup: http://www.innosetup.com/ -- http://thinkcode.tv - Prossimamente su questi schermi http://beri.it - Blog di una testina di vitello http://stacktrace.it - Aperiodico di resistenza informatica ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python