I am creating a Flask website and I want to save text input from the textarea and save that text into a txt file. Everything works good but the problem is the text saved like there is an empty line after each line. I don't want this empty line. I want normal text, like no empty line after each line. Here is my code:
this is app.py
@app.route('/textCreate', methods=['GET','POST'])
@login_required
def textCreate():
print("Inside TExt Create")
textData = Textfile.query.all()
with open('training_data/training.txt', 'w') as fh:
for line in textData:
fh.write(line.text)
return redirect(url_for('admin'))
this is my text.html
<tbody>
{% for row in files %}
<tr>
<td>{{ row.id }}</td>
<td> </td>
<td>{{ row.text }}</td>
<td><a href="edit_script/{{row.id}}" class="btn btn-default pull-right">Edit this Question</a></td>
<td><a href="delete_question/{{row.id}}" class="btn btn-default btn-danger pull-right"> Delete this Question</a></td>
</tr>
{% endfor %}
</tbody>
and this is my text input which I input it in the text area.
What is a coronavirus? Coronaviruses are a large family of viruses that are known to cause illness ranging from the common cold to more severe diseases such as Middle East Respiratory Syndrome (MERS) and Severe Acute Respiratory Syndrome (SARS). What is a novel coronavirus? A novel coronavirus (CoV) is a new strain of coronavirus that has not been previously identified in humans. Can humans become infected with a novel coronavirus of animal source? Detailed investigations found that SARS-CoV was transmitted from civet cats to humans in China in 2002 and MERS-CoV from dromedary camels to humans in Saudi Arabia in 2012. Several known coronaviruses are circulating in animals that have not yet infected humans. As surveillance improves around the world, more coronaviruses are likely to be identified.
and this is the output with the separated lines... I mean the space/empty line which is created after every line.
What is a coronavirus?
Coronaviruses are a large family of viruses that are known to cause illness ranging from the common cold to more severe diseases such as Middle East Respiratory Syndrome (MERS) and Severe Acute Respiratory Syndrome (SARS).
What is a novel coronavirus?
A novel coronavirus (CoV) is a new strain of coronavirus that has not been previously identified in humans.
Can humans become infected with a novel coronavirus of animal source?
Detailed investigations found that SARS-CoV was transmitted from civet cats to humans in China in 2002 and MERS-CoV from dromedary camels to humans in Saudi Arabia in 2012. Several known coronaviruses are circulating in animals that have not yet infected humans. As surveillance improves around the world, more coronaviruses are likely to be identified.
I don't want these empty lines. How to remove these empty lines.