做交易,一根均线上多下空,能做到稳定盈利?是“大道至简”,还是嘴盘忽悠?Python量化交易均线策略测试二

本文主要是介绍做交易,一根均线上多下空,能做到稳定盈利?是“大道至简”,还是嘴盘忽悠?Python量化交易均线策略测试二,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

 
参考视频教程:  
 **首门程序员理财课 Python量化交易系统实战  **
交易,一根均线上多下空,能做到稳定盈利?是"大道至简",还是嘴盘忽悠?Python量化交易均线策略测试一中,我们用python程序量化测试了10日均线,50日均线作为单根均线策略,测试发现收益十分不理想。

今天我们继续对单根均线策略做量化测试,今天突然想起昨天的测试还有60日均线没有做量化测试,为什么要测试60日均线,因为60日均线太有名了,外号有牛熊分界线,万能均线,生命线等。

仅仅以股价大于60均线作为买入条件,最近三年收益如下:



60均线最近三年收益

我们再把昨天python量化交易测试的10日均线,50日均线收益图贴在下面,很明显60日均线收益确实整体要稍微好一些。



10日均线,最近三年收益



50日均线,最近三年收益

我们对60日均线策略买点做一些优化

1.股价大于60日均线,且均线趋势向上

2.股价大于30日均线,且均线趋势向上

3.股价大于10日均线,且均线趋势向上

回测最近三年收益如下:


擦,貌似越优化收益越差,这也是意料之外的事情,这个优化策略,是我在百度找的一篇洋洋洒洒写了1万多字,图文并茂,貌似,看起来大神给的策略,看起来大神给的策略,量化交易回测不行啊,未完待续。。。。。。

如果你有策略愿意让我量化测试一下,请加公众号:Python量化交易探索,留言告诉我。

60日均线策略,python量化交易代码如下:

-*- coding: utf-8 -*-

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

import os

import shutil

import time

import matplotlib

def danjunxian(start,end):

mairuhou_mark = 0

zhengshouyi_num = 0

fushouyi_num = 0

cur_dir = os.getcwd() # get current path

folder_name = ‘result’

dir_new = os.path.join(cur_dir, folder_name)

end_date = [‘2019/12/31’,‘2019/12/30’,‘2019/12/29’,‘2019/12/28’]

删掉结果

if os.path.exists(dir_new + “\\” + start.replace(“/”,“_”) + “__” + end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’):

os.remove(dir_new + “\\” + start.replace(“/”,“_”) + “__” + end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’)

if os.path.exists(dir_new + “\\” + start.replace(“/”,“_”) + “__” + end.replace(“/”,“_”) + “dangtian_buy” +‘.txt’):

os.remove(dir_new + “\\” + start.replace(“/”,“_”) + “__” + end.replace(“/”,“_”) + “dangtian_buy” +‘.txt’)

if os.path.exists(dir_new + “\\” + start.replace(“/”,“_”) + “__” + end.replace(“/”,“_”) + ‘“dangtian_sell”’ +‘.txt’):

os.remove(dir_new + “\\” + start.replace(“/”,“_”) + “__” + end.replace(“/”,“_”) + ‘“dangtian_sell”’ +‘.txt’)

设置路径

dir_list = []

lujing = r’C:\gupiao\gupiaoci’

for i in os.listdir(r’C:\gupiao\gupiaoci’):

a = i.split(‘.’)[0]

if a[0] != ‘3’:

dir_list.append(lujing+‘\\’+i)

个股

total_shouyi=1

total_date_buy = []

total_date_sell = []

buy_date_zhengshouyi = []

buy_date_fushouyi = []

for j in dir_list:

获取数据

name = (j.split(‘\\’)[-1]).split(‘.’)[0]

df = pd.read_table(j,header=1,usecols=range(6), parse_dates=[0], index_col=0,encoding=‘gb2312’)

df.index.rename(‘date’, inplace=True)

df.rename(columns={’ 开盘’:‘open’, ’ 最高’:‘high’, ’ 最低’:‘low’, ’ 收盘’:‘close’,’ 成交量’:‘vol’}, inplace=True)

df = df.drop(‘数据来源:通达信’)

