티스토리 뷰

print(value, sep=' ', end='\n', file=sys.stdoutput, flush=False)

with open('somefile.txt', 'wt') as f:
    print('hello world', file=f)

Binary Data 읽고/쓰기

with open('somefile.bin', 'rb') as f:
	data = f.read()
    
with open('somefile.bin', 'wb') as f:
	f.write(b'Hello World')
    
t = "Hello World"
t[0]  # H

for c in t:
	print(c)
  
"""
H
e
l
l
o
"""

b = b'Hello World'
b[0]  # 72

for c in b:
	print(c)

"""
72
101
108
111
"""

with open('somefile.bin', 'rb') as f:
	data = f.read(16)
    text = data.decode('utf-8')
    
with open('somefile.bin', 'wb') as f:
	text = 'Hello World'
    f.write(text.encode('utf-8))

 

최근에 올라온 글
글 보관함