r/learnpython • • 4h ago

Learning Python at 37 and I can read code fine but can't write 10 lines without the lesson open

37, learning Python in the evenings for about 3 months. I can read other people's code and follow every lesson, but the moment I close the lesson and try to write something small on my own, like a script to rename my photos, I'm stuck after a few lines. I did a free intro course before this and hit the same wall, so this time I'm paying for something structured. What made writing code on your own start to click?

53 Upvotes

39 comments sorted by

25

u/joeshmowe 4h ago

Repetition

9

u/Eumericka 4h ago

Repetition

8

u/Crazeford 4h ago

Repetition

25

u/crashorbit 3h ago

That's actually how the process goes. Fourteen hours to competence. Two thousand to expertise. The normal coding workflow is to start with some simple scaffold then cycle incremental improvement in the code till it gets done. Usually I have the editor, doc window and a testing window up when I'm writing code.

6

u/quietcov3 1h ago

yeah having the docs open the whole time is just the default state of programming tbh, nobody memorizes all the syntax

16

u/desrtfx but other languages pro 3h ago • Bravo

You need to write code on your own - practice.

Practice is the only thing that can help you improve.

Sit down with pencil and paper and plan your program. Write down the overview, then detail each part. Then, develop your solutions for each part. Then, once you know what to do, start programming it.

It is a very common problem nowadays that people can follow tutorials that pre-chew and serve everything for them, yet, they never learn to think independently. That's why most tutorials around are actual garbage. They serve the solutions instead of making the learner work to develop the solutions.

A proper course, like the MOOC Python Programming 2026 from the University of Helsinki, does the opposite. It hands you the tools (keywords, commands) and demonstrates how to use them, then makes you do the actual programming through plenty practical exercises where you only get the prompt and have to develop the solution on your own. The course gives everything you need in the preceding textual chapters and then has you use what you learn.

The difference between reading and understanding code and writing it is the same as reading and understanding novels and writing comprehensive, fully developed ones. Just because you can do the former does by far not enable you to do the latter. In order to do the latter, you need to write. You need to write plenty bad ones.

8

u/ontheroadtonull 2h ago edited 46m ago

You never stop looking things up. 

Eventually you'll end up repeating some things enough that you don't need to look up stuff as much.

If you don't know what the next line of code should be, write it out in your own words before you write code.

You can actually write the whole script in human language before you even start writing code. 

Also this:  

https://en.wikipedia.org/wiki/Rubber_duck_debugging

6

u/ee_control_z 2h ago edited 1h ago

There is a quote attributed to Bruce Lee that went something along the lines of:

"I do not fear the man that has practiced 1,000 different kicks once but the man who has practiced the same kick 1,000 times."

In other words, before jumping from topic to topic for the sake of covering material, make sure that you have practiced every topic enough times such that you know the topic extremely well.

4

u/stepback269 2h ago

70+ yr old M here.

I'd be lying to you if I said I never did any kind of coding before.
Python, however, is a new one for me. I've been struggling with it for over 1.5 years now. The going is slow due to my age.

Over the years, I've watched people of varying ages try to learn computer technology. The older they are, the harder it generally gets. As a 37 yr old, you are not going to be able to learn as fast as a 20 year old. Those days of super neuroplasticity are gone.

Still there is hope for you.

When you first encounter a coding problem, DO NOT write any code. Instead draw a mind map of the problem composed of bite size definitions. In other words, demonstrate that you understand the problem and all its dimensions. More specifically, what inputs are you going to need? What outputs? What paths between inputs and outputs? Storyboard each path. Only after all that do you start trying to convert your well thought out plans into code.

See also this older Reddit posting.

3

u/fasta_guy88 3h ago

You need to understand the difference between learning a language (python) and learning to solve a problem using a programming language. For a moment or two, forget python, and think about how you would solve a problem if you were not using a computer language.

If you want to re-name all the files in a folder/directory, what do you need to do? (1) find the names of the files (2) change the names of the files.

This is why CS courses are often taught with pseudo-code -- step away from the details of the language, and simply write down the steps required to do something, independent of the programming language.

Once you have a sense of how to read python, shift to problem solving in your language (English?), and then translate that into problem solving in python.

1

u/SirGeremiah 1h ago

I started similarly (though a decade later), so here’s my input: that’s fine.

