python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
import codecs codecs.open(filePath, "r", "utf-16")
# -*- coding: utf-8 -*-
import sys f = open(sys.argv[1]) for l in f: l = l.strip() ...
ord("a")
[e.replace("'", "''") for e in l]
import re reg = '^[0-9]*?[)\.-]' p = re.compile(reg) if p.match(str): print re.sub(reg, '', str)
sub(pattern, repl, string, count=0)
Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
if a callable, it's passed the match object and must return
a replacement string to be used.
syntax reference: http://www.python.org/doc/2.3/lib/re-syntax.html
rows = [] rows.append(['vanessa', 'carlton']) rows.append(['nelly', 'furtado']) import csv csv.register_dialect('mycsv', quoting = csv.QUOTE_ALL) writer = csv.writer(open("file.csv", "wb"), 'mycsv') writer.writerows(rows)
file.csv
"vanessa","carlton" "nelly","furtado"
ref:
help(csv)# SQL fields l = [] l.append(['section', 'art_gallery']) l.append(['category', 'just a test']) l.append(['type', 'image']) # build SQL query keys = [e[0] for e in l] values = [e[1] for e in l] values = [e.replace("'", "''") for e in values] query = """insert into `media` (`%s`) values ('%s');""" % ("`, `".join(keys), "', '".join(values), ) print query
import os for dirname, dirnames, filenames in os.walk('.'): for subdirname in dirnames: print os.path.join(dirname, subdirname) for filename in filenames: print os.path.join(dirname, filename)
Source: http://stackoverflow.com/questions/120656/directory-listing-in-python
import EXIF f = open('photo.jpg', 'rb') tags = EXIF.process_file(f) print tags
Source: http://www.dudek.org/blog/154