python根据excel内容生成文件夹

python根据excel内容生成文件夹 工作需要根据excel数据信息,生成对应的文件夹,用python写了一个脚本处理了一下。 样例中表格内容也进行了调整。 环境: windows10 python3.7 + openpyxl 目标: 以list.xlsx数据为准,抽取指定sheet页中的指定字段信息,生成目录, 并在目录中创建固定的子目录. 表格格式: 表格sheet-A01 序号 项目名称 备注 1 项目1 张三 2 项目2 李四 表格sheet-A02 序号 项目名称 备注 1 项目1 王五 每一个sheet存放一个批次的任务信息, total为批次名称 代码: from openpyxl import load_workbook from openpyxl import Workbook import os import re ## 获取项目清单列表 wb = load_workbook( filename = '.\\test\\list.xlsx') #ws_in = wb_in.active outpath=".\\out\\" ## 名字列表开始结束行号 start_index = 4 ##end_index = ## 目录编号 dir_no = 1 ## 1. 找到指定的sheet页面 sheets_name = ['A01', 'A02'] ## 3. 组成符合要求的目录字符串创建目录 def mkdir(path): try: os.makedirs(path) print("CREATE") except FileExistsError: print("EXIST, NO CREATE") # Get all dirs def mksubdir(path): try: dirnames = [name for name in os.listdir('.\\model') if os.path.isdir(os.path.join('.\\model', name))] for i in dirnames: mkdir(path+"\\"+i) except : print(" CREATE SUB DIR ERROR ") for i in range(len(sheets_name)): print(i) sheet = wb[sheets_name[i]] print(sheet) ## 2. 找到相关的任务信息 for row in range(start_index, sheet.max_row+1): ## 1. 判断内容是否空格 0 or 1? if (str(sheet.cell(row, column=1).value).strip() == "None" ): print(batch_no + " is over") break; ##2. 获取表格内容生成目录 task_no = sheet.cell(row, column=1).value batch_no = sheet.title.split('-')[0] task_context = str(sheet.cell(row, column=2).value).strip() task_manager = re.search(r'张三|李四|王五', sheet.cell(row,column=3).value) task_leader = task_manager.group(0) #(序号)-批次号-批次序号-任务名称(负责人) # mkdir(path) dir_no_str = format(dir_no, '02d') task_no_str = format(task_no, '02d') dirname=dir_no_str+"-"+batch_no+"-"+task_no_str+"-"+task_context+"-"+task_leader mkdir(outpath+dirname) # mksubdir(path) mksubdir(outpath+dirname) dir_no = dir_no+1 运行结果 ├─01-A01-01-项目1-张三 │ ├─01_文档目录1 │ └─02_文档目录2 ├─02-A01-02-项目2-李四 │ ├─01_文档目录1 │ └─02_文档目录2 └─03-A02-01-项目3-王五 ├─01_文档目录1 └─02_文档目录2 ...

2020-05-01 · 2 min · 214 words

通过inode删除特殊字符文件

对于正常使用rm无法删除的文件可以通过查找inode进行删除 ls -i find -inum xxx -delete or ls -i find -inum xxx -exec rm -i {} \; 直接删除 [root@centosgpt vm]# ls -i 2278688 > 13592459 memdump2.c~ 13592454 memzero 7506486 test.c~ 2275894 118902.mem 2275882 memdump2.py 13592461 memzero.c 9733651 translate ... [root@centosgpt vm]# find -inum 2278688 -delete [root@centosgpt vm]# ls 118902.mem idle.py~ memdump3.c memory_layout processwrite.c test.c~ vsyscall.c 18 memdump memdump4 memory_layout.c processwrite.c~ translate 交互式 [root@centosgpt vm]# ls -i 7506464 > 13592459 memdump2.c~ 13592454 memzero 7506486 test.c~ 2275894 118902.mem 2275882 memdump2.py 13592461 memzero.c 9733651 translate [root@centosgpt vm]# find -inum 7506464 -exec rm -i {} \; rm: remove regular empty file ‘./>’? y [root@centosgpt vm]# ls 118902.mem idle.py~ memdump3.c memory_layout processwrite.c test.c~ vsyscall.c 18 memdump memdump4 memory_layout.c processwrite.c~ translate

