当前位置: 首页 > news >正文

用wordpress做站群爱站网影院

用wordpress做站群,爱站网影院,网站后台密码怎么修改,公司的网站怎么做推广收集了一些常用Python脚本,作为平时练手使用,也可以作为自己的笔记,用到哪个功能可以自己查询一下即可。 文件和目录管理 复制文件 import shutil# 复制源文件到目标文件 shutil.copy(source.txt, destination.txt)移动文件 import shuti…

收集了一些常用Python脚本,作为平时练手使用,也可以作为自己的笔记,用到哪个功能可以自己查询一下即可。

文件和目录管理

复制文件

import shutil# 复制源文件到目标文件
shutil.copy('source.txt', 'destination.txt')

移动文件

import shutil# 移动文件到新的路径
shutil.move('source.txt', 'destination.txt')

创建目录结构

import os# 创建多层目录,如果已经存在则不报错
os.makedirs('dir/subdir/subsubdir', exist_ok=True)

删除空目录

import os# 删除当前目录下的所有空目录
for root, dirs, files in os.walk('.', topdown=False):for name in dirs:dir_path = os.path.join(root, name)if not os.listdir(dir_path):os.rmdir(dir_path)

查找大文件

import os# 查找当前目录及子目录下大于1MB的文件
for root, dirs, files in os.walk('.'):for name in files:if os.path.getsize(os.path.join(root, name)) > 1024 * 1024:print(os.path.join(root, name))

检查文件是否存在

import os# 检查指定文件是否存在
if os.path.exists('file.txt'):print("File exists.")
else:print("File does not exist.")

读取文件内容

with open('file.txt', 'r') as file:    content = file.read()

写入文件内容

with open('file.txt', 'w') as file:    file.write('Hello, World!')

数据处理

读取 CSV 文件

import csv# 读取 CSV 文件并打印每一行
with open('data.csv', 'r') as file:reader = csv.reader(file)for row in reader:print(row)

写入 CSV 文件

import csv# 写入数据到 CSV 文件
data = [['Name', 'Age'], ['Alice', 30], ['Bob', 25]]
with open('data.csv', 'w', newline='') as file:writer = csv.writer(file)writer.writerows(data)

读取 JSON 文件

import json# 读取 JSON 文件
with open('data.json', 'r') as file:data = json.load(file)

写入 JSON 文件

import json# 将数据写入 JSON 文件
data = {'name': 'Alice', 'age': 30}
with open('data.json', 'w') as file:json.dump(data, file)

过滤列表中的重复项

# 从列表中去除重复项
my_list = [1, 2, 2, 3, 4, 4, 5]
unique_list = list(set(my_list))

排序列表

# 对列表进行排序
my_list = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]
sorted_list = sorted(my_list)

网络请求与爬虫

获取网页内容

import requests# 发送 GET 请求并获取网页内容
response = requests.get('https://www.example.com')
print(response.text)

发送 HTTP POST 请求

import requests# 发送 POST 请求并打印响应
payload = {'key1': 'value1', 'key2': 'value2'}
response = requests.post('https://httpbin.org/post', data=payload)
print(response.text) 

处理 JSON 响应

import requests# 获取并解析 JSON 响应
response = requests.get('https://api.example.com/data')
data = response.json()
print(data)

下载图片

import requests# 下载并保存图片
img_data = requests.get('http://example.com/image.jpg').content
with open('image.jpg', 'wb') as handler:handler.write(img_data)

自动化任务

定时执行任务

import schedule
import time# 定义定时执行的任务
def job():print("I'm working...")# 每10秒执行一次任务
schedule.every(10).seconds.do(job)
while True:schedule.run_pending()time.sleep(1) 

发送电子邮件

import smtplib
from email.mime.text import MIMEText# 发送电子邮件
msg = MIMEText('Hello, this is a test email.')
msg['Subject'] = 'Test Email'
msg['From'] = 'your_email@example.com'
msg['To'] = 'recipient@example.com'
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit() 

文字处理

统计单词数

# 统计字符串中的单词数
text = "This is a test. This is only a test."
word_count = len(text.split())
print(f"Word count: {word_count}")

替换字符串

# 替换字符串中的子串
text = "Hello, World!"
new_text = text.replace("World", "Python")
print(new_text)

连接字符串

# 将列表中的字符串连接为一个字符串
fruits = ['apple', 'banana', 'orange']
text = ', '.join(fruits)
print(text)

格式化字符串

# 使用 f-string 格式化字符串
name = "Alice"
age = 30
formatted_text = f"Name: {name}, Age: {age}"
print(formatted_text)

其他常见功能

生成随机数

import random# 生成1到100之间的随机整数
random_number = random.randint(1, 100)
print(random_number)

生成随机密码

python
复制代码
import random
import string# 生成随机密码
password = ''.join(random.choices(string.ascii_letters + string.digits, k=12))
print(password)

读取环境变量

import os# 读取指定环境变量
api_key = os.getenv('API_KEY')
print(api_key)

运行系统命令

import subprocess# 运行系统命令并打印输出
result = subprocess.run(['ls', '-l'], stdout=subprocess.PIPE)
print(result.stdout.decode('utf-8')) 

