liv: alternating calligraphed and modern letters (letters)
[personal profile] liv posting in [community profile] livredor
I wrote a snippet of code that does something towards what I actually want to do! I'm really pleased because I wasn't sure I was going to be able to work out where to start, and I have a pretty good idea where to go from here.

I figured out how to use a loop to create the same bit of HTML repeatedly with different years. I initially got excited about using range() rather than hard-coding a list of years, but then I came upon the problem that I couldn't concatenate the numbers, which are int, with the string containing the HTML text. The tutorial at W3Schools just says If you try to combine a string and a number, Python will give you an error. I mean, yes, yes, it does in fact give me an error, would you like to suggest what I can do about it? I can see the argument that such a suggestion would out of place in a beginner tutorial, but I also wasn't 100% confident that there is a way round this error, I was tempted to assume, this is a thing you just can't do.

I decided to work with a hard-coded list to start off with, just to see if I could get the loop part working. It took a bit of fiddling with escaping " in HTML, and it makes something ugly; I think there are various HTML templating tools for Python which would probably be more readable, but it's a start. I learned from Stack Overflow that \n means a linebreak, but quickly remembered that HTML needs actual tags for linebreaks.

I started with an embarrassing mistake of trying to put the file creation inside the loop, but was able to troubleshoot that fairly quickly. There are lots of things I want to do to improve this, starting with doing something with range() and str() so that I can generate a list of numbers rather than just writing out each year. I think something involving nested loops will let me print a link for each month of each year, which is what I ultimately want.

After that I want to make the program a bit more extendable, so I can make arbitrary lists of months rather than just the ones I decided at the start were missing from my web page. The step that seems least clear to me is working out what is already in my hypothetical HTML file, so that I can add to it starting from last time the program was run. I feel good that I have some concrete ideas about how to make my terrible first "real" program into a slightly less terrible program.

Having a program that actually works and does what I intended as a first step, I wanted to preserve it before I tried to do anything complicated. [personal profile] jack had helped me install Git for Windows, which I got from git-scm. I somewhat know git commands, at least enough to be able to look up the syntax, from when I was doing DW stuff. I'm a bit scared of using Git to interact with other people, because I messed up badly in the past, but [personal profile] jack reassured me that I can make Git store everything locally on my private computer where it won't affect anyone else. In this case I committed the first version of the code without incident, yay.

Thanks to everybody who has been commenting on my random skill-learning notes! I'd like to make clear at this point that I very much appreciate encouragement, and general advice. But I would prefer not to have specific advice like, this is the syntax I'd use to do what you want / this is a tool that already exists to do this so you don't have to reinvent the wheel. Right now I'm in a stage of learning by making my own, deliberately sub-par tools, and just being told the optimal way to accomplish my small task wouldn't help with that.

July 2025

S M T W T F S
  12345
6789101112
13141516171819
20 212223242526
2728293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 13th, 2026 09:58 pm
Powered by Dreamwidth Studios