-1

I have list

[4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 21, 22, 24, 25, 36, 39, 40, 43, 45, 46, 48, 49, 55, 57, 58, 60, 61, 64, 68, 71, 72, 74, 75, 77, 78, 80, 81, 82, 84, 86, 87, 89, 90, 92, 93, 95, 96, 98, 99, 101, 102, 104, 105, 107, 108, 110, 112, 113, 115, 116, 118, 122, 125, 127, 128, 130, 131, 133, 134, 136, 137, 139, 140]

I have tried with pickle

with open('m1.dat', 'wb') as f:
    pickle.dump(matches1, f)

but got characters like this

(lp0
I4
aI5
aI7
aI8
aI10
aI11
aI13
aI14
aI16
aI17
aI19
aI21
aI22
aI24
milenko
  • 31
  • 1
  • 10
  • 1
    What is your expectation, because that is exactly what the expectation is when using pickle. If you are looking to actually store the list AS is then you don't want to use pickle. Furthermore, if you try reading that pickle file, you will get your list back. Please clarify what it is you are trying to do – idjaw Mar 08 '16 at 15:36
  • Looks like pickled integers written to a file. What do you want? Like plain text numbers? Then don't pickle them, just write them normally. Please show us, what you expect. – kratenko Mar 08 '16 at 15:37
  • @kratenko Yes,like plain numbers. – milenko Mar 08 '16 at 15:40
  • 2
    @milenko So then why are you using pickle? Do you know what that does? – Morgan Thrapp Mar 08 '16 at 15:41

1 Answers1

1

Use json module :

import json
var = [1,4,5]
with open("file_path","w") as wfile:
     json.dump(var,wfile)