title: How can I write a string to binary file using Python3?
body: <p>I would like to write strings to a bin file as header.
  However, I can only write type 'bytes' to the binary file.
  Here is my code:</p>
  
  <pre><code>header1 = str.encode("1\n")
  header1 = str.encode("2\n")
  print (type(header))
  with open("abc.bin",'wb') as f_test:
      f_test.write(header1)
      f_test.write(header2)
  </code></pre>
  
  <p>Here are my questions:
  1, when I open the abc.bin file using notepad, I can see "1" and "2" but they are not at the separated line. Why is it seems that \n is not functional?
  2, in the .bin file, what are the format of "1" and "2". are they strings?
  3, I tried pickle and marshal too. However, when I open .bin file, I found something in front of "1" and "2"(like when I used marshal.dump(header1,f_test), it gave me: ?1?2). What are these'?' and where do they come frome?</p>