2013-11-28 1 views
0

나는 운동 17에서 일하고 있는데, 달리기가 불가능한 것 같습니다.learnpythonthehardway exercise 17 not working

나는 python test.py raw.txt copied.txt처럼 실행되지만이 오류가 나타납니다

Copying from raw.txt to copied.txt 
Traceback (most recent call last): 
    File "test.py", line 9, in <module> 
    in_file = open(from_file) 
IOError: [Errno 2] No such file or directory: 'raw.txt' 

내 코드 : 이제 모든 파일을 :을 os.path 수입에서 SYS 수입 ARGV 에서 이

script, from_file, to_file = argv 

print "Copying from %s to %s" % (from_file, to_file) 

# we could do these two on one line too, how? 
in_file = open(from_file) 
indata = in_file.read() 

print "The input file is %d bytes long" % len(indata) 

print "Does the output file exist? %r" % exists(to_file) 
print "Ready, hit RETURN to continue, CTRL-C to abort." 
raw_input() 

out_file = open(to_file, 'w') 
out_file.write(indata) 

print "Alright, all done." 

out_file.close() 
in_file.close() 
+2

트레이스 백은 텍스트입니다. 여기에 복사하여 붙여 넣을 수 있습니다. –

+3

은'python' 디렉토리에서'raw.txt'입니까? –

답변

0

이 시도 존재를 작업 디렉토리에서 검색 중입니다.

from sys import argv 
from os import getcwd 
from os.path import exists, join 

cwd = getcwd() 
script, from_file, to_file = argv 

print "Copying from %s to %s" % (from_file, to_file) 

# we could do these two on one line too, how? 
in_file = open(join(cwd, from_file)) 
indata = in_file.read() 

print "The input file is %d bytes long" % len(indata) 

print "Does the output file exist? %r" % exists(join(cwd, to_file)) 
print "Ready, hit RETURN to continue, CTRL-C to abort." 
raw_input() 

out_file = open(join(cwd, to_file), 'w') 
out_file.write(indata) 

print "Alright, all done." 

out_file.close() 
in_file.close() 
+0

'PS C : \ Users \ Schneeder> cd 파이썬 PS C : \ Users \ Schneeder \ python> 파이썬 test.py raw.txt copied.txt raw.txt에서 copied.txt로 복사 트레이스 백) : 파일 "test.py", 줄 11, in_file = open (join (cwd, from_file)) IOError : [Errno 2] 해당 파일이나 디렉터리가 없습니다. 'C : \\ Users \\ Schneeder \ \ python \\ raw.txt ' PS C : \ Users \ Schneeder \ python>' – user3047058

+0

@ user3047058 정말 그 디렉토리에 파일이 있습니까? 확인해주십시오. – akaRem