Python 代码学习(1)
# 参考网址:https://mp.weixin.qq.com/s/Q8g8-s6JT2eOsUtFkNgUTw # 3.8版本运行成功 import json import ssl import socket as f from urllib.request import urlopen from textblob import TextBlob # 文本处理,拼写检查 import pygame from pygame import mixer import sys import pyqrcode import png from pyqrcode import QRCode import pyshorteners as psn import googletrans from googletrans import Translator import pendulum import webview # 浏览器访问https://jsonip.com, 返回公网IP地址 with urlopen(r'https://jsonip.com') as fp: content = fp.read().decode() # 拼写检查 a = TextBlob("I dream about workin with goof company") a = a.correct() print("如下一行拼写检查:") print(a) # IP地址查看 hostn = f.gethostname() Laptop = f.gethostbyname(hostn) ip = json.loads(content)['ip'] print("你的电脑公网IP地址是:" + ip) print("你的电脑本地IP地址是:" + Laptop) # pyqrcode(生成二维码) inpStr = "www.baidu.com" qrc = pyqrcode.create(inpStr) qrc.png("huangtao.png", scale=6) # pyshorteners(短网址) url = "http://www.shuhai.com/" u = psn.Shortener().clckru.short(url) print("如下一行生成如下的短网址:") print(u) # googletrans(翻译) #src:源文本的语言 dest:将源文本转换为的语言。text:翻译的结果 # print(googletrans.LANGUAGES) translater = Translator() out = translater.translate("亚洲象", dest='en', src='auto') print(out) # pendulum(时间) Pendulum是一个处理日期和时间的Python库,该库在涉及时区的情况下非常有用。 past = pendulum.now().subtract(minutes=2) print(past.diff_for_humans()) print(past) # pywebview(GUI浏览器) window = webview.create_window( title='百度一下,全是广告!!!', url='http://www.baidu.com', width=1878, height=960, resizable=False, # 固定窗口大小 text_select=False, # 禁止选择文字内容 confirm_close=True # 关闭时提示 ) webview.start() # pygame(制作游戏) # 点击×可以关闭界面的代码 # pygame.display.set_mode([900, 900]) # music = "123.mp3" # mixer.init() # mixer.music.load(music) # mixer.music.play() # while 1: # for event in pygame.event.get(): # if event.type == pygame.QUIT: # sys.exit() # continue