df.close = df.close.astype(np.float32)#设置为32位,4字节,默认64位,8字节,append到list之后就会多小数位

df.low = df.low.astype(np.float32)#设置为32位,4字节,默认64位,8字节,append到list之后就会多小数位

df.vol = df.vol.astype(np.int64)

df2 = df[start:end][:len(df.vol)-1]

df = df[start:end]

均线

ma5 = df2.close.rolling(window=5,center=False).mean()

ma5= ma5[start:end]

ma3 = df2.close.rolling(window=3,center=False).mean()

ma3= ma3[start:end]

ma8 = df2.close.rolling(window=8, center=False).mean()

ma8 = ma8[start:end]

ma15 = df2.close.rolling(window=15, center=False).mean()

ma15 = ma15[start:end]

ma10 = df2.close.rolling(window=10,center=False).mean()

ma10= ma10[start:end]

ma12 = df2.close.rolling(window=12, center=False).mean()

ma12 = ma12[start:end]

ma20 = df2.close.rolling(window=20,center=False).mean()

ma20= ma20[start:end]

ma30 = df2.close.rolling(window=30,center=False).mean()

ma30 = ma30[start:end]

ma60 = df2.close.rolling(window=60,center=False).mean()

ma60 = ma60[start:end]

ma120 = df2.close.rolling(window=120,center=False).mean()

ma120 = ma120[start:end]

ma200 = df2.close.rolling(window=200, center=False).mean()

ma200 = ma200[start:end]

ma250 = df2.close.rolling(window=250,center=False).mean()

ma250 = ma250[start:end]

均量线

vol5 = df2.vol.rolling(window=5,center=False).mean()

vol5 = vol5[start:end]

vol3 = df2.vol.rolling(window=3,center=False).mean()

vol3 = vol3[start:end]

vol8 = df2.vol.rolling(window=8,center=False).mean()

vol8 = vol8[start:end]

vol10 = df2.vol.rolling(window=10,center=False).mean()

vol10 = vol10[start:end]

vol20 = df2.vol.rolling(window=20,center=False).mean()

vol20 = vol20[start:end]

vol15 = df2.vol.rolling(window=15,center=False).mean()

vol15 = vol15[start:end]

vol30 = df2.vol.rolling(window=30,center=False).mean()

vol30 = vol30[start:end]

vol60 = df2.vol.rolling(window=60, center=False).mean()

vol60 = vol60[start:end]

设置初始化数据

买入条件,buy_status = True,其次是chicang_status = False

chicang_status = False#chicang_status==False的时候表示空仓状态,可以买入,买入之后需要将其设置为True,表示股票为持有状态

buy_status = False#初始化buy的状态为False,当遇到买点出现时,设置状态为True,表示之后可以买入

buy_price = []

buy_date = []

sell_price = []

sell_date = []

low_vol = []

low_vol_index = []


fengexian_mark = 0

low_vol

df_temp = df

temp_vol = df.vol

temp_index = df.index

ma3_temp = ma3

ma5_temp = ma5

ma8_temp = ma8

ma15_temp = ma15

ma10_temp = ma10

ma12_temp = ma12

ma20_temp = ma20

ma30_temp = ma30

ma60_temp = ma60

ma120_temp = ma120

ma200_temp = ma200

ma250_temp = ma250

vol5_temp = vol5

vol3_temp = vol3

vol8_temp = vol8

vol15_temp = vol15

vol10_temp = vol10

vol20_temp = vol20

vol30_temp = vol30

vol60_temp = vol60

temp_vol_max = 0


for j in range(60,len(temp_vol)):

if buy_status == False and chicang_status == False:

buy_status = True#买点出现时,设置状态为True,表示之后可以买入

vol_max_dangtian_index = temp_index[j]

close_min_new = df_temp.close[j]

elif buy_status == True and chicang_status == False:

if df_temp.at[temp_index[j-1],‘close’] >= 300 or (df_temp.high[j]-df_temp.close[j-1])/df_temp.close[j-1] < -0.09:

chicang_status = False

buy_status = False

break

elif df_temp.close[j] > ma60_temp[j]:#股价大于60均线​,买入

if len(gupiaochichang) >= 1:

for gupiaochichang_item in gupiaochichang:

if gupiaochichang_item[0] == temp_index[j] and gupiaochichang_item[1] >= 1:

print(gupiaochichang_item)

chicang_status = False

buy_status = False

if chicang_status == False and buy_status == False:

continue

chicang_status = True

buy_status = False#买入之后设置状态为False

buy_price_m = df_temp.at[temp_index[j],‘close’]

buy_date_temp = temp_index[j]

buy_price.append(df_temp.at[temp_index[j],‘close’])

buy_date.append(temp_index[j])

total_date_buy.append([name,temp_index[j]])

fengexian_mark = 1

close_max = df_temp.close[j]#加入买入当天就是当前最高价

股票持仓,买日期加1,买日期不在list,则加入

for gupiaochichuang_item in gupiaochichang:

if gupiaochichuang_item[0] == temp_index[j]:

gupiaochichuang_item[1] += 1

if len(gupiaochichang) == 0:

gupiaochichang.append([temp_index[j],1])

else:

for i22 in range(len(gupiaochichang)):

if len(gupiaochichang) != 0 and i22 == len(gupiaochichang) -1 and gupiaochichang[i22][0] != temp_index[j]:#找到最后一个还没有找到买日期,加将买日期加入

gupiaochichang.append([temp_index[j],1])

存结果

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’,‘a’) as f:

f.write(“股票名称–” + name + ‘\n’ + “开始日期–” + start + ‘\n’ + “结束日期–” + end + ‘\n’ )

f.write(“最大vol/当天vol 大于20当天日期—–>” + str(vol_max_dangtian_index) + ‘\n’)

f.write(‘\n’ + “股票名称–” + name + “–买入价格–” + “–步长–” + “–” + “–j–” + str(j) + “–” + str(df_temp.at[temp_index[j],‘close’]) + “–买入日期–” + str(temp_index[j]))

elif chicang_status == True:

if df_temp.close[j] < ma10_temp[j]:#股价小于10日均线卖出

chicang_status = False

sell_price.append(df_temp.close[j])

sell_date.append(temp_index[j])

total_date_sell.append([name,temp_index[j]])

if (df_temp.close[j]-buy_price_m)/buy_price_m > 0:

zhengshouyi_num += 1#正收益次数加1

buy_date_zhengshouyi.append(buy_date_temp)

else:

fushouyi_num += 1#负收益次数加1

buy_date_fushouyi.append(buy_date_temp)

total_shouyi *= (1 + (df_temp.close[j]-buy_price_m)/buy_price_m)

mairuhou_mark = 0

存结果

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’,‘a’) as f:

f.write(‘\n’ + “股票名称–” + name + “–最高点下跌10%,卖出价格–” + “–步长–” + “–” + “–j–” + str(j) + “–” + str(df_temp.close[j]) + “–卖出日期–” + str(temp_index[j]))

elif (df_temp.close[j] - buy_price_m)/buy_price_m < -0.05:

chicang_status = False

sell_price.append(df_temp.close[j])

sell_date.append(temp_index[j])

total_date_sell.append([name,temp_index[j]])

fushouyi_num += 1#负收益次数加1

total_shouyi *= (1 - 0.05)

mairuhou_mark = 0

buy_date_fushouyi.append([name,buy_date_temp])

buy_date_fushouyi.append(buy_date_temp)

存结果

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’,‘a’) as f:

f.write(‘\n’ + “股票名称–” + name + “–止损-0.05,卖出价格–” + “–步长–” + “–” + “–j–” + str(j) + “–” + str(df_temp.close[j]) + “–卖出日期–” + str(temp_index[j]))

elif mairuhou_mark >= 10:

total_shouyi *= (1 + (df_temp.close[j] - buy_price_m)/buy_price_m)

chicang_status = False

sell_price.append(df_temp.close[j])

sell_date.append(temp_index[j])

total_date_sell.append([name,temp_index[j]])

mairuhou_mark = 0

if (df_temp.close[j] - buy_price_m)/(buy_price_m) > 0:

zhengshouyi_num += 1

