您的位置:首页 > 编程语言 > Python开发

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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: