current position:Home>Python series tutorials 122
Python series tutorials 122
2022-01-30 20:40:27 【AI technology of artificial intelligence】
friends , If you need to reprint, please indicate the source :blog.csdn.net/jiangjunsho…
Statement : During the teaching of artificial intelligence technology , Many students mentioned to me python Related issues , So in order to let the students master more extended knowledge and better understand AI technology , I put the assistant in charge of sharing this python Series of tutorials , I hope that helps ! Because of this python The tutorial wasn't written by me , So it's not as good as mine AI Technology teaching is humorous , It's boring to learn ; But its knowledge is in place , It's also worth reading !PS: If you don't understand this article, please read the previous article first , Step by step, learn a little everyday, and you won't find it difficult !
stay Python 3.0 and Python 2.6 in , File types are defined by open The second parameter of determines , This parameter can be called a pattern string , If the string contains a “b” Then it means opening the file in binary form , Otherwise, it is in the form of text .
Python Text and binary files have always been supported , But in Python 3.0 in , There is a clear difference between the two : • Text files represent content as regular str character string , Automatic execution Unicode Encoding and decoding , And the last line conversion is performed by default . • Binary files represent the content as a special bytes String type , And allow the program to access the contents of the file without modification .
If you need to handle internationalized applications or byte oriented data ,Python 3.0 Differences in affect the code . Usually , You have to use bytes String processing binaries , And use the regular str String processing text file . Besides , Because the text file realizes Unicode code , So you can't open a binary data file in text mode —— Otherwise, decode its contents into Unicode Text may fail .
Let's look at an example . When you read a binary data file , Will get a bytes object :
>>> data = open('data.bin','rb').read() # Open binary file: rb=read binary
>>> data # bytes string holds binary data
b'\x00\x00\x00\x07spam\x00\x08'
>>> data[4:8] # Act like strings
b'spam'
>>> data[0] # But really are small 8-bit integers
115
>>> bin(data[0]) # Python 3.0 bin() function
'0b1110011'
Copy code
Besides , Binary files do not perform any last line conversion on data . Therefore, when reading and writing files, it is necessary to distinguish whether to use text form or binary form . A file written as text , Also use text when reading . A file written in binary form , When reading, it is necessary to use binary form !
copyright notice
author[AI technology of artificial intelligence],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201302040260096.html
The sidebar is recommended
- Introduction to python (IV) dynamic web page analysis and capture
- leetcode 119. Pascal's Triangle II(python)
- leetcode 31. Next Permutation(python)
- [algorithm learning] 807 Maintain the city skyline (Java / C / C + + / Python / go / trust)
- The rich woman's best friend asked me to write her a Taobao double 11 rush purchase script in Python, which can only be arranged
- Glom module of Python data analysis module (1)
- Python crawler actual combat, requests module, python realizes the full set of skin to capture the glory of the king
- Summarize some common mistakes of novices in Python development
- Python libraries you may not know
- [Python crawler] detailed explanation of selenium from introduction to actual combat [2]
guess what you like
-
This is what you should do to quickly create a list in Python
-
On the 55th day of the journey, python opencv perspective transformation front knowledge contour coordinate points
-
Python OpenCV image area contour mark, which can be used to frame various small notes
-
How to set up an asgi Django application with Postgres, nginx and uvicorn on Ubuntu 20.04
-
Initial Python tuple
-
Introduction to Python urllib module
-
Advanced Python Basics: from functions to advanced magic methods
-
Python Foundation: data structure summary
-
Python Basics: from variables to exception handling
-
Python notes (22): time module and calendar module
Random recommended
- Python notes (20): built in high-order functions
- Python notes (17): closure
- Python notes (18): decorator
- Python notes (16): generators and iterators
- Python notes (XV): List derivation
- Python tells you what timing attacks are
- Python -- file and exception
- [Python from introduction to mastery] (IV) what are the built-in data types of Python? Figure out
- Python code to scan code to pay attention to official account login
- [algorithm learning] 1221 Split balanced string (Java / C / C + + / Python / go / trust)
- Python notes (22): errors and exceptions
- Python has been hidden for ten years, and once image recognition is heard all over the world
- Python notes (21): random number module
- Python notes (19): anonymous functions
- Use Python and OpenCV to calculate and draw two-dimensional histogram
- Python, Hough circle transformation in opencv
- A library for reading and writing markdown in Python: mdutils
- Datetime of Python time operation (Part I)
- The most useful decorator in the python standard library
- Python iterators and generators
- [Python from introduction to mastery] (V) Python's built-in data types - sequences and strings. They have no girlfriend, not a nanny, and can only be used as dry goods
- Does Python have a, = operator?
- Go through the string common sense in Python
- Fanwai 4 Handling of mouse events and solutions to common problems in Python opencv
- Summary of common functions for processing strings in Python
- When writing Python scripts, be sure to add this
- Python web crawler - Fundamentals (1)
- Pandas handles duplicate values
- Python notes (23): regular module
- Python crawlers are slow? Concurrent programming to understand it
- Parameter passing of Python function
- Stroke tuple in Python
- Talk about ordinary functions and higher-order functions in Python
- [Python data acquisition] page image crawling and saving
- [Python data collection] selenium automated test framework
- Talk about function passing and other supplements in Python
- Python programming simulation poker game
- leetcode 160. Intersection of Two Linked Lists (python)
- Python crawler actual combat, requests module, python to grab the beautiful wallpaper of a station
- Fanwai 5 Detailed description of slider in Python opencv and solutions to common problems