current position:Home>Don't you know more about a python library before the end of 2021?
Don't you know more about a python library before the end of 2021?
2022-01-29 20:23:07 【Dream eraser】
Little knowledge , Great challenge ! This article is participating in 「 A programmer must have a little knowledge 」 Creative activities
This article has participated in 「 Digging force Star Program 」 , Win a creative gift bag , Challenge creation incentive fund .
Write it at the front
In the work , What I fear most is to encounter problems , I don't know how to solve , for example , You want to convert a paragraph of Chinese into Chinese Pinyin , There's no way to start , But after reading today's article , You will become very good at this operation , Only need to consume in the future 1s, The solution immediately jumps into your mind .
open github:github.com/mozillazg/p… This web site , It's just Chinese characters to Pinyin , As python developer , Skillfully find others ( Daniel ) Written Library , For use , When you improve your coding experience , In the open source circle , Wonderful ~
The library is very powerful , Basic functions are available , As of today , The author is still updating the source code , So there is no problem with this library ,2022 One year can also be used for one year , Believe in the power of the big man .
pinyin Library application scenario
For this library , There are many application scenarios , For example, the storage of files , In many systems, Chinese support is not friendly , Need to be converted to letters , That conversion to Pinyin is a very good solution , And for URL Inside , This is where letters are often needed , More time , When you develop a project , You'll find that , The final solution to many needs may be to convert Chinese into pinyin or English , Then the problem is solved , At that time, I hope you can think of python There are similar libraries in , What we mentioned today is just one of them .
Code time
install pypinyin
This step is for a skilled hand , It's simple , Just use one line of command , But be aware that if you keep downloading , Need to switch to domestic source .
pip install pypinyin
pip install pypinyin -i pypi.tuna.tsinghua.edu.cn/simple
Three lines of code , First show a wave of basic use
from pypinyin import pinyin
text = pinyin(' Dream eraser ')
print(text)
Copy code
No problem , The operation results are correct , And the tone ,emmm...., We usually don't need this .
[['mèng'], ['xiǎng'], ['xiàng'], ['pí'], ['cā']]
The official case , I'll post it directly for you , You can feel strong , When you see that polyphonic characters are also supported , The psychology silently said a big man NB.
# Python 3(Python 2 with hands ' center ' Replace with u' center ' that will do ):
>>> from pypinyin import pinyin, lazy_pinyin, Style
>>> pinyin(' center ')
[['zhōng'], ['xīn']]
>>> pinyin(' center ', heteronym=True) # Enable polyphonic mode
[['zhōng', 'zhòng'], ['xīn']]
>>> pinyin(' center ', style=Style.FIRST_LETTER) # Set Pinyin style
[['z'], ['x']]
>>> pinyin(' center ', style=Style.TONE2, heteronym=True)
[['zho1ng', 'zho4ng'], ['xi1n']]
>>> pinyin(' center ', style=Style.TONE3, heteronym=True)
[['zhong1', 'zhong4'], ['xin1']]
>>> pinyin(' center ', style=Style.BOPOMOFO) # Phonetic style
[['ㄓㄨㄥ'], ['ㄒㄧㄣ']]
>>> lazy_pinyin(' center ') # Regardless of polyphony
['zhong', 'xin']
Copy code
For a useful library , Documentation is indispensable , Missing this part , Even if your code is wonderful , Then promote and use , In the face of any problem, it will be ruthlessly amplified , People don't usually use it , because == Not at all ==.
Official documents :pypinyin.readthedocs.io/zh_CN/maste…
pypinyin
, In this regard, we have done a good job in documentation , Common usage and questions are clearly written , This has also led to , I have nothing to write ( Actually, I'm lazy ). This explanation
Match the most correct Pinyin intelligently according to the phrase .
Support for polyphony .
Simple traditional support , Phonetic support .
Support many different Pinyin styles .
Copy code
Written in the back
Problem solving
- Why promote some python library ?
For a developer , The quickest way to solve the problem is just need , A lot of times , We haven't heard of a module , It leads us to build a lot of wheels repeatedly , Wasted time , Wasted energy , And what we do is not necessarily better than what we already have in the open source circle , So stand on the big man's shoulder first , Let the big guy's code shine , When you have enough ability , Building a better wheel , Leave it to houlang programmer .
- How new people should learn Python Language
python After understanding the basic grammatical structure of the language , More is copying practice , A lot of copy code , Don't think that if you copy and paste other people's code during the learning period, you won't grow , Quantitative change leads to qualitative change , You don't copy code , It's hard to grow fast , So the initial stage of new students' learning , See more , Copy more , Find more excellent modules , It seems very slow , In fact, it will grow up very quickly .
A lot of times , We can't solve the technical problem , It's not because we're not skilled , But because we don't know what to do
In this article, I hope you can hear from today that there is a tool called
pypinyin
.
copyright notice
author[Dream eraser],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201292023025737.html
The sidebar is recommended
- Compile D + +, and use d to call C from python
- Install tensorflow and python 3.6 in Windows 7
- Python collects and monitors system data -- psutil
- Python collects and monitors system data -- psutil
- Finally, this Python import guide has been sorted out. Look!
- Quickly build Django blog based on function calculation
- Getting started with Python - object oriented - special methods
- Teach you how to use Python to transform an alien invasion game
- You can easily get started with Excel. Python data analysis package pandas (VI): sorting
- Implementation of top-level design pattern in Python
guess what you like
-
Using linear systems in python with scipy.linalg
-
Python tiktok 5000+ V, and found that everyone love this video.
-
Using linear systems in python with scipy.linalg
-
How to get started quickly? How to learn Python
-
Modifying Python environment with Mac OS security
-
You can easily get started with Excel. Python data analysis package pandas (XI): segment matching
-
Advanced practical case: Javascript confusion of Python anti crawling
-
Better use atom to support jupyter based Python development
-
Better use atom to support jupyter based Python development
-
Fast power modulus Python implementation of large numbers
Random recommended
- Python architects recommend the book "Python programmer's Guide" which must be read by self-study Python architects. You are welcome to take it away
- Decoding the verification code of Taobao slider with Python + selenium, the road of information security
- Python game development, pyGame module, python implementation of skiing games
- This paper clarifies the chaotic switching operation and elegant derivation of Python
- You can easily get started with Excel. Python data analysis package pandas (3): making score bar
- Test Development: self study Dubbo + Python experience summary and sharing
- Python + selenium automated test: page object mode
- You can easily get started with Excel. Python data analysis package pandas (IV): any grouping score bar
- Opencv skills | saving pictures in common formats as transparent background pictures (with Python source code) - teach you to easily make logo
- You can easily get started with Excel. Python data analysis package pandas (V): duplicate value processing
- Python ThreadPoolExecutor restrictions_ work_ Queue size
- Python generates and deploys verification codes with one click (Django)
- With "Python" advanced, you can catch all the advanced syntax! Advanced function + file operation, do not look at regret Series ~
- At the beginning of "Python", you must see the series. 10000 words are only for you. It is recommended to like the collection ~
- [Python kaggle] pandas basic exercises in machine learning series (6)
- Using linear systems in python with scipy.linalg
- The founder of pandas teaches you how to use Python for data analysis (mind mapping)
- Using Python to realize national second-hand housing data capture + map display
- Python image processing, automatic generation of GIF dynamic pictures
- Pandas advanced tutorial: time processing
- How to make Python run faster? Six tips!
- Django: use of elastic search search system
- Fundamentals of Python I
- Python code reading (chapter 35): fully (deeply) expand nested lists
- Python 3.10 official release
- Solution of no Python 3.9 installation was detected when uninstalling Python
- This pandas exercise must be successfully won
- [Python homework] coupling network information dissemination
- Python application software development tool - tkinterdesigner v1.0 5.1 release!
- [Python development tool Tkinter designer]: Lecture 2: introduction to Tkinter designer's example project
- [algorithm learning] sword finger offer 64 Find 1 + 2 +... + n (Java / C / C + + / Python / go / trust)
- leetcode 58. Length of Last Word(python)
- Problems encountered in writing the HTML content of articles into the database during the development of Django blog
- leetcode 1261. Find Elements in a Contaminated Binary Tree(python)
- [algorithm learning] 1486 Array XOR operation (Java / C / C + + / Python / go / trust)
- Understand Python's built-in function and add a print function yourself
- Python implements JS encryption algorithm in thousands of music websites
- leetcode 35. Search Insert Position(python)
- leetcode 1829. Maximum XOR for Each Query(python)
- [introduction to Python visualization]: 12 small examples of complete data visualization, taking you to play with visualization ~