0

I have the file path

say='5.0'
output_path=r'C:\User\Projects\'+ say

I get an error message.

SyntaxError: EOL while scanning string literal

UPDATE!!! I also tried doing this from your suggestions but it did not work as well

output_path=r'C:\User\Projects\\'+ say

I get the string as

'C:\\User\\Projects\\\\\5.0

I want the output_path to basically be

C:\User\Projects\5.0
user35131
  • 1,105
  • 6
  • 18
  • 3
    You should have included the full error message. You cannot have a "\" before the closing quotation mark in a "raw" string. Use `'C:\\User\\Projects\\'` instead. – DYZ Jun 04 '20 at 22:16
  • I apologize. here it is SyntaxError: EOL while scanning string literal – user35131 Jun 04 '20 at 22:20
  • Please add this error to the question. – Kirtiman Sinha Jun 04 '20 at 22:20
  • Does this answer your question? [Why can't Python's raw string literals end with a single backslash?](https://stackoverflow.com/questions/647769/why-cant-pythons-raw-string-literals-end-with-a-single-backslash) – ChrisGPT was on strike Jun 04 '20 at 22:22

2 Answers2

0

I saw that this worked. Thank you.

output_path=r'C:/User/Project/ '+say
user35131
  • 1,105
  • 6
  • 18
  • what about this: `say = "5.0"; output_path="C:\\User\\Projects\\"+say` – Kirtiman Sinha Jun 04 '20 at 22:41
  • It should be `output_path = os.path.join(r'C:\User\Projects', say)`. Or in recent versions of 3.x, use a raw formatted string, e.g. `output_path = fr'C:\User\Projects\{say}'`. – Eryk Sun Jun 05 '20 at 00:20
  • Using slashes is okay if the path is passed to base file API functions (e.g. `CreateFileW`), and if you don't need a verbatim `"\\\\?\\"` path. It's less reliable if passed to the shell and in command lines. The most reliable and preferred path separator is backslash. For the system's native object paths (device paths, and also any named object, such as registry keys, jobs, events, sections), backslash is the only path separator (e.g. a section with the relative name `r"Global\Spam"`). The base file API translates slashes before calling native NT functions, but most other Windows APIs do not. – Eryk Sun Jun 05 '20 at 00:37
  • One exception is a serious bug in the base file API function `CreateSymbolicLinkW` (i.e. `os.symlink` in Python). A symlink in Windows consists of a friendly print path that can be any supported Windows file path, and also a substitute path, which is the native NT path that's actually used to resolve the link. For a relative target path (e.g. "/spam/eggs" or "../spam"), `CreateSymbolicLinkW` fails to translate slash to backslash in the substitute path, which creates a broken link. `os.symlink` could implement a workaround for this bug. Until then, only use backslashes in this case. – Eryk Sun Jun 05 '20 at 00:48
-2

output_path=r'C:\User\Projects\'+ say take the "r" out of the string, and u probably can use bytes(output_path, "utf-8") so u can basically do what "r" does before a string btw is that "r" before the string intentional?? because if not, just remove that and it will be working just fine :D

Tiago Oliveira
  • 47
  • 1
  • 12
  • It will not "_work fine_" either with or without `r`. You cannot have a single "\" before the closing quotation mark. – DYZ Jun 04 '20 at 22:19
  • I forgot to say that you should had output_path='C:\\User\\Projects\\'+ say every bar should be duobble bar because python doesn't like having single ones (just when declaring variables) – Tiago Oliveira Jun 04 '20 at 22:20