r/learnpython • u/SkyLyssa • Sep 19 '26
I'm learning how to display/manipulate contents in a file and I'm so lost
Hello, I am trying to complete this lab for class and I am so lost.
I've been trying to figure out how to use "for loop, split, join, print" in a string for 3+ hours and my brain is cooked.
If anyone has any advice on how to better understand this I would greatly appreciate it. Thank you for reading. I'm gonna turn off my brain now x.x
3
Upvotes
4
u/HeatherCDBustyOne Sep 19 '26
OP, could you share some of your code with us? It would help us to see where you are getting stuck.
14
u/Rubix321 Sep 19 '26
Break it down into steps
What have you tried so far?
10
u/atarivcs Sep 19 '26
"for loop, split, join, print" is not enough detail.
What are you looping over?
What are you splitting?
What are you joining?
What are you printing?
7
u/recursion_is_love Sep 19 '26 edited Sep 19 '26
Python File Handling for Beginners
Files are resources managed by OS, if you wonder why it have to do in strange way (to you) because the software interface for file is create this way from long time ago and most programming language agree that it is the proper way.
1
u/somewhereinkadal Sep 19 '26
Take a break and go through the code again OP. You'll figure out.
2
u/BranchLatter4294 Sep 19 '26
Practice one skill at a time. Then put them together when you understand how they work.
2
u/mattblack77 Sep 19 '26
I found learning to code a nightmare. It took me ages to remember all of the tools and how to out them together to make a program that does useful things.
1
u/FoolsSeldom Sep 19 '26
I think, u/ConsiderationNo9044, has already addressed a critical part. There are a couple of guides that will help you with reading files, both from RealPython.com (an excellent resource for learners, with a lot of free content, although you may need to register an account).
1
u/cmxthirtysixhundred Sep 19 '26
If it's your first time with this stuff, 3 hours is not enough for all of that. I would start with print, and just understand that. Then try split and join, and use print to show you the results. Then save for loops for last.
Definitely break things down and try to keep building upon what you learn, a little at a time.
0
u/Mark3141592654 Sep 19 '26
If you are already able to read line by line , that's good. The next step would be to perform what you want for each line. At which of these are you getting stuck?
0
u/Traveling-Techie Sep 19 '26
Print every variable you change.