#!/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
最新推荐文章于 2024-04-07 09:54:30 发布