Making a dynamic variable set
<p>I'm trying to put together a tool that has a notion of 'level'. 
Each 'level' has a set of variables that are needed to support the activity I want to achieve that are specific to each level. </p>

<p>I have written a hard-coded version that works (to a degree) but it is limited to the number of levels I have hard-coded. It strikes me that there must be a slicker way of writing this func so can generate the level vars on the fly:</p>

<pre><code>def levelVarsGetter(level):
    if level == 1:
        levelDict = {'URLRegEx':baseDict['L1Regex'], 'titleRegEx':baseDict['L1TitleRegex'], 'buildPortion':baseDict['L1buildPortion'], 'levelParser':'level_1'}
    elif level ==2:
        levelDict = {'URLRegEx':baseDict['L2Regex'], 'titleRegEx':baseDict['L2TitleRegex'], 'buildPortion':baseDict['L2buildPortion'], 'levelParser':'level_2'}
    elif level ==3:
        levelDict = {'URLRegEx':baseDict['L3Regex'], 'titleRegEx':baseDict['L3TitleRegex'], 'buildPortion':baseDict['L3buildPortion'], 'levelParser':'level_3'}
    elif level ==4:
        levelDict = {'URLRegEx':baseDict['L4Regex'], 'titleRegEx':baseDict['L4TitleRegex'], 'buildPortion':baseDict['L4buildPortion'], 'levelParser':'level_4'}
    elif level ==5:
        levelDict = {'URLRegEx':baseDict['L5Regex'], 'titleRegEx':baseDict['L5TitleRegex'], 'buildPortion':baseDict['L5buildPortion'], 'levelParser':'level_5'}
    return levelDict 
</code></pre>

<p>All the vars in the dict are manually entered in an initialisation func. There labels can be changed if required. </p>

<p>for context, the referring code: </p>

<pre><code>for x in xrange (1, baseDict['numberOfLevels']+1):
    links=[]
    levelDict= levelVarsGetter(x)
    URLRegEx = levelDict['URLRegEx'] 
    titleRegEx = levelDict['titleRegEx']
    buildPortion = levelDict['buildPortion']
    level = levelDict['levelParser'] 
    go = siteParser()
</code></pre>