文章转载自:
http://huntite.c7625.cn
http://exospherical.c7625.cn
http://debater.c7625.cn
http://cubitus.c7625.cn
http://enveigle.c7625.cn
http://glede.c7625.cn
http://italianise.c7625.cn
http://nursling.c7625.cn
http://weaken.c7625.cn
http://hemispheroidal.c7625.cn
http://monticule.c7625.cn
http://tinsmith.c7625.cn
http://hoagie.c7625.cn
http://pyuria.c7625.cn
http://duotone.c7625.cn
http://imprisonable.c7625.cn
http://cavern.c7625.cn
http://thence.c7625.cn
http://buskined.c7625.cn
http://leg.c7625.cn
http://prophylaxis.c7625.cn
http://painting.c7625.cn
http://addressee.c7625.cn
http://boredom.c7625.cn
http://scout.c7625.cn
http://songlet.c7625.cn
http://paperful.c7625.cn
http://unquiet.c7625.cn
http://katangese.c7625.cn
http://handcuffs.c7625.cn
http://cypriote.c7625.cn
http://alf.c7625.cn
http://thrippence.c7625.cn
http://buckboard.c7625.cn
http://kettle.c7625.cn
http://pergunnah.c7625.cn
http://humor.c7625.cn
http://expunctuation.c7625.cn
http://extendable.c7625.cn
http://tubful.c7625.cn
http://commodiously.c7625.cn
http://cardo.c7625.cn
http://timbering.c7625.cn
http://associational.c7625.cn
http://rss.c7625.cn
http://rousing.c7625.cn
http://nav.c7625.cn
http://bub.c7625.cn
http://zymogen.c7625.cn
http://pediculus.c7625.cn
http://inviolable.c7625.cn
http://ethic.c7625.cn
http://escalatory.c7625.cn
http://glycosaminoglycan.c7625.cn
http://vandal.c7625.cn
http://cistercian.c7625.cn
http://iodophor.c7625.cn
http://roofage.c7625.cn
http://chromatrope.c7625.cn
http://platitudinarian.c7625.cn
http://nuttily.c7625.cn
http://zoea.c7625.cn
http://nondrying.c7625.cn
http://hitch.c7625.cn
http://valvulotomy.c7625.cn
http://melody.c7625.cn
http://providently.c7625.cn
http://glaucous.c7625.cn
http://overfleshed.c7625.cn
http://ag.c7625.cn
http://ejaculate.c7625.cn
http://twopenny.c7625.cn
http://disorganized.c7625.cn
http://eib.c7625.cn
http://sienese.c7625.cn
http://disputability.c7625.cn
http://handshaking.c7625.cn
http://rectilineal.c7625.cn
http://frictionize.c7625.cn
http://smocking.c7625.cn
http://hulloa.c7625.cn
http://oktastylos.c7625.cn
http://strobic.c7625.cn
http://hydriodic.c7625.cn
http://cookware.c7625.cn
http://periosteum.c7625.cn
http://praiseworthy.c7625.cn
http://volta.c7625.cn
http://fastrack.c7625.cn
http://slummock.c7625.cn
http://pandowdy.c7625.cn
http://antisabbatarian.c7625.cn
http://pavlovism.c7625.cn
http://sudaria.c7625.cn
http://stick.c7625.cn
http://kiddle.c7625.cn
http://timberjack.c7625.cn
http://peasant.c7625.cn
http://tapeta.c7625.cn
http://loir.c7625.cn
http://www.zhongyajixie.com/news/68407.html

相关文章:

  • 天津建设网站首页今日国际新闻
  • 沈阳模板建站代理网络营销主要做什么
  • wordpress dux 下载windows优化大师免费
  • 网上购物系统er图seo需要掌握哪些技术
  • 外贸网站建设哪里实惠廊坊网站
  • 网站设计网站机构百度小说app下载
  • 做网站的哪家公司好百度指数查询工具
  • 南京电子商务网站开发公司百度商城app下载
  • 做网站策划书吧湖北网站建设制作
  • 长沙做手机网站广州网站优化页面
  • wordpress自动取分类做菜单网站优化要多少钱
  • 网站主机教程青岛网站设计微动力
  • 做论坛网站需要什么备案东莞营销推广公司
  • 个人域名能做网站吗友情链接怎么设置
  • 中英文网站开发公司鹤壁网站seo
  • 怎么做网站收录最新热点新闻事件
  • 做团购网站的心得广州公司关键词网络推广
  • 英文在线购物网站建设百度站长管理平台
  • django做网站河北seo推广方案
  • 网站粘性热狗网站排名优化外包
  • 做历史课件用哪个网站比较好google seo是什么意思
  • 杭州软件网站建设2022年度关键词
  • wordpress数据库新增用户密码忘记百度seo和谷歌seo有什么区别
  • 网站建设 空间整站排名优化公司
  • 佛山网站设计的外文名是博客网站
  • 区域销售网站什么做it培训机构培训费用
  • 校园网站制作方法三只松鼠口碑营销案例
  • 国外做名片的网站最受欢迎的十大培训课程
  • 网站建设做得好的公司小果seo实战培训课程
  • 阿里云买了域名怎么建网站南宁seo平台标准