[Tutor] fileinput

Remco Gerlich scarblac@pino.selwerd.nl
Sun, 23 Jul 2000 02:29:40 +0200


On Sun, Jul 23, 2000 at 09:11:51AM +0900, David Jansen wrote:
> I wanted to try out this idiom I came across in comp.lang.python but I am
> getting an attribute error...
> 
> 
> import fileinput
> 
> for line in fileinput.input('d:\python\test.txt'):
>     print line

This isn't the error described, but you should be aware that \ has a special
meaning in Python strings. Use \\ instead, or / (Windows accepts paths with
slashes too).
 
> Traceback (innermost last):
>   File "C:\Program Files\Python\Pythonwin\pywin\framework\scriptutils.py",
> line 310, in RunScript
>     exec codeObject in __main__.__dict__
>   File "D:\Python\fileInput.py", line 3, in ?
>     for line in fileinput.input("D:\Python\test.txt"):
> AttributeError: input
> 
> I checked the documentation and the above is typical usage...

Unlucky. You called your module "fileInput.py". Since Windows files aren't
case sensitive, that's the same as "fileinput.py". Python imported your
module instead of the standard, and your module has no input function.
(I think this is what happened; test with a input() function in your code).

Otherwise, you must have assigned to fileinput after the import. Fileinput
has an attribute called "input", after all.

-- 
Remco Gerlich,  scarblac@pino.selwerd.nl