It took me a lot of small, simple projects before much of the language syntax came easily. If I don’t do anything for a while, I’ll get back to that point. But if I use it regularly, the basic stuff has become easy.

Just keep doing stuff. Try to write what you can without looking it up, and look up what you must. My personal approach is to write pseudocode in the IDE, and replace each line with whatever Python it takes to do that thing. I’ll often skip some lines because I can’t easily replicate them without looking it up, so I do the easy ones first. By the time I go back to the others, I’ll be in “Python mode” in my head and will be able to write some of them. The rest, I go searching.

It’s probably not the most efficient method, but it keeps me doing what I can from memory (and those lines won’t end up with more errors than the others), which is key to learning.

1

u/RngdZed 3h ago

Here's what I did to make me learn and understand python back in 2020ish..

Codewars.com to practice syntax and algos with fun little problems. Also helps you translate problems into steps, then each step translates easily into python code.

Also try some tutorial with a gui, like a pygame tutorial. Once you're done with the tutorial, and you have a "full" working game. Copy the file, rename it, then modify the code inside to fully create another game. Obviously this works great with games that are similar in nature. In example, create a pong clone with a tutorial, then flip that thing on your own and make a breakout clone from it.

Also if you're interested, I'm working on a tutorial of my own and will create a YouTube series somewhere in 2027. I can share the GitHub if you'd like. It uses jupyter notebooks (I have a diploma in data science). Only thing I ask in return is some kind of feedback hehe

Have fun!

1

u/Pyromancer777 3h ago

Writing code and reading it are two different skillsets, so if you are good at one and struggle at the other then the only way to get better is to practice the skill you are lacking.

The balance will shift as you go too, so you gotta upskill in the part you are lacking. If you find yourself writing tons of code and stopped relying on tutorials, you may want to go back to some tutorials or explore github repos to see what other people are doing and how they structure their codebase.

For now, just pick tiny problems you can reasonably solve with the skills you have been exposed to, and just keep putting in the practice until it become automatic. Once you get familiar with a concept, learn something new and then instantly go back to practice that new concept in another project

1

u/Tall-Introduction414 3h ago

Start with the data. How will you store the data that your program needs to manipulate?

A script to rename your photos... I am guessing there will be a loop that iterates over each filename. So you will need to get a list of the files. Maybe a List object is a good place to store those. That is your data.

Then you do your rename operation on each item in the list. That is the loop I mentioned.

Use language references and reference code. I've been programming for decades and constantly look up how to do X in language Y.

0

u/spendology 4h ago

Never remember what you can look up. It's okay to continue referencing code or lessons as you work on new projects.

0

u/impatientSOB 3h ago

Repetition is definitely important but you need to learn to read your error output when you try to run your app/script. It tells you everything you need. Instead of looking up the code, look up what the errors mean.

0

u/mooglinux 3h ago

This is a very normal part of learning, don’t get discouraged. Focus on breaking down what you want the code to do first, then figure out how to work the code to accomplish that. Start with very very very small things like a function that does ___ and with practice you’ll be more comfortable.

0

u/PagliacciTheBleak 3h ago

Start with pe,n and paper, sketch out the idea in pseudocode

0

u/Popular-Being8956 3h ago

I find i helpful to chunk things up into the smallest chunk you can imagine and then write that little line. then repeat until you've written 1000 lines of code.

If you're stuck, you still haven't chunked it up enough. It's like that old joke, "how do you eat an elephant? One bite at a time". don't worry about memorizing syntax. worry about how the code flows and the logic and then if you don't remember syntax, that's ok. you can look up syntax.

0

u/patryk_builds 3h ago

Reading and writing are different skills, and lessons only train the first one. following a lesson you recognise each line. writing, you have to produce it from nothing, and that muscle only grows by doing the thing that feels bad right now: getting stuck.

What usually helps is making the task smaller until you can't be stuck. your photo script isn't one problem, it's five:

  1. print the names of the files in one folder

  2. print only the ones ending in .jpg

  3. for each, print what the new name would be

  4. rename one file, a copy, to check it works

  5. rename all of them

Write step 1, run it, see output. then step 2. each one is two or three lines, and you're never more than one small thing away from a working program. before any code, write those steps as plain comments in the file. if you can't write the comment, the problem is the plan and not python.

Two more things:

