简体   繁体   中英

When I import fileinput module, use the input method , it report AttributeError: 'module' object has no attribute 'input'

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM