473,239 Members | 1,505 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,239 software developers and data experts.

Best way to handle tabular data

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 1384
bartonc
6,596 Expert 4TB
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
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 Expert 4TB
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
Thanks for the suggestions, I got it.
Jun 11 '07 #5
bvdet
2,851 Expert Mod 2GB
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
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
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
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
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
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
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
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
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
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
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.