简体   繁体   English

无法将文件添加到 Python 中的文件夹中

[英]Can't add a file into a folder in Python

I am having trouble adding files into folders in python here is my code:我在将文件添加到 python 文件夹中时遇到问题,这是我的代码:

file = open(card_number, 'x')
file.write('Card Number:  ' + card_number + '\n')
file.write('Phone Number:  ' + full_phone + '\n')
file.write('Ballance In Wallet:  ' + wallet_printable + '\n')
file.write('Ballance In Bank:  ' + bank_printable + '\n')
file.close()

file = open('logs.txt', 'a')
file.write(card_number + '\n')
file.close()

My expected output is that so when i run the code it generates something new and adds the file into a folder called saves, after that i need to read the file and print its contexts!我的预期输出是这样,当我运行代码时,它会生成一些新内容并将文件添加到名为 saves 的文件夹中,之后我需要读取文件并打印其上下文! Thanks if you can help!如果你能帮忙,谢谢!

btw, this is for a simulation game so PLEASE do not take this in as any type malicious software!顺便说一句,这是一个模拟游戏,所以不要把它当作任何类型的恶意软件!

Happy coding!快乐编码!

您可以直接为open函数提供一个目录,例如open('saves/logs.txt', 'a') ,甚至open('saves/' + card_number, 'x')如果这是卡号所在的位置以及。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM