0

The version of python is 2.7.13.

The content of 3.txt is:

this is a river

that is a cloud

the world is beatiful

I write a python script:

import fileinput

def process(string):
    print 'Processing: ', string

for line in fileinput.input(r'E:\Python\3.txt'):
    process(line)

When I run this script , it report error:

====================== RESTART: E:\Python\fileinput.py ======================

Traceback (most recent call last):

  File "E:\Python\fileinput.py", line 1, in <module>

  import fileinput

  File "E:\Python\fileinput.py", line 7, in <module>

  for line in fileinput.input(r'E:\Python\3.txt'):

AttributeError: 'module' object has no attribute 'input'

--------------------------------------------------------------------------------

What is the reason cause this problem ?

How can I slove this problem ?

0

1 Answer 1

3

Don’t name your script “fileinput.py”. It conflicts with the library module of the same name.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.