---
title: "又是一年3月，四六级报名时"
url: "https://lerry.me/post/2012/03/python-process-excel"
date: 2012-03-21T09:34:00.000Z
updated: 2026-08-31T10:28:49.674Z
tags:
  - "Python"
language: zh-CN
---

# 又是一年3月，四六级报名时

又是一年四六级报名，辅导员好懒，让我去挑照片，就是把报名的同学的照片从一个放有所有同学照片的文件夹挑出来，名单是在excel表格里面，[这里](/post/2011/03/sorting-photos-with-python)是去年写的代码，我就在辅导员的电脑上装了个Python，把去年的代码改了下，就搞定了。

昨天写的代码：

```python
# -*- coding: utf-8 -*-
import os,shutil as s
import xlrd
xlsfile = 'temp.xls'
photos = 'imgs'
temphoto='tem6'

data = xlrd.open_workbook(xlsfile)
table1 = data.sheets()[0]

tem6ids = table1.col_values(0)
tem6names = table1.col_values(1)  
    
for id in tem6ids:
    fpath = os.path.join('C:\\temp',photos,str(id)+'.jpg')
    fpath2 = os.path.join('C:\\temp',temphoto,str(id)+'.jpg')
    if os.path.exists(fpath):
        s.copy(fpath,fpath2)
    else:
        print id
```
