From bd1c3a208c7a4a26eeadd1b144b4702afa7631c2 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Mon, 15 Aug 2016 09:16:22 +0200 Subject: [PATCH] Variable name generator --- relational/querysplit.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/relational/querysplit.py b/relational/querysplit.py index 72cfa58..a80d07a 100644 --- a/relational/querysplit.py +++ b/relational/querysplit.py @@ -17,3 +17,26 @@ # author Salvo "LtWorf" Tomaselli # # 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