Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I like to use generators for ids. Allow the generator to maintain a list of ids already used.</p> <pre><code># devplayer@gmail.com # 2012-07(jul)-19 class MakeUniqueStr(object): ''' unqstr = MakeUniqueStr(default_name='widget', sep='_') print(repr(unqstr('window'))) print(repr(unqstr('window'))) print(repr(unqstr('window'))) print(repr(unqstr('hello'))) print(repr(unqstr('hello'))) print(repr(unqstr('window'))) print(repr(unqstr('hello'))) 'window' 'window_00000' 'window_00001' 'hello' 'hello_00000' 'window_00002' 'hello_00001' ''' def __init__(self, default_name='default', sep='_'): self.default_name = default_name self.last_base_name = default_name self.sep = sep self.used_names = [] self.generator = self.Generator() self.generator.next() # initialize def __call__(self, name=None): if name &lt;&gt; None: self.last_base_name = name return self.generator.send(self.last_base_name) def _MakeName(self, name, index=1): '''_MakeName is called by the Generator. Generator will always have a name and an index to pass to _MakeName. Over ride this method to customize it.''' return name + self.sep + '%0.5d' % index def Generator(self): try_name = yield 'ready' # initialize index = 0 while 1: if try_name not in self.used_names: self.used_names.append( try_name ) sent_name = yield try_name try_name = sent_name continue try_name = self._MakeName( sent_name, index ) while try_name in self.used_names: index += 1 try_name = self._MakeName( sent_name, index ) index = 0 </code></pre> <p>Although this is not a memory effiecent way for huge in-memory datasets. If you wanted to use something like that then modify this to have the OS handle caching to a file... say via a named pipe.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload