1、emoji第三方库官方传送门:https://pypi.org/project/emoji/
2、方法一安装emoji库
pip install emoji
3、方法二安装emoji库
$ git clone https://github.com/carpedm20/emoji.git
$ cd emoji
$ python setup.py install
4、使用方法
import emoji
result = emoji.emojize("Python is :thumbs_up:")
print(result)
5、查找emoji代码:比如thumbs_up
参考:https://www.webfx.com/tools/emoji-cheat-sheet/
1、指定国内源安装
pip3 install pyinstaller -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
2、本地有1个py文件
3、进行编译成可执行文件
pyinstaller -F 1.py
或者指定python3版本
python3 -m pyinstaller -F 1.py
import requests
from bs4 import BeautifulSoup
# 要爬取的网站URL
url = 'https://www.example.com/'
# 发送HTTP GET请求获取HTML页面
response = requests.get(url)
# 解析HTML页面
soup = BeautifulSoup(response.text, 'html.parser')
# 提取所有链接
links = []
for link in soup.find_all('a'):
link_url = link.get('href')
if link_url not in links:
links.append(link_url)
# 输出所有链接
for link in links:
print(link)
1、配置邮件服务體:首先需要有一个邮件服务器,可以是自己搭建的,也可以是使用第三方的邮件服务商。在邮件服务器上配置一个邮箱,用于接收邮件。
2、编写代码调用邮件服务器的APl:使用编程语言中提供的邮件相关库,调用邮件服务器的AP1,将接收到的邮件消息获取到。
3、解析邮件消息:获取到邮件消息后,需要对邮件消息进行解析,提取出需要的信息,例如发件人、收件人、主题、正文、附件等。
4、进行业务处理:根据解析出来的信息,进行相应的业务处理,例如口格邮件存入数据库、发送回复邮件等。
import imaplib
# 邮件服务器的地址和端口号
imap_server = 'imap.example.com'
imap_port = 993
# 邮箱的用户名和密码
username = '[email protected]'
password = 'your_password'
# 连接到邮件服务器
imap_conn = imaplib.IMAP4_SSL(imap_server, imap_port)
# 登录邮箱
imap_conn.login(username, password)
# 选择收件箱
imap_conn.select('INBOX')
# 搜索邮件
typ, data = imap_conn.search(None, 'ALL')
# 遍历搜索结果
for num in data[0].split():
typ, msg_data = imap_conn.fetch(num, '(RFC822)')
# 解析邮件消息
msg_str = msg_data[0][1].decode('utf-8')
# 进行业务处理
# ...
# 关闭连接
imap_conn.close()
imap_conn.logout()
import tkinter as tk
class Calculator:
def __init__(self, master):
self.master = master
self.master.title('Calculator')
# 创建用于显示计算结果的文本框
self.result_var = tk.StringVar()
self.result_var.set('')
self.result_entry = tk.Entry(self.master, textvariable=self.result_var, state='readonly', width=20, font=('Arial', 12))
self.result_entry.grid(row=0, column=0, columnspan=4)
# 创建计算器按钮
button_texts = [
'7', '8', '9', '/',
'4', '5', '6', '*',
'1', '2', '3', '-',
'0', '.', '=', '+'
]
row, col = 1, 0
for button_text in button_texts:
button = tk.Button(self.master, text=button_text, width=5, height=2,
command=lambda text=button_text: self.button_click(text))
button.grid(row=row, column=col)
col += 1
if col > 3:
row += 1
col = 0
def button_click(self, text):
if text == '=':
try:
# 计算表达式的值
result = eval(self.result_var.get())
self.result_var.set(str(result))
except:
self.result_var.set('Error')
else:
# 更新文本框内容
self.result_var.set(self.result_var.get() + text)
if __name__ == '__main__':
root = tk.Tk()
app = Calculator(root)
root.mainloop()
import pygame
import random
# 定义颜色
white = (255, 255, 255)
black = (0, 0, 0)
red = (213, 50, 80)
green = (0, 255, 0)
blue = (50, 153, 213)
# 初始化pygame
pygame.init()
# 定义窗口大小
width = 600
height = 400
# 创建窗口
screen = pygame.display.set_mode((width, height))
# 设置窗口标题
pygame.display.set_caption('贪吃蛇')
# 定义字体
font_style = pygame.font.SysFont(None, 30)
# 定义蛇的大小和速度
snake_block = 10
snake_speed = 15
# 定义分数
def your_score(score):
value = font_style.render("Your Score: " + str(score), True, white)
screen.blit(value, [0, 0])
# 定义蛇的形状和初始位置
def our_snake(snake_block, snake_list):
for x in snake_list:
pygame.draw.rect(screen, green, [x[0], x[1], snake_block, snake_block])
# 显示游戏结束信息
def message(msg, color):
mesg = font_style.render(msg, True, color)
screen.blit(mesg, [width/6, height/3])
# 主函数
def gameLoop():
game_over = False
game_close = False
# 初始位置
x1 = width / 2
y1 = height / 2
# 移动方向
x1_change = 0
y1_change = 0
# 定义蛇的列表和长度
snake_List = []
Length_of_snake = 1
# 定义食物的位置
foodx = round(random.randrange(0, width - snake_block) / 10.0) * 10.0
foody = round(random.randrange(0, height - snake_block) / 10.0) * 10.0
while not game_over:
while game_close == True:
screen.fill(black)
message("You Lost! Press Q-Quit or C-Play Again", red)
your_score(Length_of_snake - 1)
pygame.display.update()
# 判断是否结束游戏或重新开始
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
game_over = True
game_close = False
if event.key == pygame.K_c:
gameLoop()
# 判断是否按下了'quit'按键
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x1_change = -snake_block
y1_change = 0
elif event.key == pygame.K_RIGHT:
x1_change = snake_block
y1_change = 0
elif event.key == pygame.K_UP:
y1_change = -snake_block
x1_change = 0
elif event.key == pygame.K_DOWN:
y1_change = snake_block
x1_change = 0
# 判断是否撞墙或撞到自己
if x1 >= width or x1 < 0 or y1 >= height or y1 < 0:
game_close = True
x1 += x1_change
y1 += y1_change
screen.fill(black)
pygame.draw.rect(screen, blue, [foodx, foody, snake_block, snake_block])
snake_Head = []
snake_Head.append(x1)
snake_Head.append(y1)
snake_List.append(snake_Head)
if len(snake_List) > Length_of_snake:
del snake_List[0]
# 判断是否吃到了食物
for x in snake_List[:-1]:
if x == snake_Head:
game_close = True
our_snake(snake_block, snake_List)
your_score(Length_of_snake - 1)
pygame.display.update()
# 判断是否吃到了食物并更新分数、食物位置以及蛇的长度
if x1 == foodx and y1 == foody:
foodx = round(random.randrange(0, width - snake_block) / 10.0) * 10.0
foody = round(random.randrange(0, height - snake_block) / 10.0) * 10.0
Length_of_snake += 1
# 控制蛇的速度
clock = pygame.time.Clock()
clock.tick(snake_speed)
pygame.quit()
quit()
gameLoop()