python -----example
2014-05-01 21:27
169 查看
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys from random import randint import re class My_test(object): def __init__(self, x): self.x = x def multiple(x): y = randint(0,5) return x ** y def my_re(self): a = "123abc456" print re.search("([0-9]*)([a-z]*)([0-9]*)",a).group(0) #123abc456,返回整体 print re.search("([0-9]*)([a-z]*)([0-9]*)",a).group(1) #123 def main(): my_list = [i**2 for i in range(1,11)] assert len(my_list) >= 1 # Generates a list of squares of the numbers 1 - 10 try: f = open("output.txt", "w") for item in my_list: f.write(str(item) + "\n") except IOError, e: print "Couldn not open file!" print e except EOFError: print "EOFError....." else: print "No Error!" finally: f.close() if __name__ == "__main__": main()
相关文章推荐
- [Python] example-nine 转义序列
- HTTP with Python – PycURL by Example
- python mail example
- Example code for using the Selenium 2 Python bindings. — Gist
- python embedded in java example
- python socket and SSL example
- SVM Classification python example using sklearn 分类例子
- 发现shedskin的example是学习算法的好材料(Python实现)
- python embedded in java example
- zabbix low level discovery example use python(web_site_url)
- [Python] example-ten 三引号打印多行
- Python example of SSH in multi-threads
- Python daemon example
- The C Programming Language Example and Python Implemented
- [Python] example-seven-string concatenation
- 使用python进行收据搜集示例之feature_engineering_example
- python C example:encode mp3 code
- python multiprocessing example
- K-Means clusternig example with Python and Scikit-learn(推荐)
- Python decorators example