当前位置:网站首页>IO stream ----- open
IO stream ----- open
2022-07-04 11:07:00 【It's a cinch!】
io flow
It mainly refers to the operation of computer input and output , Generally speaking, it is the input and output between memory and disk
IO Stream operation is a kind of persistence operation , Is to persist data on disk
python How to operate io flow
adopt open Global function ----- The main function is to open local files
open Function analysis :
The first parameter :file The file name or path of the open file
The second parameter :mode Turn on mode ( Default character input stream )
The other parameters
mode:
'r' open for reading (default)
'w' open for writing, truncating the file first
'x' create a new file and open it for writing
'a' open for writing, appending to the end of the file if it exists
'b' binary mode
't' text mode (default)
'+' open a disk file for updating (reading and writing)
'U' universal newline mode (deprecated)
Operation example :
from os import path # Import io flow
>>> path.abspath(".")
'C:\\Users\\hp' # View current path
>>> open("fg.txt") # Open the file in the current path
<_io.TextIOWrapper name='fg.txt' mode='r' encoding='cp936'>
>>> f=open("fg.txt","r")
>>> path.abspath(".")
'C:\\Users\\hp'
>>> open("fg.txt")
<_io.TextIOWrapper name='fg.txt' mode='r' encoding='cp936'>
>>> open("C:\\Users\\hp\\fg.txt")
<_io.TextIOWrapper name='C:\\Users\\hp\\fg.txt' mode='r' encoding='cp936'>
>>> f.read()
''
>>> f.close()IO Stream classification :
According to the flow of data ( From the perspective of memory ) The direction of
1、 Input stream
/2、 Output stream
problem : Is it an input stream or an output stream to save data in the hard disk ?------- Output stream
3、 Byte stream : Store image 、 Video etc.
/4、 Character stream
IO Stream operation data
eg. # Cover the original content
>>> f=open("fa.txt","w")
>>> f
<_io.TextIOWrapper name='fa.txt' mode='w' encoding='cp936'>
>>> f.write("hello")
5 #-------------- Returns the number of characters written
>>> f.close() # Write to characters to display
eg. # Do not turn off the display of input
>>> f=open("fa.txt","w")
>>> f.write(" Da da da da da da da da ")
12
>>> f.flush()
eg. # Do not overwrite the original content
>>> f.flush()
>>> f=open("fa.txt",mode="a")
>>> f.write("dsfsdfd")
7
>>> f.close()
边栏推荐
- Unittest+airtest+beatiulreport combine the three to make a beautiful test report
- Simple understanding of generics
- SSH原理和公钥认证
- [test theory] test process management
- The last month before a game goes online
- [Galaxy Kirin V10] [server] NUMA Technology
- Simple understanding of seesion, cookies, tokens
- Performance features focus & JMeter & LoadRunner advantages and disadvantages
- Design and common methods of test case documents
- SSH principle and public key authentication
猜你喜欢

Deepmind proposed a Zuan AI, which specially outputs network attack language

Fundamentals of software testing
![[Galaxy Kirin V10] [server] NFS setup](/img/ed/bd7f1a1e4924a615cb143a680a2ac7.jpg)
[Galaxy Kirin V10] [server] NFS setup

Introduction to Lichuang EDA

Climb Phoenix Mountain on December 19, 2021

Application and Optimization Practice of redis in vivo push platform

2022 AAAI fellow release! Yan Shuicheng, chief scientist of sail, and Feng Yan, Professor of Hong Kong University of science and technology, were selected

QQ group collection

Canoe - the third simulation project - bus simulation - 3-1 project implementation

Replace() function
随机推荐
Advanced order of function
Summary of automated testing framework
Heartbeat启动后无反应
Swagger and OpenAPI
Replace() function
QQ group collection
array_ The contains() function uses
Performance test method
Usage of with as
[Galaxy Kirin V10] [desktop] printer
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
守护进程Xinted和日志记录Syslogd
Canoe: the fourth simulation project -- bug debugging experience
Function introduction of canbedded component
Understanding of object
Local MySQL forget password modification method (Windows) [easy to understand]
Notes on writing test points in mind mapping
Performance features focus & JMeter & LoadRunner advantages and disadvantages
Interview and lecture summary 1
Hidden C2 tunnel -- use of icmpsh of ICMP