Not logged in
Talk
Contributions
Create account
Log in
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Page
Discussion
Edit
View history
Editing
Mika/Notes/Computer Stuff
(section)
From WikiDotMako
Jump to:
navigation
,
search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=Python= To be sorted * http://mysql-python.sourceforge.net/MySQLdb.html ** http://www.devshed.com/c/a/Python/MySQL-Connectivity-With-Python/2/ *TypeError: fetchone() takes exactly 1 argument (2 given) ** This really means 1 argument given because each method comes with an argument to begin with. * To obtain input, I can use raw_input(). * bpython * time ** from datetime import date, timedelta (to do day calculations) ** d=date.today()-timedelta(days=7) ** In order to compare dates in string and dates in datetime in iso formats; n > d.isoformat(): '''Problem:''' I wanted to create a [http://en.wikipedia.org/wiki/Table_markup wiki table] from CIA's Infant Mortality Rate [https://www.cia.gov/library/publications/the-world-factbook/rankorder/2091rank.html ranking] data. I didn't want to change to the wiki table format, so I decided to write a python code. '''Solutions:''' I had to read a text file, make a list for each line, take out the words I need, and print in the wiki table format. I did the following first to change tabs to commas but that was probably not necessary: sed 's/\\t/,/g' Desktop/rawIMRdata.text > rawIMRdata2.text When I forgot /g, it only outputted the last line. Here's the python code: imr_data = open("rawIMRdata6.text") #f = file("imr_data","r") print '''{| class="wikitable" border="1" \n|- \n! Ranking 1 \n! Country 2 \n! IMR \n''' for line in imr_data.readlines(): # To make a list for each line from text file: a = line.split(',') #print a and strip the space after each word one = a[0].strip() two = a[1].strip() three = a[3].strip() combined = '|-\n|' + one + '\n|' + two + '\n|' + three print combined print r'''|}''' ----
Summary:
Please note that all contributions to WikiDotMako are considered to be released under the Attribution-Share Alike 3.0 Unported (see
WikiDotMako:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:
Cancel
Editing help
(opens in new window)
Tools
What links here
Related changes
Special pages
Page information