First step : Collect data ( Data sources : Reptiles ( Network data sources )、 Questionnaire collection 、 Buy data from specialized companies 、 The database established by the company )
The second step : Data preprocessing ( Tools :python、excel、 Use both hands )
The third step : With the aid of algorithms 、 Model, etc
cost reduction , Increase revenue
Data persistence : Data changes from transient state to persistent state
open( Parameters 1、 Parameters 2、 Parameters 3…) — Open file , Open a file object
Parameters 2: The way the file is opened ( Read and write )
Parameters 3: The encoding form of file opening :utf-8
grammar : '.‘ Represents the current folder ( You can omit it );’…' To return to the next level
Between folders and between folders and files ’/' interval
Path can be divided into relative path and absolute path
Relative paths : Based on the current reference , Another file corresponds to the location of the reference , You should use ’/’
Absolute path : Take the disk as a reference , Use ’’
Suppose you are currently in a folder B in , If you want to find a file A: …/ Folder A/ file A
open('./test/ file 1')
r a w +
w: Just write , file does not exist , First automatically create ; If the file exists , Empty first ( If a folder does not exist , Don't create a folder )
a: Just write , file does not exist , Report errors ; If the file exists , Additional
+: Can read but write , take r、a、w Become readable and writable symbols :r+、a+、w+;python Operation file , Read or write , You cannot read and write at the same time
r、w、a、+ —> File editing method
t、b ----> Document presentation form
t: Text
b: byte
r、w、a Equivalent to rt、wt、at -rb、wb、ab、br、bw、ba Represents the operation of a file in bytes
encoding = ‘utf-8’
f = open(r'./test/ file 1', 'r', encoding='utf-8')print(f)
read() Read information from file objects
result = f.read()print(result, type(result))
notes : All files are stored in binary in memory
f1 = open(r'./test/123.jpg', 'rb')result1 = f1.read()print(result1, type(result1))
Write content
Keep close
Write operations
f = open('./test/ Geese .txt', 'w', encoding='utf-8')str_1 = '\t Chant goose \n\t lo bingwang \n Goose, goose and goose , Song item to the sky .\n White hair dew , Red palm dials clear waves .'print(str_1)f.write(str_1)f.write('\n Chant goose ')f.close()# f.write('1')# ValueError: I/O operation on closed file.# I/O--Input/Out
f = open('./test/ Geese .txt', 'r', encoding='utf-8')
read(): Read everything at once , The read result is a string
print(f.read())
readline(): Read one line at a time , The read result is a string
print(f.readline())
readlines(): Read all at once , Each line is treated as an element in the list
print(f.readlines())f.close()
notes :
seek()— The pointer : During file operation, the pointer is at the beginning of the file by default , The pointer changes as the file is manipulated .
Read the picture
f1 = open('./test/ Administrators .jpeg', 'rb')result = f1.read()print(result)f1.close()
Download the pictures
f2 = open('./test/photo1.jpeg', 'wb')f2.write(result)f2.close()
author : Have a strong sense of self-management .
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .