0
import sys
sys.path.append("C:/Users/peter/ud1200/ud120-projects/tools/")
sys.path.append('C:/Users/peter/ud1200/ud120-projects/choose_your_own')
sys.path.append('C:/Users/peter/ud1200/ud120-projects/datasets_questions')

import os
os.chdir('C:/Users/peter/ud1200/ud120-projects/datasets_questions')


import pickle

I tried also this solution

original = "C:/Users/peter/ud1200/ud120-projects/final_project/final_project_dataset.pkl"
destination = "C:/Users/peter/ud1200/ud120-projects/final_projec/final_project_dataset_unix.pkl"
content = ''
outsize = 0
with open(original, 'rb') as infile:
    content = infile.read()
with open(destination, 'wb') as output:
    for line in content.splitlines():
      outsize += len(line) + 1
      output.write(line + str.encode('\n'))

print("Done. Saved %s bytes." % (len(content)-outsize))

enron_data = pickle.load(open("C:/Users/peter/ud1200/ud120-projects/final_project/final_project_dataset.pkl", "rb"))

When i used this reference destination file reads there's 81 people in Enron dataset

There's another reference i used This solution

 enron_data = pickle.load(open("../final_project/final_project_dataset.pkl", "r"))
 print ('Number of people in the Enron dataset: {0}'.format(len(enron_data)))

But this solution produces the TypeError: a bytes-like object is required, not 'str' although the original solution found the right number of mails

print ('Number of people in the Enron dataset: {0}'.format(len(destination)))

Any help!!!

azro
  • 53,056
  • 7
  • 34
  • 70
Peter
  • 41
  • 6
  • Why are you assuming a binary file has lines in the first place? – chepner Aug 02 '21 at 16:56
  • Opening a file with `rb` will make `read()` return a byte array instead of a string. If the file is plain text use just `r`, if not, use `content = b''`, but I still don't think you'll find lines there (you could try `content.split(b'\n')` tough. For the `pickle.load` error, try opening the file with `rb`. – ichramm Aug 02 '21 at 16:57
  • I tried it but it also doesn't work !!!! – Peter Aug 03 '21 at 09:03

0 Answers0