Re: os.path.isfile

2017-02-12 Thread eryk sun
On Sun, Feb 12, 2017 at 4:29 AM, Chris Angelico wrote: > Registry subkeys aren't paths, and the other two cases are extremely > narrow. Convert slashes to backslashes ONLY in the cases where you > actually need to. \\?\ paths are required to exceed MAX_PATH (a paltry 260 characters) or to avoid q

Re: Rename file without overwriting existing files

2017-02-12 Thread eryk sun
On Sun, Feb 12, 2017 at 4:09 AM, Steve D'Aprano wrote: > On Fri, 10 Feb 2017 12:07 am, eryk sun wrote: > >> On Thu, Feb 9, 2017 at 11:46 AM, Steve D'Aprano >> wrote: >>> >>> So to summarise, os.rename(source, destination): >>> >>> - is atomic on POSIX systems, if source and destination are both o

Re: os.path.isfile

2017-02-12 Thread Steve D'Aprano
On Mon, 13 Feb 2017 11:43 am, Chris Angelico wrote: > On Mon, Feb 13, 2017 at 11:40 AM, Erik wrote: >> FWIW, if you'd have written the above as your first response I wouldn't >> have argued ;) You alluded to it, for sure ... :D > > Nothing wrong with respectfully arguing. It's one of the best wa

Re: os.path.isfile

2017-02-12 Thread Chris Angelico
On Mon, Feb 13, 2017 at 11:40 AM, Erik wrote: > FWIW, if you'd have written the above as your first response I wouldn't have > argued ;) You alluded to it, for sure ... :D Nothing wrong with respectfully arguing. It's one of the best ways to zero in on the truth :) ChrisA -- https://mail.python

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:34, Chris Angelico wrote: The unit "\t" always means U+0009, even if it's following a raw string literal; and the unit "\d" always means "\\d", regardless of the rawness of any of the literals involved. The thing that's biting you here is that unrecognized escapes get rendered as b

Re: os.path.isfile

2017-02-12 Thread Chris Angelico
On Mon, Feb 13, 2017 at 11:34 AM, Erik wrote: > OK, I get it now - because '\d' is not a valid escape sequence, then even in > a non-raw string literal, the '\' is treated as a literal backslash > character (not an escape). > > So, the second string token is NOT being treated as "raw", it just loo

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:23, Erik wrote: r"hello \the" "worl\d" "\t" 'hello \\theworl\\d\t' The initial string is raw. The following string adopts that (same as the second example), but the _next_ string does not! Why is the first string token parsed as a "raw" string, the second string token also pars

Re: os.path.isfile

2017-02-12 Thread Chris Angelico
On Mon, Feb 13, 2017 at 11:29 AM, Erik wrote: > On 13/02/17 00:13, Chris Angelico wrote: >> >> On Mon, Feb 13, 2017 at 11:11 AM, Chris Angelico wrote: >>> >>> The string "\t" gets shown in the repr as "\t". It is a string >>> consisting of one character, U+0009, a tab. The string r"\t" is shown >

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:13, Chris Angelico wrote: On Mon, Feb 13, 2017 at 11:11 AM, Chris Angelico wrote: The string "\t" gets shown in the repr as "\t". It is a string consisting of one character, U+0009, a tab. The string r"\t" is shown as "\\t" and consists of two characters, REVERSE SOLIDUS and LATI

Re: os.path.isfile

2017-02-12 Thread Erik
On 13/02/17 00:11, Chris Angelico wrote: Firstly, be aware that there's no such thing as a "raw string" - what you have is a "raw string literal". It's a purely syntactic feature. I do understand that. When I said "is raw"/"rawness", I am talking about what the _parser_ is doing. I don't think

Re: os.path.isfile

2017-02-12 Thread Chris Angelico
On Mon, Feb 13, 2017 at 11:11 AM, Chris Angelico wrote: > The string "\t" gets shown in the repr as "\t". It is a string > consisting of one character, U+0009, a tab. The string r"\t" is shown > as "\\t" and consists of two characters, REVERSE SOLIDUS and LATIN > SMALL LETTER T. That might be why

Re: os.path.isfile

2017-02-12 Thread Chris Angelico
On Mon, Feb 13, 2017 at 10:56 AM, Erik wrote: > Actually, while contriving those examples, I noticed that sometimes when > using string literal concatenation, the 'rawness' of the initial string is > sometimes applied to the following string and sometimes not: > "hello \the" r"worl\d" > 'hell

Re: os.path.isfile

2017-02-12 Thread Erik
On 12/02/17 23:56, Erik wrote: r"hello \the" "worl\d" 'hello \\theworl\\d' Slightly surprising. The concatenated string adopts the initial string's 'rawness'. "hello \the" r"worl\d" "\t" 'hello \theworl\\d\t' The initial string is not raw, the following string is. The string following _that

Re: os.path.isfile

2017-02-12 Thread Erik
On 12/02/17 04:53, Steve D'Aprano wrote: py> s = r'documents\' File "", line 1 s = r'documents\' ^ SyntaxError: EOL while scanning string literal (I still don't understand why this isn't just treated as a bug in raw string parsing and fixed...) I would imagine that i

Re: scrivere file

2017-02-12 Thread BartC
On 12/02/2017 21:46, Christian Gollwitzer wrote: Am 12.02.17 um 22:07 schrieb BartC: On 12/02/2017 20:38, Christian Gollwitzer wrote: Am 12.02.17 um 21:19 schrieb Paolo: Buonasera, è da un pò che sto cercando come esercizio di scrivere un file al contrario. Mi spiego meglio ho un file con N ri

Re: scrivere file

2017-02-12 Thread Christian Gollwitzer
Am 12.02.17 um 22:07 schrieb BartC: On 12/02/2017 20:38, Christian Gollwitzer wrote: Am 12.02.17 um 21:19 schrieb Paolo: Buonasera, è da un pò che sto cercando come esercizio di scrivere un file al contrario. Mi spiego meglio ho un file con N righe e vorrei scriverne un altro con gli stessi dat

Re: scrivere file

2017-02-12 Thread BartC
On 12/02/2017 20:38, Christian Gollwitzer wrote: Am 12.02.17 um 21:19 schrieb Paolo: Buonasera, è da un pò che sto cercando come esercizio di scrivere un file al contrario. Mi spiego meglio ho un file con N righe e vorrei scriverne un altro con gli stessi dati ma la 1° riga deve diventare l' ult

Re: scrivere file

2017-02-12 Thread Christian Gollwitzer
Am 12.02.17 um 21:19 schrieb Paolo: Buonasera, è da un pò che sto cercando come esercizio di scrivere un file al contrario. Mi spiego meglio ho un file con N righe e vorrei scriverne un altro con gli stessi dati ma la 1° riga deve diventare l' ultima. Es. file di partenza riga1 riga2 riga3 riga4

scrivere file

2017-02-12 Thread Paolo
Buonasera, è da un pò che sto cercando come esercizio di scrivere un file al contrario. Mi spiego meglio ho un file con N righe e vorrei scriverne un altro con gli stessi dati ma la 1° riga deve diventare l' ultima. Es. file di partenza riga1 riga2 riga3 riga4 file riscritto riga4 riga3 riga2 r