By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,640 Members | 1,108 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,640 IT Pros & Developers. It's quick & easy.

how to make the contents of a txt into a dictionary

P: 1
hi i am trying the contents of a txt file into a dictionary there are 5 txt files which are to large to manually type up so i need to know what code i can i use

the txt files are below

the program i am trying to create is a timetable that uses a cgi form to access a python script then the python script takes the inputted name from the cgi form and has to find it in a dictionary it then must show the contents of the dictionary in a HTML table

the contents of the html table will look something like this except with every L (line) it must have the subject and teacher

Week A Monday Tuesday Wednesday Thursday Friday
Period 1 L2 L3 L5 L4 L3
Period 2 L7 L2 L7 L1 LDI
Period 3 L5 L4 L3 L5 L1
Period 4 L1 L6 L6 L6 L2
Period 5 L8 L7 L4 Meeting L8

any help will be appreciated

thanks in advance
Jul 21 '08 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 127
something like this?
Expand|Select|Wrap|Line Numbers
  1. fd = open("<yourfilehere>","r")
  2. c = fd.readlines()
  3. html="<table border=\"1\">"
  4. for s in c:
  5.  html+="<tr>"
  6.  for a in s.split("\t") :
  7.   html+="<td>"+a+"</td>"
  8.  html+="</tr>"
  9. html+="</table>"
  10. print html
Jul 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.