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
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.
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
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.
Thanks for the suggestions, I got it.
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: - fn = r'X:\dir\subdir\data.txt'
-
-
# Create a list of lists of integers
-
dataList = [[int(i) for i in line.strip().split()] for line in file(fn).readlines()]
-
-
'''
-
.....................................
-
Manipulate your integer or float data here
-
.....................................
-
'''
-
-
f = file(fn, 'w')
-
f.write('\n'.join([' '.join([str(i) for i in s]) for s in dataList]))
-
f.close()
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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:...
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
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...
| |