1

Possible Duplicate:
How can I use a string with the same name of an object in Python to access the object itself?

I'm trying to change name to a variable depending on the result of a match...

inds_EUR = [whatever]
inds_AFR = [foo]
inds_ASN = [other]

pop=inds_EUR ##imagine this is the case
for pp in ('EUR', 'AFR', 'ASN'):
    if pp in pop:
    paap='inds_'+str(pp)        
    break
foos=eval(paap)

What I'm tryin, is to set "foos" as the list to pass to this expression

matches = [item for item in inds_vcf if item in foos]

It works, but don't know if it dangerous to use this eval() expression, here as it could be if using vars() Am I doing it the right way?

Thanks in advance,

peixe

Community
  • 1
  • 1
peixe
  • 1,272
  • 3
  • 14
  • 31

1 Answers1

7

Use a dictionary:

inds = {'EUR': [whatever],
        'AFR': [foo],
        'ASN': [other]}

foos = inds['EUR']
eumiro
  • 207,213
  • 34
  • 299
  • 261