2020-04-16 · 1 min · 116 words

python汇总excel数据

工作需要汇总整理相关excel数据信息,并按照规定格式进行反馈,用python写了一个脚本处理了一下。 样例中表格内容也进行了调整。 环境: windows10 python3.7 + openpyxl 目标: 以data1数据为准,通过查找data2补全相关信息, 将数据填入要求的result文件中。 表格格式: 表格1 data1.xlsx 姓名 张三 李四 表格2 data2.xlsx 序号 姓 名 性别 身份证号 联系电话 01 张三 男 130012345678901234 13911111111 02 李四 男 123012345678901234 13922222222 03 王五 男 123012345678901234 13933333333 表格3 result.xlsx 序号 所属部门 厂商 姓名 身份证号 联系电话 备注 代码: from openpyxl import load_workbook from openpyxl import Workbook import pandas as pd wb_in = load_workbook( filename = '.\\test\\data1.xlsx') ws_in = wb_in.active ## 名字列表开始结束行号 start_index = 2 end_index = 4 wb_info = load_workbook( filename = '.\\test\\data2.xlsx') ws_info = wb_info.active wb_out = load_workbook( filename = '.\\test\\result.xlsx') ws_out = wb_out.active out_index = 2 ## 找到要统计人员姓名 for x in range(start_index,end_index): name = ws_in.cell(row=x,column=1) print(name.value) ## 查找要统计人员附件信息并更新到统计表格中 find_flag = 0 for row in ws_info.iter_rows("B"): for col in row: #print(col.value) if (str(col.value).strip() == str(name.value).strip()) and (find_flag == 0): ## 第四列 身份证 第五列 联系电话 idno = ws_info.cell(row=col.row,column=4) phoneno = ws_info.cell(row=col.row, column=5) ## 更新到统计文件 ws_out['A'+ str(out_index)].value = str(out_index-1) ws_out['B'+ str(out_index)].value = 'XX部' ws_out['C'+ str(out_index)].value = 'XXX' ws_out['D'+ str(out_index)].value = name.value ws_out['E'+ str(out_index)].value = idno.value ws_out['F'+ str(out_index)].value = phoneno.value out_index = out_index + 1 find_flag = 1 break if find_flag == 0: print(name.value) wb_out.save( filename = '.\\test\\result.xlsx') 运行结果 序号 所属部门 厂商 姓名 身份证号 联系电话 备注 1 XX部 XXX 张三 130012345678901234 13911111111 2 XX部 XXX 李四 130012345678901234 13922222222 参考 Openpyxl Doc Using openpyxl to find rows that contain cell with specific value (Python 3.6)

2020-01-31 · 2 min · 223 words

putty免密登录SSH服务

环境 cenos7(X86_64) + openssh windows10 putty 配置 生成公私钥对 - 使用puttygen.exe生成公私钥对; 1. 运行puttygen.exe 点击 Generate按钮, 鼠标在进度条下方的窗口空白区移动生成公私钥对。 2. 分别点击 Save public key,Save private key导出后保存在本地. 安装公钥到远程服务器 公钥上传server, 相应用户目录下, 生成authorized_keys文件; mkdir .ssh ssh-keygen -i -f mypublickey >> .ssh/authorized_keys 其中mypublickey,为上一个步骤保存的公钥文件 配置putty 载入服务器配置信息 Session 选项卡片 Load按钮,载入要登录服务器信息 登录用户 Connection - Data选项,Auto-login username 输入登录使用的用户名 配置私钥 Connection - SSH - Auth选项卡片中, 点击Browse按钮选择之前导出私钥文件 保存信息 Session 选项卡片 Save按钮,保存登录服务器信息配置步骤: 常见问题 Server refused our key: 由于目录权限问题到导致可以通过以下命令处理: $ chmod 700 ~/.ssh $ chmod 600 ~/.ssh/authorized_keys ...

