Recent Notes

Displaying keyword search results 1 - 10
Created by Dr. Xi on October 01, 2007 03:26:46    Last update: August 25, 2011 08:57:40
Use the sub function in the re module to do global replacement: import re re.sub(pattern, replacement, inpu...
Created by Dr. Xi on August 10, 2011 14:58:49    Last update: August 10, 2011 14:58:49
In python: #!/usr/local/bin/python import sys if sys.ve... In shell script: #!/bin/bash PYTHON=/usr/local/bin/python ...
Created by Dr. Xi on August 02, 2011 15:44:45    Last update: August 02, 2011 15:44:45
The time module provides functions for time manipulation: $ python Python 2.7 (r27:82500, Sep 16 2010, 18...
Created by jk34 on April 19, 2011 15:42:24    Last update: April 19, 2011 15:42:24
Check the __name__ variable to see if the Python module was invoked from the command line. The line prints when the Python script is called from the command line, but doesn't print when it is imported by another Python module with import MyModule . if __name__ == '__main__': print 'Invoked f...
Created by Dr. Xi on April 17, 2011 21:34:20    Last update: April 17, 2011 21:34:20
#!/usr/bin/python # -*- coding: latin-1 -*- ...
Created by Dr. Xi on December 24, 2009 22:25:38    Last update: April 04, 2011 13:48:24
Use the urlparse module to parse a URL into parts. The urlparse function parses a URL into six components, returning a 6-tuple. This corresponds to the general structure of a URL: scheme://netloc/path;parameters?query#fragment >>> from urlparse import urlparse >>> parts = u...
Created by mak on March 04, 2011 14:17:32    Last update: March 04, 2011 14:18:35
To create a zipfile in python: Code: #!/usr/local/bin/python import zipfile #... Test unzip -l test.zip Archive: test.zip Lengt... To read a zipfile in python: Code: #!/usr/local/bin/python import zipfile #...
Created by Dr. Xi on January 09, 2011 21:14:52    Last update: January 09, 2011 21:14:52
The string method split does not take regular expression, to split with a regex, you have to use regex split : >>> a = 'a\r\nb\r\nc' >>> a.split('\n') ['a\...
Created by Dr. Xi on August 30, 2010 18:17:15    Last update: August 30, 2010 18:19:49
Use the codecs module to read file in Unicode. This is from the Python doc : import codecs f = codecs.open('unicode.rst', en... I had some luck reading files mainly in ASCII but contained some binary data with: import codecs f = codecs.open('unicode.rst', en...
Created by Dr. Xi on May 15, 2010 19:53:27    Last update: May 15, 2010 19:54:37
Use the locale module. >>> a = 1234.5678 >>> import locale >>> loca...
Previous  1 2 3 4 Next