Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
interesting gotcha
#11
ok, i had forgotten the terminology.

BTW, r'\' did not behave as i expected ... try it
Output:
Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> r'foo\\' 'foo\\\\' >>> r'foo\'   File "<stdin>", line 1     r'foo\'           ^ SyntaxError: EOL while scanning string literal >>>
i think i see what the interpreter is doing.  it is doing a preliminary parse for the ending quote before it considers the raw indication, then maybe applies the escape sequence conversion on what it has collected.
Output:
>>> 'foo\'bar' "foo'bar" >>> r'foo\'bar' "foo\\'bar" >>>
this is that kind of behavior (quirks) that testing things reveals.  escaping the quote is still done even for raw strings.  but that is probably done in the source code parsing layer, anyway.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#12
Hm! It's related to the single quote. This error appears when I forgot the closing quote. It looks like the raw string can't end in a single backslash. https://docs.python.org/3/reference/lexi...s-literals at the bottom of the subsection. I am learning a lot about you
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  An interesting BUG with double assignment Gribouillis 2 751 Oct-08-2023, 01:56 PM
Last Post: Gribouillis
  most interesting or useful modules? t4keheart 7 3,412 Jan-20-2020, 06:03 AM
Last Post: wavic
  Interesting/Fun Scripts? ejected 2 2,373 Mar-27-2019, 07:49 AM
Last Post: Skaperen
  Interesting article on PyTourch Larz60+ 0 2,277 Jan-03-2018, 09:06 PM
Last Post: Larz60+
  Any interesting works in progress? mpd 5 3,742 Dec-15-2017, 09:34 PM
Last Post: wavic
  An interesting blog wavic 0 2,384 Dec-12-2017, 09:09 PM
Last Post: wavic
  Interesting new features in python3 Kebap 8 5,877 Jul-05-2017, 03:53 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020