Skip to main content
edited title
Link
mkrieger1
  • 24.2k
  • 7
  • 68
  • 84

Python how How to write a list of numbers as bytes to a binary file?

I have a list of bytes as integers, which is something like

[120, 3, 255, 0, 100]

How can I write this list to a file as binary?

Would this work?

newFileBytes = [123, 3, 255, 0, 100]
# make file
newFile = open (directoryPath + newFileCounter + ""filename.txt", "wb")
# write to file
newFile.write(newFileBytes)

I have a list of bytes as integers, which is something like

[120, 3, 255, 0, 100]

How can I write this list to a file as binary?

Would this work?

newFileBytes = [123, 3, 255, 0, 100]
# make file
newFile = open (directoryPath + newFileCounter + ".txt", "wb")
# write to file
newFile.write(newFileBytes)

I have a list of bytes as integers, which is something like

[120, 3, 255, 0, 100]

How can I write this list to a file as binary?

Would this work?

newFileBytes = [123, 3, 255, 0, 100]
# make file
newFile = open("filename.txt", "wb")
# write to file
newFile.write(newFileBytes)
I just added 'k' to 'lie' so that it becomes 'like',lie didn't make sense to me as the author wrote "I have a list of bytes as integers, something lie [120, 3, 255, 0, 100]."
Source Link

I have a list of bytes as integers, which is something lie [120, 3, 255, 0, 100].like

[120, 3, 255, 0, 100]

How can I write this list to a file as binary?

Would this work?

newFileBytes = [123, 3, 255, 0, 100]
# make file
newFile = open (directoryPath + newFileCounter + ".txt", "wb")
# write to file
newFile.write(newFileBytes)

I have a list of bytes as integers, something lie [120, 3, 255, 0, 100]. How can I write this list to a file as binary?

Would this work?

newFileBytes = [123, 3, 255, 0, 100]
# make file
newFile = open (directoryPath + newFileCounter + ".txt", "wb")
# write to file
newFile.write(newFileBytes)

I have a list of bytes as integers, which is something like

[120, 3, 255, 0, 100]

How can I write this list to a file as binary?

Would this work?

newFileBytes = [123, 3, 255, 0, 100]
# make file
newFile = open (directoryPath + newFileCounter + ".txt", "wb")
# write to file
newFile.write(newFileBytes)
Source Link
Aaron Hiniker
  • 4.2k
  • 6
  • 23
  • 14
Loading