作者: Bruce.
日時: 2006/9/04(00:34)
Bruce.です。

藤岡和夫 さんは書きました (2006/09/04 0:13):
>>  これでも動きますが、fileとゆー名前は一応組み
>> 込み関数(いやタイプジェネレータだっけ?)なん
>> で、ちょっとだけ改造
> 
>  この場合、エラーにならないのは代入文だからじゃないでしようか。コンテキ
> スト的に関数ではありえないですから。「初めてのPython」から引っ張ってきた
> コードなのですね(初版、105ページ、^^)

fileがオブジェクトだから代入してもエラーにならないのですが、
実体はしっかりすりかわってます。
Pythonではふつーの関数もまたオブジェクトですので。


ython 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on
win32
ype "help", "copyright", "credits" or "license" for more information.
>> dir(file)
'__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__',
'__init_
', '__iter__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr
_', '__str__', 'close', 'closed', 'encoding', 'fileno', 'flush',
'isatty', 'mod
', 'name', 'newlines', 'next', 'read', 'readinto', 'readline',
'readlines', 'se
k', 'softspace', 'tell', 'truncate', 'write', 'writelines', 'xreadlines']
>> type(file)
type 'type'>
>> file = open('hoge.txt', 'r')
>> type(file)
type 'file'>

type(file) の結果が変わっているのに注目してください。

-- 
木村浩一
  I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
  mail kbk@...
	web  www.kt.rim.or.jp/~kbk/index.html#zakkicho
	     homepage3.nifty.com/farstar/