473,811 Members | 3,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with mass remove in text file

I'm trying to open a text file, remove all instances of the words
"f=x;" and "i=x;" where x can be any number 0-14. Also, I want to
remove all { " or ) or ( or ' } each time one of those characters
occurs respectively. This is what I've been able to piece together...
import os, string
x = ("f=;")
y = ("i=;)
inputFile = open('abcd.txt' ,'r')
data = inputFile.read( )
inputFile.close ()
search = string.find(dat a, x)
if search >=1:
data = data.replace(x)
data = data.replace(y)
outputFile = open('abcd.txt' ,'w')
outputFile.writ e(data)
outputFile.clos e()
This doesn't work, even to just remove "f=;". Any help would be great.

Thanks,
Reece

Jul 21 '05 #1
2 2117
First, in your intro you say you want to remove all strings of the form
"f=n;" where n can be 0-14. So you want to remove "f=0;" and "f=1;" and
.... Later, you appear to be trying to remove "f=;" which may be what
you want but it doesn't match your described intentions.

Second, the formatting (whitespace) is all messed up on your post (at
least in googroups), so its not entirely clear what the program is
supposed to do.

Anyway, why do you say the program doesn't work? Does it generate an
error when you try to run it? Or is it doing what you say and not what
you mean?

I'm guessing that it will give (provided it doesn't end on a
SyntaxError) at least the following error:
TypeError: replace() takes at least 2 arguments (1 given)

This is because the line:
data = data.replace(x)

doesn't use enough arguments for the replace() method. You need to say
what to replace it with. Since you want to remove whatever string it
is, you can use the empty string as the replacement value:

data = data.replace(x, '') #That's two single quotes

Also, unless you want to make a regular expression, you might have to
do a replace() call on data 15 times, sort of like this:
for i in range(15):
text_to_remove = "f=%s;" % i
data = data.replace(te xt_to_remove, '')

Jul 21 '05 #2
ro****@gmail.co m wrote:
I'm trying to open a text file, remove all instances of the words
"f=x;" and "i=x;" where x can be any number 0-14. Also, I want to
remove all { " or ) or ( or ' } each time one of those characters
occurs respectively. This is what I've been able to piece together...


See the thread titled "String Manipulation" which your classmate "jen"
started, which has several useful answers already.

Hopefully others will note that this is homework as well and not totally
hand you the answer on a platter, so you'll actually learn something.
Kudos to you for actually attempting it and posting your code though. ;-)

-Peter
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
14364
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? Basically: "Press any key to continue..." I beleive that I am looking for is something along the lines of a....
4
2710
by: Richard Tierney | last post by:
To create help output (the response to "myprog --help", for example) I currently create a big .h file, which includes a single string, such as: static char *help_text = "\ myprog: my program\n\ loads and\n\ loads of\n\ painfully manually\n\ formatted and\n\
3
2372
by: Strasser | last post by:
In Access2000 mass emailing worked perfectly (very powerful tool!). Doesn't work when using XP version of both Access and Outlook, even though I checked the box to ensure that I was sending the email. Any ideas? Thanks in advance.
6
1866
by: mail.cordon | last post by:
Hi everyone, I need an algorithm/program that can computer planetory position data for a given date/time/place. Can anyone please help me to find the same (source code/algorithm) or explain me how to find/calculate it. Thanks in advanced, K Amit
8
13767
by: Roger Dodger | last post by:
I have to send out 2500 e-mails to student survey recipients. The e-mails will appear to come from the specific departments that they belong to. I'm utilizing PHPmailer in the scripts I wrote to accomplish this. I've written several pages to edit emails utilizing placeholders so each individual email can be personalized for the recipient, and selection page to choose recipients from the database. The code I've written works just fine...
1
2014
by: teo | last post by:
Hallo, I'm performing a mass insertion from a text file to a db table with AdoNet commands, like this: myCommand.CommandText = "BULK INSERT ..." from a Win form no problem
4
1876
by: joder2006 | last post by:
So I'm working on this class and I have a major problem. This class happens to be for a rocket, it's a game that you play and you try to see it you can land safely from 1000 meters up in the air. The problem is when I input the throttle the program ignores it. It doesn't matter what i input into the throttle i get the same result. There are also other problems as well.
0
1479
by: nt91rx78 | last post by:
Our college changes 18 weeks semester to 16 semester, so our CS professor cannot finish teaching the last important chapter which is related with my problw\em. This is program C problem Anyone can help me with this problem, please!!!!!!!!! This is the problem: 3. Several input text files have been provided as input to your program. a) Write a function to combine these files into a single file. b) Write a function to take care of...
0
5578
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
9605
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10393
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10405
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 most users, this new feature is actually very convenient. If you want to control the update process,...
1
7671
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5556
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4342
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
2
3871
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.