我尝试使用PyAutoGui创建一个函数来检查屏幕上是否显示图像,并提出了这个:
def check_image_on_screen(image):
try:
pyautogui.locateCenterOnScreen(image)
return True
except:
return False
Run Code Online (Sandbox Code Playgroud)
它工作正常,但PyCharm告诉我,我不应该except裸露.把它留下来有什么问题?有没有更合适的方法来创建相同的功能?
我正在尝试检查一个字符串是否只包含 / 和数字,以用作一种验证形式,但是我找不到同时执行这两项操作的方法。ATM 我有这个:
if Variable.isdigit() == False:
Run Code Online (Sandbox Code Playgroud)
这适用于数字,但我还没有找到一种方法来检查斜线。
我想找到名称中仅包含数字的顶级文件夹。Fe 我们有这样的文件夹结构
\n\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Folder1\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 some.file\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 111\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 some.folder\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 some.file\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 some.file\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 some.file-2\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 555\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 some.folder\n| \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 some.file\nRun Code Online (Sandbox Code Playgroud)\n\n预期结果:找到文件夹“111”和“555”
\n\n这是我的代码:
\n\nimport os\n\nmain_path = 'C:\\\\Users'\ntop_folders_list = next(os.walk(main_path))[1]\ncondition = '111'\nif condition in top_folders_list:\n ...do_something...\nRun Code Online (Sandbox Code Playgroud)\n\n代码有效,但(当然)仅适用于文件夹“111”。我应该使用哪个条件来匹配“111”、“555”以及名称中仅包含数字的所有其他顶级文件夹?
\n