GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — python_test/test29.py at master · hnfurui/python_test Expand file tree/ Copy pathtest29.pyMore file actions 25 lines (20 loc) · 642 Bytes / Copy pathtest29.pyFile metadata and controls25 lines (20 loc) · 642 Bytes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 #!/usr/bin/env python3 # -*- coding: utf-8 -*- '练习读取StingIO和BytesIO' __author__ = 'sergiojune' from io import StringIO, BytesIO # StingIO和BytesIO 和在内存中读取数据,不是在文件中读取数据 s = StringIO('hello\nhi\ngood!\nheadsome boy') # 创建 # 进行读取,与文件读取差不多 for x in s.readlines(): print(x) # 也可以这样创建 s = StringIO() s.write('hello') s.write(' ') s.write('world') print(s.getvalue()) # 这时BytesIO的练习,bytesIO是写入字节码,而SrtingIO是写入str b = BytesIO('中文'.encode('utf-8')) # print(b.getvalue()) print(b.read()) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |