昆仑山:眼中无形心中有穴之穴人合一

夫君子之行,静以修身,俭以养德;非澹泊无以明志,非宁静无以致远。夫学须静也,才须学也;非学无以广才,非志无以成学。怠慢则不能励精,险躁则不能冶性。年与时驰,意与岁去,遂成枯落,多不接世。悲守穷庐,将复何及!

 

python 之文本操着

文本操作

f = open("helloworld.txt", 'r')

# 方法1

# 一次性读取文件,如果文件较大则占用内存较大
# print(f.read(120))
# print(f.read())

# 方法2
# print(f.readline())
# print(f.readline())
# print(f.readline())

# 方法3
txt=f.readlines()
print(txt)
print(type(txt))







excel 操作

import xlrd

xls = xlrd.open_workbook("9x9.xlsx")
# sheet_by_index是通过索引值的方式获取sheet,0表示第一个sheet
sheet = xls.sheet_by_index(0)
print(sheet.nrows) # 总行数
print(sheet.ncols) # 总列数
print(sheet.row_values(1)[0]) # 打印表格第二行第一列

****************************************************************************

import xlrd

xls = xlrd.open_workbook("9x9.xlsx")
sheet = xls.sheet_by_index(0)
print(sheet.nrows)  # 总行数
print(sheet.ncols)  # 总列数
for row in range(sheet.nrows):
    for col in range(sheet.ncols):
        print(sheet.row_values(row)[col])

***************************************************************
import xlrd
import xlwt

wb=xlwt.Workbook()
sheet=wb.add_sheet(u'测试')
sheet.write(0,0,"数学")
sheet.write(0,1,"英语")
wb.save("automate.xls")


posted on 2020-04-15 17:13  Indian_Mysore  阅读(113)  评论(0)    收藏  举报

导航