Задать вопрос

Тел: +7 965 3737 888

459

Просмотров

1

Ответов

Counter model - run multiple persistent counters

<p>Sometimes you just need to count things (or create unique-for-your-application IDs). This model class allows you to run as many persistent counters as you like. Basic usage looks like this:</p>
&gt;&gt;&gt; Counter.next()
0
&gt;&gt;&gt; Counter.next()
1L
&gt;&gt;&gt; Counter.next()
2L

<p>That uses the "default" counter. If you want to create and use a different counter, pass its name as a string as the parameter to the method:</p>
&gt;&gt;&gt; Counter.next('hello')
0
&gt;&gt;&gt; Counter.next('hey')
0
&gt;&gt;&gt; Counter.next('hello')
1L
&gt;&gt;&gt; Counter.next('hey')
1L
&gt;&gt;&gt; Counter.next('hey')
2L

<p>You can also get the value as hex (if you want slightly shorter IDs, for use in URLs for example):</p>
&gt;&gt;&gt; Counter.next_hex('some-counter-that-is-quite-high')
40e

Вопрос полезен? Да0/Нет0
file_2772.py(901.0б)
None

Ответы (1):

Ответjdarknet:13.01.2011
Ответ полезен? Да0/Нет0

Excelents, congratulations