Catalog
One 、 Study Python The feeling of
design sketch
Two 、 Code
1、 The library used
2、 The code analysis
On the Internet, I saw many people say that self-study Python It can perform very powerful functions in a few months , Seeing these articles, I began to doubt myself , Four months of study Python I just don't know how to use it in practice .
I didn't find the problem until the recent winter vacation , The original study is based on the content of the book , Less code , And knowledge sees more , This leads to a code shortage when learners use their ability to knock code ( I don't know how to knock it down ).
Maybe a part of learning Python Students have a lot of code typing , Also like me, I can't write a program by myself .
I deeply remember what I taught us last semester Python The teacher said to us while preparing for the final exam : This final exam will not let you do a management system , Otherwise, only single digit students in the class will pass .
Internet trends , Let many people develop in this industry , This is also my first article on code , I also believe that many students are learning Python Or other programming software , Will fall into the problem of not knowing how to knock , The only solution is : Look at the code 、 How to read 、 Knock more 、 Multiple ideas !
It would be better if there were exercises !
Let's show it first ( There are also some flaws ), Write articles to motivate yourself , It also inspires people who are learning Python you !
wordcloud、jieba、time
The first step is, of course, to import the required libraries
import wordcloud
import jieba
import time
About wordcloud and jieba These two third-party libraries , have access to PyCharm Of file Click Install in settings , Or into the system cmd Use :
pip install worlcloud
pip install jieba
The next step is to set parameters , Go straight to the code :
# Thesaurus
import wordcloud
import jieba
import time
class ocr:
def __init__(self) -> str: # Initializer
time.sleep(2)
print(" Welcome to the word segmentation system ")
time.sleep(0.5)
print(" Wait for the program to initialize , About need 1-3 Second ")
time.sleep(2)
def File(self, user: str) -> str: # Identify the file name , And process the data
if user[0] == "" or user[0] == " ":
print(" Input error !")
elif user[-4:] == '.txt':
file = open(user, 'r', encoding="UTF-8")
self.f = file.read()
file.close()
if user[-3:] != 'txt':
print(" Format error !")
else:
lcut = jieba.lcut(user)
self.f = " ".join(lcut)
def show(self): # Read text / File and output the cloud image
ls = jieba.lcut(self.f)
lst = []
for i in ls:
if len(i) >= 2:
lst.append(i)
aaa = str(lst)
word = wordcloud.WordCloud(
font_path="msyh.ttc",\
width=1000, height=800,\
background_color="white",\
)
word.generate(aaa)
picture_name = str(input(" Please enter a picture name :"))
word.to_file("{}.png".format(picture_name))
if __name__ == "__main__":
op = ocr()
user = input(" Please enter text / file name :\n")
op.File(user)
op.show()
There's a problem with the code , You can send it by private mail !
I'm programming Xiaobai , Please also ask the great God for advice !
1. install pip3 install pymsql
Preface I dont know when peop