Re: [Python] stringhe raw
On Sat, 08 Jan 2011 08:22:31 +0100, Vito 'ZeD' De Tullio zak.mc.kra...@libero.it wrote: Nicola Larosa wrote: i path hardcoded ('\\' è veramente orripilante da scrivere). Tenendo anche presente che indicare il separatore di percorso su Windows come r'\' non è portabile, mentre usare os.sep lo è. vero ma: os.sep.join(C:, Documents and Settings, Default User) non si può considerare più portabile di r'C:\Documents and Settings\Default User' Forse si riferivano a un più generico os.sep.join([base_path, some_prefix, some_other_crap, filename]) non necessariamente ad un path costante in ogni elemento. Ovviamente la soluzione vera è *non* usare path hardcoded, e - se possibile - relegarli a file di configurazione o simili. Quindi te li ritrovi in variabili, magari la base_path a cui devi concatenare un nome di file. Il modo portabile di concatenare file con os.sep o (meglio) os.path.join si applica anche alle variabili, non solo alle costanti. In ogni caso quello che hanno omesso tutti di specificare è che i forward slash (/) funzionano anche su windows. C:/autoexec.bat viene gestito correttamente dalle fuzioni python (non se va passato a tool esterni ovviamente). -- 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] stringhe raw
Daniele Varrazzo wrote: path hardcoded Forse si riferivano a un più generico os.sep.join([base_path, some_prefix, some_other_crap, filename]) non necessariamente ad un path costante in ogni elemento. io mi riferivo ai path hardcoded, invece :) Il modo portabile di concatenare file con os.sep o (meglio) os.path.join si applica anche alle variabili, non solo alle costanti. ovvio :) Che abspath = base + '/' + relpath sia un ignominia è vero a prescindere, ma non c'entra con quello che dicevo io :) In ogni caso quello che hanno omesso tutti di specificare è che i forward slash (/) funzionano anche su windows. C:/autoexec.bat viene gestito correttamente dalle fuzioni python (non se va passato a tool esterni ovviamente). umm, si, so che windows (da XP in poi?) dovrebbe supportare anche i forward slash, ma in teoria ci sarebbe anche il carattere ':' per i vecchi macOS (o non li usa più nessuno?) -- By ZeD ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] stringhe raw
Enrico Franchi wrote: Ad ogni modo, sempre che io ricordi correttamente, venivano fatte delle conversioni sensate in modo automatico. Ovvero, non mi ricordo di particolari problemi con i Path. Ma essendo roba di diversi anni fa posso essermi tranquillamente scordato le grane. cioé - in teoria - python permetterebbe di fare open(c:/prova) anche su windows 98 (che AFAIK non supporta i forward slash)? Comunque direi che l'interesse di supportare MacOS 9 e' oggi piuttosto... Come dire, fetish? $ pydoc os | grep os.sep - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\') $ prenditela con gli autori del modulo os, allora :) In effetti con la posixazione degli OS moderni credo che il separatore sia diventato un non-problema. -- By ZeD ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
[Python] stringhe raw
salve, mi e' venuto un dubbio sulle stringhe raw: che differenza ci sarebbe ad utilizzare x = 'xxx' e x = r'xxx'? Per curiosita' ho provato a fare: In [1]: xxx == r'xxx' Out[1]: True oppure ci sono dei contesti dove conviene utilissare r''? max ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] stringhe raw
Massimo Capanni wrote: che differenza ci sarebbe ad utilizzare x = 'xxx' e x = r'xxx'? In questo caso nessuna. La differenza è quando sono usate sequenze di escape ('\t', '\n', ... insomma i barra-qualcosa). oppure ci sono dei contesti dove conviene utilissare r''? I primi due che mi vengono in mente a caso: il modulo re e, se sei su windows, i path hardcoded ('\\' è veramente orripilante da scrivere). -- By ZeD ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] stringhe raw
Vito 'ZeD' De Tullio wrote: I primi due che mi vengono in mente a caso: il modulo re e, se sei su windows, i path hardcoded ('\\' è veramente orripilante da scrivere). Tenendo anche presente che indicare il separatore di percorso su Windows come r'\' non è portabile, mentre usare os.sep lo è. Certo, poi occorre tener conto di molte altre differenze, usare os.sep non è certo sufficiente, però è necessario. -- Nicola Larosa - http://www.tekNico.net/ Collectively, we will eventually figure out that schools, as currently structured, cost way too much, teach irrelevant material, have the op- posite education effect for most of the students, crowd out more benef- icial activities, break up families, and even create a long term effect similar to a mild but long term post-traumatic stress disorder. - Clark Aldrich, August 2010 ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] stringhe raw
grazie a tutti del chiarimento a presto max 2011/1/7 Nicola Larosa n...@teknico.net Vito 'ZeD' De Tullio wrote: I primi due che mi vengono in mente a caso: il modulo re e, se sei su windows, i path hardcoded ('\\' è veramente orripilante da scrivere). Tenendo anche presente che indicare il separatore di percorso su Windows come r'\' non è portabile, mentre usare os.sep lo è. Certo, poi occorre tener conto di molte altre differenze, usare os.sep non è certo sufficiente, però è necessario. -- Nicola Larosa - http://www.tekNico.net/ Collectively, we will eventually figure out that schools, as currently structured, cost way too much, teach irrelevant material, have the op- posite education effect for most of the students, crowd out more benef- icial activities, break up families, and even create a long term effect similar to a mild but long term post-traumatic stress disorder. - Clark Aldrich, August 2010 ___ 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] stringhe raw
2011/1/7 Massimo Capanni massimo.capa...@gmail.com In [1]: xxx == r'xxx' Out[1]: True oppure ci sono dei contesti dove conviene utilissare r''? A questo hanno gia' risposto. Nota che le raw string differiscono da quelle normali solo nella rappresentazione all'interno del sorgente. Una volta interpretate, sono stringhe come le altre, a differenza degli oggetti unicode: (se usi Python 3.0) 'x' is r'x' True 'x' is u'x' False 'x' == r'x' True 'x' == u'x' True type('x'), type(r'x'), type(u'x') (type 'str', type 'str', type 'unicode') ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python
Re: [Python] stringhe raw
Nicola Larosa wrote: i path hardcoded ('\\' è veramente orripilante da scrivere). Tenendo anche presente che indicare il separatore di percorso su Windows come r'\' non è portabile, mentre usare os.sep lo è. vero ma: os.sep.join(C:, Documents and Settings, Default User) non si può considerare più portabile di r'C:\Documents and Settings\Default User' Ovviamente la soluzione vera è *non* usare path hardcoded, e - se possibile - relegarli a file di configurazione o simili. Tuttavia, se proprio devo, preferisco usare le strighe raw, che almeno posso farie copia-e-incolla. -- By ZeD ___ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python