Variable name generator
This commit is contained in:
parent
36bc145ac3
commit
bd1c3a208c
@ -17,3 +17,26 @@
|
||||
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
|
||||
#
|
||||
# This module splits a query into a program.
|
||||
|
||||
|
||||
def vargen(avoid, prefix=''):
|
||||
'''
|
||||
Generates temp variables.
|
||||
|
||||
Avoid contains variable names to skip.
|
||||
'''
|
||||
count = 0
|
||||
|
||||
while True:
|
||||
r = ''
|
||||
c = count
|
||||
while True:
|
||||
r = chr((c % 26) + 97) + r
|
||||
if c < 26:
|
||||
break
|
||||
c //= 26
|
||||
|
||||
r = prefix + r
|
||||
if r not in avoid:
|
||||
yield r
|
||||
count += 1
|
||||
|
Loading…
Reference in New Issue
Block a user