I need to delete numbers from a text file on windows XP. I am new to python and just installed it for data scrubbing.
I have stored the test file in C:\folder1\test1.txt
The contexts on test1.txt is just 1 line:
This must not b3 delet3d, but the number at the end yes 134411
I want to created a file result1.txt which contains
This must not b3 delet3d, but the number at the end yes
Here is what I 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 integer it is expecting.
Can you please let me know how to go about programming to get the result I want. Thanks a lot for your help.
You're using open()
in the os
module, which takes a numeric file mode. You want instead the builtin open()
function. Also, backslashes in strings take on a special meaning in Python; you need to double them up if you really mean backslashes. Try:
fin = open('C:\\folder1\\test1.txt','r')
according to http://docs.python.org/library/os.html#file-descriptor-operations, os.open is looking for 'flag' parameter, made of one or more of these flags which 'r' is not. It also seems to indicate that you probably want to look into using open() rather than os.open()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With