OOXML Vote: The Python Script Walkthrough

27 March 2008

Let's do some more simple Python usage. For an example, lets take the votes in the OOXML standardisation process that is happening as we speak. Download my simple iso vote counting script and save it with the name iso.py

Now start the Python interpreter by typing python or ipython at the terminal. Type in or paste the following commands. Lines that start with the hash mark # can be ignored.

import iso
votes = iso.IsoVote()
# Lets populate the database with country names,
# We will do this the first time only,
# (unless you want to start again for any reason).
votes.new()

# Lets save our database.
votes.save()

# Lets start again so we can show loading.
import iso
votes = iso.IsoVote()
votes.load()

# Lets record some votes.
votes.record('China', 'No')
votes.record('Cuba', 'No')
votes.record('India', 'No')
votes.record('Brazil', 'No')
votes.record('Denmark', 'No')

#and so on, until you are done

# Lets save our votes again.
votes.save()

# Lets ask for a specific result:
votes.get('Denmark')

# Finally, lets count the votes
votes.count()

# The first number returned is the approval of P-members in percent
# Microsoft must score over 66.67%

# The second number is overall disapproval in percent
# Microsoft must **not** score over 25%

The counts are only meaningful when you have a significant amount of data. Good luck and my the worst file format lose.

If you find a mistake, especially in the count function, please let me know and I will fix it.

1 Devz says...

s/and my the worst file format lose/and may the worst file format lose/

Posted at 11:47 p.m. on March 27, 2008


What do you have to say?

Show Editing Help


About

Hello, my name is Zeth, I'll be your host here.

Command Line Warriors is about taking control of your own technology, it looks at our experiences of computing; especially using GNU/Linux, the Python programming language, the command-line and issues such as techno-ethics, best practices and whatever is cool now. If you take control of your technology then you are a Warrior too!

This site is your site too which means that you can contribute and get involved. You can leave comments using the facility provided. For me, the comments and discussions are by far the best part of the site. So please do have your say!

Latest Discussions

Nui

July 18, 2008
Hmm, this would be more persuasive as an argument with some evidence. I am a happy admin of Windows and a novice user of Linux, so I have taken the ...
Give Linux a chance

Paddy3118

July 18, 2008
Hi, I too work with Electronic Design Automation tools, where Tcl is used extensively. I tend to only occasionally have to write in Tcl and so find the TclTutor utility: ...
Python and TCL

Cliff Wells

July 17, 2008
I personally cannot live without the Web Developer extension or Firebug. Unfortunately these are probably both among the more difficult to port extensions. Given how poorly Firefox functions on Linux ...
Will Epiphany be able to compete with Firefox's extensions?

making money on the internet

July 17, 2008
[url=http://www.divinecaroline.com/public/user/profile?user_id=83997]extra money 101waystoincome.com[/url]
A year after my 2007 predictions - the score card

Leatherjackets99

July 16, 2008
New Style in Leather Jackets For Man and Woman at http://www.Leatherjackets99.com They Offer Free Shipment Worldwide.
Email Syntax Check in Python

Åke Forslund

July 13, 2008
I'm pretty much a novice in both of these languages but I find them both easy to use and preform the tasks I give them. However I rarely use them ...
Python and TCL

Christopher Thoday

July 12, 2008
A single test is not sufficient to give you confidence that the algorithm is working. You should make 'number' an argument of 'main' so that you can test some boundary ...
Python and TCL

paul21

July 10, 2008
Shame on Mozilla. They should make developers specify the extension license before hosting it. They should show the license next to download button as well.
Are your Firefox extensions proprietary software?

Tris

July 8, 2008
Justin - You say they had not heard of Linux? That doesn't sound very professional to me!
Give Linux a chance

michael

July 8, 2008
what about Galeon? in Gnome i use Galeon mostly. it is fast and stable and has a nice portal with search masks for Debian, FSF, Freshmeat and so on. wtf ...
Will Epiphany be able to compete with Firefox's extensions?

vermin

July 7, 2008
> Eventually, after a bit of digging and Googling, I found their Toolbar-License... You simply found the license of the StumbleUpon Toolbar for Internet Explorer. This is another product, much ...
Are your Firefox extensions proprietary software?

Andrew West

July 6, 2008
Both the Python and the Tcl example could do with error checking. While at first this may not seem on topic with the post I think it better shows the ...
Python and TCL

Kurushiyama

June 30, 2008
XML is no replacement for SGML, it's a subset.
An Introduction to ReStructuredText