2014-11-11 2 views
0

저는 파이썬 초보자이며 온라인 자습서를 통해 학습하고 있습니다. Study Drill # 6에서 예를 들어 15 on this page, 내가 만든 'ex15_sample.txt '파일을 열려고합니다.Powershell에서 명령어 실행하기

: 나에게 오류가 발생했습니다하는, 명령 프롬프트에서

Start 'python' to start the Python shell, and use 'open' from the prompt just like in this program. Notice how you can open files and run 'read' on them from within 'python'?

, 나는 파이썬 쉘을 시작하는 python를 입력하고 다음에 입력을 시도 :

이것은을 말하는 것입니다 open(ex15_sample.txt)

내가 오류는 다음과 같습니다

Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'ex15_sample' is not defined

ex15_sample.txt은 같은 폴더에있는 파일입니다. 프롬프트에서 open 또는 다른 명령을 어떻게 사용합니까? 나는 Powershell에서 파이썬 2.7.8을 실행 중이다.

답변

1

open의 첫 번째 인수는 파일 이름이 포함 된 문자열입니다. Quotation Mark에서

그냥 넣어 파일 이름 :

f = open('ex15_sample.txt') 
+0

좋아, 나는 그것을했고, 그것은 안 열려 그러나 그것은 나에게이 던진'0x0000000001F54150에서 <열린 파일 'ex15_sample.txt'모드 'R'을 > ' – J82

+0

은 파일이 열려 있음을 의미하므로 변수와 함께 사용할 수 있습니다. 이 [link] (https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files)를 읽어보십시오. 내 편집을 확인하십시오. –

관련 문제