2019-12-31 · 1 min · 92 words

Linux Swap 分区相关命令

/proc/swaps 文件 # cat /proc/swaps Filename Type Size Used Priority /dev/dm-1 partition 4194300 0 -2 /proc/meminfo 文件 # grep Swap /proc/meminfo SwapCached: 0 kB SwapTotal: 4194300 kB SwapFree: 4194300 kB swapon # swapon -s Filename Type Size Used Priority /dev/dm-1 partition 4194300 0 -2 free free -g/-k/-m # free -g total used free shared buff/cache available Mem: 1 0 0 0 1 1 Swap: 3 0 3 vmstat # vmstat procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 130536 172 1654888 0 0 0 3 1 23 0 0 100 0 0 top/atop/htop/glance 参考引用 How To Check Swap Usage Size and Utilization in Linux

2019-11-03 · 1 min · 122 words

查看进程内存布局

进程内存布局 可以通过一下方法查看: 命令: pmap 文件: proc filesystem maps 使用 pmap 可以从其说明看到 -X 也是从/proc/PID/smaps获取了更详细的信息 [root@centosgpt ~]# pmap 1704 1704: -bash 0000000000400000 884K r-x-- bash 00000000006dd000 4K r---- bash 00000000006de000 36K rw--- bash ... 00007f3c65515000 28K r--s- gconv-modules.cache 00007f3c6551c000 4K rw--- [ anon ] 00007f3c6551d000 4K r---- ld-2.17.so 00007f3c6551e000 4K rw--- ld-2.17.so 00007f3c6551f000 4K rw--- [ anon ] 00007ffd64655000 132K rw--- [ stack ] 00007ffd64769000 12K r---- [ anon ] 00007ffd6476c000 4K r-x-- [ anon ] ffffffffff600000 4K r-x-- [ anon ] total 115580K 查看 proc filesystem maps /proc/PID/smaps ...

2019-10-19 · 1 min · 151 words

进程中线程查看及线程栈查看

进程线程查看 可以通过一下方法查看: 命令: ps top pidstat pstree 文件: proc filesystem 使用 ps ps与线程相关的参数 THREAD DISPLAY H Show threads as if they were processes. -L Show threads, possibly with LWP and NLWP columns. m Show threads after processes. -m Show threads after processes. -T Show threads, possibly with SPID column. 使用-L ps -eLo pid,tid,tgid,pgrp,args [root@centosgpt ~]# ps -eLo pid,tid,tgid,pgrp,args|grep python 1173 1173 1173 1173 /usr/bin/python -Es /usr/sbin/tuned -l -P 1173 1594 1173 1173 /usr/bin/python -Es /usr/sbin/tuned -l -P 1173 1595 1173 1173 /usr/bin/python -Es /usr/sbin/tuned -l -P 1173 1596 1173 1173 /usr/bin/python -Es /usr/sbin/tuned -l -P 1173 1613 1173 1173 /usr/bin/python -Es /usr/sbin/tuned -l -P 77189 77189 77189 77188 grep --color=auto python 使用-m显示 ps -mLe ...

2019-10-12 · 10 min · 2039 words

Graph-Easy ascii图片绘制

安装 环境: cenos7, X86_64 kernel: 3.10.0-862.el7.x86_64 依赖安装包 1) graphviz, perl-ExtUtils-MakeMaker yum install graphviz yum install perl-ExtUtils-MakeMaker 2) 通过cpan进行安装 perl-CPAN.noarch yum install perl-CPAN 3) 运行cpan cpan> install Graph::Easy ... Reading '/root/.cpan/sources/modules/03modlist.data.gz' DONE Writing /root/.cpan/Metadata Graph::Easy is up to date (0.76). 下载安装包安装 1) 通过https://metacpan.org查找,Graph::Easy下载, 验证时需要安装 Test::More wget https://cpan.metacpan.org/authors/id/S/SH/SHLOMIF/Graph-Easy-0.76.tar.gz wget https://cpan.metacpan.org/authors/id/E/EX/EXODIST/Test-Simple-1.302168.tar.gz 2) 编译 $ tar -zxvf Test-Simple-1.302167.tar.gz $ cd Test-Simple-1.302167 $ make install $ tar -zxvf Graph-Easy-0.76.tar.gz $ perl Makefile.PL $ make test $ make install demo 画个图验证一下 ...

2019-09-07 · 1 min · 208 words

Linux 与 Windows 文本文件格式转换

问题 由于Windows与Linux对换行的定义不同,导致Windows应用不能正常按行显示Linux文本,Linux显示Windows文本时会带有^M 解决方法 下面整理一些常用的工具和处理方法: ftp : 服务端支持ASCII模式,使用ftp命令可以实现文本换行之间的转换。(由于ASCII存在一些安全隐患,所以部分ftp服务默认关闭ASCII模式传输)。 vi/vim: :%s/^M//g ^M: ctrl+v, ctrl+m awk: awk '{ sub("\r$", ""); print }' windows.txt > linux.txt awk 'sub("$", "\r")' linux.txt > windows.txt tr: tr -d '\r' < windows.txt > linux.txt sed: $ sed -e 's/$/\r/' linux.txt > windows.txt $ sed -e 's/\r$//' windows.txt > linux.txt perl $ perl -pe 's/\r?\n|\r/\r\n/g' test.txt > windows.txt $ perl -pe 's/\r?\n|\r/\n/g' test.txt > linux.txt $ perl -pe 's/\r?\n|\r/\r/g' test.txt > mac.txt test.txt可以是windows也可以是linux 相关其他命令 file $ file windows.txt windows.txt: ASCII text, with CRLF line terminators $ file linux.txt linux.txt: ASCII text $ file mac.txt mac.txt: ASCII text, with CR line terminators od $ od -a windows.txt 0000000 t e s t cr nl $ od -a linux.txt 0000000 t e s t nl cat $ cat -e windows.txt test^M$ $ cat -e linux.txt test$ hexdump $ hexdump -c windows.txt 0000000 t e s t \r \n $ hexdump -c linux.txt 0000000 t e s t \n

2019-09-01 · 1 min · 157 words

awk中的'数组'

awk中的’数组‘是一种关联数组,又称作maps、字典,他的索引不需要连续, 可以使用字符串、数字做为索引, 此外,不需要事先声明数组的大小 - 数组可以在运行时扩展/收缩。 语法: 赋值: array_name[index] = value 删除: delete array_name[index] 多维数组(使用字符串模拟) array["0,0"] = 100 遍历: for (var in arrayname) actions 实例 统计汇总 数据:Iplogs.txt 180607 093423 123.12.23.122 133 180607 121234 125.25.45.221 153 190607 084849 202.178.23.4 44 190607 084859 164.78.22.64 12 200607 012312 202.188.3.2 13 210607 084849 202.178.23.4 34 210607 121435 202.178.23.4 32 210607 132423 202.188.3.2 167 total.awk: { Ip[$3]++; } END { for (var in Ip) print var, "access", Ip[var]," times" } 注意下END后的{需要和END在一行 输出: $ awk -f total.awk Iplogs.txt 123.12.23.122 access 1 times 164.78.22.64 access 1 times 202.188.3.2 access 2 times 125.25.45.221 access 1 times 202.178.23.4 access 3 times 说明: $3是一个IP地址, Ip做为数组的索引。 对于每一行,它会增加相应IP地址索引的值。 最后在END部分中,所有索引都将是唯一IP地址的列表,其对应的值是出现次数。 ...

2019-08-31 · 3 min · 574 words