[issue44308] Raw Strings lack parody

2021-06-04 Thread STINNER Victor
STINNER Victor added the comment: I close the issue. Glad that you found a solution to your issue. -- resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker

[issue44308] Raw Strings lack parody

2021-06-04 Thread Nicholas Willhite
Nicholas Willhite added the comment: Wow, thanks for all the helpful responses! I see how this was a classic PEBKAC issue on my end. Please closed this ticket at your convenience. -- ___ Python tracker

[issue44308] Raw Strings lack parody

2021-06-04 Thread Mark Dickinson
Mark Dickinson added the comment: Ah, I think I see: you want a function that turns the string "foo\bar" into "foo\\bar". Even if this were a good idea, I don't think it's feasible to do it in a non-surprising way. For example, given such a function f, what outputs would you expect for:

[issue44308] Raw Strings lack parody

2021-06-04 Thread Mark Dickinson
Mark Dickinson added the comment: Sorry, I missed the definition of f in the last message. Trying again: >>> def f(x): return x ... >>> f(r'foo\bar') == 'foo\\bar' True -- ___ Python tracker

[issue44308] Raw Strings lack parody

2021-06-04 Thread Mark Dickinson
Mark Dickinson added the comment: > But there's no builtin function for r'foo\bar' that gives you 'foo\\bar'. I'm confused about what's being requested here. r'foo\bar' and 'foo\\bar' are different source code representations of the exact same string (same type, same contents), so the

[issue44308] Raw Strings lack parody

2021-06-04 Thread STINNER Victor
STINNER Victor added the comment: You can use br"\n" to get 2 bytes: b"\\" and b"n". IMO it's the best practice, to use raw strings for regular expressions. Converting a regular string to a raw string sounds like a bad idea. -- ___ Python tracker

[issue44308] Raw Strings lack parody

2021-06-03 Thread Steven D'Aprano
Steven D'Aprano added the comment: Remember that backslash escapes are only a Python syntactic feature. If you read data from a file, or from the input() builtin, that contains a backslash, it remains a backslash: >>> s = input() a\b >>> print(len(s), s == r'a\b') 3 True

[issue44308] Raw Strings lack parody

2021-06-03 Thread Steven D'Aprano
Steven D'Aprano added the comment: I think you have missed something important here: >>> data = b'foo\bar' >>> len(data) 6 >>> print(data) b'foo\x08ar' If you want bytes including a backslash followed by a b, you need to use raw bytes rb'foo\bar' or escape the

[issue44308] Raw Strings lack parody

2021-06-03 Thread Nicholas Willhite
New submission from Nicholas Willhite : I'm really sure this isn't filed correctly. I'm a total noob to this process, so feel free to redirect me. :) Bytes can be defined as a function, or a prefixed series. You can prefix a series with "b" and get the expected data type. You can also use