...

Python code snippets

File IO:
# read a file (whole file into memory)
infile = file('input.fa', 'r')
whole = infile.readlines()
for line in whole:
    print line
infile.close()
    
# Read a file line by line (stream into memory)
for line in file('input.fa', 'r'):
    print line.strip()    

# alternate, auto closes?    
with open(infile,'r') as fp:
    for line in fp:
        print line    
            
# Write a file
outfile = file('output.txt', 'w')
outfile.write('data') 
outfile.close() 
cx Oracle:
import cx_Oracle
connection = cx_Oracle.connect('core/core@192.168.56.10:1521/corevm')
try :
    cursor = connection.cursor()
    cursor.execute('SELECT * from loader1')
    for row in cursor:
        print row
finally:
    connection.close()