- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_io.py
More file actions
Latest commit
22 lines (20 loc) · 472 Bytes
/
Copy pathstring_io.py
File metadata and controls
22 lines (20 loc) · 472 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 18 11:05:17 2017
@author: shengjiex@qq.com
"""
fromioimportStringIO
f=StringIO()
#f.write('hello jie')
f=StringIO('Hello!\nHi!\nGoodbye!')
whileTrue:
s=f.readline()
ifs=='':
break
print(s.strip())
f.close()
#StringIO操作的只能是str,如果要操作二进制数据,就需要使用BytesIO。
fromioimportBytesIO
f=BytesIO()
f.write('中文'.encode('utf-8'))
print(f.getvalue())