buy_date_zhengshouyi.append(buy_date_temp)

print(“持有超过10天卖出:”,(df_temp.close[j] - buy_price_m)/(buy_price_m))

存结果

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’,‘a’) as f:

f.write(‘\n’ + “股票名称–” + name + “–持有超过5天卖出,大于0.01,卖出价格–” + “–” + “–j–” + str(j) + “–” + str(df_temp.close[j]) + “–卖出日期–” + str(temp_index[j]))

else:

fushouyi_num += 1

buy_date_fushouyi.append(buy_date_temp)

print(“持有超过10天卖出:”,(df_temp.close[j] - buy_price_m) / (buy_price_m ))

存结果

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’,‘a’) as f:

f.write(‘\n’ + “股票名称–” + name + “–持有超过15天卖出,小于0.01,大于0,卖出价格–” + “–j–” + str(j) + “–” + str(df_temp.close[j]) + “–卖出日期–” + str(temp_index[j]))

else:

mairuhou_mark += 1

gupiaochichang.sort(key=lambda x:x[0])

if zhengshouyi_num+fushouyi_num != 0:

print(start,“—-”,end,“total_shouyi=”,‘%.2f’%(total_shouyi),“概率”,‘%.2f’%(zhengshouyi_num/(zhengshouyi_num+fushouyi_num)),“正收益次数->”,zhengshouyi_num,“负收益次数->”,fushouyi_num)

存结果

cur_dir = os.getcwd() # get current path

folder_name = ‘result’

dir_new = os.path.join(cur_dir, folder_name)

存买入,卖出价格,日期

if len(buy_price) > len(sell_price):

if buy_date[-1] in end_date:

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “dangtian_buy” +‘.txt’,‘a’) as f:

f.writelines(‘\n’ + name + “–” + str(buy_date[-1]) + ‘\n’ + ’buy: ’ + str(buy_price[-1]) + ‘\n’)

if len(sell_price) != 0:

if sell_date[-1] in end_date:

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “dangtian_sell” +‘.txt’,‘a’) as f:

for rr in range(len(sell_price)):

if rr == 0:

f.writelines(‘\n’ + name + ‘\n’ + ’buy: ’ + str(buy_price[rr]) + str(buy_date[rr]) + ‘\n’ + ’sell: ’ + str(sell_price[rr]) + str(sell_date[rr]) + ‘\n’)

else:

f.writelines( ’buy: ’ +str(buy_price[rr]) + str(buy_date[rr]) + ‘\n’ + ’sell: ’ + str(sell_price[rr]) + str(sell_date[rr]) + ‘\n’)

if zhengshouyi_num+fushouyi_num != 0:

zshouyi = float(zhengshouyi_num/(zhengshouyi_num+fushouyi_num))

fshouyi = float(fushouyi_num/(zhengshouyi_num+fushouyi_num))

total_num = zhengshouyi_num+fushouyi_num

total_date_buy.sort(key=lambda x:x[1])

total_date_sell.sort(key=lambda x:x[1])

x = []

y = []

for i in buy_date_zhengshouyi:

if i not in x:

x.append(i)

for i in buy_date_fushouyi:

if i not in y:

y.append(i)

if fengexian_mark == 1:

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” + end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’,‘a’) as f:

f.write(‘\n’ + ‘\n’ + “——————–分割线———————-” + ‘\n’ + ‘\n’)

buy_date_zhengshouyi_count = []

buy_date_fushouyi_count = []

i = 0

x.sort()

y.sort()

for i in x:

if buy_date_zhengshouyi.count(i) >= 0:

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’,‘a’) as f:

f.write(‘\n’ + “正收益买日期–” + str(buy_date_zhengshouyi.count(i)) + “–” +str(i))

buy_date_zhengshouyi_count.append(buy_date_zhengshouyi.count(i))

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’,‘a’) as f:

f.write(‘\n’ )

for i in y:

if buy_date_fushouyi.count(i) >= 0:

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’,‘a’) as f:

f.write(‘\n’ + “负收益买日期–” + str(buy_date_fushouyi.count(i)) + “–” +str(i))

buy_date_fushouyi_count.append(buy_date_fushouyi.count(i))

