You don't have to know, there are no eggs. Some Python libraries

Source: Internet
Author: User
Tags ming



1. DeLorean, a library for processing time


Import datetime
Import pytz

# In general, we want to express time
Est = pytz.timezone("Asia/Shanghai")
t = datetime.datetime.now(est)
Print(t) # 2018-07-30 23:06:21.563803+08:00


# Using delorean
From delorean import Delorean
d = Delorean()
t = d.shift("Asia/Shanghai")
Print(t) # Delorean(datetime=datetime.datetime(2018, 7, 30, 23, 6, 21, 607802), timezone=‘Asia/Shanghai’)
Print(t.next_day(1)) # Delorean(datetime=datetime.datetime(2018, 7, 31, 23, 7, 40, 48419), timezone=‘Asia/Shanghai’)
Print(t.next_day(-1)) # Delorean(datetime=datetime.datetime(2018, 7, 29, 23, 8, 1, 593950), timezone=‘Asia/Shanghai’)

# Next Sunday
Print(t.next_sunday()) # Delorean(datetime=datetime.datetime(2018, 8, 5, 23, 8, 56, 391465), timezone=‘Asia/Shanghai’)
#Next Friday
Print(t.next_friday()) # Delorean(datetime=datetime.datetime(2018, 8, 3, 23, 8, 56, 391465), timezone=‘Asia/Shanghai’)


From delorean import stops
Import delorean
For stop in stops(freq=delorean.HOURLY, count=10):
    Print(stop)
‘‘‘
Delorean(datetime=datetime.datetime(2018, 7, 30, 15, 11, 17), timezone=‘UTC‘)
Delorean(datetime=datetime.datetime(2018, 7, 30, 16, 11, 17), timezone=‘UTC‘)
Delorean(datetime=datetime.datetime(2018, 7, 30, 17, 11, 17), timezone=‘UTC‘)
Delorean(datetime=datetime.datetime(2018, 7, 30, 18, 11, 17), timezone=‘UTC‘)
Delorean(datetime=datetime.datetime(2018, 7, 30, 19, 11, 17), timezone=‘UTC‘)
Delorean(datetime=datetime.datetime(2018, 7, 30, 20, 11, 17), timezone=‘UTC‘)
Delorean(datetime=datetime.datetime(2018, 7, 30, 21, 11, 17), timezone=‘UTC‘)
Delorean(datetime=datetime.datetime(2018, 7, 30, 22, 11, 17), timezone=‘UTC‘)
Delorean(datetime=datetime.datetime(2018, 7, 30, 23, 11, 17), timezone=‘UTC‘)
Delorean(datetime=datetime.datetime(2018, 7, 31, 0, 11, 17), timezone=‘UTC‘)
‘‘‘





2.prettybody


From prettytable import PrettyTable

p = PrettyTable()

P.field_names = ["name", "age", "gender", "husband"]

P.add_row(["satori", 18, "f", "zgg"])
P.add_row(["mashiro", 18, "f", "zgg"])
P.add_row(["miku", 18, "f", "zgg"])
P.add_row(["matsuri", 18, "f", "zgg"])
Print(p)
‘‘‘
+---------+-----+--------+---------+
| name | age | gender | husband |
+---------+-----+--------+---------+
| satori | 18 | f | zgg |
| mashiro | 18 | f | zgg |
| miku | 18 | f | zgg |
| matsuri | 18 | f | zgg |
+---------+-----+--------+---------+

‘‘‘

# Add a column
P.add_column("anime", ["Oriental Earth Hall", "Sakura Girl's Pet Girl", "Hatsune Miku", "sola"])
Print(p)
‘‘‘
+---------+-----+--------+---------+-------------- ----+
| name | age | gender | husband | anime |
+---------+-----+--------+---------+-------------- ----+
| satori | 18 | f | zgg | Oriental Earth Hall |
Mashiro | 18 | f | zgg | Pet Girl in Sakurazhuang |
| miku | 18 | f | zgg | Hatsune Miku |
| matsuri | 18 | f | zgg | sola |
+---------+-----+--------+---------+-------------- ----+
‘‘‘

