473,569 Members | 2,789 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,P ashto
Albania,AL,Tira na,Lek,Albanian
Algeria,DZ,Algi ers,Dinar,Arabi c
Andorra,AD,And. La Vella,French Franc,Catalan
Angola,AO,Luand a,New Irwanza,Portugu ese
Anguilla,AI,,Ea st 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 1386
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,P ashto
Albania,AL,Tira na,Lek,Albanian
Algeria,DZ,Algi ers,Dinar,Arabi c
Andorra,AD,And. La Vella,French Franc,Catalan
Angola,AO,Luand a,New Irwanza,Portugu ese
Anguilla,AI,,Ea st 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
8433
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 problem. The program may crash unexpectedly while writing to the file. If so, my program should detect this during startup, and then (during...
13
2125
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 DrPython for the Editor.... I still need to decide on a database........ I've really only used Access, and my SQL skills aren't that great. It...
19
4078
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 the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can...
13
2450
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 month. We are assuming that the year will be valid 4 digit integer. So you don't have to think much about that(in terms of validation) except for...
12
2795
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 we enter 4, the size of four triangles are 4 rows. In addition, I am also writing a program which i started and failed in giving the right size...
0
1238
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 dependents, martial status and a dollar amount which is a deduction for the company 401k plan. part one of the program allows one to add employee to the...
1
6205
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 dice, the code for the rolling of the dice should take place in a user written module named rolldice. b.. The rules of the game are as follows:
12
2991
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 the instructions and couldnt get the correct results. heres the code stuff... temperature=input("what is the temperature of the spam?") if...
7
2994
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 i will pay another $10 upon completion> CISY 103 - Project 01 - Fall 2007 - 02x Daily Sales report for Kahuna Burgers Overview The manager of...
5
1788
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. Assume that the bar code is to access a file that store the product descriptions, unit price and quantity of each product sold in the shop. Assume that...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7672
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6283
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
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 we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.