当前位置:网站首页>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()
边栏推荐
- Lvs+kept realizes four layers of load and high availability
- Heartbeat报错 attempted replay attack
- Appscan installation steps
- For and while loops
- OSI model notes
- VPS installation virtualmin panel
- Discussion | has large AI become autonomous? Lecun, chief scientist of openai
- Performance test process
- Basic function exercises
- The most ideal automated testing model, how to achieve layering of automated testing
猜你喜欢
![[Galaxy Kirin V10] [server] FTP introduction and common scenario construction](/img/ef/f0f722aaabdc2d98723cad63d520e0.jpg)
[Galaxy Kirin V10] [server] FTP introduction and common scenario construction

TS type gymnastics: illustrating a complex advanced type

Postman interface test

Send a request using paste raw text

F12 clear the cookies of the corresponding web address

XMIND installation

Appscan installation error: unable to install from Net runtime security policy logout appscan solution
![[Galaxy Kirin V10] [server] system partition expansion](/img/49/5d3e28eab45d300bd5695e47b35e6b.jpg)
[Galaxy Kirin V10] [server] system partition expansion
![[Galaxy Kirin V10] [server] soft RAID configuration](/img/d5/789387613fafc18f623d0cff45093b.jpg)
[Galaxy Kirin V10] [server] soft RAID configuration

Elevator dispatching (pairing project) ②
随机推荐
Local MySQL forget password modification method (Windows) [easy to understand]
Usage of with as
Polymorphic system summary
2021-11-02
QQ get group information
SSH principle and public key authentication
Elevator dispatching (pairing project) ④
[Galaxy Kirin V10] [desktop] cannot add printer
[test theory] test the dimension of professional ability
Canoe: distinguish VT, VN and vteststudio from their development history
Hidden C2 tunnel -- use of icmpsh of ICMP
Jemeter plug-in technology
[Galaxy Kirin V10] [server] failed to start the network
Usage of case when then else end statement
Daemon xinted and logging syslogd
Fundamentals of database operation
1. Circular nesting and understanding of lists
Performance features focus & JMeter & LoadRunner advantages and disadvantages
Simple understanding of generics
试题库管理系统–数据库设计[通俗易懂]