Answer the question
In order to leave comments, you need to log in
How to remove a character at the end of a line?
Good day!
There is a file with the following structure:
__NV__: 1
name: "name"
short_name: "name"
line1: 0
line2: "#updated 20/9/21,\n4845905????,\n4845956????,\n# magaz,\n4872710????,\n#nano,\n4872717????"
line3: "00000*"
line4: 0
line5: ""
line6: 1
line7: 0
line8: ""
line9: 0
The script itself, which parses the file below:
#!/usr/bin/python3
import os
os.system(r' >info_ran')
prefix = '#'
for filename in os.listdir("/home/user/ran_info/ran-09"):
file1 = open("/home/user/ran_info/ran-09/" + filename, "r")
lines = file1.readlines()
for line in lines:
if "name:" in line and "short_name" not in line:
with open('info_ran, mode='a+') as f:
f.write(line + '\n')
if "line2:" in line:
for i in line.split("\\n"):
if "line2" not in i:
if not i.startswith(prefix):
with open('info_ran', mode='a+') as f:
f.write(i + '\n')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question