From Wikipedia, the free encyclopedia

A short collection of Python code snippets

Main function

if __name__ == "__main__":
    main()

Command line arguments

import sys
for arg in sys.argv:
    print arg

sys.argv[0] is the command, sys.argv[1] is the first argument proper.

Reading from a file

f = open('attach.rtf', 'rt')
template = f.read()
f.close()

ODBC

import dbi, odbc
   conn = odbc.odbc('mydsn')
   cur = conn.cursor()
   cur.execute('select * from table1')
   list = []
   rec = cur.fetchmany(1)
   while rec:
       list.append(rec[0])
       rec = cur.fetchmany(1)
   cur.close()
   conn.close()
   for row in list:
       id = row[0]
       name = row[1]
       date = row[8]
       print '%s %s, %s' % (id, name, date)
From Wikipedia, the free encyclopedia

A short collection of Python code snippets

Main function

if __name__ == "__main__":
    main()

Command line arguments

import sys
for arg in sys.argv:
    print arg

sys.argv[0] is the command, sys.argv[1] is the first argument proper.

Reading from a file

f = open('attach.rtf', 'rt')
template = f.read()
f.close()

ODBC

import dbi, odbc
   conn = odbc.odbc('mydsn')
   cur = conn.cursor()
   cur.execute('select * from table1')
   list = []
   rec = cur.fetchmany(1)
   while rec:
       list.append(rec[0])
       rec = cur.fetchmany(1)
   cur.close()
   conn.close()
   for row in list:
       id = row[0]
       name = row[1]
       date = row[8]
       print '%s %s, %s' % (id, name, date)

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook