473,504 Members | 13,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help writing a program

2 New Member
I need help with a program that reads lines from a CSV input file and generates an output file in tabular format. So the first line in the input file should have the header infromation for the table and all the other lines are data lines. After I need to create a variant that gives the same output file and generates an HTML
file. So it's supposed to have an HTML table essentially, with a row
for each data line.

So an example of the CSV file would look like this:
Country, Code, Capital, Language, Currency
Afghanistan,AF,Kabul,Afghani,Pashto
Albania,AL,Tirana,Lek,Albanian
Algeria,DZ,Algiers,Dinar,Arabic
Andorra,AD,And. La Vella,French Franc,Catalan
Angola,AO,Luanda,New Irwanza,Portuguese
Anguilla,AI,,East Caribbean Dollar,

And the output should come like this:
COUNTRY CODE CAPITAL LANGUAGE CURRENCY
Afghanistan AF Kabul Afghani Pashto
Albania AL Tirana Lek Albanian
Algeria DZ Algiers Dinar Arabic
Andorra AD And. La Vella French Franc Catalan
Angola AO Luanda New Irwanza Portuguese
Anguilla AI East Caribbean Dollar

Any help please?
May 17 '07 #1
4 1383
dshimer
136 Recognized Expert New Member
IMHO see
http://www.thescripts.com/forum/post2570111-2.html
May 17 '07 #2
bvdet
2,851 Recognized Expert Moderator Specialist
There are several threads on this forum dealing with reading and writing files, some regarding csv and tab delimited data. I am sure we can help you, but you must show us some effort toward solving your assignment.
May 17 '07 #3
ghostdog74
511 Recognized Expert Contributor
I need help with a program that reads lines from a CSV input file and generates an output file in tabular format. So the first line in the input file should have the header infromation for the table and all the other lines are data lines. After I need to create a variant that gives the same output file and generates an HTML
file. So it's supposed to have an HTML table essentially, with a row
for each data line.

So an example of the CSV file would look like this:
Country, Code, Capital, Language, Currency
Afghanistan,AF,Kabul,Afghani,Pashto
Albania,AL,Tirana,Lek,Albanian
Algeria,DZ,Algiers,Dinar,Arabic
Andorra,AD,And. La Vella,French Franc,Catalan
Angola,AO,Luanda,New Irwanza,Portuguese
Anguilla,AI,,East Caribbean Dollar,

And the output should come like this:
COUNTRY CODE CAPITAL LANGUAGE CURRENCY
Afghanistan AF Kabul Afghani Pashto
Albania AL Tirana Lek Albanian
Algeria DZ Algiers Dinar Arabic
Andorra AD And. La Vella French Franc Catalan
Angola AO Luanda New Irwanza Portuguese
Anguilla AI East Caribbean Dollar

Any help please?
just doing the tabular part, i see the output, its just removing the ",".
so you can just read your file line by line, then use the replace() method to replace the ",".
Expand|Select|Wrap|Line Numbers
  1. eg
  2. for line in open("yourcsv"):
  3.     line = line.replace("," , "\t")
  4.     print line
  5.  
  6.  
May 17 '07 #4
on3word
2 New Member
Thanks to everyone that replied, and thanks in advance to those who will.

I know for the first main part of the program I need to get/set inputs and the open in/out files for reading/writing. And then get rid off \n at end, then split on ',' --> header_list:

I'm mostly having trouble with the syntax though and getting that work in IDLE.
May 17 '07 #5

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

Similar topics

48
8415
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
13
2114
by: Heather Stovold | last post by:
Wow - deciding to program in python sure requires a lot of decisions! So far: I've decided on python for the programming language. I've decided on wxpython for the GUI.... I've decided on...
19
4065
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
13
2444
by: vgame64 | last post by:
Hi, I have been struggling with writing a program for a few hours. The requirements are that: """You will be writing a program which will determine whether a date is valid in terms of days in that...
12
2792
by: asif929 | last post by:
I am trying to write a program which creates four triangles. The program begins with prompting a user " Enter the size of triangles", number from 1 to N is the size of four triangles For Example if...
0
1232
by: RENEE | last post by:
I Need help writing a program that will process payroll for small company with 26 employess, needs to store all employee name in sequential file along with address info, pay rate, number of...
1
6199
by: lenest | last post by:
I need help writing a program.... You are to write a python program to accomplish the following: a.. Play a dice game of Craps using a random number generator to simulate the roll of the...
12
2983
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
7
2989
by: rohitsripathi | last post by:
i need help writing this program... i am in college and i do not have time do this right now as i need to study for another test....but this is due tonight...i will pay $5 if you accept to do it and...
5
1776
by: alck1234 | last post by:
Hi, I need help on my mini project on object orientated programming. The question goes like this: A mini-mart has just installed a bar code reader to improve efficiency at their checkouts....
0
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
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
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
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
4698
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...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.