here's how to read from a file and split the first and second lines.
file = open('newfile.txt', 'r')
available = file.read().split('\r\n')[0]
used = file.read().split('\r\n')[1]
print file.read()
Hope this Helps!
Question
I need to replicate the functioning of Flaskr example (the minimal blog application), but instead of populating the fields of the output with the database contents I am getting those values from a text file in the disk. I am not sure how to read values from a text file and print them, here is the code used to retrieve values from the DB:
{% extends "layout.html" %}
{% block body %}
{% if session.logged_in %}
<form action="{{ url_for('main') }}" method=get,post class=main>
<dl>
<dt>Available:
<dd><input type=text size=15 name=available>
<dt>Used frequency:
<dd><input type=text size=15 name=used>
<dd><input type=submit value=Update>
</dl>
</form>
{% endif %}
<table border="1" style="width:300px">
<ul class=localDB>
<tr>
</ul>
<th></th>
<th>MyValues</th>
<th>maxValue</th>
</tr>
<tr>
<th>Available</th>
<td>{% for entry in localDB %} {{ entry.available }} {% endfor %}</td>
<td>N/A</td>
</tr>
<tr>
<th>Used</th>
<td>{% for entry in localDB %} {{ entry.used }} {% endfor %}</td>
<td>N/A</td>
</tr>
</ul>
</table>
{% endblock %}
Do I have to use other tools like JavaScript or I can use Flask and get the result I want.
Solution
here's how to read from a file and split the first and second lines.
file = open('newfile.txt', 'r')
available = file.read().split('\r\n')[0]
used = file.read().split('\r\n')[1]
print file.read()
Hope this Helps!