0

I want to be able to add raw input to a jupyter cell. This is something I normally would have no problem doing such as:

raw_data='''
some lengthy raw input I 'want' to "process"
'''

Everything works well, and I keep all quotes and double quotes:

![enter image description here

However, when I try e.g.

raw_data='''
this input has quotes: ["]
it unfortunately also has escaped quotes: [\"], and they end up exactly the same
'''

I loose the escaped quotes:

enter image description here

I know I could replace \ with e.g. \\ in my input, but am looking for a solution that would allow me to copy-paste the exact raw input to jupyter and have it work...

Essentially it bogs my mind that in python '''"''' and '''\"''' seem to be exactly the same....

ntg
  • 12,950
  • 7
  • 74
  • 95
  • 2
    Did you consider raw strings for your raw data? `raw_data = r'''...` – wovano Nov 16 '22 at 13:15
  • 1
    It shouldn't be so bizarre that they're the same: `\t` and `\n` and lots of other values that start with backslashes are special (when not using raw strings), and when something _isn't_ in that set, `\` just evaluates to `` (though I'd argue that it _should_ be an outright syntax error; "[errors should never pass silently](https://peps.python.org/pep-0020/)", after all). If you want a literal backslash in a non-raw string, it's written as two backslashes... as you know, though I'm not clear why it's surprising. – Charles Duffy Nov 16 '22 at 13:21
  • @wovano Wow! you just blew my mind! :) I new about `b` and `f` but had no clue about `r`! That is the answer... – ntg Nov 16 '22 at 13:35
  • And there's also `u`, but that has become pretty useless since Python 3 ;-) – wovano Nov 16 '22 at 14:12

0 Answers0