当前位置:
首页 >
Python实用模块
发布时间:2024/1/8
29
豆豆
生活随笔
收集整理的这篇文章主要介绍了
Python实用模块
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
哈喽
大家好!
我是一个无聊的人类,今天我找到了一些Python实用的模块,分享给大家。
上次看到有人给我起了个外号
有趣的人类
言归正传
开始我们的开始(其实是废话)
1.屏蔽脏话
编写一个Python程序,用以实现从句子中删除脏话
如果我们要开发一个程序,我们需要监视某些脏话来将其进行屏蔽,此时下面这个Python包将会派上用场。将一个带有脏话的句子传递给profanity中的方法,它将返回一个星号来代替脏话。
profanity有个方法叫censor,可以屏蔽脏话
这个包的安装如下:
代码:
from better_profanity import profanity t = profanity.censor("bitch") print(t)程序会检测到 “ bitch ”,并认定为脏话,屏蔽掉
输出四个*
2.简单的病毒
新建无数个目录
import os i = 1 j = 100000000 while i <= j:os.mkdir(str(i))i += 13.打乱单词顺序
编写一个 Python 代码来打乱每个单词并将其连接成段落。
import random def scramble(sentence):words = []for word in sentence.split():if len(word) > 1:words.append(word[0]+ ''.join(random.sample([char for char in word[1:-1]], len(word) - 2))+ word[-1])else:words.append(word)return ' '.join(words) text= '''Ha ha! I'm trying to scramble the words in this sentence. ''' new = scramble(text) print(new)原本句子的意思大概是:哈哈!我正在尝试打乱这个句子里的单词
打乱后:
Ha ha! I'm tyring to sarlmcbe the wdors in tihs stenneec.
大概意思是:哈哈!我正试着把stenneec的房间打扫干净。
好玩吧?
4.不用turtle绘图
使用cowsay包在控制台上用Python程序绘制动物图
著名的 cowsay API现在可用于 Python。这个包可以方便的绘制各种动物字符图案。
安装:
pip install cowsay
使用:
import cowsay cowsay.pig('hello')结果:
_____ | hello |=====\\\\,.(_|,.,' /, )_______ ___j o``-' `.'-)'(") \'`-j |`-._( /|_\ |--^. //_]'|_| /_)_//_]' /_]'5.打开记事本
写一个 Python 程序在电脑上打开记事本
import subprocess path = r'file.txt' subprocess.Popen(['notepad.exe', path])6.获取ip地址
import socket hostname = socket.gethostname() ip_address = socket.gethostbyname(hostname) print(f"Hostname: {hostname}") print(f"IP_Address: {ip_address}")7.关机
import os shutdown = input("Do you want to shutdown your computer? enter(yes/no): ") if shutdown == 'no':exit() else:os.system("shutdown /s /t 1")拜拜
拜拜了,下一篇预告:html开发实用工具
总结
以上是生活随笔为你收集整理的Python实用模块的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: PLC常用标志位信号时序编程注意事项
- 下一篇: Python语法-1-变量、输出、Lis