473,411 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

how to make the contents of a txt into a dictionary

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

http://www.mediafire.com/?ewmnjtmjjwm
http://www.mediafire.com/?zbfeexwvcml
http://www.mediafire.com/?ynjvbv1m1mj
http://www.mediafire.com/?emnhlkabvs9
http://www.mediafire.com/?3xzljbemgmx

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
Recess
Period 3 L5 L4 L3 L5 L1
Period 4 L1 L6 L6 L6 L2
Lunch
Period 5 L8 L7 L4 Meeting L8


any help will be appreciated

thanks in advance
Jul 21 '08 #1
1 1308
kudos
127 Expert 100+
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
  11.  
-kudos
Jul 21 '08 #2

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

Similar topics

1
by: none | last post by:
or is it just me? I am having a problem with using a dictionary as an attribute of a class. This happens in python 1.5.2 and 2.2.2 which I am accessing through pythonwin builds 150 and 148...
7
by: Robin Becker | last post by:
Is there a simple way to replace the contents of a dictionary entirely with those of another. for lists we can do L1 = L2 but there doesn't seem to be an equivalent for dicts. -- Robin...
7
by: Lowell Kirsh | last post by:
I have a script which I use to find all duplicates of files within a given directory and all its subdirectories. It seems like it's longer than it needs to be but I can't figure out how to shorten...
1
by: Ken Fine | last post by:
I have a menu system that has nodes that can be opened or closed. In an effort to make my code more manageable, I programmed a little widget tonight that keeps track of the open/active item and...
3
by: Bengt Richter | last post by:
Has anyone found a way besides not deriving from dict? Shouldn't there be a way? TIA (need this for what I hope is an improvement on the Larosa/Foord OrderedDict ;-) I guess I can just document...
12
by: sandravandale | last post by:
It's important that I can read the contents of the dict without flagging it as modified, but I want it to set the flag the moment I add a new element or alter an existing one (the values in the...
4
by: Water Cooler v2 | last post by:
I can't believe I've stumbled on a simple problem such as this. After all these years, that too. Anyway, it goes that I just realized that I could not iterate through my hashtable and print out...
7
by: André | last post by:
Hi, I need several cookies depending of an variable (x), so i defined a HttpCookie() as an array. My problems: 1)I get the error: Object reference not set to an instance of an object. 2)My...
7
by: Andy B | last post by:
I have an instance of an object that needs to be accessed by all members of a page like page_load, button_click events and so on. Where in the codebehind would I put the creation of the object...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.