2017-12-01 1 views
-1

여러 파일 작업 :에 ValueError : 폐쇄 파일에 대한 I/O 작업 - 초급 난 그냥 파이썬 (2.7)을 배우고 다른 파일에 대한 여러 수준의 간단한 텍스트 미로 게임을 만드는 중이라서

try: #this one works perfectly, it runs the file until it quits with quit() 
    execfile("....Lockdown.py") 
except SystemExit: 
    print "Next Level" 

try: #this one doesn't work even though it is almost perfectly identical with Lockdown 
    execfile("....Lockdown2.py") 
except SystemExit: 
    print "Next Level" 

#other levels 

을 실행 내가

Traceback (most recent call last): 
    File LockdownGame.py ... 
    #-> until execfile("....Lockdown2.py") 
    File "...Lockdown2.py", line 708, in available #available is another function 
decide(raw_input("Where do you decide to head? ")) 

ValueError: I/O operation on closed file 

Lockdown2 (그리고 잠금)이이

#the building of the maze 
def available(): #checks where the user can walk 
    #looks through the entire maze to look at where the user is standing, where his back is and if there are walls in that direction 
    #makes sure the user isn't facing 
    print "You can walk %s." % (can_walk[0]) #cutting out how it tells this 
    decide(raw_input("What direction do you decide to head? ")) 

def decide(dec): 
    if dec == "left": #and the other three directions, 
     #edits the maze and their surrounding to their new location 
    else: 
     print "(Write your option as it's written)" 
     decide(raw_input("What direction do you decide to head? ")) 

available() 

처럼 작동 얻을 Lockdown2.py이 raw_input을 넣은 후에 충돌이 발생하지만 Lockdown과 거의 동일한 코드 임에도 불구하고 충돌이 발생하기 전에 또는이 raw_input이 Lockdown에있을 때 오류가 발생하지 않습니다. 두 파일 사이의 변화는 무엇인가 -

+0

를 시작하기 전에 잠금을 닫습니다 (sys.exit을 종료? Lockdown2가 아니라 위의 스크립트에 문제가 있음을 확인하기 위해 Lockdown을 두 번 실행 해 보셨습니까? – roelofs

+0

사실상 기본 코드는 동일하며, 일부 변수 이름과 걸을 수있는 변수가 변경되었습니다. Lockdown을 두 번 실행하면 Lockdown2와 같은 오류가 발생합니다. raw_input이 요청 된 후에 오류가 나타납니다. –

+0

좋아, raw_input이 나타나는 코드를 붙여 넣을 수 있습니까? 우리가 무슨 일이 일어나고 있는지 볼 수 없다면 우리는 디버그를 도울 수 없다 ... – roelofs

답변

0

변경()), 그것은 완전히 당신이 '거의 동일'말할 때 Lockdown2

+0

질문에 관련 코드를 게시 할 수 있습니까? 그렇지 않으면 불완전하며 다른 사람에게별로 도움이되지 않습니다. – roelofs

관련 문제