Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 而循环不';在我的for循环中不能工作_Python 3.x_Loops_Validation_If Statement_While Loop - Fatal编程技术网

Python 3.x 而循环不';在我的for循环中不能工作

Python 3.x 而循环不';在我的for循环中不能工作,python-3.x,loops,validation,if-statement,while-loop,Python 3.x,Loops,Validation,If Statement,While Loop,我想列出一个路由中的所有dir,然后在该路由中找到一个字符串。如果字符串在dirs中,我需要做一些事情,如果该字符串不在dirs中,我需要做一些事情,然后再次请求一个有效的字符串 我使用os.walk函数获取dirs,它从路由返回一个包含dirs的字符串。然后我想在字符串(dirs)中找到一个字符串 如果找不到文件夹,请始终跳转到其他位置:,因为您可以使用os.path.exists(“my_dir”),并且您的代码类似于 mi_path = "F:\\releases\\" v

我想列出一个路由中的所有dir,然后在该路由中找到一个字符串。如果字符串在dirs中,我需要做一些事情,如果该字符串不在dirs中,我需要做一些事情,然后再次请求一个有效的字符串

我使用
os.walk
函数获取dirs,它从路由返回一个包含dirs的字符串。然后我想在字符串(dirs)中找到一个字符串


如果找不到文件夹,请始终跳转到
其他位置:

,因为您可以使用
os.path.exists(“my_dir”)
,并且您的代码类似于

    mi_path = "F:\\releases\\"
    validate = False
    for dirs, paths, files in os.walk(mi_path): 
        while not validate:
            if str(release_buscar) in str(dirs):
                print("Release encontrada", dirs)
                break
            else:
                print("Release no encontrada")
                release_buscar =  input("Introduce el nombre otra vez:")
                validate = False
    print("Final del bucle")

我不想那样。我想从一个车辙中列出所有的dir,然后在那个车辙中找到一个字符串。我需要做,如果字符串在目录中,然后做一些事情,如果字符串不在,然后再次要求一个有效的字符串。我不想要确切的。我想从一个车辙中列出所有的dir,然后在那个车辙中找到一个字符串。如果字符串在目录中,我需要做一些事情,如果字符串不在目录中,我需要做一些事情,然后再次请求一个有效的字符串
import os

def get_existing_dir():
    my_dir = input("Please enter a directory name : ")
    while True:
        if os.path.exists(my_dir):
            return my_dir
        my_dir = input("Please enter an existing directory name : ")