# Get the form
Print(p.get_html_string())
‘‘‘
<table>
    <tr>
        <th>name</th>
        <th>age</th>
        <th>gender</th>
        <th>husband</th>
        <th>anime</th>
    </tr>
    <tr>
        <td>satori</td>
        <td>18</td>
        <td>f</td>
        <td>zgg</td>
        <td>Oriental Earth Hall</td>
    </tr>
    <tr>
        <td>mashiro</td>
        <td>18</td>
        <td>f</td>
        <td>zgg</td>
        <td>Sakura girl's pet girl</td>
    </tr>
    <tr>
        <td>miku</td>
        <td>18</td>
        <td>f</td>
        <td>zgg</td>
        <td> Hatsune Miku</td>
    </tr>
    <tr>
        <td>matsuri</td>
        <td>18</td>
        <td>f</td>
        <td>zgg</td>
        <td>sola</td>
    </tr>
</table>
‘‘‘

Print(p.get_string())
‘‘‘
+---------+-----+--------+---------+-------------- ----+
| name | age | gender | husband | anime |
+---------+-----+--------+---------+-------------- ----+
| satori | 18 | f | zgg | Oriental Earth Hall |
Mashiro | 18 | f | zgg | Pet Girl in Sakurazhuang |
| miku | 18 | f | zgg | Hatsune Miku |
| matsuri | 18 | f | zgg | sola |
+---------+-----+--------+---------+-------------- ----+
‘‘‘

# Get the specified column, the specified row
Print(p.get_string(fields=["name", "anime"], start=0, end=4))
‘‘‘
+---------+------------------+
| name | anime |
+---------+------------------+
| satori | Oriental Earth Hall |
| mashiro | Pet girl in Sakurazhuang |
| miku | Hatsune Miku |
| matsuri | sola |
+---------+------------------+
‘‘‘





3.snowballstemmer


# Used to extract word stems and support 15 languages
From snowballstemmer import EnglishStemmer

Print(EnglishStemmer().stemWord("love"))
Print(EnglishStemmer().stemWord("production"))
Print(EnglishStemmer().stemWord("affection"))
Print(EnglishStemmer().stemWord("gravity"))
‘‘‘
Love
Product
Obese
Graviti
‘‘‘





4.wget, more useful library, can be used to download pictures


Import wget

Url = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1532975831713&di=6add9fa41ac1a7ddbddcaa919d49c497&imgtype=0&src=http%3A%2F%2Fimage.uczzd.cn%2F6715434799472055716.jpeg%3Fid%3D0"
# Parameter one: url, downloaded address, parameter two: out, output file name or path
Wget.download(url=url, out=r"C:\Users\Administrator\Desktop\aaa\matsuri.jpg"


Of course, enter an ordinary URL, the entire page will be downloaded HTML text






5.fuzzywuzzy, used to make the similarity of the string


From fuzzywuzzy import fuzz
From fuzzywuzzy import process

Print(fuzz.ratio("my name is satori", "my name is mashiro")) # 74, indicating that the similarity is 74 percent

Print(fuzz.ratio("i love satori", "I love satori")) # 92, visible is case sensitive
Print(fuzz.ratio("i love satori", "I love satori!")) # 89
Print(fuzz.partial_ratio("i love satori", "i love satori!!!!!")) # 100
# Both are sensitive to location, but ratio is a full match. Partial_ratio is a search match, knowing that one party is over, and even if there is one, it will not affect it.
Print(fuzz.ratio("I always like the ancient Ming basin", "I always like the ancient Ming basin, sleep more and worry")) # 72
Print(fuzz.partial_ratio("I always like the ancient Ming basin", "I always like the ancient Ming basin, sleep more and worry")) # 100


You don't have to know, there are no eggs. Some Python libraries


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.