Browse Source

测试项目

liuyuqi-dellpc 7 years ago
parent
commit
587fa6fc7d
6 changed files with 181 additions and 0 deletions
  1. 71 0
      test-re.ipynb
  2. 19 0
      test-re.py
  3. 24 0
      test.py
  4. 23 0
      test2.py
  5. 21 0
      test3.py
  6. 23 0
      test4.py

+ 71 - 0
test-re.ipynb

@@ -0,0 +1,71 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "metadata": {
+    "collapsed": true
+   },
+   "source": [
+    "# 正则表达式分析邮件"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "fh = open(r\"test_emails.txt\", \"r\").read()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 2",
+   "language": "python",
+   "name": "python2"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 2
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython2",
+   "version": "2.7.6"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}

+ 19 - 0
test-re.py

@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+'''
+正则表达式测试
+@Auther :liuyuqi.gov@msn.cn
+@Time :2018/4/16 13:08
+@File :test-re.py
+'''
+
+
+fh = open(r"test_emails.txt", "r").read()
+for line in fh.split("\n"):
+    if "From:" in line:
+        print(line)
+
+import re
+
+for line in re.findall("From:.*", fh):
+    print(line)

+ 24 - 0
test.py

@@ -0,0 +1,24 @@
+class B(object):
+    def fn(self):
+        print 'B fn'
+    def __init__(self):
+        print "B INIT"
+
+
+class A(object):
+    def fn(self):
+        print 'A fn'
+
+    def __new__(cls,a):
+            print "NEW", a
+            if a>10:
+                return super(A, cls).__new__(cls)
+            return B()
+
+    def __init__(self,a):
+        print "INIT", a
+
+a1 = A(5)
+a1.fn()
+a2=A(20)
+a2.fn()

+ 23 - 0
test2.py

@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+'''
+@Auther :liuyuqi.gov@msn.cn
+@Time :2018/4/14 4:56
+@File :test2.py
+'''
+
+ls = [1,2,3,4]
+list1 = [i for i in ls if i>2]
+print list1
+
+list2 = [i*2 for i in ls if i>2]
+print list2
+
+dic1 = {x: x**2 for x in (2, 4, 6)}
+print dic1
+
+dic2 = {x: 'item' + str(x**2) for x in (2, 4, 6)}
+print dic2
+
+set1 = {x for x in 'hello world' if x not in 'low level'}
+print set1

+ 21 - 0
test3.py

@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+'''
+@Auther :liuyuqi.gov@msn.cn
+@Time :2018/4/14 4:57
+@File :test3.py
+'''
+
+num = 9
+
+def f1():
+    # global num
+    num = 20
+
+def f2():
+    print num
+
+
+f2()
+f1()
+f2()

+ 23 - 0
test4.py

@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+'''
+默认方法:方法 fn1/fn2/fn3 都没有定义,添加代码,是没有定义的方法都调用mydefault函数,上面的代码应该输出
+@Auther :liuyuqi.gov@msn.cn
+@Time :2018/4/14 4:58
+@File :test4.py
+'''
+
+class A(object):
+    def __init__(self,a,b):
+        self.a1 = a
+        self.b1 = b
+        print 'init'
+    def mydefault(self):
+        print 'default'
+    def __getattr__(self,name):
+        return self.mydefault
+
+a1 = A(10,20)
+a1.fn1()
+a1.fn2()
+a1.fn3()