Skip to content
Advertisement

AttributeError: ‘FileInput’ object has no attribute ‘read’

This is my code

import fileinput
import json

with fileinput.input(files=('bot_details.json')) as f:
    my_load = json.load(f)
    TOKEN=my_load["TOKEN"]

I’m getting this error, AttributeError: 'FileInput' object has no attribute 'read'

Advertisement

Answer

For a single file use open

with open('bot_details.json') as f:
    my_load = json.load(f)
    TOKEN=my_load["TOKEN"]
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement