Python如何从父目录上的文件夹中读取TXT文件
我是Python的新手,试图同时学习和编码,以测试我可以做的事情,我在课程上学习了Java,JavaScript,PHP,HTML,CSS,因此我仍然回复了基础知识。
我达到了这个问题,几个小时后我找不到我能理解和喜欢的解决方案。
这是我的结构: 我的结构
我想在test_input.py中阅读test_input.txt用户有一些字符串,我希望这些字符串根据语言更改。我虽然要在.py文件的侧面写入.txt,但是每次函数都会生成字符串,我需要再次制作所有语言文件夹,也需要添加其他语言,我还会在每个字符串上制作各种文件夹发生。
如果可能的话,我想要一个可以读取自己内部的项目以获取.txt文件的解决方案,因为我希望此项目成为.EXE桌面程序。另外,Pyhton可以制作简单的桌面应用程序吗?我看起来像我在Java中学到的Android一样学习未来的语言,但是我想使用Kotlyn,因为“更好”,所以我以博学的习惯在Java中做到了这个项目,并且在过去做了一些事情,但是我想要“将来最常使用的内容”。
如果我错了,请在任何事情上纠正我,所有这些都更多地是关于我能做什么,以及如何感谢您的帮助!!!
I'm new to python, trying to learn and code at the same time, to test what i can do, I learned java, javascript, php, html, css, on my course, so I still remeber the basics.
I reached this problem and after hours i haven't found a solution that I can understand and like.
So this is my structure:
my structure
I want to read the test_input.txt inside the test_input.py, i want that because there are some strings for the user, and i want those strings to change based on the language. I though to write the .txt along side the .py file, but then everytime a function would generate string I would need to make all the language folders again, also if needed to add another language, I also would make various folders on every string occurency.
If possible, i want a solution that read the project inside itself to get the .txt file, because i want this project to be an .exe desktop program. Also, is pyhton good to make simple desktop apps? I'm lookin foward to learn the future languages, like I learned android in java, but I want to use kotlyn because is "better", so I cold make this project in java as a learned and did some in the past, but I want the "what will be most used on the future".
Please correct me in anything if I'm wrong, all this is more about see what I can do, and how, thanks for the help!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解您,您想加载并读取PY中的TXT文件。如我所知,如果是这种情况,那么也许您想在此处遵循本教程:
https://www.pypythontutorial.net/python-basics.net/python-basics/python-basics/python -Read-text-file/
另外,您是否已经尝试打开/加载它?如果是这样,您会遇到错误吗?在大多数情况下,对于初学者来说,这是一个路径问题,因此请确保已经设置了路径。
干杯
If I understand you correctly, you want to load and read the txt file in py. If this is the case, like i understood, then perhaps you want to follow this tutorial here:
https://www.pythontutorial.net/python-basics/python-read-text-file/
Also, did you try to open/load it already? If so, did you get an error? Most of the time, it is a path problem for beginners so make sure the path is setup already.
Cheers
我从geeksforgeeks那里得到了这个脚本,它有多种形式的读取.txt,我也将您的文档留给您。
https://www.geeksforgeeks.org/reading-writing-writing-writing-writing-writing-text-files -python/
I got this script from geeksforgeeks, it got multiple form of how to read a .txt, I am leaving you as well the documentation.
https://www.geeksforgeeks.org/reading-writing-text-files-python/