Archive for the ‘Python’ Category

Absolute, Relative, and Splitting Paths in Bash

Tuesday, 1 December 2009

The main stumbling block with splitting paths in Bash is converting a relative path into an absolute one.

Searching the Internet I found many partial solutions, but none was entirely satisfactory. There may be a better solution out there, but I didn’t find it.

(more…)

Advertisements

Palindromes

Friday, 20 November 2009

Running a simple script over a file containing a list of basic English words revealed the following palindromes.

(more…)

Python Source Code Encodings

Saturday, 17 October 2009

If when you try to run a fragment of python like this:

#!/usr/bin/python

### comment with a £pound sign
if __name__ == '__main__':
  pass

you get an error such as

SyntaxError: Non-ASCII character '\xa3' in file main.py on line 3,
  but no encoding declared ...

then what you need is an encoding declaration on the first or second line of the file.

(more…)

Painters and @Decorators?

Tuesday, 29 September 2009

Python Decorator Library

Includes:

Memoize
[Pseudo-]Currying
Pre-/Post-conditions
Type Enforcement

HCF without Division

Wednesday, 8 April 2009

The previous blog entry reminded me of this…

(more…)

Division via Multiplication

Wednesday, 8 April 2009

In very special circumstances, integer division can be replaced by (integer) multiplication.

(more…)