2017-12-20 6 views
0
dir_path = os.path.dirname(os.path.realpath(__file__)) 
from os.path import isfile, join 
onlyfiles = [f for f in listdir(dir_path) if isfile(join(dir_path, f))] 

print(onlyfiles); 

with open("config.json", 'r') as jsondata: 
    config = json.loads(jsondata.read()) 

をdoesntの言う、何とか、ここでファイルがなく、開く存在することは、このコードを実行する

print(onlyfiles); 

中にリストされたファイルにもかかわらず、非既存のエラーをトリガすることは、コンソールからフル出力ログです。

Traceback (most recent call last): 
['builder.py', 'builder.spec', 'builderloader2.rb', 'config.json', 
'Run.bat', 'Run.bat.lnk', 'test.json'] 

    File "C:/Users/cody.jones/Desktop/Builder Generator Release/builder.py", 
line 26, in <module> 
    with open("config.json", 'r') as jsondata: 

FileNotFoundError: [Errno 2] No such file or directory: 'config.json' 

Process finished with exit code 1 
+0

[File Not Found Error in Python]の可能な複製(https://stackoverflow.com/questions/17658856/file-not-found-error-in-python) – tripleee

答えて

1

は(オープン)の代わりに、それは同じディレクトリ内のファイルを検索しますデフォルトでは、として名前だけをファイルへの完全なパスを提供

試してみてください。

open(r"C:/Users/cody.jones/Desktop/Builder Generator Release/config.json", "r") 
+0

私はこれをやりすぎたようでした。 – Cody

+0

@codyはうれしい –

-1

スクリプトがでconfig.json探します現在の作業ディレクトリ - 。おそらく、スクリプトが常駐フォルダと同じではありません

あなたがALRをしたパスを含めるように開いているコールを更新eadyが生成されました。このようにそれをやって(だけではなく、絶対パスを含む)あなたは長い間、あなたが一緒にスクリプトや設定を維持するよう、別のディレクトリまたはコンピュータに移動する場合、このスクリプトはまだ動作しますことで

with open(os.path.join(dir_path, "config.json"), 'r')) as jsondata: 

関連する問題