入坑python 自己写的小工具,纪念一下

这个程序的功能是可以从表格中读取某一列数据,传到IDs 这一个参数里,然后在url中获取相应的请求值,并打印
import urllib.request
import json
import xlrd def read_excel():
# 打开文件
workbook = xlrd.open_workbook(r'G:\Python\est-export.xls')
# 获取所有sheet
print(workbook.sheet_names())# [u'sheet1', u'sheet2']
#获取sheet2
sheet2_name = workbook.sheet_names()[0]
print(sheet2_name)
# 根据sheet索引或者名称获取sheet内容
sheet2 = workbook.sheet_by_name('Sheet1')
# sheet的名称,行数,列数
print(sheet2.name,sheet2.nrows,sheet2.ncols)
rows = sheet2.row_values(3) # 获取第四行内容
cols = sheet2.col_values(2) # 获取第三列内容
print(rows)
print(",".join(cols))
return ",".join(cols)#去掉单引号 def getdata():
IDs = read_excel()
url = "http://XXX/ids?ids="+IDs
response = urllib.request.urlopen(url).read()
data = response.decode('utf-8')
reps = json.loads(data)
# print(data)
if reps["statuscode"] != 0:
print("查询失败")
nickNameList = []
for usersData in reps["usersdetailinfo"]:
username = usersData["username"]
name = usersData["nickname"]
nickNameList.append({"name": name, "username": username}) return nickNameList result = getdata()
for nickName in result:
print("用户姓名等信息,%s, %s " % (nickName["username"], nickName["name"]))
上一篇:[ubuntu]中文用户目录路径改英文


下一篇:(五十六)iOS多线程之NSOperation