0

I am trying to define a name for a long server folder path below. May I know why I still get "EOL while scanning string literal" error? Many thanks.

path= (r '\\hbap.adroot.abb\HK\Finance\00210602\AMH_A2R\1KY\Drv Reengine\Python\')
ApplePie
  • 8,814
  • 5
  • 39
  • 60
jun
  • 21
  • 2
  • does it work if you use forward slashes instead? what about doubling the backslashes like \\ – Luke_ Feb 18 '21 at 12:08
  • 1
    oh, i just saw the edit, you have a space between the r and the string – Luke_ Feb 18 '21 at 12:08
  • 1
    You have a space between `r` and `'`. – Péter Leéh Feb 18 '21 at 12:08
  • 1
    Did you copy and paste your code? You should be getting a syntax error because of the space between r and '. If you did not copy paste your code, please do so. – ApplePie Feb 18 '21 at 12:09
  • 1
    See https://stackoverflow.com/questions/647769/why-cant-pythons-raw-string-literals-end-with-a-single-backslash – Stijn De Pauw Feb 18 '21 at 12:13
  • @StijnDePauw If you think this question has an answer somewhere else in this site - [flag it as duplicate](https://stackoverflow.com/help/privileges/flag-posts) instead of posting a link as a comment... – Tomerikoo Feb 18 '21 at 12:14

1 Answers1

-1

Its not allowed to put a space between the 'r' and the string. However i suggest just doubling the backslashes to escape them like this:

path= ("\\\\hbap.adroot.abb\\HK\\Finance\\00210602\\AMH_A2R\\1KY\\Drv Reengine\\Python\\")

Alternativly, you can just leave out the backslash at the end and do this:

path= (r"\\hbap.adroot.abb\HK\Finance\00210602\AMH_A2R\1KY\Drv Reengine\Python")

All is good, as long as you escape the backslashes and dont have the string ending with a \ (except if that ending backslash is doubled)

Luke_
  • 745
  • 10
  • 23