Python script editing
- or -
Post a project like this2308
$$
- Posted:
- Proposals: 4
- Remote
- #1800290
- Completed
Description
Experience Level: Intermediate
General information for the business: Changing txt files with python
Description of requirements/functionality: Text files with up to 100,000 lines
I have to read a .txt file and remove all lines with a ' 0' at the end of each line
and save all other lines to a new file
This code only works when there are no @ or # so I am sure I am missing something
Example of file
1234423@ 0
4234324@ 0
4234521@ 1
3423423# 2
4342346@ 3
7846278@ 0
9598584# 0
Script below
delete = [' 0']
oldfile=open('c:\\Log Files\\Remove1.txt')
newfile=open('c:\\Log Files\\NewRemove.txt', 'w')
for line in oldfile:
if not any(delete in line for delete in delete):
newfile.write(line)
oldfile.close()
newfile.close()
Extra notes:
Description of requirements/functionality: Text files with up to 100,000 lines
I have to read a .txt file and remove all lines with a ' 0' at the end of each line
and save all other lines to a new file
This code only works when there are no @ or # so I am sure I am missing something
Example of file
1234423@ 0
4234324@ 0
4234521@ 1
3423423# 2
4342346@ 3
7846278@ 0
9598584# 0
Script below
delete = [' 0']
oldfile=open('c:\\Log Files\\Remove1.txt')
newfile=open('c:\\Log Files\\NewRemove.txt', 'w')
for line in oldfile:
if not any(delete in line for delete in delete):
newfile.write(line)
oldfile.close()
newfile.close()
Extra notes:
Leon S.
100% (5)Projects Completed
6
Freelancers worked with
5
Projects awarded
29%
Last project
13 Feb 2019
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies