Saturday, January 7, 2012

Specify the location with Wget?

-P prefix
--directory-prefix=prefix
           Set directory prefix to prefix.  The directory prefix is the
           directory where all other files and sub-directories will be
           saved to, i.e. the top of the retrieval tree.  The default
           is . (the current directory).
wget -P /home/username/location URL

Thursday, January 5, 2012

Add a column to an existing MySQL table

To add a column called new_column to a table called table_name with a datatype of VARCHAR(20), use the following SQL statement:

ALTER TABLE table_name ADD new_column VARCHAR(20);
This statement will add the new column new_column to the end of the table. To insert the new column after a specific column, such as old_column, use this statement:
ALTER TABLE table_name ADD new_column VARCHAR(20) AFTER old_column;
To add the new column as the first column, we can use the following mysql statement:
ALTER TABLE table_name ADD new_column VARCHAR(60) FIRST;

Wednesday, January 4, 2012

Split String Multiple Delimiters Python

The python function split([sep,[,maxsplit]]) is a good way to split a string for a given delimiter or sep. The delimiter may itself be composed of multiple characters. However, this function is insufficient when multiple delimiters are considered.

>>> l = "Birds;and,Bees"
>>> l.split(";,")
['Birds;and,Bees']

The way to achieve this is to use the regular expression package and use the re.split(pattern, string, maxsplit=0, flags=0) method available from the package.


>>> import re
>>> re.split(";|,",l)
['Birds', 'and', 'Bees']


The key is to use the "|" operator to indicate multiple delimiters.