Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python write binary

import pickle


class Person:

   def __init__(self, name, age):
       self.name = name
       self.age = age

   def get_name(self):
       return self.name

   def get_age(self):
       return self.age


person = Person('James', 21)
print(person.get_name())
print(person.get_age())

# write person object to file
with open('james', 'wb') as f:
   pickle.dump(person, f)

# read person from file
with open('james', 'rb') as f2:
   james = pickle.load(f2)

print(james.get_name())
print(james.get_age())
Comment

write binary file in python

file = open("sample.bin", "wb")
COPYfile.write(b"This binary string will be written to sample.bin")
COPYfile.close()
Comment

PREVIOUS NEXT
Code Example
Python :: python dict append value 
Python :: scroll down selenium python 
Python :: plt.imread python 
Python :: handle errors in flask 
Python :: .text python 
Python :: python update multiple dictionary values 
Python :: element wise subtraction python list 
Python :: pil crop image 
Python :: how to update requirements.txt python 
Python :: remove all odd row pandas 
Python :: plot background color matplotlib 
Python :: youtube-dl python get file name 
Python :: how to rename rengeindex pandas 
Python :: list to dataframe 
Python :: How to install pandas-profiling 
Python :: delete migrations django and start over deployment heroku 
Python :: python package version in cmd 
Python :: discord.py how to print audit logs 
Python :: python pdf fpdf example 
Python :: Python Tkinter ListBox Widget 
Python :: how to convert a set to a list in python 
Python :: blender 2.8 python set active object 
Python :: reload flask on change 
Python :: python code to print prime numbers 
Python :: python using datetime as id 
Python :: pandas rename column values dictionary 
Python :: how to make an infinite loop python 
Python :: how to add for loop in python 
Python :: how to sort a dictionary using pprint module in python 
Python :: count repeated characters in a string python 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =