(Re)-starting Python
Jan. 21st, 2019 08:54 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[community profile]](https://www.dreamwidth.org/img/silk/identity/community.png)
A couple of years ago, I wanted to learn to program, and everybody advised me that programming is much better if you have a computer that runs Linux than a Windows machine like I have. But trying to convert my netbook to Ubuntu proved an insurmountable obstacle. So I've spent a lot of time vaguely regretting that I'm not making any progress with programming, but being intimidated by the needing to switch OS part, and I've decided to start again with a clean sheet.
I poked about on CodeAcademy a bit, and found it was just annoying me in a way I didn't want to work through. Partly because there's some kind of display bug in Firefox which meant that windows kept resizing when I tried to move the mouse, and partly because the site is very non-transparent about which bits require money and which are available free.
Plus I don't really want to do coding exercises. They're like the programming equivalent of Duolingo: good for practising vocabulary / syntax, but not that helpful for actually learning. And I'm demotivated by creating code to solve already known and artificial problems. I want to do something new and actually solve a problem I have. So I did a bit of thinking and tried to come up with a plausible beginner problem.
I lit on creating an automated tool for updating the companion page to my journal. I'd been writing very repetitive HTML manually and stopped updating it for five years, and it seems like the kind of thing that a computer is better at than a human. I checked with my partners whether that looks like a reasonable beginner project, and they were encouraging, so I went ahead.
Step 0: install Python on Windows. I did this bit with
jack and
cjwatson supervising, and I'm glad I didn't try to be too independent. They helped me identify that
cjwatson did some amazing troubleshooting, even though he's completely a Linux person and doesn't use Windows at all, which I was massively impressed with, and of course grateful. He found a Microsoft answers page which caused me to discover that my computer hasn't been updating Windows since 2015. It's not quite as bad as it sounds, because there was a chunk in the middle where I was using a different machine, but argh.
It turned out the solution to this problem was to delete the update history, then iteratively install updates, restart the computer, and check for updates again, being careful not to accidentally acquire Windows Genuine Advantage or Internet Explorer 11. I would never have figured that out without help, and it does exactly match the reasons why people always say, don't try to program in Windows and ideally don't use Windows at all. Anyway, Python started up as a thing called IDLE, which is much more Windows-y (with a GUI and tabbed menus and such) than I was expecting, but there is also a more normal command prompt installed somewhere.
Next I wanted to write the traditional Hello World program. But all the tutorials assume that you want to input
I showed my work to
cjwatson, remotely at this point because he wasn't looking over my shoulder by this stage. And he pointed out that W3Schools encourages bad practice by not explicitly closing the file after opening it. So ok, I am going to try the official Python tutorial version of the same thing. That completely confused me, partly because I didn't really understand the syntax, but in the course of trying to get
cjwatson to explain, he pointed out that
After a couple of evenings of this, I have a hello world program that isn't careless about closing things after use. I don't know exactly what I'm going to need to write my HTML generator, but at least I know the general sort of shape of how to create files using Python on my own computer.
It's possible that my next step should be installing a bunch of utilities that make Windows suck less;
jack suggested Git, which I'm relieved to know can be run locally as well as on a server. And I think I need a better terminal than the Windows default one, and possibly a more programmery text editor.
I poked about on CodeAcademy a bit, and found it was just annoying me in a way I didn't want to work through. Partly because there's some kind of display bug in Firefox which meant that windows kept resizing when I tried to move the mouse, and partly because the site is very non-transparent about which bits require money and which are available free.
Plus I don't really want to do coding exercises. They're like the programming equivalent of Duolingo: good for practising vocabulary / syntax, but not that helpful for actually learning. And I'm demotivated by creating code to solve already known and artificial problems. I want to do something new and actually solve a problem I have. So I did a bit of thinking and tried to come up with a plausible beginner problem.
I lit on creating an automated tool for updating the companion page to my journal. I'd been writing very repetitive HTML manually and stopped updating it for five years, and it seems like the kind of thing that a computer is better at than a human. I checked with my partners whether that looks like a reasonable beginner project, and they were encouraging, so I went ahead.
Step 0: install Python on Windows. I did this bit with
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
x86-64
is the correct type of installer. But when I downloaded it I got a weird error. ![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
It turned out the solution to this problem was to delete the update history, then iteratively install updates, restart the computer, and check for updates again, being careful not to accidentally acquire Windows Genuine Advantage or Internet Explorer 11. I would never have figured that out without help, and it does exactly match the reasons why people always say, don't try to program in Windows and ideally don't use Windows at all. Anyway, Python started up as a thing called IDLE, which is much more Windows-y (with a GUI and tabbed menus and such) than I was expecting, but there is also a more normal command prompt installed somewhere.
Next I wanted to write the traditional Hello World program. But all the tutorials assume that you want to input
print
at the command prompt and somehow that didn't feel like a program to me. Like, I realize that giving instructions to the command prompt and getting output is in fact just as much a program as anything else, but I wanted to make a file and run it and direct its output to somewhere less ephemeral. So I quacked, mostly natural language questions, until I came on a tutorial for how to do this at W3Schools. And I wrote a tiny program and it created a text file for me in a directory. And I figured out with a bit of trial and error that running the program works from the Windows command line. I haven't quite worked out how to make it run from the one that came with the Python install, but I don't think that's critical.I showed my work to
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
f.closed
isn't actually part of the example at all, it's something to type at the command prompt to see whether with
worked correctly to close the file. The rest of my confusion was because I jumped in to the middle of the tutorial to learn how to do create and write to files which isn't planned as the first thing you try, but that bit just seems unnecessarily confusing.After a couple of evenings of this, I have a hello world program that isn't careless about closing things after use. I don't know exactly what I'm going to need to write my HTML generator, but at least I know the general sort of shape of how to create files using Python on my own computer.
It's possible that my next step should be installing a bunch of utilities that make Windows suck less;
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)