#pip3 install xlrd,xlwt,openpyxl
import xlwt
# book=xlwt.Workbook()#创建对象
# sheet=book.add_sheet("sheet1")
# sheet.write(0,0,"id")
# sheet.write(1,0,"1")
# book.save("test.xls")#结尾用xls xlsx,用office打开有问题,用wps打开没有问题
l=[[1,"wendy","女","北京"],
[2,"candy","女","上海"],
[3,"GG","男","南昌"]
]
book=xlwt.Workbook()
sheet=book.add_sheet("学生信息表")
#表头
#内容
title=["id","name","性别","地址"]
col = 0
for k in title:
sheet.write(0,col,k)
col+=1
row = 1
for i in l:
col=0
for j in i:
sheet.write(row,col,j)
col+=1
row+=1
book.save("student.xls")
--------------------------------------------------
import shutil
# shutil.copyfile('old.txt','../day2/new.txt')#只能复制文件,且要有新文件名,文件名必须有
# shutil.copy('old.txt','../day2/')#把文件复制到XX路径下
# shutil.copy('old.txt','../day2/xx.txt')##把文件复制到XX路径下且名字叫xx.txt
# shutil.copytree("logs",'../day2/logs1')#复制文件夹
# shutil.rmtree('logs')#删除非空文件夹, 找不回来
#shutil.copy('pinyin.py','../day6/logs/text.txt')
import sys
#print(sys.version)获取当前Python的版本,返回的是字符串
# print(sys.version_info)获取当前Python的版本,返回的是元祖
# print(sys.platform)获取当前的操作系统
# sys.exit()#退出
print(sys.argv)#用户获取运行Python文件的时候传入的参数
print(sys.argv)
if len(sys.argv)>1:
command = sys.argv[1]
if command == "--help":
msg= """
这个程序是用来做自动化测试的
执行bin目录下的 start.py开始运行自动化测试
"""
print(msg)
elif command == "bak":
print("开始备份")
shutil.copyfile(sys.argv[0],"%s.bak" %sys.argv[0] )
else:
print("传入参数错误,请输入--help查看帮助")
else:
print("传入参数错误,请输入--help查看帮助")
------------------------------------------------
import xpinyin
name_pinyin_list = [] #存的是不重复的名字拼音
d = {} #存的是重复的名字和她出现的次数
all_name_list = s.split() #
p = xpinyin.Pinyin()
for name in all_name_list:
name_pinyin = p.get_pinyin(name,'')
if name_pinyin not in name_pinyin_list:
name_pinyin_list.append(name_pinyin)
else:
if name_pinyin not in d:
d[name_pinyin] = 1
else:
d[name_pinyin]+=1
for name,count in d.items():
for i in range(1,count+1): #1,4
new_name = "%s%s"%(name,i)
name_pinyin_list.append(new_name)
print(name_pinyin_list)
print(len(name_pinyin_list))
------------------------------------------
安装第三方模块:
1.手动安装
whl:
pip install xpinyin-0.7.6-py3-none-any.whl
tag.gz
解压
cd xpinyin-0.7.6
python setup.py
2.自动安装
python的安装目录,加入到环境变量里面
Python的安装目录下的scripts
Python3里面pip自带
pip install xpinyin
pip install xpinyin=0.5.6#指定版本
----------------------------
python2
easy_install xpinyin
easy_install pip#安装一下Python,就可以用pip
--------
C:\Anaconda3\python -m pip install xxxx#直接进入到目录下安装