[Python] regex killer
Buongiorno a tutti Eseguendo questo codice in python 2.7.5 funziona correttamente ma in 2.7.2. e 2.7.3 python si impianta e non termina. Succede solo a me ? Grazie :) G import re t="CURRICULUM Rossi Mazzanti Vien Dal Mare Mario DF/433/43" r=r"^(?:CURRICULUM\s*)(?P(?:\w*?\s*?)*?\w*)\s*?(?P\w{2}/\w{3}/\w{2})\s*$" R=re.compile(r) a=re.search(R,t) print a.groups() ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] regex killer
On 10/16/2013 01:09 PM, Giovanni Porcari wrote: Eseguendo questo codice in python 2.7.5 funziona correttamente ma in 2.7.2. e 2.7.3 python si impianta e non termina. import re t="CURRICULUM Rossi Mazzanti Vien Dal Mare Mario DF/433/43" r=r"^(?:CURRICULUM\s*)(?P(?:\w*?\s*?)*?\w*)\s*?(?P\w{2}/\w{3}/\w{2})\s*$" R=re.compile(r) a=re.search(R,t) print a.groups() Si pianta anche a me con la 2.7.3, mentre con la 3.3 e 3.4 funziona correttamente -- Marco Buttu INAF - Osservatorio Astronomico di Cagliari Via della Scienza, Loc. Cuccuru Angius 09047 Selargius (CA) Email: mbu...@oa-cagliari.inaf.it ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] regex killer
On Wed, Oct 16, 2013 at 01:09:26PM +0200, Giovanni Porcari wrote: > Buongiorno a tutti > > > Eseguendo questo codice in python 2.7.5 funziona correttamente > ma in 2.7.2. e 2.7.3 python si impianta e non termina. > > Succede solo a me ? Che si pianti mi sembra normale. Ecco una letturina per la sera[1] oppure il libro di Beri sulle regex. In pratica questa parte "(?P(?:\w*?\s*?)*?\w*)" ha un tempo di eseguzione che è quadratico. Piuttosto mi stupische che la 2.7.5 funzioni, è cambiato qualcosa nell'implementazione? [1] http://swtch.com/~rsc/regexp/regexp1.html ciao > import re > > t="CURRICULUM Rossi Mazzanti Vien Dal Mare Mario DF/433/43" > r=r"^(?:CURRICULUM\s*)(?P(?:\w*?\s*?)*?\w*)\s*?(?P\w{2}/\w{3}/\w{2})\s*$" > R=re.compile(r) > a=re.search(R,t) > print a.groups() ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] regex killer
Il giorno 16/ott/2013, alle ore 13:27, Marco Giusti ha scritto: > On Wed, Oct 16, 2013 at 01:09:26PM +0200, Giovanni Porcari wrote: >> Buongiorno a tutti >> >> >> Eseguendo questo codice in python 2.7.5 funziona correttamente >> ma in 2.7.2. e 2.7.3 python si impianta e non termina. >> >> Succede solo a me ? > > Che si pianti mi sembra normale. Ecco una letturina per la sera[1] > oppure il libro di Beri sulle regex. > > In pratica questa parte "(?P(?:\w*?\s*?)*?\w*)" ha un tempo di > eseguzione che è quadratico. Piuttosto mi stupische che la 2.7.5 > funzioni, è cambiato qualcosa nell'implementazione? > > [1] http://swtch.com/~rsc/regexp/regexp1.html > > ciao > >> import re >> >> t="CURRICULUM Rossi Mazzanti Vien Dal Mare Mario DF/433/43" >> r=r"^(?:CURRICULUM\s*)(?P(?:\w*?\s*?)*?\w*)\s*?(?P\w{2}/\w{3}/\w{2})\s*$" >> R=re.compile(r) >> a=re.search(R,t) >> print a.groups() Capisco che sia quadratico e mi sta bene ma parliamo di applicare la regex su una stringa di 55 caratteri. Credo che il problema sia 'benaltro' . E con ciò accusatemi di benaltrismo :D:D G ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] regex killer
Giovanni Porcari wrote: > E con ciò accusatemi di benaltrismo :D:D Ma no. Per accusar qualcuno di benaltrismo ci vuol ben altrOHWAIT -- Nicola Larosa - http://www.tekNico.net/ [Anarchy] assumes that the burden of proof for anyone in a position of power and authority lies on them. Their authority is not self- justifying. They have to give a reason for it, a justification. And if they can't justify that authority and power and control, which is the usual case, then the authority ought to be dismantled and replaced by something more free and just. - Noam Chomsky, May 2013 ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] regex killer
On 2013-10-16 12:34, Giovanni Porcari wrote: Il giorno 16/ott/2013, alle ore 13:27, Marco Giusti ha scritto: On Wed, Oct 16, 2013 at 01:09:26PM +0200, Giovanni Porcari wrote: Buongiorno a tutti Eseguendo questo codice in python 2.7.5 funziona correttamente ma in 2.7.2. e 2.7.3 python si impianta e non termina. Succede solo a me ? Che si pianti mi sembra normale. Ecco una letturina per la sera[1] oppure il libro di Beri sulle regex. In pratica questa parte "(?P(?:\w*?\s*?)*?\w*)" ha un tempo di eseguzione che è quadratico. Piuttosto mi stupische che la 2.7.5 funzioni, è cambiato qualcosa nell'implementazione? [1] http://swtch.com/~rsc/regexp/regexp1.html ciao import re t="CURRICULUM Rossi Mazzanti Vien Dal Mare Mario DF/433/43" r=r"^(?:CURRICULUM\s*)(?P(?:\w*?\s*?)*?\w*)\s*?(?P\w{2}/\w{3}/\w{2})\s*$" R=re.compile(r) a=re.search(R,t) print a.groups() Capisco che sia quadratico e mi sta bene ma parliamo di applicare la regex su una stringa di 55 caratteri. Infatti, penso sia http://bugs.python.org/issue9669 v2.7.4 83117:026ee0057e2d changeset: 82226:dc8a11c16021 branch: 2.7 parent: 82219:c1b3d25882ca user:Serhiy Storchaka date:Sat Feb 16 21:23:01 2013 +0200 summary: Issue #9669: Protect re against infinite loops on zero-width matching in v2.7.3 76200:70274d53c1dd Direi rilasciato in 2.7.4. -- 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] regex killer
Il giorno 16/ott/2013, alle ore 13:45, Daniele Varrazzo ha scritto: > On 2013-10-16 12:34, Giovanni Porcari wrote: >> Il giorno 16/ott/2013, alle ore 13:27, Marco Giusti >> ha scritto: >> >>> On Wed, Oct 16, 2013 at 01:09:26PM +0200, Giovanni Porcari wrote: Buongiorno a tutti Eseguendo questo codice in python 2.7.5 funziona correttamente ma in 2.7.2. e 2.7.3 python si impianta e non termina. Succede solo a me ? >>> >>> Che si pianti mi sembra normale. Ecco una letturina per la sera[1] >>> oppure il libro di Beri sulle regex. >>> >>> In pratica questa parte "(?P(?:\w*?\s*?)*?\w*)" ha un tempo di >>> eseguzione che è quadratico. Piuttosto mi stupische che la 2.7.5 >>> funzioni, è cambiato qualcosa nell'implementazione? >>> >>> [1] http://swtch.com/~rsc/regexp/regexp1.html >>> >>> ciao >>> import re t="CURRICULUM Rossi Mazzanti Vien Dal Mare Mario DF/433/43" r=r"^(?:CURRICULUM\s*)(?P(?:\w*?\s*?)*?\w*)\s*?(?P\w{2}/\w{3}/\w{2})\s*$" R=re.compile(r) a=re.search(R,t) print a.groups() >> >> >> Capisco che sia quadratico e mi sta bene ma parliamo di applicare la >> regex su una stringa di 55 caratteri. > > Infatti, penso sia http://bugs.python.org/issue9669 > > v2.7.4 83117:026ee0057e2d > > changeset: 82226:dc8a11c16021 > branch: 2.7 > parent: 82219:c1b3d25882ca > user:Serhiy Storchaka > date:Sat Feb 16 21:23:01 2013 +0200 > summary: Issue #9669: Protect re against infinite loops on zero-width > matching in > > v2.7.3 76200:70274d53c1dd > > Direi rilasciato in 2.7.4. > > > -- > Daniele Varrazzo - Develer S.r.l. > http://www.develer.com > Grazie Daniele. Anche tu sei una roccia ;). Avevo cercato sul bugtrack ma evidentemente non sono molto abile in queste ricerche ;) Grazie ! G ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] regex killer
Daniele Varrazzo wrote: > Infatti, penso sia http://bugs.python.org/issue9669 > > v2.7.4 83117:026ee0057e2d > > changeset: 82226:dc8a11c16021 > branch: 2.7 > parent: 82219:c1b3d25882ca > user:Serhiy Storchaka > date:Sat Feb 16 21:23:01 2013 +0200 > summary: Issue #9669: Protect re against infinite loops > on zero-width > matching in > > v2.7.3 76200:70274d53c1dd > > Direi rilasciato in 2.7.4. Confermo, su 2.7.4 non s'inchioda e funziona senza problemi. -- Nicola Larosa - http://www.tekNico.net/ [Anarchy] assumes that the burden of proof for anyone in a position of power and authority lies on them. Their authority is not self- justifying. They have to give a reason for it, a justification. And if they can't justify that authority and power and control, which is the usual case, then the authority ought to be dismantled and replaced by something more free and just. - Noam Chomsky, May 2013 ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] regex killer
On 2013-10-16 12:48, Giovanni Porcari wrote: Avevo cercato sul bugtrack ma evidentemente non sono molto abile in queste ricerche ;) Non l'ho trovato sul tracker: non ci contavo. Ma immaginavo che se ci fosse stato un bug fixato sarebbe stato nel modulo C delle regexp. Ho dato un'occhiata a hg log --branch 2.7 Modules/_sre.c Ed è spuntato fuori subito. -- 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] regex killer
On Wed, Oct 16, 2013 at 01:34:07PM +0200, Giovanni Porcari wrote: > Capisco che sia quadratico e mi sta bene ma parliamo di applicare la > regex su una stringa di 55 caratteri. > > Credo che il problema sia 'benaltro' . E con ciò accusatemi di > benaltrismo :D:D Chiedo scusa per il mio qualunquismo :/ ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] domanda agli utilizzatori di pycharm.
Il 16 ottobre 2013 00:08, Marco Giusti ha scritto: > _ = __builtins__._ _ = __builtins__._ AttributeError: 'module' object has no attribute '_' no... a quanto pare non funziona... pazienza... lo metterò tra i messaggi da ignorare... Byez -- Gollum1 Tesoro, dov'é il mio teoro... ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] domanda agli utilizzatori di pycharm.
On Wed, Oct 16, 2013 at 10:59:16PM +0200, Gollum1 wrote: > Il 16 ottobre 2013 00:08, Marco Giusti ha scritto: > > _ = __builtins__._ > > >_ = __builtins__._ > AttributeError: 'module' object has no attribute '_' > > no... a quanto pare non funziona... pazienza... lo metterò tra i > messaggi da ignorare... No, hai ragione, ora mi ricordo perché con pyflakes uso quest'altre linee ma l'altra sera con la stanchezza non ricordavo più il motivo e mi sembravano un po' stupide. if False: _ = str L'eccezione è normale se il modulo viene importato prima che che gettext installi la funzione in __builtins__. Ciao Marco ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] domanda agli utilizzatori di pycharm.
Il 17/ott/2013 00:22 "Marco Giusti" ha scritto: > > No, hai ragione, ora mi ricordo perché con pyflakes uso quest'altre > linee ma l'altra sera con la stanchezza non ricordavo più il motivo e mi > sembravano un po' stupide. > > if False: > _ = str > > L'eccezione è normale se il modulo viene importato prima che che gettext > installi la funzione in __builtins__. > Non credo di aver capito... gettext installa "_" come funzione buildin solo a runtime, e da qui l'errore del l'editor... fino a qui ci ero arrivato... Ma le due righe di codice che mi hai passato non mi sono chiare... l'if è sempre falso, quindi _=str non dovrebbe mai essere eseguita. La situazione è simile a quella del wrapper che faccio per sostituire la funzione di gettext con quella di _( ) per risolvere il problema di argparse che non mi permette di localizzare alcune stringhe. Domani sera privo il tuo codice... grazie. Byez -- Gollum1 teoro, dov'è il mio teoro... ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python