이 방법이 도움이됩니까? : 숫자 문자, 'L'로 시작하지 않아야 객체의 이름으로
dic = { 1:['a','h','uu'] , 3:['zer','rty'] , 4:['hj','125','qsd'] }
print 'BEFORE LOOP :\n\nglobals()==',globals()
print
print "keys of globals() not written __xxx__ :",' , '.join(u for u in globals() if not u.startswith('__'))
print '\n-----------------------------------------------------------------\nDURING LOOP :\n'
for x in dic:
print 'x==',x
globals()['L'+str(x)+'profile'] = dic[x]
print 'keys of globals() not written __xxx__ :',' , '.join(u for u in globals() if not u.startswith('__'))
print '\n-----------------------------------------------------------------\nAFTER LOOP :\n'
print 'keys of globals() not written __xxx__ :',' , '.join(u for u in globals() if not u.startswith('__'))
print
for li in (L1profile,L3profile,L4profile):
print 'li==',li
결과
BEFORE LOOP :
globals()== {'__builtins__': <module '__builtin__' (built-in)>, '__package__': None, '__name__': '__main__', 'dic': {1: ['a', 'h', 'uu'], 3: ['zer', 'rty'], 4: ['hj', '125', 'qsd']}, '__doc__': None}
keys of globals() not written __xxx__ : dic
-----------------------------------------------------------------
DURING LOOP :
x== 1
keys of globals() not written __xxx__ : L1profile , x , dic
x== 3
keys of globals() not written __xxx__ : L1profile , L3profile , x , dic
x== 4
keys of globals() not written __xxx__ : L1profile , L3profile , x , dic , L4profile
-----------------------------------------------------------------
AFTER LOOP :
keys of globals() not written __xxx__ : L1profile , L3profile , x , dic , L4profile
li== ['a', 'h', 'uu']
li== ['zer', 'rty']
li== ['hj', '125', 'qsd']
는 생성 된 이름의 첫 글자로 체계적으로 배치됩니다.
잠깐, 와트? 어떻게 그 아이디어를 얻었습니까? ** 문자열 ** 형식입니다. – delnan
내 대답을 보았습니까? – eyquem