2012-01-11 3 views
2

의 포인터를 얻기, 나는 다음과 같은 한 :내 스크립트에서 대신 문자열

file = '%s/data.txt' % (theDirectory) 
text = open(file) 
theString = text.read 
print 'Hello, %s' % (theString) 

는 반환이 :

이 원인을 무엇
Hello, <built-in method read of file object at 0x100534a48> 

?

+0

디렉토리 분리 기호를 명시 적으로 추가하는 대신 os.path.join을 사용해야합니다 (교차 플랫폼이 더 많음). – James

답변

6

당신은 전화 방법을 사용하여 괄호 필요 : 괄호없이

theString = text.read() 

, 파이썬은 (그 시점에서, 모든 문자열이 아닌) theString의 방법 자체에 대한 참조를 할당 .

1

당신은 함께

theString = text.read 

교체해야 : text.read가 함수 인

theString = text.read() 

때문에, 또는 더 나은 기능과 문자열을 돌려 <built-in method read of file object at xxx>,
대신 text.read() 전화입니다.

관련 문제