Home Separate the values in dictionary into two column. Python and Django
Reply: 1

Separate the values in dictionary into two column. Python and Django

lo ki
1#
lo ki Published in 2017-09-14 08:49:07Z

I've a program which will read data from text file.

There are 3 types of data that I need to read from text file.

  1. visual id
  2. time
  3. tname_pb

Problem

I have 3 columns and need to separate output into different columns.

But, visual id is working perfectly, but time and tname_pb are combined together.

Question

How can I separate time and tname_pb into two different column.

Current views.py based on the picture

with open(path) as input_data:

for line in input_data:
    if line.startswith('2_visualid_'):
        visual_key = line.lstrip('2_visualid_').rstrip()
        data.update({visual_key: []})


    if 'time' in tokens:
        if search_time in line and visual_key in data:
            data[visual_key].append(next(input_data).lstrip('2_mrslt_').rstrip())


    if 'tname_pb' in tokens:
        if tname_pb in line and visual_key in data:
            data[visual_key].append(next(input_data).lstrip('2_mrslt_').rstrip())

Current template based on the picture

<div class="input-group" align="center" style=" left:10px; top:-110px; width:99%">
    <table class="table table-bordered">

        <thead class="success" >

        <tr>

            <th class="success">
                <b>Visual ID</b>
            </th>

            <th class="success">

            <b>Time Delay Index</b>

            </th>

            <th class="success">

            <b>Tname PB</b>

            </th>

        </tr>



        {% for key, values in output.items %}

        <tr class="">
            <td rowspan={{ values|length|add:1 }}><b>{{ key }}</b></td>

            {% for value in values %}

            <tr class="">
            <td ><b>{{value}}</b></td>
            </tr>

            {% endfor %}

            </tr>

        {% endfor %}

        </thead>

    </table>
</div>

NOTE

I have tried few examples from Google, but I get errors with them.

I will post them here if they help clarify my question. I left them out because I don't want my question to be confusing.

Oluwafemi Sule
2#
Oluwafemi Sule Reply to 2017-09-26 10:22:19Z

You have a new table row going on here for each value.

{% for value in values %}
    <tr class="">
       <td><b>{{value}}</b></td>
    </tr>
{% endfor %}

Instead of this, you need to make a new table cell for each value.

    <table class="table table-bordered">

        <thead class="success">
            <tr>

                <th class="success">
                    Visual ID
                </th>

                <th class="success">
                    Time Delay Index
                </th>

                <th class="success">
                    Tname PB
                </th>

            </tr>
        </thead>

        <tbody>

        {% for key, values in output.items %}
            <tr class="">
                <td><b>{{ key }}</b></td>

                {% for value in values %}
                    <td><b>{{ value }}</b></td>
                {% endfor %}
            </tr>
        {% endfor %}

        </tbody>

    </table>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300767 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO