0
Follow
0
View

python resource file!

e4qqqq 注册会员
2023-02-26 16:11

The following answers are quoted from GPT-3 model, please use them wisely:

。

你的程序没有考虑exe文件运行后的路径将会发生改变的情况,这也是出问题的原因之一。下面提供简单的代码修改建议:

def wrapper(function):
    def _open(*args, **kw):
        """ 修改路径 """
        import os
        current_path = os.getcwd()  # 获取当前的绝对路径
        args_list = list(args)
        key = current_path + '\\'  # 使用拼接的当前绝对路径
        args_list[0] = key + args[0]
        if kw.get('file'):
            kw['file'] = key + kw['file']
        return function(*args_list, **kw)
    return _open
open = wrapper(open)

这样修改后,就可以在不同路径下都能正确存储和读取用户信息了。

Please accept my answer if it answers your question

About the Author

Question Info

Publish Time
2023-02-26 16:11
Update Time
2023-02-26 16:11

Related Question

Python pydantic模型获取字段为字符串

ssd1306 分光棱镜 miropython

python输入名字时候遇到了个问题

python setup.py build_ext --inplace命令报错

我在python中制作应用程序时收到了一个错误.错误是AttributeError: '_tkinter.Tkapp对象没有属性

python的两个重复结构[duplicate]

code-server python无法正常运行

在python中将文本文件中的数字转换为base16

是否有不使用数据库的Python替代sqlite3 ?

Python只在json中获取特定的值