当前位置:网站首页>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+Keepalived实现四层负载及高可用
- Basic function exercises
- Open the neural network "black box"! Unveil the mystery of machine learning system with natural language
- Fundamentals of software testing
- Capl: timer event
- JMeter Foundation
- Daemon xinted and logging syslogd
- QQ get group settings
- Canoe test: two ways to create CAPL test module
- Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
猜你喜欢
F12 clear the cookies of the corresponding web address
Postman interface test
Canoe - the second simulation engineering - xvehicle - 2 panel design (operation)
[Galaxy Kirin V10] [desktop] cannot add printer
[machine] [server] Taishan 200
XMIND installation
Article publishing experiment
Using Lua to realize 99 multiplication table
DNS hijacking
SQL greatest() function instance detailed example
随机推荐
CAPL: on sysVar_ Update difference on sysvar
2、 Operators and branches
Unittest+airtest+beatiulreport combine the three to make a beautiful test report
1. Circular nesting and understanding of lists
[Galaxy Kirin V10] [server] iSCSI deployment
Jemeter plug-in technology
I What is security testing
[Galaxy Kirin V10] [server] grub default password
Replace() function
[Galaxy Kirin V10] [desktop] build NFS to realize disk sharing
20 kinds of hardware engineers must be aware of basic components | the latest update to 8.13
Postman advanced
Oracle11g | getting started with database. It's enough to read this 10000 word analysis
51 data analysis post
QQ one click cookie acquisition
Canoe the second simulation engineering xvehicle 3 CAPL programming (operation)
Iptables cause heartbeat brain fissure
Canoe - description of common database attributes
Design and common methods of test case documents
Supercomputing simulation research has determined a safe and effective carbon capture and storage route