parsed.org

Tips by tag: alias

Pipe Aliases by cygnus on Dec 31, 2005 04:13 PM

If you pipe the output of command into command like less or grep often, a global alias can save you a number of characters to type:

$ alias -g G='| grep'
$ alias -g L='| less'

so that this command:

$ ls * | grep foo | less

becomes:

$ ls * G foo L

(Note: This tip taken essentially verbatim from http://www.unixtips.org/index.php3?catList=30.)

aliaspipezsh
Psycopg1 Compatibility Mode by cygnus on Dec 31, 2005 04:07 PM

If you're using the psycopg Python module to connect to Postgres, you may find that you have old scripts that use version 1 of psycopg but you have version 2 installed and don't want to modify your scripts. At the time of this writing (and according to http://initd.org/tracker/psycopg/wiki/Migration), the version 2 module provides a very easy "compatibility mode". Just import the psycopg1 submodule and alias it, or fall back to the version 1 module if version 2 is not available:

try:
    # Try importing the compatibility submodule, which will only
    # work if psycopg version 2 is available.
    import psycopg.psycopg1 as psycopg
except Exception, e:
    # Fall back to version 1.
    import psycopg
aliasdbapiimportlanguagespostgresqlprogrammingpsycopgpsycopg2python
RSS