2016-07-25 7 views
0

私はかなり私がmystuff filefolderでex15_sample.txtを得たと確信しています!ここでなぜPowerShellでpython上のファイルを開いて読むことができないのですか?

は、私が遭遇したエラーです: the powershell

IOError: [Errno 2] No such file or directory: 'ex15_sample.txt' 

私のコードです

from sys import argv 

script, filename = argv 

txt = open(filename)  
print "Here's your file %r:" % filename 
print txt.read()      
print "Type the filename again:" 
file_again = raw_input("> ")   

txt_again = open(file_again)   

print txt_again.read()   ` 
+0

を使用することができ、あなたはどのようなエラー/秒に遭遇したのですか? – shiva

+0

'python.exe'は別の作業ディレクトリで始まるかもしれません。 'os.getcwd()'の出力は何ですか? –

+0

dirコマンドの出力は何ですか? – YOU

答えて

0

あなたはこの

import os 
    __location__ = os.path.realpath(
    os.path.join(os.getcwd(), os.path.dirname(__file__))) 

    file_name = raw_input("type the file name") 
    txt = open(os.path.join(__location__, filename)) 
    print txt.read() 
関連する問題