Emacs trick: adding Python mode to Emacs

Drop python-mode.el into site-lisp (in Carbon Emacs, it is in /Applications/Emacs.app/Contents/Resources/share/emacs/site-lisp/); byte-compile it,

C-x C-f /path/to/python-mode.el RET
M-x byte-compile-file RET

then modify .emacs to autoload,

(autoload `python-mode "python-mode" "Python editing mode." t)

to associate files,

(setq auto-mode-alist
      (cons `("\\.py$" . python-mode) auto-mode-alist))
(setq interpreter-mode-alist
      (cons `("python" . python-mode)
            interpreter-mode-alist))

and to have syntax highlighting by default,

(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)

done.

Apr 11, 2016

emacs-python-mode (/progtricks)
2016-04-11, 14:59 [edit]


All Python

Sep 16, 2008

python (/progtricks)
2008-09-16, 11:35 [edit]


SciPy 2008

→ Back to Python, conferences

Tutorials

Pyraf and Cython

numpy, traits, Chaco

Day 1

Plenaries

Day 2

Plenaries

Sep 16, 2008

scipy2008 (/progtricks)
2008-09-16, 11:34 [edit]


SciPy 2007

→ Back to Python, conferences

General

Conference website

→ Useful scientific Python computing resources

→ Schrodinger evolution simulation by Nagel/Perez (from scipy.org cookbook)

→ Installing numpy and scipy: in recent versions, edit site.cfg (in dist directories) for location of blas, lapack, fftw… OS X (with devtools) has accelerated blas and lapack (note a BLAS Altivec bug in OS X 10.4). Note that numpy release 1.0.3 breaks scipy build (it may be enough to link scipy/scipy to scipy/Lib).

→ New traits and ets repository; uses EasyInstall, very nice installation engine

→ Considered the NVIDA G8800 GTX as a platform for CUDA

→ Mac: building universal libraries

→ Notebook progress in ipython?

Tutorials

IPython tutorial

Idiomatic Python (see also Goodger)

Wrapping tutorial: slides, Graph.i, all materials

Day 1

→ Lots about the One Laptop per Child project; talked to Ivan Krstic about hypercard-like educational stacks wtih scientific data and its analysis. Perhaps SAGE?

Plenary talks

Lightning talks

Day 2

Plenary talks

Aug 17, 2007

scipy2007 (/progtricks)
2007-08-17, 15:05 [edit]


Python trick: installing packages

The standard installation procedure for packages built with distutils is python setup.py install. If you want to install in a nonstandard directory, add something like --prefix=/Users/vallis/…. But then the path to the library needs to be added to PYTHONPATH (colon separated), or the library won't be accessible to import without changing sys.path.

Python eggs are a nice innovation that can simplify installs involving C extensions. After installing easy_install and setting up a ~/.pydistutils.cfg specifying something like

[install]
install_lib = ~/lib/python2.4/site-packages
install_scripts = ~/bin

you simply need to run easy_install on the egg (or the tar.gz, or the package name… the tool is a veritable Swiss army knife).

By the way, a good install_lib location on OS X is ~/Library/Python/$py_version_short/site-packages, since Python will then recognize .pth files (which does not happen elsewhere)…

Note that the location specified in ~/.pydistutils.cfg may override other install locations given as --prefix parameters to setup.py. You're warned!

May 24, 2007

pythoninstall (/progtricks)
2007-05-24, 15:19 [edit]


Programming tricks: SVN keyword management

Under default preferences, svn will not edit timestamps in newly added archive files. To allow that, use something like

svn propset svn:keywords Id,Date,Author,Revision lisasim/lisasim-retard.cpp

Nov 06, 2006

svnkey (/progtricks)
2006-11-06, 08:26 [edit]


Programming tricks: generic

Nov 06, 2006

genericprog (/progtricks)
2006-11-06, 08:24 [edit]


Programming tricks: languages

Sep 22, 2006

languageprog (/progtricks)
2006-09-22, 15:48 [edit]


Notes on SciPy2006 talks

Back to Python

General

Conference website

Day 1: tutorials

→ Travis Oliphant, NumPy tutorial (NumPy website)

→ Fernando Perez, IPython tutorial (IPython website)

Day 2, morning

→ Guido Van Rossum, keynote (Python 3000 PEP)

→ Travis Oliphant, state of Numpy

→ Fernando Perez, doing science with Python

→ Michael Aivazis, Pyre

Day 2, afternoon

→ Eric Jones, Enthought Tool Suite

→ Christopher Mueller, Synthetic programming

→ Prabhu Ramachandran, MayaVi

→ Andrew Straw, realtime computing

→ William Stein, SAGE (uses very cool jsmath for TeX display)

→ Greg Wilson, software carpentry (look at Trac and DrProject, check recommended reading at his homepage)

Day 3, morning

→ Benjamin Eitzen, GpuPy

→ …

→ Bill Spotz, parallel PDE solvers in Python

Aug 18, 2006

scipy2006 (/progtricks)
2006-08-18, 12:40 [edit]


Programming tricks

Back to the wiki root

Sections:

Generic

Languages (direct link to Python)

Tools

→ See all tricks

→ See also programming on OS X

Aug 17, 2006

home (/progtricks)
2006-08-17, 18:09 [edit]


vallis.org: Michele's wikiblog

Get the inode number using

ls -il

and then remove using the incantation

find . -inum [inode # here] -exec rm -i {} \;

Mar 29, 2006

rminode (/progtricks)
2006-03-29, 16:45 [edit]


Programming Tricks: Tools

Back to Programming Tricks home

Emacs:

rerouting backup files

setting tab length

adding Python mode

Graphics:

Fast Light Toolkit

Tioga

Making cartograms

Mini Course on Color

The Color Brewer

Color Mixer

Color Scheme Generator

Literate Programming:

Amrita

Presentations:

Wink

→ CSS-based presentations: S5

→ LaTeX-based presentations: Prosper, Seminar, PdfScreen, PPower4, Tutorial

Mar 04, 2006

tools (/progtricks)
2006-03-04, 12:10 [edit]


PyX and psfonts.map

PyX 0.8.1 chokes on the stock psfonts.map installed by i-Installer on OS X Tiger (the TeX itself is TeXLive 2006 or something similar). A simple solution is to set

fontmaps = psfonts.cmz

in /etc/pyxrc. This seems to give PyX all the fonts it needs.

Feb 24, 2006

pyxfonts (/progtricks)
2006-02-24, 13:32 [edit]


Parallel Python

→ MPI: PyMPI (not actively maintained, difficult to install), Pypar (poorly maintained?), Scientific.MPI (confusing doc!), MMPI (new, seems simple), myMPI (also new, seems good approach)

→ Shared objects: Pyre, Dopy, Pyro

Feb 01, 2006

parallelpython (/progtricks)
2006-02-01, 12:13 [edit]


Sysad trick: if-then in shell scripts

#!/bin/bash
T1="foo"
T2="bar"
if [ "$T1" = "$T2" ]; then
    echo expression evaluated as true
else
    echo expression evaluated as false
fi

Jan 03, 2006

bashif (/progtricks)
2006-01-03, 15:35 [edit]


Emacs Trick: setting the tab length for Emacs (in c-mode)

In C mode, add the line

(setq c-basic-offset 4)

to your .emacs file. In Python, it is py-indent-offset. More generally, the tab-length variable is tab-width (if you want to set this in your .emacs file, use setq-default. When working interactively, use ESC-x set-variable.

Nov 02, 2005

emacs-tabs (/progtricks)
2005-11-02, 10:47 [edit]


Unix shell trick: redirecting stderr to stdout

→ In sh/bash: prog > logfile 2>&1; (to separate files) prog > logfile 2> errfile; (pipe) prog 2>&1 |.

→ In csh/tcsh: prog >& logfile; (to separate files) (prog > logfile) >& errfile; (pipe) prog |&.

For some reason I always seem to forget this.

Jul 28, 2005

stdout (/progtricks)
2005-07-28, 08:08 [edit]


Proce55ing applications

Using Proce55ing (v. greater than 91) and OS X /Developer/Applications/Java Tools/Java Bundler, it's easy to create a standalone OS X application from a Proce55ing applet. Among other things, this allows use of the very fast OpenGL graphics routines.

Just "Export" the applet under Proce55ing; if you're using any external files (such as fonts), copy them back to the Applet directory, since Proce55ing does not do this by itself (in fact, it repeatedly deletes the files that you put in).

Then open the Jar Bundler, select your main class from the jar file, and under "Classpath and Files", add all additional files and libraries that appear in the Proce55ing-created applet directory. (If you have OpenGL libraries, you should need only those that end in .jnilib; the .so files should be linux, and the .dll files should be Windows. But don't quote me on this. Under "Properties", check "Set Working Directory to Inside Application Package". Don't forget to select a catchy icon under "Build Information" (this is the "running" icon; you'll need to change the "file" icon for the application bundle in the Finder).

A compressed disk image (dmg) can be made with Disk Utility by first creating an image large enough to contain the bundle as it is, and then converting to a read-only compressed image.

Jun 18, 2005

processing-standalone (/progtricks)
2005-06-18, 14:49 [edit]


LaTeX trick: working with EPS figures

I use Mathematica and Adobe Illustrator to create the EPS figures in my papers, but the resulting EPS files often end up enormous. A quick, and usually harmless way to slim them down is to filter them through Ghostscript. I use this script.

Also, when I have multiple versions of a figure, I usually need to find out which version is being used in the current LaTeX file. This script will do that. For good measure, this other script will also find out which other TeX files are being \input into the main LaTeX.

Apr 29, 2005

latexeps (/progtricks)
2005-04-29, 13:03 [edit]


Python function decorators

Can be a powerful tool. To look into.

link

Apr 13, 2005

decorators (/progtricks)
2005-04-13, 13:14 [edit]


  Login:   Password:   [rss] [cc] [w3] [css]

© M. Vallisneri 2012 — last modified on 2010/01/29

Tantum in modicis, quantum in maximis