if zhengshouyi_num+fushouyi_num != 0:

print(start,“—-”,end,“total_shouyi=”,‘%.2f’%(total_shouyi),“概率”,‘%.2f’%(zhengshouyi_num/(zhengshouyi_num+fushouyi_num)),“正收益次数->”,zhengshouyi_num,“负收益次数->”,fushouyi_num)

with open(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’,‘a’) as f:

f.write(‘\n’ +‘\n’ + “正收益买日期count–” + str(len(buy_date_zhengshouyi_count)) + “–” + str(buy_date_zhengshouyi_count))

f.write(‘\n’ + “负收益买日期count–” + str(len(buy_date_fushouyi_count)) + “–” + str(buy_date_fushouyi_count))

f.write(‘\n’ + “买卖总次数” + str(zhengshouyi_num+fushouyi_num) + “–正收益买概率–” + str(‘%.2f’%(zhengshouyi_num/(zhengshouyi_num + fushouyi_num))) + “–正收益次数–” + str(zhengshouyi_num))

for i in range(len(gupiaochichang)):

if i == 0:

f.write(‘\n’ + “买日期count:” + ‘\n’ + str(gupiaochichang[i]))

else:

f.write(‘\n’ + str(gupiaochichang[i]))

shutil.copy(dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + “celie_xiangxi” + ‘.txt’,dir_new + “\\” + start.replace(“/”,“_”) + “__” +end.replace(“/”,“_”) + ‘_’ + “–正收益买概率–” + str(‘%.2f’%(zhengshouyi_num / (zhengshouyi_num + fushouyi_num))) + “–倍数–” + str(‘%.2f’%(total_shouyi))+ “–正收益次数–” + str(zhengshouyi_num) + “–负收益次数–” + str(fushouyi_num)+ ‘.txt’)

return [total_shouyi,zhengshouyi_num / (zhengshouyi_num + fushouyi_num)]

if name == ‘main’:

print(‘start’,time.strftime(“%Y-%m-%d %H:%M:%S”, time.localtime()))

cur_dir = os.getcwd() # get current path

folder_name = ‘result’

dir_new = os.path.join(cur_dir, folder_name)

start = [‘2016/09/01’,‘2017/09/01’,‘2018/09/01’]

end = [‘2017/12/31’,‘2018/12/31’,‘2019/12/31’]

gupiaochichang = []

total_shouyi_gailv = []

shouyi_huizong = []

gailv_huizong = []

for i in range(len(start)):

total_shouyi_gailv.append(danjunxian(start[i],end[i]))

for i in range(len(total_shouyi_gailv)):

shouyi_huizong.append(total_shouyi_gailv[i][0])

gailv_huizong.append(total_shouyi_gailv[i][1])

绘图

matplotlib.rcParams[‘font.family’] = ‘SimHei’ # SimHei黑体

matplotlib.rcParams[‘font.size’] = 10

dir_new = os.path.join(cur_dir, folder_name)

file_name = dir_new + r’/’ + ‘shouyi’

收益图

plt.subplots_adjust(hspace=0.5)

fig1 = plt.subplot(211)

fig1.set_title(“收益”)

设置坐标轴范围

fig1.set_xlim(-1, 3)

fig1.set_ylim(0, 50)

设置坐标轴名称

fig1.set_xlabel(‘日期’)

fig1.set_ylabel(‘收益’)

设置坐标轴刻度

fig1.set_xticks = np.arange(-1, 4, 1)

for a, b in zip(end, shouyi_huizong):

fig1.text(a, b + 0.1, ‘%.2f’ % b, ha=‘center’, va=‘bottom’, color=‘red’, fontsize=20)

fig1.plot(end, shouyi_huizong, color=‘blue’, marker=‘o’)

正收益概率图

fig2 = plt.subplot(212)

fig2.set_title(“收益概率”)

设置坐标轴范围

fig2.set_xlim(-1, 3)

fig2.set_ylim(0, 1.2)

设置坐标轴名称

fig2.set_xlabel(‘日期’)

fig2.set_ylabel(‘收益概率’)

设置坐标轴刻度

