Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

python - 如何从需要读取和写入单独文件夹中的.txt文件的.py文件创建python可执行文件(How to create python executable from a .py file that need to read and write .txt files in a separate folder)

I've created a python gui that can store information about the user writing .txt files in a separate folder named encrypted passwords.

(我创建了一个python gui,可以将有关编写.txt文件的用户的信息存储在名为加密密码的单独文件夹中。)

So it has lines like

(所以它有像)

file = open(file='encrypted passwords\first password.txt', mode='w')
file.write('123456')
file.close()

and

(和)

password = open(file=('encrypted passwords\first password.txt'), mode='r').read()

and

(和)

os.unlink('encrypted passwords\first password.txt')

The python script and the 'encrypted passwords' folder are in the same folder and when I run it get no problems.

(python脚本和“ encrypted passwords”文件夹位于同一文件夹中,当我运行它时,没有任何问题。)

But when I have created the .exe file using pyinstaller it did not work because it had no 'encrypted passwords' folder!

(但是,当我使用pyinstaller创建.exe文件时,该文件不起作用,因为它没有“加密密码”文件夹!)

If I added manually a 'encrypted passwords' folder it worked but is there a way in order to not manually add the folder?

(如果我手动添加了一个“加密密码”文件夹,它可以工作,但是有没有办法不手动添加该文件夹?)

  ask by rfgv translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...