当前位置:网站首页>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()
边栏推荐
- Object. Assign () & JS (= >) arrow function & foreach () function
- QQ get group link, QR code
- QQ group collection
- First article
- Appscan installation steps
- Automatic translation between Chinese and English
- For and while loops
- Usage of with as
- JMeter assembly point technology and logic controller
- Iterator generators and modules
猜你喜欢

DNS hijacking

Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
![[Galaxy Kirin V10] [server] iSCSI deployment](/img/60/13f43dc584c0768965d60811768948.jpg)
[Galaxy Kirin V10] [server] iSCSI deployment

Automatic translation between Chinese and English

Failed to configure a DataSource: ‘url‘ attribute is not specified... Bug solution
![[Galaxy Kirin V10] [server] failed to start the network](/img/0f/6d2f321da85bd7437d2b86547bd8b4.jpg)
[Galaxy Kirin V10] [server] failed to start the network

VI text editor and user rights management, group management and time management

Canoe - the third simulation project - bus simulation-1 overview

Application and Optimization Practice of redis in vivo push platform

Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
随机推荐
Daemon xinted and logging syslogd
Canoe - the third simulation project - bus simulation-1 overview
[test theory] test phase analysis (unit, integration, system test)
Canoe - the third simulation project - bus simulation - 2 function introduction, network topology
[test theory] test process management
[Galaxy Kirin V10] [desktop] login system flash back
Usage of with as
Canoe - the third simulation project - bus simulation - 3-1 project implementation
Lvs+kept realizes four layers of load and high availability
If function in SQL
regular expression
Design and common methods of test case documents
Postman interface test
shell awk
Video analysis
Summary of collection: (to be updated)
Notes on writing test points in mind mapping
Function introduction of canbedded component
software test
Regular expression