Ternary Operations
Ternary operations, also known as trinocular operations, are shorthand for simple conditional statements:
Simple Conditional statement:
if condition established: val=1else: val=2
Change to ternary operation;
file ProcessingNow there is a file ' part-time student contacts ', how to view content?
1. Installing the Text editor software
2. Select the right button. Open with a text editor
3. View or Write
4. Save, close
File operations are divided into read, write, modify
First step, read. How to open a file
R Open as read (the file does not exist, the error is not provided access_mode default value)
W is opened in write mode (the file exists is emptied and does not exist)
A opens in Append mode (creates a new file if necessary) r+ open in read-write mode (see R) w+ open in read-write mode (see W) A + opens in read-write mode (see a)
F=open (file='d:/work daily/part-time student contact us. txt', mode='r', encoding= ' Utf-8 ' #以读的方式打开文件data=f.read () #接着上一步, to continue to manipulate the file, you will assign a value, open the file, save a variable, and then. Read f.close# Close the folder
Absolute path: d:/work daily/part-time student Contact Us
Relative path: The current file can be found
Chardet: Judging the possible encoding
Decode and check.
Write mode operation file
Step Two, write the file
python-files and built-in functions open (), file ()