python的运用
来源:互联网 发布:pure music mac 编辑:程序博客网 时间:2024/05/22 01:57
python的运用
读取excel里的内容(包括不同的sheet)
Python 使用 xlrd 读取 Excel格式文件
先装xlrd
- sudo pip install xlrd
#!/usr/bin/python# coding=utf-8import xlrdfname = "Book1.xlsx"bk = xlrd.open_workbook(fname)for k in range(bk.nsheets): sheet_name="Sheet"+str(k+1) try: sh = bk.sheet_by_name(sheet_name) except: print "no sheet in %s named Sheet1" % fname #return None else: print sheet_name nrows = sh.nrows ncols = sh.ncols print "nrows %d, ncols %d" % (nrows,ncols) cell_value = sh.cell_value(0,0) #读单个的值 #print cell_value row_list = [[] for i in range (nrows)] for i in range(0,nrows): #print sh.row_values(i) #读出一行的值,是列表形式 for j in range(0, ncols): row_list[i].append(sh.cell_value(i,j)) #或者 row_list[i].append(sh.row_values(i)[j]) print row_list[i]
数组定义
python数组的使用
python的二维数组操作_浅拷贝
myList = [([0] * 3) for i in range(4)] #可避免浅拷贝
myList = [[0] * 3] * 4 #错误,会出现浅拷贝,当操作myList[0][1] = 1时,发现整个第二列都被赋值(其他行的第二列都被赋值)
row_list = [[] for i in range (nrows)] #nrows行,每行空列表,可用append添加
0 0
- Python的排列组合运用
- python的运用
- python中continue的运用
- python的多线程运用Threading
- python 中threading的运用
- python的GUI的运用(wxpython)
- python与轻量级数据库SQLite的运用
- python特殊属性和方法的运用
- Selenium -Webdriver(python) (四) --- 批处理的运用
- python requests的安装与简单运用
- python requests的安装与简单运用
- python requests的安装与简单运用
- python requests的安装与简单运用
- Python特殊属性和方法的运用
- python requests的安装与简单运用
- python requests的安装与简单运用
- python requests的安装与简单运用
- python 中的赋值语句的运用
- U-BOOT 移植过程详解:添加一块新板子的支持
- 【转】深入了解javascript中的exec与match方法
- solr4.7新建core(core就像数据库里面的一个表)
- ButterKnife使用详解
- Solr客户端 SolrJ单机 添加查询操作
- python的运用
- Linux 文件目录
- Android程序安装后应用图标不显示的问题
- linux密码破解
- 设计模式—模板设计模式
- Solr4.7从数据库导数据
- PAT 1097 Deduplication on a Linked List (25)
- android /system/vold源码分析(6)
- 动态添加TextView