How to open and edit text files from a folder? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to open and edit text files from a folder?

I have written a python program such that it will open . txt files from a folder which the user provides. However I am able to print all the. txt files present in the folder. But not able to open and edit those txt file. What is I am missing in the code? https://code.sololearn.com/ca6O2DUb5t0l/?ref=app

27th Oct 2020, 11:41 AM
Dr£@M_c@tcH£r
Dr£@M_c@tcH£r - avatar
2 Answers
+ 5
Dr£@M_c@tcH£r , what kind of operating system you are using? Independend of this, the recommended way to handle file paths or folders is to use pathlib, which is a module from python. Paths in pathlib are handeled as objects, which makes it much more easy to work with, even if the os-system where you created the code is different from the final system. It takes some time but it's worth to have a closer look on it. https://docs.python.org/3/library/pathlib.html
27th Oct 2020, 11:58 AM
Lothar
Lothar - avatar
0
This code provide a live solution for reading of text files and more: https://code.sololearn.com/cPeBWF4tkD8w/?ref=app
27th Oct 2020, 11:49 AM
JaScript
JaScript - avatar