473,485 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Best way to handle tabular data

3 New Member
I'm trying to read in a file line, change some of the line contents, and put the new contents back in the file to replace the old line. What's the best way to do this
Jun 11 '07 #1
5 1388
bartonc
6,596 Recognized Expert Expert
I'm trying to read in a file line, change some of the line contents, and put the new contents back in the file to replace the old line. What's the best way to do this
There are many ways. A "best" way is up for interpretation. Let's see what you are trying to do and see if we can improve on it. That's how things work around here.

Thanks for joining.
Jun 11 '07 #2
thaddeusj113
3 New Member
Well I'm really looking for the easiest, not necessarily the best. I have a file that is just 100 rows of 10 columns of numbers seperated by spaces. I want to read in a row, increment one of the columns based on some input, and replace the line with the new data
Jun 11 '07 #3
bartonc
6,596 Recognized Expert Expert
Well I'm really looking for the easiest, not necessarily the best. I have a file that is just 100 rows of 10 columns of numbers seperated by spaces. I want to read in a row, increment one of the columns based on some input, and replace the line with the new data
I'd say that the easiest thing would be to do all your manipulation in a 2 dimensional list, then use cpickle to store and retrieve the list from disk. The best way would be to use a true database.
Jun 11 '07 #4
thaddeusj113
3 New Member
Thanks for the suggestions, I got it.
Jun 11 '07 #5
bvdet
2,851 Recognized Expert Moderator Specialist
Well I'm really looking for the easiest, not necessarily the best. I have a file that is just 100 rows of 10 columns of numbers seperated by spaces. I want to read in a row, increment one of the columns based on some input, and replace the line with the new data
Handling data stored this way is very straightforward. Pickling the data is a good way, but reading, updating, and writing back to file is also a good way:
Expand|Select|Wrap|Line Numbers
  1. fn = r'X:\dir\subdir\data.txt'
  2.  
  3. # Create a list of lists of integers
  4. dataList = [[int(i) for i in line.strip().split()] for line in file(fn).readlines()]
  5.  
  6. '''
  7. .....................................
  8. Manipulate your integer or float data here
  9. .....................................
  10. '''
  11.  
  12. f = file(fn, 'w')
  13. f.write('\n'.join([' '.join([str(i) for i in s]) for s in dataList]))
  14. f.close()
Jun 11 '07 #6

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

Similar topics

145
8669
by: Mark Johnson | last post by:
Oddly enough, I found it difficult, using Google, to find a list of best-of sites based on the quality of their css packages. So I'd ask. Does anyone know of particularly good sites which are in...
4
2170
by: bobdedogh | last post by:
can anyone add live hyperlinks to the sortable table made by the code supplied by Machi, or know of a simple alternative bob Machi wrote Mar 10 1999, 8:00 am >>>>>>>>>>>>>> .... Hello...
2
1307
by: t | last post by:
Hi, I have the following problem. The web-based software I am to create is going to display tabular data. Lots of data so I need some pagging mechanism. I thought about creating three classes:...
7
2610
jhardman
by: jhardman | last post by:
I recently answered a post in the asp forum where a newbie had trouble accessing his form data. I chastised him for his sloppy coding and told him to validate his code (his form and input tags were...
38
3243
by: Sanders Kaufman | last post by:
I'm converting my table-based layouts to css-positioned divs - but the ONLY reason I'm doing it is because it's *considered* a best practice. I don't really see where anything goes hinky when...
5
2288
by: Lars Eighner | last post by:
Is a calendar tabular data, logically meriting table markup? -- Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner> Countdown: 465 days to go. What do you do when...
3
2205
scubak1w1
by: scubak1w1 | last post by:
Hello, I am wanting a "pretty output" of tabular data generated on the fly and saved in an array (PHP)... That is, I have a link so users can chart (JpGraph) and download (CSV) tabular data,...
2
2134
by: sabbadin12 | last post by:
Hi, I'm going to work on an application that uses a postgreSQL database so that it can uses SQLServer 2005. I think I solved most problems on the programming side, but I still have some doubts...
1
2024
by: LBLB | last post by:
In terms of processing speed, what is the best method for displaying tabular data from a database in a Windows forms C# app? We generally use data grids (Infragistics WinGrid), but have an instance...
0
7090
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,...
1
6825
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
7275
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...
0
5418
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,...
1
4857
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
4551
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
3063
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1376
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 ...
0
247
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.