Categories
Computers

Some Kind of Pythonic Magic

I’ve been tinkering with my nascent Python “game”. Each time I expand on it, it’s to learn a bit more about Python, or some feature or module that seems appropriate. To that end, I’ve heard that Python comes with “batteries included”. Meaning the standard suite of tools that come with a typical install of Python is extensive.

To that end, it feels like the built in libraries are somewhat magical in how well they handle things. I’m comparing to C, whose idea of standard libraries feels unbelievably spartan in comparison. Different tools for different jobs, I suppose. There are really weird, simple pleasures in programming in Python. Consider:

import os from pathlib import Path scoreboard = Path(os.environ.get("XDG_DATA_HOME") + "/guessing-game/scores.txt") if scoreboard.exists: with scoreboard.open("a+") as scores: // Game code here

This is delightful. I don’t have to do stuff like count to see if the return from Path is greater than 1 to indicate existence of a file, like I have to in JS when selecting elements, Path comes with a ready-made exists method that does exactly what it says on the tin. Oh, and the whole thing figures out the path on POSIX vs Windows path styles. Scrumptious!

I know my little honeymoon phase with my incredibly basic script will probably come crashing down when I want to do stuff more complicated, like have a high-scores list, but I’m enjoying it while it lasts.

Categories
Programming

Python Games

Yesterday, I posted about being generally uninterested in programming. Burnout is a pretty common case, and add on my preexisting condition, and you’ve got yourself an issue. In order to combat that, I decided to take up learning a very popular language: Python. I’ve always admired Python from afar. It seemed like a well-organized language with some interesting components. There is a module for everything and while performance isn’t quite as fast as C, it’s interpreted, so it’s to be expected.

To that end, I began writing a small game. Just guess a randomly chosen number in a range. You get a couple of attempts. Nothing hard, nothing that I’d have to dig too deep into learning how the whole thing works. A test to see if I enjoyed it.

I did enjoy it. For the most part. Learning (or relearning) the Python grammar after being embedded in C-styled languages for so long was a little bit of a hurdle. Overall, I was able to get things put together pretty well. I think I’m going to continue to extend and learn more about the deeper functions and modules available in core.

I’m not unfamiliar with programming, though, I’m sure Gordon Ramsay is not far off, eying my bread for a little sandwich making.

Idiot Sandwich

If you want to follow along, you can check out the edits and commit history I’ve posted to the repo. I may even enable issues to allow people to chime in where I might have done something wrong.

Categories
Computers Media

Python is Fun

Python is fun.

No, really, it’s fun. There are a bunch of modules that make it easy to implement ideas that may feel complex in other languages (I’m looking at you Perl.).

😀

Not to mention, the most excellent program (for mac) TextMate makes it all the more fun It does auto- complete and you can run your script inside TextMate with a single command (or externally with a different, single, command).