Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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())
Source by codefreelance.net #
 
PREVIOUS NEXT
Tagged: #python #write #binary
ADD COMMENT
Topic
Name
8+5 =