Why using "\" shows error in jython

I am trying to use the copy command for Windows, and we have directories such as c:\oracle.

When trying to perform one of these, we get the following error:

source_file=folder+"\"
                          ^
SyntaxError: Lexical error at line 17, column 23.  Encountered: "\r" (13), after : ""

Here the folder is my path c: \ oracle and when trying to add a file to it, for example:

source=folder+"\"+src_file

I can not do it. Any suggestion on how to solve this problem?

I tried to use /, but my copies calling the source code in os.commandget "the syntax is incorrect"and the only way to solve this is to use \, but I get the above error.

Please offer. Thank you for your help.

Thank.

+3
source share
3 answers

Short answer:

You need:

source_file = folder + "\\" + src_file

Long answer:

source_file = folder + "\" + src_file

, \ escape-. , , ", , , :

source_file = folder + "X + src_file

.

, , ", (\r, ). , :

Encountered: "\r" (13)
+7

Paxdiablo , \ . , , os.path.normpath , .

+3

, , : "this is a quote: "." , , (!) - :

  • , # 2 # 3, , ;
  • № 3, , .

: . Escaping , , ( \), . , "no, *this* is a quote: \"." , # 2 - \ .

- escape- ? : ! "This is an escape: \\!" , : # 1 - escape-, # 2 - escape-: escape-, .

, :

source=folder+"\\"+src_file

BTW: upvote @paxdiablo ( ) @Nick ( Pythonic , )

+1

Source: https://habr.com/ru/post/1750935/


All Articles