with open('somefile.txt', 'rb') as f:
data = f.read()
with open('somefile.txt', 'wb') as f:
f.write(b'Hello World')
t = 'Hello World'
print(t[0])
for c in t:
print(c)
b = b'Hello World'
print(b[0])
for c in b:
print(c)
with open('somefile.txt', 'rb') as f:
data = f.read(16)
text = data.decode('utf-8')
with open('somefile.txt', 'wb') as f:
text = 'Hello World'
f.write(text.encode('utf-8'))
import array
a = array.array('i', [0, 0, 0, 0, 0, 0, 0, 0])
with open('data.txt', 'rb') as f:
f.readinto(a)
print(a)