G
G
German Jet2015-01-28 00:05:32
Flask
German Jet, 2015-01-28 00:05:32

How to deserialize a string in Python?

You need to deserialize a string like this in Python

a:16:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"3";i:3;s:1:"4";i:4;s:1:"5";i:5;s:1:"6";i:6;s:1:"8";i:7;s:1:"9";i:8;s:2:"11";i:9;s:2:"12";i:10;s:2:"13";i:11;s:2:"14";i:12;s:2:"15";i:13;s:2:"16";i:14;s:2:"17";i:15;s:2:"18";}

There is a function in PHP unserialize($str)
for Python found pypi.python.org/pypi/phpserialize , but I don't quite understand how to parse the resulting array.
from phpserialize import serialize, unserialize

@widgets.position('user_menu', order=1)
def user_menu():
    ... ... ...
    rights = unserialize(perms)
    return dict(rights=rights)


{% for r in rights %}
    <li>
        {{r}}
    </li>
{% endfor %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rostislav Grigoriev, 2015-01-28
@GeraJet

<ul>
{% for key, value in rights.items %} 
  <li>{{key}} - {{value}}</li>
 {% endfor %}
</ul>

Most likely the output order will always be different.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question