非常にpythonプログラミングの新機能です.3000以上のjsonファイルを含むフォルダを反復するために、次のpythonスクリプトを作成しました。これらの3000で反復する方法はわかりません。 jsonファイルを手動でスクリプトに入れないようにする必要があります。また、特定のパスを置く必要があります。jsonファイルも同様に配置されています。宣言方法はわかりません。Pythonでjsonデータを取得する方法
import json
all_results = {}
json_file_list = ['1.json', '2.json']
for file in json_file_list:
with open(file) as json_file:
json_data = json.load(json_file)
for key, value in json_data.iteritems():
if 'result' in value:
all_results[key] = value['result']
return all_results
後の私のPythonスクリプトを実行して、私は次のエラーがあります: "@ gem_reloc_overflowシングルオーバーフロー@ IGT" 私のjsonsファイル
{ どのように見えるか
File "getResult.py", line 20
return all_results
SyntaxError: 'return' outside function
をし、これは次のとおりです。 { "タイプ": "TestResult"、 "コマンド": "/ home/gfx/intel-graphics/intel-gpu-tools/tests/gem_reloc_overflow --run-subtestシングルオーバーフロー"、"、""err": "dmesg": ""、 ""環境変数 "PIGLIT_PLATFORM = \" mixed_glx_egl \ "PIGLIT_SOURCE_DIR = \"/home/gfx/intel-graphics/intel-gpu-tools/piglit \ "" (gem_reloc_overflow:19562)危険:アサーションの失敗:gem_execbuf(fd、& execbuf)== -14 \ n(gem_reloc_overflow:19562)重要:テストアサーション失敗関数reloc_tests、ファイルgem_reloc_overflow.c:260:\ n (gem_reloc_overflow:19562)CRITICAL:エラー:-22!= -14 \ nSubtestシングルオーバーフローに失敗しました。\ n **** DEBUG **** \ n(gem_reloc_overflow:19562)DEBUG:再配置カウント= 4294967295 \ n(gem_reloc_overflow:19562)CRITICAL :テストアサーション失敗関数reloc_tests、ファイルgem_reloc_overflow.c:260:\ n(gem_reloc_overflow:19562)CRITICAL:失敗したアサーション:__gem_execbuf(fd、& execbuf)== -14 \ n(gem_reloc_overflow:19562)CRITICAL:エラー:-22 != -14 \ n **** END **** \ n "、(Linux:4.6.0-rc4-drm-intel-nightly-ww17-commit-1e81bac + x86_64)\ nStack trace:\ IGNT-version:1.14-g1e9a3ac(x86_64) \ nSubtestシングルオーバーフロー:FAIL(8.469s)\ n "、 " pid ":19562、 "結果#1 [reloc_tests + 0x6d6] \ n#2 [+ 0x6d6] ": ""、 "失敗リターンコード":99、 "サブテスト":{ " __type ": "サブテスト" }、 "時間":{ " タイプ ": "TimeAttribute"、 " 「終了」:1462072402.5360818, 「開始」:1462072393.7328644 }、 「トレースバック」:ヌル }}
任意のヘルプは大歓迎です、ありがとう
感謝を使用し、JSONファイル名を持っていますが、このコマンドでいったん:onlyfiles = [LISTDIRでF(mypathで)ISFILEあれば(F)、(mypathで参加する)ためのF]、私は持っていますjsonのファイル名、そしてpythonが私にそれがファイルを見つけることができないことを示すので、私は名前の完全なパスが必要です – shaveax