Code is printing only the first index item in the list but not the rest
I have this web application that will allow a user to enter a Input id to get information for. For example:
Input: x632
Output would be like:
Comp Unique ID: x123 Label of Page: Apple Name of Comp: Fruit
Comp Unique ID: x456 Label of Page: Water Name of Comp: Environment
Comp Unique ID: x789 Label of Page: Shirt Name of Comp: Clothing
HTML code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="name">
<button type="submit">Submit</button>
</form>
<ol>
</ol>
</body>
</html>
Python Code:
from flask import Flask, request, render_template
import xml.etree.ElementTree as ET
import datetime
import os
import csv
import re
import glob
app = Flask(__name__)
temp_storage = {}
def myFunction(COMP, source="."):
list_output = []
for pathway in glob.glob(os.pathway.join(source,"x*.xml")):
document = temp_storage.setdefault(pathway, ET.parse(pathway).getroot())
theLocationPoint = document.findall('.//*[@Comp="' + COMP + '"]')
if theLocationPoint:
comp_unique_id = document.get("ID")
comp_label = document.tag
comp_name = document.get("Name")
myFunction(comp_unique_id, source=source)
list_output.append("Comp Unique ID: " + comp_unique_id + " " + "Label of Page: " + comp_label + " " + "Name of Comp: " + comp_name)
myFunction(comp_unique_id, source=source)
return list_output
# Creating a route that has both GET and POST request methods
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
name = request.form.get('name')
#calling myFunction
return_string = myFunction(name, source=r"C:/Sam/XMLContentFiles/")
return render_template('my-form.html', result=return_string)
return render_template('my-form.html', result='')
if __name__ == '__main__':
app.run()
Question: The problem I am running into with this code is that this code prints only the first index of the list_output
to the web page.
For example if I input
input: x632
The Output is:
Comp Unique ID: x123 Label of Page: Apple Name of Comp: Fruit
But the output should actually be:
Comp Unique ID: x123 Label of Page: Apple Name of Comp: Fruit
Comp Unique ID: x456 Label of Page: Water Name of Comp: Environment
Comp Unique ID: x789 Label of Page: Shirt Name of Comp: Clothing
Why is the code printing only the first index in the list? Is it not being appended
properly? Is it ignoring the myFunction()
recursive call? I am thinking there is something wrong with these lines of code but I am exactly sure why:
list_output.append("Comp Unique ID: " + comp_unique_id + " " + "Label of Page: " + comp_label + " " + "Name of Comp: " + comp_name)
myFunction(comp_unique_id, source=source)
Comments
Post a Comment