为什么使用"\"在jython中显示错误

kde*_*dev 4 jython

我正在尝试使用Windows的复制命令,我们有目录,如c:\oracle.

在尝试执行此类操作时,我们收到以下错误:

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

这里的文件夹是我的c:\ oracle的路径,并在尝试向其添加文件时:

source=folder+"\"+src_file
Run Code Online (Sandbox Code Playgroud)

我无法这样做.关于如何解决这个问题的任何建议?

我试过/但是我的副本窗口调用源代码os.command正在获取"the syntax is incorrect"并且解决它的唯一方法是使用\但是我在这样做时遇到上述错误.

请建议.谢谢你的帮助

谢谢.

pax*_*blo 8

简短回答:

你需要:

source_file = folder + "\\" + src_file
Run Code Online (Sandbox Code Playgroud)

答案很长:

这个问题

source_file = folder + "\" + src_file
Run Code Online (Sandbox Code Playgroud)

\是逃脱角色.它在这种特殊情况下所做的是逃避"它,以便它被视为字符串的字符而不是字符串终止符,类似于:

source_file = folder + "X + src_file
Run Code Online (Sandbox Code Playgroud)

哪个会有同样的问题.

换句话说,您正在尝试构造一个由"其他文本和行尾((\r回车符)组成的字符串).这就是你的错误来自:

Encountered: "\r" (13)
Run Code Online (Sandbox Code Playgroud)