---
title: "第一个python程序-blog数目统计"
author: "caicono"
date: "2010-01-01T21:41:00Z"
tags: []
slug: "python-blog"
draft: false
lastmod: "2010-01-01T21:41:00Z"
id: 609061
url: "https://caicono.iteye.com/blog/609061"
---

第一个python程序，统计2009年日志数目。

 

![](http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)![](http://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)统计blog数目

```

<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--> 1 filename = "C://blog-total.txt"
 2 file = open(filename,'r')
 3 sum =0
 4  while 1:
 5     line= file.readline()
 6     print(line,end='')
 7     if(len(line)==0):
 8         break
 9     left =line.find('(')
10     right =line.rfind(')')
11     sum += int( line[left+1:right])
12 
13 file.close()
14  print("\nYou have written {t} blogs".format(t=sum))
15 
```

结果：

&gt;&gt;&gt;  
2009年12月 (6)  
2009年11月 (6)  
2009年10月 (6)  
2009年9月 (16)  
2009年8月 (16)  
2009年7月 (11)  
2009年6月 (12)  
2009年5月 (11)  
2009年4月 (6)  
2009年3月 (13)  
2009年2月 (3)  
2009年1月 (1)  
You have written 107 blogs