Roy Tang

Programmer, engineer, scientist, critic, gamer, dreamer, and kid-at-heart.

Blog Notes Photos Links Archives About

All entries tagged python.

You can subscribe to an RSS feed of this list.

Jan 2020

  • Flask vs Django

Aug 2019

  • Python: Markov Chains

    Back when I was still learning Python in 2008, one of the first “fun” scripts I wrote was a text generator using Markov chains. I’d run it against all the chat logs I had with people at work and serve the results from a webserver on my computer. THe results were often amusing and sometimes hilarious. Since I’ve been going through my old scripts lately, I thought I’d update that script to Python 3 (read: add parentheses around print params and use pathlib) and run it against all the posts on this here site.

    read more (162 words)

    Posted by under post at #software development #python
    Also on: twitter / 0 / 162 words
  • Devnotes: Python Pathlib

    Ever since I started learning Python back in 2008ish, I’ve been using it as my primary scripting language for various tasks such as processing log files, organizing my own file system, processing stuff on this blog, and so on. A lot of it is basically moving files around. In the days of Python 2, that involved a lot of imports of different libraries like os, shutil and glob. It can become a bit messy with so many imports, and I often can’t remember which import I need for a particular case and end up having to search for the documentation (or stackoverflow, let’s not kid ourselves here).

    read more (316 words)

Feb 2019

Oct 2018

Mar 2017

Feb 2017

Jan 2017

  • So the other day I was reworking a Python script that I had been using for years on my home PC to manage and categorize some downloaded files for me. This time I wanted to add some smarter behavior to make it more able to figure out when to group files into folders without constantly needing manual intervention from me. To do this, I needed to persist some data between runs – so that the script remembers how it categorized previous files and is able to group similar files together.

    read more (322 words)

    Posted by under post at #python #Software Development
    Also on: tumblr twitter / 0 / 322 words

Aug 2011

Oct 2010

Jul 2010

Jun 2010

  • Is there any Python library that allows me to parse an HTML document similar to what jQuery does?

    i.e. I’d like to be able to use CSS selector syntax to grab an arbitrary set of nodes from the document, read their content/attributes, etc.

    The only Python HTML parsing lib I’ve used before was BeautifulSoup, and even though it’s fine I keep thinking it would be faster to do my parsing if I had jQuery syntax available. :D

Jan 2010

Dec 2009

Sep 2009

Apr 2009

Feb 2009

Jan 2009

  • Using Django Pingback

    I actually had some trouble using django-pingback on my custom blog engine; the django-pingback documentation is mostly fine, but there were some caveats that I had to discover myself through a bit of debugging: The URL specified for the XML-RPC endpoint in the HTML head needs to be a full absolute url including domain, i.e. http://roytang.net/xmlrpc/, which gave me trouble when I was trying to test using localhost pinging to an online server.

    read more (317 words)

Dec 2008

  • Colophon 2008

    Frontend: All page templates are valid (X)HTML. However, I choose not to claim valid XHTML (and no doc type declaration) since I can’t guarantee that blog posts I write are compliant! The site uses standard CSS and uses the Blueprint CSS Framework for the grid layout of the page. The site design is entirely original (if not simple and bland – I’m not very good with website design yet!). The site has minor usage of JQuery Javascript library in some parts.

    read more (283 words)

  • Fixing up the comments

    I played around with the built-in comments app today, trying to clean it up. Some findings: Some of the moderation views, such as flagging a post or deleting a post, accept a next parameter that determines where the view will redirect to after the operation. However, the way the url’s are set up, there’s no easy way to pass this parameter normally, even through query strings. This lovely bug is documented in http://code.

    read more (438 words)

Nov 2008

Oct 2008

Jul 2008