当前位置:网站首页>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()
边栏推荐
- Strings and characters
- Climb Phoenix Mountain on December 19, 2021
- Hidden C2 tunnel -- use of icmpsh of ICMP
- The last month before a game goes online
- Understanding of object
- Postman interface test
- Capl: timer event
- Locust installation
- Appscan installation steps
- [test theory] test phase analysis (unit, integration, system test)
猜你喜欢
Oracle11g | getting started with database. It's enough to read this 10000 word analysis
[Galaxy Kirin V10] [server] set time synchronization of intranet server
Canoe: what is vtsystem
Canoe - description of common database attributes
What if the book written is too popular? Author of "deep reinforcement learning" at Peking University: then open the download
[Galaxy Kirin V10] [server] system partition expansion
Digital simulation beauty match preparation -matlab basic operation No. 6
Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
JMeter common configuration components and parameterization
Elevator dispatching (pairing project) ④
随机推荐
Lvs+kept realizes four layers of load and high availability
QQ group administrators
[Galaxy Kirin V10] [server] iSCSI deployment
array_ The contains() function uses
CAPL: on sysVar_ Update difference on sysvar
Using Lua to realize 99 multiplication table
[Galaxy Kirin V10] [server] grub default password
VPS安装Virtualmin面板
Replace() function
Elevator dispatching (pairing project) ②
Interview and lecture summary 1
三立期货安全么?期货开户怎么开?目前期货手续费怎么降低?
QQ get group member operation time
Personal thoughts on the development of game automation protocol testing tool
R built in data set
Postman advanced
守护进程Xinted和日志记录Syslogd
JMeter assembly point technology and logic controller
Hidden C2 tunnel -- use of icmpsh of ICMP
Jemeter plug-in technology