GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — python_test/test29.py at master · zhangyfzone/python_test

Expand file tree

/

test29.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
25 lines (20 loc) · 642 Bytes
/

test29.py

Copy path

File metadata and controls

25 lines (20 loc) · 642 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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.