关于#python#的问题:很冒昧打扰一下 我想请问一下 这种问题怎么解决啊

img

很冒昧打扰一下 我想请问一下 这种问题怎么解决啊

img


然后这个程序运行还只能跑前面一小部分

  • 这有个类似的问题, 你可以参考下: https://ask.csdn.net/questions/7474371
  • 这篇博客你也可以参考下:Python编写程序,使用列表生成表达式生成一个包含20个随机整数的列表,然后对其中偶数下标的元素进行降序排列,奇数下标的元素不变。商品筛选(提示,使用切片)
  • 同时,你还可以查看手册:python- 定义扩展类型:已分类主题- 终结和内存释放 中的内容
  • 除此之外, 这篇博客: Python用户登录和文件操作系统中的 学写了一半结合能用到的知识点,写了个模拟用户登录和文件操作系统,发出来记录一下,也有很多不足的地方,如果发现了可以留言给我改正一下 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 复制就可以用,有兴趣的可以复制运行一下

    #!/usr/bin/env python
    # -*- coding: UTF-8 -*-
    '''
    @IDE    :PyCharm
    @Author :Berserker
    @Date   :2019-12-18 22:30
    @Desc   :
    '''
    import os
    import random
    import shutil
    import time
    
    STORE_PATH = r"D:\UserCopyFileProgram\users" # 读取账户和密码路径
    USERS_PATH = os.path.join(STORE_PATH, "users.txt")  # 用户名和密码的记录
    PUBLIC_QUERY_PATH = r"D:\UserCopyFileProgram\Query" # 启用搜索后会保存到这个路径下的txt文件中
    
    
    def auth_code():
        str_code = "ABCDEFGHIJKLMNOPQUSTRVWSYZ1234567890abcdefghijklmnopqustuvwsyz"
        code = ""
        for cout in range(4):
            code += str_code[random.randint(0, len(str_code) - 1)]
        print("验证码:", code)
        auth = input("请输入验证码:")
        if code.lower() == auth.lower():
            return True
        else:
            again = input("验证码输入错误,是否重新输入(Y/N):")
            if again.lower() == "y":
                auth_code()
            else:
                return False
    
    
    def precise_query():
        print("            ************** 欢迎使用精准查找 **************            ")
    
        location = input("请输入需要查询的盘符:")
        query_fileName = input("请输入需要查询的文件名(如:1.jpg):")
    
        for root, dirs, files in os.walk(location):
            for file in files:
                if file == query_fileName:
                    query_path = os.path.join(root, file)
                    print("文件的路径为:{}".format(query_path))
                    if not os.path.exists(PUBLIC_QUERY_PATH):
                        os.makedirs(PUBLIC_QUERY_PATH)
                    with open(os.path.join(PUBLIC_QUERY_PATH, "precise_query.txt"), "a") as wstream:
                        wstream.write("{} : {}\n".format(time.strftime("%Y-%m-%d %H:%M:%S"), query_path))
        user_view()
    
    
    def vague_query():
        print("            ************** 欢迎使用模糊查找 **************            ")
        vague_location = input("请输入需要查询的盘符:")
        vague_filename = input("请输入需要查询的文件概括名:")
    
        for root, dirs, files in os.walk(vague_location):
            for file in files:
                if vague_filename in file:
                    vague_path = os.path.join(root, file)  # 记录查询到的路径
                    print("文件绝对路径为:", vague_path)
                    if not os.path.isdir(PUBLIC_QUERY_PATH):
                        os.makedirs(PUBLIC_QUERY_PATH)
                    with open(os.path.join(PUBLIC_QUERY_PATH, "vague_query.txt"), "a") as wstream:
                        wstream.write("{} : {}\n".format(time.strftime("%Y-%m-%d %H:%M:%S"), vague_path))
        user_view()
    
    
    def copy_file(fn_target_path, fn_str_path):
        file_number = 0  # 统计有多少个文件被复制了
        list_path = os.listdir(fn_target_path)  # 获取当前路径下的所有文件和文件夹名
    
        for result in list_path:
            copy_file_name = os.path.join(fn_str_path, result)  # 获取复制文件的路径
            target_file_name = os.path.join(fn_target_path, result)  # 获取目标文件的路径
    
            if os.path.isdir(target_file_name):
                if not os.path.isdir(copy_file_name):
                    os.makedirs(copy_file_name)
                    copy_file(target_file_name, copy_file_name)
                else:
                    copy_file(target_file_name, copy_file_name)
            else:
                with open(target_file_name, "rb") as fStream:
                    fileName = fStream.read()  # 读取文件二进制码
                    with open(copy_file_name, "wb") as wStream:
                        wStream.write(fileName)  # 写入文件二进制码
                        print("文件复制成功:{}".format(target_file_name))
                        file_number += 1
        print('''
                *************************
                
                    成功复制了({})个文件
                    
                *************************
                '''.format(file_number))
    
    
    def register_user():
        user_name = input("请输入用户名:")
        pass_word = input("请输入密码:")
        affirm_password = input("请确认密码:")
    
        if pass_word == affirm_password:
            if auth_code():
                if not os.path.isdir(STORE_PATH):  # 判断储存目录是否存在
                    os.makedirs(STORE_PATH)  # 创建储存目录
                with open(USERS_PATH, "a") as wstream:
                    wstream.write("{} {}\n".format(user_name, pass_word))
                print("恭喜,注册成功!")
                return True
            else:
                print("不好意思,注册失败!")
                return True
        else:
            again = input("两次密码输入不一致是否重新注册(Y/N):")
            if again.lower() == "y":
                register_user()
            else:
                return True
    
    
    def remove_file(remove_filepath):
        if not os.path.exists(remove_filepath):
            print("需要删除的文件不存在")
            user_view()
        else:
            affirm = input("请输入(Y/N)确认是否删除:")
            if affirm.lower() == "y":
                if os.path.isdir(remove_filepath):
                    print("正在删除文件请等待..............")
                    shutil.rmtree(remove_filepath)
                    print("文件删除成功!")
                else:
                    print("正在删除文件请等待..............")
                    os.remove(remove_filepath)
                    print("文件删除成功!")
            else:
                user_view()
    
    
    def login_user():
        if not os.path.exists(USERS_PATH):
            print("当前没有可用的用户名和密码,请注册后使用!")
            return True
        login_username = input("请输入你的用户名:")
        login_password = input("请输入你的密码;")
    
        with open(USERS_PATH) as rstream:
            if auth_code():
                while True:
                    users_code = rstream.readline()
                    if users_code == "{} {}\n".format(login_username, login_password):
                        return user_view()
                    elif users_code == "":
                        print("登录失败")
                        return True
            else:
                again = input("用户名或者密码错误是否重新登陆(Y/N):")
                if again.lower() == "y":
                    login_user()
                else:
                    return True
    
    
    def user_view():
        print('''
            **************** 欢迎使用文件管理系统 ****************
                               1.精 准 搜 索
                               2.模 糊 搜 索
                               3.拷 贝 文 件
                               4.删 除 文 件
                               5.返 回 上 层
                               6.退      出
            ***************************************************
            ''')
        choice = input("请输入需要的选项:")
        if choice == '1':
            precise_query()
            user_view()
        elif choice == '2':
            vague_query()
            user_view()
        elif choice == '3':
            targetPath = input("请输入需要复制的目录路径:")
            if os.path.exists(targetPath):
                file_name = targetPath[targetPath.rfind("\\") + 1:]  # 获取需要复制的文件目录
                copy_file_path = input("请输入需要复制到的路径:")
                copy_path = os.path.join(copy_file_path, file_name)
                copy_file(targetPath, copy_path)
                user_view()
            else:
                print("系统找不到指定的路径!")
                user_view()
        elif choice == '4':
            remove_filename = input("请输入删除文件的路径:")
            remove_file(remove_filename)
            user_view()
        elif choice == '5':
            system_view()
        elif choice == '6':
            return False
        else:
            print("不好意思,没有你输入的选项")
    
    
    def system_view():
        print('''
            **************** 欢迎使用文件管理系统 ****************
                               1.登 录 用 户
                               2.注 册 用 户
                               3.退      出
            ***************************************************
            ''')
        choice = input("请输入需要的选项:")
        if choice == '1':
            return login_user()
        elif choice == '2':
            return register_user()
        elif choice == '3':
            return False
        else:
            print("不好意思,没有你输入的选项")
            return True
    
    
    isFlag = True
    while isFlag:
        isFlag = system_view()
    
    

    在这里插入图片描述

  • 您还可以看一下 jeevan老师的Python量化交易,大操手量化投资系列课程之内功修炼篇课程中的 讲师简介,量化交易介绍及自动化交易演示小节, 巩固相关知识点

在load_img函数中,要指定图像路径和期望的图像尺寸。以下案例代码将加载名为“example.jpg”的图像,并将其调整为大小为(224, 224)的图像。
img = load_img('example.jpg', target_size=(224, 224)),如果还有问题就只能换一下加载图片的函数了,或者私我👀详细代码