r/learnpython • • 1d 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?

155 Upvotes

86 comments sorted by

81

u/crashorbit 23h 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.

28

u/quietcov3 21h ago

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

8

u/Slothemo 18h ago

For common language features though, you should absolutely get to a point where you've internalized it. Experienced coders don't have the docs open to remember how to write a function or a for loop.

6

u/crashorbit 16h ago

So often the IDE has pasted in something faster than I can.

4

u/Slothemo 16h ago

Sure, but without any IDE support, I have no issue writing basic python syntax, and also functions/features of libraries I commonly work with. This should be expected with enough experience.

44

u/desrtfx but other languages pro 23h 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.

3

u/PossibleProgress3316 16h ago

The problem I've found with all the tutorials is they just give you basics but they don't teach you how to actually make it all work, I want to learn how to actually build the application not just what a variable is but how it actually works in the application you are building, MOOC is definitely a good resource though

23

u/ontheroadtonull 22h ago edited 20h 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

19

u/ee_control_z 22h ago edited 12h 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, be sure that you have practiced each topic enough times such that you fully understand them prior to moving on to new ones.

4

u/Ok_Fun6233 17h ago

I really like this. It clicks alot

6

u/SirGeremiah 21h 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.

6

u/EbbMother5325 13h ago

This is normal. Just build your own projects and look stuff up when you get stuck.

Even experienced programmers still look up the most basic things they haven’t used daily recently. It’s part of the work.

Coding is not a history book with chapters that you memorize. Many newbies make that mistake. Coding is repetitively making mistakes until you’ve bumped your head enough times that you somehow remember. And then you’ll forget again.

11

u/stepback269 22h 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.

1

u/stepback269 10h ago

So a little more here about what I mean by "storyboarding":

This link (here) shows one of my past attempts at developing a pre-coding story of what the code is intended to do for a script I call Xpander (BTW, ultimately, I modified it even more before writing code. In other words even the storyboard gets repeatedly re-factored. It is not set in stone)

6

u/fasta_guy88 23h 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.

3

u/ThinkierTim 1h ago

Guido van Rossum, the creator of Python, was asked about learning to program in Python "the right way".

His response:
"Find something you actually want to do with it. If you say 'I wanna learn skill X', that's not enough motivation. You need to pick something (and it can be a crazy problem you want to solve; it can be completely unrealistic), but something that challenges you into actually learning coding in some language."

My advice:
Stop reading/watching tutorials. The information comes in too fast; you don't have time to sit with it, reason about it. That's not learning... it's consumption and immediate regurgitation. It's easy, so it doesn't stick*.*

Sit down with your IDE on one side of your screen (or your primary monitor), and the documentation on the other. Make something. When you get stuck, search the documentation. If you can't figure out what function to call, search Google with "&udm=14" appended to the URL, to avoid having the AI hand you the answer without you needing to think about it.

Take notes. Write in pencil, on paper. The act of writing it down makes a physical connection with the information; it makes it easier to recall.

Your brain is like a muscle; practice makes it stronger. No, really; repeated thoughts "burn in" the traces so you can think faster about that thing next time. If you want to learn, it needs to be hard. AI thinks for you, which lets your brain get lazy; it stops remembering, because it doesn't have to.

You don't learn by osmosis, you learn by putting in the effort to retain the information. Through practice. Through thinking about the steps, in order, to reach your goal.
Stop watching tutorial videos and expecting it to teach you something.

2

u/ThinkierTim 1h ago

It occurred to me that many people don't know how to add a custom search engine to their browser, so I thought I'd add this little skill upgrade for those what want to ban AI from their search results:

Open the settings in your browser. Find the section where it has search engines. Make a new one, with the search url as follows:
https://www.google.com/search?udm=14&q=%s

I've set that as my default search engine; it lets me get to the query results (what I'm actually after) without having to scroll past the hallucination machine's babbling. I can still get to the AI's answer, it just takes an extra click on either "All" or "AI" in the links at the top of the page.

Disclaimer: I'm not anti-AI, I just don't want to become "AI-by-default"; I like thinking for myself, and I want to continue doing so.

2

u/digitizedeagle 18h ago

That's the way to go. With practice, you will be riding your script again and again. Even professional coders don't remember the syntax perfectly. It's fine to check your sources.

