简体   繁体   English

在 Python 菜单中扫描字符串文字时 EOL

[英]EOL while scanning string literal in Python menu

You won´t be able to run the script, sadly I don´t know why.您将无法运行该脚本,遗憾的是我不知道为什么。 It's about EOL but I'm not that much into python so I need your help, I´ve tried different stuff and didn't work.这是关于 EOL 的,但我对 Python 不太感兴趣,所以我需要你的帮助,我尝试了不同的东西但没有奏效。 Also, my friend that actually is into phyton tried and failed.另外,我真正喜欢 phyton 的朋友尝试过但失败了。

this is just a menu code for running multiple antiviruses whenever I want to check my computer这只是一个菜单代码,用于在我想检查我的计算机时运行多个防病毒软件

import sys, string, os, arcgisscripting
def menu():
    print ("Welcome To S1MPL3 MENU, an simple made antivirus for open Wi-Fi and Computer Repair.\n 1. Easy File Check \n 2.Total Time Security \n 3.Suspicius Ip Check")
    choice = input()

    if choice == "1":
        print("Checking Files ... (The process wont take long !")
        os.chdir 'C:\Users\alexa\Desktop\Core_Files\Projects\S1mpl3 Antivirus\Check\Files\File_Check.vbs\
        menu()

    if choice == "2":
        print("TTS Chosen!")
        os.chdir  'C:\Users\alexa\Desktop\Projects\S1mpl3_Antivirus\Check\\Files\Ip_Check\'
        menu()

    if  choice == "3":
         print("Checking For Suspicius Ip in your Home Wi-Fi")
         os.chdir 'C:\Users\alexa\Desktop\Core_Files\Projects\S1mpl3 Antivirus\Check\Files\Ip_Check\'
         menu()

menu()

The error should be in the S1m of choice 2错误应该在选择 2 的 S1m 中

Error: Syntax Error EOL while scanning string literal错误:扫描字符串文字时出现语法错误 EOL

You are using backslash characters '\\' in your paths.您在路径中使用了反斜杠字符 '\\'。 While this is OK on the command line, it is (mostly) not correct in source code.虽然这在命令行上是可以的,但它(大部分)在源代码中是不正确的。 The backslash character is used as escape character to change the meaning of the following character.反斜杠字符用作转义字符以更改以下字符的含义。 In your case the trailing apostroph is escaped so that the path string is not closed.在您的情况下,尾随撇号被转义,因此路径字符串不会关闭。

You can use a raw string like @RonaldAaronson proposed:您可以使用像@RonaldAaronson 建议的原始字符串:

r'C:\Users\alexa\Desktop\Projects\S1mpl3_Antivirus\Check\Files\Ip_Check\'

Or replace all single backslash with double like this:或者像这样用双倍替换所有单反斜杠:

'C:\\Users\\alexa\\Desktop\\Projects\\S1mpl3_Antivirus\\Check\\Files\\Ip_Check\\'

Many Windows function also work with the unixoid path separator '/', and os.chdir() does so, too:许多 Windows 函数也可以使用 unixoid 路径分隔符“/”,而os.chdir()也可以这样做:

os.chdir('C:/Users/alexa/Desktop/Projects/S1mpl3_Antivirus/Check/Files/Ip_Check')

The library os has os.sep and os.altsep that are pathname separators.osos.sepos.altsep是路径名分隔符。 Use these to write better portable code.使用这些来编写更好的可移植代码。 Please read the documentation.请阅读文档。 This is always a good idea.这总是一个好主意。

Second observation: You need to call os.chdir() with parentheses.第二个观察:你需要用括号调用os.chdir()

You are missing a single quote at the end of the line:您在行尾缺少单引号:

if choice == "1":
        print("Checking Files ... (The process wont take long !")
        os.chdir 'C:\Users\alexa\Desktop\Core_Files\Projects\S1mpl3 Antivirus\Check\Files\File_Check.vbs\   **<---here**
        menu()

I have a similar problem while opening a directory.我在打开目录时遇到了类似的问题。 I used raw string and double backslashes and it works.我使用了原始字符串和双反斜杠,它可以工作。 Example:例子:

os.chdir(r"C:\\Users\\alexa\Desktop\\Core_Files\\Projects\\S1mpl3Antivirus\\Check\\Files\\")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM