【问题标题】:Python find txt and continue this is causing the faultPython找到txt并继续这是导致错误的原因
【发布时间】:2017-12-17 19:37:34
【问题描述】:

我想如果找到 txt 并等待程序。但是程序找到 txt 并继续这导致错误我该怎么办?

    import time
import os
hard_drive = 'D:\\sifreler.txt' , 'E:\\sifreler.txt' , 'F:\\sifreler.txt' , 'G:\\sifreler.txt' , 'I:\\sifreler.txt'
hard_drive1 = hard_drive

while True:
    for i in hard_drive1:
        try:
            sifre = open(i, "r")
            sifree = sifre.readline()

            if sifree == "8da0dd52e2ee6c04528ede0cd84e6770":
                print("True")
                explorer1 = os.system("start explorer.exe")
                time.sleep(1)

        except FileNotFoundError:
            print("File Not Found")
            explorer1 = os.system("TASKKILL /F /IM explorer.exe")
            time.sleep(1)

        except PermissionError:
            print()

【问题讨论】:

  • 你遇到了什么故障?
  • File Not Found File Not Found True File Not Found File Not Found program if True 等待程序。不要继续 FileNotFoundError
  • D:/E:/G:/H:/ 中找不到文件sifreler.txt
  • 我不明白你的意思是“我想要 `sifre = open(i, "r") 写 i 而不是 F:/sifreler.txt”。您试图用这段代码解决的全部问题是什么?听起来您缺少一些使其适合您的目的的逻辑。
  • 如果您需要包含更多详细信息,请将它们编辑到帖子中,以便其他人可以理解上下文。如果你不能向大家清楚地解释问题,那么帮助你将非常困难。

标签: python python-3.x


【解决方案1】:

我解决了。编辑所有代码现在找到 txt 并阅读作品耶!!!

   drive = "D:\\"
        if "sifreler.txt" in drive:
            print("TXT find")
            drive2 = "D:\\" + "sifreler.txt"

        elif not "sifreler.txt" in drive:
            drive = os.listdir("E:\\")
            drive1 = drive

            if "sifreler.txt" in drive:
                print("TXT find")
                drive2 = "E:\\" + "sifreler.txt"

            elif not "sifreler.txt" in drive:
                drive = os.listdir("F:\\")
                drive1 = drive

                if "sifreler.txt" in drive:
                    print("TXT find")
                    drive2 = "F:\\" + "sifreler.txt"

                elif not "sifreler.txt" in drive:
                    drive = os.listdir("G:\\")
                    drive1 = drive

                    if "sifreler.txt" in drive:
                        print("TXT find")
                        drive2 = "G:\\" + "sifreler.txt"

                    elif not "sifreler.txt" in drive:
                        print("TXT don't find")

        sifre1 = open(drive2, "r")
        sifree1 = sifre1.readline()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    • 1970-01-01
    • 2018-08-04
    • 2012-12-05
    • 1970-01-01
    相关资源
    最近更新 更多