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
#5
(Jun-12-2020, 10:20 AM)DreamingInsanity Wrote: Sorry, my mistake - it should work if you do this:
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(open(f, 'rb'))
   ###do whatever else you need to
I forgot to open the file.

I am getting this error:

Using TensorFlow backend.
Traceback (most recent call last):
  File "source_code_modified.py", line 80, in <module>
    dict1 = pickle.load(open(f, 'rb'))
_pickle.UnpicklingError: A load persistent id instruction was encountered,
but no persistent_load function was specified.
I am trying to solve it though, but I thought posting it for more help. Thank you...
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 254 May-03-2024, 07:23 AM
Last Post: Pedroski55
  Recommended way to read/create PDF file? Winfried 3 2,959 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,583 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,130 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