Python excel文件读取
来源:互联网 发布:图搜索算法的特点 编辑:程序博客网 时间:2024/04/30 20:14
1. 读取excel文件,建类存储excel数据,
在我的excel文件中存储了学生信息,(姓名,出生年月)
定义class Student
class Etudiant(object):
def __init__(self,idEtudiant, nom,prenom,date,group):
self.idEtudiant=idEtudiant
self.nom = nom
self.prenom=prenom
self.date=date
self.group=group
def adresselec(self):
return self.prenom + '.' + self.nom +'@etu.univ-tours.fr'
def age(self):
return 2016-self.date.year
定义两个函数产生邮箱和年龄
定义日期类
class Date(object):
"""docstring for Date"""
def __init__(self, day,month,year):
self.day=day
self.month=month
self.year=year
def __eq__(self,date):
if self.year == date.year and self.month==date.month and self.day==date.day:
return 1
else:
return 0;
def __lt__(self,date):
if self.year <date.year:
return 1
elif self.year>date.year:
return 0
elif self.month< date.month:
return 1
elif self.month>date.month:
return 0
elif self.day < date.day:
return 1
else: return 0
重写==和<两个函数。
读取excel文件
from student import Etudiant
from date import Date
import csv
students=[]
reader=csv.reader(open('fichetu.csv','r'))
for line in reader:
numero, nom,prenom,date=line[0].split(';')
day, month,year =date.split('/')
dat=Date(day,month,year)
student=Etudiant(nom,prenom,dat)
students.append(student)
文件内容被存储到了students这个list里边OK!
- Python excel文件读取
- python读取excel文件
- python读取excel文件
- python读取excel文件
- python读取excel文件
- Python读取Excel文件
- python读取excel文件
- python 读取excel文件
- Python读取Microsoft Excel文件
- python简单读取excel文件
- Python读取excel写入到RTF文件
- 读取excel文件并绘制图表[Python]
- 【python】 读取Excel文件并绘制图表
- Python读取excel文件(xlrd,xlwt)
- python读取excel文件(xrld模块)
- 【python】 读取Excel文件并绘制图表
- python使用xlwt读取文件写入Excel
- python读取excel文件—xlrd
- Github学习笔记3- Github flow & 创建文件
- HTML5游戏制作之路_04_来做个动画吧
- 【并发编程】Java中断机制——协作式中断含义及应用
- HTML5游戏制作之路_05_egret对位图的操作
- ltib - fails to build Busybox in Ubuntu 12.04
- Python excel文件读取
- HTML5游戏制作之路_06_egret关于精灵表单spritesheet
- ltib L3.0.35_4.1.0_130816 在ubuntu12.04的安装
- 面试重点-getchar,getch,scanf,gets,getche一群纠结的兄弟
- C++编程学习经典网站(持续收集中)
- HeatMap 和 GIS
- LINUX怎样配置静态IP
- 软件开发工程师技术能力层次模型
- 高质高效软件开发组织能力模型