June 2015 Meeting

The Good, The Bad, and The Mechanized


Jun 10 2015




Until we can have JARVIS, we have web pages. Sometimes we want to get information out of them, and their owners don’t want us to. NOT NICE! We need something smarter than ‘curl’, but easier than raw Selenium. ‘Smart’ is no problem, but how about ‘smart, AND EASY’? Enter ‘Mechanize’. With just a few lines of code, you log into secure pages, scroll through controls and form fields, enter data, and submit for the win! Short programs to get info from pages you like as a human, that don’t cooperate with curl.

BONUS Follow-Up: After a helpful person said “BeautifulSoup is neat, but, wow, I could have done that with lxml…” I decided to up-the-game. Let’s revisit for a couple minutes using BeautifulSoup to parse pages with all the </a>, </title>, and several tags missing!

We’ll be glad to see you there, snacks provided by Techlahoma!

May 2015 Meeting

Is It BeautifulSoup Yet?


May 13 2015




Need to get some info out of a crummy web site? Parse some wonky XML? Any -ML, whether its well-formed or not?

Let me tell you about “BeautifulSoup”, the 4x4 of markup processing libraries. Its not only capable, but also easy.

Process out a chunk of a big web page with a dozen lines of python? How about messed up HTML with missing closing tags or tags closing out of order? No problem. What about a goofy markup dialect (DWML) that makes SAXParser crash? Its no problem.

BeautifulSoup is sturdy, easy (enough) and fast, and it’s easy to include in your program. Come see some simple, iPython Notebook-equipped examples that you can checkout and run from github, and hey, thanks to Techlahoma, have some tasty pizza to keep you busy all the while.

Mar 15 Contest


My son has a card game called Spot it Jr.! Animals that has round cards, with each card showing 6 animals on it. Given any two cards, there is exactly one animal that can be found on both cards. There are a total of 31 unique animals across the cards.

Example Cards


Given a number of animals that will appear on each card and a list of animals, print out the list of cards that need to be generated.


Your submission must be a valid Python (2 or 3) program.
Assuming your main python file is named animals.py, then to execute we would call:

$ python numbers_game.py num_animals "animal1" "animal2" "animal3" ... "animalN"

Print to standard out a line per card, where each line is a tab delimited list of animal names for the card.


$ python animals.py 2 "goat" "lamb" "sea cucumber"
goat  lamb
goat  sea cucumber
lamb  sea cucumber


The results will be judged primarily on correctness, then succinctness of solution, then speed of execution.

I have made a solution_checker.py which can be used to verify your program is working correctly.

You can test running it by running:

$ python solution_checker.py example_animals.py
'2         goat         lamb    sea cucumber' - success in 0.01 seconds
'2         potato monster     larry    lark' - fail in 0.02 seconds

Submissions Due

Email your solution to contest201503@okcpython.org by midnight of April 4th.
The test runner can be found at https://github.com/tobynance/okcpython under contests/2015_03_11_animals.

Feb '15 Contest

Numbers Game

One of the longest-running quiz shows on UK TV is called Countdown, and has a “numbers round”. There are some cards laid face down in front of the host - the top row contains ‘large’ numbers (from the set 25, 50, 75, 100), and the rest are ‘small’ (1 to 10). Six cards are picked and displayed: the choice is made by one of the contestants, who typically will ask for one large number and five small ones.

Next, a machine called “Cecil” picks a target number between 100 and 999 at random. The contestants then have 30 seconds to find a way of combining the source numbers using the normal arithmetic operators (+, -, *, /) to make the target number, or to get as close as possible.

Each source number can be used 0 or 1 times.

Easy Example

source 50 9 4 1 10 2
target 402

( 50 * (9 - 1) ) + 2 = 402
-- OR --
( ( ( 50 * 10 ) / 4 ) + 9 ) * ( 2 + 1 ) = 402

Medium Example

source 100 5 5 2 6 8
target 522

100 *  5 = 500
  5 +  6 =  11
 11 *  2 =  22
500 + 22 = 522

Resulting in (5*100)+((5+6)*2) = 522

Another solution is (100+6)*5-8 = 522

Hard Example

source 75 5 4 4 9 7
target 933

   9 * 7  = 63
  63 * 4  = 252
 252 * 4  = 1008
1008 - 75 = 933

Resulting in ((9 * 7 * 4) * 4) - 75 = 933

Another solution is ( ( (9 * 7) * ( (5 * 4) - 4 ) ) - 75 = 933

Normal arithmetic rules apply, and in particular you are not allowed to use integer rounding. That is, 7 divided by 3 is 2 1/3, not 2.

The program will accept one target number and a list of source numbers, and generate a solution which calculates the target or a number as close to the target as possible. Solve for the 3 examples above. You can consult http://www.crosswordtools.com/numbers-game/ for more games and solutions if you need more for testing.


NOTE: lines starting with $ signify a command prompt line, and lines starting with > signify output from the executed program.

Assuming your main python file is named numbers_game.py, then to execute we would call:

$ python numbers_game.py target num1 num2 num3 ... numN
> (mathematical formula)

for example:

$ # medium example above
$ python numbers_game.py 522 100 5 5 2 6 8
> (100 + 6) * 5 - 8 = 522

Whitespace in output is optional.


The results will be judged primarily on correctness, then succinctness of solution. Solutions that take longer than a second to execute will be penalized relative to other correct solutions.


Write a python program to solve the problem.
Email solution to contest201502@okcpython.org by March 6th at 12:00:00AM with PUG: numbers game for the subject.

There will be a prizes lottery for the participating contestants.

Solution must be runnable on Ubuntu 14.04, with any special requirements documented.

Feb '15 SnakeBites

Feb 2015 — Tapas Programming


February 11 2015




Our speakers this month are Mike Mattice, Greg Suddeth, and Toby Nance. They’re going to cover tidbits of code to do useful things.

July 9 2014: Parallel Processing in Python

Weaving Your Fate


July 9, 2014

11:30 a.m.



We’ll be talking about some of the ways you can do parallel processing in Python. We’ll cover the threading package, the multiprocessing package, and directly interacting with the lower level system methods like os.fork and os.exec. You’ll walk away knowing what the heck GIL stands for, and some ways to do parallel processing in Python. Assuming you can thwart your destiny and throw off the shackles of single-threaded applications.

Read More

August 13 2014: Django

Intro to Django


August 13 2014




Our Speaker this month is Buddy Lindsey Jr. who is going to give us an introduction to Django. Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.

Read More