fig2.set_xticks = np.arange(-1, 4, 1)

for a, b in zip(end, gailv_huizong):

fig2.text(a, b + 0.1, ‘%.2f’ % b, ha=‘center’, va=‘bottom’, color=‘blue’, fontsize=20)

fig2.plot(end, gailv_huizong, color=‘blue’, marker=‘o’)

plt.savefig(file_name, dpi=300)

print(‘end’,time.strftime(“%Y-%m-%d %H:%M:%S”, time.localtime()))

这篇关于做交易,一根均线上多下空,能做到稳定盈利?是“大道至简”,还是嘴盘忽悠?Python量化交易均线策略测试二的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/1136458

相关文章

Python实现终端清屏的几种方式详解

《Python实现终端清屏的几种方式详解》在使用Python进行终端交互式编程时,我们经常需要清空当前终端屏幕的内容,本文为大家整理了几种常见的实现方法,有需要的小伙伴可以参考下... 目录方法一:使用 `os` 模块调用系统命令方法二:使用 `subprocess` 模块执行命令方法三:打印多个换行符模拟

Python实现MQTT通信的示例代码

《Python实现MQTT通信的示例代码》本文主要介绍了Python实现MQTT通信的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 安装paho-mqtt库‌2. 搭建MQTT代理服务器(Broker)‌‌3. pytho

基于Python开发一个图像水印批量添加工具

《基于Python开发一个图像水印批量添加工具》在当今数字化内容爆炸式增长的时代,图像版权保护已成为创作者和企业的核心需求,本方案将详细介绍一个基于PythonPIL库的工业级图像水印解决方案,有需要... 目录一、系统架构设计1.1 整体处理流程1.2 类结构设计(扩展版本)二、核心算法深入解析2.1 自

从入门到进阶讲解Python自动化Playwright实战指南

《从入门到进阶讲解Python自动化Playwright实战指南》Playwright是针对Python语言的纯自动化工具,它可以通过单个API自动执行Chromium,Firefox和WebKit... 目录Playwright 简介核心优势安装步骤观点与案例结合Playwright 核心功能从零开始学习

Python 字典 (Dictionary)使用详解

《Python字典(Dictionary)使用详解》字典是python中最重要,最常用的数据结构之一,它提供了高效的键值对存储和查找能力,:本文主要介绍Python字典(Dictionary)... 目录字典1.基本特性2.创建字典3.访问元素4.修改字典5.删除元素6.字典遍历7.字典的高级特性默认字典

Python自动化批量重命名与整理文件系统

《Python自动化批量重命名与整理文件系统》这篇文章主要为大家详细介绍了如何使用Python实现一个强大的文件批量重命名与整理工具,帮助开发者自动化这一繁琐过程,有需要的小伙伴可以了解下... 目录简介环境准备项目功能概述代码详细解析1. 导入必要的库2. 配置参数设置3. 创建日志系统4. 安全文件名处

使用Python构建一个高效的日志处理系统

《使用Python构建一个高效的日志处理系统》这篇文章主要为大家详细讲解了如何使用Python开发一个专业的日志分析工具,能够自动化处理、分析和可视化各类日志文件,大幅提升运维效率,需要的可以了解下... 目录环境准备工具功能概述完整代码实现代码深度解析1. 类设计与初始化2. 日志解析核心逻辑3. 文件处

python生成随机唯一id的几种实现方法

《python生成随机唯一id的几种实现方法》在Python中生成随机唯一ID有多种方法,根据不同的需求场景可以选择最适合的方案,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来一起学习学习... 目录方法 1:使用 UUID 模块(推荐)方法 2:使用 Secrets 模块(安全敏感场景)方法

使用Python删除Excel中的行列和单元格示例详解

《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定

Python通用唯一标识符模块uuid使用案例详解

《Python通用唯一标识符模块uuid使用案例详解》Pythonuuid模块用于生成128位全局唯一标识符,支持UUID1-5版本,适用于分布式系统、数据库主键等场景,需注意隐私、碰撞概率及存储优... 目录简介核心功能1. UUID版本2. UUID属性3. 命名空间使用场景1. 生成唯一标识符2. 数