Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Sunday, February 12, 2012

Easy Permutation Calculation in Python

I was recently doing some Python programming, and had to compute all possible combinations of items from two separate lists. At first, I thought, I'll just do it this way:

list1 = ['a', 'b', 'c']
list2 = ['x', 'y', 'z']
for i in list1:
    for j in list2:
        print i, j
a x
a y
a z
b x
b y
b z
c x
c y
c z

However, my loop body was something that was a little more complicated than a print, and couldn't be done well inside of a loop like that. And besides - this is Python we're talking about. Surely there is a better way!

Well, there is - and don't call me Shirley. Details coming up after the break!

Sunday, January 29, 2012

Web Form Automation with Selenium WebDriver

Have you ever had a tedious task involving a web site form that you have wanted to automate, but couldn't? Or perhaps you wanted to automatically test a website you were making? Well, there's a fairly well-known tool for browser automation called Selenium. I'd heard of it before, and was looking into it when I had a project where I want to take some JavaScript based pages, run them through a JavaScript engine so they could generate the HTML I needed and then save the results. But until now, I had never had a chance to use it. It's powerful, and there's a lot you can do with it that I won't cover. But the basics will get you a long way.

More after the break.