It's a temptation to lean on AI. But it should only help you create your scripts by yourself by hinting at the solution or the next step.

2

u/cointoss3 18h ago

The best way is to develop a routine.

For example, when you start a project, what do you do so you can run your script entry point? What is your entry point?

Now that you have your entry point, you might write out comments for each step that needs to happen in your program, then you might write functions for each step.

Getting the project setup so you have a starting point and can add the libraries you need is easier now. I use uv and just run uv init inside my project folder and it will get things set up for me.

(If you’re not using uv, you really should be https://docs.astral.sh/uv/ :)

Also, you’re always going to be looking at documentation. Don’t think your goal is to be able to write without ever looking things up. Your IDE can be very helpful here with type hints and docstrings. My editor of choice is Zed. https://zed.dev

2

u/try_pull_the_other 18h ago

Failing (and tossing all night trying to solve it in your head), asking for guidance tiny progress, failing again... the learning cycle continues. In my case for a long time.

2

u/Naive_Programmer_232 18h ago edited 17h ago

you gotta just keep trying to write it. repetition/practice. think of it like learning a spoken language. you can learn the vocab / understand what others are saying, but you still gotta get out there and speak it with others in order to gain the skill. programming is very similar in that sense.

instead of having to inventing assignments to practice, something that helped me in the past is sites like codewars or leetcode where you're given a problem to solve and they basically stress-test your solution with many test cases. this helps to think beyond typical things that can break your code, it also forces defensive programming to an extent, but most importantly expands your mind to consider edge cases, which do matter in the end, especially if there is scale.

I'd highly suggest codewars first. It starts off easier than leetcode and is more practical problem solving imo, less hell bent on knowledge of canonical optimized algorithms and data structures knowledge than leetcode is from the get-go.

Lastly, try to solve the problem generally first, in your own words, then break that solution down into steps, then translate each step into code; getting into the habit of this can help offset the analysis paralysis that can happen by thinking with a code-first mindset. And in the long run, as well, even outside of well-defined problem solving, when building sizable projects, this will aid in the development of design-first mindset too imo. You want to train to think beyond the code first, then once that is figured out, then code.

1

u/JustNomalboy 19h ago

it is ok I think. Keep writing, no need to worry about referencing from lessons. lessons are ment to be references to your work anyway

1

u/CC94x 17h ago

Start simple, like super batshit crazy simple. Like make a whole program that all it does is print(“hello”). Then add one baby step at a time from memory. Each one building upon the last. Use your comments. Make a battle plan before even writing a single line of code. Kinda like a pseudo code or a wishlist too.

1

u/DrNoxin 17h ago

It is easier to understand a language than it is to speak it. Same applies to programming languages. I can follow along a lot of math, physics, etc. that I can't do personally. I can't code ASM, but I can follow along as to what it is doing.

1

u/BingusGaming44 17h ago

Hi!
Currently at uni @ 33 years old learning SWD & Computer Engineering.
Ive recently had to learn python for a discrete math class.

I highly recommend spending a considerable amount of time psuedo coding and literally writing down what your objectives are and hypothetical ways to reach those objectives. Though its an anecdote, it has greatly helped me simplify the problem to solve and logically think through methods in which to complete the objective.

As others have mentioned repetition is also key.

Here is an example of a singular function I wrote for a recent project I submitted :

#write your function for Task 8 here
# lets think about this logically, I just read the cryptography guide question for this specific task, not super helpful unfortunately.
# I tried out one myself, and I think I actually got it wrong. Seems like it may not be as intuitive as initially thought.
# I have a rough idea of how I might solve this mathematically: it seems that the general flow may suggest the following : i * key % len(word) = the designated placement for each char.
# when I did the guided resource question, this seemed to be the most accurate, though I was still wrong so may need some tweaking...
# Im going to try that first, the real question on my mind is how am I going to remake it into a string. I used a cheeky slice for T7.. that may not work here.
# ok so though my logic seems pretty air tight here, Im running into an issue.. because my list of chars is a list and not an array, I cant keep tabs of the index
# alrighty, we've made some progress. Python is sweet. Using the insert built-in might be a good option here, I already have the designated placement formula, now I just need to place each char in the correct spot using insert.
def skip_ahead_encrypt(word, key):
chars = list(word) # make a list of each char
char_array = [""] * len(word) # init an array to store and convert these late, (later michael here, testing what happens when I force the array to be a specific size...)
final_string = "" # init a string because I was running into issues with scoping in the loops
index = 0
for i, char in enumerate(chars): # for each element of the chars list
placement = ((i * key) % len(word)) # take the index of the list * key % len(word) as discussed in the pre-programming thoughts above
char_array[placement] = char
print("adding : " + char + "at placement " + str(placement))
# we're still running into an issue here: 'CFCLHAEGK' != 'CFHLEACGK'.. hmm.. super close. Im thinking maybe lists use a different index starting point? Ill check this before I go further
# reason being, if lists start @ 1 and arrays start @ 0 this may be solved by - 1 from some value. Lets assess.
# brain blast! an issue could arise from multiplying the index and the key together: Evaluate at 0... 0*5 = 0 % len(word) = 0... problematic!
# the real issue may be with inserting... Joe... please impart some wisdom upon me! Joe started with 0 because it doesnt move, so maybe joe and I are on a similar wavelength.
# another legitimate concern COULD be reoccuring characters... Im starting to see where that could throw me a curve ball. All things considered C (the only reocurring letter in this) IS giving me the issue..
final_string = "".join(char_array) # finally, put them all together
print("final string: " + final_string)

return final_string

#ugh, wow a wild ride, luckily I found that I can brute force entries into a specific index using my_array[desired_placement_index] = some_var
# I revised some of my approach, sorry that the comments dont necessarily represent the changes I made towards the end. I spent WAY too much time on this...

Now I understand this might be overkill, considering that the objective is fairly simple, but for someone like myself who just started programming about a year ago, this is the #1 way that Ive improved in programming without relying on AI, Stack overflow, google, etc.

1

u/TimBrownDev 17h ago

First thing to know is reading & writing are different skills. Even in natural languages writing usually takes twice as long to learn. Searching for answers is also an important programming skill so shouldn't be discounted.

If you need more practice I built a roadmap of the best practice problems I've seen to help teach python timbrown.dev/roadmap

1

u/OedipusOrgeron 16h ago

You learn a programming language by using the programming language. Write functions that do things, just to do them. Explore different parts of the language and do things with each part. Before you know it, you'll have built up a foundational knowledge to write anything because you know enough of the glue parts to help everything stick together. It's fine to refer to the docs if you don't remember something.

1

u/Aromatic_Fact8656 16h ago

Just keep at it, keep practicing. I’m 36 and more or less in the same boat. Just aim to get a little better each day

1

u/areweeveralive 16h ago

Brother I was still clicking purple links on stack overflow with 5+ years in python before agentic coding took off. This is how you learn - repetition. Knowing there is an answer and going to find it

1

u/dbsitebuilder 15h ago

There's no learning like problem solving. Buod something, and build some more. There are no shortcuts.

1

u/good_name_0 15h ago

I'm a senior software engineer and almost every time I go to write something, I have to open something else to remember how it works. If I'm writing in one or two languages exclusively for long enough, I'll remember their syntax no problem, but won't be able to write anything else

1

u/TinCanSailor987 15h ago

I'm learning at 54 and can't read code (yet)...so you're way ahead of me!

1

u/BotSlamminDayNNight 15h ago

reduction of a problem i was interested in solving into smaller and smaller pieces until i could map each piece to a piece of syntax.

1

u/kilkil 14h ago

I would highly recommend for you to spend more time on basic practice exercises. when I was learning Python in school I started with http://codingbat.com, can recommend. I would also recommend codewars and leetcode Easy difficulty problems.

the idea is to get practice writing short snippets of code that achieve a particular task. then, when you want to write something for yourself (e.g. a little script to execute locally on your machine, like you described), you will be more confident with your intuition about using basic language features (variables, if statements, loops, functions, etc). that will be a huge help for you.

the other thing I would recommend, while you are doing practice exercises, if you come across something you don't understand or recognize get practice reading the docs (https://docs.python.org). that will also later be a huge help to you, especially for things like renaming your local files (which requires knowing how to look up the docs for the Python standard library, so that you can check what the file related functions are and what the right way is to call then).

1

u/jesseisgod5 14h ago

Bro no use learning code at this point. Learn to use AI

1

u/WorriedTumbleweed289 14h ago

Unless this is a class in school, programming is open book. Keep manuals close. Python tutorial and manual is online and can be used for this purpose.

1

u/curly_spork 12h ago

You don't need to! Not with the LLMs! 

1

u/Sam_I_am_007 12h ago

Omg that was me. I was 36 when I started. 13 years ago with barely any videos on youtube. Read write and do it all over again. Start with string and list and loop through them. It took me 2 years until it starred to click. Remember you are 2 things. Learning python syntax and how to program. Order of operations. Be patient with yourself and youll get it. 

1

u/copperfoxtech 12h ago

I started my journey with Python at 37 too. You have to start even more simple. Write programs that run in the terminal only. For example a number guessing game where the computer chooses a number at random between a fixed range, accepts a users guess. Then expand from there.

  • Next add 3 tries only before game over.

  • Next add a hot and cold hint after each guess.

  • Next allow the user to enter the upper range of numbers to guess

  • Next ask them to enter their name and add a greeting

  • Next store their name in a JSON file along with a timestamp, the random number, and how many guesses.

  • Next when they enter a user name, cross check that with the JSON file to see if they have played before and if so, continue logging their scores under their name

  • Make the game a loop and ask at the end if they wish to continue, quit, or switch users.

Trust me. Start very small. Then incrementally add small new things.

This logic can be used to build a terminal based Todo list then once you have that and expand to learning backend and DB, you will have the foundations to build a BE part of a web app.

The first things I built were the number guessing, quiz, Todo, blackjack (this wrecked me lol but I learned classes here.)

1

u/StellarDust93 9h ago

you need to have fights with the compiler

1

u/Top-Cauliflower-1808 8h ago

The course is not the missing piece. Lessons teach you to follow a path and solo work means making the path. Pick one tiny script and write the ugly version first then fix one error at a time.

1

u/dariusbiggs 7h ago

This is a skill you develop over time, just repeat and practice.

You have your basic building blocks, now its just a matter of cutting your problem down into small enough steps.

Keep cutting it down until you have the outline of the program in those building blocks.

Do you need to iterate over something, ok that means you need a looping construct.

Do you need to check something to make a decision, that's a conditional check.

So what are the building blocks?

  • simple data types like numbers

  • boolean logic

  • conditionals

  • looping constructs

  • function calls

  • complex data types

  • basic arithmetic

  • error handling and exception handling

Then each language can have its own special sauce that makes them good at X, in Go that would be goroutines and channels

1

u/mkhanwrites_ 7h ago

Coding is really hard. I had to put in a lot of time, and I took two classes in high school for it and went to a summer program in high school for it. Honestly, for me it was time, and realizing what practices of mine were inefficient and hindering learning, and what processes of mine were efficient and helped learning. I think learning how to learn is an important skill for learning difficult things like coding (perhaps some people get it naturally but we're not all so lucky)

1

u/semanticlifer 7h ago

Check out Programming 2.0 on YouTube to help with that n+1 step from understanding the concepts to composing programs yourself.

https://www.youtube.com/@programming2.0

His videos on "The Perfect Programming Process" and "Abstraction - in Art and Programming" are probably what will benefit you the most at this moment. His examples are in JavaScript, but the whole point of programming is abstraction and Python and JavaScript are quite similar in their general feel for simple stuff (imperative, support for a notion of "objects", etc). He also has videos that are worked examples of how to go from an idea to a program that follows his own process.

1

u/Pengwin0 7h ago

How do you learn any skill? Time and repetition. Pick a project and just build it and keep doing it. Something small and easy first. Look up things you forget as you go and it will eventually become natural.

1

u/SmartSaaSBuilder 6h ago

Stop taking notes and start building small, useless projects. Try to automate one tiny task (like renaming files) without looking at the tutorial. You will fail 10 times, but on the 11th, the logic will just click. Also, try to understand what each line does, not just memorizing the syntax. Keep going! Python is very forgiving.

1

u/Relevant-Magic-Card 6h ago

Build stuff without si for a bit. Just code your heart out, break things down. Study and practice architectures, debugging, design. Imo you should train your brain as much as you can before you touch ai

1

u/wjrasmussen 5h ago

Reading code isn't helping you. You have to understand every part of it. Why was it done this way? Then play around with things on your own. I recommend writing code on paper.

1

u/PvtRoom 3h ago

A lot of what learning programming languages is, is learning what doesn't work, and why.

That learning, really requires just doing it.

You need to fail, precisely one metric fuckton times.

1

u/Lyrael9 3h ago

Your age is irrelevant. It just takes time and repetition. It's similar to a spoken language, reading a new language comes first whereas starting from scratch and writing a paragraph is more difficult and takes more practice.

You get stuck and have to look stuff up, then try another project, get stuck, look up, etc. And eventually you'll be looking stuff up less and less. I find if I'm away from it for a while, I have to look stuff up again which is annoying because I know I know it but that's OK. It comes back and then I don't have to look it up anymore.

1

u/chaotik_1130 3h ago

I don't understand why people think that watching some videos is good enough to learn how to code/program. It's good enough as an introduction to get you started. It's not going to get you anywhere close to any kind of mastery. We used to sit down with giant reference books and sit there and look stuff up and try different things trying to figure out how to do a thing. That process of getting stuck, and not knowing, and then struggling to figure it out, and then succeeding, and repeating it - that's learning. Watching a video or taking an online course - that's not really learning - that's someone telling you exactly what to do and that's great and all for an introduction but it's not teaching you how to figure out how to do other things on your own. You're destroying your ability to actually learn and retain by continuing to return to videos as your primary source of learning material.

1

u/Louicio 3h ago

Your problem isn't the programming language, it's constructing a working machine. 95% of tutorial content is just the same recycled junk, basic syntax and a few examples. Most languages have a fairly similar range of basic tools, it's how you use them to create a program that matters. Take the time to think about your process, search the internet for answers to each step of your process, fail and go back figure out why, or a better way to do things. Then do it all over again. Repetition.

1

u/jongscx 2h ago

If you've ever learned to speak a 2nd language, it's pretty similar. You can read words and follow a conversation, but until you're actually conversing in that language, you won't gain fluency.

Similarly, you need to 'converse' with the interpreter, so your brain can practice and get feedback when you try something that doesn't.

Something that helped me personally, is to purposefully not copy-paste code snippets. If I'm following something online, I'm manually typing everything out.
Don't know why, but I guess I was "more present with the code" or something. I just noticed when I start copy-pasting I run into more errors that I ultimately can't debug myself. Versus when I write things out 'manually'.

1

u/Jim-Jones 1h ago

That's quite usual, unless you are 14 years old. It's a bit like learning a foreign language, very little benefit until you finally get to enough knowledge. Keep trying.

1

u/mooglinux 23h 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.

1

u/RngdZed 23h 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/PagliacciTheBleak 23h ago

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

1

u/Popular-Being8956 23h 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.

1

u/patryk_builds 23h 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

1

u/BluishInventor 23h 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.

1

u/Tall-Introduction414 23h 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.

1

u/paperic 23h ago edited 23h 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.

1

u/oldendude 23h 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/spendology 23h 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/Pyromancer777 23h 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

0

u/impatientSOB 23h 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/errorseven 23h 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/thelimeisgreen 21h ago

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

0

u/uja_kan 13h ago

I have had the same problem but I have found solution for myself and getting better. I can write full script for GIS Analysis that I can very comfortably and independently do in any GIS environment. Here is how I got that. I stopped looking for tutorials and created one for myself. I created a 300 page tutorial document using Claude AI. I basically described myself and what my challenges are with regards to python programming. Then ask it to write a 300 page minimum tutorial book for me that will help me start writing code independently. It gave me a very structured tutorials with problems that I have to write write scripts to solve after every chapter. Before going through tutorials, I went hard on myself by reading logical reasoning and critical thinking books, read books on syntax, then anytime I want to write a script to solve the problem, I make sure I understand the problem and write pseudo code for it then I turn the pseudo code to python code line by line. If you would like to learn together, dm and let’s form a learn challenge group. We will both give each other problems and write code for it on live call.

-1

u/TheRNGuy 22h ago

You need to know API.

Use frameworks if needed.

Google or ask ai how to do things.

-1

u/mm_reads 22h ago

Keep going. Repeat, repeat. Practice makes perfect.

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

-1

u/Ayano-Keiko 22h ago

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

-2

u/Quirky_Database_5197 23h ago

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