Python Forum
TypeError: file must have 'read' and 'readline' attributes
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: file must have 'read' and 'readline' attributes
#3
(Jun-12-2020, 09:01 AM)DreamingInsanity Wrote: What it looks like you are trying to do is 'open' a directory to get all the images, so you can use them elsewhere.
I would recommend the glob module for that.
import glob

def open_train_data():
    return glob.glob('/home/mojito/Desktop/CNN/datasets/training_data/images/*') #the '*' is a 'wildcard' and it means to match one or more characters
 
for f in open_train_data():
   dict1 = pickle.load(f)
   ###do whatever else you need to

I ran the code you posted. I got this error:

Using TensorFlow backend.
Traceback (most recent call last):
  File "source_code_modified.py", line 78, in <module>
    dict1 = pickle.load(f)
TypeError: file must have 'read' and 'readline' attributes
It explodes at this point:

dict1 = pickle.load(f)
Reply


Messages In This Thread
RE: TypeError: file must have 'read' and 'readline' attributes - by hobbyist - Jun-12-2020, 10:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 255 May-03-2024, 07:23 AM
Last Post: Pedroski55
  Recommended way to read/create PDF file? Winfried 3 2,960 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,585 Nov-09-2023, 10:56 AM
Last Post: mg24
  read file txt on my pc to telegram bot api Tupa 0 1,166 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,162 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,397 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 7,140 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Pyserial Readline() conversion to array bprosman 1 1,963 Apr-11-2023, 12:44 AM
Last Post: deanhystad
  Read csv file with inconsistent delimiter gracenz 2 1,246 Mar-27-2023, 08:59 PM
Last Post: deanhystad
  Greek letters with .readline() and tkinter KinkgOfKeks 7 1,820 Mar-24-2023, 05:13 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020