Chris Hager
Programming, Technology & More

Python

RSS Feed

Python Utilities by Peter Norvig

Peter Norvig, the famous American computer scientist and Director of Research at Google Inc., participated in this year’s Advent of Code (a series of small programming puzzles), and shared his experience in an interesting blog post. The post starts with this amazing collection of Python utility functions, which may also be useful for your next project: # Python 3.x import re import numpy as np import math import urllib.request from collections import Counter, defaultdict, namedtuple, deque from functools import lru_cache from itertools import permutations, combinations, chain, cycle, product from heapq import heappop, heappush def Input(day): "Open this day's input file.


Python Thread Pool

A thread pool is a group of pre-instantiated, idle threads which stand ready to be given work. These are often preferred over instantiating new threads for each task when there is a large number of (short) tasks to be done rather than a small number of long ones. Suppose you want do download 1000s of documents from the internet, but only have resources for downloading 50 at a time.


How to install Qt 5.6 and PyQt5 in a Python 3.4 virtual environment on Mac OS X and Linux

A simple guide on installing the latest Qt (currently 5.6) and PyQt5 on Mac OS X 10.11 (El Capitan) and Linux with Python 3.4, inside a virtual environment.
This is a simple guide on installing the latest Qt (currently 5.6) and PyQt5 on Mac OS X 10.11 (El Capitan) and Linux with Python 3.4, inside a virtual environment. Installation Steps Python 3 Xcode and command-line tools Qt libraries Virtual environment SIP Python package PyQt5 Python package Python 3 First of all, make sure that Python 3 is available on your system. You can easily check this by opening the terminal and entering the command python3.


Find broken hyperlinks in a PDF document with PDFx

Easily find broken hyperlinks in PDF documents with PDFx, a free tool to extract references and metadata from PDFs.
PDFx is a free command-line tool to extract references, links and metadata from PDF files. You can also use it to find broken links in a PDF file, using pdfx -c: For each URL and PDF reference, pdfx performs a HEAD request and checks the status code. It there are broken links, PDFx print the link with the page number where the link was found in the original pdf:


Creating standalone Mac OS X applications with Python and py2app

In this tutorial we’ll be using py2app to create a standalone OSX application from a Python 2 or 3 source code with a simple Tkinter user interface. "py2app is a Python setuptools command which will allow you to make standalone application bundles and plugins from Python scripts. py2app is similar in purpose and design to py2exe for Windows." Relevant links about py2app: Documentation Source on BitBucket (last commit 2015-05-05) Issue Tracker, Mailing List This guide is loosely based on the official tutorial.


Python Helpers for String/Unicode Encoding, Decoding and Printing

String encoding and decoding as well as encoding detection can be a headache, more so in Python 2 than in Python 3. Here are two little helpers which are used in PDFx, the PDF metadata and reference extractor: make_compat_str - decode any kind of bytes/str into an unicode object print_to_console - print (unicode) strings to any kind of console (even windows with cp437, etc.) All of this code is in the public domain via The Unlicense.


David Beazley - Python Concurrency From the Ground Up (LIVE @PyCon 2015)

Great talk and engaging live coding session “Python Concurrency From the Ground Up” by David Beazley at PyCon 2015! Recommended 47 minutes watch. A few selected quotes: The fact that he walked in and did this demo from scratch while keeping the packed room engaged was incredible. A more comprehensive quote: David Beazley's 2015 PyCon talk on concurrency was one of my favorite talks of the conference, and it was almost all just live coding.


PDFx v1.0 - Extract metadata and URLs from PDFs, and download all referenced PDFs

I just released PDFx version 1.0, a Python tool and library to extract metadata and URLs from PDFs, and to automatically download all referenced PDFs. The project is released under the Apache license with the source code on Github! Features Extract metadata and PDF URLs from a given PDF (file or URL) Download all PDFs referenced in the original PDF Works with local and online pdfs Use as command-line tool or Python package Compatible with Python 2 and 3 Quick Start Grab a copy of pdfx with easy_install or pip and run it:


App Engine Boilerplate 2.0 – Using html5-boilerplate v2 on Google App Engine

Just a year ago Paul Irish and several contributors started working on html5-boilerplate, a popular repository of boilerplate and best practices for creating cross-browser compatible, html5-enabled websites. Thanks to the efforts of many front-end developers and researchers who have spent countless hours on developing and evolving best practices, html5 boilerplate is rapidly maturing and establishing itself as the de-facto standard html boilerplate. The authors just celebrated the one-year anniversary with the release of version 2.


App Engine Boilerplate

I recently started appengine-boilerplate, a repository of often used boilerplate code for Google’s App Engine, which allows to quickly setup new projects without having to re-invent the most common wheels. All code is released under the BSD license, and It comes with the following goodies: html5-boilerplate (incl. jQuery) OpenID authentication User preferences data model (with gravatar image link) Memcache for datastore objects Handlers for /, /profile, /login and /logout Custom template tags Various tools such as is_testenv(), decode(input) and slugify(title) app.

swirl