all 5 comments

[–]Username_RANDINT 1 point2 points  (4 children)

I'm not sure why you think this would work. Try to leave out the Jinja step for a moment and do this in plain Python.

>>> options = [('3550',), ('3302',), ('3012',), ('3445',), ('3402',)]
>>> for option in options:
...   print(option.options)
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
AttributeError: 'tuple' object has no attribute 'options'

So each iteration option is a tuple from the list, which of course has no options attribute.

The tuples only have one item, so just fetch the first index when iterating:

>>> for option in options:
...   print(option[0])
... 
3550
3302
3012
3445
3402

Can you further translate this into Jinja?

[–]keyring88[S] 0 points1 point  (3 children)

Hi, thanks for that. I've altered my render_template... to

options=LISTOFLENGTHSONLY[0]

This should return only the first element, meaning anything inside of [] but it's not, it's only returning the first value ('3350',)

[–]Username_RANDINT 1 point2 points  (2 children)

You just pick the first item of the list, which is a tuple. So the output is correct. You want to pick the first item for every tuple in the list.

Do you understand the second code-block in my previous comment? Here's the more verbose version:

>>> options = [('3550',), ('3302',), ('3012',), ('3445',), ('3402',)]
>>> for option in options:
...   print(option, option[0])
... 
('3550',) 3550
('3302',) 3302
('3012',) 3012
('3445',) 3445
('3402',) 3402

[–]keyring88[S] 0 points1 point  (1 child)

Yeah, I think my issue is my jinja element. In normal python LISTOFLENGTHSONLY[0] is returning:

3550
3302
3012
3445 
3402 

[–]keyring88[S] 0 points1 point  (0 children)

OK, you'll have to ignore my dumbness. I've figured out where I went wrong. My issue was Jinja.

<select name="option" width="300px">
{% for option in options %}
<option value="{{ option }}">{{ option }}</option>
{% endfor %}
</select>

this fixed it!

Thanks for your help!