- Looking things up is allowed. nobody remembers how to list files, they search "python list files in folder" every time. closing the lesson shouldn't mean closing the docs

- After a lesson, close it and rebuild the same example from memory the next day. the parts you can't rebuild are the parts to reread

Three months of evenings is still early. the wall you're describing is the normal one, and a paid course won't remove it, only writing small ugly scripts will

0

u/BluishInventor 3h ago

Active recall.

When you read or watch a lesson. Always try to write it from memory. Dont stop until you can.

You don't learn to ride a bike by watching videos or reading a book. You learn by riding the bike.

0

u/paperic 3h ago edited 3h ago

I've been doing this for a long time and there ain't no way I could rename a photo right now, without referencing the manual, in any language I currently use or ever used.

The one exception would be bash, but that's literally just the command line invoking mv, which is a separate program, so bash is not actually even doing the rename. 

In python?

I suppose I'd need to import the os, filepath and filesystem tools, but don't ask me what they're called. 

"sys"? "system"? "os"? "fs"? "filesystem"? "filesystems"? "file"? "files"? "filepath"? "fspath"? 

It could be any of this and I may need more than one.

Each language calls them something different, each of them works differently, there's no common patterns in it, and I have better things to do than memorising dozens of insane libraries when I can just look them up in 5 seconds.

And that's assuming I can't autocomplete my way to a solution.

Treat your brain like a cache, not the main storage of information.

0

u/errorseven 3h ago

Gotta solve problems with your noggin and not look things up. I suggest CodeAbbey to get you up to speed. Challenge yourself to solve as many problems as you can everyday, without googling or asking ai for answers, for a month solid. Read a problem in the morning, let your brain work on it through out the day before you sit down at a computer to test your answers. Explain to non programmers how you solved a problem. You should experience many Eureka moments in this month long endeavor and at the end it you will no longer have the issue you describe.

0

u/oldendude 3h ago

Writing code.

Start very, very small. You want to write a script to rename your photos. Maybe proceed as follows:

  1. Write a program that takes a directory name as input and prints the names of the files in that directory. That's it, that's the whole program.

  2. Suppose the rename you want to do is currently named IMG_nnnn.jpg (as might be generated by your phone), and you want to change that to nnnn.jpg. (Dumb example, but I don't know if you want some kind of wholesale renaming, or to base the rename on a list of old/new names.) Write a program with a rename(filename) function. The function takes the string IMG_nnnn.jpg as input, and returns nnnn.jpg as output. That's it, that's the whole program.

  3. Research how to rename a file in python.

  4. Put all the above together. You now have a program that does the rename of the photos in a directory.

  5. Expand the program to visit subdirectories too, recursively.

Just do the one next thing and keep going.

WARNING: Do not try this on your actual directory of photos until you are positive that your program works. You don't want to lose your photos. For example, if you rename every photo to i_fucked_up.jpg, then you will lose all of your photos except for one.

0

u/TheRNGuy 2h ago

You need to know API.

Use frameworks if needed.

Google or ask ai how to do things.

0

u/Ayano-Keiko 2h ago

Follow a project on GitHub or study with friends maybe fast way to learn

0

u/thelimeisgreen 1h ago

Build your own projects. Step away from tutorials. Study codebases. And repetition…

-1

u/Quirky_Database_5197 3h ago

do you have any goals in mind? why are you learning python? it's hard to give you an advice without that context.

-1

u/SearchContinues 3h ago

This is the "I can read Spanish but can't speak it" problem. (Sorry for my Anglo-centric reference there)

Learning programming in any language requires:

  1. Understanding the basics of computer logic, nesting, etc. All the things that all languages have. (You recognize a noun from a verb)

  2. The syntax of the language you are using and some of the basic vocabulary (I can read it, but I can't speak it)

  3. Learning what functionality exists so you can actually do things besides "Hello World". (Actual vocabulary and nuances of a specific language)

You are probably entering that third stage. You probably know how a loop works and recognize the operators, and since python uses recognizable words, you can decipher code. But now you need to really immerse yourself in order to be able to speak the language. "How do I move a file?" "How does python know where the files are?" etc.

-1

u/mm_reads 2h ago

Keep going. Repeat, repeat. Practice makes perfect.

Also just wait until you're in your 50s and only sporadically code. Hahahaha