2017-09-11 4 views
0

나는만큼 XXX를 표시하는 숫자 세트의 세트를 포맷하려고, XXX, XXX 대신포맷 로케일

값으로하는 사전을 통해 포맷터 반복 xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxx의 파이썬에서 목록. 이것은 내가 가지고있는 잘못된 코딩이

{'ST': [Decimal('21529992.247811'), 
Decimal('75922363.959394'), Decimal('1.688401841437798245794341100')], 
'LQT': [Decimal('23034058.811000'), Decimal('45706418.420000'), 
Decimal('0.243186493430996726476558100')], 'SR': 
[Decimal('8389288.802664'), Decimal('0393135.373964'), 
Decimal('-2.146515189191049793306943120')], 'MIS7': 
[Decimal('6382868.080000'), Decimal('5336228.320000'), 
Decimal('-4.879627090905261579809913330')], 'LQ': 
[Decimal('98508613.709000'), Decimal('38822011.125000'), 
Decimal('-3.983067033313078110002846960')] } 

:

처럼 보이는 것입니다

import locale 
    locale.setlocale(locale.LC_ALL, '') 
    for k in result.keys(): 
     if result[k] == result[k]: 
      result[k] = locale.format('%d', result[k], grouping = True) 
    if len(result) == 0: 
     result["None"] = "None" 

내 오류 문자열은 긴하지만,이 메인 비트 같습니다

TypeError: %d format: a number is required, not list 

무엇을해야합니까?

import locale 
    locale.setlocale(locale.LC_ALL, '') 
    for r in result: 
     for k in result[r]: 
      print locale.format('%2f', k, grouping = True) # Note there is not result[k]. Use your preferred number format instead of '%2f' 

을 여기에 출력이 '%2f'을 사용하고 있습니다 : 당신에게 왜 단순히

답변

0

감사

23.034.058,811000 
45.706.418,420000 
0,243186 
8.389.288,802664 
393.135,373964 
-2,146515 
6.382.868,080000 
5.336.228,320000 
-4,879627 
98.508.613,709000 
38.822.011,125000 
-3,983067 
21.529.992,247811 
75.922.363,959394 
1,688402 
+0

그것을 시도! 여기에 내 오류가 있습니다 : "TypeError : % d 형식 : str이 아닌 숫자가 필요합니다." – ifthenifthen

+0

잘 작동합니다. 내 코드의 변경 사항에 유의하십시오. 추신 :'결과'는 귀하의'dict'입니다. 물론 – floatingpurr

+0

@ifthenifthen이 작동하는지 알려주십시오.) – floatingpurr