Sunday, January 29, 2012

Python Rocks

Attended a great Python Workshop led by Hackers DC. Detailed and fast paced. Learned a ton.
Can't wait to write my own API!!!




Cool things I learned:

  • Join columns with tabs or commas
columns = []
for header in headers:
    columns.append(header.text)
print '\t'.join(columns)
%or
print ','.join(columns)

  • Generic try statement with pass instead of specifying an error:
   try:
       bank_name = data[0].text
       print bank_name
   except:
       pass

  • Randomize the frequency of url hits
%time.random
%fake the user client
random.choice(range(1,10))

No comments:

Post a Comment