Python: deleting numbers in a file

I need to remove numbers from a text file in Windows XP. I am new to python and just installed it to clear the data.

I saved the test file in the folder C: \ folder1 \ test1.txt

The contexts on test1.txt are just one line:

It should not b3 delete3d, but the number at the end is yes 134411

I want to create a result1.txt file containing

It should not b3 delete3d, but the number at the end is yes

Here is what I have tried so far

import os fin = os.open('C:\folder1\test1.txt','r') 

I get the following error:

 TypeError: an integer is required. 

I am not sure what whole it expects.

Could you let me know how to program to get the result I want. Many thanks for your help.

+4
source share
3 answers

You use open() in the os module, which accepts numeric file mode. Instead, you want to use the built-in open() function. In addition, backslashes in strings take on special meaning in Python; you need to double them if you really mean a backslash. Try:

 fin = open('C:\\folder1\\test1.txt','r') 
+8
source

according to http://docs.python.org/library/os.html#file-descriptor-operations , os.open is looking for a flag parameter made from one or more of these flags that are not “r”. This also indicates that you probably want to learn about using open () rather than os.open ()

+2
source
 f = open(r'C:\folder1\test1.txt','r') 
0
source

All Articles